summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-04-07 13:40:50 +0200
committerJustus Winter <justus@sequoia-pgp.org>2024-03-13 10:59:50 +0100
commit3f76b32c8a161c83f1564cfffdce67b9fec45cd3 (patch)
tree730f574bc87f360653f4bc804d064c18835baa57
parentc6bcc4141df0a8b3eae5c024a9d59c23efed560b (diff)
openpgp: Implement the v6 cleartext signature framework.
TODO: reject headers
-rw-r--r--openpgp/src/armor.rs18
-rw-r--r--openpgp/src/parse/stream.rs16
-rw-r--r--openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt16
-rw-r--r--openpgp/tests/data/crypto-refresh/cleartext-signed-message.txt.plain5
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 3f30d696..d3647912 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -3199,11 +3199,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.
@@ -3267,6 +3268,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