Search in sources :

Example 86 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project jdk8u_jdk by JetBrains.

the class CookieHttpsClientTest method doClientSide.

/*
     * Define the client side of the test.
     *
     * If the server prematurely exits, serverReady will be set to true
     * to avoid infinite hangs.
     */
void doClientSide() throws Exception {
    // Wait for server to get started.
    while (!serverReady) {
        Thread.sleep(50);
    }
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    });
    URL url = new URL("https://localhost:" + serverPort + "/");
    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    // read response body so connection can be reused
    while (in.read() != -1) ;
    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);
    in = url.openConnection().getInputStream();
    while (in.read() != -1) ;
    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
Also used : InputStream(java.io.InputStream) SSLSession(javax.net.ssl.SSLSession) URL(java.net.URL) CookieManager(java.net.CookieManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 87 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project openstack4j by ContainX.

the class ConfigTest method testUnequalConfigHostnameVerifier.

@Test
public void testUnequalConfigHostnameVerifier() {
    Config firstConfig = Config.newConfig();
    firstConfig.withHostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String hostname, SSLSession session) {
            // TODO Auto-generated method stub
            return false;
        }
    });
    Config secondConfig = Config.newConfig();
    Assert.assertNotEquals(firstConfig, secondConfig);
}
Also used : Config(org.openstack4j.core.transport.Config) SSLSession(javax.net.ssl.SSLSession) HostnameVerifier(javax.net.ssl.HostnameVerifier) Test(org.testng.annotations.Test)

Example 88 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project ignite by apache.

the class GridCommonAbstractTest method setUp.

/** {@inheritDoc} */
@Override
protected final void setUp() throws Exception {
    // Disable SSL hostname verifier.
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String s, SSLSession sslSes) {
            return true;
        }
    });
    getTestCounters().incrementStarted();
    super.setUp();
}
Also used : SSLSession(javax.net.ssl.SSLSession) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 89 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project incubator-atlas by apache.

the class SecureClientUtils method newSslConnConfigurator.

private static ConnectionConfigurator newSslConnConfigurator(final int timeout, Configuration conf) throws IOException, GeneralSecurityException {
    final SSLFactory factory;
    final SSLSocketFactory sf;
    final HostnameVerifier hv;
    factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
    factory.init();
    sf = factory.createSSLSocketFactory();
    hv = factory.getHostnameVerifier();
    return new ConnectionConfigurator() {

        @Override
        public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
            if (conn instanceof HttpsURLConnection) {
                HttpsURLConnection c = (HttpsURLConnection) conn;
                c.setSSLSocketFactory(sf);
                c.setHostnameVerifier(hv);
            }
            setTimeouts(conn, timeout);
            return conn;
        }
    };
}
Also used : ConnectionConfigurator(org.apache.hadoop.security.authentication.client.ConnectionConfigurator) SSLFactory(org.apache.hadoop.security.ssl.SSLFactory) HttpURLConnection(java.net.HttpURLConnection) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 90 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project BBS-Android by bdpqchen.

the class UpdatePasswordClient method getUnSaveBuilder.

private static OkHttpClient.Builder getUnSaveBuilder() {
    try {
        // Create a trust manager that does not validate certificate chains
        final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

            @Override
            public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
            }

            @Override
            public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[] {};
            }
        } };
        // 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 javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.sslSocketFactory(sslSocketFactory);
        builder.hostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
        return builder;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) X509TrustManager(javax.net.ssl.X509TrustManager) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) X509TrustManager(javax.net.ssl.X509TrustManager)

Aggregations

HostnameVerifier (javax.net.ssl.HostnameVerifier)94 SSLSession (javax.net.ssl.SSLSession)41 SSLContext (javax.net.ssl.SSLContext)30 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)27 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)24 TrustManager (javax.net.ssl.TrustManager)19 IOException (java.io.IOException)18 URL (java.net.URL)18 X509Certificate (java.security.cert.X509Certificate)17 X509TrustManager (javax.net.ssl.X509TrustManager)17 Test (org.junit.Test)16 HttpURLConnection (java.net.HttpURLConnection)14 SecureRandom (java.security.SecureRandom)14 InputStream (java.io.InputStream)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 CertificateException (java.security.cert.CertificateException)10 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)10 KeyManagementException (java.security.KeyManagementException)9 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8