Search in sources :

Example 16 with AttributeTypeAndValue

use of org.bouncycastle.asn1.x500.AttributeTypeAndValue 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

IOException (java.io.IOException)7 AttributeTypeAndValue (org.apache.harmony.security.x501.AttributeTypeAndValue)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 BigInteger (java.math.BigInteger)3 GeneralSecurityException (java.security.GeneralSecurityException)3 MessageDigest (java.security.MessageDigest)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Signature (java.security.Signature)3 Certificate (java.security.cert.Certificate)3 X509Certificate (java.security.cert.X509Certificate)3 X500Principal (javax.security.auth.x500.X500Principal)3 BerInputStream (org.apache.harmony.security.asn1.BerInputStream)3 ContentInfo (org.apache.harmony.security.pkcs7.ContentInfo)3 SignedData (org.apache.harmony.security.pkcs7.SignedData)3 SignerInfo (org.apache.harmony.security.pkcs7.SignerInfo)3 AttributeValue (org.apache.harmony.security.x501.AttributeValue)3 ASN1String (org.bouncycastle.asn1.ASN1String)3 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)3