Key generation with GPGME and GnuPG hangs at gpgme_op_genkey

Sandra Schreiner sasc0041 at stud.hs-kl.de
Tue Jan 26 09:54:17 CET 2016


Hello,

This is my first message to an e-mail list ever. I don't even know if this is the right e-mail list for me, please forgive me if I'm wrong, but unfortunately I didn't found a GPGME e-mail list.
Currently I'm trying to use GPGME in my C++ application with GnuPG for key-management and encryption. Sadly I'm not able to create a new key, because my code hangs at gpgme_op_genkey. I have gpg 1.4.18 and gpg2 2.0.26 and GPGME 1.5.1 on my 64 bit Debian VM system (version Jesse) available. This is how I initialize the library:

    gpgme_engine_info_t info;
    gpgme_error_t  error;
    const char * CONFIG_DIR = "/";

    // Initializes gpgme
    gpgme_check_version(NULL);

    // Initialize the locale environment.
    setlocale(LC_ALL, "");
    gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
#ifdef LC_MESSAGES
    gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
#endif
    error = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, NULL,
                                  CONFIG_DIR);
    if(error)
        return false;
    error = gpgme_new(&mContext);
    if(error)
        return false;
    // Check OpenPGP
    error = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
    if(error)
        return false;
    // load engine info
    error = gpgme_get_engine_info(&info);
    if(error)
        return false;
    while(info && info->protocol != gpgme_get_protocol(mContext)) {
        info = info->next;
    }
    // set path to our config file
    error = gpgme_ctx_set_engine_info(mContext, GPGME_PROTOCOL_OpenPGP, NULL,
                                      CONFIG_DIR);
    if(error)
        return false;

-----------------------------------------------------------------------------------------------------------------------------
Here I try to create the key:

     std::string def = "<GnupgKeyParms format=\"internal\"> \n"
                              " Key-Type: default \n"
                              " Subkey-Type: default \n"
                              " Name-Real: Joe Tester3 \n"
                              " Name-Comment: with stupid passphrase \n"
                              " Name-Email: joe3 at foo.bar \n"
                              " Expire-Date: 0 \n"
                              " Passphrase: abc \n"
                              " </GnupgKeyParms> \n";

            gpgme_error_t error = gpgme_op_genkey(mContext, def.c_str(), NULL, NULL);

            if(GPG_ERR_INV_VALUE  == gpgme_err_code(error)){
                std::cout << "Value error";
            }
            if(GPG_ERR_NOT_SUPPORTED == gpgme_err_code(error)){
                std::cout << "Not supported error";
            }
            if(GPG_ERR_GENERAL  ==  gpgme_err_code(error)){
                std::cout << "general error";
            }
            if(error == gpgme_err_code(GPG_ERR_NO_ERROR)){
                gpgme_genkey_result_t res = gpgme_op_genkey_result(mContext);
                if(res->primary && res->sub){
                    result = true;
                }
            }
There is no error while initialising the library, so I don't know why it stops at gpgme_op_genkey. Maybe GnuPG is trying to collect entropie? If I generate a key using the GnuPG command line it tooks a very long time to collect entropie. But after ~15 minutes the key generation completes successfully (I didn't noticed that my program finished so far, even after 15 minutes+). I already tried to remove the \n in each line, but I received a general error in this case. Am I doing something wrong? Any help or hint is highly appreciated.

Best regards,
Sandra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20160126/2adfe143/attachment-0001.html>


More information about the Gnupg-users mailing list