|
|
@ -29,6 +29,7 @@ import io.entgra.device.mgt.core.certificate.mgt.core.util.CertificateManagement
|
|
|
|
import io.entgra.device.mgt.core.certificate.mgt.core.util.CommonUtil;
|
|
|
|
import io.entgra.device.mgt.core.certificate.mgt.core.util.CommonUtil;
|
|
|
|
import io.entgra.device.mgt.core.certificate.mgt.core.util.Serializer;
|
|
|
|
import io.entgra.device.mgt.core.certificate.mgt.core.util.Serializer;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.bouncycastle.asn1.ASN1Encodable;
|
|
|
|
import org.bouncycastle.asn1.ASN1Encodable;
|
|
|
@ -429,19 +430,34 @@ public class CertificateGenerator {
|
|
|
|
generateCertificate(byteArrayInputStream);
|
|
|
|
generateCertificate(byteArrayInputStream);
|
|
|
|
|
|
|
|
|
|
|
|
if (reqCert != null && reqCert.getSerialNumber() != null) {
|
|
|
|
if (reqCert != null && reqCert.getSerialNumber() != null) {
|
|
|
|
log.debug("looking up certificate for serial: " + reqCert.getSerialNumber().toString());
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
CertificateResponse lookUpCertificate = keyStoreReader.getCertificateBySerial(
|
|
|
|
log.debug("looking up certificate for serial: " + reqCert.getSerialNumber().toString());
|
|
|
|
reqCert.getSerialNumber().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
String orgUnit = CommonUtil.getSubjectDnAttribute(reqCert,
|
|
|
|
|
|
|
|
CertificateManagementConstants.ORG_UNIT_ATTRIBUTE);
|
|
|
|
|
|
|
|
CertificateResponse lookUpCertificate;
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(orgUnit)) {
|
|
|
|
|
|
|
|
int tenantId = Integer.parseInt(orgUnit.split(("_"))[1]);
|
|
|
|
|
|
|
|
lookUpCertificate = keyStoreReader.getCertificateBySerial(reqCert.getSerialNumber().toString(),
|
|
|
|
|
|
|
|
tenantId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
lookUpCertificate = keyStoreReader.getCertificateBySerial(
|
|
|
|
|
|
|
|
reqCert.getSerialNumber().toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
if (lookUpCertificate != null && lookUpCertificate.getCertificate() != null) {
|
|
|
|
if (lookUpCertificate != null && lookUpCertificate.getCertificate() != null) {
|
|
|
|
log.debug("certificate found for serial: " + reqCert.getSerialNumber()
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
.toString());
|
|
|
|
log.debug("certificate found for serial: " + reqCert.getSerialNumber()
|
|
|
|
|
|
|
|
.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
Certificate certificate = (Certificate) Serializer.deserialize(lookUpCertificate.getCertificate());
|
|
|
|
Certificate certificate = (Certificate) Serializer.deserialize(lookUpCertificate.getCertificate());
|
|
|
|
if (certificate instanceof X509Certificate) {
|
|
|
|
if (certificate instanceof X509Certificate) {
|
|
|
|
return (X509Certificate) certificate;
|
|
|
|
return (X509Certificate) certificate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.debug("certificate not found for serial: " + reqCert.getSerialNumber()
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
.toString());
|
|
|
|
log.debug("certificate not found for serial: " + reqCert.getSerialNumber()
|
|
|
|
|
|
|
|
.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -464,7 +480,6 @@ public class CertificateGenerator {
|
|
|
|
log.error(errorMsg);
|
|
|
|
log.error(errorMsg);
|
|
|
|
throw new KeystoreException(errorMsg, e);
|
|
|
|
throw new KeystoreException(errorMsg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|