summaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2018-06-25 09:38:09 +0200
committerNeal H. Walfield <neal@pep.foundation>2018-06-25 09:38:09 +0200
commitc0e4617c1a7080f11b4407dce942a3bc730291b3 (patch)
treeb223d77e01717353c1c738fd81a0b960a38cf33d /tool
parentcd982a0d8773f163bc12a96b8d07e741e2f805a8 (diff)
openpgp: Add support for parsing Autocrypt headers.
- Also implement 'sq autocrypt decode' to convert an autocrypt header to an OpenPGP key.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/cli.rs12
-rw-r--r--tool/src/sq-usage.rs35
-rw-r--r--tool/src/sq.rs23
3 files changed, 69 insertions, 1 deletions
diff --git a/tool/src/cli.rs b/tool/src/cli.rs
index eb1f4004..098aa6e8 100644
--- a/tool/src/cli.rs
+++ b/tool/src/cli.rs
@@ -83,6 +83,18 @@ pub fn build() -> App<'static, 'static> {
.long("output")
.short("o")
.help("Sets the output file to use")))
+ .subcommand(SubCommand::with_name("autocrypt")
+ .about("Autocrypt support")
+ .subcommand(SubCommand::with_name("decode")
+ .about("Converts Autocrypt-encoded keys to OpenPGP TPKs")
+ .arg(Arg::with_name("input").value_name("FILE")
+ .long("input")
+ .short("i")
+ .help("Sets the input file to use"))
+ .arg(Arg::with_name("output").value_name("FILE")
+ .long("output")
+ .short("o")
+ .help("Sets the output file to use"))))
.subcommand(SubCommand::with_name("dump")
.about("Lists OpenPGP packets")
.arg(Arg::with_name("input").value_name("FILE")
diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs
index f6e4220d..37a0c7cd 100644
--- a/tool/src/sq-usage.rs
+++ b/tool/src/sq-usage.rs
@@ -18,6 +18,7 @@
//! -s, --store <STORE> Sets the store to use (default: 'default')
//!
//! SUBCOMMANDS:
+//! autocrypt Autocrypt support
//! dearmor Removes ASCII Armor from a file
//! decrypt Decrypts an OpenPGP message
//! dump Lists OpenPGP packets
@@ -30,6 +31,40 @@
//! store Interacts with key stores
//! ```
//!
+//! ## Subcommand autocrypt
+//!
+//! ```text
+//! Autocrypt support
+//!
+//! USAGE:
+//! sq autocrypt [SUBCOMMAND]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! SUBCOMMANDS:
+//! decode Converts Autocrypt-encoded keys to OpenPGP TPKs
+//! help Prints this message or the help of the given subcommand(s)
+//! ```
+//!
+//! ### Subcommand autocrypt decode
+//!
+//! ```text
+//! Converts Autocrypt-encoded keys to OpenPGP TPKs
+//!
+//! USAGE:
+//! sq autocrypt decode [OPTIONS]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! OPTIONS:
+//! -i, --input <FILE> Sets the input file to use
+//! -o, --output <FILE> Sets the output file to use
+//! ```
+//!
//! ## Subcommand dearmor
//!
//! ```text
diff --git a/tool/src/sq.rs b/tool/src/sq.rs
index 738b291d..5ecf8a7d 100644
--- a/tool/src/sq.rs
+++ b/tool/src/sq.rs
@@ -20,7 +20,7 @@ extern crate sequoia_core;
extern crate sequoia_net;
extern crate sequoia_store;
-use openpgp::{armor, Fingerprint, TPK};
+use openpgp::{armor, autocrypt, Fingerprint, TPK};
use sequoia_core::{Context, NetworkPolicy};
use sequoia_net::KeyServer;
use sequoia_store::{Store, LogIter};
@@ -101,6 +101,27 @@ fn real_main() -> Result<(), failure::Error> {
let mut filter = armor::Reader::new(&mut input, armor::Kind::Any);
io::copy(&mut filter, &mut output)?;
},
+ ("autocrypt", Some(m)) => {
+ match m.subcommand() {
+ ("decode", Some(m)) => {
+ let mut input = open_or_stdin(m.value_of("input"))?;
+ let mut output = create_or_stdout(m.value_of("output"))?;
+ let ac = autocrypt::AutocryptHeaders::from_reader(input)?;
+ for h in &ac.headers {
+ if let Some(ref tpk) = h.key {
+ let mut filter = armor::Writer::new(
+ &mut output, armor::Kind::PublicKey);
+ tpk.serialize(&mut filter)?;
+ }
+ }
+ }
+ _ => {
+ eprintln!("No autocrypt subcommand given.");
+ exit(1);
+ }
+ }
+ },
+
("dump", Some(m)) => {
let input = open_or_stdin(m.value_of("input"))?;
let mut output = create_or_stdout(m.value_of("output"))?;