|
|
@ -376,15 +376,31 @@ public class CertificateGenerator {
|
|
|
|
CertificateResponse lookUpCertificate = null;
|
|
|
|
CertificateResponse lookUpCertificate = null;
|
|
|
|
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
|
|
|
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
|
|
|
if (distinguishedName != null && !distinguishedName.isEmpty()) {
|
|
|
|
if (distinguishedName != null && !distinguishedName.isEmpty()) {
|
|
|
|
if (distinguishedName.contains("/CN=")) {
|
|
|
|
if (distinguishedName.contains("CN=")) {
|
|
|
|
String[] dnSplits = distinguishedName.split("/");
|
|
|
|
String[] dnSplits = null;
|
|
|
|
|
|
|
|
if (distinguishedName.contains("/")) {
|
|
|
|
|
|
|
|
dnSplits = distinguishedName.split("/");
|
|
|
|
|
|
|
|
} else if (distinguishedName.contains(",")) {
|
|
|
|
|
|
|
|
//some older versions of nginx will forward the client certificate subject dn separated with commas
|
|
|
|
|
|
|
|
dnSplits = distinguishedName.split(",");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String commonNameExtracted = null;
|
|
|
|
|
|
|
|
int tenantId = 0;
|
|
|
|
|
|
|
|
if (dnSplits != null && dnSplits.length >= 1) {
|
|
|
|
for (String dnPart : dnSplits) {
|
|
|
|
for (String dnPart : dnSplits) {
|
|
|
|
if (dnPart.contains("CN=")) {
|
|
|
|
if (dnPart.contains("CN=")) {
|
|
|
|
String commonNameExtracted = dnPart.replace("CN=", "");
|
|
|
|
commonNameExtracted = dnPart.replace("CN=", "");
|
|
|
|
lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted);
|
|
|
|
} else if (dnPart.contains("OU=")) {
|
|
|
|
break;
|
|
|
|
//the OU of the certificate will be like OU=tenant_<TENANT_ID> ex: OU=tenant_-1234
|
|
|
|
|
|
|
|
//splitting by underscore to extract the tenant domain
|
|
|
|
|
|
|
|
String[] orgUnitSplits = dnPart.split("_");
|
|
|
|
|
|
|
|
tenantId = Integer.parseInt(orgUnitSplits[1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
LdapName ldapName;
|
|
|
|
LdapName ldapName;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -813,10 +829,6 @@ public class CertificateGenerator {
|
|
|
|
|
|
|
|
|
|
|
|
BigInteger serialNumber = BigInteger.valueOf(System.currentTimeMillis());
|
|
|
|
BigInteger serialNumber = BigInteger.valueOf(System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD:components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/CertificateGenerator.java
|
|
|
|
|
|
|
|
<<<<<<< HEAD:components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/CertificateGenerator.java
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
>>>>>>> d34adaae96 (Fix issue with Nginx not recognizing the SCEP client certificate (#105)):components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java
|
|
|
|
|
|
|
|
//Reversing the order of components of the subject DN due to Nginx not verifying the client certificate
|
|
|
|
//Reversing the order of components of the subject DN due to Nginx not verifying the client certificate
|
|
|
|
//generated by Java using this subject DN.
|
|
|
|
//generated by Java using this subject DN.
|
|
|
|
//Ref: https://stackoverflow.com/questions/33769978 & engineering mail SCEP implementation for Android
|
|
|
|
//Ref: https://stackoverflow.com/questions/33769978 & engineering mail SCEP implementation for Android
|
|
|
@ -829,8 +841,9 @@ public class CertificateGenerator {
|
|
|
|
X500Name issuerName = new X500Name(subjectDn);
|
|
|
|
X500Name issuerName = new X500Name(subjectDn);
|
|
|
|
String commonName = certificationRequest.getSubject().getRDNs(BCStyle.CN)[0].getFirst()
|
|
|
|
String commonName = certificationRequest.getSubject().getRDNs(BCStyle.CN)[0].getFirst()
|
|
|
|
.getValue().toString();
|
|
|
|
.getValue().toString();
|
|
|
|
X500Name subjectName = new X500Name("O=" + commonName + "O=AndroidDevice,CN=" +
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
serialNumber);
|
|
|
|
X500Name subjectName = new X500Name("O=" + commonName + ",CN=" +
|
|
|
|
|
|
|
|
serialNumber + ", OU=tenant_"+tenantId);
|
|
|
|
Date startDate = new Date(System.currentTimeMillis());
|
|
|
|
Date startDate = new Date(System.currentTimeMillis());
|
|
|
|
Date endDate = new Date(System.currentTimeMillis()
|
|
|
|
Date endDate = new Date(System.currentTimeMillis()
|
|
|
|
+ TimeUnit.DAYS.toMillis(365 * 100));
|
|
|
|
+ TimeUnit.DAYS.toMillis(365 * 100));
|
|
|
|