List of usage examples for javax.net.ssl SSLContext init
public final void init(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws KeyManagementException
From source file:org.eclipse.lyo.oslc4j.bugzilla.utils.BugzillaHttpClient.java
private static SSLContext getTrustingSSLContext() { // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; }//from w w w. j ava 2 s .c om public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); return sc; } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:com.wareninja.opensource.common.wsrequest.HttpUtils.java
/** * Open an URL connection. If HTTPS, accepts any certificate even if not * valid, and connects to any host name. * /*from w ww . j a v a2 s . com*/ * @param url * The destination URL, HTTP or HTTPS. * @return The URLConnection. * @throws IOException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public static URLConnection getConnection(URL url) throws IOException, NoSuchAlgorithmException, KeyManagementException { URLConnection conn = url.openConnection(); if (conn instanceof HttpsURLConnection) { // Trust all certificates SSLContext context = SSLContext.getInstance("TLS"); context.init(new KeyManager[0], TRUST_MANAGER, new SecureRandom()); SSLSocketFactory socketFactory = context.getSocketFactory(); ((HttpsURLConnection) conn).setSSLSocketFactory(socketFactory); // Allow all hostnames ((HttpsURLConnection) conn).setHostnameVerifier(HOSTNAME_VERIFIER); } conn.setConnectTimeout(SOCKET_TIMEOUT); conn.setReadTimeout(SOCKET_TIMEOUT); return conn; }
From source file:ch.truesolutions.payit.https.EasySSLProtocolSocketFactory.java
private static SSLContext createEasySSLContext() { try {/*from ww w.j a v a2s. c om*/ // DS create a KeyStore todo KeyStore keyStore = KeyStore.getInstance("JKS"); SSLContext context = SSLContext.getInstance("SSL"); context.init(null, new TrustManager[] { new EasyX509TrustManager(keyStore) }, null); return context; } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e.toString()); } }
From source file:com.panoramagl.downloaders.ssl.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/*w ww .j av a 2 s . c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Throwable e) { throw new IOException(e.getMessage()); } }
From source file:com.rackspacecloud.client.cloudfiles.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException, NoSuchAlgorithmException, KeyStoreException { KeyStore keystore = null;/* w w w . jav a2 s . c o m*/ EasyX509TrustManager extm = new EasyX509TrustManager(keystore); try { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { extm }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:org.openhab.binding.rwesmarthome.internal.communicator.util.EasySSLSocketFactory.java
/** * Creates an SSL context.// w w w . j a v a2s. c om * * @return * @throws IOException */ private static SSLContext createEasySSLContext() throws IOException { try { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:Main.java
public static String[][] getSpreadSheet(String docId, String tab) { try {/*from w w w.j ava 2 s . c o m*/ // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(final X509Certificate[] chain, final String authType) { } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } } }; // Install the all-trusting trust manager final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); //sslSocketFactory. // All set up, we can get a resource through https now: final URLConnection urlCon = new URL( "https://docs.google.com/spreadsheets/d/" + docId + "/export?format=csv&gid=" + tab) .openConnection(); // Tell the url connection object to use our socket factory which bypasses security checks ((HttpsURLConnection) urlCon).setSSLSocketFactory(sslSocketFactory); final InputStream input = urlCon.getInputStream(); BufferedReader r = new BufferedReader(new InputStreamReader(input)); StringBuilder total = new StringBuilder(); String line; while ((line = r.readLine()) != null) { total.append(line); total.append("\n"); } String theString = total.toString(); String[][] out = null; String rows[] = theString.split("\n"); out = new String[rows.length][]; for (int i = 0; i < out.length; i++) { String columns[] = rows[i].split(","); out[i] = new String[columns.length]; int corrected = 0; for (int j = 0; j < columns.length; j++) { if (columns[j].length() > 0 && columns[j].charAt(0) == '"') { out[i][j - corrected] = (columns[j] + ", " + columns[j + 1]).replace("\"", ""); j++; corrected += 1; } else { out[i][j - corrected] = columns[j]; } } } return out; } catch (final Exception e) { e.printStackTrace(); } return null; }
From source file:microsoft.exchange.webservices.data.core.EwsSSLProtocolSocketFactory.java
/** * Create SSL context and initialize it using specific trust manager. * * @param trustManager trust manager//from w w w .ja v a 2 s .com * @return initialized SSL context * @throws GeneralSecurityException on security error */ public static SSLContext createSslContext(TrustManager trustManager) throws GeneralSecurityException { EwsX509TrustManager x509TrustManager = new EwsX509TrustManager(null, trustManager); SSLContext sslContext = SSLContexts.createDefault(); sslContext.init(null, new TrustManager[] { x509TrustManager }, null); return sslContext; }
From source file:com.google.resting.rest.CustomSSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/*from w ww . j a v a 2 s . c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new CustomX509TrustManager() }, new java.security.SecureRandom()); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.kylinolap.jdbc.util.DefaultSslProtocolSocketFactory.java
private static SSLContext createEasySSLContext() { try {//from w ww. j a va2 s . co m SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new DefaultX509TrustManager(null) }, null); return context; } catch (Exception e) { LOG.error(e.getMessage(), e); throw new HttpClientError(e.toString()); } }