Skip to content

Commit 64642a1

Browse files
committed
handled null pointer
1 parent c084b83 commit 64642a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

0 commit comments

Comments
 (0)