Fix incomplete certificate requests causing crashes

This commit is contained in:
Marvin W 2019-07-03 11:24:34 +02:00
parent 5d6e9ac01c
commit 8a0010a1d8
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A
2 changed files with 20 additions and 2 deletions

View File

@ -16,6 +16,7 @@
package com.google.android.gms.common; package com.google.android.gms.common;
import android.content.pm.PackageManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.annotation.Keep; import android.support.annotation.Keep;
import android.util.Log; import android.util.Log;
@ -55,6 +56,14 @@ public class GoogleCertificatesImpl extends IGoogleCertificatesApi.Stub {
@Override @Override
public boolean isGoogleOrPlatformSigned(GoogleCertificatesQuery query, IObjectWrapper packageManager) throws RemoteException { public boolean isGoogleOrPlatformSigned(GoogleCertificatesQuery query, IObjectWrapper packageManager) throws RemoteException {
return PackageUtils.isGooglePackage(query.getPackageName(), query.getCertData().getBytes()); PackageManager pm = ObjectWrapper.unwrapTyped(packageManager, PackageManager.class);
if (query == null || query.getPackageName() == null) {
return false;
} else if (query.getCertData() == null) {
if (pm == null) return false;
return PackageUtils.isGooglePackage(pm, query.getPackageName());
} else {
return PackageUtils.isGooglePackage(query.getPackageName(), query.getCertData().getBytes());
}
} }
} }

View File

@ -69,6 +69,11 @@ public class PackageUtils {
return isGooglePackage(packageName, signatureDigest); return isGooglePackage(packageName, signatureDigest);
} }
public static boolean isGooglePackage(PackageManager packageManager, String packageName) {
String signatureDigest = firstSignatureDigest(packageManager, packageName);
return isGooglePackage(packageName, signatureDigest);
}
public static boolean isGooglePackage(String packageName, byte[] bytes) { public static boolean isGooglePackage(String packageName, byte[] bytes) {
return isGooglePackage(packageName, sha1sum(bytes)); return isGooglePackage(packageName, sha1sum(bytes));
} }
@ -102,7 +107,11 @@ public class PackageUtils {
@Nullable @Nullable
public static String firstSignatureDigest(Context context, String packageName) { public static String firstSignatureDigest(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager(); return firstSignatureDigest(context.getPackageManager(), packageName);
}
@Nullable
public static String firstSignatureDigest(PackageManager packageManager, String packageName) {
final PackageInfo info; final PackageInfo info;
try { try {
info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);