Skip to content

Commit e7a6790

Browse files
authored
Merge pull request #80 from adkumar3/future
handled null pointer
2 parents 834fb69 + 6e2003d commit e7a6790

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private static Document soapWrapAndSign(
200200
Document resultDocument = null;
201201

202202
SecurityUtil.loadMerchantP12File(mc,logger);
203-
logger.log(Logger.LT_INFO, "Client, End of loadMerchantP12File ", true);
203+
logger.log(Logger.LT_INFO, "Client, End of loading Merchant Certificates ", true);
204204

205205
// sign Document object
206206
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getMerchantID(), mc.getKeyPassword(), logger);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ public static void readJdkCert(MerchantConfig merchantConfig, Logger logger) thr
286286
String merchantKeyAlias = null;
287287
try {
288288
Enumeration enumKeyStore = keystore.aliases();
289+
if(!enumKeyStore.hasMoreElements()){
290+
throw new SignException("Empty Keystore or Missing Certificate ");
291+
}
289292
while (enumKeyStore.hasMoreElements()) {
290293
KeyStore.PrivateKeyEntry keyEntry = null;
291294
merchantKeyAlias = (String) enumKeyStore.nextElement();
@@ -332,7 +335,9 @@ private static void loadJavaKeystore(String keystore_location, MerchantConfig me
332335
Identity identity;
333336

334337
java.security.cert.Certificate[] cert = keystore.getCertificateChain(merchantConfig.getKeyAlias());
335-
338+
if (cert == null) {
339+
throw new SignException("Empty Keystore or Missing Certificate ");
340+
}
336341
PrivateKey key = null;
337342
try {
338343
key = (PrivateKey)keystore.getKey(merchantConfig.getKeyAlias(), merchantConfig.getKeyAlias().toCharArray());
@@ -361,6 +366,9 @@ private static void loadJavaKeystore(String keystore_location, MerchantConfig me
361366
}
362367
}
363368
java.security.cert.Certificate serverCert = keystore.getCertificate(SERVER_ALIAS);
369+
if(serverCert == null){
370+
throw new SignException("Missing Server Certificate ");
371+
}
364372
identity = new Identity(merchantConfig,
365373
(X509Certificate) serverCert);
366374
localKeyStoreHandler

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ private static Document soapWrapAndSign(
342342
Document resultDocument = null;
343343

344344
SecurityUtil.loadMerchantP12File(mc,logger);
345-
logger.log(Logger.LT_INFO, "Client, End of loadMerchantP12File ", true);
345+
logger.log(Logger.LT_INFO, "Client, End of loading Merchant Certificate ", true);
346346

347347
// sign Document object
348348
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword(),logger);

0 commit comments

Comments
 (0)