Certificate extends AcmeResource { public void revoke() throws AcmeException { revoke(null); } protected  Certificate(Login login, URL certUrl); void download(); X509Certificate getCertificate(); List<X509Certificate> getCertificateChain(); List<URL> getAlternates(); void writeCertificate(Writer out); void revoke(); void revoke(@Nullable RevocationReason reason); static void revoke(Login login, X509Certificate cert, @Nullable RevocationReason reason); static void revoke(Session session, KeyPair domainKeyPair, X509Certificate cert,
            @Nullable RevocationReason reason);  }
@Test public void testRevokeCertificate() throws AcmeException, IOException { final List<X509Certificate> originalCert = TestUtils.createCertificate(); TestableConnectionProvider provider = new TestableConnectionProvider() { private boolean certRequested = false; @Override public int sendCertificateRequest(URL url, Login login) { assertThat(url, is(locationUrl)); assertThat(login, is(notNullValue())); certRequested = true; return HttpURLConnection.HTTP_OK; } @Override public int sendSignedRequest(URL url, JSONBuilder claims, Login login) { assertThat(url, is(resourceUrl)); assertThat(claims.toString(), sameJSONAs(getJSON("revokeCertificateRequest").toString())); assertThat(login, is(notNullValue())); certRequested = false; return HttpURLConnection.HTTP_OK; } @Override public List<X509Certificate> readCertificates() { assertThat(certRequested, is(true)); return originalCert; } @Override public Collection<URL> getLinks(String relation) { assertThat(relation, is("alternate")); return Collections.emptyList(); } }; provider.putTestResource(Resource.REVOKE_CERT, resourceUrl); Certificate cert = new Certificate(provider.createLogin(), locationUrl); cert.revoke(); provider.close(); }
@Test public void testRevokeCertificateWithReason() throws AcmeException, IOException { final List<X509Certificate> originalCert = TestUtils.createCertificate(); TestableConnectionProvider provider = new TestableConnectionProvider() { private boolean certRequested = false; @Override public int sendCertificateRequest(URL url, Login login) { assertThat(url, is(locationUrl)); assertThat(login, is(notNullValue())); certRequested = true; return HttpURLConnection.HTTP_OK; } @Override public int sendSignedRequest(URL url, JSONBuilder claims, Login login) { assertThat(url, is(resourceUrl)); assertThat(claims.toString(), sameJSONAs(getJSON("revokeCertificateWithReasonRequest").toString())); assertThat(login, is(notNullValue())); certRequested = false; return HttpURLConnection.HTTP_OK; } @Override public List<X509Certificate> readCertificates() { assertThat(certRequested, is(true)); return originalCert; } @Override public Collection<URL> getLinks(String relation) { assertThat(relation, is("alternate")); return Collections.emptyList(); } }; provider.putTestResource(Resource.REVOKE_CERT, resourceUrl); Certificate cert = new Certificate(provider.createLogin(), locationUrl); cert.revoke(RevocationReason.KEY_COMPROMISE); provider.close(); }
@Test public void testRevokeCertificateByKeyPair() throws AcmeException, IOException { final List<X509Certificate> originalCert = TestUtils.createCertificate(); final KeyPair certKeyPair = TestUtils.createDomainKeyPair(); TestableConnectionProvider provider = new TestableConnectionProvider() { @Override public int sendSignedRequest(URL url, JSONBuilder claims, Session session, KeyPair keypair) { assertThat(url, is(resourceUrl)); assertThat(claims.toString(), sameJSONAs(getJSON("revokeCertificateWithReasonRequest").toString())); assertThat(session, is(notNullValue())); assertThat(keypair, is(certKeyPair)); return HttpURLConnection.HTTP_OK; } }; provider.putTestResource(Resource.REVOKE_CERT, resourceUrl); Session session = provider.createSession(); Certificate.revoke(session, certKeyPair, originalCert.get(0), RevocationReason.KEY_COMPROMISE); provider.close(); }