[sign] Approval: a deploy approval may expire up to 25 hours ahead (was an hour), so a release's day-long card can still be signed; v0.17.1

This commit is contained in:
2026-11-14 16:51:47 +01:00
parent ff14c8902f
commit f84ac575bd
7 changed files with 34 additions and 24 deletions
+7 -5
View File
@@ -430,8 +430,9 @@ pub fn sha256_hex(bytes: &[u8]) -> String {
/// The largest approval text Custos reads (docs/SIGNING.md).
pub const MAX_APPROVAL: usize = 8 * 1024;
/// An approval expires at most this many seconds after it is checked.
pub const APPROVAL_MAX_AHEAD: u64 = 3600;
/// An approval expires at most this many seconds after it is checked: 25 hours (a release's approval lives a day,
/// and its card may wait for Mark that long; an hour before core 0.17.1).
pub const APPROVAL_MAX_AHEAD: u64 = 25 * 3600;
/// A deploy approval, read from its canonical JSON (docs/SIGNING.md, "approval"). Nothing in it is secret.
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
@@ -520,15 +521,16 @@ fn unprintable(c: char) -> bool {
}
/// Checks that `text` is a deploy approval in canonical form that has not expired at `now_secs` and expires at most
/// an hour later (docs/SIGNING.md). It is parsed, written again in canonical form and compared byte for byte, so
/// any other spelling of the same values (key order, spaces, escapes, a trailing newline) is refused.
/// 25 hours later ([`APPROVAL_MAX_AHEAD`], docs/SIGNING.md). It is parsed, written again in canonical form and
/// compared byte for byte, so any other spelling of the same values (key order, spaces, escapes, a trailing newline)
/// is refused.
pub fn approval_check(text: &str, now_secs: u64) -> Result<Approval, Error> {
let a = approval_parse(text)?;
if a.expires <= now_secs {
return Err(Error::Approval("it has expired"));
}
if a.expires > now_secs.saturating_add(APPROVAL_MAX_AHEAD) {
return Err(Error::Approval("it expires more than an hour from now"));
return Err(Error::Approval("it expires more than 25 hours from now"));
}
Ok(a)
}
+6 -2
View File
@@ -142,11 +142,15 @@ fn targets_have_limits() {
}
#[test]
fn the_expiry_is_after_now_and_within_an_hour() {
fn the_expiry_is_after_now_and_within_25_hours() {
let at = |exp: u64| with(&format!("\"expires\":{}", NOW + 600), &format!("\"expires\":{exp}"));
assert!(approval_check(&at(NOW + 1), NOW).is_ok());
assert!(approval_check(&at(NOW + 3600), NOW).is_ok());
for exp in [NOW, NOW - 1, 0, NOW + 3601, u64::MAX] {
// A release's approval lives a day, and its card may wait for Mark that long (core 0.17.1).
assert_eq!(APPROVAL_MAX_AHEAD, 25 * 3600);
assert!(approval_check(&at(NOW + 24 * 3600), NOW).is_ok());
assert!(approval_check(&at(NOW + 25 * 3600), NOW).is_ok());
for exp in [NOW, NOW - 1, 0, NOW + 25 * 3600 + 1, u64::MAX] {
let e = refused(&at(exp), NOW);
assert!(e.contains("expire"), "{exp}: {e}");
}
+1 -1
View File
@@ -700,7 +700,7 @@ impl Vault {
}
/// [`Vault::signing_check`] at `now` (Unix milliseconds): an approval must not have expired then, and must
/// expire at most an hour later.
/// expire at most 25 hours later (`custos_sign::APPROVAL_MAX_AHEAD`).
pub fn signing_check_at(&self, req: &Request, now: i64) -> Result<KeyView, Refusal> {
self.check(req, now).map(|(view, _)| view)
}
+5 -1
View File
@@ -322,8 +322,12 @@ fn an_approval_needs_its_run_a_canonical_unexpired_text_and_a_matching_context()
spaced.approval = Some(spaced.approval.unwrap().replace(',', ", "));
invalid(&mut v, &spaced);
let mut late = approval_req("r-42");
late.approval = Some(approval_text("r-42", "Arca", 3601));
late.approval = Some(approval_text("r-42", "Arca", 25 * 3600 + 1));
invalid(&mut v, &late);
// A day ahead is fine (core 0.17.1): a release's approval lives that long.
let mut day = approval_req("r-42");
day.approval = Some(approval_text("r-42", "Arca", 24 * 3600));
assert!(v.signing_check_at(&day, NOW).is_ok());
let mut past = approval_req("r-42");
past.approval = Some(approval_text("r-42", "Arca", 0));
invalid(&mut v, &past);