/** * @see SSLContexts#createDefault() */ public static final SSLContext getPreferredSSLContext(final SecureRandom secureRandom) { try { final SSLContext sslcontext = SSLContext.getInstance("TLS"); // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html sslcontext.init(null, null, secureRandom); return sslcontext; } catch (final NoSuchAlgorithmException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } catch (final KeyManagementException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } } }
public boolean calls() { boolean isRet = false; //https try { this.callHttps(); isRet = true; } catch (UnrecoverableKeyException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (KeyManagementException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (CertificateException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (KeyStoreException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (NoSuchAlgorithmException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (IOException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (Exception e) { _log.error("", e); this.errInfo = e.getMessage(); } return isRet; }
/** * @see SSLContexts#createDefault() */ public static final SSLContext getPreferredSSLContext(final SecureRandom secureRandom) { try { final SSLContext sslcontext = SSLContext.getInstance("TLS"); // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html sslcontext.init(null, null, secureRandom); return sslcontext; } catch (final NoSuchAlgorithmException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } catch (final KeyManagementException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } } }
public static HttpClient getHttpClient() { HttpClient httpClient = null; TrustStrategy easyStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }; try { SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier()); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", DEFAULT_PORT, sf)); ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (KeyManagementException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (UnrecoverableKeyException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (NoSuchAlgorithmException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (KeyStoreException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } return httpClient; }
/** * Disable SSL and hostname verification for given HTTP connection * * @param conn * a {@link org.eclipse.jgit.transport.http.HttpConnection} * object. * @throws java.io.IOException * @since 4.3 */ public static void disableSslVerify(HttpConnection conn) throws IOException { final TrustManager[] trustAllCerts = new TrustManager[] { new DummyX509TrustManager() }; try { conn.configure(null, trustAllCerts, null); conn.setHostnameVerifier(new DummyHostnameVerifier()); } catch (KeyManagementException e) { throw new IOException(e.getMessage()); } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage()); } }
protected DefaultHttpClient getHttpsClient() { try { SSLContext sslContext = SSLUtils.getSSLContext(); X509TrustManager tm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] {tm}, new SecureRandom()); SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", nmsUrl.getPort(), socketFactory)); BasicClientConnectionManager mgr = new BasicClientConnectionManager(registry); return new DefaultHttpClient(mgr); } catch (NoSuchAlgorithmException ex) { throw new CloudRuntimeException(ex.getMessage()); } catch (KeyManagementException ex) { throw new CloudRuntimeException(ex.getMessage()); } }
httpClient = new DefaultHttpClient(ccm); } catch (final KeyManagementException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (final UnrecoverableKeyException e) { s_logger.error("failed to initialize http client " + e.getMessage());
httpClient = new DefaultHttpClient(ccm); } catch (KeyManagementException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (UnrecoverableKeyException e) { s_logger.error("failed to initialize http client " + e.getMessage());
throw e; } catch (KeyManagementException e) { s_logger.error("KeyManagementException: " + e.getMessage(), e); } catch (NoSuchAlgorithmException e) { s_logger.error("NoSuchAlgorithmException: " + e.getMessage(), e);
} catch (KeyManagementException e) { throw new IllegalArgumentException("KeyManagementException." + e.getMessage());
public TLSSocketFactory() throws SSLException { try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, null, null); // use system security providers mInternalSSLSocketFactory = sslContext.getSocketFactory(); } catch (NoSuchAlgorithmException ex) { throw new SSLException(ex.getMessage()); } catch (KeyManagementException e) { throw new SSLException(e.getMessage()); } }
/** Returns TLSv1.2 only SSL Socket Factory. */ private SSLSocketFactory TlsSocketFactory() { SSLContext sc; try { sc = SSLContext.getInstance("TLSv1.2"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage(), e); } try { sc.init(null, null, null); return sc.getSocketFactory(); } catch (KeyManagementException e) { throw new RuntimeException(e.getMessage(), e); } }
public UntrustedSSLSocketFactory() { try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new X509TrustManager[] { new BogusTrustManager() }, null); factory = sslcontext.getSocketFactory(); } catch (NoSuchAlgorithmException exc) { throw new IllegalStateException("Unable to get SSL context: " + exc.getMessage()); } catch (KeyManagementException exc) { throw new IllegalStateException("Unable to initialize ctx with BogusTrustManager: " + exc.getMessage()); } }
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
public Socket createSocket(InetAddress host, int port, InetAddress clientHost, int clientPort) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort, HttpConnectionParams params) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
public Socket createSocket(String host, int port) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
public Socket createSocket(InetAddress host, int port) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
protected Socket createSocket(TcpSocketKey key) throws IOException { try { return tls.getSocketFactory().createSocket(key.getInetAddress(), key.getPort()); } catch (NoSuchAlgorithmException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } catch (KeyManagementException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } }