use super::launch;
use super::LinuxBackend;
use crate::contract::report::ObservedFact;
pub(super) fn attest_launcher(path: &std::path::Path, observed: &mut Vec<ObservedFact>) {
let Ok(bytes) = std::fs::read(path) else {
return;
};
let digest = batpak::event::hash::compute_hash(&bytes);
let hex: String = digest.iter().map(|b| format!("{b:02x}")).collect();
observed.push(ObservedFact {
kind: "launcher_identity".to_string(),
detail: format!(
"blake3={hex} observed_at_path={} (pre-spawn; not the exec'd-fd bytes — \
fd-exec pinning is the follow-on)",
path.display()
),
});
}
pub(super) fn resolve_launcher(backend: &LinuxBackend) -> Result<std::path::PathBuf, String> {
if let Some(path) = &backend.launcher_path {
if path.is_file() {
return Ok(path.clone());
}
return Err(format!(
"injected launcher path does not exist: {}",
path.display()
));
}
if let Ok(p) = std::env::var(launch::ENV_LAUNCHER_BIN) {
if !p.trim().is_empty() {
let path = std::path::PathBuf::from(p);
if path.is_file() {
return Ok(path);
}
return Err(format!(
"{} points to a non-existent launcher binary: {}",
launch::ENV_LAUNCHER_BIN,
path.display()
));
}
}
let exe = std::env::current_exe()
.map_err(|e| format!("cannot locate the current executable to find the launcher: {e}"))?;
let dir = exe
.parent()
.ok_or_else(|| "current executable has no parent directory".to_string())?;
let default = dir.join("bvisor-linux-launcher");
if default.is_file() {
return Ok(default);
}
Err(format!(
"no launcher binary: {} unset and no bvisor-linux-launcher beside {}",
launch::ENV_LAUNCHER_BIN,
exe.display()
))
}