Bug 1643145 - Allow a configurable extra encryption OpenPGP recipient key, only in non-release builds. r=PatrickBrunschwig a=wsmwk
authorKai Engert <kaie@kuix.de>
Wed, 03 Jun 2020 21:59:12 +0200
changeset 39392 ab8496ca706f40f08ac03f905ebbf0eafbdd7fc5
parent 39391 385e98c56c20d53f56f00e13eacf948f33f2bc31
child 39393 1a3ece9ab4905766239ca9a9b3e6e20284632ff3
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersPatrickBrunschwig, wsmwk
bugs1643145
Bug 1643145 - Allow a configurable extra encryption OpenPGP recipient key, only in non-release builds. r=PatrickBrunschwig a=wsmwk Differential Revision: https://phabricator.services.mozilla.com/D78145
mail/extensions/am-e2e/prefs/e2e-prefs.js
mail/extensions/openpgp/content/modules/RNP.jsm
--- a/mail/extensions/am-e2e/prefs/e2e-prefs.js
+++ b/mail/extensions/am-e2e/prefs/e2e-prefs.js
@@ -25,16 +25,18 @@ pref("mail.identity.default.signing_cert
 
 // 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", "");
 
+// When sending, encrypt to this additional key. Not available in release channel builds.
+pref("mail.openpgp.debug.extra_encryption_key", "");
 
 // Hide prefs and menu entries from non-advanced users
 pref("temp.openpgp.advancedUser", false);
 
 // ** enigmail keySel preferences:
 // use rules to assign keys
 pref("temp.openpgp.assignKeysByRules", true);
 // use email addresses to assign keys
--- a/mail/extensions/openpgp/content/modules/RNP.jsm
+++ b/mail/extensions/openpgp/content/modules/RNP.jsm
@@ -1,14 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const EXPORTED_SYMBOLS = ["RNP"];
 
+var { AppConstants } = ChromeUtils.import(
+  "resource://gre/modules/AppConstants.jsm"
+);
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { ctypes } = ChromeUtils.import("resource://gre/modules/ctypes.jsm");
 var { RNPLibLoader } = ChromeUtils.import(
   "chrome://openpgp/content/modules/RNPLib.jsm"
 );
 var { EnigmailConstants } = ChromeUtils.import(
   "chrome://openpgp/content/modules/constants.jsm"
 );
@@ -1690,16 +1693,36 @@ var RNP = {
         if (bccKey.isNull()) {
           resultStatus.statusFlags |= EnigmailConstants.INVALID_RECIPIENT;
           return null;
         }
         this.addSuitableEncryptKey(bccKey, op);
         RNPLib.rnp_key_handle_destroy(bccKey);
       }
 
+      if (AppConstants.MOZ_UPDATE_CHANNEL != "release") {
+        let debugKey = Services.prefs.getStringPref(
+          "mail.openpgp.debug.extra_encryption_key"
+        );
+        if (debugKey) {
+          console.debug("searching for " + debugKey);
+          let handle = this.getKeyHandleByKeyIdOrFingerprint(
+            RNPLib.ffi,
+            debugKey
+          );
+          if (handle.isNull()) {
+            console.debug("cannot get handle for debug key " + debugKey);
+          } else {
+            console.debug("FOUND get handle for debug key " + debugKey);
+            this.addSuitableEncryptKey(handle, op);
+            RNPLib.rnp_key_handle_destroy(handle);
+          }
+        }
+      }
+
       // TODO decide if our compatibility requirements allow us to
       // use AEAD
       if (RNPLib.rnp_op_encrypt_set_cipher(op, "AES256")) {
         throw new Error("rnp_op_encrypt_set_cipher failed");
       }
 
       // TODO, map args.signatureHash string to RNP and call
       //       rnp_op_encrypt_set_hash