修复 DSA 签名游戏无法正常更新的问题
This commit is contained in:
@ -216,14 +216,17 @@ public class PackageUtils {
|
||||
* 判断是否是插件包
|
||||
*/
|
||||
public static boolean isSignedByGh(Context context, String packageName) {
|
||||
String signature = getApkSignatureByPackageName(context, packageName);
|
||||
String signature = getApkSignatureByPackageName(context, packageName)[0];
|
||||
return publicKey.equals(signature);
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据包名,获取apk的签名信息
|
||||
* String[0] 为系统风格的公钥字符串
|
||||
* String[1] 为接口风格的公钥字符串
|
||||
* 请自行根据需要取用
|
||||
*/
|
||||
public static String getApkSignatureByPackageName(Context context, String packageName) {
|
||||
public static String[] getApkSignatureByPackageName(Context context, String packageName) {
|
||||
try {
|
||||
PackageInfo packageInfo = context.getApplicationContext().getPackageManager()
|
||||
.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
|
||||
@ -231,14 +234,14 @@ public class PackageUtils {
|
||||
|
||||
// 使用幸运破解器破解安卓签名认证可能会出现不用签名也能装的情况,这里有可能是空的
|
||||
if (signatures[0] != null) {
|
||||
return parseSignature(signatures[0].toByteArray())[0];
|
||||
return parseSignature(signatures[0].toByteArray());
|
||||
} else {
|
||||
return null;
|
||||
return new String[]{null, null};
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return new String[]{null, null};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,14 +254,17 @@ public class PackageUtils {
|
||||
*/
|
||||
public static boolean isInstalledAppAndApkFileShareTheSameSignature(Context context, String packageName, String apkFilePath) {
|
||||
try {
|
||||
String installedPublicKey = getApkSignatureByPackageName(context, packageName);
|
||||
String[] installedPublicKeys = getApkSignatureByPackageName(context, packageName);
|
||||
|
||||
String installedPublicKey1 = installedPublicKeys[0];
|
||||
String installedPublicKey2 = installedPublicKeys[1];
|
||||
|
||||
String v1SignaturePublicKey = getV1SignatureFromFile(apkFilePath);
|
||||
if (!TextUtils.isEmpty(v1SignaturePublicKey)) {
|
||||
return v1SignaturePublicKey.equals(getApkSignatureByPackageName(context, packageName));
|
||||
return v1SignaturePublicKey.equals(installedPublicKey1) || v1SignaturePublicKey.equals(installedPublicKey2);
|
||||
}
|
||||
|
||||
return getV2SignatureFromFile(apkFilePath).equals(installedPublicKey);
|
||||
return getV2SignatureFromFile(apkFilePath).equals(installedPublicKey1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -286,8 +292,12 @@ public class PackageUtils {
|
||||
return cert.getPublicKey().toString();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
|
||||
ApkVerifier verifier = new ApkVerifier.Builder(new File(apkFilePath)).build();
|
||||
ApkVerifier.Result result = verifier.retrieveV1Signature();
|
||||
|
||||
return result.getV1SchemeSigners().get(0).getCertificate().getPublicKey().toString();
|
||||
} catch (Throwable e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -321,7 +331,7 @@ public class PackageUtils {
|
||||
new ByteArrayInputStream(signature));
|
||||
ret = new String[]{cert.getPublicKey().toString(), cert.getSerialNumber().toString()};
|
||||
if (ret[0].startsWith("DSA")) {
|
||||
ret[0] = "DSAPublicKey{" + ApkSigningBlockUtilsLite.toHex(cert.getPublicKey().getEncoded()) + "}";
|
||||
ret[1] = "DSAPublicKey{" + ApkSigningBlockUtilsLite.toHex(cert.getPublicKey().getEncoded()) + "}";
|
||||
}
|
||||
} catch (CertificateException e) {
|
||||
e.printStackTrace();
|
||||
@ -352,7 +362,7 @@ public class PackageUtils {
|
||||
}
|
||||
|
||||
// 判断当前已安装应用是否为光环签名
|
||||
if (publicKey.equals(getApkSignatureByPackageName(context, packageName))) {
|
||||
if (publicKey.equals(getApkSignatureByPackageName(context, packageName)[0])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user