Class CertificateMgtUtils


  • public class CertificateMgtUtils
    extends Object
    This class holds the utility methods for certificate management.
    • Method Detail

      • addCertificateToSenderTrustStore

        public ResponseCode addCertificateToSenderTrustStore​(String base64Cert,
                                                             String alias)
      • addCertificateToListenerTrustStore

        public ResponseCode addCertificateToListenerTrustStore​(String base64Cert,
                                                               String alias)
      • addCertificateToTrustStore

        public ResponseCode addCertificateToTrustStore​(String base64Cert,
                                                       String alias)
        This method generates a certificate from a base64 encoded certificate string and add to the configured trust store.
        Parameters:
        base64Cert - : The base 64 encoded string of the server certificate.
        alias - : The alias for the certificate.
        Returns:
        : ResponseCode which matches the execution result. Response Codes. SUCCESS : If certificate added successfully. INTERNAL_SERVER_ERROR : If any internal error occurred ALIAS_EXISTS_IN_TRUST_STORE : If the alias exists in trust store. CERTIFICATE_EXPIRED : If the given certificate is expired.
      • validateCertificate

        public ResponseCode validateCertificate​(String alias,
                                                int tenantId,
                                                String certificate)
        To validate the current certificate and alias.
        Parameters:
        alias - Alias of the certificate.
        certificate - Bas64 endcoded certificated.
        Returns:
        response code based on the validation
      • removeCertificateFromListenerTrustStore

        public ResponseCode removeCertificateFromListenerTrustStore​(String alias)
      • removeCertificateFromSenderTrustStore

        public ResponseCode removeCertificateFromSenderTrustStore​(String alias)
      • removeCertificateFromTrustStore

        public ResponseCode removeCertificateFromTrustStore​(String alias)
        This method will remove certificate from the trust store which matches the given alias.
        Parameters:
        alias - : The alias which the certificate should be deleted.
        Returns:
        : ResponseCode based on the execution.

        Response Codes SUCCESS : If the certificate is deleted successfully. INTERNAL_SERVER_ERROR : If any exception occurred. CERTIFICATE_NOT_FOUND : If the Alias is not found in the key store.

      • getCertificateInformation

        public org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO getCertificateInformation​(String alias)
                                                                                           throws CertificateManagementException
        Method to get the information of the certificate.
        Parameters:
        alias - : Alias of the certificate which information should be retrieved
        Returns:
        : The details of the certificate as a MAP.
        Throws:
        CertificateManagementException
      • getCertificateInfo

        public org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO getCertificateInfo​(String base64EncodedCertificate)
        To get the certificate information from base64 encoded certificate.
        Parameters:
        base64EncodedCertificate - Base 64 encoded certificate.
        Returns:
        Certificate information.
      • getUniqueIdentifierOfCertificate

        public String getUniqueIdentifierOfCertificate​(String certificate)
        To get the unique identifier(serialnumber_issuerdn) of the certificate.
        Parameters:
        certificate - Base64 encoded certificate.
        Returns:
        unique identifier of the certification.
      • getSSLSenderProfilePath

        public static String getSSLSenderProfilePath()
      • getSSLListenerProfilePath

        public static String getSSLListenerProfilePath()
      • startListenerCertificateReLoader

        public static void startListenerCertificateReLoader()
      • convert

        public static Optional<X509Certificate> convert​(Certificate cert)
        Convert javax.security.cert.X509Certificate to java.security.cert.X509Certificate
        Parameters:
        cert - the certificate to be converted
        Returns:
        java.security.cert.X509Certificate type certificate