MD5 校验值:59d6bb13fd8223deae94352611fb8159
SSLFactory.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.openmediation.sdk.utils.request.network.certificate; import android.os.Build; import com.openmediation.sdk.utils.crash.CrashUtil; import java.net.InetAddress; import java.net.Socket; import java.security.GeneralSecurityException; import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.X509TrustManager; public class SSLFactory extends SSLSocketFactory { private static String[] cipherSuites; private static String[] protocols; private SSLSocketFactory defaultFactory; static { try { SSLSocket sSLSocket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(); if (sSLSocket != null) { LinkedList linkedList = new LinkedList(); for (String str : sSLSocket.getSupportedProtocols()) { if (!str.toUpperCase().contains("SSL")) { linkedList.add(str); } } protocols = (String[]) linkedList.toArray(new String[linkedList.size()]); if (Build.VERSION.SDK_INT < 21) { List asList = Arrays.asList("TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECHDE_RSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"); List asList2 = Arrays.asList(sSLSocket.getSupportedCipherSuites()); HashSet hashSet = new HashSet(asList); hashSet.retainAll(asList2); hashSet.addAll(new HashSet(Arrays.asList(sSLSocket.getEnabledCipherSuites()))); cipherSuites = (String[]) hashSet.toArray(new String[hashSet.size()]); } } } catch (Exception e) { CrashUtil.getSingleton().saveException(e); } } public SSLFactory() { try { SSLContext sSLContext = SSLContext.getInstance("TLS"); sSLContext.init(null, new X509TrustManager[]{new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) { } @Override public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) { } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }}, null); this.defaultFactory = sSLContext.getSocketFactory(); } catch (GeneralSecurityException unused) { throw new AssertionError(); } } private void upgradeTLS(SSLSocket sSLSocket) { String[] strArr; String[] strArr2 = protocols; if (strArr2 != null) { sSLSocket.setEnabledProtocols(strArr2); } if (Build.VERSION.SDK_INT >= 21 || (strArr = cipherSuites) == null) { return; } sSLSocket.setEnabledCipherSuites(strArr); } @Override public Socket createSocket(String str, int i) { Socket createSocket = this.defaultFactory.createSocket(str, i); if (createSocket instanceof SSLSocket) { upgradeTLS((SSLSocket) createSocket); } return createSocket; } @Override public Socket createSocket(String str, int i, InetAddress inetAddress, int i2) { Socket createSocket = this.defaultFactory.createSocket(str, i, inetAddress, i2); if (createSocket instanceof SSLSocket) { upgradeTLS((SSLSocket) createSocket); } return createSocket; } @Override public Socket createSocket(InetAddress inetAddress, int i) { Socket createSocket = this.defaultFactory.createSocket(inetAddress, i); if (createSocket instanceof SSLSocket) { upgradeTLS((SSLSocket) createSocket); } return createSocket; } @Override public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress2, int i2) { Socket createSocket = this.defaultFactory.createSocket(inetAddress, i, inetAddress2, i2); if (createSocket instanceof SSLSocket) { upgradeTLS((SSLSocket) createSocket); } return createSocket; } @Override public Socket createSocket(Socket socket, String str, int i, boolean z) { Socket createSocket = this.defaultFactory.createSocket(socket, str, i, z); if (createSocket instanceof SSLSocket) { upgradeTLS((SSLSocket) createSocket); } return createSocket; } @Override public String[] getDefaultCipherSuites() { return cipherSuites; } @Override public String[] getSupportedCipherSuites() { return cipherSuites; } }