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

Commit bf0cb9af authored by Alex Buynytskyy's avatar Alex Buynytskyy Committed by Android (Google) Code Review
Browse files

Merge "Verify incoming signature." into main

parents 567054d8 7250d76a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -110,6 +110,11 @@ public class ApkChecksums {

    private static final Certificate[] EMPTY_CERTIFICATE_ARRAY = {};

    /**
     * Arbitrary size restriction for the signature, used to sign the checksums.
     */
    private static final int MAX_SIGNATURE_SIZE_BYTES = 35 * 1024;

    /**
     * Check back in 1 second after we detected we needed to wait for the APK to be fully available.
     */
@@ -260,6 +265,10 @@ public class ApkChecksums {
     */
    public static @NonNull Certificate[] verifySignature(Checksum[] checksums, byte[] signature)
            throws NoSuchAlgorithmException, IOException, SignatureException {
        if (signature == null || signature.length > MAX_SIGNATURE_SIZE_BYTES) {
            throw new SignatureException("Invalid signature");
        }

        final byte[] blob;
        try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
            writeChecksums(os, checksums);
+1 −1
Original line number Diff line number Diff line
@@ -1612,7 +1612,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            try {
                Certificate[] ignored = ApkChecksums.verifySignature(checksums, signature);
            } catch (IOException | NoSuchAlgorithmException | SignatureException e) {
                throw new IllegalArgumentException("Can't verify signature", e);
                throw new IllegalArgumentException("Can't verify signature: " + e.getMessage(), e);
            }
        }