Skip to content

Commit b9af481

Browse files
committed
modified the code in MerchantConfig,SecurityUtil java file to enable reloading of cacerts file content at runtime.Also modified README and cybs.properties file description inside
1 parent d5ac7ae commit b9af481

File tree

7 files changed

+29
-43
lines changed

7 files changed

+29
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +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-
- If `enableCacerts` is set to true, certificates will be read from the cacerts folder under the " %JAVA_HOME\jre\lib\security ".
64-
Also point keysDirectory to " %JAVA_HOME\\jre\\lib\\security " and keyFilename=cacerts .
63+
- If enableCacert property is enabled then it means the certificates are kept under the keysDirectory path.
64+
By default, keysDirectory path is set to Java Installation cacerts location.
6565
- 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
6666
- `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.
6767
- Set integer values for config parameter `numberOfRetries` *and* `retryInterval`. Retry Interval is time delay for next retry in seconds.

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,12 @@ public MerchantConfig(Properties _props, String _merchantID)
330330
}
331331
}
332332
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-
}
333+
if(StringUtils.isBlank(keysDirectory)){
334+
keysDirectory = System.getProperty("java.home") + "/lib/security".replace('/', File.separatorChar);
335+
}
336+
if(StringUtils.isBlank(keyFilename)){
337+
keyFilename = "cacerts";
338+
}
342339
}
343340
}
344341

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void loadMerchantP12File(MerchantConfig merchantConfig, Logger log
101101
}
102102
else if(merchantConfig.isCacertEnabled()){
103103
logger.log(Logger.LT_INFO," Loading the certificate from JRE security cacert file");
104-
SecurityUtil.readJdkCert(merchantConfig,logger);
104+
SecurityUtil.loadJavaKeystore(merchantConfig,logger);
105105
}
106106
else{
107107
logger.log(Logger.LT_INFO,"Loading the certificate from p12 file ");
@@ -265,18 +265,11 @@ public static Document createSignedDoc(Document workingDocument,String merchantI
265265
}
266266

267267

268-
public static void readJdkCert(MerchantConfig merchantConfig, Logger logger) throws SignEncryptException, SignException{
268+
public static void readJdkCert(MerchantConfig merchantConfig, Logger logger) throws SignEncryptException, SignException, ConfigException{
269269
KeyStore keystore=null;
270270

271271
String pass=merchantConfig.getKeyPassword();
272272

273-
if (merchantConfig.isCacertEnabled()){
274-
String path = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
275-
loadJavaKeystore(path, merchantConfig,logger);
276-
277-
}
278-
279-
else{
280273
try{
281274
FileInputStream is = new FileInputStream(merchantConfig.getKeyFile());
282275
keystore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -326,13 +319,13 @@ public static void readJdkCert(MerchantConfig merchantConfig, Logger logger) thr
326319
logger.log(Logger.LT_EXCEPTION, "Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
327320
throw new SignException(e);
328321
}
329-
}
322+
330323
}
331324

332-
private static void loadJavaKeystore(String keystore_location, MerchantConfig merchantConfig,Logger logger) throws SignException, SignEncryptException{
325+
private static void loadJavaKeystore(MerchantConfig merchantConfig,Logger logger) throws SignException, SignEncryptException, ConfigException{
333326
FileInputStream is = null;
334327
try {
335-
File file = new File(keystore_location);
328+
File file = new File(merchantConfig.getKeyFile().getCanonicalPath());
336329
is = new FileInputStream(file);
337330
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
338331
String password = merchantConfig.getCacertPassword();

java/src/main/resources/cybs.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ retryInterval=5
3232
#customHttpClassEnabled=
3333
#customHttpClass=
3434

35-
# If This property is set to true then the p12 certificate must be stored in JKS format
36-
# program will read it from there. If it is set to false then the certificate will be read from
37-
# the location specified above from the key directory location
35+
# If enableJdkCert property is set to true then the p12 certificate must be stored in JKS format.
36+
# program will read it from keysDirectory path.
3837
enableJdkCert=false
3938

40-
# 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.
39+
# If enableCacert property is enabled then it means the certificates are kept under the keysDirectory path.
40+
# By default, keysDirectory path set to Java Installation cacerts location
4241
enableCacert=false
4342
# Enter the password for cacert file. Default password for JDK cacert is changeit
4443
cacertPassword=

java/src/test/resources/test_cybs.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ retryInterval=5
3030
#customHttpClassEnabled=
3131
#customHttpClass=
3232

33-
# If This property is set to true then the p12 certificate must be stored in JKS format
34-
# program will read it from there. If it is set to false then the certificate will be read from
35-
# the location specified above from the key directory location
33+
# If enableJdkCert property is set to true then the p12 certificate must be stored in JKS format.
34+
# program will read it from keysDirectory path.
3635
enableJdkCert=false
3736

38-
# 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.
37+
# If enableCacert property is enabled then it means the certificates are kept under the keysDirectory path.
38+
# By default, keysDirectory path set to Java Installation cacerts location
4039
enableCacert=false
4140
# Enter the password for cacert file. Default password for JDK cacert is changeit
4241
cacertPassword=

samples/nvp/cybs.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ retryInterval=5
3333
#customHttpClassEnabled=
3434
#customHttpClass=
3535

36-
# If This property is set to true then the p12 certificate must be stored in JKS format
37-
# program will read it from there. If it is set to false then the certificate will be read from
38-
# the location specified above from the key directory location
36+
# If enableJdkCert property is set to true then the p12 certificate must be stored in JKS format.
37+
# program will read it from keysDirectory path.
3938
enableJdkCert=false
4039

41-
# 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.
40+
# If enableCacert property is enabled then it means the certificates are kept under the keysDirectory path.
41+
# By default, keysDirectory path set to Java Installation cacerts location
4342
enableCacert=false
4443
# Enter the password for cacert file. Default password for JDK cacert is changeit
4544
cacertPassword=

samples/xml/cybs.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ retryInterval=5
3333
#customHttpClassEnabled=
3434
#customHttpClass=
3535

36-
# If This property is set to true then the p12 certificate must be stored in JKS format
37-
# program will read it from there. If it is set to false then the certificate will be read from
38-
# the location specified above from the key directory location
36+
# If enableJdkCert property is set to true then the p12 certificate must be stored in JKS format.
37+
# program will read it from keysDirectory path.
3938
enableJdkCert=false
4039

41-
# 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.
40+
# If enableCacert property is enabled then it means the certificates are kept under the keysDirectory path.
41+
# By default, keysDirectory path set to Java Installation cacerts location
4342
enableCacert=false
4443
# Enter the password for cacert file. Default password for JDK cacert is changeit
4544
cacertPassword=

0 commit comments

Comments
 (0)