[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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user