mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 05:22:06 +01:00
Check callbackHandler/keystorePath for null
before using it.
This commit is contained in:
parent
d5c7eb7349
commit
e0cbb95b5d
1 changed files with 14 additions and 9 deletions
|
@ -91,6 +91,7 @@ import javax.net.ssl.KeyManagerFactory;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import javax.security.auth.callback.Callback;
|
import javax.security.auth.callback.Callback;
|
||||||
|
import javax.security.auth.callback.CallbackHandler;
|
||||||
import javax.security.auth.callback.PasswordCallback;
|
import javax.security.auth.callback.PasswordCallback;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -675,6 +676,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
|
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
final String keyStoreType = config.getKeystoreType();
|
final String keyStoreType = config.getKeystoreType();
|
||||||
|
final CallbackHandler callbackHandler = config.getCallbackHandler();
|
||||||
|
final String keystorePath = config.getKeystorePath();
|
||||||
if ("PKCS11".equals(keyStoreType)) {
|
if ("PKCS11".equals(keyStoreType)) {
|
||||||
try {
|
try {
|
||||||
Constructor<?> c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class);
|
Constructor<?> c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class);
|
||||||
|
@ -684,7 +687,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
Security.addProvider(p);
|
Security.addProvider(p);
|
||||||
ks = KeyStore.getInstance("PKCS11",p);
|
ks = KeyStore.getInstance("PKCS11",p);
|
||||||
pcb = new PasswordCallback("PKCS11 Password: ",false);
|
pcb = new PasswordCallback("PKCS11 Password: ",false);
|
||||||
this.config.getCallbackHandler().handle(new Callback[]{pcb});
|
callbackHandler.handle(new Callback[]{pcb});
|
||||||
ks.load(null,pcb.getPassword());
|
ks.load(null,pcb.getPassword());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -700,14 +703,16 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
}
|
}
|
||||||
else if (keyStoreType != null){
|
else if (keyStoreType != null){
|
||||||
ks = KeyStore.getInstance(keyStoreType);
|
ks = KeyStore.getInstance(keyStoreType);
|
||||||
try {
|
if (callbackHandler != null && StringUtils.isNotEmpty(keystorePath)) {
|
||||||
pcb = new PasswordCallback("Keystore Password: ",false);
|
try {
|
||||||
config.getCallbackHandler().handle(new Callback[]{pcb});
|
pcb = new PasswordCallback("Keystore Password: ", false);
|
||||||
ks.load(new FileInputStream(config.getKeystorePath()), pcb.getPassword());
|
callbackHandler.handle(new Callback[] { pcb });
|
||||||
}
|
ks.load(new FileInputStream(keystorePath), pcb.getPassword());
|
||||||
catch(Exception e) {
|
}
|
||||||
LOGGER.log(Level.WARNING, "Exception", e);
|
catch (Exception e) {
|
||||||
ks = null;
|
LOGGER.log(Level.WARNING, "Exception", e);
|
||||||
|
ks = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue