Wire preserved update control, health evidence and record publication
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -5,9 +5,9 @@ use rmm_domain::jobs::hash;
|
||||
use rmm_updater_handoff::{FileRole, Handoff};
|
||||
use rmm_updater_linux::{
|
||||
Budget,
|
||||
files::{Directory, FileProof, Role, Staged},
|
||||
files::{BoundStage, Directory, FileProof, Role, Staged},
|
||||
};
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{ffi::OsStr, path::Path};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -29,12 +29,20 @@ fn role(role: FileRole) -> Result<Role> {
|
||||
_ => anyhow::bail!("UPDATE_LINUX_FILE_ROLE"),
|
||||
}
|
||||
}
|
||||
#[derive(Serialize)]
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Proof {
|
||||
role: Role,
|
||||
original: FileProof,
|
||||
staged: FileProof,
|
||||
}
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Record {
|
||||
schema_version: u32,
|
||||
owner_nonce: Uuid,
|
||||
files: Vec<Proof>,
|
||||
}
|
||||
pub struct FileWitnesses {
|
||||
files: Vec<Proof>,
|
||||
nonce: Uuid,
|
||||
@@ -63,6 +71,7 @@ impl FileWitnesses {
|
||||
)?;
|
||||
ensure!(
|
||||
stage.proof().identity.links == 1
|
||||
&& stage.proof().identity.device == original.proof().identity.device
|
||||
&& stage.proof().identity.uid == original.proof().identity.uid
|
||||
&& stage.proof().identity.gid == original.proof().identity.gid
|
||||
&& stage.proof().identity.mode == original.proof().identity.mode,
|
||||
@@ -74,7 +83,11 @@ impl FileWitnesses {
|
||||
staged: stage.proof().clone(),
|
||||
});
|
||||
}
|
||||
let digest = hash(&serde_json::to_vec(&files)?);
|
||||
let digest = hash(&serde_json::to_vec(&Record {
|
||||
schema_version: 1,
|
||||
owner_nonce: nonce,
|
||||
files: files.clone(),
|
||||
})?);
|
||||
Ok(Self {
|
||||
files,
|
||||
nonce,
|
||||
@@ -84,6 +97,65 @@ impl FileWitnesses {
|
||||
pub fn sha256(&self) -> &str {
|
||||
&self.sha256
|
||||
}
|
||||
pub fn bytes(&self) -> Result<Vec<u8>> {
|
||||
let bytes = serde_json::to_vec(&Record {
|
||||
schema_version: 1,
|
||||
owner_nonce: self.nonce,
|
||||
files: self.files.clone(),
|
||||
})?;
|
||||
ensure!(
|
||||
bytes.len() <= 65536 && hash(&bytes) == self.sha256,
|
||||
"UPDATE_FILE_WITNESS_CHANGED"
|
||||
);
|
||||
Ok(bytes)
|
||||
}
|
||||
/// Protected bundle bytes remain observations only. Actual phase-specific
|
||||
/// path/FD/hash verification is separate and mandatory before any effect.
|
||||
pub fn from_bound_bytes(raw: &[u8], handoff: &Handoff) -> Result<Self> {
|
||||
ensure!(
|
||||
!raw.is_empty() && raw.len() <= 65536 && hash(raw) == handoff.staged_files_sha256,
|
||||
"UPDATE_FILE_WITNESS_HASH"
|
||||
);
|
||||
let record: Record = serde_json::from_slice(raw)?;
|
||||
ensure!(
|
||||
record.schema_version == 1
|
||||
&& record.owner_nonce == handoff.owner_nonce
|
||||
&& record.files.len() == 4
|
||||
&& serde_json::to_vec(&record)? == raw,
|
||||
"UPDATE_FILE_WITNESS_CODEC"
|
||||
);
|
||||
for (role, file) in ROLES.iter().zip(&record.files) {
|
||||
ensure!(*role == file.role, "UPDATE_FILE_WITNESS_ROLE_ORDER");
|
||||
for proof in [&file.original, &file.staged] {
|
||||
ensure!(
|
||||
proof.identity.inode > 0
|
||||
&& proof.identity.uid == 0
|
||||
&& proof.identity.links > 0
|
||||
&& proof.identity.mode & libc::S_IFMT == libc::S_IFREG
|
||||
&& proof.identity.mode & 0o022 == 0
|
||||
&& proof.bytes > 0
|
||||
&& proof.bytes <= 256 * 1024 * 1024
|
||||
&& rmm_domain::agent_update::digest(&proof.sha256),
|
||||
"UPDATE_FILE_WITNESS_SHAPE"
|
||||
);
|
||||
}
|
||||
ensure!(
|
||||
file.staged.identity.links == 1
|
||||
&& file.staged.identity.device == file.original.identity.device
|
||||
&& file.original.identity.uid == file.staged.identity.uid
|
||||
&& file.original.identity.gid == file.staged.identity.gid
|
||||
&& file.original.identity.mode == file.staged.identity.mode,
|
||||
"UPDATE_FILE_WITNESS_METADATA"
|
||||
);
|
||||
}
|
||||
let result = Self {
|
||||
files: record.files,
|
||||
nonce: record.owner_nonce,
|
||||
sha256: hash(raw),
|
||||
};
|
||||
result.bind(handoff)?;
|
||||
Ok(result)
|
||||
}
|
||||
pub fn bind(&self, handoff: &Handoff) -> Result<()> {
|
||||
ensure!(
|
||||
handoff.files.len() == 4
|
||||
@@ -101,6 +173,30 @@ impl FileWitnesses {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// Reopen only the exact preconsumption protected stages. This is not a
|
||||
/// dispatch or restart path: the live original owner and each Core claim
|
||||
/// remain independently mandatory before Stop/Swap/Start.
|
||||
pub fn reopen_stages(&self, handoff: &Handoff, budget: &Budget) -> Result<[Staged; 4]> {
|
||||
self.bind(handoff)?;
|
||||
let mut opened = Vec::new();
|
||||
for proof in &self.files {
|
||||
let path = Path::new(proof.role.target());
|
||||
let dir = Directory::open(path.parent().context("UPDATE_TARGET_PARENT")?, 0, false)?;
|
||||
opened.push(Staged::reopen_bound(
|
||||
&dir,
|
||||
BoundStage {
|
||||
role: proof.role,
|
||||
nonce: self.nonce,
|
||||
original: &proof.original,
|
||||
staged: &proof.staged,
|
||||
},
|
||||
budget,
|
||||
)?);
|
||||
}
|
||||
opened
|
||||
.try_into()
|
||||
.map_err(|_| anyhow::anyhow!("UPDATE_STAGE_COUNT"))
|
||||
}
|
||||
pub fn verify_original_and_stage(&self, which: FileRole, budget: &Budget) -> Result<()> {
|
||||
let file = self.file(which)?;
|
||||
budget.check()?;
|
||||
|
||||
Reference in New Issue
Block a user