mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
Move PKCS11 registration to a separate class to avoid ClassNotFoundException
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@849 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
a01b996220
commit
19ca110e94
@ -27,14 +27,12 @@ import org.apache.commons.httpclient.params.HttpConnectionParams;
|
|||||||
import org.apache.commons.httpclient.protocol.Protocol;
|
import org.apache.commons.httpclient.protocol.Protocol;
|
||||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||||
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
|
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
|
||||||
import sun.security.pkcs11.SunPKCS11;
|
|
||||||
|
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import javax.security.auth.callback.Callback;
|
import javax.security.auth.callback.Callback;
|
||||||
import javax.security.auth.callback.CallbackHandler;
|
import javax.security.auth.callback.CallbackHandler;
|
||||||
import javax.security.auth.callback.PasswordCallback;
|
import javax.security.auth.callback.PasswordCallback;
|
||||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -81,8 +79,7 @@ public class DavGatewaySSLProtocolSocketFactory implements SecureProtocolSocketF
|
|||||||
if (pkcs11Config != null && pkcs11Config.length() > 0) {
|
if (pkcs11Config != null && pkcs11Config.length() > 0) {
|
||||||
pkcs11Buffer.append(pkcs11Config).append('\n');
|
pkcs11Buffer.append(pkcs11Config).append('\n');
|
||||||
}
|
}
|
||||||
Provider p = new SunPKCS11(new ByteArrayInputStream(pkcs11Buffer.toString().getBytes()));
|
SunPKCS11ProviderHandler.registerProvider(pkcs11Buffer.toString());
|
||||||
Security.addProvider(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(/*KeyManagerFactory.getDefaultAlgorithm()*/"NewSunX509");
|
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(/*KeyManagerFactory.getDefaultAlgorithm()*/"NewSunX509");
|
||||||
|
45
src/java/davmail/http/SunPKCS11ProviderHandler.java
Normal file
45
src/java/davmail/http/SunPKCS11ProviderHandler.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
* Copyright (C) 2009 Mickael Guessant
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package davmail.http;
|
||||||
|
|
||||||
|
import sun.security.pkcs11.SunPKCS11;
|
||||||
|
|
||||||
|
import java.security.Provider;
|
||||||
|
import java.security.Security;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the SunPKCS11 Provider.
|
||||||
|
*/
|
||||||
|
public class SunPKCS11ProviderHandler {
|
||||||
|
|
||||||
|
private SunPKCS11ProviderHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register PKCS11 provider.
|
||||||
|
*
|
||||||
|
* @param pkcs11Config PKCS11 config string
|
||||||
|
*/
|
||||||
|
public static void registerProvider(String pkcs11Config) {
|
||||||
|
Provider p = new SunPKCS11(new ByteArrayInputStream(pkcs11Config.getBytes()));
|
||||||
|
Security.addProvider(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user