[sign_virt_apex] Update vbmeta related bootconfigs
Signing microdroid super images will change vbmeta digest & size, these
are embedded in ramdisk & hence need to be changed too. For this we
detach the bootconfigs from ramdisk, update them & re-attach them.
Other then that, this patch also removes signing of legacy images like
bootloader.
Test: atest
MicrodroidHostTests#testBootSucceedsWhenNonProtectedVmStartsWithImagesSignedWithDifferentKey
Bug: 245277660
Change-Id: Ia1d2ab0a7c76c7ee7435e55bab9a1c9d4f29f202
diff --git a/tests/hostside/Android.bp b/tests/hostside/Android.bp
index 7679c57..6e0cf5a 100644
--- a/tests/hostside/Android.bp
+++ b/tests/hostside/Android.bp
@@ -29,6 +29,7 @@
// For re-sign test
"avbtool",
"img2simg",
+ "initrd_bootconfig",
"lpmake",
"lpunpack",
"mk_payload",
diff --git a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
index 2ee33e6..4186ebb 100644
--- a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
+++ b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
@@ -55,7 +55,6 @@
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
@@ -170,7 +169,11 @@
.isSuccess();
}
- private void resignVirtApex(File virtApexDir, File signingKey, Map<String, File> keyOverrides) {
+ private void resignVirtApex(
+ File virtApexDir,
+ File signingKey,
+ Map<String, File> keyOverrides,
+ boolean updateBootconfigs) {
File signVirtApex = findTestFile("sign_virt_apex");
RunUtil runUtil = new RunUtil();
@@ -181,6 +184,9 @@
List<String> command = new ArrayList<>();
command.add(signVirtApex.getAbsolutePath());
+ if (!updateBootconfigs) {
+ command.add("--do_not_update_bootconfigs");
+ }
keyOverrides.forEach(
(filename, keyFile) ->
command.add("--key_override " + filename + "=" + keyFile.getPath()));
@@ -268,7 +274,11 @@
}
private VmInfo runMicrodroidWithResignedImages(
- File key, Map<String, File> keyOverrides, boolean isProtected) throws Exception {
+ File key,
+ Map<String, File> keyOverrides,
+ boolean isProtected,
+ boolean updateBootconfigs)
+ throws Exception {
CommandRunner android = new CommandRunner(getDevice());
File virtApexDir = FileUtil.createTempDir("virt_apex");
@@ -281,7 +291,7 @@
assertWithMessage("Failed to pull " + VIRT_APEX + "etc")
.that(getDevice().pullDir(VIRT_APEX + "etc", virtApexEtcDir)).isTrue();
- resignVirtApex(virtApexDir, key, keyOverrides);
+ resignVirtApex(virtApexDir, key, keyOverrides, updateBootconfigs);
// Push back re-signed virt APEX contents and updated microdroid.json
getDevice().pushDir(virtApexDir, TEST_ROOT);
@@ -450,7 +460,8 @@
// Act
VmInfo vmInfo =
- runMicrodroidWithResignedImages(key, /*keyOverrides=*/ Map.of(), protectedVm);
+ runMicrodroidWithResignedImages(
+ key, /*keyOverrides=*/ Map.of(), protectedVm, /*updateBootconfigs=*/ true);
// Assert
vmInfo.mProcess.waitFor(5L, TimeUnit.SECONDS);
@@ -461,16 +472,15 @@
vmInfo.mProcess.destroy();
}
- // TODO(b/245277660): Resigning the system/vendor image changes the vbmeta hash.
- // So, unless vbmeta related bootconfigs are updated the following test will fail
@Test
- @Ignore("b/245277660")
@CddTest(requirements = {"9.17/C-2-2", "9.17/C-2-6"})
public void testBootSucceedsWhenNonProtectedVmStartsWithImagesSignedWithDifferentKey()
throws Exception {
File key = findTestFile("test.com.android.virt.pem");
Map<String, File> keyOverrides = Map.of();
- VmInfo vmInfo = runMicrodroidWithResignedImages(key, keyOverrides, /*isProtected=*/ false);
+ VmInfo vmInfo =
+ runMicrodroidWithResignedImages(
+ key, keyOverrides, /*isProtected=*/ false, /*updateBootconfigs=*/ true);
// Device online means that boot must have succeeded.
adbConnectToMicrodroid(getDevice(), vmInfo.mCid);
vmInfo.mProcess.destroy();
@@ -481,10 +491,10 @@
public void testBootFailsWhenVbMetaDigestDoesNotMatchBootconfig() throws Exception {
// Sign everything with key1 except vbmeta
File key = findTestFile("test.com.android.virt.pem");
- File key2 = findTestFile("test2.com.android.virt.pem");
- Map<String, File> keyOverrides = Map.of("microdroid_vbmeta.img", key2);
// To be able to stop it, it should be a daemon.
- VmInfo vmInfo = runMicrodroidWithResignedImages(key, keyOverrides, /*isProtected=*/ false);
+ VmInfo vmInfo =
+ runMicrodroidWithResignedImages(
+ key, Map.of(), /*isProtected=*/ false, /*updateBootconfigs=*/ false);
// Wait so that init can print errors to console (time in cuttlefish >> in real device)
assertThatEventually(
100000,