List of usage examples for javax.net.ssl HostnameVerifier HostnameVerifier
HostnameVerifier
From source file:com.bytelightning.opensource.pokerface.HelloWorldScriptTest.java
@BeforeClass public static void setUpBeforeClass() throws Exception { PrevSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory(); PrevHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); proxy = new PokerFace(); XMLConfiguration conf = new XMLConfiguration(); conf.load(ProxySpecificTest.class.getResource("/HelloWorldTestConfig.xml")); proxy.config(conf);/*from w ww . j a va 2s .c o m*/ boolean started = proxy.start(); Assert.assertTrue("Successful proxy start", started); SSLContext sc = SSLContext.getInstance("TLS"); TrustManager[] trustAllCertificates = { new X509TrustAllManager() }; sc.init(null, trustAllCertificates, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; // Just allow them all. } }); }
From source file:org.jssec.android.https.vulnerables.VulnerableSamples.java
public void emptyHostnameVerifier() { HostnameVerifier hv = new HostnameVerifier() { @Override//from w w w.j a v a 2 s . c o m public boolean verify(String hostname, SSLSession session) { // ?true? ??????? return true; } }; }
From source file:org.mifos.tools.provider.RestAdapterProvider.java
private OkHttpClient createClient() { final OkHttpClient client = new OkHttpClient(); final TrustManager[] certs = new TrustManager[] { new X509TrustManager() { @Override// w w w .jav a2 s . c o m public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } @Override public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } } }; SSLContext ctx = null; try { ctx = SSLContext.getInstance("TLS"); ctx.init(null, certs, new SecureRandom()); } catch (final java.security.GeneralSecurityException ex) { // do nothing, ignore } try { final HostnameVerifier hostnameVerifier = new HostnameVerifier() { @Override public boolean verify(final String hostname, final SSLSession session) { return true; } }; client.setHostnameVerifier(hostnameVerifier); client.setSslSocketFactory(ctx.getSocketFactory()); } catch (final Exception e) { // do nothing, ignore } return client; }
From source file:org.wso2.carbon.membership.scheme.kubernetes.api.KubernetesHttpsApiEndpoint.java
private static void disableCertificateValidation() { TrustManager[] dummyTrustMgr = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }/*from ww w . jav a 2 s . c o m*/ public void checkClientTrusted(X509Certificate[] certs, String authType) { // do nothing } public void checkServerTrusted(X509Certificate[] certs, String authType) { // do nothing } } }; // Ignore differences between given hostname and certificate hostname HostnameVerifier dummyHostVerifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { // always true return true; } }; // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, dummyTrustMgr, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(dummyHostVerifier); } catch (Exception ignored) { } }
From source file:io.fabric8.elasticsearch.plugin.HttpsProxyClientCertAuthenticatorIntegrationTest.java
@Test public void testProxyAuthWithSSL() throws Exception { SSLContext sslContext = new SSLContextBuilder() .loadTrustMaterial(new File(keyStoreFile), keystorePW.toCharArray(), new TrustSelfSignedStrategy()) .build();//from w w w .j ava 2s.c o m try (CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslContext) .setSSLHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }).build()) { Executor ex = Executor.newInstance(httpclient); Response response = ex.execute(Request.Get("https://localhost:9200/blahobar.234324234/logs/1") .addHeader("Authorization", String.format("Bearer %s", token)) .addHeader("X-Proxy-Remote-User", proxyUser)); System.out.println(response.returnContent().asString()); } catch (Exception e) { System.out.println(e); fail("Test Failed"); } }
From source file:com.voa.weixin.utils.HttpUtils.java
/** * httpspost?/*from w w w. ja va 2 s . co m*/ * * @param url * @param param * @return * @throws Exception */ private static String doHttps(String url, String param, String method) throws Exception { HttpsURLConnection conn = null; OutputStream out = null; String rsp = null; byte[] content = param.getBytes("utf-8"); try { try { SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom()); SSLContext.setDefault(ctx); conn = getConnection(new URL(url), method, ctype); conn.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); conn.setConnectTimeout(60000); conn.setReadTimeout(60000); } catch (Exception e) { throw e; } try { out = conn.getOutputStream(); if (StringUtils.isNotBlank(param)) out.write(content); rsp = getResponseAsString(conn); } catch (IOException e) { throw e; } } finally { if (out != null) { out.close(); } if (conn != null) { conn.disconnect(); } } return rsp; }
From source file:sit.web.client.HTTPTrustHelper.java
public static void init(String securityAlgorithm, KeyManager[] kms, TrustManager[] tms) { // Install the all-trusting trust manager try {/* w w w. j av a2 s . c o m*/ SSLContext sc = SSLContext.getInstance(securityAlgorithm); sc.init(kms, tms, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception ex) { Logger.getLogger(HttpHelper.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String string, SSLSession ssls) { return true; } }); HttpsURLConnection.setFollowRedirects(true); }
From source file:client.lib.Client.java
public Client() throws NoSuchAlgorithmException, KeyManagementException { TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { X509Certificate[] myTrustedAnchors = new X509Certificate[0]; return myTrustedAnchors; }/*from w ww. j a v a 2s . c om*/ @Override public void checkClientTrusted(X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); http2Client = new OkHttpClient(); http2Client.setSslSocketFactory(sslSocketFactory); http2Client.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); httpClient = http2Client.clone(); httpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1)); http2Client.setProtocols(Arrays.asList(Protocol.HTTP_2)); }
From source file:com.ethercamp.harmony.util.TrustSSL.java
public static void applyAnother() { try {//ww w .j a v a2s.c o m TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String authType) throws CertificateException { System.out.println( "x509Certificates = [" + x509Certificates + "], authType = [" + authType + "]"); } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String authType) throws CertificateException { System.out.println( "x509Certificates = [" + x509Certificates + "], authType = [" + authType + "]"); } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; // Install the all-trusting trust manager SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); // Create all-trusting host name verifier HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { System.out.println("hostname = [" + hostname + "], session = [" + session + "]"); return true; } }; // Install the all-trusting host verifier HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.jaspersoft.jasperserver.jaxrs.client.core.SessionStorage.java
private void initSSL(ClientBuilder clientBuilder) { try {/*from w w w . ja v a2 s .c o m*/ SSLContext sslContext = SSLContext.getInstance("SSL"); HostnameVerifier hostnameVerifier = new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }; sslContext.init(null, configuration.getTrustManagers(), new SecureRandom()); clientBuilder.sslContext(sslContext); clientBuilder.hostnameVerifier(hostnameVerifier); } catch (Exception e) { log.error("Unable inFolder init SSL context", e); throw new RuntimeException("Unable inFolder init SSL context", e); } }