xtask: Switch from shim to crdyshim After building crdyshim, sign it and copy to the test disk in the same way as the crdyboot executable. On the test disk it will be named `boot<arch>.efi`, overwriting the shim executable. All the old shim code is still present for now, in case we need to revert. BUG=b:203705645 TEST=cargo xtask setup TEST=cargo xtask check Change-Id: Ic383a8d695c5eb7b7afe4b00321301df16fed89f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crdyboot/+/4679321 Reviewed-by: Ted Brandston <tbrandston@google.com> Commit-Queue: Nicholas Bishop <nicholasbishop@google.com> Tested-by: Nicholas Bishop <nicholasbishop@google.com>
diff --git a/xtask/src/gen_disk.rs b/xtask/src/gen_disk.rs index 1eda12a..ac1a31a 100644 --- a/xtask/src/gen_disk.rs +++ b/xtask/src/gen_disk.rs
@@ -387,8 +387,24 @@ }) } -/// Sign crdyboot, then copy it into the disk image. -pub fn copy_in_crdyboot(conf: &Config) -> Result<()> { +/// Sign the bootloaders (both crdyshim and crdyboot) and copy them into +/// the disk image. +pub fn sign_and_copy_bootloaders(conf: &Config) -> Result<()> { + SignAndUpdateBootloader { + disk_path: conf.disk_path(), + key_paths: conf.secure_boot_root_key_paths(), + mapping: Arch::all() + .iter() + .map(|arch| { + ( + conf.target_exec_path(*arch, EfiExe::Crdyshim), + arch.efi_file_name("boot"), + ) + }) + .collect(), + } + .run()?; + SignAndUpdateBootloader { disk_path: conf.disk_path(), key_paths: conf.secure_boot_shim_key_paths(),
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7ccf1f5..cc9b321 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs
@@ -261,8 +261,8 @@ // Check various properties of the bootloader binaries. bin_checks::run_bin_checks(conf)?; - // Update the disk image with the new executable. - gen_disk::copy_in_crdyboot(conf)?; + // Update the disk image with the new executables. + gen_disk::sign_and_copy_bootloaders(conf)?; // Add or remove the `crdyboot_verbose` file. gen_disk::update_verbose_boot_file(conf, verbose)
diff --git a/xtask/src/vm_test.rs b/xtask/src/vm_test.rs index f16ade4..bccd7bd 100644 --- a/xtask/src/vm_test.rs +++ b/xtask/src/vm_test.rs
@@ -14,7 +14,7 @@ use command_run::Command; use fs_err as fs; use std::fs::Permissions; -use std::io::{BufRead, BufReader, Read}; +use std::io::{BufRead, BufReader}; use std::os::unix::fs::PermissionsExt; use std::thread; use std::time::{Duration, Instant}; @@ -180,32 +180,6 @@ launch_test_disk_and_expect_errors(conf, expected_errors) } -/// Wrapper that prints `text` when dropped if `print` is true. This is -/// used for printing test output when a panic occurs. -struct PrintOutputOnDrop { - text: String, - print: bool, -} - -impl PrintOutputOnDrop { - fn new() -> Self { - Self { - text: String::new(), - print: true, - } - } -} - -impl Drop for PrintOutputOnDrop { - fn drop(&mut self) { - if self.print { - println!("start output ---"); - println!("{}", self.text); - println!("--- end output"); - } - } -} - /// This test modifies a byte in the `.vbpubk` section of the /// bootloader, then verifies that shim refuses to launch crdyboot due /// to the executable's signature no longer being valid. @@ -220,40 +194,8 @@ corrupt_pubkey_section(conf, &conf.test_disk_path(), SignAfterCorrupt(false))?; - let opts = QemuOpts { - capture_output: true, - display: Display::None, - image_path: conf.test_disk_path(), - ovmf: conf.ovmf_paths(Arch::X64), - secure_boot: true, - snapshot: true, - timeout: Some(VM_ERROR_TIMEOUT), - tpm_version: None, - }; - let vm = opts.spawn_disk_image(conf)?; - let mut stdout = vm.qemu.lock().unwrap().stdout.take().unwrap(); - let mut output = PrintOutputOnDrop::new(); - loop { - // Read one byte at a time since there's no newline character - // after the message we are looking for. - let mut byte = [0]; - if stdout.read(&mut byte)? == 0 { - // EOF reached. - bail!("QEMU no longer running"); - } - output.text.push(char::try_from(byte[0]).unwrap()); - - if output - .text - .contains("Verification failed: (0x1A) Security Violation") - { - // The expected failure occurred, test is successful. Kill - // the VM. - output.print = false; - vm.qemu.lock().unwrap().kill().unwrap(); - return Ok(()); - } - } + let expected_errors = &["boot failed: signature verification failed"]; + launch_test_disk_and_expect_errors(conf, expected_errors) } /// This test modifies a byte in the `.vbpubk` section of crdyboot and