Skip to content

Commit 837dc44

Browse files
committed
Adjust all code to use ComposefsRepository alias
This ensures we're SHA-512 across the board. Signed-off-by: Colin Walters <[email protected]>
1 parent ebdddb5 commit 837dc44

File tree

5 files changed

+41
-46
lines changed

5 files changed

+41
-46
lines changed

crates/initramfs/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustix::{
2222
use serde::Deserialize;
2323

2424
use composefs::{
25-
fsverity::{FsVerityHashValue, Sha256HashValue},
25+
fsverity::{FsVerityHashValue, Sha512HashValue},
2626
mount::FsHandle,
2727
mountcompat::{overlayfs_set_fd, overlayfs_set_lower_and_data_fds, prepare_mount},
2828
repository::Repository,
@@ -207,7 +207,7 @@ fn open_root_fs(path: &Path) -> Result<OwnedFd> {
207207
/// * insecure - Whether fsverity is optional or not
208208
#[context("Mounting composefs image")]
209209
pub fn mount_composefs_image(sysroot: &OwnedFd, name: &str, insecure: bool) -> Result<OwnedFd> {
210-
let mut repo = Repository::<Sha256HashValue>::open_path(sysroot, "composefs")?;
210+
let mut repo = Repository::<Sha512HashValue>::open_path(sysroot, "composefs")?;
211211
repo.set_insecure(insecure);
212212
repo.mount(name).context("Failed to mount composefs image")
213213
}
@@ -282,7 +282,7 @@ pub fn setup_root(args: Args) -> Result<()> {
282282
// TODO: Deduplicate this with composefs branch karg parser
283283
None => &std::fs::read_to_string("/proc/cmdline")?,
284284
};
285-
let (image, insecure) = get_cmdline_composefs::<Sha256HashValue>(cmdline)?;
285+
let (image, insecure) = get_cmdline_composefs::<Sha512HashValue>(cmdline)?;
286286

287287
let new_root = match args.root_fs {
288288
Some(path) => open_root_fs(&path).context("Failed to clone specified root fs")?,

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ use cap_std_ext::{
1414
};
1515
use clap::ValueEnum;
1616
use composefs::fs::read_file;
17-
use composefs::tree::{FileSystem, RegularFile};
17+
use composefs::tree::RegularFile;
1818
use composefs_boot::bootloader::{PEType, EFI_ADDON_DIR_EXT, EFI_ADDON_FILE_EXT, EFI_EXT};
1919
use composefs_boot::BootOps;
2020
use fn_error_context::context;
21-
use ostree_ext::composefs::{
22-
fsverity::{FsVerityHashValue, Sha256HashValue},
23-
repository::Repository as ComposefsRepository,
24-
};
21+
use ostree_ext::composefs::fsverity::{FsVerityHashValue, Sha512HashValue};
2522
use ostree_ext::composefs_boot::bootloader::UsrLibModulesVmlinuz;
2623
use ostree_ext::composefs_boot::{
2724
bootloader::BootEntry as ComposefsBootEntry, cmdline::get_cmdline_composefs,
@@ -32,14 +29,14 @@ use rustix::path::Arg;
3229
use schemars::JsonSchema;
3330
use serde::{Deserialize, Serialize};
3431

35-
use crate::bootc_composefs::repo::open_composefs_repo;
3632
use crate::bootc_composefs::state::{get_booted_bls, write_composefs_state};
3733
use crate::bootc_composefs::status::get_sorted_uki_boot_entries;
3834
use crate::composefs_consts::{TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED};
3935
use crate::parsers::bls_config::{BLSConfig, BLSConfigType};
4036
use crate::parsers::grub_menuconfig::MenuEntry;
4137
use crate::spec::ImageReference;
4238
use crate::task::Task;
39+
use crate::{bootc_composefs::repo::open_composefs_repo, store::ComposefsFilesystem};
4340
use crate::{
4441
composefs_consts::{
4542
BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_DIGEST,
@@ -68,9 +65,9 @@ const SYSTEMD_UKI_DIR: &str = "EFI/Linux/bootc";
6865

6966
pub(crate) enum BootSetupType<'a> {
7067
/// For initial setup, i.e. install to-disk
71-
Setup((&'a RootSetup, &'a State, &'a FileSystem<Sha256HashValue>)),
68+
Setup((&'a RootSetup, &'a State, &'a ComposefsFilesystem)),
7269
/// For `bootc upgrade`
73-
Upgrade((&'a FileSystem<Sha256HashValue>, &'a Host)),
70+
Upgrade((&'a ComposefsFilesystem, &'a Host)),
7471
}
7572

7673
#[derive(
@@ -107,8 +104,8 @@ impl TryFrom<&str> for BootType {
107104
}
108105
}
109106

110-
impl From<&ComposefsBootEntry<Sha256HashValue>> for BootType {
111-
fn from(entry: &ComposefsBootEntry<Sha256HashValue>) -> Self {
107+
impl From<&ComposefsBootEntry<Sha512HashValue>> for BootType {
108+
fn from(entry: &ComposefsBootEntry<Sha512HashValue>) -> Self {
112109
match entry {
113110
ComposefsBootEntry::Type1(..) => Self::Bls,
114111
ComposefsBootEntry::Type2(..) => Self::Uki,
@@ -181,8 +178,8 @@ pub fn type1_entry_conf_file_name(sort_key: impl std::fmt::Display) -> String {
181178
/// * repo - The composefs repository
182179
#[context("Computing boot digest")]
183180
fn compute_boot_digest(
184-
entry: &UsrLibModulesVmlinuz<Sha256HashValue>,
185-
repo: &ComposefsRepository<Sha256HashValue>,
181+
entry: &UsrLibModulesVmlinuz<Sha512HashValue>,
182+
repo: &crate::store::ComposefsRepository,
186183
) -> Result<String> {
187184
let vmlinuz = read_file(&entry.vmlinuz, &repo).context("Reading vmlinuz")?;
188185

@@ -255,9 +252,9 @@ fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<String>> {
255252
#[context("Writing BLS entries to disk")]
256253
fn write_bls_boot_entries_to_disk(
257254
boot_dir: &Utf8PathBuf,
258-
deployment_id: &Sha256HashValue,
259-
entry: &UsrLibModulesVmlinuz<Sha256HashValue>,
260-
repo: &ComposefsRepository<Sha256HashValue>,
255+
deployment_id: &Sha512HashValue,
256+
entry: &UsrLibModulesVmlinuz<Sha512HashValue>,
257+
repo: &crate::store::ComposefsRepository,
261258
) -> Result<()> {
262259
let id_hex = deployment_id.to_hex();
263260

@@ -300,8 +297,8 @@ fn write_bls_boot_entries_to_disk(
300297
/// # Returns
301298
/// - (title, version)
302299
fn osrel_title_and_version(
303-
fs: &FileSystem<Sha256HashValue>,
304-
repo: &ComposefsRepository<Sha256HashValue>,
300+
fs: &crate::store::ComposefsFilesystem,
301+
repo: &crate::store::ComposefsRepository,
305302
) -> Result<Option<(Option<String>, Option<String>)>> {
306303
// Every update should have its own /usr/lib/os-release
307304
let (dir, fname) = fs
@@ -359,9 +356,9 @@ struct BLSEntryPath<'a> {
359356
pub(crate) fn setup_composefs_bls_boot(
360357
setup_type: BootSetupType,
361358
// TODO: Make this generic
362-
repo: ComposefsRepository<Sha256HashValue>,
363-
id: &Sha256HashValue,
364-
entry: &ComposefsBootEntry<Sha256HashValue>,
359+
repo: crate::store::ComposefsRepository,
360+
id: &Sha512HashValue,
361+
entry: &ComposefsBootEntry<Sha512HashValue>,
365362
) -> Result<String> {
366363
let id_hex = id.to_hex();
367364

@@ -569,8 +566,8 @@ pub(crate) fn setup_composefs_bls_boot(
569566
/// Writes a PortableExecutable to ESP along with any PE specific or Global addons
570567
#[context("Writing {file_path} to ESP")]
571568
fn write_pe_to_esp(
572-
repo: &ComposefsRepository<Sha256HashValue>,
573-
file: &RegularFile<Sha256HashValue>,
569+
repo: &crate::store::ComposefsRepository,
570+
file: &RegularFile<Sha512HashValue>,
574571
file_path: &Utf8Path,
575572
pe_type: PEType,
576573
uki_id: &String,
@@ -588,7 +585,7 @@ fn write_pe_to_esp(
588585
let cmdline = uki::get_cmdline(&efi_bin).context("Getting UKI cmdline")?;
589586

590587
let (composefs_cmdline, insecure) =
591-
get_cmdline_composefs::<Sha256HashValue>(cmdline).context("Parsing composefs=")?;
588+
get_cmdline_composefs::<Sha512HashValue>(cmdline).context("Parsing composefs=")?;
592589

593590
// If the UKI cmdline does not match what the user has passed as cmdline option
594591
// NOTE: This will only be checked for new installs and now upgrades/switches
@@ -676,7 +673,7 @@ fn write_grub_uki_menuentry(
676673
root_path: Utf8PathBuf,
677674
setup_type: &BootSetupType,
678675
boot_label: String,
679-
id: &Sha256HashValue,
676+
id: &Sha512HashValue,
680677
esp_device: &String,
681678
) -> Result<()> {
682679
let boot_dir = root_path.join("boot");
@@ -764,7 +761,7 @@ fn write_systemd_uki_config(
764761
esp_dir: &Dir,
765762
setup_type: &BootSetupType,
766763
boot_label: String,
767-
id: &Sha256HashValue,
764+
id: &Sha512HashValue,
768765
) -> Result<()> {
769766
let default_sort_key = "0";
770767

@@ -833,9 +830,9 @@ fn write_systemd_uki_config(
833830
pub(crate) fn setup_composefs_uki_boot(
834831
setup_type: BootSetupType,
835832
// TODO: Make this generic
836-
repo: ComposefsRepository<Sha256HashValue>,
837-
id: &Sha256HashValue,
838-
entries: Vec<ComposefsBootEntry<Sha256HashValue>>,
833+
repo: crate::store::ComposefsRepository,
834+
id: &Sha512HashValue,
835+
entries: Vec<ComposefsBootEntry<Sha512HashValue>>,
839836
) -> Result<()> {
840837
let (root_path, esp_device, bootloader, is_insecure_from_opts, uki_addons) = match setup_type {
841838
BootSetupType::Setup((root_setup, state, ..)) => {

crates/lib/src/bootc_composefs/repo.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use std::sync::Arc;
44
use anyhow::{Context, Result};
55

66
use ostree_ext::composefs::{
7-
fsverity::{FsVerityHashValue, Sha256HashValue},
8-
repository::Repository as ComposefsRepository,
9-
tree::FileSystem,
7+
fsverity::{FsVerityHashValue, Sha512HashValue},
108
util::Sha256Digest,
119
};
1210
use ostree_ext::composefs_boot::{bootloader::BootEntry as ComposefsBootEntry, BootOps};
@@ -20,10 +18,8 @@ use cap_std_ext::cap_std::{ambient_authority, fs::Dir};
2018

2119
use crate::install::{RootSetup, State};
2220

23-
pub(crate) fn open_composefs_repo(
24-
rootfs_dir: &Dir,
25-
) -> Result<ComposefsRepository<Sha256HashValue>> {
26-
ComposefsRepository::open_path(rootfs_dir, "composefs")
21+
pub(crate) fn open_composefs_repo(rootfs_dir: &Dir) -> Result<crate::store::ComposefsRepository> {
22+
crate::store::ComposefsRepository::open_path(rootfs_dir, "composefs")
2723
.context("Failed to open composefs repository")
2824
}
2925

@@ -78,10 +74,10 @@ pub(crate) async fn pull_composefs_repo(
7874
transport: &String,
7975
image: &String,
8076
) -> Result<(
81-
ComposefsRepository<Sha256HashValue>,
82-
Vec<ComposefsBootEntry<Sha256HashValue>>,
83-
Sha256HashValue,
84-
FileSystem<Sha256HashValue>,
77+
crate::store::ComposefsRepository,
78+
Vec<ComposefsBootEntry<Sha512HashValue>>,
79+
Sha512HashValue,
80+
crate::store::ComposefsFilesystem,
8581
)> {
8682
let rootfs_dir = Dir::open_ambient_dir("/sysroot", ambient_authority())?;
8783

@@ -98,8 +94,9 @@ pub(crate) async fn pull_composefs_repo(
9894
tracing::info!("id: {}, verity: {}", hex::encode(id), verity.to_hex());
9995

10096
let repo = open_composefs_repo(&rootfs_dir)?;
101-
let mut fs = create_composefs_filesystem(&repo, &hex::encode(id), None)
102-
.context("Failed to create composefs filesystem")?;
97+
let mut fs: crate::store::ComposefsFilesystem =
98+
create_composefs_filesystem(&repo, &hex::encode(id), None)
99+
.context("Failed to create composefs filesystem")?;
103100

104101
let entries = fs.transform_for_boot(&repo)?;
105102
let id = fs.commit_image(&repo, None)?;

crates/lib/src/bootc_composefs/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use camino::Utf8PathBuf;
1010
use cap_std_ext::cap_std::ambient_authority;
1111
use cap_std_ext::cap_std::fs::Dir;
1212
use cap_std_ext::dirext::CapStdExtDirExt;
13-
use composefs::fsverity::{FsVerityHashValue, Sha256HashValue};
13+
use composefs::fsverity::{FsVerityHashValue, Sha512HashValue};
1414
use fn_error_context::context;
1515

1616
use ostree_ext::container::deploy::ORIGIN_CONTAINER;
@@ -107,7 +107,7 @@ pub(crate) fn copy_etc_to_state(
107107
#[context("Writing composefs state")]
108108
pub(crate) fn write_composefs_state(
109109
root_path: &Utf8PathBuf,
110-
deployment_id: Sha256HashValue,
110+
deployment_id: Sha512HashValue,
111111
imgref: &ImageReference,
112112
staged: bool,
113113
boot_type: BootType,

crates/lib/src/store/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::utils::deployment_fd;
3737
/// See https://github.com/containers/composefs-rs/issues/159
3838
pub type ComposefsRepository =
3939
composefs::repository::Repository<composefs::fsverity::Sha512HashValue>;
40+
pub type ComposefsFilesystem = composefs::tree::FileSystem<composefs::fsverity::Sha512HashValue>;
4041

4142
/// Path to the physical root
4243
pub const SYSROOT: &str = "sysroot";

0 commit comments

Comments
 (0)