List of usage examples for org.apache.http.conn.ssl StrictHostnameVerifier StrictHostnameVerifier
StrictHostnameVerifier
From source file:org.jivesoftware.smack.android.AndroidSmackInitializer.java
@Override public List<Exception> initialize() { SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier()); Base64.setEncoder(AndroidBase64Encoder.getInstance()); Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance()); return null;/*w w w . j a v a 2s . c o m*/ }
From source file:com.magnet.android.mms.connection.SslManager.java
synchronized HostnameVerifier getHostnameVerifier() { String verifierStr = MagnetDefaultSettings.getInstance(mContext).getSslHostnameVerifier(); Log.d(TAG, "getHostnameVerifier(): Value from settings: " + verifierStr); try {// w w w.ja va 2s. com HostnameVerifierEnum verifier = HostnameVerifierEnum.valueOf(verifierStr); if (mHostnameVerifier == null || verifier != mCurrentVerifier) { switch (verifier) { case ALLOW_ALL: mHostnameVerifier = new AllowAllHostnameVerifier(); break; case BROWSER_COMPAT: mHostnameVerifier = new BrowserCompatHostnameVerifier(); break; case STRICT: default: mHostnameVerifier = new StrictHostnameVerifier(); } mCurrentVerifier = verifier; } } catch (Exception ex) { Log.w(TAG, "getHostnameVerifier(): caught exception. Will default to STRICT.", ex); if (mCurrentVerifier != HostnameVerifierEnum.STRICT) { mHostnameVerifier = new StrictHostnameVerifier(); mCurrentVerifier = HostnameVerifierEnum.STRICT; } } return mHostnameVerifier; }
From source file:org.keycloak.truststore.JSSETruststoreConfigurator.java
public HostnameVerifier getHostnameVerifier() { if (provider == null) { return null; }/*w w w . j a v a 2 s . c o m*/ HostnameVerificationPolicy policy = provider.getPolicy(); switch (policy) { case ANY: return new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }; case WILDCARD: return new BrowserCompatHostnameVerifier(); case STRICT: return new StrictHostnameVerifier(); default: throw new IllegalStateException("Unknown policy: " + policy.name()); } }
From source file:org.couchpotato.CouchPotato.java
private CouchPotato(String scheme, String hostname, int port, String path, String api, String username, String password, boolean trustAll, String trustMe) { this.scheme = scheme; this.hostName = hostname; this.port = port; this.path = path; this.api = api; this.username = username; this.password = password; this.trustAll = trustAll; if (this.username == null) this.username = ""; if (this.password == null) this.password = ""; // Configure SSL behavior based on user preferences Authenticator.setDefault(new CouchAuthenticator(username, password, hostname)); HostnameVerifier verifier;//from w w w . ja va2s.c o m try { SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager(trustAll, trustMe) }, new SecureRandom()); if (trustAll) { verifier = new AllowAllHostnameVerifier(); } else { verifier = new StrictHostnameVerifier(); } HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(verifier); } catch (NoSuchAlgorithmException e) { } catch (KeyManagementException e) { } catch (KeyStoreException e) { } }
From source file:org.envirocar.wps.TrackToCSVProcess.java
protected HttpClient createClient() throws IOException { SSLSocketFactory sslsf;//from w w w. j ava 2 s . c om try { sslsf = new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { // XXX !!! return true; } }, new StrictHostnameVerifier()); } catch (KeyManagementException e) { throw new IOException(e); } catch (UnrecoverableKeyException e) { throw new IOException(e); } catch (NoSuchAlgorithmException e) { throw new IOException(e); } catch (KeyStoreException e) { throw new IOException(e); } Scheme httpsScheme2 = new Scheme("https", 443, sslsf); DefaultHttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register(httpsScheme2); return client; }
From source file:org.sickbeard.SickBeard.java
public SickBeard(String hostname, String port, String api, boolean https, String extraPath, String user, String password, boolean trustAll, String trustMe) { this.hostname = hostname; this.port = port; this.extraPath = "/" + extraPath + "/"; this.path = this.extraPath + "/api/" + api + "/"; try {//from w w w.j a va 2 s .c o m this.https = https; this.scheme = https ? "https" : "http"; Authenticator.setDefault(new SickAuthenticator(user, password, hostname)); HostnameVerifier verifier; SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager(trustAll, trustMe) }, new SecureRandom()); if (trustAll) { verifier = new AllowAllHostnameVerifier(); } else { verifier = new StrictHostnameVerifier(); } HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(verifier); } catch (Exception e) { ; } /*********************************************************** * ANDROID SPECIFIC START * ***********************************************************/ // start a AsyncTask to try and find the actual api version number AsyncTask<Void, Void, CommandsJson> task = new AsyncTask<Void, Void, CommandsJson>() { @Override protected CommandsJson doInBackground(Void... arg0) { try { return SickBeard.this.sbGetCommands(); } catch (Exception e) { Log.e("SickBeard", e.getMessage(), e); return null; } } @Override protected void onPostExecute(CommandsJson result) { // do nothing because this is a network error if (result == null) return; try { // if we get a version use it SickBeard.this.apiVersion = Integer.valueOf(result.api_version); } catch (NumberFormatException e) { // 2 was the odd float so assume its 2 if we cant get an int SickBeard.this.apiVersion = 2; } } }; task.execute(); /*********************************************************** * ANDROID SPECIFIC END * ***********************************************************/ }
From source file:com.axibase.tsd.client.HttpClient.java
static PoolingHttpClientConnectionManager createConnectionManager(ClientConfiguration clientConfiguration, SslConfigurator sslConfig) {/*from w w w . j ava 2 s . co m*/ SSLContext sslContext = sslConfig.createSSLContext(); X509HostnameVerifier hostnameVerifier; if (clientConfiguration.isIgnoreSSLErrors()) { ignoreSslCertificateErrorInit(sslContext); hostnameVerifier = new AllowAllHostnameVerifier(); } else { hostnameVerifier = new StrictHostnameVerifier(); } LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); return new PoolingHttpClientConnectionManager(registry); }
From source file:org.opensaml.security.httpclient.HttpClientSecuritySupportTest.java
@Test public void testMarshalSecurityParametersEmptyContext() { HttpClientContext context = HttpClientContext.create(); HttpClientSecurityParameters params = new HttpClientSecurityParameters(); params.setCredentialsProvider(new BasicCredentialsProvider()); params.setTLSTrustEngine(new MockTrustEngine()); params.setTLSCriteriaSet(new CriteriaSet()); params.setTLSProtocols(Lists.newArrayList("foo")); params.setTLSCipherSuites(Lists.newArrayList("foo")); params.setClientTLSCredential(new BasicX509Credential(cert)); params.setHostnameVerifier(new StrictHostnameVerifier()); HttpClientSecuritySupport.marshalSecurityParameters(context, params, false); Assert.assertSame(context.getCredentialsProvider(), params.getCredentialsProvider()); Assert.assertSame(context.getAttribute(CONTEXT_KEY_TRUST_ENGINE), params.getTLSTrustEngine()); Assert.assertSame(context.getAttribute(CONTEXT_KEY_CRITERIA_SET), params.getTLSCriteriaSet()); Assert.assertSame(context.getAttribute(CONTEXT_KEY_TLS_PROTOCOLS), params.getTLSProtocols()); Assert.assertSame(context.getAttribute(CONTEXT_KEY_TLS_CIPHER_SUITES), params.getTLSCipherSuites()); Assert.assertSame(context.getAttribute(CONTEXT_KEY_CLIENT_TLS_CREDENTIAL), params.getClientTLSCredential()); Assert.assertSame(context.getAttribute(CONTEXT_KEY_HOSTNAME_VERIFIER), params.getHostnameVerifier()); }
From source file:org.opensaml.security.httpclient.impl.TrustEngineTLSSocketFactoryTest.java
@Test public void testSuccessWithEngineAndVerifier() throws IOException { X509Credential cred = getCredential("foo-1A1-good.crt"); ExplicitKeyTrustEngine trustEngine = new ExplicitKeyTrustEngine(new StaticCredentialResolver(cred)); httpContext.setAttribute(HttpClientSecurityConstants.CONTEXT_KEY_TRUST_ENGINE, trustEngine); trustEngineFactory = new TrustEngineTLSSocketFactory( buildInnerSSLFactory(Collections.singletonList((Certificate) cred.getEntityCertificate()), hostname),//w w w.jav a 2s . c o m new StrictHostnameVerifier()); Socket socket = trustEngineFactory.createSocket(httpContext); trustEngineFactory.connectSocket(0, socket, new HttpHost(hostname, 443, "https"), null, null, httpContext); Assert.assertEquals( httpContext.getAttribute(HttpClientSecurityConstants.CONTEXT_KEY_SERVER_TLS_CREDENTIAL_TRUSTED), Boolean.TRUE); }
From source file:org.opensaml.security.httpclient.impl.SecurityEnhancedTLSSocketFactoryTest.java
@Test public void testSuccessWithEngineAndVerifier() throws IOException { X509Credential cred = getCredential("foo-1A1-good.crt"); ExplicitKeyTrustEngine trustEngine = new ExplicitKeyTrustEngine(new StaticCredentialResolver(cred)); httpContext.setAttribute(HttpClientSecurityConstants.CONTEXT_KEY_TRUST_ENGINE, trustEngine); securityEnhancedSocketFactory = new SecurityEnhancedTLSSocketFactory( buildInnerSSLFactory(Collections.singletonList((Certificate) cred.getEntityCertificate()), hostname),//from w ww.j a v a 2s . com new StrictHostnameVerifier()); Socket socket = securityEnhancedSocketFactory.createSocket(httpContext); securityEnhancedSocketFactory.connectSocket(0, socket, new HttpHost(hostname, 443, "https"), null, null, httpContext); Assert.assertEquals( httpContext.getAttribute(HttpClientSecurityConstants.CONTEXT_KEY_SERVER_TLS_CREDENTIAL_TRUSTED), Boolean.TRUE); }