GPGME: looking for keys with respect to user settings

Wiktor Kwapisiewicz wiktor at metacode.biz
Fri Jul 6 21:49:56 CEST 2018


Hello,

I'm trying to replicate `gpg --locate-keys $EMAIL` using GPGME and have 
one question.

I'm using `gpgme_op_keylist_ext_start` for starting the search and want 
to search using whatever is configured in gpg.conf or defaults.

`gpgme_set_keylist_mode` [0] seems to take several flags such as 
GPGME_KEYLIST_MODE_LOCATE but it's a combination of LOCAL and EXTERN 
search (in case of e-mail address that would be WKD).

If I don't specify mode it looks like it's always using LOCAL even if I 
explicitly set "auto-key-locate local,wkd" in .gnupg/gpg.conf

Is this by design that keylist_mode is not set to what is used by 
--locate-key? (that is GPGME is not using settings used by gpg)

A little bit of context: I'm trying to add WKD search in mutt (in case 
someone enables explicitly encryption and doesn't have the key locally) 
but a valid question was raised, why isn't GPGME already using what the 
user has configured in their gpg.conf.

Thanks in advance for help!

Kind regards,
Wiktor

[0]: https://www.gnupg.org/documentation/manuals/gpgme/Key-Listing-Mode.html

For the record I'm using this sample code for testing:

#include <gpgme.h>
#include <locale.h>

int main() {
     gpgme_ctx_t ctx;
     gpgme_error_t err;
     gpgme_key_t key;
     gpgme_keylist_result_t result;

     setlocale (LC_ALL, "");
     gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
     gpgme_check_version(NULL);

     gpgme_new (&ctx);

     const char* pattern[] = { "wiktor at metacode.biz", 0 };
    printf("locating\n");
// uncommenting will explicitly enable WKD
// commented out like that will always use LOCAL
//   gpgme_set_keylist_mode(ctx, GPGME_KEYLIST_MODE_LOCAL | 
GPGME_KEYLIST_MODE_EXTERN);
     gpgme_op_keylist_ext_start (ctx, pattern, 0, 0);

     while (!(err = gpgme_op_keylist_next (ctx, &key))) {
         fprintf(stdout, "Key ID: %s\n", key->subkeys->keyid);
         gpgme_key_unref (key);
     }

     gpgme_release(ctx);

     return 0;
}

-- 
https://metacode.biz/@wiktor



More information about the Gnupg-devel mailing list