Class CertificateMgtUtils
- java.lang.Object
-
- org.wso2.carbon.apimgt.impl.utils.CertificateMgtUtils
-
public class CertificateMgtUtils extends Object
This class holds the utility methods for certificate management.
-
-
Field Summary
Fields Modifier and Type Field Description static String
SENDER_PROFILE_JKS_NAME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ResponseCode
addCertificateToListenerTrustStore(String base64Cert, String alias)
ResponseCode
addCertificateToSenderTrustStore(String base64Cert, String alias)
ResponseCode
addCertificateToTrustStore(String base64Cert, String alias)
This method generates a certificate from a base64 encoded certificate string and add to the configured trust store.static void
backupOriginalTrustStore()
static Optional<X509Certificate>
convert(Certificate cert)
Convert javax.security.cert.X509Certificate to java.security.cert.X509CertificateByteArrayInputStream
getCertificateContent(String alias)
Retrieve the certificate which is represented by the given alias.ByteArrayInputStream
getCertificateContentFromDB(String base64EncodedCertificate)
To get the certificate information from base64 encoded certificate.org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO
getCertificateInfo(String base64EncodedCertificate)
To get the certificate information from base64 encoded certificate.org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO
getCertificateInformation(String alias)
Method to get the information of the certificate.static CertificateMgtUtils
getInstance()
To get the instance of CertificateMgtUtils class.static String
getSSLListenerProfilePath()
static String
getSSLSenderProfilePath()
String
getUniqueIdentifierOfCertificate(String certificate)
To get the unique identifier(serialnumber_issuerdn) of the certificate.ResponseCode
removeCertificateFromListenerTrustStore(String alias)
ResponseCode
removeCertificateFromSenderTrustStore(String alias)
ResponseCode
removeCertificateFromTrustStore(String alias)
This method will remove certificate from the trust store which matches the given alias.static void
startListenerCertificateReLoader()
ResponseCode
updateCertificate(String certificate, String alias)
Method to update the certificate which matches the given alias.ResponseCode
validateCertificate(String alias, int tenantId, String certificate)
To validate the current certificate and alias.
-
-
-
Field Detail
-
SENDER_PROFILE_JKS_NAME
public static final String SENDER_PROFILE_JKS_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static CertificateMgtUtils getInstance()
To get the instance of CertificateMgtUtils class.- Returns:
- instance of
CertificateMgtUtils
-
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.
-
updateCertificate
public ResponseCode updateCertificate(String certificate, String alias) throws CertificateManagementException
Method to update the certificate which matches the given alias.- Parameters:
certificate
- : The base64 encoded certificate string.alias
- : Alias of the certificate that should be retrieved.- Returns:
- :
- Throws:
CertificateManagementException
-
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.
-
getCertificateContentFromDB
public ByteArrayInputStream getCertificateContentFromDB(String base64EncodedCertificate) throws CertificateManagementException
To get the certificate information from base64 encoded certificate.- Parameters:
base64EncodedCertificate
- Base 64 encoded certificate.- Returns:
- Certificate information.
- Throws:
CertificateManagementException
-
getCertificateContent
public ByteArrayInputStream getCertificateContent(String alias) throws CertificateManagementException
Retrieve the certificate which is represented by the given alias.- Parameters:
alias
- : The alias of the required certificate.- Returns:
- : The Certificate as a ByteArrayInputStream.
- Throws:
CertificateManagementException
- :
-
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()
-
backupOriginalTrustStore
public static void backupOriginalTrustStore() throws CertificateManagementException
- Throws:
CertificateManagementException
-
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
-
-