private HostConfiguration setupSSLIfNeeded(Settings settings, SecureSettings secureSettings, HostConfiguration hostConfig) { if (!sslEnabled) { return hostConfig; } // we actually have a socks proxy, let's start the setup if (log.isDebugEnabled()) { log.debug("SSL Connection enabled"); } // // switch protocol // due to how HttpCommons work internally this dance is best to be kept as is // String schema = "https"; int port = 443; SecureProtocolSocketFactory sslFactory = new SSLSocketFactory(settings, secureSettings); replaceProtocol(sslFactory, schema, port); return hostConfig; }
private SSLContext getSSLContext() { if (sslContext == null) { sslContext = createSSLContext(); } return sslContext; }
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException, UnknownHostException { return getSSLContext().getSocketFactory().createSocket(host, port, localAddress, localPort); }
private SSLContext createSSLContext() { SSLContext ctx; try { ctx = SSLContext.getInstance(sslProtocol); } catch (NoSuchAlgorithmException ex) { throw new EsHadoopIllegalStateException("Cannot instantiate SSL - " + ex.getMessage(), ex); } try { ctx.init(loadKeyManagers(), loadTrustManagers(), null); } catch (Exception ex) { throw new EsHadoopIllegalStateException("Cannot initialize SSL - " + ex.getMessage(), ex); } return ctx; }
private KeyManager[] loadKeyManagers() throws GeneralSecurityException, IOException { if (!StringUtils.hasText(keyStoreLocation)) { LOG.debug("No keystore location specified! SSL is continuing with no keystore."); return null; } char[] pass = (StringUtils.hasText(keyStorePass) ? keyStorePass.trim().toCharArray() : null); KeyStore keyStore = loadKeyStore(keyStoreLocation, pass); KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmFactory.init(keyStore, pass); return kmFactory.getKeyManagers(); }
private SSLContext createSSLContext() { SSLContext ctx; try { ctx = SSLContext.getInstance(sslProtocol); } catch (NoSuchAlgorithmException ex) { throw new EsHadoopIllegalStateException("Cannot instantiate SSL - " + ex.getMessage(), ex); } try { ctx.init(loadKeyManagers(), loadTrustManagers(), null); } catch (Exception ex) { throw new EsHadoopIllegalStateException("Cannot initialize SSL - " + ex.getMessage(), ex); } return ctx; }
private TrustManager[] loadTrustManagers() throws GeneralSecurityException, IOException { KeyStore keyStore = null; if (StringUtils.hasText(trustStoreLocation)) { char[] pass = (StringUtils.hasText(trustStorePass) ? trustStorePass.trim().toCharArray() : null); keyStore = loadKeyStore(trustStoreLocation, pass); } else { LOG.debug("No truststore location specified! SSL is continuing with no truststore."); } TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmFactory.init(keyStore); TrustManager[] tms = tmFactory.getTrustManagers(); if (tms != null && trust != null) { // be defensive since the underlying impl might not give us a copy TrustManager[] clone = new TrustManager[tms.length]; for (int i = 0; i < tms.length; i++) { TrustManager tm = tms[i]; if (tm instanceof X509TrustManager) { tm = new TrustManagerDelegate((X509TrustManager) tm, trust); } clone[i] = tm; } tms = clone; } return tms; }
@Override public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose); }
private SSLContext createSSLContext() { SSLContext ctx; try { ctx = SSLContext.getInstance(sslProtocol); } catch (NoSuchAlgorithmException ex) { throw new EsHadoopIllegalStateException("Cannot instantiate SSL - " + ex.getMessage(), ex); } try { ctx.init(loadKeyManagers(), loadTrustManagers(), null); } catch (Exception ex) { throw new EsHadoopIllegalStateException("Cannot initialize SSL - " + ex.getMessage(), ex); } return ctx; }
private KeyManager[] loadKeyManagers() throws GeneralSecurityException, IOException { if (!StringUtils.hasText(keyStoreLocation)) { LOG.debug("No keystore location specified! SSL is continuing with no keystore."); return null; } char[] pass = (StringUtils.hasText(keyStorePass) ? keyStorePass.trim().toCharArray() : null); KeyStore keyStore = loadKeyStore(keyStoreLocation, pass); KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmFactory.init(keyStore, pass); return kmFactory.getKeyManagers(); }
private SSLContext getSSLContext() { if (sslContext == null) { sslContext = createSSLContext(); } return sslContext; }
private HostConfiguration setupSSLIfNeeded(Settings settings, SecureSettings secureSettings, HostConfiguration hostConfig) { if (!sslEnabled) { return hostConfig; } // we actually have a socks proxy, let's start the setup if (log.isDebugEnabled()) { log.debug("SSL Connection enabled"); } // // switch protocol // due to how HttpCommons work internally this dance is best to be kept as is // String schema = "https"; int port = 443; SecureProtocolSocketFactory sslFactory = new SSLSocketFactory(settings, secureSettings); replaceProtocol(sslFactory, schema, port); return hostConfig; }
@Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { return getSSLContext().getSocketFactory().createSocket(host, port); }
private SSLContext createSSLContext() { SSLContext ctx; try { ctx = SSLContext.getInstance(sslProtocol); } catch (NoSuchAlgorithmException ex) { throw new EsHadoopIllegalStateException("Cannot instantiate SSL - " + ex.getMessage(), ex); } try { ctx.init(loadKeyManagers(), loadTrustManagers(), null); } catch (Exception ex) { throw new EsHadoopIllegalStateException("Cannot initialize SSL - " + ex.getMessage(), ex); } return ctx; }
private KeyManager[] loadKeyManagers() throws GeneralSecurityException, IOException { if (!StringUtils.hasText(keyStoreLocation)) { LOG.debug("No keystore location specified! SSL is continuing with no keystore."); return null; } char[] pass = (StringUtils.hasText(keyStorePass) ? keyStorePass.trim().toCharArray() : null); KeyStore keyStore = loadKeyStore(keyStoreLocation, pass); KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmFactory.init(keyStore, pass); return kmFactory.getKeyManagers(); }
private SSLContext getSSLContext() { if (sslContext == null) { sslContext = createSSLContext(); } return sslContext; }
private HostConfiguration setupSSLIfNeeded(Settings settings, SecureSettings secureSettings, HostConfiguration hostConfig) { if (!sslEnabled) { return hostConfig; } // we actually have a socks proxy, let's start the setup if (log.isDebugEnabled()) { log.debug("SSL Connection enabled"); } // // switch protocol // due to how HttpCommons work internally this dance is best to be kept as is // String schema = "https"; int port = 443; SecureProtocolSocketFactory sslFactory = new SSLSocketFactory(settings, secureSettings); replaceProtocol(sslFactory, schema, port); return hostConfig; }
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); } int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = getSSLContext().getSocketFactory(); if (timeout == 0) { return socketfactory.createSocket(host, port, localAddress, localPort); } else { Socket socket = socketfactory.createSocket(); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.bind(localaddr); socket.connect(remoteaddr, timeout); return socket; } }
private SSLContext createSSLContext() { SSLContext ctx; try { ctx = SSLContext.getInstance(sslProtocol); } catch (NoSuchAlgorithmException ex) { throw new EsHadoopIllegalStateException("Cannot instantiate SSL - " + ex.getMessage(), ex); } try { ctx.init(loadKeyManagers(), loadTrustManagers(), null); } catch (Exception ex) { throw new EsHadoopIllegalStateException("Cannot initialize SSL - " + ex.getMessage(), ex); } return ctx; }
private KeyManager[] loadKeyManagers() throws GeneralSecurityException, IOException { if (!StringUtils.hasText(keyStoreLocation)) { LOG.debug("No keystore location specified! SSL is continuing with no keystore."); return null; } char[] pass = (StringUtils.hasText(keyStorePass) ? keyStorePass.trim().toCharArray() : null); KeyStore keyStore = loadKeyStore(keyStoreLocation, pass); KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmFactory.init(keyStore, pass); return kmFactory.getKeyManagers(); }