summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-12-09 13:40:45 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-12-09 13:40:45 +0100
commit1b0bcd18d0c0cb9980636f56ce1e03f35c827f16 (patch)
tree0d549ba9cff005f72fae518df874e2c2dfb59fdb
parent172955fe39e7b800e06c63ac4ad9bc7d1ed84c56 (diff)
sq: Implement searching hkp servers by email address.
- Fixes #389.
-rw-r--r--sq/src/sq-usage.rs2
-rw-r--r--sq/src/sq.rs42
-rw-r--r--sq/src/sq_cli.rs6
3 files changed, 33 insertions, 17 deletions
diff --git a/sq/src/sq-usage.rs b/sq/src/sq-usage.rs
index 1e232f26..db5e559d 100644
--- a/sq/src/sq-usage.rs
+++ b/sq/src/sq-usage.rs
@@ -323,7 +323,7 @@
//! -o, --output <FILE> Sets the output file to use
//!
//! ARGS:
-//! <QUERY> Fingerprint or KeyID of the key to retrieve
+//! <QUERY> Fingerprint, KeyID, or email address of the cert(s) to retrieve
//! ```
//!
//! ### Subcommand keyserver send
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index 266a8bd8..d75c2cae 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -22,6 +22,7 @@ use openpgp::{
Fingerprint,
KeyID,
KeyHandle,
+ packet::UserID,
};
use crate::openpgp::{armor, Cert};
use sequoia_autocrypt as autocrypt;
@@ -444,22 +445,35 @@ fn main() -> Result<()> {
}
};
- if handle.is_none() {
- Err(anyhow::anyhow!(
- "Malformed key handle: {:?}\n\
- (Note: only Fingerprints long KeyIDs are \
- supported.)", query))?;
- }
- let handle = handle.unwrap();
+ if let Some(handle) = handle {
+ let cert = rt.block_on(ks.get(handle))
+ .context("Failed to retrieve cert")?;
- let mut output = create_or_stdout(m.value_of("output"), force)?;
- let cert = rt.block_on(ks.get(handle))
- .context("Failed to retrieve key")?;
- if ! m.is_present("binary") {
- cert.armored().serialize(&mut output)
+ let mut output =
+ create_or_stdout(m.value_of("output"), force)?;
+ if ! m.is_present("binary") {
+ cert.armored().serialize(&mut output)
+ } else {
+ cert.serialize(&mut output)
+ }.context("Failed to serialize cert")?;
+ } else if let Ok(Some(addr)) = UserID::from(query).email() {
+ let certs = rt.block_on(ks.search(addr))
+ .context("Failed to retrieve certs")?;
+
+ let mut output =
+ create_or_stdout_pgp(m.value_of("output"), force,
+ m.is_present("binary"),
+ armor::Kind::PublicKey)?;
+ for cert in certs {
+ cert.serialize(&mut output)
+ .context("Failed to serialize cert")?;
+ }
+ output.finalize()?;
} else {
- cert.serialize(&mut output)
- }.context("Failed to serialize key")?;
+ Err(anyhow::anyhow!(
+ "Query must be a fingerprint, a keyid, \
+ or an email address: {:?}", query))?;
+ }
},
("send", Some(m)) => {
let mut input = open_or_stdin(m.value_of("input"))?;
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index c4c8fd73..9c56154b 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -304,8 +304,10 @@ pub fn build() -> App<'static, 'static> {
.help("Don't ASCII-armor encode the OpenPGP data"))
.arg(Arg::with_name("query").value_name("QUERY")
.required(true)
- .help("Fingerprint or KeyID of the key \
- to retrieve")))
+ .help(
+ "Fingerprint, KeyID, or email \
+ address of the cert(s) to retrieve"
+ )))
.subcommand(SubCommand::with_name("send")
.about("Sends a key")
.arg(Arg::with_name("input").value_name("FILE")