1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 14:02:06 +01:00

Checking for PKCS support in java and punting if it doesn't exist.

Using bytestream config instead of full config.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@9689 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Daniel Henninger 2007-12-27 16:15:57 +00:00 committed by dhenninger
parent 048e5b679c
commit 5c92ced702

View file

@ -37,7 +37,6 @@ import javax.net.ssl.KeyManager;
import java.io.*; import java.io.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Collection; import java.util.Collection;
@ -1316,12 +1315,21 @@ public class XMPPConnection {
pcb = null; pcb = null;
} }
else if(configuration.getKeystoreType().equals("PKCS11")) { else if(configuration.getKeystoreType().equals("PKCS11")) {
Provider p = new sun.security.pkcs11.SunPKCS11(configuration.getPKCSConfig()); try {
Security.addProvider(p); Constructor c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(String.class);
ks = KeyStore.getInstance("PKCS11",p); String pkcs11Config = "name = SmartCard\nlibrary = "+configuration.getPKCSConfig();
pcb = new PasswordCallback("PKCS11 Password: ",false); ByteArrayInputStream config = new ByteArrayInputStream(pkcs11Config.getBytes());
callbackHandler.handle(new Callback[]{pcb}); Provider p = (Provider)c.newInstance(config);
ks.load(null,pcb.getPassword()); Security.addProvider(p);
ks = KeyStore.getInstance("PKCS11",p);
pcb = new PasswordCallback("PKCS11 Password: ",false);
callbackHandler.handle(new Callback[]{pcb});
ks.load(null,pcb.getPassword());
}
catch (Exception e) {
ks = null;
pcb = null;
}
} }
else if(configuration.getKeystoreType().equals("Apple")) { else if(configuration.getKeystoreType().equals("Apple")) {
ks = KeyStore.getInstance("KeychainStore","Apple"); ks = KeyStore.getInstance("KeychainStore","Apple");
@ -1331,15 +1339,15 @@ public class XMPPConnection {
} }
else { else {
ks = KeyStore.getInstance(configuration.getKeystoreType()); ks = KeyStore.getInstance(configuration.getKeystoreType());
try { try {
ks.load(new FileInputStream(configuration.getKeystorePath()), pcb.getPassword()); ks.load(new FileInputStream(configuration.getKeystorePath()), pcb.getPassword());
pcb = new PasswordCallback("Keystore Password: ",false); pcb = new PasswordCallback("Keystore Password: ",false);
callbackHandler.handle(new Callback[]{pcb}); callbackHandler.handle(new Callback[]{pcb});
} }
catch(Exception e) { catch(Exception e) {
ks = null; ks = null;
pcb = null; pcb = null;
} }
} }
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
try { try {