Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getKeystoreInstance from KeystoreUtils #21623

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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