import java.util.zip.ZipOutputStream;\r
\r
import javax.crypto.Cipher;\r
+import javax.naming.ldap.LdapName;\r
\r
import org.bouncycastle.asn1.ASN1ObjectIdentifier;\r
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;\r
}\r
\r
public static X509Metadata getMetadata(X509Certificate cert) {\r
- // manually split DN into OID components\r
- // this is instead of parsing with LdapName which:\r
- // (1) I don't trust the order of values\r
- // (2) it filters out values like EMAILADDRESS\r
- String dn = cert.getSubjectDN().getName();\r
Map<String, String> oids = new HashMap<String, String>();\r
- for (String kvp : dn.split(",")) {\r
- String [] val = kvp.trim().split("=");\r
- String oid = val[0].toUpperCase().trim();\r
- String data = val[1].trim();\r
- oids.put(oid, data);\r
+ try {\r
+ String dn = cert.getSubjectDN().getName();\r
+ LdapName ldapName = new LdapName(dn);\r
+ for (int i = 0; i < ldapName.size(); i++) {\r
+ String [] val = ldapName.get(i).trim().split("=", 2);\r
+ String oid = val[0].toUpperCase().trim();\r
+ String data = val[1].trim();\r
+ oids.put(oid, data);\r
+ }\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
}\r
\r
X509Metadata metadata = new X509Metadata(oids.get("CN"), "whocares");\r