Search in sources :

Example 11 with PolicyInformation

use of sun.security.x509.PolicyInformation in project jdk8u_jdk by JetBrains.

the class PolicyChecker method removeInvalidNodes.

/**
     * Removes those nodes which do not intersect with the initial policies
     * specified by the user.
     *
     * @param rootNode the root node of the valid policy tree
     * @param certIndex the index of the certificate being processed
     * @param initPolicies the Set of policies required by the user
     * @param currCertPolicies the CertificatePoliciesExtension of the
     * certificate being processed
     * @returns the root node of the valid policy tree after modification
     * @exception CertPathValidatorException Exception thrown if error occurs.
     */
private static PolicyNodeImpl removeInvalidNodes(PolicyNodeImpl rootNode, int certIndex, Set<String> initPolicies, CertificatePoliciesExtension currCertPolicies) throws CertPathValidatorException {
    List<PolicyInformation> policyInfo = null;
    try {
        policyInfo = currCertPolicies.get(CertificatePoliciesExtension.POLICIES);
    } catch (IOException ioe) {
        throw new CertPathValidatorException("Exception while " + "retrieving policyOIDs", ioe);
    }
    boolean childDeleted = false;
    for (PolicyInformation curPolInfo : policyInfo) {
        String curPolicy = curPolInfo.getPolicyIdentifier().getIdentifier().toString();
        if (debug != null)
            debug.println("PolicyChecker.processPolicies() " + "processing policy second time: " + curPolicy);
        Set<PolicyNodeImpl> validNodes = rootNode.getPolicyNodesValid(certIndex, curPolicy);
        for (PolicyNodeImpl curNode : validNodes) {
            PolicyNodeImpl parentNode = (PolicyNodeImpl) curNode.getParent();
            if (parentNode.getValidPolicy().equals(ANY_POLICY)) {
                if ((!initPolicies.contains(curPolicy)) && (!curPolicy.equals(ANY_POLICY))) {
                    if (debug != null)
                        debug.println("PolicyChecker.processPolicies() " + "before deleting: policy tree = " + rootNode);
                    parentNode.deleteChild(curNode);
                    childDeleted = true;
                    if (debug != null)
                        debug.println("PolicyChecker.processPolicies() " + "after deleting: policy tree = " + rootNode);
                }
            }
        }
    }
    if (childDeleted) {
        rootNode.prune(certIndex);
        if (!rootNode.getChildren().hasNext()) {
            rootNode = null;
        }
    }
    return rootNode;
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) PolicyInformation(sun.security.x509.PolicyInformation) IOException(java.io.IOException)

Example 12 with PolicyInformation

use of sun.security.x509.PolicyInformation in project nhin-d by DirectProject.

the class CertificatePolicyCpsUriExtensionField method injectReferenceValue.

/**
	 * {@inheritDoc}
	 */
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
    this.certificate = value;
    final DERObject exValue = getExtensionValue(value);
    if (exValue == null) {
        if (isRequired())
            throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
        else {
            final Collection<String> emptyList = Collections.emptyList();
            this.policyValue = PolicyValueFactory.getInstance(emptyList);
            return;
        }
    }
    final Collection<String> retVal = new ArrayList<String>();
    final ASN1Sequence seq = (ASN1Sequence) exValue;
    @SuppressWarnings("unchecked") final Enumeration<DEREncodable> pols = seq.getObjects();
    while (pols.hasMoreElements()) {
        final PolicyInformation pol = PolicyInformation.getInstance(pols.nextElement());
        if (pol.getPolicyQualifiers() != null) {
            @SuppressWarnings("unchecked") final Enumeration<DEREncodable> polInfos = pol.getPolicyQualifiers().getObjects();
            while (polInfos.hasMoreElements()) {
                final PolicyQualifierInfo polInfo = PolicyQualifierInfo.getInstance(polInfos.nextElement());
                if (polInfo.getPolicyQualifierId().equals(PolicyQualifierId.id_qt_cps)) {
                    retVal.add(polInfo.getQualifier().toString());
                }
            }
        }
    }
    ///CLOVER:OFF
    if (retVal.isEmpty() && isRequired())
        throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
    ///CLOVER:ON	
    this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) DEREncodable(org.bouncycastle.asn1.DEREncodable) ArrayList(java.util.ArrayList) PolicyQualifierInfo(org.bouncycastle.asn1.x509.PolicyQualifierInfo)

Example 13 with PolicyInformation

use of sun.security.x509.PolicyInformation in project nhin-d by DirectProject.

the class CertificatePolicyIndentifierExtensionField method injectReferenceValue.

/**
	 * {@inheritDoc}
	 */
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
    this.certificate = value;
    final DERObject exValue = getExtensionValue(value);
    if (exValue == null) {
        if (isRequired())
            throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
        else {
            final Collection<String> emptyList = Collections.emptyList();
            this.policyValue = PolicyValueFactory.getInstance(emptyList);
            return;
        }
    }
    final Collection<String> retVal = new ArrayList<String>();
    final ASN1Sequence seq = (ASN1Sequence) exValue;
    @SuppressWarnings("unchecked") final Enumeration<DEREncodable> pols = seq.getObjects();
    while (pols.hasMoreElements()) {
        final PolicyInformation pol = PolicyInformation.getInstance(pols.nextElement());
        retVal.add(pol.getPolicyIdentifier().getId());
    }
    this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) DEREncodable(org.bouncycastle.asn1.DEREncodable) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)8 CertPathValidatorException (java.security.cert.CertPathValidatorException)8 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)8 PolicyInformation (org.bouncycastle.asn1.x509.PolicyInformation)8 HashSet (java.util.HashSet)7 Enumeration (java.util.Enumeration)6 Iterator (java.util.Iterator)6 List (java.util.List)6 Set (java.util.Set)6 ExtCertPathValidatorException (org.bouncycastle.jce.exception.ExtCertPathValidatorException)6 GeneralSecurityException (java.security.GeneralSecurityException)4 X509Certificate (java.security.cert.X509Certificate)4 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)4 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)4 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)4 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)4 DERObject (org.bouncycastle.asn1.DERObject)3 PolicyInformation (sun.security.x509.PolicyInformation)3 CertPathBuilderException (java.security.cert.CertPathBuilderException)2