From def9e45affaf5212cd10b71a55f0b668f2e73ee4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 5 Jan 2012 16:34:51 -0600 Subject: Search for PGP subkeys in a keyserver-acceptable way PGP keyservers are pieces of sh** when it comes to searching for subkeys, and only allow it if you submit an 8-character fingerprint rather than the recommended and less chance of collision 16-character fingerprint. Add a second remote lookup for the 8-character version of a key ID if we don't find anything the first time we look up the key. This fixes FS#27612 and the deficiency has been sent upstream to the GnuPG users mailing list as well. Signed-off-by: Dan McGee --- lib/libalpm/signing.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index 92f34b56..1a53deaa 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -251,10 +251,24 @@ static int key_search(alpm_handle_t *handle, const char *fpr, err = gpgme_get_key(ctx, fpr, &key, 0); if(gpg_err_code(err) == GPG_ERR_EOF) { _alpm_log(handle, ALPM_LOG_DEBUG, "key lookup failed, unknown key\n"); - ret = 0; - goto error; - } else if(gpg_err_code(err) != GPG_ERR_NO_ERROR) { - _alpm_log(handle, ALPM_LOG_DEBUG, "gpg error: %s\n", gpgme_strerror(err)); + /* Try an alternate lookup using the 8 character fingerprint value, since + * busted-ass keyservers can't support lookups using subkeys with the full + * value as of now. This is why 2012 is not the year of PGP encryption. */ + if(strlen(fpr) > 8) { + const char *short_fpr = fpr + strlen(fpr) - 8; + _alpm_log(handle, ALPM_LOG_DEBUG, + "looking up key %s remotely\n", short_fpr); + err = gpgme_get_key(ctx, short_fpr, &key, 0); + if(gpg_err_code(err) == GPG_ERR_EOF) { + _alpm_log(handle, ALPM_LOG_DEBUG, "key lookup failed, unknown key\n"); + ret = 0; + } + } else { + ret = 0; + } + } + + if(gpg_err_code(err) != GPG_ERR_NO_ERROR) { goto error; } @@ -270,9 +284,11 @@ static int key_search(alpm_handle_t *handle, const char *fpr, pgpkey->email = key->uids->email; pgpkey->created = key->subkeys->timestamp; pgpkey->expires = key->subkeys->expires; - ret = 1; + gpgme_release(ctx); + return 1; error: + _alpm_log(handle, ALPM_LOG_DEBUG, "gpg error: %s\n", gpgme_strerror(err)); gpgme_release(ctx); return ret; } -- cgit v1.2.3-70-g09d2 From a1437cbf1bccc025d33e083e1a79e85c57c6e2df Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 5 Jan 2012 16:48:21 -0600 Subject: Remove useless logger message We don't need two log messages back-to-back about the same thing here. Signed-off-by: Dan McGee --- lib/libalpm/remove.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 44f3ee93..41cee514 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -461,7 +461,6 @@ int _alpm_remove_single_package(alpm_handle_t *handle, db: /* remove the package from the database */ - _alpm_log(handle, ALPM_LOG_DEBUG, "updating database\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "removing database entry '%s'\n", pkgname); if(_alpm_local_db_remove(handle->db_local, oldpkg) == -1) { _alpm_log(handle, ALPM_LOG_ERROR, _("could not remove database entry %s-%s\n"), -- cgit v1.2.3-70-g09d2