Bug 1642614 - Support an alternative gpg executable when using GPGME. r=PatrickBrunschwig a=wsmwk
authorKai Engert <kaie@kuix.de>
Tue, 02 Jun 2020 15:49:34 +0200
changeset 39391 385e98c56c20d53f56f00e13eacf948f33f2bc31
parent 39390 b06a7c1b08f72733d9c07b038842c91ec93aedcd
child 39392 ab8496ca706f40f08ac03f905ebbf0eafbdd7fc5
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersPatrickBrunschwig, wsmwk
bugs1642614
Bug 1642614 - Support an alternative gpg executable when using GPGME. r=PatrickBrunschwig a=wsmwk Differential Revision: https://phabricator.services.mozilla.com/D77805
mail/extensions/am-e2e/prefs/e2e-prefs.js
mail/extensions/openpgp/content/modules/GPGMELib.jsm
--- a/mail/extensions/am-e2e/prefs/e2e-prefs.js
+++ b/mail/extensions/am-e2e/prefs/e2e-prefs.js
@@ -20,16 +20,18 @@ pref("mail.identity.default.encryption_c
 pref("mail.identity.default.signing_cert_name", "");
 
 /**
  * OpenPGP prefs
  */
 
 // If true, we allow the use of GnuPG for OpenPGP secret key operations
 pref("mail.openpgp.allow_external_gnupg", false);
+// If allow_external_gnupg is true: Optionally use a different gpg executable
+pref("mail.openpgp.alternative_gpg_path", "");
 // The hexadecimal OpenPGP key ID used for an identity.
 pref("mail.identity.default.openpgp_key_id", "");
 
 
 // Hide prefs and menu entries from non-advanced users
 pref("temp.openpgp.advancedUser", false);
 
 // ** enigmail keySel preferences:
--- a/mail/extensions/openpgp/content/modules/GPGMELib.jsm
+++ b/mail/extensions/openpgp/content/modules/GPGMELib.jsm
@@ -194,17 +194,38 @@ function enableGPGMELibJS() {
     path: libgpgmePath,
 
     init() {
       // GPGME 1.9.0 released 2017-03-28 is the first version that
       // supports GPGME_DECRYPT_UNWRAP, requiring >= gpg 2.1.12
       let versionPtr = this.gpgme_check_version("1.9.0");
       let version = versionPtr.readString();
       console.debug("gpgme version: " + version);
-      return true;
+
+      let gpgExe = Services.prefs.getStringPref(
+        "mail.openpgp.alternative_gpg_path"
+      );
+      if (!gpgExe) {
+        return true;
+      }
+
+      let extResult = this.gpgme_set_engine_info(
+        this.GPGME_PROTOCOL_OpenPGP,
+        gpgExe,
+        null
+      );
+      let success = extResult === this.GPG_ERR_NO_ERROR;
+      let info = success ? "success" : "failure: " + extResult;
+      console.debug(
+        "configuring GPGME to use an external OpenPGP engine " +
+          gpgExe +
+          " - " +
+          info
+      );
+      return success;
     },
 
     exportKeys(pattern, secret = false) {
       let resultArray = [];
       let allFingerprints = [];
 
       let c1 = new gpgme_ctx_t();
       if (this.gpgme_new(c1.address())) {
@@ -282,16 +303,25 @@ function enableGPGMELibJS() {
 
     gpgme_check_version: libgpgme.declare(
       "gpgme_check_version",
       abi,
       ctypes.char.ptr,
       ctypes.char.ptr
     ),
 
+    gpgme_set_engine_info: libgpgme.declare(
+      "gpgme_set_engine_info",
+      abi,
+      gpgme_error_t,
+      gpgme_protocol_t,
+      ctypes.char.ptr,
+      ctypes.char.ptr
+    ),
+
     gpgme_new: libgpgme.declare("gpgme_new", abi, gpgme_error_t, gpgme_ctx_t),
 
     gpgme_release: libgpgme.declare(
       "gpgme_release",
       abi,
       ctypes.void_t,
       gpgme_ctx_t
     ),