Check for encryption
- collect body of incoming mail. - check if incoming mail is already encrypted - dont touch it if it is. - check if recipients of that mail can encrypt.
This commit is contained in:
+32
-3
@@ -7,9 +7,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow;
|
||||
use sequoia_openpgp::parse::Parse;
|
||||
use bytes::Bytes;
|
||||
use sequoia_openpgp::parse::{PacketParser, PacketParserResult, Parse};
|
||||
use sequoia_openpgp::policy::StandardPolicy;
|
||||
use sequoia_openpgp::{Fingerprint, Cert};
|
||||
use sequoia_openpgp::{Fingerprint, Cert, Packet};
|
||||
use sequoia_openpgp::cert::raw::RawCertParser;
|
||||
use sequoia_cert_store::{Store, CertStore, LazyCert};
|
||||
use sequoia_wot::{self as wot};
|
||||
@@ -55,7 +56,7 @@ pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
|
||||
|
||||
}
|
||||
|
||||
pub fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
||||
pub fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
||||
-> Vec<Arc<LazyCert<'hc>>> {
|
||||
|
||||
let cert_store = &context.cert_store;
|
||||
@@ -125,3 +126,31 @@ pub fn get_introducers<'c>(cert_store: &CertStore<'c>, policy: &StandardPolicy,
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn is_encrypted(body: &Bytes) -> bool {
|
||||
|
||||
let mut ppr = match PacketParser::from_bytes(body) {
|
||||
Ok(pp) => pp,
|
||||
Err(_) => return false, // no OpenPGP artifacts
|
||||
};
|
||||
|
||||
let mut encrypted: bool = false;
|
||||
|
||||
while let PacketParserResult::Some(pp) = ppr {
|
||||
if let Packet::SEIP(_) = pp.packet {
|
||||
encrypted = true;
|
||||
}
|
||||
|
||||
// parse the whole message, don't stop at first SEIP
|
||||
ppr = match pp.recurse() {
|
||||
Ok((_, next_ppr)) => next_ppr,
|
||||
Err(_) => return false, // broken artifact -> not encrypted
|
||||
}
|
||||
}
|
||||
if let PacketParserResult::EOF(eof) = ppr {
|
||||
if eof.is_message().is_ok() && encrypted {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user