| 1 |
//! Operations on certs. |
| 2 |
|
| 3 |
use sequoia_openpgp as openpgp; |
| 4 |
use openpgp::{ |
| 5 |
Fingerprint, |
| 6 |
KeyHandle, |
| 7 |
}; |
| 8 |
|
| 9 |
use crate::{ |
| 10 |
Result, |
| 11 |
Sq, |
| 12 |
cli::cert::{Command, list, Subcommands}, |
| 13 |
commands::cert::authenticate::AuthenticateContext, |
| 14 |
commands::cert::authenticate::Query, |
| 15 |
commands::cert::authenticate::QueryKind, |
| 16 |
common::pki::authenticate, |
| 17 |
}; |
| 18 |
|
| 19 |
pub mod import; |
| 20 |
pub mod export; |
| 21 |
pub mod lint; |
| 22 |
|
| 23 |
pub fn dispatch(sq: Sq, command: Command) -> Result<()> |
| 24 |
{ |
| 25 |
match command.subcommand { |
| 26 |
Subcommands::Import(command) => |
| 27 |
import::dispatch(sq, command), |
| 28 |
|
| 29 |
Subcommands::Export(command) => |
| 30 |
export::dispatch(sq, command), |
| 31 |
|
| 32 |
// List all authenticated bindings. |
| 33 |
Subcommands::List(list::Command { |
| 34 |
certs, pattern, gossip, unusable, certification_network, |
| 35 |
trust_amount, show_paths, |
| 36 |
}) => { |
| 37 |
let mut certs: Vec<Query> = Query::for_cert_designators(certs, true); |
| 38 |
|
| 39 |
if let Some(pattern) = pattern.as_ref() { |
| 40 |
let mut query_kind = None; |
| 41 |
if let Ok(kh) = pattern.parse::<KeyHandle>() { |
| 42 |
if matches!(kh, KeyHandle::Fingerprint(Fingerprint::Unknown { .. })) { |
| 43 |
let hex = pattern.chars() |
| 44 |
.map(|c| { |
| 45 |
if c == ' ' { 0 } else { 1 } |
| 46 |
}) |
| 47 |
.sum::<usize>(); |
| 48 |
|
| 49 |
if hex >= 16 { |
| 50 |
weprintln!("Warning: {} looks like a fingerprint or key ID, \ |
| 51 |
but it is invalid. Treating it as a text pattern.", |
| 52 |
pattern); |
| 53 |
} |
| 54 |
} else { |
| 55 |
query_kind = Some(QueryKind::AuthenticatedCert(kh)); |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
let query_kind = query_kind.unwrap_or_else(|| { |
| 60 |
QueryKind::Pattern(pattern.clone()) |
| 61 |
}); |
| 62 |
certs.push(Query { |
| 63 |
argument: Some(format!("{:?}", pattern)), |
| 64 |
kind: query_kind, |
| 65 |
}); |
| 66 |
} |
| 67 |
|
| 68 |
authenticate( |
| 69 |
&mut std::io::stdout(), |
| 70 |
&sq, |
| 71 |
AuthenticateContext::PKI, |
| 72 |
certs, |
| 73 |
*gossip, |
| 74 |
*unusable, |
| 75 |
*certification_network, |
| 76 |
*trust_amount, |
| 77 |
*show_paths) |
| 78 |
}, |
| 79 |
|
| 80 |
Subcommands::Lint(command) => |
| 81 |
lint::lint(sq, command), |
| 82 |
} |
| 83 |
} |