From 72a09bf90bf4080ddb7807ea8b38c1faf5e78d25 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Sun, 12 Nov 2017 08:14:30 +0530 Subject: [PATCH] This commit fixes the unable to parse the DN issue Currently when a DN cannot be parsed if the DN is not in RFC2253 format. This commit fixeds this issue. --- .../mgt/core/impl/CertificateGenerator.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index 877d606af8..d07c109dfa 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -323,19 +323,25 @@ public class CertificateGenerator { CertificateResponse lookUpCertificate = null; KeyStoreReader keyStoreReader = new KeyStoreReader(); if (distinguishedName != null && !distinguishedName.isEmpty()) { - LdapName ldapName; - try { - ldapName = new LdapName(distinguishedName); - } catch (InvalidNameException e) { - throw new KeystoreException( - "Invalid name exception while trying to create a LDAP name using the distinguished name ", e); - } - for (Rdn relativeDistinuguishedNames : ldapName.getRdns()) { - if (relativeDistinuguishedNames.getType().equalsIgnoreCase("CN")) { - System.err.println("CN is: " + relativeDistinuguishedNames.getValue()); - lookUpCertificate = keyStoreReader - .getCertificateBySerial(String.valueOf(relativeDistinuguishedNames.getValue())); - break; + if (distinguishedName.contains("/CN=")) { + String[] dnSplits = distinguishedName.split("/CN="); + String commonNameExtracted = dnSplits[dnSplits.length - 1]; + lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted); + } else { + LdapName ldapName; + try { + ldapName = new LdapName(distinguishedName); + } catch (InvalidNameException e) { + throw new KeystoreException( + "Invalid name exception while trying to create a LDAP name using the distinguished name ", + e); + } + for (Rdn relativeDistinguishedNames : ldapName.getRdns()) { + if (relativeDistinguishedNames.getType().equalsIgnoreCase("CN")) { + lookUpCertificate = keyStoreReader + .getCertificateBySerial(String.valueOf(relativeDistinguishedNames.getValue())); + break; + } } } }