mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +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,16 +703,18 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
}
|
}
|
||||||
else if (keyStoreType != null){
|
else if (keyStoreType != null){
|
||||||
ks = KeyStore.getInstance(keyStoreType);
|
ks = KeyStore.getInstance(keyStoreType);
|
||||||
|
if (callbackHandler != null && StringUtils.isNotEmpty(keystorePath)) {
|
||||||
try {
|
try {
|
||||||
pcb = new PasswordCallback("Keystore Password: ",false);
|
pcb = new PasswordCallback("Keystore Password: ", false);
|
||||||
config.getCallbackHandler().handle(new Callback[]{pcb});
|
callbackHandler.handle(new Callback[] { pcb });
|
||||||
ks.load(new FileInputStream(config.getKeystorePath()), pcb.getPassword());
|
ks.load(new FileInputStream(keystorePath), pcb.getPassword());
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch (Exception e) {
|
||||||
LOGGER.log(Level.WARNING, "Exception", e);
|
LOGGER.log(Level.WARNING, "Exception", e);
|
||||||
ks = null;
|
ks = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ks != null) {
|
if (ks != null) {
|
||||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
|
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
|
||||||
|
|
Loading…
Reference in a new issue