Example usage for org.apache.http.conn.ssl SSLSocketFactory getHostnameVerifier

List of usage examples for org.apache.http.conn.ssl SSLSocketFactory getHostnameVerifier

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl SSLSocketFactory getHostnameVerifier.

Prototype

public X509HostnameVerifier getHostnameVerifier() 

Source Link

Usage

From source file:eu.trentorise.smartcampus.ac.network.HttpsClientBuilder.java

private static HttpClient getWildcartHttpClient(HttpParams inParams) {
    HttpClient client = null;/* w ww .  j av  a 2s.  c  o  m*/

    HttpParams params = inParams != null ? inParams : new BasicHttpParams();

    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

        SSLSocketFactory sslSocketFactory = new CustomSSLSocketFactory(trustStore);
        final X509HostnameVerifier delegate = sslSocketFactory.getHostnameVerifier();
        if (!(delegate instanceof WildcardVerifier)) {
            sslSocketFactory.setHostnameVerifier(new WildcardVerifier(delegate));
        }
        registry.register(new Scheme("https", sslSocketFactory, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        client = new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        client = new DefaultHttpClient(params);
    }

    return client;
}

From source file:org.androidannotations.test.SSLConnectionTest.java

@Test
public void strictHostnameVerifier() {
    assertNotNull(activity.mHttpsClientTest2);
    ClientConnectionManager ccm = activity.mHttpsClientTest2.getConnectionManager();
    Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https");
    SSLSocketFactory socketFactHttps = (SSLSocketFactory) httpsScheme.getSocketFactory();

    assertEquals(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER, socketFactHttps.getHostnameVerifier());
}

From source file:nl.esciencecenter.octopus.webservice.JobLauncherServiceTest.java

@Test
public void useInsecureSSL_NoHostnameVerifier()
        throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
    HttpClient httpClient = new DefaultHttpClient();

    service.useInsecureSSL(httpClient);//  w ww . j a  v  a 2 s .c om

    Scheme scheme = httpClient.getConnectionManager().getSchemeRegistry().get("https");
    SSLSocketFactory factory = (SSLSocketFactory) scheme.getSchemeSocketFactory();
    assertEquals(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,
            factory.getHostnameVerifier());
}

From source file:com.davidivins.checkin4me.oauth.OAuth2Request.java

/**
 * getTolerantClient/*w ww  .  ja  v  a  2s  .c  o m*/
 * 
 * Stolen from stackoverflow.com
 * http://stackoverflow.com/questions/3135679/android-httpclient-hostname-in-certificate-didnt-match-example-com-exa
 * 
 * @return DefaultttpClient
 */
public DefaultHttpClient getTolerantClient() {
    DefaultHttpClient client = new DefaultHttpClient();

    SSLSocketFactory sslSocketFactory = (SSLSocketFactory) client.getConnectionManager().getSchemeRegistry()
            .getScheme("https").getSocketFactory();

    final X509HostnameVerifier delegate = sslSocketFactory.getHostnameVerifier();

    if (!(delegate instanceof TolerantVerifier))
        sslSocketFactory.setHostnameVerifier(new TolerantVerifier(delegate));

    return client;
}

From source file:com.nookdevs.library.Smashwords.java

private boolean authenticate() {
    String url = AUTH_URL;
    try {//  w ww . j  a va  2s  .c  o m
        nookLib.waitForNetwork(lock);
        SSLSocketFactory factory = SSLSocketFactory.getSocketFactory();
        X509HostnameVerifier orgVerifier = factory.getHostnameVerifier();
        factory.setHostnameVerifier(new AllowAllHostnameVerifier());
        HttpPost request = new HttpPost(url);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", m_User));
        nvps.add(new BasicNameValuePair("password", m_Pass));
        request.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = httpClient.execute(request);
        parseBookShelf(response.getEntity().getContent());
        factory.setHostnameVerifier(orgVerifier);
        lock.release();
        return true;
    } catch (Exception ex) {
        Log.e("Smashwords", "exception during authentication", ex);
        return false;
    }
}

From source file:com.nookdevs.library.FictionwiseBooks.java

private boolean authenticate() {
    String url = AUTH_URL;
    try {/*  w w w .  ja  va 2 s  . c  om*/
        nookLib.waitForNetwork(lock);
        SSLSocketFactory factory = SSLSocketFactory.getSocketFactory();
        X509HostnameVerifier orgVerifier = factory.getHostnameVerifier();
        factory.setHostnameVerifier(new AllowAllHostnameVerifier());
        HttpPost request = new HttpPost(url);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("loginid", m_User));
        nvps.add(new BasicNameValuePair("password", m_Pass));
        nvps.add(new BasicNameValuePair("login", "Login"));
        request.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        HttpResponse response = httpClient.execute(request);
        m_BookShelfHtml = EntityUtils.toString(response.getEntity());
        factory.setHostnameVerifier(orgVerifier);
        m_Auth = true;
        return true;
    } catch (Exception ex) {
        Log.e("FictionwiseBooks", "exception during authentication", ex);
        return false;
    }
}