Search in sources :

Example 16 with OCSPReq

use of org.bouncycastle.cert.ocsp.OCSPReq in project ddf by codice.

the class OcspChecker method logRequest.

private void logRequest(OCSPReq ocspRequest) {
    StringBuilder logBuilder = new StringBuilder();
    logBuilder.append("OCSP Request:\n");
    logBuilder.append("  TBSRequest:\n");
    logBuilder.append("    version: " + getValueOrDefault(ocspRequest.getVersionNumber(), "") + "\n");
    logBuilder.append("    requestorName: " + getValueOrDefault(ocspRequest.getRequestorName(), "").toString() + "\n");
    logBuilder.append("    requestList:\n");
    Req[] requests = ocspRequest.getRequestList();
    if (requests != null) {
        for (int i = 0; i < requests.length; i++) {
            logBuilder.append("      Certificate " + i + "\n");
            CertificateID cert = requests[i].getCertID();
            if (cert != null) {
                logBuilder.append("        hashAlgorithm: " + getValueOrDefault(cert.getHashAlgOID(), "").toString() + "\n");
                logBuilder.append("        issuerNameHash: " + getValueOrDefault(Arrays.toString(cert.getIssuerNameHash()), "") + "\n");
                logBuilder.append("        issuerKeyHash: " + getValueOrDefault(Arrays.toString(cert.getIssuerKeyHash()), "") + "\n");
                logBuilder.append("        cert serial number: " + getValueOrDefault(cert.getSerialNumber(), "").toString() + "\n");
            }
        }
    }
    LOGGER.trace(logBuilder.toString());
}
Also used : CertificateID(org.bouncycastle.cert.ocsp.CertificateID) Req(org.bouncycastle.cert.ocsp.Req) OCSPReq(org.bouncycastle.cert.ocsp.OCSPReq)

Example 17 with OCSPReq

use of org.bouncycastle.cert.ocsp.OCSPReq in project ddf by codice.

the class OcspCheckerTest method testSendOcspRequestBrokenServerUrls.

@Test
public void testSendOcspRequestBrokenServerUrls() throws Exception {
    brokenEndpoints.add(new URI("https://brokenurl:8993"));
    brokenEndpoints.add(new URI("https://brokenurl2:8993"));
    brokenEndpoints.add(new URI("https://brokenurl3:8993"));
    List<URI> ocspServerUrls = new ArrayList<>(brokenEndpoints);
    brokenEndpoints.add(new URI(EMBEDDED_OCSP_SERVER_URL));
    OcspChecker ocspChecker = new OcspChecker(factory, eventAdmin);
    ocspChecker.setSecurityLogger(mock(SecurityLogger.class));
    ocspChecker.setOcspEnabled(true);
    ocspChecker.setOcspServerUrls(ocspServerUrls.stream().map(URI::toString).collect(Collectors.toList()));
    OCSPReq ocspReq = ocspChecker.generateOcspRequest(trustedCertBc);
    Map<URI, CertificateStatus> ocspStatuses = ocspChecker.sendOcspRequests(trustedCertX509, ocspReq);
    assertStatuses(ocspStatuses);
}
Also used : OCSPReq(org.bouncycastle.cert.ocsp.OCSPReq) CertificateStatus(org.bouncycastle.cert.ocsp.CertificateStatus) ArrayList(java.util.ArrayList) URI(java.net.URI) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 18 with OCSPReq

use of org.bouncycastle.cert.ocsp.OCSPReq in project ddf by codice.

the class OcspCheckerTest method testSendOcspRequestsRevokedEmbeddedUrl.

@Test
public void testSendOcspRequestsRevokedEmbeddedUrl() throws Exception {
    unknownEndpoints.add(new URI("https://unknownurl:8993"));
    unknownEndpoints.add(new URI("https://unknownurl2:8993"));
    revokedEndpoints.add(new URI(EMBEDDED_OCSP_SERVER_URL));
    List<URI> ocspServerUrls = new ArrayList<>(unknownEndpoints);
    OcspChecker ocspChecker = new OcspChecker(factory, eventAdmin);
    ocspChecker.setSecurityLogger(mock(SecurityLogger.class));
    ocspChecker.setOcspEnabled(true);
    ocspChecker.setOcspServerUrls(ocspServerUrls.stream().map(URI::toString).collect(Collectors.toList()));
    OCSPReq ocspReq = ocspChecker.generateOcspRequest(trustedCertBc);
    Map<URI, CertificateStatus> ocspStatuses = ocspChecker.sendOcspRequests(trustedCertX509, ocspReq);
    assertStatuses(ocspStatuses);
}
Also used : OCSPReq(org.bouncycastle.cert.ocsp.OCSPReq) CertificateStatus(org.bouncycastle.cert.ocsp.CertificateStatus) ArrayList(java.util.ArrayList) URI(java.net.URI) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 19 with OCSPReq

