Parsing the issuerDN / subjectDN in an SSL (X.509) certificate in Scala


You’ll get values like this:

CN = COMODO ECC Domain Validation Secure Server CA 2
O = COMODO CA Limited
L = Salford
S = Greater Manchester
C = GB

There are several possible fields that can show up here, and I don’t believe the order is guaranteed. This format comes from LDAP / Active Directory, and is helpfully called “Distinguished Names“.

You can parse these in scala like so:

val issuer = new LdapName(cert.getIssuerDN.toString)
val issuerDN = issuer.getAll()
val issuerDNValues =
      () => {
    .takeWhile(_ => issuerDN.hasMoreElements)