Android SSLSocketFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SSLSocketFactory class.

This code example shows how to use the following methods:setHostnameVerifier
			Context context) {
		try { 
			// Pass the keystore to the SSLSocketFactory. The factory is 
			// responsible 
			// for the verification of the server certificate. 
			SSLSocketFactory sf = new SSLSocketFactory(loadOWKeyStore(context));
			// Hostname verification from certificate 
			// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 
			sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
			return sf;
		} catch (Exception e) {
			throw new AssertionError(e);
		} 
	} 
 
 
	private static KeyStore loadOWKeyStore(Context c) {
		KeyStore trusted = null;
		try { 
			// Get an instance of the Bouncy Castle KeyStore format 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createSocket
                return delegate.isSecure(sock);
            } 
            @Override public Socket createSocket(Socket socket, String host, int port,
                    boolean autoClose) throws IOException {
                injectHostname(socket, host);
                return delegate.createSocket(socket, host, port, autoClose);
            } 
            private void injectHostname(Socket socket, String host) {
                try { 
                    Field field = InetAddress.class.getDeclaredField("hostName");
                    field.setAccessible(true);
                    field.set(socket.getInetAddress(), host);
                } catch (Exception ignored) {
                } 
            } 
        }; 
        client.getConnectionManager().getSchemeRegistry()
                .register(new Scheme("https", socketFactory, 443));
    } 
     
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        boolean strictHostVerification = securityOne.isStrictHostVerification() && securityTwo.isStrictHostVerification();
 
        context.init(new KeyManager[]{keyManagerOne, keyManagerTwo}, new TrustManager[]{trustManager}, new SecureRandom());
        X509HostnameVerifier verifier = strictHostVerification ?
                SSLSocketFactory.STRICT_HOSTNAME_VERIFIER : SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        return new SSLSocketFactory(context, verifier);
    } 
 
    public static SSLSocketFactory getFactory(Security security) throws GeneralSecurityException {
        X509HostnameVerifier verifier = security.isStrictHostVerification() ?
                SSLSocketFactory.STRICT_HOSTNAME_VERIFIER : SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        SSLSocketFactory socketFactory = new SSLSocketFactory(security.getSslContextProtocol(),
                security.getKeyStore(), security.getKeyStorePasswordAsString(),
                security.getTrustStore(), new SecureRandom(), null, verifier);
        return socketFactory;
    } 
 
 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHostnameVerifier
			// Get the raw resource, which contains the keystore with 
			// your trusted certificates (root and any intermediate certs) 
			// Pass the keystore to the SSLSocketFactory. The factory is 
			// responsible 
			// for the verification of the server certificate. 
			SSLSocketFactory sf = new SSLSocketFactory(trusted);
			// Hostname verification from certificate 
			// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 
			sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
			return sf;
		} 
		catch (Exception e)
		{ 
			throw new AssertionError(e);
		} 
	} 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHostnameVerifier
This code example shows how to use the following methods:setHostnameVerifier
This code example shows how to use the following methods:setHostnameVerifier
 
    public static SSLSocketFactory getFixedSocketFactory() {
        SSLSocketFactory socketFactory;
        try { 
            socketFactory = new MySSLSocketFactory(getKeystore());
            socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        } catch (Throwable t) {
            t.printStackTrace();
            socketFactory = SSLSocketFactory.getSocketFactory();
        } 
        return socketFactory;
    } 
 
} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHostnameVerifier
			KeyStore trustStore = KeyStore.getInstance(KeyStore
					.getDefaultType());
			trustStore.load(null, null);
 
			SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
			sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_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);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHostnameVerifier
			KeyStore trustStore = KeyStore.getInstance(KeyStore
					.getDefaultType());
			trustStore.load(null, null);
 
			SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
			sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_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);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHostnameVerifier
		 */ 
	 
		if ((keyStore == null) || (trustStore == null))
			throw new Exception("[SOAPSenderImpl] keystore initialization missing");
		 
		SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, // String algorithm
				keyStore, 					 // KeyStore keystore
				keyStoreParam.getPassword(), // String keystorePassword
				trustStore, 				 // KeyStore truststore
				null, 						 // SecureRandom random 
				null 						 // HostNameResolver nameResolver 
		); 
 
		// Hostname verification from certificate 
		// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 
		socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // .STRICT_HOSTNAME_VERIFIER);
		return socketFactory;
			 
	} 
 
	/** 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android SSLSocketFactory Questions & Answers:

See Code Examples for Android SSLSocketFactory Methods: