Page MenuHome GnuPG

Exporting secret keys via gpgme
Closed, ResolvedPublic

Description

I am having trouble exporting secret keys programmatically. I am using GPGME via the Rust bindings but as you can see in the attached link it seems that the issue comes from the library itself. The passphrase callback is not used when exporting secret keys. I am not sure if this is expected or not.


I tried adding this code before _gpgme_engine_op_export in export_start:

if (ctx->passphrase_cb)
    {
      err = _gpgme_engine_set_command_handler
        (ctx->engine, _gpgme_passphrase_command_handler, ctx);
      if (err)
        return err;
    }

It it still not using the callback.

Revisions and Commits

Event Timeline

The following patch make it work:

diff --git a/src/export.c b/src/export.c
index 7e394dff..599841b3 100644
--- a/src/export.c
+++ b/src/export.c
@@ -165,6 +165,14 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,

   _gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);

+  if (ctx->passphrase_cb)
+    {
+      err = _gpgme_engine_set_command_handler
+        (ctx->engine, _gpgme_passphrase_command_handler, ctx);
+      if (err)
+        return err;
+    }
+
   return _gpgme_engine_op_export (ctx->engine, pattern, mode, keydata,
                                  ctx->use_armor);
 }
@@ -260,6 +268,14 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[],

   _gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);

+  if (ctx->passphrase_cb)
+    {
+      err = _gpgme_engine_set_command_handler
+        (ctx->engine, _gpgme_passphrase_command_handler, ctx);
+      if (err)
+        return err;
+    }
+
   return _gpgme_engine_op_export_ext (ctx->engine, pattern, mode, keydata,
                                      ctx->use_armor);
 }
bernhard renamed this task from Exporting secret keys to Exporting secret keys via gpgme.Sep 7 2020, 10:17 AM
gniibe triaged this task as Normal priority.
gniibe added a subscriber: gniibe.

Thank you.

I think that exporting secret keys by GPGME are not used, so, not implemented.

I do minor edit about the order of calls (_gpgme_engine_set_command_handler and _gpgme_engine_set_status_handler) to follow the pattern in sign.c.