Search in sources :

Example 26 with PolicyRequiredException

use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.

the class BasicContraintsExtensionField 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 {
            this.policyValue = PolicyValueFactory.getInstance(false);
            return;
        }
    }
    final BasicConstraints constraints = BasicConstraints.getInstance(exValue);
    this.policyValue = PolicyValueFactory.getInstance(constraints.isCA());
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) BasicConstraints(org.bouncycastle.asn1.x509.BasicConstraints)

Example 27 with PolicyRequiredException

use of org.nhindirect.policy.PolicyRequiredException 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 28 with PolicyRequiredException

use of org.nhindirect.policy.PolicyRequiredException 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)

Example 29 with PolicyRequiredException

use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.

the class SubjectAltNameExtensionField_injectReferenceValueTest method testInjectRefereneValue_subjectAltNameDoesNotExist_required_assertException.

public void testInjectRefereneValue_subjectAltNameDoesNotExist_required_assertException() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("dsa1024.der");
    final SubjectAltNameExtensionField field = new SubjectAltNameExtensionField(true);
    boolean exceptionOccured = false;
    try {
        field.injectReferenceValue(cert);
    } catch (PolicyRequiredException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) X509Certificate(java.security.cert.X509Certificate)

Example 30 with PolicyRequiredException

use of org.nhindirect.policy.PolicyRequiredException in project nhin-d by DirectProject.

the class SubjectAttributeField_injectReferenceValueTest method testInjectRefereneValue_rdnAttributeDoesNotExist_required_throwException.

public void testInjectRefereneValue_rdnAttributeDoesNotExist_required_throwException() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
    final SubjectAttributeField field = new SubjectAttributeField(true, RDNAttributeIdentifier.INITIALS);
    boolean exceptionOccured = false;
    try {
        field.injectReferenceValue(cert);
    } catch (PolicyRequiredException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) SubjectAttributeField(org.nhindirect.policy.x509.SubjectAttributeField) X509Certificate(java.security.cert.X509Certificate)

Aggregations

PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)31 X509Certificate (java.security.cert.X509Certificate)19 DERObject (org.bouncycastle.asn1.DERObject)12 ArrayList (java.util.ArrayList)7 PolicyExpression (org.nhindirect.policy.PolicyExpression)4 PolicyFilter (org.nhindirect.policy.PolicyFilter)3 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)3 InternetAddress (javax.mail.internet.InternetAddress)2 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)2 DEREncodable (org.bouncycastle.asn1.DEREncodable)2 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)2 AccessDescription (org.bouncycastle.asn1.x509.AccessDescription)2 AuthorityInformationAccess (org.bouncycastle.asn1.x509.AuthorityInformationAccess)2 GeneralName (org.bouncycastle.asn1.x509.GeneralName)2 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)2 PolicyInformation (org.bouncycastle.asn1.x509.PolicyInformation)2 PolicyProcessException (org.nhindirect.policy.PolicyProcessException)2 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1