Skip to content

Commit 3f59a96

Browse files
authored
Merge pull request #101 from ammajumd/future
Now user can load jks or cacerts file at runtime similar like p12 file
2 parents 1427b37 + d955196 commit 3f59a96

File tree

9 files changed

+40
-39
lines changed

9 files changed

+40
-39
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ You do not need to download and build the source to use the SDK but if you want
5858
- `sendToProduction` is initially set to false. Set it to true only when you are ready to send live transactions.
5959
- Set `sendToAkamai` config parameter with toggle value "true/false" to turn on/off routing requests through Akamai to Cybersource. By default, it is set to true.
6060
- `serverURL` config parameter will take precedence over `sendToProduction` and `sendToAkamai` config parameters. By default the `serverURL` configuration is commented out.
61-
- 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.
61+
- 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 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
6464
- 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
6565
- `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.
6666
- Set integer values for config parameter `numberOfRetries` *and* `retryInterval`. Retry Interval is time delay for next retry in seconds.
@@ -137,7 +137,8 @@ keytool -list -v -keystore <Your_keystore_name>`
137137
- It should have two entries.
138138
- The first entry should contain a chain of two certificates - `CyberSourceCertAuth` and <Merchant_ID> with alias name <Merchant_ID>
139139
- Second entry should be for `CyberSource_SJC_US` certificate with alias name as CyberSource_SJC_US
140-
140+
141+
141142
## Message Level Encryption
142143
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.
143144

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ public MerchantConfig(Properties _props, String _merchantID)
329329
throw new ConfigException("Invalid value of numberOfRetries and/or retryInterval");
330330
}
331331
}
332+
if(isCacertEnabled()){
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+
}
339+
}
332340
}
333341

334342
/**

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

Lines changed: 9 additions & 13 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.loadJavaKeystore(merchantConfig,logger);
101105
}
102106
else{
103107
logger.log(Logger.LT_INFO,"Loading the certificate from p12 file ");
@@ -261,21 +265,13 @@ public static Document createSignedDoc(Document workingDocument,String merchantI
261265
}
262266

263267

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

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

270-
if (merchantConfig.isCacertEnabled()){
271-
path = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
272-
loadJavaKeystore(path, merchantConfig,logger);
273-
274-
}
275-
276-
else{
277273
try{
278-
FileInputStream is = new FileInputStream(path);
274+
FileInputStream is = new FileInputStream(merchantConfig.getKeyFile());
279275
keystore = KeyStore.getInstance(KeyStore.getDefaultType());
280276
keystore.load(is, pass.toCharArray());
281277
}
@@ -323,13 +319,13 @@ public static void readJdkCert(MerchantConfig merchantConfig, Logger logger) thr
323319
logger.log(Logger.LT_EXCEPTION, "Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
324320
throw new SignException(e);
325321
}
326-
}
322+
327323
}
328324

329-
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{
330326
FileInputStream is = null;
331327
try {
332-
File file = new File(keystore_location);
328+
File file = new File(merchantConfig.getKeyFile().getCanonicalPath());
333329
is = new FileInputStream(file);
334330
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
335331
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. This property will be considered only if enableJDKcert is set to true.
39+
# If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.
40+
# If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
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. This property will be considered only if enableJDKcert is set to true.
37+
# If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.
38+
# If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
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. This property will be considered only if enableJDKcert is set to true.
40+
# If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.
41+
# If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
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. This property will be considered only if enableJDKcert is set to true.
40+
# If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.
41+
# If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
4342
enableCacert=false
4443
# Enter the password for cacert file. Default password for JDK cacert is changeit
4544
cacertPassword=

zip/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ Refer to our Developer's Guide for details <http://apps.cybersource.com/library/
6363

6464
h. "serverURL" config parameter will take precedence over sendToProduction and sendToAkamai config parameters. By default the "serverURL" configuration is commented out.
6565

66-
i. 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.
66+
i. 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.
6767
To convert p12 to JKS refer to the JKS creation section.
6868

69-
j. `cacerts` property is considered only if `enablejdkcert` is set to true. If `cacerts` is set to true, certificates will be read from the cacerts folder under the JDK.
69+
j. - If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
7070

7171
k. "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.
7272
Set integer values for config parameter numberOfRetries & retryInterval. Retry Interval is time delay for next retry in seconds. number of retry parameter should be set between

0 commit comments

Comments
 (0)