use of org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException in project carbon-apimgt by wso2.
the class CertificateMgtUtils method getCertificateInformation.
/**
* Method to get the information of the certificate.
*
* @param alias : Alias of the certificate which information should be retrieved
* @return : The details of the certificate as a MAP.
*/
public synchronized CertificateInformationDTO getCertificateInformation(String alias) throws CertificateManagementException {
CertificateInformationDTO certificateInformation = new CertificateInformationDTO();
File trustStoreFile = new File(trustStoreLocation);
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream localTrustStoreStream = new FileInputStream(trustStoreFile)) {
trustStore.load(localTrustStoreStream, trustStorePassword);
}
if (trustStore.containsAlias(alias)) {
X509Certificate certificate = (X509Certificate) trustStore.getCertificate(alias);
certificateInformation = getCertificateMetaData(certificate);
}
} catch (IOException e) {
throw new CertificateManagementException("Error wile loading the keystore.", e);
} catch (CertificateException e) {
throw new CertificateManagementException("Error loading the keystore from the stream.", e);
} catch (NoSuchAlgorithmException e) {
throw new CertificateManagementException("Could not find the algorithm to load the certificate.", e);
} catch (KeyStoreException e) {
throw new CertificateManagementException("Error reading certificate contents.", e);
}
return certificateInformation;
}
use of org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException in project carbon-apimgt by wso2.
the class CertificateMgtUtils method backupOriginalTrustStore.
public static void backupOriginalTrustStore() throws CertificateManagementException {
try {
TrustStoreDTO senderProfileTrustStore = getSenderProfileTrustStore();
TrustStoreDTO listenerProfileTrustStore = getListenerProfileTrustStore();
File srcFile = new File(senderProfileTrustStore.getLocation());
if (senderProfileTrustStore.getLocation().equals(listenerProfileTrustStore.getLocation())) {
String parent = srcFile.getParent();
String destPath = parent + File.separator + COMMON_CERT_NAME;
File destFile = new File(destPath);
deletePreviousBackupJKSFile(destFile);
FileUtils.copyFile(srcFile, destFile);
updateSenderProfileTrustStoreLocation(destPath);
updateListenerProfileTrustStoreLocation(destPath);
} else {
if (srcFile.exists()) {
String parent = srcFile.getParent();
String destPath = parent + File.separator + SENDER_PROFILE_JKS_NAME;
File destFile = new File(destPath);
deletePreviousBackupJKSFile(destFile);
FileUtils.copyFile(srcFile, destFile);
updateSenderProfileTrustStoreLocation(destPath);
}
File listenerProfileTrustStoreFile = new File(listenerProfileTrustStore.getLocation());
if (listenerProfileTrustStoreFile.exists()) {
String parent = listenerProfileTrustStoreFile.getParent();
String destPath = parent + File.separator + LISTER_PROFILE_JKS_NAME;
File destFile = new File(destPath);
deletePreviousBackupJKSFile(destFile);
FileUtils.copyFile(listenerProfileTrustStoreFile, destFile);
updateListenerProfileTrustStoreLocation(destPath);
}
}
} catch (XMLStreamException | IOException e) {
throw new CertificateManagementException("Error while backup truststore", e);
}
}
Aggregations