Skip to content

Commit

Permalink
Use getKeystoreInstance from KeystoreUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
hwupathum committed Sep 30, 2024
1 parent 3f4cc59 commit 3de9649
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
import org.opensaml.soap.soap11.Envelope;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.XMLObjectBuilderFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.core.util.KeyStoreManager;
import org.wso2.carbon.identity.application.authenticator.samlsso.exception.ArtifactResolutionException;
import org.wso2.carbon.identity.application.authenticator.samlsso.util.SSOConstants;
import org.wso2.carbon.identity.application.authenticator.samlsso.util.SSOUtils;
import org.wso2.carbon.utils.CarbonUtils;

import java.io.IOException;
Expand Down Expand Up @@ -137,30 +138,28 @@ private SSLContext getSSLContext(final ServerConfiguration serverConfig)

SSLContext sslContext = null;
KeyManagerFactory keyManagerFactory;
KeyStore keyStore;
String keyStorePath;
String keyStorePassword;
String keyStoreType;

if (serverConfig != null) {
keyStorePath = serverConfig.getFirstProperty(SSOConstants.SECURITY_KEYSTORE_LOCATION);
keyStorePassword = serverConfig.getFirstProperty(SSOConstants.ServerConfig.KEY_PASSWORD);
keyStoreType = serverConfig.getFirstProperty(SSOConstants.SECURITY_KEYSTORE_TYPE);
String keyStorePath = serverConfig.getFirstProperty(SSOConstants.SECURITY_KEYSTORE_LOCATION);
String keyStorePassword = serverConfig.getFirstProperty(SSOConstants.ServerConfig.KEY_PASSWORD);
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);

char[] kspassphrase = keyStorePassword.toCharArray();

sslContext = SSLContext.getInstance("TLSv1.2");
keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyStore = SSOUtils.loadKeyStoreFromFileSystem(keyStorePath, keyStorePassword, keyStoreType);
keyManagerFactory.init(keyStore, kspassphrase);
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
try {
KeyStore keyStore = keyStoreManager.getPrimaryKeyStore();
keyManagerFactory.init(keyStore, kspassphrase);
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
} catch (Exception e) {
throw new GeneralSecurityException("Error when try to load keystore" + keyStorePath, e);
}

if (log.isDebugEnabled()) {
log.debug("Created SSL Context using keystore: " + keyStorePath + " and keyStorePassword: " +
keyStorePassword);
log.debug("Created SSL Context using keystore: " + keyStorePath);
}
}

return sslContext;
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@
<identity.outbound.auth.samlsso.imp.pkg.version.range>[1.0.0, 2.0.0)</identity.outbound.auth.samlsso.imp.pkg.version.range>

<!--Carbon Kernel Version-->
<carbon.kernel.version>4.9.23</carbon.kernel.version>
<carbon.kernel.feature.version>4.9.0</carbon.kernel.feature.version>
<carbon.kernel.version>4.10.9</carbon.kernel.version>
<carbon.kernel.feature.version>4.10.9</carbon.kernel.feature.version>
<carbon.kernel.imp.pkg.version.range>[4.4.0, 5.0.0)</carbon.kernel.imp.pkg.version.range>
<carbon.user.api.imp.pkg.version.range>[1.0.1, 2.0.0)</carbon.user.api.imp.pkg.version.range>

Expand Down

0 comments on commit 3de9649

Please sign in to comment.