Search in sources :

Example 1 with PolicyRequiredException

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

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_missingRequiredField_assertFalse.

public void testIsCertPolicyCompliant_missingRequiredField_assertFalse() throws Exception {
    final TrustModel model = new TrustModel();
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyRequiredException("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);
    assertFalse(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) X509Certificate(java.security.cert.X509Certificate)

Example 2 with PolicyRequiredException

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

the class AuthorityInfoAccessOCSPLocExtentionField 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 AuthorityInformationAccess aia = AuthorityInformationAccess.getInstance(exValue);
    final Collection<String> retVal = new ArrayList<String>();
    for (AccessDescription accessDescription : aia.getAccessDescriptions()) {
        if (accessDescription.getAccessMethod().equals(AccessDescription.id_ad_ocsp))
            retVal.add(accessDescription.getAccessLocation().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) AuthorityInformationAccess(org.bouncycastle.asn1.x509.AuthorityInformationAccess) DERObject(org.bouncycastle.asn1.DERObject) AccessDescription(org.bouncycastle.asn1.x509.AccessDescription) ArrayList(java.util.ArrayList)

Example 3 with PolicyRequiredException

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

the class StackMachine_getCompilationReportTest method testGetCompilationReportTest_switchModes_assertCorrectReportSize.

public void testGetCompilationReportTest_switchModes_assertCorrectReportSize() throws Exception {
    final X509Certificate cert1 = TestUtils.loadCertificate("umesh.der");
    KeyUsageExtensionField keyExtendExp = new KeyUsageExtensionField(true);
    final StackMachineCompiler machine = new StackMachineCompiler();
    machine.setReportModeEnabled(true);
    assertTrue(machine.isReportModeEnabled());
    machine.compile(cert1, keyExtendExp);
    assertEquals(1, machine.getCompilationReport().size());
    // turn off report mode and make sure the report is empty
    keyExtendExp = new KeyUsageExtensionField(true);
    machine.setReportModeEnabled(false);
    assertFalse(machine.isReportModeEnabled());
    boolean exceptionOccured = false;
    try {
        machine.compile(cert1, keyExtendExp);
    } catch (PolicyRequiredException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    assertTrue(machine.getCompilationReport().isEmpty());
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) KeyUsageExtensionField(org.nhindirect.policy.x509.KeyUsageExtensionField) X509Certificate(java.security.cert.X509Certificate)

Example 4 with PolicyRequiredException

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

the class StackMachine_getCompilationReportTest method testGetCompilationReportTest_missingRequiredField_reportModeOff_assertEmptyCollection.

public void testGetCompilationReportTest_missingRequiredField_reportModeOff_assertEmptyCollection() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("umesh.der");
    final KeyUsageExtensionField keyExtendExp = new KeyUsageExtensionField(true);
    final StackMachineCompiler machine = new StackMachineCompiler();
    machine.setReportModeEnabled(false);
    assertFalse(machine.isReportModeEnabled());
    boolean exceptionOccured = false;
    try {
        machine.compile(cert, keyExtendExp);
    } catch (PolicyRequiredException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    assertTrue(machine.getCompilationReport().isEmpty());
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) KeyUsageExtensionField(org.nhindirect.policy.x509.KeyUsageExtensionField) X509Certificate(java.security.cert.X509Certificate)

Example 5 with PolicyRequiredException

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

the class AuthorityKeyIdentifierKeyIdExtensionField_injectReferenceValueTest method testInjectRefereneValue_keyIdDoesNotExist_required_assertException.

public void testInjectRefereneValue_keyIdDoesNotExist_required_assertException() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("cernerDemosCaCert.der");
    final AuthorityKeyIdentifierKeyIdExtensionField field = new AuthorityKeyIdentifierKeyIdExtensionField(true);
    boolean exceptionOccured = false;
    try {
        field.injectReferenceValue(cert);
    } catch (PolicyRequiredException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) AuthorityKeyIdentifierKeyIdExtensionField(org.nhindirect.policy.x509.AuthorityKeyIdentifierKeyIdExtensionField) 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