diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/IdentityServerTestSuitInitializerTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/IdentityServerTestSuitInitializerTestCase.java index fb9eda85607..bca5435c501 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/IdentityServerTestSuitInitializerTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/IdentityServerTestSuitInitializerTestCase.java @@ -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; @@ -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); + } } } 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 2b2bc5b41f0..68d0183d0b5 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 @@ -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; @@ -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"; @@ -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. * 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 7169db317be..c0ff3b95329 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 @@ -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" + diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java index d4a56857990..554c0770041 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java @@ -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; @@ -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; @@ -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; @@ -117,6 +125,8 @@ public class OAuth2ServiceAbstractIntegrationTest extends ISIntegrationTest { protected OauthAdminClient adminClient; protected RemoteUserStoreManagerServiceClient remoteUSMServiceClient; protected OAuth2RestClient restClient; + protected RSAPrivateKey spPrivateKey; + protected X509Certificate spX509PublicCert; /** @@ -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; } /** @@ -1273,4 +1281,23 @@ private ClaimConfiguration buildClaimConfigurationForRequestedClaims(List