Skip to content

Commit

Permalink
Check callbackHandler/keystorePath for null
Browse files Browse the repository at this point in the history
before using it.
  • Loading branch information
Flowdalic committed Jan 23, 2016
1 parent d5c7eb7 commit e0cbb95
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;

import java.io.BufferedReader;
Expand Down Expand Up @@ -675,6 +676,8 @@ private void proceedTLSReceived() throws NoSuchAlgorithmException, CertificateEx

if (context == null) {
final String keyStoreType = config.getKeystoreType();
final CallbackHandler callbackHandler = config.getCallbackHandler();
final String keystorePath = config.getKeystorePath();
if ("PKCS11".equals(keyStoreType)) {
try {
Constructor<?> c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class);
Expand All @@ -684,7 +687,7 @@ private void proceedTLSReceived() throws NoSuchAlgorithmException, CertificateEx
Security.addProvider(p);
ks = KeyStore.getInstance("PKCS11",p);
pcb = new PasswordCallback("PKCS11 Password: ",false);
this.config.getCallbackHandler().handle(new Callback[]{pcb});
callbackHandler.handle(new Callback[]{pcb});
ks.load(null,pcb.getPassword());
}
catch (Exception e) {
Expand All @@ -700,14 +703,16 @@ else if ("Apple".equals(keyStoreType)) {
}
else if (keyStoreType != null){
ks = KeyStore.getInstance(keyStoreType);
try {
pcb = new PasswordCallback("Keystore Password: ",false);
config.getCallbackHandler().handle(new Callback[]{pcb});
ks.load(new FileInputStream(config.getKeystorePath()), pcb.getPassword());
}
catch(Exception e) {
LOGGER.log(Level.WARNING, "Exception", e);
ks = null;
if (callbackHandler != null && StringUtils.isNotEmpty(keystorePath)) {
try {
pcb = new PasswordCallback("Keystore Password: ", false);
callbackHandler.handle(new Callback[] { pcb });
ks.load(new FileInputStream(keystorePath), pcb.getPassword());
}
catch (Exception e) {
LOGGER.log(Level.WARNING, "Exception", e);
ks = null;
}
}
}

Expand Down

0 comments on commit e0cbb95

Please sign in to comment.