Search in sources :

Example 61 with HostnameVerifier

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

the class URLConnectionFactory method newSslConnConfigurator.

/**
   * Create a new ConnectionConfigurator for SSL connections
   */
private static ConnectionConfigurator newSslConnConfigurator(final int defaultTimeout, Configuration conf) throws IOException, GeneralSecurityException {
    final SSLFactory factory;
    final SSLSocketFactory sf;
    final HostnameVerifier hv;
    final int connectTimeout;
    final int readTimeout;
    factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
    factory.init();
    sf = factory.createSSLSocketFactory();
    hv = factory.getHostnameVerifier();
    connectTimeout = (int) conf.getTimeDuration(HdfsClientConfigKeys.DFS_WEBHDFS_SOCKET_CONNECT_TIMEOUT_KEY, defaultTimeout, TimeUnit.MILLISECONDS);
    readTimeout = (int) conf.getTimeDuration(HdfsClientConfigKeys.DFS_WEBHDFS_SOCKET_READ_TIMEOUT_KEY, defaultTimeout, TimeUnit.MILLISECONDS);
    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);
            }
            URLConnectionFactory.setTimeouts(conn, connectTimeout, readTimeout);
            return conn;
        }
    };
}
Also used : ConnectionConfigurator(org.apache.hadoop.security.authentication.client.ConnectionConfigurator) OAuth2ConnectionConfigurator(org.apache.hadoop.hdfs.web.oauth2.OAuth2ConnectionConfigurator) 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 62 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project OpenAttestation by OpenAttestation.

the class CitrixClient method connect.

public void connect() throws NoSuchAlgorithmException, KeyManagementException, BadServerResponse, XenAPIException, XmlRpcException, XmlRpcException {
    URL url = null;
    try {
        url = new URL("https://" + hostIpAddress + ":" + port);
    } catch (MalformedURLException e) {
        throw new ASException(e, ErrorCode.AS_HOST_COMMUNICATION_ERROR, hostIpAddress);
    }
    TrustManager[] trustAllCerts = new TrustManager[] { tlsConnection.getTlsPolicy().getTrustManager() };
    // Install the all-trusting trust manager  
    SSLContext sc = SSLContext.getInstance("SSL");
    // Create empty HostnameVerifier  
    HostnameVerifier hv = tlsConnection.getTlsPolicy().getHostnameVerifier();
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    connection = new Connection(url);
    Session.loginWithPassword(connection, userName, password, APIVersion.latest().toString());
}
Also used : SecureRandom(java.security.SecureRandom) MalformedURLException(java.net.MalformedURLException) TlsConnection(com.intel.mtwilson.tls.TlsConnection) Connection(com.xensource.xenapi.Connection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SSLContext(javax.net.ssl.SSLContext) URL(java.net.URL) ASException(com.intel.mountwilson.as.common.ASException) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 63 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project platformlayer by platformlayer.

the class PlatformLayerAuthenticationClientProvider method get.

@Override
public PlatformLayerAuthenticationClient get() {
    String keystoneUserUrl = configuration.lookup("auth.user.url", "https://127.0.0.1:" + PORT_PLATFORMLAYER_AUTH_USER + "/v2.0/");
    HostnameVerifier hostnameVerifier = null;
    KeyManager keyManager = null;
    TrustManager trustManager = null;
    String trustKeys = configuration.lookup("auth.user.ssl.keys", null);
    if (trustKeys != null) {
        trustManager = new PublicKeyTrustManager(Splitter.on(',').trimResults().split(trustKeys));
        hostnameVerifier = new AcceptAllHostnameVerifier();
    }
    SslConfiguration sslConfiguration = new SslConfiguration(keyManager, trustManager, hostnameVerifier);
    RestfulClient restfulClient = new JreRestfulClient(httpStrategy, keystoneUserUrl, sslConfiguration);
    PlatformLayerAuthenticationClient authClient = new PlatformLayerAuthenticationClient(restfulClient);
    return authClient;
}
Also used : PublicKeyTrustManager(com.fathomdb.crypto.ssl.PublicKeyTrustManager) SslConfiguration(org.platformlayer.http.SslConfiguration) JreRestfulClient(org.platformlayer.rest.JreRestfulClient) RestfulClient(org.platformlayer.rest.RestfulClient) KeyManager(javax.net.ssl.KeyManager) AcceptAllHostnameVerifier(com.fathomdb.crypto.ssl.AcceptAllHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) TrustManager(javax.net.ssl.TrustManager) PublicKeyTrustManager(com.fathomdb.crypto.ssl.PublicKeyTrustManager) AcceptAllHostnameVerifier(com.fathomdb.crypto.ssl.AcceptAllHostnameVerifier) JreRestfulClient(org.platformlayer.rest.JreRestfulClient)

Example 64 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project robovm by robovm.

the class HttpEngine method connect.

/** Connect to the origin server either directly or via a proxy. */
protected final void connect() throws IOException {
    if (connection != null) {
        return;
    }
    if (routeSelector == null) {
        String uriHost = uri.getHost();
        if (uriHost == null) {
            throw new UnknownHostException(uri.toString());
        }
        SSLSocketFactory sslSocketFactory = null;
        HostnameVerifier hostnameVerifier = null;
        if (uri.getScheme().equalsIgnoreCase("https")) {
            sslSocketFactory = client.getSslSocketFactory();
            hostnameVerifier = client.getHostnameVerifier();
        }
        Address address = new Address(uriHost, getEffectivePort(uri), sslSocketFactory, hostnameVerifier, client.getAuthenticator(), client.getProxy(), client.getTransports());
        routeSelector = new RouteSelector(address, uri, client.getProxySelector(), client.getConnectionPool(), Dns.DEFAULT, client.getRoutesDatabase());
    }
    connection = routeSelector.next(method);
    if (!connection.isConnected()) {
        connection.connect(client.getConnectTimeout(), client.getReadTimeout(), getTunnelConfig());
        client.getConnectionPool().maybeShare(connection);
        client.getRoutesDatabase().connected(connection.getRoute());
    } else {
        connection.updateReadTimeout(client.getReadTimeout());
    }
    connected(connection);
    if (connection.getRoute().getProxy() != client.getProxy()) {
        // Update the request line if the proxy changed; it may need a host name.
        requestHeaders.getHeaders().setRequestLine(getRequestLine());
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Address(com.squareup.okhttp.Address) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 65 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project robovm by robovm.

the class HostnameVerifierTest method testVerifyIpAddress.

public void testVerifyIpAddress() throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    InputStream in = new ByteArrayInputStream(X509_MULTIPLE_SUBJECT_ALT);
    X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
    mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
    HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
    assertTrue(verifier.verify("127.0.0.1", session));
    assertFalse(verifier.verify("127.0.0.2", session));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) HostnameVerifier(javax.net.ssl.HostnameVerifier)

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