Search in sources :

Example 6 with PolicyRequiredException

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

the class CRLDistributionPointNameExtentionField 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> coll = Collections.emptyList();
            this.policyValue = PolicyValueFactory.getInstance(coll);
            return;
        }
    }
    final CRLDistPoint distPoints = CRLDistPoint.getInstance(exValue);
    final Collection<String> retVal = new ArrayList<String>();
    for (DistributionPoint distPoint : distPoints.getDistributionPoints()) {
        if (distPoint.getDistributionPoint() != null && distPoint.getDistributionPoint().getType() == DistributionPointName.FULL_NAME) {
            final GeneralNames names = GeneralNames.getInstance(distPoint.getDistributionPoint().getName());
            for (GeneralName name : names.getNames()) {
                retVal.add(name.getName().toString());
            }
        }
    }
    if (retVal.isEmpty() && isRequired())
        throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
    this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) ArrayList(java.util.ArrayList) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) GeneralName(org.bouncycastle.asn1.x509.GeneralName) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint)

Example 7 with PolicyRequiredException

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

the class ExtendedKeyUsageExtensionField 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 ExtendedKeyUsage usages = ExtendedKeyUsage.getInstance(exValue);
    @SuppressWarnings("unchecked") final Collection<DERObjectIdentifier> purposeList = usages.getUsages();
    final Collection<String> usageList = new ArrayList<String>();
    for (DERObjectIdentifier purpose : purposeList) usageList.add(purpose.getId());
    this.policyValue = PolicyValueFactory.getInstance(usageList);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) ArrayList(java.util.ArrayList) ExtendedKeyUsage(org.bouncycastle.asn1.x509.ExtendedKeyUsage) DERObjectIdentifier(org.bouncycastle.asn1.DERObjectIdentifier)

Example 8 with PolicyRequiredException

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

the class KeyUsageExtensionField 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(0);
            return;
        }
    }
    final KeyUsage keyUsage = new KeyUsage((DERBitString) exValue);
    final byte[] data = keyUsage.getBytes();
    final int intValue = (data.length == 1) ? data[0] & 0xff : (data[1] & 0xff) << 8 | (data[0] & 0xff);
    this.policyValue = PolicyValueFactory.getInstance(intValue);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) KeyUsage(org.bouncycastle.asn1.x509.KeyUsage)

Example 9 with PolicyRequiredException

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

the class SubjectKeyIdentifierExtensionField 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("");
            return;
        }
    }
    final SubjectKeyIdentifier keyId = SubjectKeyIdentifier.getInstance(exValue);
    keyId.getKeyIdentifier();
    this.policyValue = PolicyValueFactory.getInstance(PolicyUtils.createByteStringRep(keyId.getKeyIdentifier()));
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) SubjectKeyIdentifier(org.bouncycastle.asn1.x509.SubjectKeyIdentifier)

Example 10 with PolicyRequiredException

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

the class CertificatePolicyCpsUriExtensionField_injectReferenceValueTest method testInjectRefereneValue_policyQualUriNotExist_required_assertException.

public void testInjectRefereneValue_policyQualUriNotExist_required_assertException() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
    final CertificatePolicyCpsUriExtensionField field = new CertificatePolicyCpsUriExtensionField(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) CertificatePolicyCpsUriExtensionField(org.nhindirect.policy.x509.CertificatePolicyCpsUriExtensionField)

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