Skip to content

Commit a45785c

Browse files
committed
Now user can load jks or cacerts file at runtime similar like p12 file
1 parent 0003987 commit a45785c

File tree

8 files changed

+27
-8
lines changed

8 files changed

+27
-8
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ You do not need to download and build the source to use the SDK but if you want
6060
- `serverURL` config parameter will take precedence over `sendToProduction` and `sendToAkamai` config parameters. By default the `serverURL` configuration is commented out.
6161
- if `enablejdkcert` parameter is set to true, certificates will be read from the JKS file specified at keysDirectory location. The JKS file should be of the same name as specified in keyFilename.
6262
- To know how to convert p12 to JKS refer the JKS creation section of this document.
63-
- `enableCacerts` property is considered only if `enablejdkcert` is set to true. If `enableCacerts` is set to true, certificates will be read from the cacerts folder under the JDK.
63+
- If `enableCacerts` is set to true, certificates will be read from the cacerts folder under the JDKxx\jre\lib\security.
64+
Also point keysDirectory to " C:\\Program Files\\Java\\jdk1.8.0_152\\jre\\lib\\security " and keyFilename=cacerts in case of windows environment
6465
- if `certificateCacheEnabled` parameter is set to false (default is true), the p12 certificate of a merchant will be reloaded from filesystem every time a transaction is made
6566
- `allowRetry` config parameter will only work for HttpClient. Set `allowRetry` config parameter to "true" to enable retry mechanism and set merchant specific values for the retry.
6667
- Set integer values for config parameter `numberOfRetries` *and* `retryInterval`. Retry Interval is time delay for next retry in seconds.
@@ -137,6 +138,10 @@ keytool -list -v -keystore <Your_keystore_name>`
137138
- It should have two entries.
138139
- The first entry should contain a chain of two certificates - `CyberSourceCertAuth` and <Merchant_ID> with alias name <Merchant_ID>
139140
- Second entry should be for `CyberSource_SJC_US` certificate with alias name as CyberSource_SJC_US
141+
-Keep the .jks file under C:\Program Files\Java\jdk1.8.0_152\jre\lib\security folder
142+
-Give full access permission to cacerts file.
143+
run the command
144+
keytool -importkeystore -alias keyfilealias -srckeystore keyfilealias.jks -keystore cacerts
140145

141146
## Message Level Encryption
142147
CyberSource supports Message Level Encryption (MLE) for Simple Order API. Message level encryption conforms to the SOAP Security 1.0 specification published by the OASIS standards group.

java/src/main/java/com/cybersource/ws/client/Identity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Lo
5757
if(this.logger == null){
5858
this.logger=logger;
5959
}
60-
if(merchantConfig.isJdkCertEnabled()){
60+
if(merchantConfig.isJdkCertEnabled() || merchantConfig.isCacertEnabled()){
6161
setupJdkServerCerts();
6262
}
6363
else{

java/src/main/java/com/cybersource/ws/client/MerchantConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ public MerchantConfig(Properties _props, String _merchantID)
329329
throw new ConfigException("Invalid value of numberOfRetries and/or retryInterval");
330330
}
331331
}
332+
if(isCacertEnabled()){
333+
String keyPath=this.getKeysDirectory();
334+
String keysFilename=this.getKeyFilename();
335+
if(!(keyPath == null)){
336+
keysDirectory=keyPath;
337+
}
338+
if(!(keysFilename == null)){
339+
keyFilename=keysFilename;
340+
341+
}
342+
}
332343
}
333344

334345
/**

java/src/main/java/com/cybersource/ws/client/SecurityUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public static void loadMerchantP12File(MerchantConfig merchantConfig, Logger log
9898
if(merchantConfig.isJdkCertEnabled()){
9999
logger.log(Logger.LT_INFO," Loading the certificate from JDK Cert");
100100
SecurityUtil.readJdkCert(merchantConfig,logger);
101+
}
102+
else if(merchantConfig.isCacertEnabled()){
103+
logger.log(Logger.LT_INFO," Loading the certificate from JRE security cacert file");
104+
SecurityUtil.readJdkCert(merchantConfig,logger);
101105
}
102106
else{
103107
logger.log(Logger.LT_INFO,"Loading the certificate from p12 file ");
@@ -264,11 +268,10 @@ public static Document createSignedDoc(Document workingDocument,String merchantI
264268
public static void readJdkCert(MerchantConfig merchantConfig, Logger logger) throws SignEncryptException, SignException{
265269
KeyStore keystore=null;
266270

267-
String path=merchantConfig.getKeysDirectory()+"/"+merchantConfig.getKeyFilename();
268271
String pass=merchantConfig.getKeyPassword();
269272

270273
if (merchantConfig.isCacertEnabled()){
271-
path = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
274+
String path = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
272275
loadJavaKeystore(path, merchantConfig,logger);
273276

274277
}

java/src/main/resources/cybs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ retryInterval=5
3838
enableJdkCert=false
3939

4040
# if Cacert property is enabled then it means the certificates are kept under the cacert folder of JDK
41-
# And it will read from JDK cert. This property will be considered only if enableJDKcert is set to true.
41+
# And it will read from JDK cert.
4242
enableCacert=false
4343
# Enter the password for cacert file. Default password for JDK cacert is changeit
4444
cacertPassword=

java/src/test/resources/test_cybs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ retryInterval=5
3636
enableJdkCert=false
3737

3838
# if Cacert property is enabled then it means the certificates are kept under the cacert folder of JDK
39-
# And it will read from JDK cert. This property will be considered only if enableJDKcert is set to true.
39+
# And it will read from JDK cert.
4040
enableCacert=false
4141
# Enter the password for cacert file. Default password for JDK cacert is changeit
4242
cacertPassword=

samples/nvp/cybs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ retryInterval=5
3939
enableJdkCert=false
4040

4141
# if Cacert property is enabled then it means the certificates are kept under the cacert folder of JDK
42-
# And it will read from JDK cert. This property will be considered only if enableJDKcert is set to true.
42+
# And it will read from JDK cert.
4343
enableCacert=false
4444
# Enter the password for cacert file. Default password for JDK cacert is changeit
4545
cacertPassword=

samples/xml/cybs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ retryInterval=5
3939
enableJdkCert=false
4040

4141
# if Cacert property is enabled then it means the certificates are kept under the cacert folder of JDK
42-
# And it will read from JDK cert. This property will be considered only if enableJDKcert is set to true.
42+
# And it will read from JDK cert.
4343
enableCacert=false
4444
# Enter the password for cacert file. Default password for JDK cacert is changeit
4545
cacertPassword=

0 commit comments

Comments
 (0)