Search in sources :

Example 1 with CertAndSigningRequest

use of org.webpieces.plugin.secure.sslcert.CertAndSigningRequest in project webpieces by deanhiller.

the class TestFullSslSetupWizard method postOrgAndPlaceOrderAndFinalizeOrder.

private MockProxyAuthorization postOrgAndPlaceOrderAndFinalizeOrder(String url) throws MalformedURLException {
    URL accountUrl = new URL("http://someurlfor.com/myexact/account/1234");
    mockAcmeClient.setOpenAccount(XFuture.completedFuture(accountUrl));
    List<ProxyAuthorization> proxyAuth = new ArrayList<>();
    MockProxyAuthorization mockProxyAuth = new MockProxyAuthorization("domain.com", Instant.now(), Status.PENDING, new URL("http://somelocation.asdf"), "sometokenforwebdisplay", "authcontent111");
    proxyAuth.add(mockProxyAuth);
    mockAcmeClient.setProxyOrder(XFuture.completedFuture(new ProxyOrder(null, proxyAuth)));
    mockAcmeClient.setCertAndSigningRequest(XFuture.completedFuture(new CertAndSigningRequest("fakecsr", new ArrayList<>())));
    HttpFullRequest req = Requests.createPostRequest(url, "organization", "DeanCo");
    req.addHeader(new Header(KnownHeaderName.COOKIE, "webSession=1-xjrs6SeNeSxmJQtaTwM8gDorNiQ=:backendUser=admin"));
    XFuture<HttpFullResponse> respFuture = https11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    List<Header> headers = response.getResponse().getHeaderLookupStruct().getHeaders(KnownHeaderName.LOCATION);
    Assert.assertEquals(1, headers.size());
    Assert.assertEquals("https://myhost.com/@sslcert/maintainssl", headers.get(0).getValue());
    return mockProxyAuth;
}
Also used : ProxyOrder(org.webpieces.plugin.secure.sslcert.acme.ProxyOrder) ArrayList(java.util.ArrayList) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) URL(java.net.URL) CertAndSigningRequest(org.webpieces.plugin.secure.sslcert.CertAndSigningRequest) HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ProxyAuthorization(org.webpieces.plugin.secure.sslcert.acme.ProxyAuthorization)

Example 2 with CertAndSigningRequest

use of org.webpieces.plugin.secure.sslcert.CertAndSigningRequest in project webpieces by deanhiller.

the class AcmeClientProxy method finalizeOrder.

private XFuture<CertAndSigningRequest> finalizeOrder(ProxyOrder proxyOrder, String domain, String organization, KeyPair accountKeyPair) {
    try (StringWriter writer = new StringWriter()) {
        Order order = proxyOrder.getOrder();
        CSRBuilder csrb = new CSRBuilder();
        csrb.addDomain(domain);
        csrb.setOrganization(organization);
        csrb.sign(accountKeyPair);
        byte[] csr = csrb.getEncoded();
        // NEED to store the csr as base64 into the DB!!!
        order.execute(csr);
        while (order.getStatus() != Status.VALID) {
            Thread.sleep(3000L);
            order.update();
        }
        csrb.write(writer);
        Certificate cert = order.getCertificate();
        return XFuture.completedFuture(new CertAndSigningRequest(writer.toString(), cert.getCertificateChain()));
    } catch (AcmeException | IOException | InterruptedException e) {
        throw SneakyThrow.sneak(e);
    }
}
Also used : Order(org.shredzone.acme4j.Order) CertAndSigningRequest(org.webpieces.plugin.secure.sslcert.CertAndSigningRequest) StringWriter(java.io.StringWriter) AcmeException(org.shredzone.acme4j.exception.AcmeException) IOException(java.io.IOException) CSRBuilder(org.shredzone.acme4j.util.CSRBuilder) Certificate(org.shredzone.acme4j.Certificate)

Aggregations

CertAndSigningRequest (org.webpieces.plugin.secure.sslcert.CertAndSigningRequest)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Certificate (org.shredzone.acme4j.Certificate)1 Order (org.shredzone.acme4j.Order)1 AcmeException (org.shredzone.acme4j.exception.AcmeException)1 CSRBuilder (org.shredzone.acme4j.util.CSRBuilder)1 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)1 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)1 Header (org.webpieces.httpparser.api.common.Header)1 ProxyAuthorization (org.webpieces.plugin.secure.sslcert.acme.ProxyAuthorization)1 ProxyOrder (org.webpieces.plugin.secure.sslcert.acme.ProxyOrder)1 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)1