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

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

Introduction

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

Prototype

X509HostnameVerifier STRICT_HOSTNAME_VERIFIER

To view the source code for org.apache.http.conn.ssl SSLSocketFactory STRICT_HOSTNAME_VERIFIER.

Click Source Link

Usage

From source file:org.switchyard.quickstarts.demo.policy.security.wss.signencrypt.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);//from   ww  w.j  a  va  2 s. c  om
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(SIGNENCRYPT) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            scheme = "https";
            port = getPort(8443);
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme https = new Scheme(scheme, port, sf);
            SchemeRegistry sr = new SchemeRegistry();
            sr.register(https);
        } else {
            scheme = "http";
            port = getPort(8080);
        }
        boolean signencrypt = policies.contains(SIGNENCRYPT);
        invokeWorkService(scheme, port, getContext(), signencrypt);
    }
}

From source file:org.switchyard.quickstarts.demo.security.propagation.jms.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);/*from w w w.  j av a  2 s.  c om*/
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            scheme = "https";
            port = getPort(8443);
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme https = new Scheme(scheme, port, sf);
            SchemeRegistry sr = new SchemeRegistry();
            sr.register(https);
        } else {
            scheme = "http";
            port = getPort(8080);
        }
        String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "the-frog-1" }
                : null;
        invokeWorkService(scheme, port, getContext(), userPass);
    }
}

From source file:org.switchyard.quickstarts.demo.policy.security.basic.propagate.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);/*from   w ww.j av a 2 s.com*/
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            scheme = "https";
            port = 8443;
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme https = new Scheme(scheme, port, sf);
            SchemeRegistry sr = new SchemeRegistry();
            sr.register(https);
        } else {
            scheme = "http";
            port = 8080;
        }
        String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "the-frog-1" }
                : null;
        invokeWorkService(scheme, port, userPass);
    }
}

From source file:org.acme.insurance.policyquote.test.WorkServiceMain.java

public static void main(String... args) throws Exception {
    serverHostname = System.getProperty("serverHostname", serverHostname);

    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);/*from   ww w.j av  a2  s.co m*/
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            LOGGER.info("Invoking service via SSL...");
            scheme = "https";
            port = 443;
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme https = new Scheme(scheme, port, sf);
            SchemeRegistry sr = new SchemeRegistry();
            sr.register(https);
        } else {
            scheme = "http";
            port = 8080;
        }
        Element assertion = policies.contains(CLIENT_AUTHENTICATION) ? getAssertion() : null;
        invokeWorkService(scheme, port, assertion);
    }
}

From source file:com.prey.net.HttpUtils.java

public static HttpClient getNewHttpClient() {
    try {//from   ww w  .j ava  2  s. c  o  m
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = SSLSocketFactory.getSocketFactory();
        sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

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

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

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

From source file:com.amazon.s3.http.ConnectionManagerFactory.java

public static ThreadSafeClientConnManager createThreadSafeClientConnManager(ClientConfiguration config,
        HttpParams httpClientParams) {//from w ww  .j  a v  a2 s. c  o m
    ConnManagerParams.setMaxConnectionsPerRoute(httpClientParams, new ConnPerRouteBean(20));

    SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

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

    return new ThreadSafeClientConnManager(httpClientParams, registry);
}

From source file:com.mobicage.rogerthat.util.http.HTTPUtil.java

public static HttpClient getHttpClient(int connectionTimeout, int socketTimeout, final int retryCount) {
    final HttpParams params = new BasicHttpParams();

    HttpConnectionParams.setStaleCheckingEnabled(params, true);
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, socketTimeout);

    HttpClientParams.setRedirecting(params, false);

    final DefaultHttpClient httpClient = new DefaultHttpClient(params);

    if (shouldUseTruststore()) {
        KeyStore trustStore = loadTrustStore();

        SSLSocketFactory socketFactory;
        try {/*w w w . j av  a 2s.co  m*/
            socketFactory = new SSLSocketFactory(null, null, trustStore);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

        Scheme sch = new Scheme("https", socketFactory, CloudConstants.HTTPS_PORT);
        httpClient.getConnectionManager().getSchemeRegistry().register(sch);
    }

    if (retryCount > 0) {
        httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
            @Override
            public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
                return executionCount < retryCount;
            }
        });
    }
    return httpClient;
}

From source file:com.amalto.workbench.utils.SSLContextProvider.java

public static HostnameVerifier getHostnameVerifier() {
    boolean verify = store.getBoolean(PreferenceConstants.VERIFY_HOSTNAME);
    if (verify) {
        return SSLSocketFactory.STRICT_HOSTNAME_VERIFIER;
    } else {/* w w  w  . j  a v a 2  s . c  o  m*/
        return SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
    }
}

From source file:com.lonepulse.travisjr.net.ZombieConfig.java

@Override
public HttpClient httpClient() {

    HttpClient client = super.httpClient();

    try {/*from   w  w w  .  j  a  v  a2 s . c o m*/

        KeyStore keyStore = KeyStore.getInstance("BKS");
        InputStream is = TravisJr.Application.getContext().getResources().openRawResource(R.raw.travisjr);

        try {

            keyStore.load(is, null);
        } finally {

            is.close();
        }

        SSLSocketFactory sslSocketFactory = new SSLSocketFactory(keyStore);
        sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

        SchemeRegistry schemeRegistry = ((ThreadSafeClientConnManager) client.getConnectionManager())
                .getSchemeRegistry();

        schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
    } catch (Exception e) {

        Log.e(getClass().getSimpleName(), "HttpClient configuration with a custom SSLSocketFactory failed.", e);
    }

    return client;
}

From source file:ee.vvk.ivotingverification.util.CustomHttpsClient.java

private SSLSocketFactory newSslSocketFactory() {
    KeyStore trustStore;/*from   w  ww . j  a  v a2 s  .c o m*/
    try {

        trustStore = Util.loadTrustStore((Activity) context);

        SSLSocketFactory sf = new SSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

        return sf;
    } catch (Exception e) {
        if (Util.DEBUGGABLE) {
            Log.e(TAG, "Tehniline viga: " + e.getMessage(), e);
        }
        Util.startErrorIntent((Activity) context, C.badServerResponseMessage, true);
    }

    return null;
}