GPGME: looking for keys with respect to user settings

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


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,


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_new (&ctx);

     const char* pattern[] = { "wiktor at", 0 };
// uncommenting will explicitly enable WKD
// commented out like that will always use LOCAL
//   gpgme_set_keylist_mode(ctx, GPGME_KEYLIST_MODE_LOCAL | 
     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);


     return 0;


More information about the Gnupg-devel mailing list