diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-05-09 15:19:24 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-05-09 15:19:24 +0200 |
commit | 75d4e6dda12e8b7ae8573227e61e718ede3f2cfc (patch) | |
tree | c6b9e3f177d8c65d134acfd889c236203b2ac13f /tool | |
parent | 8e0f817f312f469871a5fbed6bb961f6117ba742 (diff) |
openpgp: Communicate message structure from the decryptor.
- Fixes #100.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/commands/decrypt.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 131 |
2 files changed, 77 insertions, 60 deletions
diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs index 4d000cc3..c762c454 100644 --- a/tool/src/commands/decrypt.rs +++ b/tool/src/commands/decrypt.rs @@ -13,7 +13,7 @@ use openpgp::{Fingerprint, TPK, KeyID, Result}; use openpgp::packet::{Key, key::SecretKey, Signature, PKESK, SKESK}; use openpgp::parse::PacketParser; use openpgp::parse::stream::{ - VerificationHelper, VerificationResult, DecryptionHelper, Decryptor, + VerificationHelper, DecryptionHelper, Decryptor, MessageStructure, }; extern crate sequoia_store as store; @@ -93,8 +93,8 @@ impl<'a> VerificationHelper for Helper<'a> { fn get_public_keys(&mut self, ids: &[KeyID]) -> Result<Vec<TPK>> { self.vhelper.get_public_keys(ids) } - fn check(&mut self, sigs: Vec<Vec<VerificationResult>>) -> Result<()> { - self.vhelper.check(sigs) + fn check(&mut self, structure: &MessageStructure) -> Result<()> { + self.vhelper.check(structure) } } diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index 172e9042..0f729968 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -18,6 +18,7 @@ use openpgp::parse::{ }; use openpgp::parse::stream::{ Verifier, DetachedVerifier, VerificationResult, VerificationHelper, + MessageStructure, MessageLayer, }; use openpgp::serialize::stream::{ Message, Signer, LiteralWriter, Encryptor, EncryptionMode, @@ -189,6 +190,66 @@ impl<'a> VHelper<'a> { eprintln!("."); } } + + fn print_sigs(&mut self, results: &[VerificationResult]) { + use self::VerificationResult::*; + for result in results { + let (issuer, level) = match result { + GoodChecksum(ref sig, ..) => (sig.get_issuer(), sig.level()), + MissingKey(ref sig) => (sig.get_issuer(), sig.level()), + BadChecksum(ref sig) => (sig.get_issuer(), sig.level()), + }; + + let trusted = issuer.as_ref().map(|i| { + self.trusted.contains(&i) + }).unwrap_or(false); + let what = match (level == 0, trusted) { + (true, true) => "signature".into(), + (false, true) => format!("level {} notarization", level), + (true, false) => "checksum".into(), + (false, false) => + format!("level {} notarizing checksum", level), + }; + + match result { + GoodChecksum(..) => { + let issuer = issuer + .expect("good checksum has an issuer"); + let issuer_str = format!("{}", issuer); + eprintln!("Good {} from {}", what, + self.labels.get(&issuer).unwrap_or( + &issuer_str)); + if trusted { + self.good_signatures += 1; + } else { + self.good_checksums += 1; + } + }, + MissingKey(_) => { + let issuer = issuer + .expect("missing key checksum has an issuer"); + eprintln!("No key to check {} from {}", what, issuer); + self.unknown_checksums += 1; + }, + BadChecksum(_) => { + if let Some(issuer) = issuer { + let issuer_str = format!("{}", issuer); + eprintln!("Bad {} from {}", what, + self.labels.get(&issuer).unwrap_or( + &issuer_str)); + } else { + eprintln!("Bad {} without issuer information", + what); + } + if trusted { + self.bad_signatures += 1; + } else { + self.bad_checksums += 1; + } + }, + } + } + } } impl<'a> VerificationHelper for VHelper<'a> { @@ -241,64 +302,20 @@ impl<'a> VerificationHelper for VHelper<'a> { Ok(tpks) } - fn check(&mut self, sigs: Vec<Vec<VerificationResult>>) -> Result<()> { - use self::VerificationResult::*; - for (i, results) in sigs.into_iter().rev().enumerate() { - for result in results { - let issuer = match result { - GoodChecksum(ref sig, ..) => sig.get_issuer(), - MissingKey(ref sig) => sig.get_issuer(), - BadChecksum(ref sig) => sig.get_issuer(), - }; - - let trusted = issuer.as_ref().map(|i| { - self.trusted.contains(&i) - }).unwrap_or(false); - let what = match (i == 0, trusted) { - (true, true) => "signature".into(), - (false, true) => format!("level {} notarization", i), - (true, false) => "checksum".into(), - (false, false) => - format!("level {} notarizing checksum", i), - }; - - match result { - GoodChecksum(..) => { - let issuer = issuer - .expect("good checksum has an issuer"); - let issuer_str = format!("{}", issuer); - eprintln!("Good {} from {}", what, - self.labels.get(&issuer).unwrap_or( - &issuer_str)); - if trusted { - self.good_signatures += 1; - } else { - self.good_checksums += 1; - } - }, - MissingKey(_) => { - let issuer = issuer - .expect("missing key checksum has an issuer"); - eprintln!("No key to check {} from {}", what, issuer); - self.unknown_checksums += 1; - }, - BadChecksum(_) => { - if let Some(issuer) = issuer { - let issuer_str = format!("{}", issuer); - eprintln!("Bad {} from {}", what, - self.labels.get(&issuer).unwrap_or( - &issuer_str)); - } else { - eprintln!("Bad {} without issuer information", - what); - } - if trusted { - self.bad_signatures += 1; - } else { - self.bad_checksums += 1; - } + fn check(&mut self, structure: &MessageStructure) -> Result<()> { + for layer in structure.iter() { + match layer { + MessageLayer::Compression { algo } => + eprintln!("Compressed using {}", algo), + MessageLayer::Encryption { sym_algo, aead_algo } => + if let Some(aead_algo) = aead_algo { + eprintln!("Encrypted and protected using {}/{}", + sym_algo, aead_algo); + } else { + eprintln!("Encrypted using {}", sym_algo); }, - } + MessageLayer::SignatureGroup { ref results } => + self.print_sigs(results), } } |