diff options
Diffstat (limited to 'tool/src')
-rw-r--r-- | tool/src/commands/decrypt.rs | 8 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 24 | ||||
-rw-r--r-- | tool/src/sq-usage.rs | 72 | ||||
-rw-r--r-- | tool/src/sq.rs | 82 | ||||
-rw-r--r-- | tool/src/sq_cli.rs | 34 |
5 files changed, 111 insertions, 109 deletions
diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs index 9906b583..bde80c2b 100644 --- a/tool/src/commands/decrypt.rs +++ b/tool/src/commands/decrypt.rs @@ -31,7 +31,7 @@ struct Helper<'a> { } impl<'a> Helper<'a> { - fn new(ctx: &'a Context, store: &'a mut store::Store, + fn new(ctx: &'a Context, mapping: &'a mut store::Mapping, signatures: usize, tpks: Vec<TPK>, secrets: Vec<TPK>, dump_session_key: bool, dump: bool, hex: bool) -> Self { @@ -77,7 +77,7 @@ impl<'a> Helper<'a> { } Helper { - vhelper: VHelper::new(ctx, store, signatures, tpks), + vhelper: VHelper::new(ctx, mapping, signatures, tpks), secret_keys: keys, key_identities: identities, key_hints: hints, @@ -292,13 +292,13 @@ impl<'a> DecryptionHelper for Helper<'a> { } } -pub fn decrypt(ctx: &Context, store: &mut store::Store, +pub fn decrypt(ctx: &Context, mapping: &mut store::Mapping, input: &mut io::Read, output: &mut io::Write, signatures: usize, tpks: Vec<TPK>, secrets: Vec<TPK>, dump_session_key: bool, dump: bool, hex: bool) -> Result<()> { - let helper = Helper::new(ctx, store, signatures, tpks, secrets, + let helper = Helper::new(ctx, mapping, signatures, tpks, secrets, dump_session_key, dump, hex); let mut decryptor = Decryptor::from_reader(input, helper, None) .context("Decryption failed")?; diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index f9cbb776..de671fa6 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -84,7 +84,7 @@ fn get_signing_keys(tpks: &[openpgp::TPK]) Ok(keys) } -pub fn encrypt(store: &mut store::Store, +pub fn encrypt(mapping: &mut store::Mapping, input: &mut io::Read, output: &mut io::Write, npasswords: usize, recipients: Vec<&str>, mut tpks: Vec<openpgp::TPK>, signers: Vec<openpgp::TPK>, @@ -92,7 +92,7 @@ pub fn encrypt(store: &mut store::Store, compression: &str) -> Result<()> { for r in recipients { - tpks.push(store.lookup(r).context("No such key found")?.tpk()?); + tpks.push(mapping.lookup(r).context("No such key found")?.tpk()?); } let mut passwords: Vec<crypto::Password> = Vec::with_capacity(npasswords); for n in 0..npasswords { @@ -171,7 +171,7 @@ pub fn encrypt(store: &mut store::Store, struct VHelper<'a> { ctx: &'a Context, - store: &'a mut store::Store, + mapping: &'a mut store::Mapping, signatures: usize, tpks: Option<Vec<TPK>>, labels: HashMap<KeyID, String>, @@ -184,12 +184,12 @@ struct VHelper<'a> { } impl<'a> VHelper<'a> { - fn new(ctx: &'a Context, store: &'a mut store::Store, signatures: usize, + fn new(ctx: &'a Context, mapping: &'a mut store::Mapping, signatures: usize, tpks: Vec<TPK>) -> Self { VHelper { ctx: ctx, - store: store, + mapping: mapping, signatures: signatures, tpks: Some(tpks), labels: HashMap::new(), @@ -298,14 +298,14 @@ impl<'a> VerificationHelper for VHelper<'a> { // Explicitly provided keys are trusted. self.trusted = seen.clone(); - // Try to get missing TPKs from the store. + // Try to get missing TPKs from the mapping. for id in ids.iter().filter(|i| !seen.contains(i)) { let _ = - self.store.lookup_by_subkeyid(id) + self.mapping.lookup_by_subkeyid(id) .and_then(|binding| { self.labels.insert(id.clone(), binding.label()?); - // Keys from our store are trusted. + // Keys from our mapping are trusted. self.trusted.insert(id.clone()); binding.tpk() @@ -362,13 +362,13 @@ impl<'a> VerificationHelper for VHelper<'a> { } } -pub fn verify(ctx: &Context, store: &mut store::Store, +pub fn verify(ctx: &Context, mapping: &mut store::Mapping, input: &mut io::Read, detached: Option<&mut io::Read>, output: &mut io::Write, signatures: usize, tpks: Vec<TPK>) -> Result<()> { - let helper = VHelper::new(ctx, store, signatures, tpks); + let helper = VHelper::new(ctx, mapping, signatures, tpks); let mut verifier = if let Some(dsig) = detached { DetachedVerifier::from_reader(dsig, input, helper, None)? } else { @@ -468,7 +468,7 @@ pub fn join(inputs: Option<clap::Values>, output: &mut io::Write) Ok(()) } -pub fn store_print_stats(store: &store::Store, label: &str) -> Result<()> { +pub fn mapping_print_stats(mapping: &store::Mapping, label: &str) -> Result<()> { fn print_stamps(st: &store::Stamps) -> Result<()> { println!("{} messages using this key", st.count); if let Some(t) = st.first { @@ -494,7 +494,7 @@ pub fn store_print_stats(store: &store::Store, label: &str) -> Result<()> { Ok(()) } - let binding = store.lookup(label)?; + let binding = mapping.lookup(label)?; println!("Binding {:?}", label); print_stats(&binding.stats().context("Failed to get stats")?)?; let key = binding.key().context("Failed to get key")?; diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs index bc450862..3c535633 100644 --- a/tool/src/sq-usage.rs +++ b/tool/src/sq-usage.rs @@ -15,15 +15,15 @@ //! //! OPTIONS: //! --home <DIRECTORY> Sets the home directory to use +//! -m, --mapping <MAPPING> Sets the realm and mapping to use [default: org.sequoia-pgp.contacts/default] //! -p, --policy <NETWORK-POLICY> Sets the network policy to use -//! -s, --store <STORE> Sets the realm and store to use [default: org.sequoia-pgp.contacts/default] //! //! SUBCOMMANDS: //! decrypt Decrypts an OpenPGP message //! encrypt Encrypts a message //! sign Signs a message //! verify Verifies a message -//! store Interacts with key stores +//! mapping Interacts with key mappings //! keyserver Interacts with keyservers //! autocrypt Autocrypt support //! dearmor Removes ASCII Armor from a file @@ -31,7 +31,7 @@ //! help Prints this message or the help of the given subcommand(s) //! inspect Inspects a sequence of OpenPGP packets //! key Manipulates keys -//! list Lists key stores and known keys +//! list Lists key mappings and known keys //! packet OpenPGP Packet manipulation //! wkd Interacts with Web Key Directories //! ``` @@ -137,13 +137,13 @@ //! <FILE> Sets the input file to use //! ``` //! -//! ## Subcommand store +//! ## Subcommand mapping //! //! ```text -//! Interacts with key stores +//! Interacts with key mappings //! //! USAGE: -//! sq store <SUBCOMMAND> +//! sq mapping <SUBCOMMAND> //! //! FLAGS: //! -h, --help Prints help information @@ -151,22 +151,22 @@ //! //! SUBCOMMANDS: //! add Add a key identified by fingerprint -//! delete Deletes bindings or stores +//! delete Deletes bindings or mappings //! export Exports a key //! help Prints this message or the help of the given subcommand(s) //! import Imports a key -//! list Lists keys in the store +//! list Lists keys in the mapping //! log Lists the keystore log //! stats Get stats for the given label //! ``` //! -//! ### Subcommand store add +//! ### Subcommand mapping add //! //! ```text //! Add a key identified by fingerprint //! //! USAGE: -//! sq store add <LABEL> <FINGERPRINT> +//! sq mapping add <LABEL> <FINGERPRINT> //! //! FLAGS: //! -h, --help Prints help information @@ -177,30 +177,30 @@ //! <FINGERPRINT> Key to add //! ``` //! -//! ### Subcommand store delete +//! ### Subcommand mapping delete //! //! ```text -//! Deletes bindings or stores +//! Deletes bindings or mappings //! //! USAGE: -//! sq store delete [FLAGS] [LABEL] +//! sq mapping delete [FLAGS] [LABEL] //! //! FLAGS: -//! -h, --help Prints help information -//! --the-store Delete the selected store (change with --store) -//! -V, --version Prints version information +//! -h, --help Prints help information +//! --the-mapping Delete the selected mapping (change with --mapping) +//! -V, --version Prints version information //! //! ARGS: //! <LABEL> Delete binding with this label //! ``` //! -//! ### Subcommand store export +//! ### Subcommand mapping export //! //! ```text //! Exports a key //! //! USAGE: -//! sq store export [FLAGS] [OPTIONS] <LABEL> +//! sq mapping export [FLAGS] [OPTIONS] <LABEL> //! //! FLAGS: //! -B, --binary Don't ASCII-armor encode the OpenPGP data @@ -214,13 +214,13 @@ //! <LABEL> Label to use //! ``` //! -//! ### Subcommand store import +//! ### Subcommand mapping import //! //! ```text //! Imports a key //! //! USAGE: -//! sq store import <LABEL> [FILE] +//! sq mapping import <LABEL> [FILE] //! //! FLAGS: //! -h, --help Prints help information @@ -231,26 +231,26 @@ //! <FILE> Sets the input file to use //! ``` //! -//! ### Subcommand store list +//! ### Subcommand mapping list //! //! ```text -//! Lists keys in the store +//! Lists keys in the mapping //! //! USAGE: -//! sq store list +//! sq mapping list //! //! FLAGS: //! -h, --help Prints help information //! -V, --version Prints version information //! ``` //! -//! ### Subcommand store log +//! ### Subcommand mapping log //! //! ```text //! Lists the keystore log //! //! USAGE: -//! sq store log [LABEL] +//! sq mapping log [LABEL] //! //! FLAGS: //! -h, --help Prints help information @@ -260,13 +260,13 @@ //! <LABEL> List messages related to this label //! ``` //! -//! ### Subcommand store stats +//! ### Subcommand mapping stats //! //! ```text //! Get stats for the given label //! //! USAGE: -//! sq store stats <LABEL> +//! sq mapping stats <LABEL> //! //! FLAGS: //! -h, --help Prints help information @@ -499,7 +499,7 @@ //! ## Subcommand list //! //! ```text -//! Lists key stores and known keys +//! Lists key mappings and known keys //! //! USAGE: //! sq list <SUBCOMMAND> @@ -509,17 +509,17 @@ //! -V, --version Prints version information //! //! SUBCOMMANDS: -//! bindings Lists all bindings in all key stores +//! bindings Lists all bindings in all key mappings //! help Prints this message or the help of the given subcommand(s) //! keys Lists all keys in the common key pool //! log Lists the server log -//! stores Lists key stores +//! mappings Lists key mappings //! ``` //! //! ### Subcommand list bindings //! //! ```text -//! Lists all bindings in all key stores +//! Lists all bindings in all key mappings //! //! USAGE: //! sq list bindings [PREFIX] @@ -529,7 +529,7 @@ //! -V, --version Prints version information //! //! ARGS: -//! <PREFIX> List only bindings from stores with the given realm prefix +//! <PREFIX> List only bindings from mappings with the given realm prefix //! ``` //! //! ### Subcommand list keys @@ -558,20 +558,20 @@ //! -V, --version Prints version information //! ``` //! -//! ### Subcommand list stores +//! ### Subcommand list mappings //! //! ```text -//! Lists key stores +//! Lists key mappings //! //! USAGE: -//! sq list stores [PREFIX] +//! sq list mappings [PREFIX] //! //! FLAGS: //! -h, --help Prints help information //! -V, --version Prints version information //! //! ARGS: -//! <PREFIX> List only stores with the given realm prefix +//! <PREFIX> List only mappings with the given realm prefix //! ``` //! //! ## Subcommand packet diff --git a/tool/src/sq.rs b/tool/src/sq.rs index ac247978..94486ac7 100644 --- a/tool/src/sq.rs +++ b/tool/src/sq.rs @@ -22,7 +22,7 @@ use std::process::exit; extern crate sequoia_openpgp as openpgp; extern crate sequoia_core; extern crate sequoia_net; -extern crate sequoia_store; +extern crate sequoia_store as store; use crate::openpgp::{armor, autocrypt, Fingerprint, TPK}; use crate::openpgp::conversions::hex; @@ -32,7 +32,7 @@ use crate::openpgp::serialize::Serialize; use crate::openpgp::tpk::TPKParser; use sequoia_core::{Context, NetworkPolicy}; use sequoia_net::{KeyServer, wkd}; -use sequoia_store::{Store, LogIter}; +use store::{Mapping, LogIter}; mod sq_cli; mod commands; @@ -151,8 +151,8 @@ fn real_main() -> Result<(), failure::Error> { }, }; let force = matches.is_present("force"); - let (realm_name, store_name) = { - let s = matches.value_of("store").expect("has a default value"); + let (realm_name, mapping_name) = { + let s = matches.value_of("mapping").expect("has a default value"); if let Some(i) = s.find('/') { (&s[..i], &s[i+1..]) } else { @@ -179,9 +179,9 @@ fn real_main() -> Result<(), failure::Error> { let secrets = m.values_of("secret-key-file") .map(load_tpks) .unwrap_or(Ok(vec![]))?; - let mut store = Store::open(&ctx, realm_name, store_name) - .context("Failed to open the store")?; - commands::decrypt(&ctx, &mut store, + let mut mapping = Mapping::open(&ctx, realm_name, mapping_name) + .context("Failed to open the mapping")?; + commands::decrypt(&ctx, &mut mapping, &mut input, &mut output, signatures, tpks, secrets, m.is_present("dump-session-key"), @@ -197,8 +197,8 @@ fn real_main() -> Result<(), failure::Error> { } else { output }; - let mut store = Store::open(&ctx, realm_name, store_name) - .context("Failed to open the store")?; + let mut mapping = Mapping::open(&ctx, realm_name, mapping_name) + .context("Failed to open the mapping")?; let recipients = m.values_of("recipient") .map(|r| r.collect()) .unwrap_or(vec![]); @@ -218,7 +218,7 @@ fn real_main() -> Result<(), failure::Error> { .set_encrypt_for_transport(true), _ => unreachable!("uses possible_values"), }; - commands::encrypt(&mut store, &mut input, &mut output, + commands::encrypt(&mut mapping, &mut input, &mut output, m.occurrences_of("symmetric") as usize, recipients, additional_tpks, additional_secrets, mode, @@ -250,9 +250,9 @@ fn real_main() -> Result<(), failure::Error> { let tpks = m.values_of("public-key-file") .map(load_tpks) .unwrap_or(Ok(vec![]))?; - let mut store = Store::open(&ctx, realm_name, store_name) - .context("Failed to open the store")?; - commands::verify(&ctx, &mut store, &mut input, + let mut mapping = Mapping::open(&ctx, realm_name, mapping_name) + .context("Failed to open the mapping")?; + commands::verify(&ctx, &mut mapping, &mut input, detached.as_mut().map(|r| r as &mut io::Read), &mut output, signatures, tpks)?; }, @@ -402,28 +402,28 @@ fn real_main() -> Result<(), failure::Error> { _ => unreachable!(), } }, - ("store", Some(m)) => { - let store = Store::open(&ctx, realm_name, store_name) - .context("Failed to open the store")?; + ("mapping", Some(m)) => { + let mapping = Mapping::open(&ctx, realm_name, mapping_name) + .context("Failed to open the mapping")?; match m.subcommand() { ("list", Some(_)) => { - list_bindings(&store, realm_name, store_name)?; + list_bindings(&mapping, realm_name, mapping_name)?; }, ("add", Some(m)) => { let fp = Fingerprint::from_hex(m.value_of("fingerprint").unwrap()) .expect("Malformed fingerprint"); - store.add(m.value_of("label").unwrap(), &fp)?; + mapping.add(m.value_of("label").unwrap(), &fp)?; }, ("import", Some(m)) => { let label = m.value_of("label").unwrap(); help_warning(label); let mut input = open_or_stdin(m.value_of("input"))?; let tpk = TPK::from_reader(&mut input)?; - store.import(label, &tpk)?; + mapping.import(label, &tpk)?; }, ("export", Some(m)) => { - let tpk = store.lookup(m.value_of("label").unwrap())?.tpk()?; + let tpk = mapping.lookup(m.value_of("label").unwrap())?.tpk()?; let mut output = create_or_stdout(m.value_of("output"), force)?; if m.is_present("binary") { tpk.serialize(&mut output)?; @@ -432,30 +432,30 @@ fn real_main() -> Result<(), failure::Error> { } }, ("delete", Some(m)) => { - if m.is_present("label") == m.is_present("the-store") { - eprintln!("Please specify either a label or --the-store."); + if m.is_present("label") == m.is_present("the-mapping") { + eprintln!("Please specify either a label or --the-mapping."); exit(1); } - if m.is_present("the-store") { - store.delete().context("Failed to delete the store")?; + if m.is_present("the-mapping") { + mapping.delete().context("Failed to delete the mapping")?; } else { - let binding = store.lookup(m.value_of("label").unwrap()) + let binding = mapping.lookup(m.value_of("label").unwrap()) .context("Failed to get key")?; binding.delete().context("Failed to delete the binding")?; } }, ("stats", Some(m)) => { - commands::store_print_stats(&store, + commands::mapping_print_stats(&mapping, m.value_of("label").unwrap())?; }, ("log", Some(m)) => { if m.is_present("label") { - let binding = store.lookup(m.value_of("label").unwrap()) + let binding = mapping.lookup(m.value_of("label").unwrap()) .context("No such key")?; print_log(binding.log().context("Failed to get log")?, false); } else { - print_log(store.log().context("Failed to get log")?, true); + print_log(mapping.log().context("Failed to get log")?, true); } }, _ => unreachable!(), @@ -463,13 +463,13 @@ fn real_main() -> Result<(), failure::Error> { }, ("list", Some(m)) => { match m.subcommand() { - ("stores", Some(m)) => { + ("mappings", Some(m)) => { let mut table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); table.set_titles(row!["realm", "name", "network policy"]); for (realm, name, network_policy, _) - in Store::list(&ctx, m.value_of("prefix").unwrap_or(""))? { + in Mapping::list(&ctx, m.value_of("prefix").unwrap_or(""))? { table.add_row(Row::new(vec![ Cell::new(&realm), Cell::new(&name), @@ -480,9 +480,9 @@ fn real_main() -> Result<(), failure::Error> { table.printstd(); }, ("bindings", Some(m)) => { - for (realm, name, _, store) - in Store::list(&ctx, m.value_of("prefix").unwrap_or(""))? { - list_bindings(&store, &realm, &name)?; + for (realm, name, _, mapping) + in Mapping::list(&ctx, m.value_of("prefix").unwrap_or(""))? { + list_bindings(&mapping, &realm, &name)?; } }, ("keys", Some(_)) => { @@ -490,7 +490,7 @@ fn real_main() -> Result<(), failure::Error> { table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); table.set_titles(row!["fingerprint", "updated", "status"]); - for (fingerprint, key) in Store::list_keys(&ctx)? { + for (fingerprint, key) in store::Pool::list_keys(&ctx)? { let stats = key.stats() .context("Failed to get key stats")?; table.add_row(Row::new(vec![ @@ -507,7 +507,7 @@ fn real_main() -> Result<(), failure::Error> { table.printstd(); }, ("log", Some(_)) => { - print_log(Store::server_log(&ctx)?, true); + print_log(store::Pool::server_log(&ctx)?, true); }, _ => unreachable!(), } @@ -573,18 +573,20 @@ fn real_main() -> Result<(), failure::Error> { return Ok(()) } -fn list_bindings(store: &Store, realm: &str, name: &str) -> Result<(), failure::Error> { - if store.iter()?.count() == 0 { - println!("No label-key bindings in the \"{}/{}\" store.", realm, name); +fn list_bindings(mapping: &Mapping, realm: &str, name: &str) + -> Result<(), failure::Error> { + if mapping.iter()?.count() == 0 { + println!("No label-key bindings in the \"{}/{}\" mapping.", + realm, name); return Ok(()); } - println!("Realm: {:?}, store: {:?}:", realm, name); + println!("Realm: {:?}, mapping: {:?}:", realm, name); let mut table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); table.set_titles(row!["label", "fingerprint"]); - for (label, fingerprint, _) in store.iter()? { + for (label, fingerprint, _) in mapping.iter()? { table.add_row(Row::new(vec![ Cell::new(&label), Cell::new(&fingerprint.to_string())])); diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs index 0ff166fe..f477281a 100644 --- a/tool/src/sq_cli.rs +++ b/tool/src/sq_cli.rs @@ -14,11 +14,11 @@ pub fn build() -> App<'static, 'static> { .arg(Arg::with_name("home").value_name("DIRECTORY") .long("home") .help("Sets the home directory to use")) - .arg(Arg::with_name("store").value_name("STORE") - .long("store") - .short("s") + .arg(Arg::with_name("mapping").value_name("MAPPING") + .long("mapping") + .short("m") .default_value("org.sequoia-pgp.contacts/default") - .help("Sets the realm and store to use")) + .help("Sets the realm and mapping to use")) .arg(Arg::with_name("policy").value_name("NETWORK-POLICY") .long("policy") .short("p") @@ -284,12 +284,12 @@ pub fn build() -> App<'static, 'static> { .about("Sends a key") .arg(Arg::with_name("input").value_name("FILE") .help("Sets the input file to use")))) - .subcommand(SubCommand::with_name("store") + .subcommand(SubCommand::with_name("mapping") .display_order(30) - .about("Interacts with key stores") + .about("Interacts with key mappings") .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand(SubCommand::with_name("list") - .about("Lists keys in the store")) + .about("Lists keys in the mapping")) .subcommand(SubCommand::with_name("add") .about("Add a key identified by fingerprint") .arg(Arg::with_name("label").value_name("LABEL") @@ -319,10 +319,10 @@ pub fn build() -> App<'static, 'static> { .short("B") .help("Don't ASCII-armor encode the OpenPGP data"))) .subcommand(SubCommand::with_name("delete") - .about("Deletes bindings or stores") - .arg(Arg::with_name("the-store") - .long("the-store") - .help("Delete the selected store (change with --store)")) + .about("Deletes bindings or mappings") + .arg(Arg::with_name("the-mapping") + .long("the-mapping") + .help("Delete the selected mapping (change with --mapping)")) .arg(Arg::with_name("label") .value_name("LABEL") .help("Delete binding with this label"))) @@ -337,16 +337,16 @@ pub fn build() -> App<'static, 'static> { .value_name("LABEL") .help("List messages related to this label")))) .subcommand(SubCommand::with_name("list") - .about("Lists key stores and known keys") + .about("Lists key mappings and known keys") .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand(SubCommand::with_name("stores") - .about("Lists key stores") + .subcommand(SubCommand::with_name("mappings") + .about("Lists key mappings") .arg(Arg::with_name("prefix").value_name("PREFIX") - .help("List only stores with the given realm prefix"))) + .help("List only mappings with the given realm prefix"))) .subcommand(SubCommand::with_name("bindings") - .about("Lists all bindings in all key stores") + .about("Lists all bindings in all key mappings") .arg(Arg::with_name("prefix").value_name("PREFIX") - .help("List only bindings from stores with the given realm prefix"))) + .help("List only bindings from mappings with the given realm prefix"))) .subcommand(SubCommand::with_name("keys") .about("Lists all keys in the common key pool")) .subcommand(SubCommand::with_name("log") |