Page MenuHome GnuPG

better heuristic for choosing an encryption key based on a User ID
Closed, ResolvedPublic


Currently, if a user asks gpg to encrypt data to a name (as opposed to a key
ID), gpg selects the first valid key in its keyring that has a matching User ID
(regardless of the calculated validity of the User ID itself).

This is problematic in a number of use cases, and can cause potentially serious
security problems if data is encrypted to the wrong key.

A proposed new heuristic for selecting a key is:

Select the most recently-generated valid key that has a non-revoked,
non-expired encryption-capable subkey, and has a matching user ID with
the highest-available-class of calculated validity for the given User

discussion and details about the concern can be found in gnupg-users:

Event Timeline

We can implement that in 2.1 after having replaced the current keyring based DB
with the Keybox based one. The latter is far more efficient and does not
require sequential scans all the time. Some breakage will anyway happen and
thus a new selection strategy, i.e. a well defined one, won't harm either.

If a recipient has more than one key - for instance outdated keys, needed for
decryption of older messages, it is sometimes difficult or impossible to make a
mail application encrypt with the correct key. Recently I fought this one, and
got around the problem in both KMail and Thunderbird by demoting the Trust
status of the older key, but although this works it's not ideal for the
following reason.

Both mail agents have a mechanism for setting default keys for recipients, KMail
by using the recipient's addressbook record and/or by marking default keys in
KGpg, and Thunderbird by the Per-Recipient rules. When a user has set the
default using one of these he expects that new default to be used for
encryption. In fact the recipient is quite likely to find that the older key
has been used, and it may not be possible to decrypt the message - my
correspondent had a corrupt private key.

Ideally, GPG should respect the default key set in the mail-agent being used.
If that is not possible, perhaps it would be possible to make some easy-ish way
for the user to tell gpg which key should be considered default, instead of
simply taking the first record found. I could find nothing about this in the
man page.

neal claimed this task.

Comitted in a958ffd.

Whoops, I closed the wrong bug report, sorry. Reopening.

Just noticed this issue as it was mentioned in T2359 which is "my" issue
about this topic ;-)
I've actually implemented the algorithm outlined in T1143 (dkg on Sep 23 2009, 06:53 PM / Roundup) in libkleo/ QGgpME
for a better opportunistic encryption support in kmail ( )

Werner told me that something like that will be done in GnuPG itself. Afaik the
current plan is to have --locate-keys use a similar algorithm to return exactly
one "best" key if a mailbox is given. And if I understood werner correctly this
would then also be the key used when you would do a "gpg -er <mailbox>"

Should this be closed as Superseded?

werner added a project: Duplicate.

Duplicate of T2359