pkixcertpathvalidatorspi.java

来自「bouncycastle 是一个JAVA安全提供者」· Java 代码 · 共 1,907 行 · 第 1/5 页

JAVA
1,907
字号
                if ((_usage != null) && !_usage[5])                {                    throw new CertPathValidatorException(                                "Issuer certificate keyusage extension is critical an does not permit key signing.\n",                                null, certPath, index);                }                //                // (o)                //                Set criticalExtensions = new HashSet(cert.getCriticalExtensionOIDs());                // these extensions are handle by the algorithem                criticalExtensions.remove(KEY_USAGE);                criticalExtensions.remove(CERTIFICATE_POLICIES);                criticalExtensions.remove(POLICY_MAPPINGS);                criticalExtensions.remove(INHIBIT_ANY_POLICY);                criticalExtensions.remove(ISSUING_DISTRIBUTION_POINT);                criticalExtensions.remove(DELTA_CRL_INDICATOR);                criticalExtensions.remove(POLICY_CONSTRAINTS);                criticalExtensions.remove(BASIC_CONSTRAINTS);                criticalExtensions.remove(SUBJECT_ALTERNATIVE_NAME);                criticalExtensions.remove(NAME_CONSTRAINTS);                tmpIter = pathCheckers.iterator();                while (tmpIter.hasNext())                {                    try                    {                        ((PKIXCertPathChecker)tmpIter.next()).check(cert, criticalExtensions);                    }                    catch (CertPathValidatorException e)                    {                        throw new CertPathValidatorException(e.getMessage(), e.getCause(), certPath, index);                    }                }                if (!criticalExtensions.isEmpty())                {                    throw new CertPathValidatorException(                        "Certificate has unsupported critical extension", null, certPath, index);                }            }                // set signing certificate for next round            sign = cert;            workingPublicKey = sign.getPublicKey();            try            {                workingIssuerName = getSubjectPrincipal(sign);            }            catch (IllegalArgumentException ex)            {                throw new CertPathValidatorException(sign.getSubjectDN().getName() + " :" + ex.toString());            }            workingAlgId = getAlgorithmIdentifier(workingPublicKey);            workingPublicKeyAlgorithm = workingAlgId.getObjectId();            workingPublicKeyParameters = workingAlgId.getParameters();        }        //        // 6.1.5 Wrap-up procedure        //        //        // (a)        //        if (!isSelfIssued(cert) && (explicitPolicy != 0))        {            explicitPolicy--;        }            //        // (b)        //        ASN1Sequence pc = (ASN1Sequence)getExtensionValue(cert, POLICY_CONSTRAINTS);        if (pc != null)        {            Enumeration policyConstraints = pc.getObjects();            while (policyConstraints.hasMoreElements())            {                ASN1TaggedObject    constraint = (ASN1TaggedObject)policyConstraints.nextElement();                switch (constraint.getTagNo())                {                case 0:                    tmpInt = DERInteger.getInstance(constraint).getValue().intValue();                    if (tmpInt == 0)                    {                        explicitPolicy = 0;                    }                    break;                }            }        }            //        // (c) (d) and (e) are already done        //            //        // (f)         //        Set criticalExtensions = cert.getCriticalExtensionOIDs();                if (criticalExtensions != null)        {            criticalExtensions = new HashSet(criticalExtensions);            // these extensions are handle by the algorithm            criticalExtensions.remove(KEY_USAGE);            criticalExtensions.remove(CERTIFICATE_POLICIES);            criticalExtensions.remove(POLICY_MAPPINGS);            criticalExtensions.remove(INHIBIT_ANY_POLICY);            criticalExtensions.remove(ISSUING_DISTRIBUTION_POINT);            criticalExtensions.remove(DELTA_CRL_INDICATOR);            criticalExtensions.remove(POLICY_CONSTRAINTS);            criticalExtensions.remove(BASIC_CONSTRAINTS);            criticalExtensions.remove(SUBJECT_ALTERNATIVE_NAME);            criticalExtensions.remove(NAME_CONSTRAINTS);        }        else        {            criticalExtensions = new HashSet();        }                tmpIter = pathCheckers.iterator();        while (tmpIter.hasNext())        {            try            {                ((PKIXCertPathChecker)tmpIter.next()).check(cert, criticalExtensions);            }            catch (CertPathValidatorException e)            {                throw new CertPathValidatorException(e.getMessage(), e.getCause(), certPath, index);            }        }                if (!criticalExtensions.isEmpty())        {            throw new CertPathValidatorException(                "Certificate has unsupported critical extension", null, certPath, index);        }        //        // (g)        //        PKIXPolicyNode intersection;                //        // (g) (i)        //        if (validPolicyTree == null)        {             if (paramsPKIX.isExplicitPolicyRequired())            {                throw new CertPathValidatorException("Explicit policy requested but none available.");            }            intersection = null;        }        else if (isAnyPolicy(userInitialPolicySet)) // (g) (ii)        {            if (paramsPKIX.isExplicitPolicyRequired())            {                if (acceptablePolicies.isEmpty())                {                    throw new CertPathValidatorException("Explicit policy requested but none available.");                }                else                {                    Set _validPolicyNodeSet = new HashSet();                                        for (int j = 0; j < policyNodes.length; j++)                    {                        List      _nodeDepth = policyNodes[j];                                                for (int k = 0; k < _nodeDepth.size(); k++)                        {                            PKIXPolicyNode _node = (PKIXPolicyNode)_nodeDepth.get(k);                                                        if (ANY_POLICY.equals(_node.getValidPolicy()))                            {                                Iterator _iter = _node.getChildren();                                while (_iter.hasNext())                                {                                    _validPolicyNodeSet.add(_iter.next());                                }                            }                        }                    }                                        Iterator _vpnsIter = _validPolicyNodeSet.iterator();                    while (_vpnsIter.hasNext())                    {                        PKIXPolicyNode _node = (PKIXPolicyNode)_vpnsIter.next();                        String _validPolicy = _node.getValidPolicy();                                                if (!acceptablePolicies.contains(_validPolicy))                        {                            validPolicyTree = removePolicyNode(validPolicyTree, policyNodes, _node);                        }                    }                    if (validPolicyTree != null)                    {                        for (int j = (n - 1); j >= 0; j--)                        {                            List      nodes = policyNodes[j];                                                        for (int k = 0; k < nodes.size(); k++)                            {                                PKIXPolicyNode node = (PKIXPolicyNode)nodes.get(k);                                if (!node.hasChildren())                                {                                    validPolicyTree = removePolicyNode(validPolicyTree, policyNodes, node);                                }                            }                        }                    }                }            }            intersection = validPolicyTree;        }        else        {            //            // (g) (iii)            //            //            // (g) (iii) 1            //            Set _validPolicyNodeSet = new HashSet();                        for (int j = 0; j < policyNodes.length; j++)            {                List      _nodeDepth = policyNodes[j];                                for (int k = 0; k < _nodeDepth.size(); k++)                {                    PKIXPolicyNode _node = (PKIXPolicyNode)_nodeDepth.get(k);                                        if (ANY_POLICY.equals(_node.getValidPolicy()))                    {                        Iterator _iter = _node.getChildren();                        while (_iter.hasNext())                        {                            PKIXPolicyNode _c_node = (PKIXPolicyNode)_iter.next();                            if (!ANY_POLICY.equals(_c_node.getValidPolicy()))                            {                                _validPolicyNodeSet.add(_c_node);                            }                        }                    }                }            }                        //            // (g) (iii) 2            //            Iterator _vpnsIter = _validPolicyNodeSet.iterator();            while (_vpnsIter.hasNext())            {                PKIXPolicyNode _node = (PKIXPolicyNode)_vpnsIter.next();                String _validPolicy = _node.getValidPolicy();                if (!userInitialPolicySet.contains(_validPolicy))                {                    validPolicyTree = removePolicyNode(validPolicyTree, policyNodes, _node);                }            }                        //            // (g) (iii) 4            //            if (validPolicyTree != null)            {                for (int j = (n - 1); j >= 0; j--)                {                    List      nodes = policyNodes[j];                                        for (int k = 0; k < nodes.size(); k++)                    {                        PKIXPolicyNode node = (PKIXPolicyNode)nodes.get(k);                        if (!node.hasChildren())                        {                            validPolicyTree = removePolicyNode(validPolicyTree, policyNodes, node);                        }                    }                }            }                        intersection = validPolicyTree;        }         if ((explicitPolicy > 0) || (intersection != null))        {            return new PKIXCertPathValidatorResult(trust, intersection, workingPublicKey);        }        throw new CertPathValidatorException("Path processing failed on policy.", null, certPath, index);    }    /**     * Return a Collection of all CRLs found in the     * CertStore's that are matching the crlSelect criteriums.     *     * @param certSelector a {@link CertSelector CertSelector}     * object that will be used to select the certificates     * @param certStores a List containing only {@link CertStore     * CertStore} objects. These are used to search for     * CRLs     *     * @return a Collection of all found {@link CRL CRL}     * objects. May be empty but never <code>null</code>.     */    private final Collection findCRLs(        X509CRLSelector crlSelect,        List            crlStores)        throws CertPathValidatorException    {        Set crls = new HashSet();        Iterator iter = crlStores.iterator();        while (iter.hasNext())        {            CertStore   certStore = (CertStore)iter.next();            try            {                crls.addAll(certStore.getCRLs(crlSelect));            }            catch (CertStoreException ex)            {                throw new CertPathValidatorException(ex);            }        }        return crls;    }    /**     * Search the given Set of TrustAnchor's for one that is the     * issuer of the fiven X509 certificate.     *     * @param cert the X509 certificate     * @param trustAnchors a Set of TrustAnchor's     *     * @return the <code>TrustAnchor</code> object if found or     * <code>null</code> if not.     *     * @exception CertPathValidatorException if a TrustAnchor  was     * found but the signature verification on the given certificate     * has thrown an exception. This Exception can be obtainted with     * <code>getCause()</code> method.     **/    final TrustAnchor findTrustAnchor(        X509Certificate cert,        CertPath        certPath,        int             index,        Set             trustAnchors)         throws CertPathValidatorException    {        Iterator iter = trustAnchors.iterator();        TrustAnchor trust = null;        PublicKey trustPublicKey = null;        Exception invalidKeyEx = null;        X509CertSelector certSelectX509 = new X509CertSelector();        try        {            certSelectX509.setSubject(getEncodedIssuerPrincipal(cert).getEncoded());        }        catch (IOException ex)        {            throw new CertPathValidatorException(ex);        }        while

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?