From 7b603eecf8085e06c43c818ebbe87caaa3c5f03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Knobloch?= Date: Wed, 10 Mar 2021 12:41:40 +0100 Subject: [PATCH] Prepare add-on for JSON-183: Not to protect subject for PGP partners if applicable. --- addon/content/dialogs/options.js | 2 ++ addon/content/modules/pEp.js | 15 +++++++++++++++ addon/content/modules/pEpAdapter.js | 22 +++++++++++++++++++++- addon/content/pEpForThunderbird.js | 3 +++ addon/content/pepmessengercompose.js | 14 +++++++++++--- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/addon/content/dialogs/options.js b/addon/content/dialogs/options.js index 9d3df5e..7fbe65e 100644 --- a/addon/content/dialogs/options.js +++ b/addon/content/dialogs/options.js @@ -65,8 +65,10 @@ var pEpOptions = { protectSubjectsChange() { if (Services.prefs.getBoolPref("extensions.pEp.protectSubjects", true)) { pEpController.enableprotectSubjects(); + pEpController.protectSubjects = true; } else { pEpController.disableprotectSubjects(); + pEpController.protectSubjects = false; } }, diff --git a/addon/content/modules/pEp.js b/addon/content/modules/pEp.js index 1ab2de3..af56c9f 100644 --- a/addon/content/modules/pEp.js +++ b/addon/content/modules/pEp.js @@ -116,6 +116,21 @@ class pEp { return this.adapter.outgoing_message_rating(message, preview); } + async getOutgoingRatingWithPartnerInfo(from, to = [], cc) { + this.log.info("getOutgoingRatingWithPartnerInfo: ", from, to, cc); + + if (to.length == 0 && (!cc || cc.length == 0)) return { rating: 0, onlyPEP: false }; + + const msgId = PEP_PREFIX + String(this.requestId++); + const message = new pEp.Message(msgId, "test", "test", from, to); + + if (cc) { + message.setCc(cc); + } + + return this.adapter.outgoing_message_rating_with_partner_info(message); + } + async cache_mime_decode_message(message) { return this.adapter.cache_mime_decode_message(message, message.length); } diff --git a/addon/content/modules/pEpAdapter.js b/addon/content/modules/pEpAdapter.js index d24fa6f..6e5cd9e 100644 --- a/addon/content/modules/pEpAdapter.js +++ b/addon/content/modules/pEpAdapter.js @@ -9,6 +9,7 @@ const API_METHOD_CACHE_ENCRYPT_MESSAGE = "cache_encrypt_message"; const API_METHOD_CACHE_ENCRYPT_MESSAGE_FOR_SELF = "cache_encrypt_message_for_self"; const API_METHOD_OUTGOING_MESSAGE_RATING = "outgoing_message_rating"; const API_METHOD_OUTGOING_MESSAGE_RATING_PREVIEW = "outgoing_message_rating_preview"; +const API_METHOD_OUTGOING_MESSAGE_RATING_WPI = "outgoing_message_rating_with_partner_info"; const API_METHOD_RE_EVALUATE_MESSAGE_RATING = "re_evaluate_message_rating"; const API_METHOD_IDENTITY_RATING = "identity_rating"; const API_METHOD_CACHE_MIME_DECODE_MESSAGE = "cache_mime_decode_message"; @@ -157,7 +158,7 @@ class pEpAdapter { async outgoing_message_rating(message, preview) { this.log.info("pEpAdapter.js: outgoing_message_rating()"); - const params = [message, "0"]; + const params = [message, "OUT"]; return this.delegateCallPepAdapter( SERVER_TYPE_CALL_FUNC, preview ? API_METHOD_OUTGOING_MESSAGE_RATING_PREVIEW : API_METHOD_OUTGOING_MESSAGE_RATING, @@ -174,6 +175,25 @@ class pEpAdapter { }); } + async outgoing_message_rating_with_partner_info(message) { + this.log.info("pEpAdapter.js: outgoing_message_rating_with_partner_info()"); + const params = [message, "OUT", "OUT"]; + return this.delegateCallPepAdapter( + SERVER_TYPE_CALL_FUNC, + API_METHOD_OUTGOING_MESSAGE_RATING_WPI, + params, + ).then((response) => { + this.log.debug("pEpAdapter.js: outgoing_message_rating_with_partner_info()", response); + if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) { + this.log.error(`returned status ${response.result.return.status}`); + } + return { rating: response.result.outParams[1].rating, onlyPEP: response.result.outParams[0] }; + }).catch((err) => { + this.log.error(err.message); + throw err; + }); + } + async re_evaluate_message_rating(message, keyList, oldRating) { this.log.info("pEpAdapter.js: re_evaluate_message_rating()"); const params = [message, keyList, { rating: oldRating }, "OUT"]; diff --git a/addon/content/pEpForThunderbird.js b/addon/content/pEpForThunderbird.js index ba5d565..046ad88 100644 --- a/addon/content/pEpForThunderbird.js +++ b/addon/content/pEpForThunderbird.js @@ -59,6 +59,7 @@ class pEpForThunderbird extends pEp { this.newMessageKeys = []; this.pollSession = null; this.clientID = null; + this.protectSubjects = true; this.MOZ_APP_VERSION = parseInt(AppConstants.MOZ_APP_VERSION, 10); this.platform = AppConstants.platform; @@ -128,8 +129,10 @@ class pEpForThunderbird extends pEp { // Setup protect subjects at startup if (Services.prefs.getBoolPref("extensions.pEp.protectSubjects", true)) { this.enableprotectSubjects(); + this.protectSubjects = true; } else { this.disableprotectSubjects(); + this.protectSubjects = false; } // Import keys from RNP starting at Thunderbird 78. diff --git a/addon/content/pepmessengercompose.js b/addon/content/pepmessengercompose.js index 68522a2..3b5b0b1 100644 --- a/addon/content/pepmessengercompose.js +++ b/addon/content/pepmessengercompose.js @@ -554,9 +554,17 @@ var pEpComposer = { // This is a hack. We tell the engine whether we want protected subjects, // but when we pass the MIME tree back in pEpMimeEncrypt.js, the engine-provided // headers are just ignored. So we manipulate the header here manually which isn't ideal. - // We always hide the subject, even if the user chose not to protect subjects for - // PGP communication partners. To be revisited once JSON-183 is implemented. - compFields.subject = PEP_ENCRYPTED_SUBJECT; + if (true || pEpController.protectSubjects) { // else branch disabled pending JSON-183. + // We unconditionally replace the subject. + compFields.subject = PEP_ENCRYPTED_SUBJECT; + } else { + // We need to check whether there are any non-pEp comm partners. + let { dummy, onlyPEP } = pEpController.synchronise( + // eslint-disable-next-line comma-dangle + pEpController.getOutgoingRatingWithPartnerInfo(compSec.fromSender, compSec.toRecipients, compSec.ccRecipients) + ); + if (onlyPEP) compFields.subject = PEP_ENCRYPTED_SUBJECT; + } } } },