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 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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));
    } 
     
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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;
    } 
 
 
} 
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
		} 
	} 
} 
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: setHostnameVerifier

Related Android SSLSocketFactory Questions & Answers:

See Code Examples for Android SSLSocketFactory Methods: