Exporting secret keys via gpgme
Open, Needs TriagePublic

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.

dblouis created this task.Wed, Sep 2, 5:30 PM
dblouis updated the task description. (Show Details)Wed, Sep 2, 5:41 PM
dblouis updated the task description. (Show Details)Sat, Sep 5, 7:03 PM

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.Mon, Sep 7, 10:17 AM