@Test public void testNoStrictSSLHostnameVerifier() { HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); SSLSession sslSession = Mockito.mock(SSLSession.class); String value = "some.hostname"; assertFalse(HttpsURLConnection.getDefaultHostnameVerifier().verify(value,sslSession)); HttpHelper.noStrictSSL(); assertNotEquals(hostnameVerifier,HttpsURLConnection.getDefaultHostnameVerifier()); assertTrue(HttpsURLConnection.getDefaultHostnameVerifier().verify(value,sslSession)); }
public static void noStrictSSL(){ LOGGER.warn("Strict SSL is set to false! Invalid certificates will be accepted for connection!"); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } 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()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier ((hostname, session) -> true); } catch (GeneralSecurityException e) { LOGGER.error("The configuration for no strict SSL went wrong"); } }
HttpHelper { public static void noStrictSSL(){ LOGGER.warn("Strict SSL is set to false! Invalid certificates will be accepted for connection!"); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } 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()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier ((hostname, session) -> true); } catch (GeneralSecurityException e) { LOGGER.error("The configuration for no strict SSL went wrong"); } } }
HttpHelper { public static void noStrictSSL(){ LOGGER.warn("Strict SSL is set to false! Invalid certificates will be accepted for connection!"); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } 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()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier ((hostname, session) -> true); } catch (GeneralSecurityException e) { LOGGER.error("The configuration for no strict SSL went wrong"); } }  }
HttpHelper { public static void noStrictSSL(){ LOGGER.warn("Strict SSL is set to false! Invalid certificates will be accepted for connection!"); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } 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()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier ((hostname, session) -> true); } catch (GeneralSecurityException e) { LOGGER.error("The configuration for no strict SSL went wrong"); } }  static void noStrictSSL(); }
HttpHelper { public static void noStrictSSL(){ LOGGER.warn("Strict SSL is set to false! Invalid certificates will be accepted for connection!"); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } 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()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier ((hostname, session) -> true); } catch (GeneralSecurityException e) { LOGGER.error("The configuration for no strict SSL went wrong"); } }  static void noStrictSSL();  }