Search in sources :

Example 36 with Extension

use of org.apache.harmony.security.x509.Extension in project jmeter by apache.

the class SMIMEAssertion method getEmailFromCert.

/**
     * Extract email addresses from a certificate
     * 
     * @param cert the X509 certificate holder
     * @return a List of all email addresses found
     * @throws CertificateException
     */
private static List<String> getEmailFromCert(X509CertificateHolder cert) throws CertificateException {
    List<String> res = new ArrayList<>();
    X500Name subject = cert.getSubject();
    for (RDN emails : subject.getRDNs(BCStyle.EmailAddress)) {
        for (AttributeTypeAndValue emailAttr : emails.getTypesAndValues()) {
            if (log.isDebugEnabled()) {
                log.debug("Add email from RDN: {}", IETFUtils.valueToString(emailAttr.getValue()));
            }
            res.add(IETFUtils.valueToString(emailAttr.getValue()));
        }
    }
    Extension subjectAlternativeNames = cert.getExtension(Extension.subjectAlternativeName);
    if (subjectAlternativeNames != null) {
        for (GeneralName name : GeneralNames.getInstance(subjectAlternativeNames.getParsedValue()).getNames()) {
            if (name.getTagNo() == GeneralName.rfc822Name) {
                String email = IETFUtils.valueToString(name.getName());
                log.debug("Add email from subjectAlternativeName: {}", email);
                res.add(email);
            }
        }
    }
    return res;
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) ArrayList(java.util.ArrayList) X500Name(org.bouncycastle.asn1.x500.X500Name) GeneralName(org.bouncycastle.asn1.x509.GeneralName) RDN(org.bouncycastle.asn1.x500.RDN) AttributeTypeAndValue(org.bouncycastle.asn1.x500.AttributeTypeAndValue)

Aggregations

Extension (org.bouncycastle.asn1.x509.Extension)25 Enumeration (java.util.Enumeration)21 Extensions (org.bouncycastle.asn1.x509.Extensions)18 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)17 HashSet (java.util.HashSet)13 Set (java.util.Set)13 IOException (java.io.IOException)11 Date (java.util.Date)8 VerisignCzagExtension (org.bouncycastle.asn1.misc.VerisignCzagExtension)8 Extension (org.gluu.oxtrust.model.scim2.Extension)8 X500Name (org.bouncycastle.asn1.x500.X500Name)7 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 X509CRLEntry (java.security.cert.X509CRLEntry)6 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)6 BigDecimal (java.math.BigDecimal)5 DEROctetString (org.bouncycastle.asn1.DEROctetString)5 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)5 GluuAttribute (org.xdi.model.GluuAttribute)5 ArrayList (java.util.ArrayList)4 ASN1String (org.bouncycastle.asn1.ASN1String)4