Add introducers
- add the `Introducer` types - get introducers from the certificate store (and log them)
This commit is contained in:
+44
-1
@@ -8,14 +8,17 @@ use std::sync::Arc;
|
||||
|
||||
use anyhow;
|
||||
use sequoia_openpgp::parse::Parse;
|
||||
use sequoia_openpgp::policy::StandardPolicy;
|
||||
use sequoia_openpgp::{Fingerprint, Cert};
|
||||
use sequoia_openpgp::cert::raw::RawCertParser;
|
||||
use sequoia_cert_store::{Store, CertStore, LazyCert};
|
||||
use sequoia_wot::{self as wot};
|
||||
use wot::store::Store as _;
|
||||
use wot::{Depth, Path};
|
||||
|
||||
use crate::types::errors::HuskError;
|
||||
use crate::types::husk_context::HuskContext;
|
||||
use crate::types::introducer::Introducer;
|
||||
|
||||
pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
|
||||
|
||||
@@ -71,7 +74,7 @@ pub fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
||||
if let Some(userid) = some_userid {
|
||||
let paths = n.authenticate(userid, &fpr, wot::FULLY_TRUSTED);
|
||||
if paths.len() > 0 {
|
||||
log::debug!("authenticated!!!");
|
||||
log::debug!("{} authenticated!!!", email);
|
||||
for (path, _) in paths.iter() {
|
||||
if let Ok(cert) = cert_store.lookup_by_cert_fpr(&path.target().fingerprint()) {
|
||||
result.push(cert);
|
||||
@@ -82,3 +85,43 @@ pub fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_introducers<'c>(cert_store: &CertStore<'c>, policy: &StandardPolicy, local_trust_root: Fingerprint) -> Vec<Introducer> {
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
||||
let trust_roots = vec![(local_trust_root, wot::FULLY_TRUSTED)];
|
||||
let wot_store = wot::store::CertStore::from_store(cert_store, policy, None);
|
||||
let n = wot::NetworkBuilder::rooted(&wot_store, &*trust_roots)
|
||||
.build();
|
||||
|
||||
n.certified_userids().iter().for_each(|(fpr, user_id)| {
|
||||
let paths = n.authenticate(user_id, fpr, wot::FULLY_TRUSTED);
|
||||
|
||||
// find the longest path (highest trust depth)
|
||||
let mut depth = Depth::Limit(0);
|
||||
let mut target: Option<&Path> = None;
|
||||
paths.iter().for_each(|(path, amount)| {
|
||||
if *amount == wot::FULLY_TRUSTED {
|
||||
let d = path.residual_depth();
|
||||
if d > depth {
|
||||
depth = d;
|
||||
target = Some(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if depth > Depth::Limit(0) {
|
||||
if let Some(p) = target {
|
||||
if let Some(c) = p.certifications().last() {
|
||||
result.push( Introducer {
|
||||
cert: p.target().clone(),
|
||||
certification: c.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user