diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-04-07 13:40:50 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-07-01 12:46:46 +0200 |
commit | 83068f6c6f17d91730feb39b9eea0fa03a8bcf2e (patch) | |
tree | 825b3c28d831ef9e9c8b798a2b395d972cdfcfd7 | |
parent | 26e86a11e61b9b81ed1369b0f3fce7dd2c59a4f8 (diff) |
openpgp: Implement the v6 cleartext signature framework.
TODO: reject headers
-rw-r--r-- | openpgp/src/armor.rs | 18 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 16 | ||||
-rw-r--r-- | openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt | 16 | ||||
-rw-r--r-- | openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt.plain | 5 |
4 files changed, 37 insertions, 18 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 21b39511..75d7ca25 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -1506,7 +1506,7 @@ impl<'a> Reader<'a> { let mut opss = Vec::with_capacity(sigs.len()); for p in sigs.iter().rev() { if let Packet::Signature(sig) = p { - if let Ok(ops) = OnePassSig3::try_from(sig) { + if let Ok(ops) = OnePassSig::try_from(sig) { opss.push(ops); } } @@ -2406,19 +2406,9 @@ mod test { assert_eq!(reference.pop(), Some(b'\n')); reference }, HashAlgorithm::SHA256)?; - f(crate::tests::message("a-cypherpunks-manifesto.txt.cleartext.sig"), - { - // The test vector, created by GnuPG, does not preserve - // the final newline. - // - // The transformation process trims trailing whitespace, - // and the manifesto has a trailing whitespace right at - // the end. - let mut manifesto = crate::tests::manifesto().to_vec(); - assert_eq!(manifesto.pop(), Some(b'\n')); - assert_eq!(manifesto.pop(), Some(b' ')); - manifesto - }, HashAlgorithm::SHA256)?; + f(crate::tests::file("crypto-refresh/cleartext-signed-message.txt"), + crate::tests::file("crypto-refresh/cleartext-signed-message.txt.plain"), + HashAlgorithm::SHA512)?; Ok(()) } } diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index bd9f821b..974fba73 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -3213,11 +3213,12 @@ pub mod test { let p = P::new(); let certs = [ - "neal.pgp", - "testy-new.pgp", - "emmelie-dorothea-dina-samantha-awina-ed25519.pgp" + "keys/neal.pgp", + "keys/testy-new.pgp", + "keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp", + "crypto-refresh/v6-minimal-cert.key", ].iter() - .map(|f| Cert::from_bytes(crate::tests::key(f)).unwrap()) + .map(|f| Cert::from_bytes(crate::tests::file(f)).unwrap()) .collect::<Vec<_>>(); let tests = &[ // Signed messages. @@ -3281,6 +3282,13 @@ pub mod test { false, None, VHelper::new(1, 0, 0, 0, certs.clone())), + (crate::tests::file("crypto-refresh/cleartext-signed-message.txt") + .to_vec(), + crate::tests::file("crypto-refresh/cleartext-signed-message.txt.plain") + .to_vec(), + false, + None, + VHelper::new(1, 0, 0, 0, certs.clone())), // A key as example of an invalid message. (crate::tests::key("neal.pgp").to_vec(), crate::tests::manifesto().to_vec(), diff --git a/openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt b/openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt new file mode 100644 index 00000000..8a02b102 --- /dev/null +++ b/openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNED MESSAGE----- +SaltedHash: SHA512:dklfUCGIkPf14u48GCJRT3BQD1UdhuXJIeQE40pT+6w + +What we need from the grocery store: + +- - tofu +- - vegetables +- - noodles + +-----BEGIN PGP SIGNATURE----- + +wpgGARsKAAAAKQWCY5ijYyIhBssYbE8GCaaX5NUt+mxyKwwfHifBilZwj2Ul7Ce6 +2azJAAAAAGk2IHZJX1AhiJD39eLuPBgiUU9wUA9VHYblySHkBONKU/usJ9BvuAqo +/FvLFuGWMbKAdA+epq7V4HOtAPlBWmU8QOd6aud+aSunHQaaEJ+iTFjP2OMW0KBr +NK2ay45cX1IVAQ== +-----END PGP SIGNATURE----- diff --git a/openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt.plain b/openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt.plain new file mode 100644 index 00000000..d812d543 --- /dev/null +++ b/openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt.plain @@ -0,0 +1,5 @@ +What we need from the grocery store: + +- tofu +- vegetables +- noodles |