8000 fix(pgp): ask keys.openpgp.org when gpg's keyserver has no key by hanthor · Pull Request #690 · hyprlab/hylki · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

- **Fixed: Fetch the sender's key found nothing for many addresses.** gpg
asks only the keyserver it is set up with, keyserver.ubuntu.com by
default, which lacks many keys (edward-en@fsf.org's among them). When WKD
and that keyserver find nothing, Hylki now asks keys.openpgp.org too, both
for **Fetch the sender's key** and for **Fetch by address…**.

- **New: contacts picked from the mail** (#677, requested by
DarkStarCrashes123). **From Mail…** in the Contacts view's import menu
lists everyone in the cached mail who is not a contact yet, with how many
Expand Down
3 changes: 2 additions & 1 deletion docs/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,8 @@ signature. There are four ways to get one, none of which need a terminal:
- A signed message from someone whose key you don't have shows an amber shield
beside their name. Click it and choose **Fetch the sender's key**. Hylki
looks in the message itself first (many clients attach the key in an
Autocrypt header), then asks the sender's provider (WKD), then the keyservers.
Autocrypt header), then asks the sender's provider (WKD), then gpg's
keyserver, and keys.openpgp.org when that has nothing.
A key from the message's Autocrypt header is taken only when the header
names the sender's own address, and it goes into Hylki's own keyring of
found keys, never yours (see below).
Expand Down
62 changes: 39 additions & 23 deletions src/mail/pgp/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,43 +456,59 @@ pub(crate) fn generate_key(
.unwrap_or_else(|| i18n("gpg did not create the key.")))
}

/// The keyserver asked when gpg's own finds nothing: keys.openpgp.org
/// lists a key under an address only once its owner proved the address,
/// and holds many that gpg's default (keyserver.ubuntu.com) lacks.
const FALLBACK_KEYSERVER: &str = "hkps://keys.openpgp.org";

/// Look a key up by address (WKD, then the keyservers), and by key id
/// when the message named one, importing what is found.
/// when the message named one, importing what is found. What gpg's own
/// keyserver lacks is asked of [`FALLBACK_KEYSERVER 8000 `].
pub(crate) fn fetch_key(
gpg: &Gpg,
addr: &str,
key_id: Option<&str>,
) -> Result<ImportSummary, String> {
let mut total = ImportSummary::default();
let mut detail = None;
if !addr.trim().is_empty() {
let out = run(
gpg,
&[
"--auto-key-locate",
"clear,wkd,keyserver",
"--locate-external-keys",
addr.trim(),
],
b"",
None,
);
total.add(import_summary(&out));
detail = out.detail;
}
if total.fingerprints.is_empty() {
if let Some(id) = key_id.filter(|k| !k.is_empty()) {
let out = run(gpg, &["--recv-keys", id], b"", None);
let addr = addr.trim();
let key_id = key_id.filter(|k| !k.is_empty());
for keyserver in [None, Some(FALLBACK_KEYSERVER)] {
let mut base: Vec<&str> = Vec::new();
if let Some(server) = keyserver {
base.extend(["--keyserver", server]);
}
if !addr.is_empty() {
// WKD asks the address's own domain: once is enough.
let locate = if keyserver.is_some() {
"clear,keyserver"
} else {
"clear,wkd,keyserver"
};
let mut args = base.clone();
args.extend(["--auto-key-locate", locate, "--locate-external-keys", addr]);
let out = run(gpg, &args, b"", None);
total.add(import_summary(&out));
if out.detail.is_some() {
detail = out.detail;
}
}
if total.fingerprints.is_empty() {
if let Some(id) = key_id {
let mut args = base;
args.extend(["--recv-keys", id]);
let out = run(gpg, &args, b"", None);
total.add(import_summary(&out));
if out.detail.is_some() {
detail = out.detail;
}
}
}
if !total.fingerprints.is_empty() {
return Ok(total);
}
}
if total.fingerprints.is_empty() {
return Err(detail.unwrap_or_else(|| i18n("No key was found for that address.")));
}
Ok(total)
Err(detail.unwrap_or_else(|| i18n("No key was found for that address.")))
}

/// Vouch for a key: a local (non-exportable) signature with one of the
Expand Down
0