From 00001111031ca5206f06d5d0e4ad877f3ff595da Mon Sep 17 00:00:00 2001 From: Billy Lau Date: Tue, 10 Jan 2023 14:13:20 -0600 Subject: [PATCH] BinaryTransparencyService: Fix printPackageInstallationInfo It seems that APEX_PRELOAD_LOCATION_ERROR is consistently returned as the value of original APEX location when calling `getOriginalApexPreinstalledLocation` when preloaded APEXs are compressed. While this change does not address the root issue of why that is the case, it prevents the error value to be used as a legitimate path to compute digests for by guarding the control flow based on sane values of apex install location. Bug: 264925790 Test: Manual. adb shell cmd transparency get apex_info -v Change-Id: I924ba889cb6d11a874cf06ca8692f8320b86b588 --- .../server/BinaryTransparencyService.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/services/core/java/com/android/server/BinaryTransparencyService.java b/services/core/java/com/android/server/BinaryTransparencyService.java index 819c948fd0e31..68722d207ae3c 100644 --- a/services/core/java/com/android/server/BinaryTransparencyService.java +++ b/services/core/java/com/android/server/BinaryTransparencyService.java @@ -531,27 +531,30 @@ public class BinaryTransparencyService extends SystemService { pw.println("|--> Pre-installed package install location: " + origPackageFilepath); - if (useSha256) { - String sha256Digest = PackageUtils.computeSha256DigestForLargeFile( - origPackageFilepath, PackageUtils.createLargeFileBuffer()); - pw.println("|--> Pre-installed package SHA-256 digest: " - + sha256Digest); - } + if (!origPackageFilepath.equals(APEX_PRELOAD_LOCATION_ERROR)) { + if (useSha256) { + String sha256Digest = PackageUtils.computeSha256DigestForLargeFile( + origPackageFilepath, PackageUtils.createLargeFileBuffer()); + pw.println("|--> Pre-installed package SHA-256 digest: " + + sha256Digest); + } - - Map contentDigests = computeApkContentDigest( - origPackageFilepath); - if (contentDigests == null) { - pw.println("ERROR: Failed to compute package content digest for " - + origPackageFilepath); - } else { - for (Map.Entry entry : contentDigests.entrySet()) { - Integer algorithmId = entry.getKey(); - byte[] contentDigest = entry.getValue(); - pw.println("|--> Pre-installed package content digest: " - + HexEncoding.encodeToString(contentDigest, false)); - pw.println("|--> Pre-installed package content digest algorithm: " - + translateContentDigestAlgorithmIdToString(algorithmId)); + Map contentDigests = computeApkContentDigest( + origPackageFilepath); + if (contentDigests == null) { + pw.println("|--> ERROR: Failed to compute package content digest " + + "for " + origPackageFilepath); + } else { + for (Map.Entry entry : contentDigests.entrySet()) { + Integer algorithmId = entry.getKey(); + byte[] contentDigest = entry.getValue(); + pw.println("|--> Pre-installed package content digest: " + + HexEncoding.encodeToString(contentDigest, false)); + pw.println("|--> Pre-installed package content digest " + + "algorithm: " + + translateContentDigestAlgorithmIdToString( + algorithmId)); + } } } }