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

Add BC provider to integration tests #21638

Merged
merged 2 commits into from
Nov 11, 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 @@ -18,6 +18,7 @@

package org.wso2.identity.integration.test;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.testng.annotations.Test;
import org.wso2.identity.integration.test.util.Utils;

Expand All @@ -27,5 +28,10 @@ public class IdentityServerTestSuitInitializerTestCase {
public void testInitialize() throws Exception {
//save the carbon.home system property
Utils.getResidentCarbonHome();
//add BC provider
BouncyCastleProvider bouncyCastleProvider = new BouncyCastleProvider();
if (java.security.Security.getProvider(bouncyCastleProvider.getName()) == null) {
java.security.Security.addProvider(bouncyCastleProvider);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,14 @@
import org.testng.annotations.BeforeClass;
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;
import org.wso2.identity.integration.test.utils.DataExtractUtil;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.text.ParseException;
Expand All @@ -85,10 +77,6 @@
*/
public class OAuth2IDTokenEncryptionTestCase extends OAuth2ServiceAbstractIntegrationTest {

private RSAPrivateKey spPrivateKey;

private X509Certificate spX509PublicCert;

private static final String CALLBACK_URL = "https://localhost/callback";
private static final String ENCRYPTION_ALGORITHM = "RSA-OAEP";
private static final String ENCRYPTION_METHOD = "A256GCM";
Expand Down Expand Up @@ -437,30 +425,6 @@ private String getLocationHeaderValue(HttpResponse response) {
return location.getValue();
}

/**
* Initiate service provider keys required for the tests.
*
* @throws Exception If an error occurred while getting certificate.
*/
private void initServiceProviderKeys() throws Exception {

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";

keyStore.load(Files.newInputStream(Paths.get(pkcs12Path)), pkcs12Password.toCharArray());

String alias = "wso2carbon";
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias,
new KeyStore.PasswordProtection(pkcs12Password.toCharArray()));
spPrivateKey = (RSAPrivateKey) pkEntry.getPrivateKey();

// Load certificate chain
Certificate[] chain = keyStore.getCertificateChain(alias);
spX509PublicCert = (X509Certificate) chain[0];
}

/**
* Sends a log in post to the IS instance and extract and return the sessionDataKeyConsent from the response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ private String buildSignedJWT(String consumerKey, RSAPrivateKey privateKey) thro
return signedJWT.serialize();
}

private void initServiceProviderKeys() throws Exception {
@Override
protected void initServiceProviderKeys() throws Exception {

KeyStore keyStore = KeystoreUtils.getKeystoreInstance(ISIntegrationTest.KEYSTORE_TYPE);
String pkcs12Path = TestConfigurationProvider.getResourceLocation("IS") + File.separator + "sp" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider;
import org.wso2.carbon.identity.application.common.model.xsd.Claim;
import org.wso2.carbon.identity.application.common.model.xsd.Property;
import org.wso2.carbon.identity.application.common.model.xsd.*;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.utils.security.KeystoreUtils;
import org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient;
import org.wso2.identity.integration.common.clients.oauth.OauthAdminClient;
import org.wso2.identity.integration.common.clients.usermgt.remote.RemoteUserStoreManagerServiceClient;
Expand Down Expand Up @@ -78,11 +80,15 @@
import org.wso2.identity.integration.test.restclients.OAuth2RestClient;
import org.wso2.identity.integration.test.util.Utils;
import org.wso2.identity.integration.test.utils.OAuth2Constant;
import sun.security.provider.X509Factory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -109,6 +115,8 @@ public class OAuth2ServiceAbstractIntegrationTest extends ISIntegrationTest {
private static final String customClaimURI2 = "http://wso2.org/claims/stateorprovince";
private static final String GRANT_TYPE_PASSWORD = "password";
private static final String SCOPE_PRODUCTION = "PRODUCTION";
private static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
private static final String END_CERT = "-----END CERTIFICATE-----";
public static final String OIDC = "oidc";
public static final String SAML = "saml";
private final static int TOMCAT_PORT = 8490;
Expand All @@ -117,6 +125,8 @@ public class OAuth2ServiceAbstractIntegrationTest extends ISIntegrationTest {
protected OauthAdminClient adminClient;
protected RemoteUserStoreManagerServiceClient remoteUSMServiceClient;
protected OAuth2RestClient restClient;
protected RSAPrivateKey spPrivateKey;
protected X509Certificate spX509PublicCert;


/**
Expand Down Expand Up @@ -903,10 +913,8 @@ public void updateApplicationCertificate(String appId, X509Certificate sp1X509Pu
*/
public String convertToPem(X509Certificate x509Certificate) throws CertificateEncodingException {

String certBegin = X509Factory.BEGIN_CERT;
String endCert = X509Factory.END_CERT;
String pemCert = new String(java.util.Base64.getEncoder().encode(x509Certificate.getEncoded()));
return certBegin + pemCert + endCert;
String pemCert = new String(java.util.Base64.getEncoder().encode(x509Certificate.getEncoded()));
return BEGIN_CERT + pemCert + END_CERT;
}

/**
Expand Down Expand Up @@ -1273,4 +1281,23 @@ private ClaimConfiguration buildClaimConfigurationForRequestedClaims(List<UserCl

return claimConfiguration;
}

protected void initServiceProviderKeys() throws Exception {

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";

keyStore.load(Files.newInputStream(Paths.get(pkcs12Path)), pkcs12Password.toCharArray());

String alias = "wso2carbon";
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias,
new KeyStore.PasswordProtection(pkcs12Password.toCharArray()));
spPrivateKey = (RSAPrivateKey) pkEntry.getPrivateKey();

// Load certificate chain
java.security.cert.Certificate[] chain = keyStore.getCertificateChain(alias);
spX509PublicCert = (X509Certificate) chain[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.hamcrest.collection.IsIn;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
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.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;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel;
Expand All @@ -65,15 +61,9 @@
import org.wso2.identity.integration.test.utils.OAuth2Constant;
import org.wso2.identity.integration.test.utils.UserUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -83,8 +73,6 @@
public class OIDCAuthzCodeIdTokenValidationTestCase extends OAuth2ServiceAbstractIntegrationTest {

public static final String TEST_NONCE = "test_nonce";
private RSAPrivateKey spPrivateKey;
private X509Certificate spX509PublicCert;
private static final String CALLBACK_URL = "https://localhost/callback";
private CloseableHttpClient client;
private String sessionDataKey;
Expand Down Expand Up @@ -276,23 +264,4 @@ private String getLocationHeaderValue(HttpResponse response) {
Assert.assertNotNull(location);
return location.getValue();
}

private void initServiceProviderKeys() throws Exception {

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";

keyStore.load(new FileInputStream(pkcs12Path), pkcs12Password.toCharArray());

String alias = "wso2carbon";
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias,
new KeyStore.PasswordProtection(pkcs12Password.toCharArray()));
spPrivateKey = (RSAPrivateKey) pkEntry.getPrivateKey();

// Load certificate chain
Certificate[] chain = keyStore.getCertificateChain(alias);
spX509PublicCert = (X509Certificate) chain[0];
}
}