Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bff526f4 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Automerger Merge Worker
Browse files

[framework] Extract v3 digest for v4 checking correctly am: 087cf41e

Change-Id: Ib3cfeacc33ea6a133f8fc08527544c2e44d473d6
parents f31281a8 087cf41e
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -213,15 +213,24 @@ public class ApkSignatureSchemeV3Verifier {
                    verityDigest, apk.length(), signatureInfo);
        }

        if (contentDigests.containsKey(CONTENT_DIGEST_CHUNKED_SHA512)) {
            result.digest = contentDigests.get(CONTENT_DIGEST_CHUNKED_SHA512);
        } else if (contentDigests.containsKey(CONTENT_DIGEST_CHUNKED_SHA256)) {
            result.digest = contentDigests.get(CONTENT_DIGEST_CHUNKED_SHA256);
        }
        result.digest = pickBestV3DigestForV4(contentDigests);

        return result;
    }

    // Keep in sync with pickBestV3DigestForV4 in apksigner.V3SchemeVerifier.
    private static byte[] pickBestV3DigestForV4(Map<Integer, byte[]> contentDigests) {
        final int[] orderedContentDigestTypes =
                {CONTENT_DIGEST_CHUNKED_SHA512, CONTENT_DIGEST_VERITY_CHUNKED_SHA256,
                        CONTENT_DIGEST_CHUNKED_SHA256};
        for (int contentDigestType : orderedContentDigestTypes) {
            if (contentDigests.containsKey(contentDigestType)) {
                return contentDigests.get(contentDigestType);
            }
        }
        return null;
    }

    private static VerifiedSigner verifySigner(
            ByteBuffer signerBlock,
            Map<Integer, byte[]> contentDigests,