From 9cde4b27309582715edc0692501a5df9d62c9f17 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 6 Jul 2023 18:24:59 +0200 Subject: openpgp: Fix hashing v3 signatures. - The high-level hashing functions are implemented on SignatureFields (so that we can use them from the SignatureBuilder). Unfortunately, when those functions invoke SignatureFields::hash, the type encoding the packet version has been erased. - Recover the version at runtime and dispatch to the right hashing function. --- openpgp/src/cert.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'openpgp/src/cert.rs') diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index 23050580..0170b0e8 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -7247,4 +7247,32 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= Ok(()) } + + /// Tests v3 binding signatures. + #[test] + fn v3_binding_signature() -> Result<()> { + if ! crate::types::PublicKeyAlgorithm::DSA.is_supported() { + eprintln!("Skipping because DSA is not supported"); + return Ok(()); + } + + let c = Cert::from_bytes( + crate::tests::key("pgp5-dsa-elg-v3-subkey-binding.pgp"))?; + assert_eq!(c.bad_signatures().count(), 0); + + let np = crate::policy::NullPolicy::new(); + + // The subkey is interesting because it is bound using a v3 + // signature. + let vcert = c.with_policy(&np, None)?; + assert_eq!(vcert.keys().subkeys().count(), 1); + + // XXX: Unfortunately, it being a v3 signature, the subkey has + // no keyflags, limiting its usefulness for now. + + // The subkey is interesting because it is bound using a v3 + // signature. + assert_eq!(c.keys().subkeys().with_policy(&np, None).count(), 1); + Ok(()) + } } -- cgit v1.2.3