diff --git a/src/java/davmail/http/DavGatewaySSLProtocolSocketFactory.java b/src/java/davmail/http/DavGatewaySSLProtocolSocketFactory.java index 194af841..c4b21287 100644 --- a/src/java/davmail/http/DavGatewaySSLProtocolSocketFactory.java +++ b/src/java/davmail/http/DavGatewaySSLProtocolSocketFactory.java @@ -27,14 +27,12 @@ import org.apache.commons.httpclient.params.HttpConnectionParams; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; -import sun.security.pkcs11.SunPKCS11; import javax.net.ssl.*; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.UnsupportedCallbackException; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.InetAddress; import java.net.MalformedURLException; @@ -81,8 +79,7 @@ public class DavGatewaySSLProtocolSocketFactory implements SecureProtocolSocketF if (pkcs11Config != null && pkcs11Config.length() > 0) { pkcs11Buffer.append(pkcs11Config).append('\n'); } - Provider p = new SunPKCS11(new ByteArrayInputStream(pkcs11Buffer.toString().getBytes())); - Security.addProvider(p); + SunPKCS11ProviderHandler.registerProvider(pkcs11Buffer.toString()); } KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(/*KeyManagerFactory.getDefaultAlgorithm()*/"NewSunX509"); diff --git a/src/java/davmail/http/SunPKCS11ProviderHandler.java b/src/java/davmail/http/SunPKCS11ProviderHandler.java new file mode 100644 index 00000000..e36a5158 --- /dev/null +++ b/src/java/davmail/http/SunPKCS11ProviderHandler.java @@ -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); + } + +}