Add certificates
- Refactor `Recipient` out of `MailContext`. - Add lookup of authenticated certificates for recipients.
This commit is contained in:
+38
-1
@@ -4,12 +4,18 @@
|
||||
// cryptographic functions
|
||||
//
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow;
|
||||
use sequoia_openpgp::parse::Parse;
|
||||
use sequoia_openpgp::{Fingerprint, Cert};
|
||||
use sequoia_openpgp::cert::raw::RawCertParser;
|
||||
use sequoia_cert_store::CertStore;
|
||||
use sequoia_cert_store::{Store, CertStore, LazyCert};
|
||||
use sequoia_wot::{self as wot};
|
||||
use wot::store::Store as _;
|
||||
|
||||
use crate::types::errors::HuskError;
|
||||
use crate::types::husk_context::HuskContext;
|
||||
|
||||
pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
|
||||
|
||||
@@ -45,3 +51,34 @@ pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
||||
-> Vec<Arc<LazyCert<'hc>>> {
|
||||
|
||||
let cert_store = &context.cert_store;
|
||||
let trust_roots = vec![(context.local_trust_root.fingerprint(), wot::FULLY_TRUSTED)];
|
||||
let wot_store = wot::store::CertStore::from_store(cert_store, &context.policy, None);
|
||||
let nb = wot::NetworkBuilder::rooted(&wot_store, &*trust_roots);
|
||||
let n = nb.build();
|
||||
|
||||
let bindings: Vec<_> = n.lookup_synopses_by_email(email)
|
||||
.into_iter()
|
||||
.map(|(fp, userid)| (fp, Some(userid)))
|
||||
.collect();
|
||||
|
||||
let mut result = vec![];
|
||||
for (fpr, some_userid) in bindings {
|
||||
if let Some(userid) = some_userid {
|
||||
let paths = n.authenticate(userid, &fpr, wot::FULLY_TRUSTED);
|
||||
if paths.len() > 0 {
|
||||
log::debug!("authenticated!!!");
|
||||
for (path, _) in paths.iter() {
|
||||
if let Ok(cert) = cert_store.lookup_by_cert_fpr(&path.target().fingerprint()) {
|
||||
result.push(cert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user