Add a global option, --policy-as-of, to select a crypto policy.
- When working with older messages, it may be necessary to use a different cryptographic policy. Add an option, `--policy-as-of`, to select the cryptographic policy that was in effect at the specified time. - Fixes #123. Co-authored-by: Neal H. Walfield <neal@sequoia-pgp.org>
This commit is contained in:
parent
0889d18da7
commit
4f73627020
2
NEWS
2
NEWS
@ -8,6 +8,8 @@
|
||||
certificates.
|
||||
- `sq verify` now deletes the output file on failure.
|
||||
- `sq decrypt` now deletes the output file on failure.
|
||||
- Add a global option, `--policy-as-of`, that selects the
|
||||
cryptographic policy as of the specified time.
|
||||
|
||||
* Changes in 0.39.0
|
||||
** Notable changes
|
||||
|
@ -382,10 +382,11 @@ store, and the results are merged together."
|
||||
)]
|
||||
// TODO is this the right type?
|
||||
pub known_notation: Vec<String>,
|
||||
|
||||
#[clap(
|
||||
long = "time",
|
||||
value_name = "TIME",
|
||||
help = "Set the reference time as ISO 8601 formatted timestamp",
|
||||
help = "Set the reference time as an ISO 8601 formatted timestamp",
|
||||
global = true,
|
||||
help_heading = GLOBAL_OPTIONS_HEADER,
|
||||
long_help = "\
|
||||
@ -409,6 +410,34 @@ $ sq --time 20130721T0550+0200 verify msg.pgp
|
||||
",
|
||||
)]
|
||||
pub time: Option<types::Time>,
|
||||
#[clap(
|
||||
long = "policy-as-of",
|
||||
value_name = "TIME",
|
||||
help = "Select the cryptographic policy as of the specified time",
|
||||
global = true,
|
||||
help_heading = GLOBAL_OPTIONS_HEADER,
|
||||
long_help = "\
|
||||
Select the cryptographic policy as of the specified time, which is \
|
||||
expressed as an ISO 8601 formatted timestamp. The policy determines \
|
||||
what cryptographic constructs are allowed.
|
||||
|
||||
If you are working with a message that sq rejects, because it is \
|
||||
protected by cryptographic constructs that are now considered broken, \
|
||||
you can use this option to select a different cryptographic policy. \
|
||||
If you are relying on the cryptography, e.g., you are verifying a \
|
||||
signature, then you should only do this if you are confident that the \
|
||||
message hasn't been tampered with.
|
||||
|
||||
TIME is interpreted as an ISO 8601 timestamp. To set the \
|
||||
policy time to January 1, 2007 at midnight UTC, you can do:
|
||||
|
||||
$ sq --policy-as-of 20070101 verify msg.pgp
|
||||
|
||||
Defaults to the reference time, which can be set using --time.
|
||||
",
|
||||
)]
|
||||
pub policy_as_of: Option<types::Time>,
|
||||
|
||||
#[clap(
|
||||
long = "trust-root",
|
||||
value_name = "FINGERPRINT|KEYID",
|
||||
|
@ -197,12 +197,12 @@ pub fn lint(mut sq: Sq, args: Command) -> Result<()> {
|
||||
|
||||
// Standard policy that unconditionally rejects SHA-1: this is
|
||||
// where we want to be.
|
||||
let mut sp = StandardPolicy::new();
|
||||
let mut sp = StandardPolicy::at(sq.policy_as_of);
|
||||
sp.reject_hash(HashAlgorithm::SHA1);
|
||||
let sp = &sp;
|
||||
|
||||
// A standard policy that also accepts SHA-1.
|
||||
let mut sp_sha1 = StandardPolicy::new();
|
||||
let mut sp_sha1 = StandardPolicy::at(sq.policy_as_of);
|
||||
sp_sha1.accept_hash(HashAlgorithm::SHA1);
|
||||
let sp_sha1 = &sp_sha1;
|
||||
|
||||
|
11
src/main.rs
11
src/main.rs
@ -206,7 +206,13 @@ fn real_main() -> Result<()> {
|
||||
let time: SystemTime =
|
||||
c.time.clone().unwrap_or_else(|| Time::now()).into();
|
||||
|
||||
let mut policy = sequoia_policy_config::ConfiguredStandardPolicy::new();
|
||||
let policy_as_of = c.policy_as_of.clone()
|
||||
.map(|t| SystemTime::from(t)).unwrap_or_else(|| {
|
||||
time.clone()
|
||||
});
|
||||
|
||||
let mut policy
|
||||
= sequoia_policy_config::ConfiguredStandardPolicy::at(policy_as_of);
|
||||
policy.parse_default_config()?;
|
||||
let mut policy = policy.build();
|
||||
|
||||
@ -231,9 +237,10 @@ fn real_main() -> Result<()> {
|
||||
quiet: c.quiet,
|
||||
overwrite: c.overwrite,
|
||||
batch: c.batch,
|
||||
policy: &policy,
|
||||
time,
|
||||
time_is_now,
|
||||
policy_as_of,
|
||||
policy: &policy,
|
||||
home: if let Some(p) = c.home.as_ref().and_then(|a| a.path()) {
|
||||
sequoia_directories::Home::new(p)?
|
||||
} else {
|
||||
|
@ -95,9 +95,10 @@ pub struct Sq<'store, 'rstore>
|
||||
/// Prevent any kind of interactive prompting.
|
||||
pub batch: bool,
|
||||
|
||||
pub policy: &'rstore P<'rstore>,
|
||||
pub time: SystemTime,
|
||||
pub time_is_now: bool,
|
||||
pub policy: &'rstore P<'rstore>,
|
||||
pub policy_as_of: SystemTime,
|
||||
pub home: sequoia_directories::Home,
|
||||
// --no-cert-store
|
||||
pub no_rw_cert_store: bool,
|
||||
|
120
tests/data/messages/signed-by-only-sha1.pgp
Normal file
120
tests/data/messages/signed-by-only-sha1.pgp
Normal file
@ -0,0 +1,120 @@
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
xA0DAAoBa4eC1VsZ6TIBy9NsYgAAAAAAQSBDeXBoZXJwdW5rJ3MgTWFuaWZlc3Rv
|
||||
CmJ5IEVyaWMgSHVnaGVzCgpQcml2YWN5IGlzIG5lY2Vzc2FyeSBmb3IgYW4gb3Bl
|
||||
biBzb2NpZXR5IGluIHRoZSBlbGVjdHJvbmljCmFnZS4gUHJpdmFjeSBpcyBub3Qg
|
||||
c2VjcmVjeS4gQSBwcml2YXRlIG1hdHRlciBpcyBzb21ldGhpbmcgb25lIGRvZXNu
|
||||
J3QKd2FudCB0aGUgd2hvbGUgd29ybGQgdG8ga25vdywgYnV0IGEgc2VjcmV0IG1h
|
||||
dHRlciBpcyBzb21ldGhpbmcgb25lCmRvZXNuJ3Qgd2FudCBhbnlib2R5IHRvIGtu
|
||||
b3cuIFByaXZhY3kgaXMgdGhlIHBvd2VyIHRvIHNlbGVjdGl2ZWx5CnJldmVhbCBv
|
||||
bmVzZWxmIHRvIHRoZSB3b3JsZC4KCklmIHR3byBwYXJ0aWVzIGhhdmUgc29tZSBz
|
||||
b3J0IG9mIGRlYWxpbmdzLCB0aGVuIGVhY2ggaGFzIGEgbWVtb3J5IG9mCnRoZWly
|
||||
IGludGVyYWN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Y5vpcWYOkDpqdbZ35hQaIHRN0nfZ6yAYC96esuw6oNWXbGl1pcT41Od0c
|
||||
Kumq8KmIzjxKRzRmx34qgMzWEAmmijcwgJCh9TFQR6DVcQ0KGs/KGzlkiPY=
|
||||
=kp6c
|
||||
-----END PGP MESSAGE-----
|
@ -17,6 +17,7 @@ use assert_cmd::Command;
|
||||
|
||||
use chrono::DateTime;
|
||||
use chrono::Duration;
|
||||
use chrono::TimeZone;
|
||||
use chrono::Utc;
|
||||
|
||||
use openpgp::packet::Signature;
|
||||
@ -260,6 +261,19 @@ impl Drop for Sq {
|
||||
}
|
||||
|
||||
impl Sq {
|
||||
/// Creates a new Sq context in a new, emphemeral home directory.
|
||||
/// The clock is set to the specified time.
|
||||
pub fn at_str(t: &str) -> Self {
|
||||
if let Ok(d) = chrono::NaiveDateTime::parse_from_str(t, "%Y-%m-%dT%H:%M:%S") {
|
||||
return Self::at(Utc.from_utc_datetime(&d).into());
|
||||
}
|
||||
if let Ok(d) = chrono::NaiveDate::parse_from_str(t, "%Y-%m-%d") {
|
||||
let pad_date_with = chrono::NaiveTime::from_hms_opt(0, 0, 0).unwrap();
|
||||
return Self::at(Utc.from_utc_datetime(&d.and_time(pad_date_with)).into());
|
||||
}
|
||||
panic!("Invalid timestamp, must be YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS");
|
||||
}
|
||||
|
||||
/// Creates a new Sq context in a new, emphemeral home directory.
|
||||
/// The clock is set to the specified time.
|
||||
pub fn at(now: std::time::SystemTime) -> Self {
|
||||
|
@ -6,6 +6,7 @@ use std::io;
|
||||
use sequoia_openpgp as openpgp;
|
||||
use openpgp::Result;
|
||||
|
||||
use super::common::artifact;
|
||||
use super::common::Sq;
|
||||
|
||||
// Make sure verifying bad data fails, and removes the intermediate
|
||||
@ -72,3 +73,59 @@ fn sq_verify_bad() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Make sure --policy-as-of works
|
||||
#[test]
|
||||
fn sq_verify_policy_as_of() -> Result<()> {
|
||||
let sq = Sq::at_str("2024-11-01");
|
||||
|
||||
let cert = artifact("keys/only-sha1-pub.pgp");
|
||||
let msg = artifact("messages/signed-by-only-sha1.pgp");
|
||||
|
||||
assert!(
|
||||
sq.verify_maybe(
|
||||
&[
|
||||
"--signer-file", &cert.display().to_string(),
|
||||
],
|
||||
&msg,
|
||||
None)
|
||||
.is_err());
|
||||
|
||||
// Setting the reference time is not enough, because the message's
|
||||
// creation time would be in the future.
|
||||
assert!(
|
||||
sq.verify_maybe(
|
||||
&[
|
||||
"--time", "2022-01-01",
|
||||
"--signer-file", &cert.display().to_string(),
|
||||
],
|
||||
&msg,
|
||||
None)
|
||||
.is_err());
|
||||
|
||||
// But setting the policy time is.
|
||||
assert!(
|
||||
sq.verify_maybe(
|
||||
&[
|
||||
"--policy-as-of", "2022-01-01",
|
||||
"--signer-file", &cert.display().to_string(),
|
||||
],
|
||||
&msg,
|
||||
None)
|
||||
.is_ok());
|
||||
|
||||
// Make sure we can set both the reference time and the policy
|
||||
// time.
|
||||
assert!(
|
||||
sq.verify_maybe(
|
||||
&[
|
||||
"--time", "2025-01-01",
|
||||
"--policy-as-of", "2022-01-01",
|
||||
"--signer-file", &cert.display().to_string(),
|
||||
],
|
||||
&msg,
|
||||
None)
|
||||
.is_ok());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user