1

For specifying the preferenced order of encryption algorithms in GPG I use

gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, NULL, CONFIG_DIR);

to set a custom config file. However how can I check if this operation was successful? home_dir is set to the given value, but this also happens if I pass a directory without a config file. I can't see any function or call in the documentation to evaluate if the config file was loaded OR what the current preference order is.

Cœur
  • 37,241
  • 25
  • 195
  • 267
little_planet
  • 1,005
  • 1
  • 16
  • 35

1 Answers1

1

The function returns an error value if a problem occured. From the documentation:

This function returns the error code GPG_ERR_NO_ERROR if successful, or an eror code on failure.

You observed unexpected behavior with setting a home directory without a configuration file:

home_dir is set to the given value, but this also happens if I pass a directory without a config file.

This is expected behavior in GnuPG. An empty configuration file is not an error, but simply means no other configuration but the defaults is in place. Similar things happen if you pass --homedir to GnuPG with a reference to an empty folder: GnuPG will try to initialize this folder as a home directory, but print an information message:

$ LANG=C gpg --homedir /tmp
gpg: keyring `/tmp/secring.gpg' created
gpg: keyring `/tmp/pubring.gpg' created
gpg: Go ahead and type your message ...

If you want to verify the folder is already set up, I'd propose to verify some options you'd expect, or test for a configuration file (or whatever you expect to be available) on your own.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
  • How can I verify that the prefered order of the ciphers is as expected? I only can access `home_dir`, `protocol`, `file_name`, `version` and `req_version` in `gpgme_engine_info_t`. – little_planet Jan 21 '16 at 14:29
  • 1
    GPGME does not expose an interface to the GnuPG configuration directly. You might want to use the built-in [`gpgme_op_spawn`](https://www.gnupg.org/documentation/manuals/gpgme/Running-other-Programs.html#Running-other-Programs) function to run [`gpgconf`](https://www.gnupg.org/documentation/manuals/gnupg/gpgconf.html) (or directly execute it as you'd do with other system processes) . – Jens Erat Jan 21 '16 at 15:20