Search in sources :

Example 46 with RDN

use of org.openecard.bouncycastle.asn1.x500.RDN in project athenz by yahoo.

the class Crypto method extractX509CSRCommonName.

public static String extractX509CSRCommonName(PKCS10CertificationRequest certReq) {
    String cn = null;
    X500Name x500name = certReq.getSubject();
    RDN cnRdn = x500name.getRDNs(BCStyle.CN)[0];
    if (cnRdn != null) {
        cn = IETFUtils.valueToString(cnRdn.getFirst().getValue());
    }
    return cn;
}
Also used : DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) X500Name(org.bouncycastle.asn1.x500.X500Name) RDN(org.bouncycastle.asn1.x500.RDN)

Example 47 with RDN

use of org.openecard.bouncycastle.asn1.x500.RDN in project athenz by yahoo.

the class Crypto method extractX509CertCommonName.

public static String extractX509CertCommonName(X509Certificate x509Cert) {
    // in case there are multiple CNs, we're only looking at the first one
    String cn = null;
    String principalName = x509Cert.getSubjectX500Principal().getName();
    if (principalName != null && !principalName.isEmpty()) {
        X500Name x500name = new X500Name(principalName);
        RDN cnRdn = x500name.getRDNs(BCStyle.CN)[0];
        if (cnRdn != null) {
            cn = IETFUtils.valueToString(cnRdn.getFirst().getValue());
        }
    }
    return cn;
}
Also used : DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) X500Name(org.bouncycastle.asn1.x500.X500Name) RDN(org.bouncycastle.asn1.x500.RDN)

Example 48 with RDN

use of org.openecard.bouncycastle.asn1.x500.RDN in project xabber-android by redsolution.

the class CustomDomainVerifier method getCommonNames.

private static List<String> getCommonNames(X509Certificate certificate) {
    List<String> domains = new ArrayList<>();
    try {
        X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
        RDN[] rdns = x500name.getRDNs(BCStyle.CN);
        for (int i = 0; i < rdns.length; ++i) {
            domains.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[i].getFirst().getValue()));
        }
        return domains;
    } catch (CertificateEncodingException e) {
        return domains;
    }
}
Also used : ArrayList(java.util.ArrayList) CertificateEncodingException(java.security.cert.CertificateEncodingException) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) X500Name(org.bouncycastle.asn1.x500.X500Name) JcaX509CertificateHolder(org.bouncycastle.cert.jcajce.JcaX509CertificateHolder) RDN(org.bouncycastle.asn1.x500.RDN)

Example 49 with RDN

use of org.openecard.bouncycastle.asn1.x500.RDN in project xipki by xipki.

the class X509Ca method removeEmptyRdns.

// remove the RDNs with empty content
private static X500Name removeEmptyRdns(X500Name name) {
    RDN[] rdns = name.getRDNs();
    List<RDN> tmpRdns = new ArrayList<>(rdns.length);
    boolean changed = false;
    for (RDN rdn : rdns) {
        String textValue = X509Util.rdnValueToString(rdn.getFirst().getValue());
        if (StringUtil.isBlank(textValue)) {
            changed = true;
        } else {
            tmpRdns.add(rdn);
        }
    }
    return changed ? new X500Name(tmpRdns.toArray(new RDN[0])) : name;
}
Also used : ArrayList(java.util.ArrayList) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) X500Name(org.bouncycastle.asn1.x500.X500Name) RDN(org.bouncycastle.asn1.x500.RDN)

Example 50 with RDN

use of org.openecard.bouncycastle.asn1.x500.RDN in project xipki by xipki.

the class CaUtil method sortX509Name.

public static X500Name sortX509Name(X500Name name) {
    ParamUtil.requireNonNull("name", name);
    RDN[] requstedRdns = name.getRDNs();
    List<RDN> rdns = new LinkedList<>();
    List<ASN1ObjectIdentifier> sortedDNs = SubjectDnSpec.getForwardDNs();
    int size = sortedDNs.size();
    for (int i = 0; i < size; i++) {
        ASN1ObjectIdentifier type = sortedDNs.get(i);
        RDN[] thisRdns = getRdns(requstedRdns, type);
        if (thisRdns == null) {
            continue;
        }
        if (thisRdns.length == 0) {
            continue;
        }
        for (RDN m : thisRdns) {
            rdns.add(m);
        }
    }
    return new X500Name(rdns.toArray(new RDN[0]));
}
Also used : X500Name(org.bouncycastle.asn1.x500.X500Name) RDN(org.bouncycastle.asn1.x500.RDN) LinkedList(java.util.LinkedList) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint)

Aggregations

RDN (org.bouncycastle.asn1.x500.RDN)55 X500Name (org.bouncycastle.asn1.x500.X500Name)33 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)18 ArrayList (java.util.ArrayList)15 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)15 X509Certificate (java.security.cert.X509Certificate)13 DERIA5String (org.bouncycastle.asn1.DERIA5String)13 AttributeTypeAndValue (org.bouncycastle.asn1.x500.AttributeTypeAndValue)13 IOException (java.io.IOException)12 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)12 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)12 LinkedList (java.util.LinkedList)10 DEROctetString (org.bouncycastle.asn1.DEROctetString)10 JcaX509CertificateHolder (org.bouncycastle.cert.jcajce.JcaX509CertificateHolder)10 KeyStoreException (java.security.KeyStoreException)8 List (java.util.List)8 InputStream (java.io.InputStream)7 KeyStore (java.security.KeyStore)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 CertificateException (java.security.cert.CertificateException)7