Skip to content

Commit

Permalink
Set keystore type to PKCS12
Browse files Browse the repository at this point in the history
  • Loading branch information
hwupathum committed Nov 8, 2024
1 parent 41f10ee commit dc58661
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class ClientSignKeyDataHolder implements X509Credential {

private PublicKey publicKey = null;

private static final String KEYSTORE_TYPE = "PKCS12";

/**
* Constructor method
* @param keyStorePath path to the key store
Expand All @@ -75,7 +77,7 @@ public ClientSignKeyDataHolder(String keyStorePath, String password, String key
try {
File file = new File(keyStorePath);
is = new FileInputStream(file);
KeyStore keystore = KeystoreUtils.getKeystoreInstance(KeyStore.getDefaultType());
KeyStore keystore = KeystoreUtils.getKeystoreInstance(KEYSTORE_TYPE);
keystore.load(is, password.toCharArray());

privateKey = (PrivateKey) keystore.getKey(keyAlias, password.toCharArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import org.wso2.carbon.utils.security.KeystoreUtils;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.util.Utils;

import java.io.FileInputStream;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void start() {
wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig()
.httpsPort(8089)
.keystorePath(Paths.get(Utils.getResidentCarbonHome(), "repository", "resources", "security",
"wso2carbon.p12").toAbsolutePath().toString())
ISIntegrationTest.KEYSTORE_NAME).toAbsolutePath().toString())
.keystorePassword("wso2carbon")
.keyManagerPassword("wso2carbon")
.extensions(
Expand Down Expand Up @@ -179,7 +180,7 @@ public void verifyForLogoutFlow() {

private String buildIdToken() throws Exception {

KeyStore wso2KeyStore = getKeyStoreFromFile("wso2carbon.p12", "wso2carbon",
KeyStore wso2KeyStore = getKeyStoreFromFile(ISIntegrationTest.KEYSTORE_NAME, "wso2carbon",
Utils.getResidentCarbonHome());
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) wso2KeyStore.getKey("wso2carbon", "wso2carbon".toCharArray());

Expand Down Expand Up @@ -213,7 +214,7 @@ private KeyStore getKeyStoreFromFile(String keystoreName, String password, Strin

Path tenantKeystorePath = Paths.get(home, "repository", "resources", "security", keystoreName);
FileInputStream file = new FileInputStream(tenantKeystorePath.toString());
KeyStore keystore = KeystoreUtils.getKeystoreInstance(KeyStore.getDefaultType());
KeyStore keystore = KeystoreUtils.getKeystoreInstance(ISIntegrationTest.KEYSTORE_TYPE);
keystore.load(file, password.toCharArray());
return keystore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void readX509Credentials(InputStream keyStoreInputStream, char[] keySt
char[] privateKeyPassword)
throws Exception {
try {
KeyStore keyStore = KeystoreUtils.getKeystoreInstance("PKCS12");
KeyStore keyStore = Keystore.getInstance("PKCS12");
keyStore.load(keyStoreInputStream, keyStorePassword);
readX509Credentials(keyStore, publicCertAlias, privateKeyAlias, privateKeyPassword);
} catch (Exception e) {
Expand Down

0 comments on commit dc58661

Please sign in to comment.