use openmoat_hosts::Host;
use super::super::Call;
use super::super::Target;
use super::super::hook::{self, Scratch};
use super::super::hosts::{self, Answer};
use super::status::Evidence;
pub const PROBE: &str = "hook-malformed-payload";
const MALFORMED: &str = "{\"hook_event_name\":\"PreToolUse\",\"tool_name\":";
pub const GUARD_CHECK: &str =
"`openmoat guard` answers a payload it cannot read with a deny the host reads as deny";
pub const HOST_CHECK: &str = "the host blocks the call when its hook crashes or times out";
pub fn guard(target: &Target, scratch: &Scratch, hosts: &[Host]) -> Vec<Evidence> {
let call = Call::Shell("true".to_owned());
hosts
.iter()
.map(|&host| {
let reply = hook::send(&mut target.command(scratch, host), MALFORMED);
match hosts::classify(host, &call, &reply) {
Answer::Deny => Evidence::Held,
other => Evidence::Broken(format!(
"{}: a payload the guard cannot read is read as {} ({})",
host.id(),
other.word(),
reply.cause()
)),
}
})
.collect()
}
pub fn hosts(hosts: &[Host]) -> Vec<Evidence> {
hosts
.iter()
.map(|&host| {
Evidence::Unexercised(format!(
"{}: needs the real host; THREAT_MODEL.md ยง5 says: {}",
host.id(),
hosts::failure(host)
))
})
.collect()
}