File |
Line |
simplespider/simplespider/bot/http/apache/ssl/EasySSLProtocolSocketFactory.java |
56
|
simplespider/simplespider/bot/http/apache/ssl/TrustAllSSLProtocolSocketFactory.java |
56
|
context.init(null, new TrustManager[] { new TrustAllX509TrustManager(null) }, null);
return context;
} catch (final Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private SSLContext getSSLContext() {
if (this.sslcontext == null) {
this.sslcontext = createEasySSLContext();
}
return this.sslcontext;
}
/**
* @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
*/
public Socket createSocket(final String host, final int port, final InetAddress clientHost, final int clientPort) throws IOException,
UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort);
}
/**
* Attempts to get a new socket connection to the given host within the given time limit.
* <p>
* To circumvent the limitations of older JREs that do not support connect timeout a controller thread is executed. The controller thread attempts
* to create a new socket within the given limit of time. If socket constructor does not return until the timeout expires, the controller
* terminates and throws an {@link ConnectTimeoutException}
* </p>
*
* @param host
* the host name/IP
* @param port
* the port on the host
* @param clientHost
* the local host name/IP to bind the socket to
* @param clientPort
* the port on the local machine
* @param params
* {@link HttpConnectionParams Http connection parameters}
* @return Socket a new socket
* @throws IOException
* if an I/O error occurs while creating the socket
* @throws UnknownHostException
* if the IP address of the host cannot be determined
*/
public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort,
final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
final int timeout = params.getConnectionTimeout();
final SocketFactory socketfactory = getSSLContext().getSocketFactory();
if (timeout == 0) {
return socketfactory.createSocket(host, port, localAddress, localPort);
} else {
final Socket socket = socketfactory.createSocket();
final SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
final SocketAddress remoteaddr = new InetSocketAddress(host, port);
socket.bind(localaddr);
socket.connect(remoteaddr, timeout);
return socket;
}
}
/**
* @see SecureProtocolSocketFactory#createSocket(java.lang.String,int)
*/
public Socket createSocket(final String host, final int port) throws IOException, UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(host, port);
}
/**
* @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
*/
public Socket createSocket(final Socket socket, final String host, final int port, final boolean autoClose) throws IOException,
UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public boolean equals(final Object obj) {
return ((obj != null) && obj.getClass().equals(TrustAllSSLProtocolSocketFactory.class));
|
File |
Line |
simplespider/simplespider/bot/http/apache/ssl/EasyX509TrustManager.java |
42
|
simplespider/simplespider/bot/http/apache/ssl/TrustAllX509TrustManager.java |
38
|
public TrustAllX509TrustManager(final KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
super();
final TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init(keystore);
final TrustManager[] trustmanagers = factory.getTrustManagers();
if (trustmanagers.length == 0) {
throw new NoSuchAlgorithmException("no trust manager found");
}
this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}
/**
* @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
*/
public void checkClientTrusted(final X509Certificate[] certificates, final String authType) throws CertificateException {
// this.standardTrustManager.checkClientTrusted(certificates, authType);
}
/**
* @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType)
*/
public void checkServerTrusted(final X509Certificate[] certificates, final String authType) throws CertificateException {
|