java.security.cert.Extension#getValue()源码实例Demo

下面列出了java.security.cert.Extension#getValue() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u-backup   文件: OCSP.java
/**
 * Checks the revocation status of a list of certificates using OCSP.
 *
 * @param certIds the CertIds to be checked
 * @param responderURI the URI of the OCSP responder
 * @param issuerInfo the issuer's certificate and/or subject and public key
 * @param responderCert the OCSP responder's certificate
 * @param date the time the validity of the OCSP responder's certificate
 *    should be checked against. If null, the current time is used.
 * @param extensions zero or more OCSP extensions to be included in the
 *    request.  If no extensions are requested, an empty {@code List} must
 *    be used.  A {@code null} value is not allowed.
 * @return the OCSPResponse
 * @throws IOException if there is an exception connecting to or
 *    communicating with the OCSP responder
 * @throws CertPathValidatorException if an exception occurs while
 *    encoding the OCSP Request or validating the OCSP Response
 */
static OCSPResponse check(List<CertId> certIds, URI responderURI,
                          OCSPResponse.IssuerInfo issuerInfo,
                          X509Certificate responderCert, Date date,
                          List<Extension> extensions, String variant)
    throws IOException, CertPathValidatorException
{
    byte[] nonce = null;
    for (Extension ext : extensions) {
        if (ext.getId().equals(PKIXExtensions.OCSPNonce_Id.toString())) {
            nonce = ext.getValue();
        }
    }

    OCSPResponse ocspResponse = null;
    try {
        byte[] response = getOCSPBytes(certIds, responderURI, extensions);
        ocspResponse = new OCSPResponse(response);

        // verify the response
        ocspResponse.verify(certIds, issuerInfo, responderCert, date,
                nonce, variant);
    } catch (IOException ioe) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            ioe, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    return ocspResponse;
}
 
源代码2 项目: openjdk-jdk9   文件: OCSP.java
/**
 * Checks the revocation status of a list of certificates using OCSP.
 *
 * @param certIds the CertIds to be checked
 * @param responderURI the URI of the OCSP responder
 * @param issuerInfo the issuer's certificate and/or subject and public key
 * @param responderCert the OCSP responder's certificate
 * @param date the time the validity of the OCSP responder's certificate
 *    should be checked against. If null, the current time is used.
 * @param extensions zero or more OCSP extensions to be included in the
 *    request.  If no extensions are requested, an empty {@code List} must
 *    be used.  A {@code null} value is not allowed.
 * @return the OCSPResponse
 * @throws IOException if there is an exception connecting to or
 *    communicating with the OCSP responder
 * @throws CertPathValidatorException if an exception occurs while
 *    encoding the OCSP Request or validating the OCSP Response
 */
static OCSPResponse check(List<CertId> certIds, URI responderURI,
                          OCSPResponse.IssuerInfo issuerInfo,
                          X509Certificate responderCert, Date date,
                          List<Extension> extensions, String variant)
    throws IOException, CertPathValidatorException
{
    byte[] nonce = null;
    for (Extension ext : extensions) {
        if (ext.getId().equals(PKIXExtensions.OCSPNonce_Id.toString())) {
            nonce = ext.getValue();
        }
    }

    OCSPResponse ocspResponse = null;
    try {
        byte[] response = getOCSPBytes(certIds, responderURI, extensions);
        ocspResponse = new OCSPResponse(response);

        // verify the response
        ocspResponse.verify(certIds, issuerInfo, responderCert, date,
                nonce, variant);
    } catch (IOException ioe) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            ioe, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    return ocspResponse;
}
 
