Merge "Limit the number of supported v1 and v2 signers" into rvc-dev am: 00f3afecdb am: d8cdf2d931 am: b4784aeb00 am: 027abf1925 am: 6cc59ca486
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22390145 Change-Id: Ib8513a41ae205e9683989302893b1f1480f05792 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -74,6 +74,11 @@ public class ApkSignatureSchemeV2Verifier {
|
|||||||
|
|
||||||
private static final int APK_SIGNATURE_SCHEME_V2_BLOCK_ID = 0x7109871a;
|
private static final int APK_SIGNATURE_SCHEME_V2_BLOCK_ID = 0x7109871a;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of signers supported by the v2 APK signature scheme.
|
||||||
|
*/
|
||||||
|
private static final int MAX_V2_SIGNERS = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} if the provided APK contains an APK Signature Scheme V2 signature.
|
* Returns {@code true} if the provided APK contains an APK Signature Scheme V2 signature.
|
||||||
*
|
*
|
||||||
@@ -182,6 +187,11 @@ public class ApkSignatureSchemeV2Verifier {
|
|||||||
}
|
}
|
||||||
while (signers.hasRemaining()) {
|
while (signers.hasRemaining()) {
|
||||||
signerCount++;
|
signerCount++;
|
||||||
|
if (signerCount > MAX_V2_SIGNERS) {
|
||||||
|
throw new SecurityException(
|
||||||
|
"APK Signature Scheme v2 only supports a maximum of " + MAX_V2_SIGNERS
|
||||||
|
+ " signers");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ByteBuffer signer = getLengthPrefixedSlice(signers);
|
ByteBuffer signer = getLengthPrefixedSlice(signers);
|
||||||
X509Certificate[] certs = verifySigner(signer, contentDigests, certFactory);
|
X509Certificate[] certs = verifySigner(signer, contentDigests, certFactory);
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ class StrictJarVerifier {
|
|||||||
"SHA1",
|
"SHA1",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of signers supported by the JAR signature scheme.
|
||||||
|
*/
|
||||||
|
private static final int MAX_JAR_SIGNERS = 10;
|
||||||
|
|
||||||
private final String jarName;
|
private final String jarName;
|
||||||
private final StrictJarManifest manifest;
|
private final StrictJarManifest manifest;
|
||||||
private final HashMap<String, byte[]> metaEntries;
|
private final HashMap<String, byte[]> metaEntries;
|
||||||
@@ -293,10 +298,16 @@ class StrictJarVerifier {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int signerCount = 0;
|
||||||
Iterator<String> it = metaEntries.keySet().iterator();
|
Iterator<String> it = metaEntries.keySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String key = it.next();
|
String key = it.next();
|
||||||
if (key.endsWith(".DSA") || key.endsWith(".RSA") || key.endsWith(".EC")) {
|
if (key.endsWith(".DSA") || key.endsWith(".RSA") || key.endsWith(".EC")) {
|
||||||
|
if (++signerCount > MAX_JAR_SIGNERS) {
|
||||||
|
throw new SecurityException(
|
||||||
|
"APK Signature Scheme v1 only supports a maximum of " + MAX_JAR_SIGNERS
|
||||||
|
+ " signers");
|
||||||
|
}
|
||||||
verifyCertificate(key);
|
verifyCertificate(key);
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user