gpgme cannot list keys (gpgme 1.6, FreeBSD)

Andreas Sommer andreas.sommer87 at googlemail.com
Mon Jan 4 09:42:59 CET 2016


Hi all,

I've only started using gpgme today and am getting an unknown error status 117456895 (= hex 0x7003fff) from gpgme_op_keylist_next, for which gpgme_strerror_r outputs "End of file". My use case is to first find the recipient key by e-mail address, then encrypt some data. Find attached the error log gpgme.log, as created with `GPGME_DEBUG=9:/tmp/log myprogram`.

Running the same command line as shown in the logs (without --status-fd) works fine:

> $ gpg2 --batch --no-sk-comments --no-tty --charset utf8 --enable-progress-filter --with-colons --fixed-list-mode --with-fingerprint --list-keys --
> gpg: Warning: using insecure memory!
> tru::1:1450870578:0:3:1:5

This is on FreeBSD 10.1-RELEASE with gpgme 1.6 installed as package.

Pseudocode (I'm actually wrapping using C++):

> gpgme_check_version(NULL);
> gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
> gpgme_ctx_t ctx;
> gpgme_new(&ctx);
> 
> // These don't matter, mostly defaults anyway
> gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP);
> gpgme_set_keylist_mode(ctx, GPGME_KEYLIST_MODE_LOCAL);
> gpgme_set_armor(ctx, 1);
> gpgme_set_textmode(ctx, 0);
> //gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, NULL, "/home/asommer/.gnupg");
> 
> gpgme_op_keylist_start(ctx, NULL, 0);
> gpgme_key_t key = NULL;
> auto res = gpgme_op_keylist_next(ctx, &key); // returns 117456895 and key is NULL

So I'm doing the same thing as other examples. To dig deeper, I created a pure C example for me/you to test (see attached gpgme-example.c). It works fine on Mac OS X (displays my public key), but not in my FreeBSD 10.1 VM ("Error in res: res=-5232: Unknown system error"). On FreeBSD 9.1, the error is "Error in res: res=-9472: Unknown system error". Both logs are attached.

OSX: gpg2 version 2.0.29, libgcrypt 1.6.4
FreeBSD 10.1: gpg2 version 2.1.8, libgcrypt 1.6.3
FreeBSD 9.1: gpg2 version 2.1.6, libgcrypt 1.6.3

Anything else to try? Does it work for anyone?

Thank you very much,
 Andreas Sommer

-------------- next part --------------
// clang -o gpgme-example gpgme-example.c -lgpgme -I /usr/local/include/ -L /usr/local/lib/ && GPGME_DEBUG=9:/tmp/gpgme-example.log ./gpgme-example
#ifdef __FreeBSD__
#include <gpgme/gpgme.h>
#else
#include <gpgme.h>
#endif

// Just a stupid example
#define check(expr) \
    { \
        printf("check %s\n", #expr); \
        gpgme_error_t res = (expr); \
        if (res != GPG_ERR_NO_ERROR) \
        { \
            printf("Error in %s: res=%d: %s\n", #expr, res, gpgme_strerror(res)); \
            return 1; \
        } \
    }

int main()
{
    gpgme_check_version(NULL);
    check(gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP));
    gpgme_ctx_t ctx;
    check(gpgme_new(&ctx));

    // These don't matter, mostly defaults anyway
    check(gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP));
    check(gpgme_set_keylist_mode(ctx, GPGME_KEYLIST_MODE_LOCAL));
    gpgme_set_armor(ctx, 1);
    gpgme_set_textmode(ctx, 0);
    //check(gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, NULL, "/home/asommer/.gnupg"));

    check(gpgme_op_keylist_start(ctx, NULL, 0));
    gpgme_key_t key = NULL;
    gpgme_error_t res = gpgme_op_keylist_next(ctx, &key); // returns 117456895 and key is NULL
    if (res == GPG_ERR_EOF)
    {
        printf("No more keys (expected error)\n");
    }
    else
    {
        check(res);

        printf("Found key: %s\n", key->uids->email);
    }

    return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logs.tgz
Type: application/x-gzip
Size: 5953 bytes
Desc: not available
URL: </pipermail/attachments/20160104/daa3cf8f/attachment.bin>


More information about the Gnupg-devel mailing list