Search in sources :

Example 6 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project nhin-d by DirectProject.

the class CertificateServiceImpl method getOwner.

private String getOwner(X509Certificate certificate) {
    String address = "";
    // check alternative names first
    Collection<List<?>> altNames = null;
    try {
        altNames = certificate.getSubjectAlternativeNames();
    } catch (CertificateParsingException ex) {
    /* no -op */
    }
    if (altNames != null) {
        for (List<?> entries : altNames) {
            if (// should always be the case according the altNames spec, but checking to be defensive
            entries.size() >= 2) {
                Integer nameType = (Integer) entries.get(0);
                // prefer email over over domain?
                if (nameType == RFC822Name_TYPE)
                    address = (String) entries.get(1);
                else if (nameType == DNSName_TYPE && address.isEmpty())
                    address = (String) entries.get(1);
            }
        }
    }
    if (!address.isEmpty())
        return address;
    // can't find subject address in alt names... try the principal 
    X500Principal issuerPrin = certificate.getSubjectX500Principal();
    // get the domain name
    Map<String, String> oidMap = new HashMap<String, String>();
    // OID for email address
    oidMap.put("1.2.840.113549.1.9.1", "EMAILADDRESS");
    String prinName = issuerPrin.getName(X500Principal.RFC1779, oidMap);
    // see if there is an email address first in the DN
    String searchString = "EMAILADDRESS=";
    int index = prinName.indexOf(searchString);
    if (index == -1) {
        searchString = "CN=";
        // no Email.. check the CN
        index = prinName.indexOf(searchString);
        if (index == -1)
            // no CN... nothing else that can be done from here
            return "";
    }
    // look for a "," to find the end of this attribute
    int endIndex = prinName.indexOf(",", index);
    if (endIndex > -1)
        address = prinName.substring(index + searchString.length(), endIndex);
    else
        address = prinName.substring(index + searchString.length());
    return address;
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) HashMap(java.util.HashMap) X500Principal(javax.security.auth.x500.X500Principal) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException07.

/**
     * Test for <code>CertificateParsingException(String, Throwable)</code>
     * constructor Assertion: constructs CertificateParsingException when
     * <code>cause</code> is null <code>msg</code> is not null
     */
public void testCertificateParsingException07() {
    CertificateParsingException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertificateParsingException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException)

Example 8 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException06.

/**
     * Test for <code>CertificateParsingException(String, Throwable)</code>
     * constructor Assertion: constructs CertificateParsingException when
     * <code>cause</code> is null <code>msg</code> is null
     */
public void testCertificateParsingException06() {
    CertificateParsingException tE = new CertificateParsingException(null, null);
    assertNull("getMessage() must return null", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException)

Example 9 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException08.

/**
     * Test for <code>CertificateParsingException(String, Throwable)</code>
     * constructor Assertion: constructs CertificateParsingException when
     * <code>cause</code> is not null <code>msg</code> is null
     */
public void testCertificateParsingException08() {
    CertificateParsingException tE = new CertificateParsingException(null, tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() must should ".concat(toS), (getM.indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException)

Example 10 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException03.

/**
     * Test for <code>CertificateParsingException(String)</code> constructor
     * Assertion: constructs CertificateParsingException when <code>msg</code>
     * is null
     */
public void testCertificateParsingException03() {
    String msg = null;
    CertificateParsingException tE = new CertificateParsingException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException)

Aggregations

CertificateParsingException (java.security.cert.CertificateParsingException)72 List (java.util.List)25 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 X509Certificate (java.security.cert.X509Certificate)15 CertificateException (java.security.cert.CertificateException)13 Collection (java.util.Collection)12 X500Principal (javax.security.auth.x500.X500Principal)11 BigInteger (java.math.BigInteger)8 InvalidKeyException (java.security.InvalidKeyException)7 HashMap (java.util.HashMap)7 DERIA5String (org.bouncycastle.asn1.DERIA5String)7 DEROctetString (org.bouncycastle.asn1.DEROctetString)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 NoSuchProviderException (java.security.NoSuchProviderException)6 SignatureException (java.security.SignatureException)6 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 CertificateExpiredException (java.security.cert.CertificateExpiredException)6 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)6 GeneralName (org.bouncycastle.asn1.x509.GeneralName)6