Search in sources :

Example 1 with AuthorityInfoAccessExtentionField

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

the class AuthorityInfoAccessExtentionField_injectReferenceValueTest method testInjectRefereneValue_aiaExists_assertValue.

public void testInjectRefereneValue_aiaExists_assertValue() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("CernerDirectProviderCA.der");
    final AuthorityInfoAccessExtentionField field = new AuthorityInfoAccessExtentionField(false);
    field.injectReferenceValue(cert);
    Collection<String> usages = field.getPolicyValue().getPolicyValue();
    assertFalse(field.getPolicyValue().getPolicyValue().isEmpty());
    assertTrue(usages.contains(AuthorityInfoAccessMethodIdentifier.OCSP.getName() + ":" + "http://ca.cerner.com/OCSP"));
    assertTrue(usages.contains(AuthorityInfoAccessMethodIdentifier.CA_ISSUERS.getName() + ":" + "http://ca.cerner.com/public/root.der"));
}
Also used : AuthorityInfoAccessExtentionField(org.nhindirect.policy.x509.AuthorityInfoAccessExtentionField) X509Certificate(java.security.cert.X509Certificate)

Example 2 with AuthorityInfoAccessExtentionField

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

the class AuthorityInfoAccessExtentionField_injectReferenceValueTest method testInjectRefereneValue_noInjection_getPolicyValue_assertException.

public void testInjectRefereneValue_noInjection_getPolicyValue_assertException() throws Exception {
    final AuthorityInfoAccessExtentionField field = new AuthorityInfoAccessExtentionField(true);
    boolean exceptionOccured = false;
    try {
        field.getPolicyValue();
    } catch (IllegalStateException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : AuthorityInfoAccessExtentionField(org.nhindirect.policy.x509.AuthorityInfoAccessExtentionField)

Example 3 with AuthorityInfoAccessExtentionField

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

the class AuthorityInfoAccessExtentionField_injectReferenceValueTest method testInjectRefereneValue_aiaDoesNotExist_notRequired_assertValueEmpty.

public void testInjectRefereneValue_aiaDoesNotExist_notRequired_assertValueEmpty() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
    final AuthorityInfoAccessExtentionField field = new AuthorityInfoAccessExtentionField(false);
    field.injectReferenceValue(cert);
    assertTrue(field.getPolicyValue().getPolicyValue().isEmpty());
}
Also used : AuthorityInfoAccessExtentionField(org.nhindirect.policy.x509.AuthorityInfoAccessExtentionField) X509Certificate(java.security.cert.X509Certificate)

Example 4 with AuthorityInfoAccessExtentionField

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

the class AuthorityInfoAccessExtentionField_injectReferenceValueTest method testInjectRefereneValue_aiaDoesNotExist_required_assertException.

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

Example 5 with AuthorityInfoAccessExtentionField

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

the class TrustChainValidator method getIntermediateCertsByAIA.

/**
     * Retrieves intermediate certificate using the AIA extension.
     * @param certificate The certificate to search for AIA extensions.
     * @return Returns a collection of intermediate certs using the AIA extension.  If the AIA extension does not exists
     * or the certificate cannot be downloaded from the URL, then an empty list is returned.
     */
protected Collection<X509Certificate> getIntermediateCertsByAIA(X509Certificate certificate) {
    final Collection<X509Certificate> retVal = new ArrayList<X509Certificate>();
    // check to see if there are extensions
    final AuthorityInfoAccessExtentionField aiaField = new AuthorityInfoAccessExtentionField(false);
    try {
        // we can get all names from the AuthorityInfoAccessExtentionField objects
        aiaField.injectReferenceValue(certificate);
        final Collection<String> urlPairs = aiaField.getPolicyValue().getPolicyValue();
        // look through all of the values (if they exist) for caIssuers
        for (String urlPair : urlPairs) {
            if (urlPair.startsWith(CA_ISSUER_CHECK_STRING)) {
                // the url pair is in the format of caIssuer:URL... need to break it 
                // apart to get the url
                final String url = urlPair.substring(CA_ISSUER_CHECK_STRING.length());
                // now pull the certificate from the URL
                try {
                    final Collection<X509Certificate> intermCerts = downloadCertsFromAIA(url);
                    retVal.addAll(intermCerts);
                } catch (NHINDException e) {
                    LOGGER.warn("Intermediate cert cannot be resolved from AIA extension.", e);
                }
            }
        }
    }///CLOVER:OFF
     catch (PolicyProcessException e) {
        LOGGER.warn("Intermediate cert cannot be resolved from AIA extension.", e);
    }
    return retVal;
}
Also used : AuthorityInfoAccessExtentionField(org.nhindirect.policy.x509.AuthorityInfoAccessExtentionField) ArrayList(java.util.ArrayList) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) NHINDException(org.nhindirect.stagent.NHINDException) X509Certificate(java.security.cert.X509Certificate) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Aggregations

AuthorityInfoAccessExtentionField (org.nhindirect.policy.x509.AuthorityInfoAccessExtentionField)5 X509Certificate (java.security.cert.X509Certificate)4 ArrayList (java.util.ArrayList)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 PolicyProcessException (org.nhindirect.policy.PolicyProcessException)1 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)1 NHINDException (org.nhindirect.stagent.NHINDException)1