We have 2 environments and for each we have a certificate PFX file.
I tried to import these 2 certs to make one JKS/P12 file and tried to access cert based on alias name. Though I can see 2 entries using the command
keytool -list -v -keystore "C:/yyyyy/xxxx.jks" -storepass "kdjfkdjfkdjf" > "C:/KeyStoreContents.txt"
, I am unable to access any of the cert and seeing the error 'alias not found'.
I there a way to set the values of javax.net.ssl.keyStore
and javax.net.ssl.keyStorePassword
based on application environment?
I tried to set them in beanshell pre-processor with:
System.setProperty("javax.net.ssl.keyStore","C:/yyyyy/" + pOneTwoName + ".p12");
System.setProperty("javax.net.ssl.keyStorePassword", pOneTwoPwd);
It didn't work as well.
I also tried ${__P(javax.net.ssl.keyStore, C:/yyyyyy/QA.p12)}
and ${__setProperty(javax.net.ssl.keyStore, C:/yyyyyy/QA.p12)}
and none of the above worked.
Is there a way to load these values dynamically before Keystore Configuration
element gets executed?
I am able to solve this issue with the below steps:
Set a meaningful alias names to these certs with the below command:
keytool -changealias -alias "ExistingAliasName" -destalias "AppName_Environment" -keystore "C:\JKS\AppName_environment.p12" -storepass "StorePassword"
Notes for step 3:
a. It might ask to enter keypass and we can enter the store pass
b. Even we provide upper case in alias name, the text will be converted to lower case and will be set as alias name
c. Here I followed this alias naming convention: application name_environment name as mentioned in JMeter
Import the certs into a JKS file and we can set any password to JKS and need not be same as cert. See the below command:
keytool -importkeystore -srckeystore "C:\ JKS\ AppName _ Environment.p12" -srcstoretype pkcs12 -srcstorepass "SourceStorePasword” -destkeystore "C:\HomesiteJKS\BungalowFinal.jks" -deststoretype JKS -storepass "JKSPassword"
Once we have the final JKS, we can start changing password for each of the cert in JKS and make it same as JKS(keystore) password. See the below command:
keytool -keypasswd -alias " AppName_Environment" -keystore “C:\JKS\Final.jks"
Note for step 6: It will ask you to enter keystore password, existing cert password, new password and repeat new password
Now we can use this file and add below entries in system.properties of JMeter:
javax.net.ssl.keyStore=C:/JKS/Final.jks
javax.net.ssl.keyStorePassword=JKSPassword
Add the below entry either in user.properties or jmeter.properties of JMeter, which will allow us to use multiple certs from JKS file:
https.use.cached.ssl.context=false
HttpClient4
Add Keystore configuration element to JMeter test with the below values:
a. Preload: True
b. Variable name holding certificate alias: CertAlias
c. Alias Start index: 0
d. Alias End index: 10000