GPGME export secret subkeys

Werner Koch wk at gnupg.org
Wed May 30 20:00:39 CEST 2018


On Wed, 30 May 2018 17:22, tookmund at gmail.com said:
> GPGME has export and import functions that work well as alternatives to
> "gpg --import" and "gpg --export". However, looking through the
> documentation I cannot find an equivalent to "gpg
> --export-secret-subkeys". Have I missed something, or does such
> functionality not yet exist?

GPGME does not support all features of gpg; that is to avoid creating a
too baroque API.  If you need this you can resort to the gpgme_op_spawn
API.  For example here is how we make sure in GPA that the gpg-agent is
started (required for direct smartcard operations).


--8<---------------cut here---------------start------------->8---
void
gpa_start_agent (void)
{
  gpg_error_t err;
  gpgme_ctx_t ctx;
  char *pgm;
  const char *argv[3];

  pgm = get_gpg_connect_agent_path ();
  if (!pgm)
    {
      g_message ("tool to start the agent is not available");
      return;
    }

  ctx = gpa_gpgme_new ();
  gpgme_set_protocol (ctx, GPGME_PROTOCOL_SPAWN);
  argv[0] = "";   /* Auto-insert the basename.  */
  argv[1] = "NOP";
  argv[2] = NULL;
  err = gpgme_op_spawn (ctx, pgm, argv, NULL, NULL, NULL, GPGME_SPAWN_DETACHED);
  if (err)
    g_message ("error running '%s': %s", pgm, gpg_strerror (err));
  g_free (pgm);
  gpgme_release (ctx);
}
--8<---------------cut here---------------end--------------->8---

You need to adjust it for your needs; for example the first fucntion
call should be get_gpg_path which can be implemented this way:

--8<---------------cut here---------------start------------->8---
static const gchar *
get_gpg_path (void)
{
  gpgme_engine_info_t engine;

  gpgme_get_engine_info (&engine);
  while (engine)
    {
      if (engine->protocol == GPGME_PROTOCOL_OpenPGP)
	return engine->file_name;
      engine = engine->next;
    }
  return NULL;
}
--8<---------------cut here---------------end--------------->8---



Salam-Shalom,

   Werner

-- 
#  Please read:  Daniel Ellsberg - The Doomsday Machine  #
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 227 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20180530/bc1e454c/attachment.sig>


More information about the Gnupg-users mailing list