From 78e6367e632a87d278a10e050318b319c803b979 Mon Sep 17 00:00:00 2001 From: Udara Pathum <46132469+hwupathum@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:00:27 +0530 Subject: [PATCH] Use getKeystoreInstance from KeystoreUtils --- .../integration/common/clients/KeyStoreAdminClient.java | 3 ++- .../common/clients/sso/saml/query/ClientSignKeyDataHolder.java | 3 ++- .../integration/test/base/MockOIDCIdentityProvider.java | 3 ++- .../test/oauth2/OAuth2IDTokenEncryptionTestCase.java | 3 ++- .../oauth2/OAuth2RequestObjectSignatureValidationTestCase.java | 3 ++- .../test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java | 3 ++- .../commons/security/SSOAgentX509KeyStoreCredential.java | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/KeyStoreAdminClient.java b/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/KeyStoreAdminClient.java index f726273a85f..02fcf401142 100644 --- a/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/KeyStoreAdminClient.java +++ b/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/KeyStoreAdminClient.java @@ -38,6 +38,7 @@ import org.wso2.carbon.security.mgt.stub.keystore.RemoveCertFromStore; import org.wso2.carbon.security.mgt.stub.keystore.xsd.KeyStoreData; import org.wso2.carbon.security.mgt.stub.keystore.xsd.PaginatedKeyStoreData; +import org.wso2.carbon.utils.security.KeystoreUtils; import java.io.ByteArrayInputStream; import java.rmi.RemoteException; @@ -143,7 +144,7 @@ public boolean isPrivateKeyStore(byte[] content, String password, String type) try { boolean isPrivateStore = false; ByteArrayInputStream stream = new ByteArrayInputStream(content); - KeyStore store = KeyStore.getInstance(type); + KeyStore store = KeystoreUtils.getKeystoreInstance(type); store.load(stream, password.toCharArray()); Enumeration aliases = store.aliases(); while (aliases.hasMoreElements()) { diff --git a/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/sso/saml/query/ClientSignKeyDataHolder.java b/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/sso/saml/query/ClientSignKeyDataHolder.java index ddeb0a68609..8fc1d2b62e5 100644 --- a/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/sso/saml/query/ClientSignKeyDataHolder.java +++ b/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/sso/saml/query/ClientSignKeyDataHolder.java @@ -24,6 +24,7 @@ import org.opensaml.security.credential.CredentialContextSet; import org.opensaml.security.credential.UsageType; import org.opensaml.security.x509.X509Credential; +import org.wso2.carbon.utils.security.KeystoreUtils; import java.io.File; import java.io.FileInputStream; @@ -74,7 +75,7 @@ public ClientSignKeyDataHolder(String keyStorePath, String password, String key try { File file = new File(keyStorePath); is = new FileInputStream(file); - KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); + KeyStore keystore = KeystoreUtils.getKeystoreInstance(KeyStore.getDefaultType()); keystore.load(is, password.toCharArray()); privateKey = (PrivateKey) keystore.getKey(keyAlias, password.toCharArray()); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockOIDCIdentityProvider.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockOIDCIdentityProvider.java index 59533900bd1..5de4b224d9a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockOIDCIdentityProvider.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockOIDCIdentityProvider.java @@ -30,6 +30,7 @@ import com.nimbusds.jose.crypto.RSASSASigner; import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; +import org.wso2.carbon.utils.security.KeystoreUtils; import org.wso2.identity.integration.test.util.Utils; import java.io.FileInputStream; @@ -212,7 +213,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 = KeyStore.getInstance(KeyStore.getDefaultType()); + KeyStore keystore = KeystoreUtils.getKeystoreInstance(KeyStore.getDefaultType()); keystore.load(file, password.toCharArray()); return keystore; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java index 5cd4f30e68e..2b2bc5b41f0 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2IDTokenEncryptionTestCase.java @@ -58,6 +58,7 @@ import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; +import org.wso2.carbon.utils.security.KeystoreUtils; import org.wso2.identity.integration.common.utils.ISIntegrationTest; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; @@ -443,7 +444,7 @@ private String getLocationHeaderValue(HttpResponse response) { */ private void initServiceProviderKeys() throws Exception { - KeyStore keyStore = KeyStore.getInstance(ISIntegrationTest.KEYSTORE_TYPE); + KeyStore keyStore = KeystoreUtils.getKeystoreInstance(ISIntegrationTest.KEYSTORE_TYPE); String pkcs12Path = TestConfigurationProvider.getResourceLocation("IS") + File.separator + "sp" + File.separator + "keystores" + File.separator + "sp1KeyStore.p12"; String pkcs12Password = "wso2carbon"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java index 9d6453fcddf..7169db317be 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2RequestObjectSignatureValidationTestCase.java @@ -42,6 +42,7 @@ import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; +import org.wso2.carbon.utils.security.KeystoreUtils; import org.wso2.identity.integration.common.utils.ISIntegrationTest; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; @@ -282,7 +283,7 @@ private String buildSignedJWT(String consumerKey, RSAPrivateKey privateKey) thro private void initServiceProviderKeys() throws Exception { - KeyStore keyStore = KeyStore.getInstance(ISIntegrationTest.KEYSTORE_TYPE); + KeyStore keyStore = KeystoreUtils.getKeystoreInstance(ISIntegrationTest.KEYSTORE_TYPE); String pkcs12Path = TestConfigurationProvider.getResourceLocation("IS") + File.separator + "sp" + File.separator + "keystores" + File.separator + "sp1KeyStore.p12"; String pkcs12Password = "wso2carbon"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java index d1c411d748d..2bebaf37f0a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthzCodeIdTokenValidationTestCase.java @@ -53,6 +53,7 @@ import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; +import org.wso2.carbon.utils.security.KeystoreUtils; import org.wso2.identity.integration.common.utils.ISIntegrationTest; import org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; @@ -278,7 +279,7 @@ private String getLocationHeaderValue(HttpResponse response) { private void initServiceProviderKeys() throws Exception { - KeyStore keyStore = KeyStore.getInstance(ISIntegrationTest.KEYSTORE_TYPE); + KeyStore keyStore = KeystoreUtils.getKeystoreInstance(ISIntegrationTest.KEYSTORE_TYPE); String pkcs12Path = TestConfigurationProvider.getResourceLocation("IS") + File.separator + "sp" + File.separator + "keystores" + File.separator + "sp1KeyStore.p12"; String pkcs12Password = "wso2carbon"; diff --git a/product-scenarios/scenarios-commons/src/main/java/org/wso2/identity/scenarios/commons/security/SSOAgentX509KeyStoreCredential.java b/product-scenarios/scenarios-commons/src/main/java/org/wso2/identity/scenarios/commons/security/SSOAgentX509KeyStoreCredential.java index f851937f32c..cde78f46c19 100644 --- a/product-scenarios/scenarios-commons/src/main/java/org/wso2/identity/scenarios/commons/security/SSOAgentX509KeyStoreCredential.java +++ b/product-scenarios/scenarios-commons/src/main/java/org/wso2/identity/scenarios/commons/security/SSOAgentX509KeyStoreCredential.java @@ -98,7 +98,7 @@ protected void readX509Credentials(InputStream keyStoreInputStream, char[] keySt char[] privateKeyPassword) throws Exception { try { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); + KeyStore keyStore = KeystoreUtils.getKeystoreInstance("PKCS12"); keyStore.load(keyStoreInputStream, keyStorePassword); readX509Credentials(keyStore, publicCertAlias, privateKeyAlias, privateKeyPassword); } catch (Exception e) {