源代码3 项目: jdk8u-jdk   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码4 项目: jdk8u_jdk   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        certId = new CertId(issuerInfo.getName(), issuerInfo.getPublicKey(),
                currCert.getSerialNumberObject());

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerInfo,
                    responderCert, params.date(), nonce, params.variant());

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                    responderURI, issuerInfo, responderCert, null,
                    ocspExtensions, params.variant());
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码5 项目: openjdk-8   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码6 项目: j2objc   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        if (issuerCert != null) {
            certId = new CertId(issuerCert,
                                currCert.getSerialNumberObject());
        } else {
            // must be an anchor name and key
            certId = new CertId(anchor.getCA(), anchor.getCAPublicKey(),
                                currCert.getSerialNumberObject());
        }

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerCert,
                            responderCert, params.date(), nonce);

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                                  responderURI, issuerCert, responderCert,
                                  null, ocspExtensions);
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码7 项目: TencentKona-8   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(
                        PKIXExtensions.OCSPNonce_Id.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码8 项目: jdk8u-dev-jdk   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码9 项目: openjdk-jdk9   文件: OCSPNonceExtensionTests.java
@Override
public Map.Entry<Boolean, String> runTest() {
    Boolean pass = Boolean.FALSE;
    String message = null;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        Extension nonceByDer = new sun.security.x509.Extension(
                new DerValue(OCSP_NONCE_DER));

        // Verify overall encoded extension structure
        nonceByDer.encode(baos);
        verifyExtStructure(baos.toByteArray());

        // Verify the name, elements, and data conform to
        // expected values for this specific object.
        boolean crit = nonceByDer.isCritical();
        String oid = nonceByDer.getId();
        DerValue nonceData = new DerValue(nonceByDer.getValue());

        if (!crit) {
            message = "Extension lacks expected criticality setting";
        } else if (!oid.equals(OCSP_NONCE_OID)) {
            message = "Incorrect OID (Got " + oid + ", Expected " +
                    OCSP_NONCE_OID + ")";
        } else if (nonceData.getTag() != DerValue.tag_OctetString) {
            message = "Incorrect nonce data tag type (Got " +
                    String.format("0x%02X", nonceData.getTag()) +
                    ", Expected 0x04)";
        } else if (nonceData.getOctetString().length != 48) {
            message = "Incorrect nonce byte length (Got " +
                    nonceData.getOctetString().length +
                    ", Expected 48)";
        } else {
            pass = Boolean.TRUE;
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        message = e.getClass().getName();
    }

    return new AbstractMap.SimpleEntry<>(pass, message);
}
 
源代码10 项目: jdk8u60   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        if (issuerCert != null) {
            certId = new CertId(issuerCert,
                                currCert.getSerialNumberObject());
        } else {
            // must be an anchor name and key
            certId = new CertId(anchor.getCA(), anchor.getCAPublicKey(),
                                currCert.getSerialNumberObject());
        }

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerCert,
                            responderCert, params.date(), nonce);

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                                  responderURI, issuerCert, responderCert,
                                  null, ocspExtensions);
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码11 项目: hottub   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码12 项目: hottub   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        if (issuerCert != null) {
            certId = new CertId(issuerCert,
                                currCert.getSerialNumberObject());
        } else {
            // must be an anchor name and key
            certId = new CertId(anchor.getCA(), anchor.getCAPublicKey(),
                                currCert.getSerialNumberObject());
        }

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerCert,
                            responderCert, params.date(), nonce);

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                                  responderURI, issuerCert, responderCert,
                                  null, ocspExtensions);
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码13 项目: jdk8u-jdk   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        if (issuerCert != null) {
            certId = new CertId(issuerCert,
                                currCert.getSerialNumberObject());
        } else {
            // must be an anchor name and key
            certId = new CertId(anchor.getCA(), anchor.getCAPublicKey(),
                                currCert.getSerialNumberObject());
        }

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerCert,
                            responderCert, params.date(), nonce);

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                                  responderURI, issuerCert, responderCert,
                                  null, ocspExtensions);
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(
                        PKIXExtensions.OCSPNonce_Id.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码15 项目: openjdk-jdk8u-backup   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        certId = new CertId(issuerInfo.getName(), issuerInfo.getPublicKey(),
                currCert.getSerialNumberObject());

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerInfo,
                    responderCert, params.date(), nonce, params.variant());

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                    responderURI, issuerInfo, responderCert, null,
                    ocspExtensions, params.variant());
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码16 项目: jdk8u_jdk   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(
                        PKIXExtensions.OCSPNonce_Id.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码17 项目: Bytecoder   文件: OCSPRequest.java
byte[] encodeBytes() throws IOException {

        // encode tbsRequest
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream requestsOut = new DerOutputStream();
        for (CertId certId : certIds) {
            DerOutputStream certIdOut = new DerOutputStream();
            certId.encode(certIdOut);
            requestsOut.write(DerValue.tag_Sequence, certIdOut);
        }

        tmp.write(DerValue.tag_Sequence, requestsOut);
        if (!extensions.isEmpty()) {
            DerOutputStream extOut = new DerOutputStream();
            for (Extension ext : extensions) {
                ext.encode(extOut);
                if (ext.getId().equals(
                        PKIXExtensions.OCSPNonce_Id.toString())) {
                    nonce = ext.getValue();
                }
            }
            DerOutputStream extsOut = new DerOutputStream();
            extsOut.write(DerValue.tag_Sequence, extOut);
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)2), extsOut);
        }

        DerOutputStream tbsRequest = new DerOutputStream();
        tbsRequest.write(DerValue.tag_Sequence, tmp);

        // OCSPRequest without the signature
        DerOutputStream ocspRequest = new DerOutputStream();
        ocspRequest.write(DerValue.tag_Sequence, tbsRequest);

        byte[] bytes = ocspRequest.toByteArray();

        if (dump) {
            HexDumpEncoder hexEnc = new HexDumpEncoder();
            debug.println("OCSPRequest bytes...\n\n" +
                hexEnc.encode(bytes) + "\n");
        }

        return bytes;
    }
 
