BinaryTransparencyService: Translate content digest algo ID to string
Created a new helper method (`translateContentDigestAlgorithmIdToString`) that translates an int representing a content digest algorithm ID to a string that is more human readable, explaining what algorithm that is being used to compute the content digest. Bug: 259348134 Test: atest BinaryTransparencyServiceTest. Change-Id: I64853145fa7d46269a1533bd59398bc52ee958f5
This commit is contained in:
@@ -489,24 +489,10 @@ public class BinaryTransparencyService extends SystemService {
|
||||
Integer algorithmId = entry.getKey();
|
||||
byte[] contentDigest = entry.getValue();
|
||||
|
||||
// TODO(b/259348134): consider refactoring the following to a helper method
|
||||
switch (algorithmId) {
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA256:
|
||||
pw.print("CHUNKED_SHA256:");
|
||||
break;
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA512:
|
||||
pw.print("CHUNKED_SHA512:");
|
||||
break;
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_VERITY_CHUNKED_SHA256:
|
||||
pw.print("VERITY_CHUNKED_SHA256:");
|
||||
break;
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_SHA256:
|
||||
pw.print("SHA256:");
|
||||
break;
|
||||
default:
|
||||
pw.print("UNKNOWN_ALGO_ID(" + algorithmId + "):");
|
||||
}
|
||||
pw.print(translateContentDigestAlgorithmIdToString(algorithmId));
|
||||
pw.print(":");
|
||||
pw.print(HexEncoding.encodeToString(contentDigest, false));
|
||||
pw.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,31 +519,13 @@ public class BinaryTransparencyService extends SystemService {
|
||||
pw.println("ERROR: Failed to compute package content digest for "
|
||||
+ origPackageFilepath);
|
||||
} else {
|
||||
// TODO(b/259348134): consider refactoring this to a helper method
|
||||
for (Map.Entry<Integer, byte[]> entry : contentDigests.entrySet()) {
|
||||
Integer algorithmId = entry.getKey();
|
||||
byte[] contentDigest = entry.getValue();
|
||||
pw.print("|--> Pre-installed package content digest algorithm: ");
|
||||
switch (algorithmId) {
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA256:
|
||||
pw.print("CHUNKED_SHA256");
|
||||
break;
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA512:
|
||||
pw.print("CHUNKED_SHA512");
|
||||
break;
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_VERITY_CHUNKED_SHA256:
|
||||
pw.print("VERITY_CHUNKED_SHA256");
|
||||
break;
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_SHA256:
|
||||
pw.print("SHA256");
|
||||
break;
|
||||
default:
|
||||
pw.print("UNKNOWN");
|
||||
}
|
||||
pw.print("\n");
|
||||
pw.print("|--> Pre-installed package content digest: ");
|
||||
pw.print(HexEncoding.encodeToString(contentDigest, false));
|
||||
pw.print("\n");
|
||||
pw.println("|--> Pre-installed package content digest: "
|
||||
+ HexEncoding.encodeToString(contentDigest, false));
|
||||
pw.println("|--> Pre-installed package content digest algorithm: "
|
||||
+ translateContentDigestAlgorithmIdToString(algorithmId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -739,7 +707,6 @@ public class BinaryTransparencyService extends SystemService {
|
||||
pw.print(packageName + ","
|
||||
+ packageInfo.getLongVersionCode() + ",");
|
||||
printPackageMeasurements(packageInfo, pw);
|
||||
pw.print("\n");
|
||||
|
||||
if (verbose) {
|
||||
ModuleInfo moduleInfo;
|
||||
@@ -802,7 +769,6 @@ public class BinaryTransparencyService extends SystemService {
|
||||
pw.print(packageInfo.packageName + ",");
|
||||
pw.print(packageInfo.getLongVersionCode() + ",");
|
||||
printPackageMeasurements(packageInfo, pw);
|
||||
pw.print("\n");
|
||||
|
||||
if (verbose) {
|
||||
printModuleDetails(module, pw);
|
||||
@@ -858,7 +824,6 @@ public class BinaryTransparencyService extends SystemService {
|
||||
pw.print(packageInfo.packageName + ",");
|
||||
pw.print(packageInfo.getLongVersionCode() + ",");
|
||||
printPackageMeasurements(packageInfo, pw);
|
||||
pw.print("\n");
|
||||
|
||||
if (verbose) {
|
||||
printAppDetails(packageInfo, printLibraries, pw);
|
||||
@@ -1079,6 +1044,21 @@ public class BinaryTransparencyService extends SystemService {
|
||||
FrameworkStatsLog.write(FrameworkStatsLog.VBMETA_DIGEST_REPORTED, mVbmetaDigest);
|
||||
}
|
||||
|
||||
private String translateContentDigestAlgorithmIdToString(int algorithmId) {
|
||||
switch (algorithmId) {
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA256:
|
||||
return "CHUNKED_SHA256";
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA512:
|
||||
return "CHUNKED_SHA512";
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_VERITY_CHUNKED_SHA256:
|
||||
return "VERITY_CHUNKED_SHA256";
|
||||
case ApkSigningBlockUtils.CONTENT_DIGEST_SHA256:
|
||||
return "SHA256";
|
||||
default:
|
||||
return "UNKNOWN_ALGO_ID(" + algorithmId + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<PackageInfo> getCurrentInstalledApexs() {
|
||||
List<PackageInfo> results = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user