Guest User

Untitled

a guest
Oct 8th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.02 KB | None | 0 0
  1. package com.google.android.gms.common.security;
  2.  
  3. import android.content.Context;
  4. import android.content.pm.PackageManager.NameNotFoundException;
  5. import android.util.Log;
  6. import com.google.android.gms.common.util.DynamiteApi;
  7. import com.google.android.gms.common.util.RetainForClient;
  8. import com.google.android.gms.org.conscrypt.OpenSSLProvider;
  9. import java.lang.reflect.Field;
  10. import java.security.NoSuchAlgorithmException;
  11. import java.security.Security;
  12. import javax.net.ssl.HttpsURLConnection;
  13. import javax.net.ssl.SSLContext;
  14. import javax.net.ssl.SSLServerSocketFactory;
  15. import javax.net.ssl.SSLSocketFactory;
  16. import p000.oat;
  17. import p000.oau;
  18. import p000.ojo;
  19. import p000.olm;
  20. import p000.olp;
  21.  
  22. @RetainForClient
  23. @DynamiteApi
  24. /* compiled from: :com.google.android.gms@[email protected] (110400-213742215) */
  25. public class ProviderInstallerImpl {
  26.     /* renamed from: a */
  27.     private static final Object f2866a = new Object();
  28.     /* renamed from: b */
  29.     private static OpenSSLProvider f2867b;
  30.  
  31.     private static native int getNativeCodeVersion();
  32.  
  33.     @RetainForClient
  34.     public static void insertProvider(Context context) {
  35.         Context oau = new oau(context);
  36.         synchronized (f2866a) {
  37.             if (f2867b == null) {
  38.                 if ("com.google.android.gms".equals(oau.getPackageName())) {
  39.                     try {
  40.                         oau.getPackageManager().getApplicationInfo(oau.getPackageName(), 0);
  41.                         if (olm.m3976b(oau, "conscrypt_gmscore_jni")) {
  42.                             if (olp.m3983a(ojo.m3763b(oau)) != getNativeCodeVersion()) {
  43.                                 Log.e("ProviderInstaller", String.format("libgmscore version mismatch (%d vs. %d)", new Object[]{Integer.valueOf(olp.m3983a(ojo.m3763b(oau))), Integer.valueOf(getNativeCodeVersion())}));
  44.                                 throw new SecurityException();
  45.                             }
  46.                         }
  47.                         throw new SecurityException();
  48.                     } catch (UnsatisfiedLinkError e) {
  49.                         throw new SecurityException();
  50.                     } catch (NameNotFoundException e2) {
  51.                         Log.e("ProviderInstaller", "Failed to find ApplicationInfo");
  52.                         throw new SecurityException();
  53.                     } catch (NoSuchAlgorithmException e3) {
  54.                         Log.e("ProviderInstaller", "Failed to find SSLContext.Default provider");
  55.                         throw new SecurityException();
  56.                     } catch (NoSuchAlgorithmException e4) {
  57.                         Log.e("ProviderInstaller", "Failed to find SSLContext.Default provider");
  58.                         throw new SecurityException();
  59.                     } catch (IllegalAccessException e5) {
  60.                         Log.e("ProviderInstaller", "Failed to set socket factory via reflection");
  61.                         throw new SecurityException();
  62.                     } catch (NoSuchFieldException e6) {
  63.                         Log.e("ProviderInstaller", "Failed to set socket factory via reflection");
  64.                         throw new SecurityException();
  65.                     }
  66.                 }
  67.                 System.loadLibrary("conscrypt_gmscore_jni");
  68.                 f2867b = new OpenSSLProvider("GmsCore_OpenSSL");
  69.             }
  70.             int insertProviderAt = Security.insertProviderAt(f2867b, 1);
  71.             if (insertProviderAt == 1) {
  72.                 SSLContext instance = SSLContext.getInstance("Default");
  73.                 Field declaredField = SSLSocketFactory.class.getDeclaredField("defaultSocketFactory");
  74.                 declaredField.setAccessible(true);
  75.                 declaredField.set(null, instance.getSocketFactory());
  76.                 declaredField = SSLServerSocketFactory.class.getDeclaredField("defaultServerSocketFactory");
  77.                 declaredField.setAccessible(true);
  78.                 declaredField.set(null, instance.getServerSocketFactory());
  79.                 Security.setProperty("ssl.SocketFactory.provider", "com.google.android.gms.org.conscrypt.OpenSSLSocketFactoryImpl");
  80.                 Security.setProperty("ssl.ServerSocketFactory.provider", "com.google.android.gms.org.conscrypt.OpenSSLServerSocketFactoryImpl");
  81.                 instance = SSLContext.getInstance("Default");
  82.                 SSLContext.setDefault(instance);
  83.                 HttpsURLConnection.setDefaultSSLSocketFactory(instance.getSocketFactory());
  84.                 HttpsURLConnection.setDefaultHostnameVerifier(new oat());
  85.                 Log.i("ProviderInstaller", "Installed default security provider GmsCore_OpenSSL");
  86.             } else if (insertProviderAt != -1) {
  87.                 StringBuilder stringBuilder = new StringBuilder(72);
  88.                 stringBuilder.append("Failed to install security provider GmsCore_OpenSSL, result: ");
  89.                 stringBuilder.append(insertProviderAt);
  90.                 Log.e("ProviderInstaller", stringBuilder.toString());
  91.                 throw new SecurityException();
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment