Search in sources :

Example 86 with DERObject

use of org.bouncycastle.asn1.DERObject 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 87 with DERObject

use of org.bouncycastle.asn1.DERObject 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

ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)47 DERSequence (org.bouncycastle.asn1.DERSequence)42 DERObject (org.bouncycastle.asn1.DERObject)31 IOException (java.io.IOException)15 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)15 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)13 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)12 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)12 DERInteger (org.bouncycastle.asn1.DERInteger)11 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)10 ArrayList (java.util.ArrayList)8 DEREncodable (org.bouncycastle.asn1.DEREncodable)8 DEROctetString (org.bouncycastle.asn1.DEROctetString)8 DERBitString (org.bouncycastle.asn1.DERBitString)7 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)7 GeneralSecurityException (java.security.GeneralSecurityException)5 CertPathValidatorException (java.security.cert.CertPathValidatorException)5 Enumeration (java.util.Enumeration)5 BERSequence (org.bouncycastle.asn1.BERSequence)5 PolicyProcessException (org.nhindirect.policy.PolicyProcessException)5