gpgme

gpgme_op_export_keys Invalid value


I am stuck with debugging gpgme. When I turn the loglevel up to 9 i get the exact location where the error occurs.

GPGME 2017-06-02 16:25:42 <0x3968>  gpgme_op_export_keys: enter: ctx=08A19D68, mode=0x10, keydata=089C4578
GPGME 2017-06-02 16:25:42 <0x3968>  gpgme_op_export_keys: check: ctx=08A19D68, keys[0] = 089C4190 (9E799EB266729E930BE7A22B7650B73C8AD5436D)
GPGME 2017-06-02 16:25:42 <0x3968>  gpgme_op_export_keys: error: Invalid value <GPGME>

I have a c++ library that uses gpgme. When I use the library in a Boost.Test application the error does not occur. When I use the library in a C# application the error occurs.

What I am doing is exporting a private ascii armored key from my keyring. It is always the same fingerprint. Where can I go from here, are there things I need to validate on gpgme to find differences?


EDIT: I have additional information about that problem. I redistribute some gpgme files with my application. Namely: libassuan-0.dll, libgpg-error-0.dll, libgpgme-11.dll.

When I instead copy my whole installation into the same folder the same calls run without an error.

This leads me to believe that there is a background setup running when i load the libraries. Reading the dokumentation for gpgme_set_global_flag i can see that there are some entries that refere to gpgconf.

What do I need to export in order to allow to run my application with the prosper configuration?

EDIT 2: The gpgme.log differs from a succesful run to a failed run in the temprorary folder creation.

good:

_gpgme_io_spawn: check: path=00444FB8, CreateProcess ready: hProcess=000005D0, hThread=000005CC, dwProcessID=6184, dwThreadId=16268

bad:

_gpgme_io_spawn: check: path=001850E8, CreateProcess failed: ec=87

Both folders follow about the same naming scheme. I am unsure what is failing here.

EDIT: I am slowly driven into insanity. The setup seems non deterministic. Occasionally setup functions as expected. Occasionally it does not. I made sure I have the latest libraries - installed gpg4win and copied the libraries from there - now the debug log does either not show debug entries or gpg stopped looking for paths all together. It now fails at a later stage when I try to use OpenPGP. I recon the reason is still the same.


Solution

  • The path of the standard installation contains spaces.

    C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
    

    It appears as if that is not properly handled by gpgme. It looks like the path is not wrapped for a CreateProcess call.

    As a hotfix I added gpgconf.exe to the execution path of my custom client.

    gpgme has a detection for that file that looks in this path first.

    This way when CreateProcess is invoked there are no spaces in the path and the call succeeds.

    It is only a hotfix since my customer now needs to be sure he does not install my application in a path with spaces.


    EDIT: unmarked it again. It worked for a short while and now gpgme has stopped calling gpgconf.exe. So naturally now there is a different bug.


    ....and now everything is suddently fine again.

    So I guess the only correct solution with a falkey experience is to throw the whole thing out the window.