package com.huawei.secure.android.common; import android.content.Context; import com.huawei.secure.android.common.ssl.SSLUtil; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.X509TrustManager; import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier; import org.apache.http.conn.ssl.StrictHostnameVerifier; import org.apache.http.conn.ssl.X509HostnameVerifier; @Deprecated public class SecureSSLSocketFactory extends SSLSocketFactory { public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER = new BrowserCompatHostnameVerifier(); public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER = new StrictHostnameVerifier(); private static volatile SecureSSLSocketFactory c = null; private SSLContext a; private Context b; private SecureSSLSocketFactory(Context context) throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException, KeyManagementException, IllegalAccessException { this.a = null; this.b = context; this.a = SSLUtil.setSSLContext(); SecureX509TrustManager secureX509TrustManager = new SecureX509TrustManager(this.b); this.a.init(null, new X509TrustManager[]{secureX509TrustManager}, null); } private void a(Socket socket) { SSLSocket sSLSocket = (SSLSocket) socket; SSLUtil.setEnabledProtocols(sSLSocket); SSLUtil.setEnableSafeCipherSuites(sSLSocket); } @Deprecated public static SecureSSLSocketFactory getInstance(Context context) throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IllegalAccessException, KeyManagementException { if (c == null) { synchronized (SecureSSLSocketFactory.class) { if (c == null) { c = new SecureSSLSocketFactory(context); } } } return c; } @Override // javax.net.SocketFactory public Socket createSocket(String str, int i) throws IOException, UnknownHostException { Socket createSocket = this.a.getSocketFactory().createSocket(str, i); if (createSocket instanceof SSLSocket) { a(createSocket); } return createSocket; } public String[] getDefaultCipherSuites() { return new String[0]; } public String[] getSupportedCipherSuites() { return new String[0]; } @Override // javax.net.SocketFactory public Socket createSocket(InetAddress inetAddress, int i) throws IOException { return createSocket(inetAddress.getHostAddress(), i); } @Override // javax.net.SocketFactory public Socket createSocket(String str, int i, InetAddress inetAddress, int i2) throws IOException, UnknownHostException { return createSocket(str, i); } @Override // javax.net.SocketFactory public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress2, int i2) throws IOException { return createSocket(inetAddress.getHostAddress(), i); } @Override // javax.net.ssl.SSLSocketFactory public Socket createSocket(Socket socket, String str, int i, boolean z) throws IOException { Socket createSocket = this.a.getSocketFactory().createSocket(socket, str, i, z); if (createSocket instanceof SSLSocket) { a(createSocket); } return createSocket; } @Deprecated public SecureSSLSocketFactory(InputStream inputStream, String str) throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException, KeyManagementException { this.a = null; this.a = SSLUtil.setSSLContext(); HiCloudX509TrustManager hiCloudX509TrustManager = new HiCloudX509TrustManager(inputStream, str); this.a.init(null, new X509TrustManager[]{hiCloudX509TrustManager}, null); } }