Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientSslProtocolSocketFactory.java54
1 files changed, 36 insertions, 18 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientSslProtocolSocketFactory.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientSslProtocolSocketFactory.java
index 9dc843170..c64dfa81f 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientSslProtocolSocketFactory.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientSslProtocolSocketFactory.java
@@ -13,24 +13,23 @@ package org.eclipse.ecf.provider.filetransfer.httpclient;
import java.io.IOException;
import java.net.*;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
+import javax.net.ssl.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.util.Proxy;
import org.eclipse.ecf.core.util.ProxyAddress;
-import org.eclipse.ecf.internal.provider.filetransfer.httpclient.Activator;
-import org.eclipse.ecf.internal.provider.filetransfer.httpclient.Messages;
/**
*
*/
public class HttpClientSslProtocolSocketFactory implements ProtocolSocketFactory {
- private SSLContext sslContext;
+ public static final String DEFAULT_SSL_PROTOCOL = "https.protocols"; //$NON-NLS-1$
+
+ private SSLContext sslContext = null;
+
+ private String defaultProtocolNames = System.getProperty(DEFAULT_SSL_PROTOCOL);
private Proxy proxy;
@@ -38,29 +37,48 @@ public class HttpClientSslProtocolSocketFactory implements ProtocolSocketFactory
this.proxy = proxy;
}
- private SSLContext getSslContext() {
- if (sslContext == null) {
+ private SSLSocketFactory getSSLSocketFactory() throws IOException {
+ if (null == sslContext) {
try {
- sslContext = SSLContext.getInstance("SSL"); //$NON-NLS-1$
- sslContext.init(null, new TrustManager[] {new HttpClientSslTrustManager()}, null);
+ sslContext = getSSLContext(defaultProtocolNames);
} catch (Exception e) {
- Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1111, Messages.SslProtocolSocketFactory_Status_Create_Error, e));
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+ return (sslContext == null) ? (SSLSocketFactory) SSLSocketFactory.getDefault() : sslContext.getSocketFactory();
+ }
+
+ public SSLContext getSSLContext(String protocols) {
+ SSLContext rtvContext = null;
+
+ if (protocols != null) {
+ String protocolNames[] = protocols.split(","); //$NON-NLS-1$
+ for (int i = 0; i < protocolNames.length; i++) {
+ try {
+ rtvContext = SSLContext.getInstance(protocolNames[i]);
+ sslContext.init(null, new TrustManager[] {new HttpClientSslTrustManager()}, null);
+ break;
+ } catch (Exception e) {
+ // just continue
+ }
}
}
- return sslContext;
+ return rtvContext;
}
public Socket createSocket(String remoteHost, int remotePort) throws IOException, UnknownHostException {
- return getSslContext().getSocketFactory().createSocket(remoteHost, remotePort);
+ return getSSLSocketFactory().createSocket(remoteHost, remotePort);
}
public Socket createSocket(String remoteHost, int remotePort, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException {
- return getSslContext().getSocketFactory().createSocket(remoteHost, remotePort, clientHost, clientPort);
+ return getSSLSocketFactory().createSocket(remoteHost, remotePort, clientHost, clientPort);
}
public Socket createSocket(String remoteHost, int remotePort, InetAddress clientHost, int clientPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (params == null || params.getConnectionTimeout() == 0)
- return getSslContext().getSocketFactory().createSocket(remoteHost, remotePort, clientHost, clientPort);
+ return getSSLSocketFactory().createSocket(remoteHost, remotePort, clientHost, clientPort);
if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
ProxyClient proxyClient = new ProxyClient();
@@ -79,12 +97,12 @@ public class HttpClientSslProtocolSocketFactory implements ProtocolSocketFactory
ProxyClient.ConnectResponse response = proxyClient.connect();
if (response.getSocket() != null) {
// tunnel SSL via the resultant socket
- Socket sslsocket = getSslContext().getSocketFactory().createSocket(response.getSocket(), remoteHost, remotePort, true);
+ Socket sslsocket = getSSLSocketFactory().createSocket(response.getSocket(), remoteHost, remotePort, true);
return sslsocket;
}
}
// Direct connection
- Socket socket = getSslContext().getSocketFactory().createSocket();
+ Socket socket = getSSLSocketFactory().createSocket();
socket.bind(new InetSocketAddress(clientHost, clientPort));
socket.connect(new InetSocketAddress(remoteHost, remotePort), params.getConnectionTimeout());
return socket;

Back to the top