jobs/runner/src/key.rs
//! **The per-boot result key**: Heimdall's [`BootKey`], made when a runner starts from
//! the operating system's randomness, held in the runner's own memory (outside every
//! job) and never written anywhere. The caller pins its public half at boot; a result
//! signed before a restart, or by anything else, does not verify.
use heimdall_core::{BootId, BootKey, JobResult, RunError, SignedResult, VerifyingKey};
/// A runner's per-boot signing key.
#[derive(Debug)]
pub struct ResultKey {
key: BootKey,
}
impl ResultKey {
/// A fresh key from the operating system's randomness.
pub fn per_boot() -> Self {
Self {
key: BootKey::generate(),
}
}
/// The key from fixed bytes: tests only.
#[doc(hidden)]
pub fn from_seed(seed: [u8; 32]) -> Self {
Self {
key: BootKey::from_seed(seed, BootId([seed[0]; 16])),
}
}
pub fn verifying_key(&self) -> VerifyingKey {
self.key.verifying_key()
}
/// Sign `result` (Heimdall's canonical wire v2, `heimdall.signed-result.v2`).
pub fn sign(&self, result: JobResult) -> Result<SignedResult, RunError> {
self.key.sign(result).map_err(RunError::Sign)
}
}
/// The id a pinned key goes by: `ed25519:` and Heimdall's key id in hex.
pub fn key_words(key: &VerifyingKey) -> String {
format!(
"ed25519:{}",
heimdall_core::key_id_of(key.as_bytes()).to_hex()
)
}