what-the-bank/sources/com/google/android/gms/common/GoogleSignatureVerifier.java

142 lines
5.2 KiB
Java

package com.google.android.gms.common;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import com.google.android.gms.common.internal.Preconditions;
import com.google.errorprone.annotations.RestrictedInheritance;
import java.util.Set;
@RestrictedInheritance(allowedOnPath = ".*java.*/com/google/android/gms/common/testing/.*", explanation = "Sub classing of GMS Core's APIs are restricted to testing fakes.", link = "go/gmscore-restrictedinheritance")
/* loaded from: classes.dex */
public class GoogleSignatureVerifier {
private static GoogleSignatureVerifier zza;
private static volatile Set zzb;
private final Context zzc;
private volatile String zzd;
public GoogleSignatureVerifier(Context context) {
this.zzc = context.getApplicationContext();
}
public static GoogleSignatureVerifier getInstance(Context context) {
Preconditions.checkNotNull(context);
synchronized (GoogleSignatureVerifier.class) {
if (zza == null) {
zzn.zze(context);
zza = new GoogleSignatureVerifier(context);
}
}
return zza;
}
static final zzj zza(PackageInfo packageInfo, zzj... zzjVarArr) {
if (packageInfo.signatures == null || packageInfo.signatures.length != 1) {
return null;
}
zzk zzkVar = new zzk(packageInfo.signatures[0].toByteArray());
for (int i = 0; i < zzjVarArr.length; i++) {
if (zzjVarArr[i].equals(zzkVar)) {
return zzjVarArr[i];
}
}
return null;
}
public static final boolean zzb(PackageInfo packageInfo, boolean z) {
zzj zza2;
if (z && packageInfo != null && ("com.android.vending".equals(packageInfo.packageName) || "com.google.android.gms".equals(packageInfo.packageName))) {
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
z = (applicationInfo == null || (applicationInfo.flags & 129) == 0) ? false : true;
}
if (packageInfo != null && packageInfo.signatures != null) {
if (z) {
zza2 = zza(packageInfo, zzm.zza);
} else {
zza2 = zza(packageInfo, zzm.zza[0]);
}
if (zza2 != null) {
return true;
}
}
return false;
}
private final zzx zzc(String str, boolean z, boolean z2) {
zzx zzc;
if (str == null) {
return zzx.zzc("null pkg");
}
if (str.equals(this.zzd)) {
return zzx.zzb();
}
if (zzn.zzg()) {
zzc = zzn.zzb(str, GooglePlayServicesUtilLight.honorsDebugCertificates(this.zzc), false, false);
} else {
try {
PackageInfo packageInfo = this.zzc.getPackageManager().getPackageInfo(str, 64);
boolean honorsDebugCertificates = GooglePlayServicesUtilLight.honorsDebugCertificates(this.zzc);
if (packageInfo == null) {
zzc = zzx.zzc("null pkg");
} else if (packageInfo.signatures == null || packageInfo.signatures.length != 1) {
zzc = zzx.zzc("single cert required");
} else {
zzk zzkVar = new zzk(packageInfo.signatures[0].toByteArray());
String str2 = packageInfo.packageName;
zzx zza2 = zzn.zza(str2, zzkVar, honorsDebugCertificates, false);
zzc = (!zza2.zza || packageInfo.applicationInfo == null || (packageInfo.applicationInfo.flags & 2) == 0 || !zzn.zza(str2, zzkVar, false, true).zza) ? zza2 : zzx.zzc("debuggable release cert app rejected");
}
} catch (PackageManager.NameNotFoundException e) {
return zzx.zzd("no pkg ".concat(str), e);
}
}
if (zzc.zza) {
this.zzd = str;
}
return zzc;
}
public boolean isGooglePublicSignedPackage(PackageInfo packageInfo) {
if (packageInfo == null) {
return false;
}
if (zzb(packageInfo, false)) {
return true;
}
return zzb(packageInfo, true) && GooglePlayServicesUtilLight.honorsDebugCertificates(this.zzc);
}
public boolean isPackageGoogleSigned(String str) {
zzx zzc = zzc(str, false, false);
zzc.zze();
return zzc.zza;
}
public boolean isUidGoogleSigned(int i) {
zzx zzc;
int length;
String[] packagesForUid = this.zzc.getPackageManager().getPackagesForUid(i);
if (packagesForUid != null && (length = packagesForUid.length) != 0) {
zzc = null;
int i2 = 0;
while (true) {
if (i2 < length) {
zzc = zzc(packagesForUid[i2], false, false);
if (zzc.zza) {
break;
}
i2++;
} else {
Preconditions.checkNotNull(zzc);
break;
}
}
} else {
zzc = zzx.zzc("no pkgs");
}
zzc.zze();
return zzc.zza;
}
}