Skip to content

Commit

Permalink
Merge pull request #21623 from hwupathum/pkcs12integration
Browse files Browse the repository at this point in the history
Use getKeystoreInstance from KeystoreUtils
  • Loading branch information
hwupathum authored Nov 6, 2024
2 parents bba0ec6 + 78e6367 commit cbd2c6d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> aliases = store.aliases();
while (aliases.hasMoreElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
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 = KeyStore.getInstance("PKCS12");
KeyStore keyStore = KeystoreUtils.getKeystoreInstance("PKCS12");
keyStore.load(keyStoreInputStream, keyStorePassword);
readX509Credentials(keyStore, publicCertAlias, privateKeyAlias, privateKeyPassword);
} catch (Exception e) {
Expand Down

0 comments on commit cbd2c6d

Please sign in to comment.