Restore V2+ signature requirement for system apps

In Android R, the platform began enforcing a requirement that apps
targeting this release or later must be signed with at least the V2
signature scheme. Initially, this requirement was applied to system
apps, but due to the build system stripping V2+ signatures due to
compressed dex and library files, the requirement had to be relaxed
for system apps; since then, the system apps have been updated with
uncompressed dex and library files to prevent the signature stripping
by the build system. This commit restores the requirement that
system apps targeting SDK version 30+ must be signed with at least
the V2 signature scheme.

Bug: 215046612
Test: Manually verified fix properly identified system app without
       V2+ signature
Change-Id: I5b482931a99ea8c2308d516912317ff0828153e2
This commit is contained in:
Michael Groover
2022-03-25 17:25:03 -07:00
parent 27e35ec6c3
commit 7cb3a32293
4 changed files with 14 additions and 20 deletions

View File

@@ -1414,11 +1414,9 @@ public class PackageParser {
final ParseTypeImpl input = ParseTypeImpl.forDefaultParsing();
final ParseResult<android.content.pm.SigningDetails> result;
if (skipVerify) {
// systemDir APKs are already trusted, save time by not verifying; since the signature
// is not verified and some system apps can have their V2+ signatures stripped allow
// pulling the certs from the jar signature.
// systemDir APKs are already trusted, save time by not verifying
result = ApkSignatureVerifier.unsafeGetCertsWithoutVerification(
input, apkPath, SigningDetails.SignatureSchemeVersion.JAR);
input, apkPath, minSignatureScheme);
} else {
result = ApkSignatureVerifier.verify(input, apkPath, minSignatureScheme);
}

View File

@@ -4190,8 +4190,8 @@ final class InstallPackageHelper {
assertOverlayIsValid(pkg, parseFlags, scanFlags);
}
// If the package is not on a system partition ensure it is signed with at least the
// minimum signature scheme version required for its target SDK.
// Ensure the package is signed with at least the minimum signature scheme version
// required for its target SDK.
ScanPackageUtils.assertMinSignatureSchemeIsValid(pkg, parseFlags);
}
}

View File

@@ -690,16 +690,14 @@ final class ScanPackageUtils {
public static void assertMinSignatureSchemeIsValid(AndroidPackage pkg,
@ParsingPackageUtils.ParseFlags int parseFlags) throws PackageManagerException {
if ((parseFlags & ParsingPackageUtils.PARSE_IS_SYSTEM_DIR) == 0) {
int minSignatureSchemeVersion =
ApkSignatureVerifier.getMinimumSignatureSchemeVersionForTargetSdk(
pkg.getTargetSdkVersion());
if (pkg.getSigningDetails().getSignatureSchemeVersion()
< minSignatureSchemeVersion) {
throw new PackageManagerException(INSTALL_PARSE_FAILED_NO_CERTIFICATES,
"No signature found in package of version " + minSignatureSchemeVersion
+ " or newer for package " + pkg.getPackageName());
}
int minSignatureSchemeVersion =
ApkSignatureVerifier.getMinimumSignatureSchemeVersionForTargetSdk(
pkg.getTargetSdkVersion());
if (pkg.getSigningDetails().getSignatureSchemeVersion()
< minSignatureSchemeVersion) {
throw new PackageManagerException(INSTALL_PARSE_FAILED_NO_CERTIFICATES,
"No signature found in package of version " + minSignatureSchemeVersion
+ " or newer for package " + pkg.getPackageName());
}
}

View File

@@ -3069,11 +3069,9 @@ public class ParsingPackageUtils {
}
final ParseResult<SigningDetails> verified;
if (skipVerify) {
// systemDir APKs are already trusted, save time by not verifying; since the
// signature is not verified and some system apps can have their V2+ signatures
// stripped allow pulling the certs from the jar signature.
// systemDir APKs are already trusted, save time by not verifying
verified = ApkSignatureVerifier.unsafeGetCertsWithoutVerification(input, baseCodePath,
SigningDetails.SignatureSchemeVersion.JAR);
minSignatureScheme);
} else {
verified = ApkSignatureVerifier.verify(input, baseCodePath, minSignatureScheme);
}