Bug 1775115 - Optimize automatic processing of OpenPGP public key atttachments, avoid quadratic complexity. r=mkmelin
authorKai Engert <kaie@kuix.de>
Tue, 19 Jul 2022 20:44:08 +1000
changeset 36316 e21ab006cec7fd8d44bfcee403b1c5dc8e768e0f
parent 36315 ee722467f6f0502cf35b8c30450fd86cfdd2b581
child 36317 1074faeb5c46a76a5230162949e5b433957c2ae8
push id20110
push user[email protected]
push dateTue, 19 Jul 2022 10:56:17 +0000
treeherdercomm-central@4720ce86c109 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1775115
Bug 1775115 - Optimize automatic processing of OpenPGP public key atttachments, avoid quadratic complexity. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D152079
mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js
--- a/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js
+++ b/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js
@@ -2830,49 +2830,43 @@ Enigmail.msg = {
     }
 
     let errorMsgObj = {};
     let preview = await EnigmailKey.getKeyListFromKeyBlock(
       keyData,
       errorMsgObj,
       true,
       true,
-      false
+      true
     );
 
     // If we cannot analyze the keyblock, or if it's empty, or if we
     // got an error message, then the key is bad and shouldn't be used.
     if (!preview || !preview.length || errorMsgObj.value) {
       return;
     }
 
     this.fetchParticipants();
 
     for (let newKey of preview) {
-      let keyDataOneKey = await RNP.getOnePubKeyFromKeyBlock(
-        keyData,
-        newKey.fpr,
-        false
-      );
-
       let oldKey = EnigmailKeyRing.getKeyById(newKey.fpr);
       if (!oldKey) {
         // If the key is unknown, an expired key cannot help us
         // for anything new, so don't use it.
         if (newKey.keyTrust == "e") {
           continue;
         }
 
         // Potentially merge the revocation into CollectedKeysDB, it if
         // already has that key.
         if (newKey.keyTrust == "r") {
           let db = await CollectedKeysDB.getInstance();
           let existing = await db.findKeyForFingerprint(newKey.fpr);
           if (existing) {
-            let key = await db.mergeExisting(newKey, keyDataOneKey, {
+            let key = await db.mergeExisting(newKey, newKey.pubKey, {
               uri: `mid:${gMessageDisplay.displayedMessage.messageId}`,
               type: isBinaryAutocrypt ? "autocrypt" : "attachment",
               description,
             });
             await db.storeKey(key);
             Services.obs.notifyObservers(null, "openpgp-key-change");
           }
           continue;
@@ -2919,17 +2913,17 @@ Enigmail.msg = {
           let nextIndex = Enigmail.msg.attachedKeys.length;
           let info = {
             fpr: "0x" + newKey.fpr,
             idx: nextIndex,
             keyInfo: newKey,
             binary: isBinaryAutocrypt,
           };
           Enigmail.msg.attachedSenderEmailKeysIndex.push(info);
-          Enigmail.msg.attachedKeys.push(keyDataOneKey);
+          Enigmail.msg.attachedKeys.push(newKey.pubKey);
         }
 
         // We want to collect keys for potential later use, however,
         // we also want to avoid that an attacker can send us a large
         // number of keys to poison our cache, so we only collect keys
         // that are related to the author or one of the recipients.
         // Also, we don't want a public key, if we already have a
         // secret key for that email address.
@@ -2960,18 +2954,18 @@ Enigmail.msg = {
             this.keyCollectCandidates.set(relatedParticipantEmailAddress, {
               skip: true,
             });
           } else {
             let candidate = {};
             candidate.skip = false;
             candidate.newKeyObj = newKey;
             candidate.pubKey = isBinaryAutocrypt
-              ? RNP.enArmorString(keyDataOneKey, "public key")
-              : keyDataOneKey;
+              ? RNP.enArmorString(newKey.pubKey, "public key")
+              : newKey.pubKey;
             candidate.source = {
               uri: `mid:${gMessageDisplay.displayedMessage.messageId}`,
               type: isBinaryAutocrypt ? "autocrypt" : "attachment",
               description,
             };
             this.keyCollectCandidates.set(
               relatedParticipantEmailAddress,
               candidate
@@ -2999,17 +2993,17 @@ Enigmail.msg = {
 
       if (!newHasNewValidity) {
         continue;
       }
 
       if (
         !(await EnigmailKeyRing.importKeyDataSilent(
           window,
-          keyDataOneKey,
+          newKey.pubKey,
           isBinaryAutocrypt,
           "0x" + newKey.fpr
         ))
       ) {
         console.debug(
           "EnigmailKeyRing.importKeyDataSilent failed 0x" + newKey.fpr
         );
       }