Java Code Examples for sun.security.x509.X509CertImpl#toImpl()
The following examples show how to use
sun.security.x509.X509CertImpl#toImpl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OCSP.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public static RevocationStatus check(X509Certificate cert, X509Certificate issuerCert, URI responderURI, X509Certificate responderCert, Date date, List<Extension> extensions) throws IOException, CertPathValidatorException { CertId certId = null; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, issuerCert, responderCert, date, extensions); return (RevocationStatus) ocspResponse.getSingleResponse(certId); }
Example 2
Source File: OCSP.java From Bytecoder with Apache License 2.0 | 6 votes |
public static RevocationStatus check(X509Certificate cert, URI responderURI, TrustAnchor anchor, X509Certificate issuerCert, X509Certificate responderCert, Date date, List<Extension> extensions, String variant) throws IOException, CertPathValidatorException { CertId certId; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, new OCSPResponse.IssuerInfo(anchor, issuerCert), responderCert, date, extensions, variant); return (RevocationStatus) ocspResponse.getSingleResponse(certId); }
Example 3
Source File: OCSP.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Obtains the revocation status of a certificate using OCSP using the most * common defaults. The OCSP responder URI is retrieved from the * certificate's AIA extension. The OCSP responder certificate is assumed * to be the issuer's certificate (or issued by the issuer CA). * * @param cert the certificate to be checked * @param issuerCert the issuer certificate * @return the RevocationStatus * @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 */ public static RevocationStatus check(X509Certificate cert, X509Certificate issuerCert) throws IOException, CertPathValidatorException { CertId certId = null; URI responderURI = null; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); responderURI = getResponderURI(certImpl); if (responderURI == null) { throw new CertPathValidatorException ("No OCSP Responder URI in certificate"); } certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, issuerCert, null, null, Collections.<Extension>emptyList()); return (RevocationStatus)ocspResponse.getSingleResponse(certId); }
Example 4
Source File: OCSP.java From j2objc with Apache License 2.0 | 6 votes |
public static RevocationStatus check(X509Certificate cert, X509Certificate issuerCert, URI responderURI, X509Certificate responderCert, Date date, List<Extension> extensions) throws IOException, CertPathValidatorException { CertId certId = null; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, issuerCert, responderCert, date, extensions); return (RevocationStatus) ocspResponse.getSingleResponse(certId); }
Example 5
Source File: OCSP.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static RevocationStatus check(X509Certificate cert, URI responderURI, TrustAnchor anchor, X509Certificate issuerCert, X509Certificate responderCert, Date date, List<Extension> extensions, String variant) throws IOException, CertPathValidatorException { CertId certId; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, new OCSPResponse.IssuerInfo(anchor, issuerCert), responderCert, date, extensions, variant); return (RevocationStatus) ocspResponse.getSingleResponse(certId); }
Example 6
Source File: OCSP.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static RevocationStatus check(X509Certificate cert, URI responderURI, TrustAnchor anchor, X509Certificate issuerCert, X509Certificate responderCert, Date date, List<Extension> extensions, String variant) throws IOException, CertPathValidatorException { CertId certId; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, new OCSPResponse.IssuerInfo(anchor, issuerCert), responderCert, date, extensions, variant); return (RevocationStatus) ocspResponse.getSingleResponse(certId); }
Example 7
Source File: OCSP.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Obtains the revocation status of a certificate using OCSP using the most * common defaults. The OCSP responder URI is retrieved from the * certificate's AIA extension. The OCSP responder certificate is assumed * to be the issuer's certificate (or issued by the issuer CA). * * @param cert the certificate to be checked * @param issuerCert the issuer certificate * @return the RevocationStatus * @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 */ public static RevocationStatus check(X509Certificate cert, X509Certificate issuerCert) throws IOException, CertPathValidatorException { CertId certId = null; URI responderURI = null; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); responderURI = getResponderURI(certImpl); if (responderURI == null) { throw new CertPathValidatorException ("No OCSP Responder URI in certificate"); } certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, issuerCert, null, null, Collections.<Extension>emptyList()); return (RevocationStatus)ocspResponse.getSingleResponse(certId); }
Example 8
Source File: OCSP.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static RevocationStatus check(X509Certificate cert, X509Certificate issuerCert, URI responderURI, X509Certificate responderCert, Date date, List<Extension> extensions) throws IOException, CertPathValidatorException { CertId certId = null; try { X509CertImpl certImpl = X509CertImpl.toImpl(cert); certId = new CertId(issuerCert, certImpl.getSerialNumberObject()); } catch (CertificateException | IOException e) { throw new CertPathValidatorException ("Exception while encoding OCSPRequest", e); } OCSPResponse ocspResponse = check(Collections.singletonList(certId), responderURI, issuerCert, responderCert, date, extensions); return (RevocationStatus) ocspResponse.getSingleResponse(certId); }
Example 9
Source File: PolicyChecker.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Internal method to run through all the checks. * * @param currCert the certificate to be processed * @exception CertPathValidatorException Exception thrown if * the certificate does not verify */ private void checkPolicy(X509Certificate currCert) throws CertPathValidatorException { String msg = "certificate policies"; if (debug != null) { debug.println("PolicyChecker.checkPolicy() ---checking " + msg + "..."); debug.println("PolicyChecker.checkPolicy() certIndex = " + certIndex); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "explicitPolicy = " + explicitPolicy); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "policyMapping = " + policyMapping); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "inhibitAnyPolicy = " + inhibitAnyPolicy); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "policyTree = " + rootNode); } X509CertImpl currCertImpl = null; try { currCertImpl = X509CertImpl.toImpl(currCert); } catch (CertificateException ce) { throw new CertPathValidatorException(ce); } boolean finalCert = (certIndex == certPathLen); rootNode = processPolicies(certIndex, initPolicies, explicitPolicy, policyMapping, inhibitAnyPolicy, rejectPolicyQualifiers, rootNode, currCertImpl, finalCert); if (!finalCert) { explicitPolicy = mergeExplicitPolicy(explicitPolicy, currCertImpl, finalCert); policyMapping = mergePolicyMapping(policyMapping, currCertImpl); inhibitAnyPolicy = mergeInhibitAnyPolicy(inhibitAnyPolicy, currCertImpl); } certIndex++; if (debug != null) { debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "explicitPolicy = " + explicitPolicy); debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "policyMapping = " + policyMapping); debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "inhibitAnyPolicy = " + inhibitAnyPolicy); debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "policyTree = " + rootNode); debug.println("PolicyChecker.checkPolicy() " + msg + " verified"); } }
Example 10
Source File: ConstraintsChecker.java From j2objc with Apache License 2.0 | 4 votes |
/** * Helper to fold sets of name constraints together */ static NameConstraintsExtension mergeNameConstraints( X509Certificate currCert, NameConstraintsExtension prevNC) throws CertPathValidatorException { X509CertImpl currCertImpl; try { currCertImpl = X509CertImpl.toImpl(currCert); } catch (CertificateException ce) { throw new CertPathValidatorException(ce); } NameConstraintsExtension newConstraints = currCertImpl.getNameConstraintsExtension(); if (debug != null) { debug.println("prevNC = " + prevNC + ", newNC = " + String.valueOf(newConstraints)); } // if there are no previous name constraints, we just return the // new name constraints. if (prevNC == null) { if (debug != null) { debug.println("mergedNC = " + String.valueOf(newConstraints)); } if (newConstraints == null) { return newConstraints; } else { // Make sure we do a clone here, because we're probably // going to modify this object later and we don't want to // be sharing it with a Certificate object! return (NameConstraintsExtension)newConstraints.clone(); } } else { try { // after merge, prevNC should contain the merged constraints prevNC.merge(newConstraints); } catch (IOException ioe) { throw new CertPathValidatorException(ioe); } if (debug != null) { debug.println("mergedNC = " + prevNC); } return prevNC; } }
Example 11
Source File: ConstraintsChecker.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Helper to fold sets of name constraints together */ static NameConstraintsExtension mergeNameConstraints( X509Certificate currCert, NameConstraintsExtension prevNC) throws CertPathValidatorException { X509CertImpl currCertImpl; try { currCertImpl = X509CertImpl.toImpl(currCert); } catch (CertificateException ce) { throw new CertPathValidatorException(ce); } NameConstraintsExtension newConstraints = currCertImpl.getNameConstraintsExtension(); if (debug != null) { debug.println("prevNC = " + prevNC); debug.println("newNC = " + String.valueOf(newConstraints)); } // if there are no previous name constraints, we just return the // new name constraints. if (prevNC == null) { if (debug != null) { debug.println("mergedNC = " + String.valueOf(newConstraints)); } if (newConstraints == null) { return newConstraints; } else { // Make sure we do a clone here, because we're probably // going to modify this object later and we don't want to // be sharing it with a Certificate object! return (NameConstraintsExtension)newConstraints.clone(); } } else { try { // after merge, prevNC should contain the merged constraints prevNC.merge(newConstraints); } catch (IOException ioe) { throw new CertPathValidatorException(ioe); } if (debug != null) { debug.println("mergedNC = " + prevNC); } return prevNC; } }
Example 12
Source File: PKIXCertPathValidator.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private static PKIXCertPathValidatorResult validate(ValidatorParams params) throws CertPathValidatorException { if (debug != null) debug.println("PKIXCertPathValidator.engineValidate()..."); // Retrieve the first certificate in the certpath // (to be used later in pre-screening) AdaptableX509CertSelector selector = null; List<X509Certificate> certList = params.certificates(); if (!certList.isEmpty()) { selector = new AdaptableX509CertSelector(); X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); // check the validity period selector.setValidityPeriod(firstCert.getNotBefore(), firstCert.getNotAfter()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. */ try { X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); selector.parseAuthorityKeyIdentifierExtension( firstCertImpl.getAuthorityKeyIdentifierExtension()); } catch (CertificateException | IOException e) { // ignore } } CertPathValidatorException lastException = null; // We iterate through the set of trust anchors until we find // one that works at which time we stop iterating for (TrustAnchor anchor : params.trustAnchors()) { X509Certificate trustedCert = anchor.getTrustedCert(); if (trustedCert != null) { // if this trust anchor is not worth trying, // we move on to the next one if (selector != null && !selector.match(trustedCert)) { if (debug != null) { debug.println("NO - don't try this trustedCert"); } continue; } if (debug != null) { debug.println("YES - try this trustedCert"); debug.println("anchor.getTrustedCert()." + "getSubjectX500Principal() = " + trustedCert.getSubjectX500Principal()); } } else { if (debug != null) { debug.println("PKIXCertPathValidator.engineValidate(): " + "anchor.getTrustedCert() == null"); } } try { return validate(anchor, params); } catch (CertPathValidatorException cpe) { // remember this exception lastException = cpe; } } // could not find a trust anchor that verified // (a) if we did a validation and it failed, use that exception if (lastException != null) { throw lastException; } // (b) otherwise, generate new exception throw new CertPathValidatorException ("Path does not chain with any of the trust anchors", null, null, -1, PKIXReason.NO_TRUST_ANCHOR); }
Example 13
Source File: PKIXCertPathValidator.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static PKIXCertPathValidatorResult validate(ValidatorParams params) throws CertPathValidatorException { if (debug != null) debug.println("PKIXCertPathValidator.engineValidate()..."); // Retrieve the first certificate in the certpath // (to be used later in pre-screening) AdaptableX509CertSelector selector = null; List<X509Certificate> certList = params.certificates(); if (!certList.isEmpty()) { selector = new AdaptableX509CertSelector(); X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); // check the validity period selector.setValidityPeriod(firstCert.getNotBefore(), firstCert.getNotAfter()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. */ try { X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); selector.parseAuthorityKeyIdentifierExtension( firstCertImpl.getAuthorityKeyIdentifierExtension()); } catch (CertificateException | IOException e) { // ignore } } CertPathValidatorException lastException = null; // We iterate through the set of trust anchors until we find // one that works at which time we stop iterating for (TrustAnchor anchor : params.trustAnchors()) { X509Certificate trustedCert = anchor.getTrustedCert(); if (trustedCert != null) { // if this trust anchor is not worth trying, // we move on to the next one if (selector != null && !selector.match(trustedCert)) { if (debug != null) { debug.println("NO - don't try this trustedCert"); } continue; } if (debug != null) { debug.println("YES - try this trustedCert"); debug.println("anchor.getTrustedCert()." + "getSubjectX500Principal() = " + trustedCert.getSubjectX500Principal()); } } else { if (debug != null) { debug.println("PKIXCertPathValidator.engineValidate(): " + "anchor.getTrustedCert() == null"); } } try { return validate(anchor, params); } catch (CertPathValidatorException cpe) { // remember this exception lastException = cpe; } } // could not find a trust anchor that verified // (a) if we did a validation and it failed, use that exception if (lastException != null) { throw lastException; } // (b) otherwise, generate new exception throw new CertPathValidatorException ("Path does not chain with any of the trust anchors", null, null, -1, PKIXReason.NO_TRUST_ANCHOR); }
Example 14
Source File: ForwardState.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Update the state with the next certificate added to the path. * * @param cert the certificate which is used to update the state */ @Override public void updateState(X509Certificate cert) throws CertificateException, IOException, CertPathValidatorException { if (cert == null) return; X509CertImpl icert = X509CertImpl.toImpl(cert); /* see if certificate key has null parameters */ if (PKIX.isDSAPublicKeyWithoutParams(icert.getPublicKey())) { keyParamsNeededFlag = true; } /* update certificate */ this.cert = icert; /* update issuer DN */ issuerDN = cert.getIssuerX500Principal(); if (!X509CertImpl.isSelfIssued(cert)) { /* * update traversedCACerts only if this is a non-self-issued * intermediate CA cert */ if (!init && cert.getBasicConstraints() != -1) { traversedCACerts++; } } /* update subjectNamesTraversed only if this is the EE cert or if this cert is not self-issued */ if (init || !X509CertImpl.isSelfIssued(cert)){ X500Principal subjName = cert.getSubjectX500Principal(); subjectNamesTraversed.add(X500Name.asX500Name(subjName)); try { SubjectAlternativeNameExtension subjAltNameExt = icert.getSubjectAlternativeNameExtension(); if (subjAltNameExt != null) { GeneralNames gNames = subjAltNameExt.get( SubjectAlternativeNameExtension.SUBJECT_NAME); for (GeneralName gName : gNames.names()) { subjectNamesTraversed.add(gName.getName()); } } } catch (IOException e) { if (debug != null) { debug.println("ForwardState.updateState() unexpected " + "exception"); e.printStackTrace(); } throw new CertPathValidatorException(e); } } init = false; }
Example 15
Source File: PKIXCertPathValidator.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private static PKIXCertPathValidatorResult validate(ValidatorParams params) throws CertPathValidatorException { if (debug != null) debug.println("PKIXCertPathValidator.engineValidate()..."); // Retrieve the first certificate in the certpath // (to be used later in pre-screening) AdaptableX509CertSelector selector = null; List<X509Certificate> certList = params.certificates(); if (!certList.isEmpty()) { selector = new AdaptableX509CertSelector(); X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. */ try { X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); selector.setSkiAndSerialNumber( firstCertImpl.getAuthorityKeyIdentifierExtension()); } catch (CertificateException | IOException e) { // ignore } } CertPathValidatorException lastException = null; // We iterate through the set of trust anchors until we find // one that works at which time we stop iterating for (TrustAnchor anchor : params.trustAnchors()) { X509Certificate trustedCert = anchor.getTrustedCert(); if (trustedCert != null) { // if this trust anchor is not worth trying, // we move on to the next one if (selector != null && !selector.match(trustedCert)) { if (debug != null) { debug.println("NO - don't try this trustedCert"); } continue; } if (debug != null) { debug.println("YES - try this trustedCert"); debug.println("anchor.getTrustedCert()." + "getSubjectX500Principal() = " + trustedCert.getSubjectX500Principal()); } } else { if (debug != null) { debug.println("PKIXCertPathValidator.engineValidate(): " + "anchor.getTrustedCert() == null"); } } try { return validate(anchor, params); } catch (CertPathValidatorException cpe) { // remember this exception lastException = cpe; } } // could not find a trust anchor that verified // (a) if we did a validation and it failed, use that exception if (lastException != null) { throw lastException; } // (b) otherwise, generate new exception throw new CertPathValidatorException ("Path does not chain with any of the trust anchors", null, null, -1, PKIXReason.NO_TRUST_ANCHOR); }
Example 16
Source File: PKIXCertPathValidator.java From hottub with GNU General Public License v2.0 | 4 votes |
private static PKIXCertPathValidatorResult validate(ValidatorParams params) throws CertPathValidatorException { if (debug != null) debug.println("PKIXCertPathValidator.engineValidate()..."); // Retrieve the first certificate in the certpath // (to be used later in pre-screening) AdaptableX509CertSelector selector = null; List<X509Certificate> certList = params.certificates(); if (!certList.isEmpty()) { selector = new AdaptableX509CertSelector(); X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. */ try { X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); selector.setSkiAndSerialNumber( firstCertImpl.getAuthorityKeyIdentifierExtension()); } catch (CertificateException | IOException e) { // ignore } } CertPathValidatorException lastException = null; // We iterate through the set of trust anchors until we find // one that works at which time we stop iterating for (TrustAnchor anchor : params.trustAnchors()) { X509Certificate trustedCert = anchor.getTrustedCert(); if (trustedCert != null) { // if this trust anchor is not worth trying, // we move on to the next one if (selector != null && !selector.match(trustedCert)) { if (debug != null) { debug.println("NO - don't try this trustedCert"); } continue; } if (debug != null) { debug.println("YES - try this trustedCert"); debug.println("anchor.getTrustedCert()." + "getSubjectX500Principal() = " + trustedCert.getSubjectX500Principal()); } } else { if (debug != null) { debug.println("PKIXCertPathValidator.engineValidate(): " + "anchor.getTrustedCert() == null"); } } try { return validate(anchor, params); } catch (CertPathValidatorException cpe) { // remember this exception lastException = cpe; } } // could not find a trust anchor that verified // (a) if we did a validation and it failed, use that exception if (lastException != null) { throw lastException; } // (b) otherwise, generate new exception throw new CertPathValidatorException ("Path does not chain with any of the trust anchors", null, null, -1, PKIXReason.NO_TRUST_ANCHOR); }
Example 17
Source File: PKIXCertPathValidator.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static PKIXCertPathValidatorResult validate(ValidatorParams params) throws CertPathValidatorException { if (debug != null) debug.println("PKIXCertPathValidator.engineValidate()..."); // Retrieve the first certificate in the certpath // (to be used later in pre-screening) AdaptableX509CertSelector selector = null; List<X509Certificate> certList = params.certificates(); if (!certList.isEmpty()) { selector = new AdaptableX509CertSelector(); X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. */ try { X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); selector.setSkiAndSerialNumber( firstCertImpl.getAuthorityKeyIdentifierExtension()); } catch (CertificateException | IOException e) { // ignore } } CertPathValidatorException lastException = null; // We iterate through the set of trust anchors until we find // one that works at which time we stop iterating for (TrustAnchor anchor : params.trustAnchors()) { X509Certificate trustedCert = anchor.getTrustedCert(); if (trustedCert != null) { // if this trust anchor is not worth trying, // we move on to the next one if (selector != null && !selector.match(trustedCert)) { if (debug != null) { debug.println("NO - don't try this trustedCert"); } continue; } if (debug != null) { debug.println("YES - try this trustedCert"); debug.println("anchor.getTrustedCert()." + "getSubjectX500Principal() = " + trustedCert.getSubjectX500Principal()); } } else { if (debug != null) { debug.println("PKIXCertPathValidator.engineValidate(): " + "anchor.getTrustedCert() == null"); } } try { return validate(anchor, params); } catch (CertPathValidatorException cpe) { // remember this exception lastException = cpe; } } // could not find a trust anchor that verified // (a) if we did a validation and it failed, use that exception if (lastException != null) { throw lastException; } // (b) otherwise, generate new exception throw new CertPathValidatorException ("Path does not chain with any of the trust anchors", null, null, -1, PKIXReason.NO_TRUST_ANCHOR); }
Example 18
Source File: PolicyChecker.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Internal method to run through all the checks. * * @param currCert the certificate to be processed * @exception CertPathValidatorException Exception thrown if * the certificate does not verify */ private void checkPolicy(X509Certificate currCert) throws CertPathValidatorException { String msg = "certificate policies"; if (debug != null) { debug.println("PolicyChecker.checkPolicy() ---checking " + msg + "..."); debug.println("PolicyChecker.checkPolicy() certIndex = " + certIndex); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "explicitPolicy = " + explicitPolicy); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "policyMapping = " + policyMapping); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "inhibitAnyPolicy = " + inhibitAnyPolicy); debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: " + "policyTree = " + rootNode); } X509CertImpl currCertImpl = null; try { currCertImpl = X509CertImpl.toImpl(currCert); } catch (CertificateException ce) { throw new CertPathValidatorException(ce); } boolean finalCert = (certIndex == certPathLen); rootNode = processPolicies(certIndex, initPolicies, explicitPolicy, policyMapping, inhibitAnyPolicy, rejectPolicyQualifiers, rootNode, currCertImpl, finalCert); if (!finalCert) { explicitPolicy = mergeExplicitPolicy(explicitPolicy, currCertImpl, finalCert); policyMapping = mergePolicyMapping(policyMapping, currCertImpl); inhibitAnyPolicy = mergeInhibitAnyPolicy(inhibitAnyPolicy, currCertImpl); } certIndex++; if (debug != null) { debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "explicitPolicy = " + explicitPolicy); debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "policyMapping = " + policyMapping); debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "inhibitAnyPolicy = " + inhibitAnyPolicy); debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: " + "policyTree = " + rootNode); debug.println("PolicyChecker.checkPolicy() " + msg + " verified"); } }
Example 19
Source File: PKIXCertPathValidator.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static PKIXCertPathValidatorResult validate(ValidatorParams params) throws CertPathValidatorException { if (debug != null) debug.println("PKIXCertPathValidator.engineValidate()..."); // Retrieve the first certificate in the certpath // (to be used later in pre-screening) AdaptableX509CertSelector selector = null; List<X509Certificate> certList = params.certificates(); if (!certList.isEmpty()) { selector = new AdaptableX509CertSelector(); X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. */ try { X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); selector.setSkiAndSerialNumber( firstCertImpl.getAuthorityKeyIdentifierExtension()); } catch (CertificateException | IOException e) { // ignore } } CertPathValidatorException lastException = null; // We iterate through the set of trust anchors until we find // one that works at which time we stop iterating for (TrustAnchor anchor : params.trustAnchors()) { X509Certificate trustedCert = anchor.getTrustedCert(); if (trustedCert != null) { // if this trust anchor is not worth trying, // we move on to the next one if (selector != null && !selector.match(trustedCert)) { if (debug != null) { debug.println("NO - don't try this trustedCert"); } continue; } if (debug != null) { debug.println("YES - try this trustedCert"); debug.println("anchor.getTrustedCert()." + "getSubjectX500Principal() = " + trustedCert.getSubjectX500Principal()); } } else { if (debug != null) { debug.println("PKIXCertPathValidator.engineValidate(): " + "anchor.getTrustedCert() == null"); } } try { return validate(anchor, params); } catch (CertPathValidatorException cpe) { // remember this exception lastException = cpe; } } // could not find a trust anchor that verified // (a) if we did a validation and it failed, use that exception if (lastException != null) { throw lastException; } // (b) otherwise, generate new exception throw new CertPathValidatorException ("Path does not chain with any of the trust anchors", null, null, -1, PKIXReason.NO_TRUST_ANCHOR); }
Example 20
Source File: ConstraintsChecker.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Helper to fold sets of name constraints together */ static NameConstraintsExtension mergeNameConstraints( X509Certificate currCert, NameConstraintsExtension prevNC) throws CertPathValidatorException { X509CertImpl currCertImpl; try { currCertImpl = X509CertImpl.toImpl(currCert); } catch (CertificateException ce) { throw new CertPathValidatorException(ce); } NameConstraintsExtension newConstraints = currCertImpl.getNameConstraintsExtension(); if (debug != null) { debug.println("prevNC = " + prevNC + ", newNC = " + String.valueOf(newConstraints)); } // if there are no previous name constraints, we just return the // new name constraints. if (prevNC == null) { if (debug != null) { debug.println("mergedNC = " + String.valueOf(newConstraints)); } if (newConstraints == null) { return newConstraints; } else { // Make sure we do a clone here, because we're probably // going to modify this object later and we don't want to // be sharing it with a Certificate object! return (NameConstraintsExtension)newConstraints.clone(); } } else { try { // after merge, prevNC should contain the merged constraints prevNC.merge(newConstraints); } catch (IOException ioe) { throw new CertPathValidatorException(ioe); } if (debug != null) { debug.println("mergedNC = " + prevNC); } return prevNC; } }