use of org.bouncycastle.cert.ocsp.OCSPReq in project ddf by codice.

the class OcspCheckerTest method testSendOcspRequestsUnknownStatus.

@Test
public void testSendOcspRequestsUnknownStatus() throws Exception {
    unknownEndpoints.add(new URI("https://unknownurl:8993"));
    brokenEndpoints.add(new URI(EMBEDDED_OCSP_SERVER_URL));
    List<URI> ocspServerUrls = new ArrayList<>(unknownEndpoints);
    OcspChecker ocspChecker = new OcspChecker(factory, eventAdmin);
    ocspChecker.setSecurityLogger(mock(SecurityLogger.class));
    ocspChecker.setOcspEnabled(true);
    ocspChecker.setOcspServerUrls(ocspServerUrls.stream().map(URI::toString).collect(Collectors.toList()));
    OCSPReq ocspReq = ocspChecker.generateOcspRequest(trustedCertBc);
    Map<URI, CertificateStatus> ocspStatuses = ocspChecker.sendOcspRequests(trustedCertX509, ocspReq);
    assertStatuses(ocspStatuses);
}
Also used : OCSPReq(org.bouncycastle.cert.ocsp.OCSPReq) CertificateStatus(org.bouncycastle.cert.ocsp.CertificateStatus) ArrayList(java.util.ArrayList) URI(java.net.URI) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 20 with OCSPReq

use of org.bouncycastle.cert.ocsp.OCSPReq in project ddf by codice.

the class OcspCheckerTest method testSendOcspRequestsGoodStatus.

@Test
public void testSendOcspRequestsGoodStatus() throws Exception {
    goodEndpoints.add(new URI("https://goodurl:8993"));
    brokenEndpoints.add(new URI(EMBEDDED_OCSP_SERVER_URL));
    List<URI> ocspServerUrls = new ArrayList<>(goodEndpoints);
    OcspChecker ocspChecker = new OcspChecker(factory, eventAdmin);
    ocspChecker.setSecurityLogger(mock(SecurityLogger.class));
    ocspChecker.setOcspEnabled(true);
    ocspChecker.setOcspServerUrls(ocspServerUrls.stream().map(URI::toString).collect(Collectors.toList()));
    OCSPReq ocspReq = ocspChecker.generateOcspRequest(trustedCertBc);
    Map<URI, CertificateStatus> ocspStatuses = ocspChecker.sendOcspRequests(trustedCertX509, ocspReq);
    assertStatuses(ocspStatuses);
}
Also used : OCSPReq(org.bouncycastle.cert.ocsp.OCSPReq) CertificateStatus(org.bouncycastle.cert.ocsp.CertificateStatus) ArrayList(java.util.ArrayList) URI(java.net.URI) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Aggregations

OCSPReq (org.bouncycastle.cert.ocsp.OCSPReq)23 CertificateStatus (org.bouncycastle.cert.ocsp.CertificateStatus)12 URI (java.net.URI)11 SecurityLogger (ddf.security.audit.SecurityLogger)10 Test (org.junit.Test)10 X509Certificate (java.security.cert.X509Certificate)8 ArrayList (java.util.ArrayList)8 BasicOCSPResp (org.bouncycastle.cert.ocsp.BasicOCSPResp)7 OCSPResp (org.bouncycastle.cert.ocsp.OCSPResp)7 IOException (java.io.IOException)6 CertificateID (org.bouncycastle.cert.ocsp.CertificateID)6 OCSPReqBuilder (org.bouncycastle.cert.ocsp.OCSPReqBuilder)5 SingleResp (org.bouncycastle.cert.ocsp.SingleResp)5 JcaDigestCalculatorProviderBuilder (org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder)5 BigInteger (java.math.BigInteger)4 Date (java.util.Date)4 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)4 RevokedStatus (org.bouncycastle.cert.ocsp.RevokedStatus)4 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)4 InputStream (java.io.InputStream)3