SourceStampVerification Return more specific error code when verification fails

Summary:
Upstream from Meta
If the source stamp tag is not present, SignatureNotFoundException is thrown.
In such cases , it is better to return with
SourceStampVerificationResult.notPresent() instead of
SourceStampVerificationResult.notVerified()
Also modified Android platform core tests (APCT) to reflect this change

Test: Verified using Android platform core tests (APCT)
All other tests pass successfully

Reviewers:

Subscribers:

Tasks:

Tags:
Change-Id: Ifb4b05b6c4a18646cb72fbdc03c529e80f798b21
Signed-off-by: sourabh-nanoti <sourabhn@meta.com>
This commit is contained in:
sourabh-nanoti
2023-06-21 21:16:22 -07:00
parent 3e77c6f37e
commit 5fae7f3900
2 changed files with 8 additions and 3 deletions

View File

@@ -142,16 +142,21 @@ public abstract class SourceStampVerifier {
private static SourceStampVerificationResult verify(
RandomAccessFile apk, byte[] sourceStampCertificateDigest, byte[] manifestBytes) {
SignatureInfo signatureInfo;
try {
SignatureInfo signatureInfo =
signatureInfo =
ApkSigningBlockUtils.findSignature(apk, SOURCE_STAMP_BLOCK_ID);
} catch (IOException | SignatureNotFoundException | RuntimeException e) {
return SourceStampVerificationResult.notPresent();
}
try {
Map<Integer, Map<Integer, byte[]>> signatureSchemeApkContentDigests =
getSignatureSchemeApkContentDigests(apk, manifestBytes);
return verify(
signatureInfo,
getSignatureSchemeDigests(signatureSchemeApkContentDigests),
sourceStampCertificateDigest);
} catch (IOException | SignatureNotFoundException | RuntimeException e) {
} catch (IOException | RuntimeException e) {
return SourceStampVerificationResult.notVerified();
}
}

View File

@@ -100,7 +100,7 @@ public class SourceStampVerifierTest {
SourceStampVerificationResult result =
SourceStampVerifier.verify(mPrimaryApk.getAbsolutePath());
assertTrue(result.isPresent());
assertFalse(result.isPresent());
assertFalse(result.isVerified());
assertNull(result.getCertificate());
}