summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjuga <juga@sequoia-pgp.org>2019-05-24 11:41:32 +0000
committerjuga <juga@sequoia-pgp.org>2019-05-28 11:29:02 +0000
commit941502b44228d921e2c4383dc58b44aa2dd431fe (patch)
treeb2cef356439adb6c6956140ecaa1c21407dd861e
parent32795158e702c70d000b0f48d221950050bd5c2a (diff)
tool: Add wkd command and get, url subcommands
- Using the wkd client implemented in the wkd module. - Fixes #251.
-rw-r--r--tool/src/sq-usage.rs45
-rw-r--r--tool/src/sq.rs32
-rw-r--r--tool/src/sq_cli.rs21
3 files changed, 97 insertions, 1 deletions
diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs
index f3159937..9902d0a0 100644
--- a/tool/src/sq-usage.rs
+++ b/tool/src/sq-usage.rs
@@ -34,6 +34,7 @@
//! key Manipulates keys
//! list Lists key stores and known keys
//! packet OpenPGP Packet manipulation
+//! wkd Interacts with Web Key Directories
//! ```
//!
//! ## Subcommand decrypt
@@ -625,5 +626,49 @@
//! ARGS:
//! <FILE> Sets the input file to use
//! ```
+//! ## Subcommand wkd
+//! ```text
+//! Interacts with Web Key Directories
+//!
+//! USAGE:
+//! sq wkd [SUBCOMMAND]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! SUBCOMMANDS:
+//! get Writes to the standard output the Transferable Public Key retrieved from a Web Key Directory, given an email address
+//! help Prints this message or the help of the given subcommand(s)
+//! url Prints the Web Key Directory URI of an email address.
+//! ```
+//! ### Subcommand wkd url
+//! ```text
+//! Prints the Web Key Directory URI of an email address
+//!
+//! USAGE:
+//! sq wkd url [EMAIL_ADDRESS]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! ARGS:
+//! <EMAIL_ADDRESS> The email address from which to obtain the WKD URI.
+//! ```
+//! ### Subcommand wkd get
+//! ```text
+//!
+//! Writes to the standard output the Transferable Public Key retrieved from a Web Key Directory, given an email address
+//! USAGE:
+//! sq wkd get [EMAIL_ADDRESS]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! ARGS:
+//! <EMAIL_ADDRESS> The email address from which to obtain the TPK from a WKD.
+//! ```
include!("sq.rs");
diff --git a/tool/src/sq.rs b/tool/src/sq.rs
index 83235bb7..3fa9ea6a 100644
--- a/tool/src/sq.rs
+++ b/tool/src/sq.rs
@@ -27,7 +27,7 @@ use openpgp::conversions::hex;
use openpgp::parse::Parse;
use openpgp::serialize::Serialize;
use sequoia_core::{Context, NetworkPolicy};
-use sequoia_net::KeyServer;
+use sequoia_net::{KeyServer, wkd};
use sequoia_store::{Store, LogIter};
mod sq_cli;
@@ -459,6 +459,36 @@ fn real_main() -> Result<(), failure::Error> {
("generate", Some(m)) => commands::key::generate(m, force)?,
_ => unreachable!(),
},
+ ("wkd", Some(m)) => {
+ match m.subcommand() {
+ ("url", Some(m)) => {
+ let email_address = m.value_of("input").unwrap();
+ let wkd_url = wkd::Url::from(email_address)?;
+ // XXX: Add other subcomand to specify whether it should be
+ // created with the advanced or the direct method.
+ let url = wkd_url.to_url(None)?;
+ println!("{}", url);
+ },
+ ("get", Some(m)) => {
+ let email_address = m.value_of("input").unwrap();
+ // XXX: EmailAddress could be created here to
+ // check it's a valid email address, print the error to
+ // stderr and exit.
+ // Because it might be created a WkdServer struct, not
+ // doing it for now.
+ let tpks = wkd::get(&email_address)?;
+ // This is different to `store export` and `keyserver get`,
+ // Since the output is always bytes.
+ // XXX: Still give the possibility to write to a file.
+ let mut output = create_or_stdout(m.value_of("output"), force)?;
+
+ for tpk in tpks {
+ tpk.serialize(&mut output)?;
+ }
+ },
+ _ => unreachable!(),
+ }
+ },
_ => unreachable!(),
}
diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs
index 51f78468..535d5b22 100644
--- a/tool/src/sq_cli.rs
+++ b/tool/src/sq_cli.rs
@@ -433,4 +433,25 @@ pub fn build() -> App<'static, 'static> {
.help("Sets the prefix to use for output files \
(defaults to the input filename with a dash, \
or 'output')"))))
+
+ .subcommand(SubCommand::with_name("wkd")
+ .about("Interacts with Web Key Directories")
+ .setting(AppSettings::ArgRequiredElseHelp)
+ .subcommand(SubCommand::with_name("url")
+ .about("Prints the Web Key Directory URl of \
+ an email address.")
+ .arg(Arg::with_name("input")
+ .value_name("EMAIL_ADDRESS")
+ .help("The email address from which to \
+ obtain the WKD URI.")))
+ .subcommand(SubCommand::with_name("get")
+ .about("Writes to the standard output the \
+ Transferable Public Key retrieved \
+ from a Web Key Directory, given an \
+ email address")
+ .arg(Arg::with_name("input")
+ .value_name("EMAIL_ADDRESS")
+ .help("The email address from which to \
+ obtain the TPK from a WKD.")))
+ )
}