源代码18 项目: Bytecoder   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        certId = new CertId(issuerInfo.getName(), issuerInfo.getPublicKey(),
                currCert.getSerialNumberObject());

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerInfo,
                    responderCert, params.date(), nonce, params.variant());

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                    responderURI, issuerInfo, responderCert, null,
                    ocspExtensions, params.variant());
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码19 项目: openjdk-8   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        if (issuerCert != null) {
            certId = new CertId(issuerCert,
                                currCert.getSerialNumberObject());
        } else {
            // must be an anchor name and key
            certId = new CertId(anchor.getCA(), anchor.getCAPublicKey(),
                                currCert.getSerialNumberObject());
        }

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerCert,
                            responderCert, params.date(), nonce);

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                                  responderURI, issuerCert, responderCert,
                                  null, ocspExtensions);
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
源代码20 项目: openjdk-jdk9   文件: RevocationChecker.java
private void checkOCSP(X509Certificate cert,
                       Collection<String> unresolvedCritExts)
    throws CertPathValidatorException
{
    X509CertImpl currCert = null;
    try {
        currCert = X509CertImpl.toImpl(cert);
    } catch (CertificateException ce) {
        throw new CertPathValidatorException(ce);
    }

    // The algorithm constraints of the OCSP trusted responder certificate
    // does not need to be checked in this code. The constraints will be
    // checked when the responder's certificate is validated.

    OCSPResponse response = null;
    CertId certId = null;
    try {
        certId = new CertId(issuerInfo.getName(), issuerInfo.getPublicKey(),
                currCert.getSerialNumberObject());

        // check if there is a cached OCSP response available
        byte[] responseBytes = ocspResponses.get(cert);
        if (responseBytes != null) {
            if (debug != null) {
                debug.println("Found cached OCSP response");
            }
            response = new OCSPResponse(responseBytes);

            // verify the response
            byte[] nonce = null;
            for (Extension ext : ocspExtensions) {
                if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
                    nonce = ext.getValue();
                }
            }
            response.verify(Collections.singletonList(certId), issuerInfo,
                    responderCert, params.date(), nonce, params.variant());

        } else {
            URI responderURI = (this.responderURI != null)
                               ? this.responderURI
                               : OCSP.getResponderURI(currCert);
            if (responderURI == null) {
                throw new CertPathValidatorException(
                    "Certificate does not specify OCSP responder", null,
                    null, -1);
            }

            response = OCSP.check(Collections.singletonList(certId),
                    responderURI, issuerInfo, responderCert, null,
                    ocspExtensions, params.variant());
        }
    } catch (IOException e) {
        throw new CertPathValidatorException(
            "Unable to determine revocation status due to network error",
            e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }

    RevocationStatus rs =
        (RevocationStatus)response.getSingleResponse(certId);
    RevocationStatus.CertStatus certStatus = rs.getCertStatus();
    if (certStatus == RevocationStatus.CertStatus.REVOKED) {
        Date revocationTime = rs.getRevocationTime();
        if (revocationTime.before(params.date())) {
            Throwable t = new CertificateRevokedException(
                revocationTime, rs.getRevocationReason(),
                response.getSignerCertificate().getSubjectX500Principal(),
                rs.getSingleExtensions());
            throw new CertPathValidatorException(t.getMessage(), t, null,
                                                 -1, BasicReason.REVOKED);
        }
    } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
        throw new CertPathValidatorException(
            "Certificate's revocation status is unknown", null,
            params.certPath(), -1,
            BasicReason.UNDETERMINED_REVOCATION_STATUS);
    }
}
 
 方法所在类
 同类方法