Search in sources :

Example 1 with PolicyProcessException

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

the class MessageSigInspector method getObject.

protected static DERObject getObject(byte[] ext) throws PolicyProcessException {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        ASN1OctetString octs = (ASN1OctetString) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(octs.getOctets());
        return aIn.readObject();
    } catch (Exception e) {
        throw new PolicyProcessException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) CMSException(org.bouncycastle.cms.CMSException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Example 2 with PolicyProcessException

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

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered() throws Exception {
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyProcessException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
    final PolicyExpression expression = mock(PolicyExpression.class);
    final X509Certificate cert = mock(X509Certificate.class);
    final Collection<X509Certificate> certs = Arrays.asList(cert);
    final PolicyResolver resolver = mock(PolicyResolver.class);
    when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
    agent.setPolicyFilter(filter);
    boolean exceptionOccured = false;
    try {
        agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
    } catch (AgentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) X509Certificate(java.security.cert.X509Certificate)

Example 3 with PolicyProcessException

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

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyExpressionError_assertExecption.

public void testIsCertPolicyCompliant_policyExpressionError_assertExecption() throws Exception {
    final TrustModel model = new TrustModel();
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyProcessException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
    final PolicyResolver resolver = mock(PolicyResolver.class);
    final PolicyExpression expression = mock(PolicyExpression.class);
    when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
    model.setTrustPolicyResolver(resolver);
    model.setPolicyFilter(filter);
    final X509Certificate cert = mock(X509Certificate.class);
    boolean exceptionOccured = false;
    try {
        model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert);
    } catch (AgentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) AgentException(org.nhindirect.stagent.AgentException) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) X509Certificate(java.security.cert.X509Certificate)

Example 4 with PolicyProcessException

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

the class AbstractX509Field method getObject.

/**
	 * Converts an encoded internal octet string object to a DERObject
	 * @param ext The encoded octet string as a byte array
	 * @return The converted DERObject
	 * @throws PolicyProcessException
	 */
protected DERObject getObject(byte[] ext) throws PolicyProcessException {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        ASN1OctetString octs = (ASN1OctetString) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(octs.getOctets());
        return aIn.readObject();
    } catch (Exception e) {
        throw new PolicyProcessException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Example 5 with PolicyProcessException

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

the class AbstractX509Field method getDERObject.

/**
	 * Converts an encoded internal sequence object to a DERObject
	 * @param ext The encoded sequence as a byte array
	 * @return The converted DERObject
	 * @throws PolicyProcessException
	 */
protected DERObject getDERObject(byte[] ext) throws PolicyProcessException {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        DERSequence seq = (DERSequence) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(seq.getDEREncoded());
        return aIn.readObject();
    } catch (Exception e) {
        throw new PolicyProcessException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERSequence(org.bouncycastle.asn1.DERSequence) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Aggregations

PolicyProcessException (org.nhindirect.policy.PolicyProcessException)12 X509Certificate (java.security.cert.X509Certificate)4 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 PolicyExpression (org.nhindirect.policy.PolicyExpression)3 InternetAddress (javax.mail.internet.InternetAddress)2 DERObject (org.bouncycastle.asn1.DERObject)2 TBSCertificateStructure (org.bouncycastle.asn1.x509.TBSCertificateStructure)2 PolicyFilter (org.nhindirect.policy.PolicyFilter)2 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)2 StackMachine (org.nhindirect.policy.impl.machine.StackMachine)2 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)2 ArrayList (java.util.ArrayList)1 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)1 DERSequence (org.bouncycastle.asn1.DERSequence)1 X509Name (org.bouncycastle.asn1.x509.X509Name)1 CMSException (org.bouncycastle.cms.CMSException)1 AuthorityInfoAccessExtentionField (org.nhindirect.policy.x509.AuthorityInfoAccessExtentionField)1 AgentException (org.nhindirect.stagent.AgentException)1 NHINDException (org.nhindirect.stagent.NHINDException)1