From e9cf04551a76663b31fa3b03938be901003fef26 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Fri, 23 Sep 2022 06:52:10 +0530 Subject: [PATCH] Fix ios enrolment error fixes https://gitlab.com/entgra/product-iots/-/issues/1541 --- .../mgt/core/impl/CertificateGenerator.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 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 b25837154f..752c50acf4 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 @@ -400,23 +400,39 @@ public class CertificateGenerator { generateCertificate(byteArrayInputStream); if (reqCert != null && reqCert.getSerialNumber() != null) { - Certificate lookUpCertificate = keyStoreReader.getCertificateByAlias( + log.debug("looking up certificate for serial: " + reqCert.getSerialNumber().toString()); + CertificateResponse lookUpCertificate = keyStoreReader.getCertificateBySerial( reqCert.getSerialNumber().toString()); - - if (lookUpCertificate instanceof X509Certificate) { - return (X509Certificate) lookUpCertificate; + if (lookUpCertificate != null && lookUpCertificate.getCertificate() != null) { + log.debug("certificate found for serial: " + reqCert.getSerialNumber() + .toString()); + Certificate certificate = (Certificate) Serializer.deserialize(lookUpCertificate.getCertificate()); + if (certificate instanceof X509Certificate) { + return (X509Certificate) certificate; + } + } else { + log.debug("certificate not found for serial: " + reqCert.getSerialNumber() + .toString()); } + } } } catch (CMSException e) { String errorMsg = "CMSException when decoding certificate signature"; + log.error(errorMsg); throw new KeystoreException(errorMsg, e); } catch (IOException e) { String errorMsg = "IOException when decoding certificate signature"; + log.error(errorMsg); throw new KeystoreException(errorMsg, e); } catch (CertificateException e) { String errorMsg = "CertificateException when decoding certificate signature"; + log.error(errorMsg); + throw new KeystoreException(errorMsg, e); + } catch (ClassNotFoundException e) { + String errorMsg = "Certificate class not found"; + log.error(errorMsg); throw new KeystoreException(errorMsg, e); }