summaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorjuga <juga@sequoia-pgp.org>2019-06-14 11:34:25 +0000
committerJustus Winter <justus@sequoia-pgp.org>2019-09-09 17:00:49 +0200
commitf61f57d4ad1ee45b3d6b0014bf4339a6d1469f9b (patch)
tree9ff16cf0373c044579aab6273bf5136a259d7b68 /tool
parent50c48030b2b9c7bb6ae160bb23717f68b2e7509f (diff)
tool: Add 'wkd generate' subcommand.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/sq-usage.rs32
-rw-r--r--tool/src/sq.rs17
-rw-r--r--tool/src/sq_cli.rs25
3 files changed, 71 insertions, 3 deletions
diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs
index e06ea6b5..bc012ae3 100644
--- a/tool/src/sq-usage.rs
+++ b/tool/src/sq-usage.rs
@@ -670,9 +670,35 @@
//! -V, --version Prints version information
//!
//! SUBCOMMANDS:
-//! get Writes to the standard output the TPK 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 URL of an email address.
+//! generate Generates a Web Key Directory for the given domain and keys.
+//! The owner of the directory and files will be the user that runs this command.
+//! This command only works on Unix-like systems.
+//! get Writes to the standard output the TPK 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 URL of an email address.
+//! ```
+//!
+//! ### Subcommand wkd generate
+//!
+//! ```text
+//! Generates a Web Key Directory for the given domain and keys.
+//! The owner of the directory and files will be the user that runs this command.
+//! This command only works on Unix-like systems.
+//!
+//! USAGE:
+//! sq wkd generate [FLAGS] [OPTIONS] <DOMAIN> [KEYRING]
+//!
+//! FLAGS:
+//! -d, --direct_method Use the direct method. [default: advanced method]
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! OPTIONS:
+//! -o, --output <output> The top level directory directory. [default: /var/www/html]
+//!
+//! ARGS:
+//! <DOMAIN> The domain for the WKD.
+//! <KEYRING> The keyring file with the keys to add to the WKD.
//! ```
//!
//! ### Subcommand wkd get
diff --git a/tool/src/sq.rs b/tool/src/sq.rs
index bd1d1129..e3213285 100644
--- a/tool/src/sq.rs
+++ b/tool/src/sq.rs
@@ -29,6 +29,7 @@ use crate::openpgp::conversions::hex;
use crate::openpgp::packet::KeyFlags;
use crate::openpgp::parse::Parse;
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};
@@ -544,6 +545,22 @@ fn real_main() -> Result<(), failure::Error> {
serialize_keyring(&mut output, &tpks,
m.is_present("binary"))?;
},
+ ("generate", Some(m)) => {
+ let domain = m.value_of("domain").unwrap();
+ let mut f = open_or_stdin(m.value_of("input"))?;
+ // XXX: is a bad idea to use this default dir?
+ let base_path = m.value_of("output")
+ .unwrap_or("/var/www/html");
+ let direct_method = m.is_present("direct_method");
+ let mut buffer: Vec<u8> = Vec::new();
+ f.read_to_end(&mut buffer)?;
+ let parser = TPKParser::from_bytes(&buffer)?;
+ let tpks: Vec<TPK> = parser.filter_map(|tpk| tpk.ok())
+ .collect();
+ wkd::generate(domain, &tpks, &base_path, direct_method)
+ .context(format!("Failed to generate the WKD in {}.",
+ base_path))?;
+ }
_ => unreachable!(),
}
},
diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs
index 9ec8ca8e..126fb363 100644
--- a/tool/src/sq_cli.rs
+++ b/tool/src/sq_cli.rs
@@ -501,5 +501,30 @@ pub fn build() -> App<'static, 'static> {
.long("binary")
.short("B")
.help("Don't ASCII-armor encode the OpenPGP data")))
+ .subcommand(SubCommand::with_name("generate")
+ .about("Generates a Web Key Directory for the \
+ given domain and keys.\n\
+ The owner of the directory and files will be the user \
+ that runs this command.\n\
+ This command only works on Unix-like systems.")
+ .arg(Arg::with_name("output")
+ .long("output")
+ .short("o")
+ .takes_value(true)
+ .help("The top level directory directory. \
+ [default: /var/www/html]"))
+ .arg(Arg::with_name("direct_method")
+ .long("direct_method")
+ .short("d")
+ .help("Use the direct method. \
+ [default: advanced method]"))
+ .arg(Arg::with_name("domain")
+ .value_name("DOMAIN")
+ .help("The domain for the WKD.")
+ .required(true))
+ .arg(Arg::with_name("input")
+ .value_name("KEYRING")
+ .help("The keyring file with the keys to add to the WKD."))
+ )
)
}