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

Improve keystore configuration retrieval. #170

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 @@ -35,6 +35,7 @@
import org.wso2.carbon.identity.application.authenticator.samlsso.util.SSOErrorConstants.ErrorMessages;
import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.security.KeystoreUtils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -121,13 +122,10 @@ public X509CredentialImpl(String tenantDomain, String idpCert) throws SAMLSSOExc
*/
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
FrameworkUtils.startTenantFlow(tenantDomain);
// derive key store name
String ksName = tenantDomain.trim().replace(".", "-");
// derive JKS name
String jksName = ksName + ".jks";
String fileName = KeystoreUtils.getKeyStoreFileLocation(tenantDomain);
key =
(PrivateKey) keyStoreManager.getPrivateKey(jksName, tenantDomain);
cert = (X509Certificate) keyStoreManager.getKeyStore(jksName)
(PrivateKey) keyStoreManager.getPrivateKey(fileName, tenantDomain);
cert = (X509Certificate) keyStoreManager.getKeyStore(fileName)
.getCertificate(tenantDomain);
} else {
if (isSignKeyStoreConfigured()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;
import org.wso2.carbon.utils.security.KeystoreUtils;

import java.security.Key;
import java.security.KeyStore;
Expand All @@ -59,7 +60,7 @@
* Unit tests for X509CredentialImpl.
*/
@PowerMockIgnore({"org.mockito.*","org.powermock.api.mockito.invocation.*"})
@PrepareForTest({KeyStoreManager.class, FrameworkUtils.class})
@PrepareForTest({KeyStoreManager.class, FrameworkUtils.class, KeystoreUtils.class})
public class X509CredentialImplTest {

@Mock
Expand Down Expand Up @@ -101,6 +102,12 @@ public void initTest() throws Exception {
TestConstants.IDP_CERTIFICATE);
}

private void prepareForGetKeyStorePath() throws Exception {
mockStatic(KeystoreUtils.class);
when(KeystoreUtils.getKeyStoreFileLocation(TestConstants.SAMPLE_TENANT_DOMAIN_NAME)).thenReturn(
TestUtils.getFilePath("wso2carbon.jks"));
}

@Test(priority = 1)
public void testX509CredentialImplForSuperTenant() throws Exception {

Expand Down Expand Up @@ -132,6 +139,7 @@ public void testX509CredentialImplForATenant() throws Exception {
when(tenantKeyStoreManager.getPrivateKey(anyString(), anyString())).thenReturn(key);
when(tenantKeyStoreManager.getKeyStore(anyString())).thenReturn(keyStore);
keyStore.setCertificateEntry(TestConstants.SAMPLE_TENANT_DOMAIN_NAME, certificate);
prepareForGetKeyStorePath();

X509Credential x509Credential = new X509CredentialImpl(TestConstants.SAMPLE_TENANT_DOMAIN_NAME, "");

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<identity.outbound.auth.samlsso.imp.pkg.version.range>[1.0.0, 2.0.0)</identity.outbound.auth.samlsso.imp.pkg.version.range>

<!--Carbon Kernel Version-->
<carbon.kernel.version>4.9.17</carbon.kernel.version>
<carbon.kernel.version>4.9.23</carbon.kernel.version>
<carbon.kernel.feature.version>4.9.0</carbon.kernel.feature.version>
<carbon.kernel.imp.pkg.version.range>[4.4.0, 5.0.0)</carbon.kernel.imp.pkg.version.range>
<carbon.user.api.imp.pkg.version.range>[1.0.1, 2.0.0)</carbon.user.api.imp.pkg.version.range>
Expand Down
Loading