public Socket createSocket(HttpParams httpParams) throws IOException { return createSSLContext(httpParams).getSocketFactory().createSocket(); }
private SSLContext createSSLContext(HttpParams params) throws IOException { if(this.sslcontext == null) try { // Get the Desired kind of authentication this.sslcontext = trustedauthentication(params); if(this.sslcontext == null) this.sslcontext = stdauthentication(); } catch (KeyManagementException e) { throw new HTTPException("Key Management exception: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { throw new HTTPException("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { throw new HTTPException("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { throw new HTTPException("Key management exception: " + e.getMessage()); } catch (IOException e) { throw new HTTPException("I/O error reading keystore/truststore file: " + e.getMessage()); } catch (Exception e) { throw new IOException(e.getMessage(), e); } return this.sslcontext; }
KeyManager[] keymanagers = null; KeyStore keystore = buildstore(keypath, keypassword, "key"); if(keystore != null) { KeyManagerFactory kmfactory = KeyManagerFactory.getInstance("SunX509"); keymanagers = kmfactory.getKeyManagers(); KeyStore truststore = buildstore(trustpath, trustpassword, "trust"); if(truststore != null) {
public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException { int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); SSLSocket sslsocket = (SSLSocket) ((sock != null) ? sock : createSocket(params)); if (localAddress != null) { sslsocket.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params)); sslsocket.bind(localAddress); } try { sslsocket.setSoTimeout(soTimeout); sslsocket.connect(remoteAddress, connTimeout ); } catch (SocketTimeoutException ex) { throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out"); } return sslsocket; }
@Override public Socket createLayeredSocket(Socket socket, String s, int i, HttpParams httpParams) throws IOException { return createSSLContext(httpParams).getSocketFactory().createSocket(); }