use of org.wso2.carbon.apimgt.impl.dto.TrustStoreDTO in project carbon-apimgt by wso2.
the class CertificateMgtUtils method getListenerProfileTrustStore.
private static TrustStoreDTO getListenerProfileTrustStore() throws FileNotFoundException, XMLStreamException {
String fullPath = getSSLListenerProfilePath();
if (StringUtils.isNotEmpty(fullPath)) {
OMElement customSSLProfilesOmElement = new StAXOMBuilder(fullPath).getDocumentElement();
SecretResolver secretResolver = SecretResolverFactory.create(customSSLProfilesOmElement, true);
if (customSSLProfilesOmElement != null) {
Iterator profileIterator = customSSLProfilesOmElement.getChildrenWithLocalName("profile");
if (profileIterator != null) {
OMElement profile = (OMElement) profileIterator.next();
while (profileIterator.hasNext()) {
OMElement tempProfile = (OMElement) profileIterator.next();
OMElement bindAddress = tempProfile.getFirstChildWithName(new QName("bindAddress"));
if ("0.0.0.0".equals(bindAddress.getText())) {
{
profile = tempProfile;
break;
}
}
}
if (profile != null) {
OMElement trustStoreElement = profile.getFirstChildWithName(new QName("TrustStore"));
if (trustStoreElement != null) {
OMElement location = trustStoreElement.getFirstChildWithName(new QName("Location"));
String path = getFullPath(location.getText());
OMElement type = trustStoreElement.getFirstChildWithName(new QName("Type"));
OMElement passwordElement = trustStoreElement.getFirstChildWithName(new QName("Password"));
String resolvedValue = "";
if (passwordElement != null) {
resolvedValue = MiscellaneousUtil.resolve(passwordElement, secretResolver);
}
return new TrustStoreDTO(path, type.getText(), resolvedValue.toCharArray());
}
}
}
}
}
return getParentTrustStore();
}
use of org.wso2.carbon.apimgt.impl.dto.TrustStoreDTO in project carbon-apimgt by wso2.
the class CertificateMgtUtils method getSenderProfileTrustStore.
private static TrustStoreDTO getSenderProfileTrustStore() throws FileNotFoundException, XMLStreamException {
String fullPath = getSSLSenderProfilePath();
if (StringUtils.isNotEmpty(fullPath)) {
OMElement customSSLProfilesOmElement = new StAXOMBuilder(fullPath).getDocumentElement();
SecretResolver secretResolver = SecretResolverFactory.create(customSSLProfilesOmElement, true);
if (customSSLProfilesOmElement != null) {
Iterator profileIterator = customSSLProfilesOmElement.getChildrenWithLocalName("profile");
if (profileIterator != null) {
OMElement profile = (OMElement) profileIterator.next();
while (profileIterator.hasNext()) {
OMElement tempProfile = (OMElement) profileIterator.next();
OMElement servers = tempProfile.getFirstChildWithName(new QName("servers"));
if ("*".equals(servers.getText())) {
{
profile = tempProfile;
break;
}
}
}
if (profile != null) {
OMElement trustStoreElement = profile.getFirstChildWithName(new QName("TrustStore"));
if (trustStoreElement != null) {
OMElement location = trustStoreElement.getFirstChildWithName(new QName("Location"));
String path = getFullPath(location.getText());
OMElement type = trustStoreElement.getFirstChildWithName(new QName("Type"));
OMElement passwordElement = trustStoreElement.getFirstChildWithName(new QName("Password"));
String resolvedValue = "";
if (passwordElement != null) {
resolvedValue = MiscellaneousUtil.resolve(passwordElement, secretResolver);
}
return new TrustStoreDTO(path, type.getText(), resolvedValue.toCharArray());
}
}
}
}
}
return getParentTrustStore();
}
use of org.wso2.carbon.apimgt.impl.dto.TrustStoreDTO in project carbon-apimgt by wso2.
the class CertificateReLoader method run.
@Override
public void run() {
TrustStoreDTO trustStoreDTO = CertificateReLoaderUtil.getTrustStore();
if (trustStoreDTO != null) {
File trustStoreFile = new File(trustStoreDTO.getLocation());
FileInputStream localTrustStoreStream;
try {
long lastUpdatedTimeStamp = CertificateReLoaderUtil.getLastUpdatedTimeStamp();
long lastModified = trustStoreFile.lastModified();
if (lastUpdatedTimeStamp != lastModified) {
CertificateReLoaderUtil.setLastUpdatedTimeStamp(lastModified);
localTrustStoreStream = new FileInputStream(trustStoreFile);
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(localTrustStoreStream, trustStoreDTO.getPassword());
ServiceReferenceHolder.getInstance().setListenerTrustStore(trustStore);
}
} catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException e) {
log.error("Unable to find the certificate", e);
}
}
}
use of org.wso2.carbon.apimgt.impl.dto.TrustStoreDTO 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);
}
}
use of org.wso2.carbon.apimgt.impl.dto.TrustStoreDTO in project carbon-apimgt by wso2.
the class CertificateMgtUtils method startListenerCertificateReLoader.
public static void startListenerCertificateReLoader() {
try {
TrustStoreDTO listenerProfileTrustStore = getListenerProfileTrustStore();
File trustStoreFile = new File(listenerProfileTrustStore.getLocation());
try (FileInputStream trustStoreStream = new FileInputStream(trustStoreFile)) {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(trustStoreStream, listenerProfileTrustStore.getPassword());
CertificateReLoaderUtil.setLastUpdatedTimeStamp(trustStoreFile.lastModified());
CertificateReLoaderUtil.setCertificate(listenerProfileTrustStore);
CertificateReLoaderUtil.startCertificateReLoader();
ServiceReferenceHolder.getInstance().setListenerTrustStore(trustStore);
}
} catch (IOException | KeyStoreException | CertificateException | NoSuchAlgorithmException | XMLStreamException e) {
log.error("Error in loading trust store.", e);
}
}
Aggregations