fc5871
# HG changeset patch
fc5871
# User Kai Engert <kaie@kuix.de>
fc5871
# Date 1664378971 0
fc5871
#      Wed Sep 28 15:29:31 2022 +0000
fc5871
# Node ID 98bde42cf14e966da1cdf098e2d0917032c0f327
fc5871
# Parent  af0b1f5e4c7710f824c6141103e516ca60bc78aa
fc5871
Bug 1791195 - Adjust OpenPGP signature handling for RNP >= 0.16.2. r=mkmelin
fc5871
fc5871
Differential Revision: https://phabricator.services.mozilla.com/D158270
fc5871
fc5871
diff --git a/comm/mail/extensions/openpgp/content/modules/RNP.jsm b/comm/mail/extensions/openpgp/content/modules/RNP.jsm
fc5871
--- a/comm/mail/extensions/openpgp/content/modules/RNP.jsm
fc5871
+++ b/comm/mail/extensions/openpgp/content/modules/RNP.jsm
fc5871
@@ -1150,22 +1150,25 @@ var RNP = {
fc5871
 
fc5871
     result.exitCode = RNPLib.rnp_op_verify_execute(verify_op);
fc5871
 
fc5871
     let rnpCannotDecrypt = false;
fc5871
     let queryAllEncryptionRecipients = false;
fc5871
+    let stillUndecidedIfSignatureIsBad = false;
fc5871
 
fc5871
     let useDecodedData;
fc5871
     let processSignature;
fc5871
     switch (result.exitCode) {
fc5871
       case RNPLib.RNP_SUCCESS:
fc5871
         useDecodedData = true;
fc5871
         processSignature = true;
fc5871
         break;
fc5871
       case RNPLib.RNP_ERROR_SIGNATURE_INVALID:
fc5871
-        result.statusFlags |= EnigmailConstants.BAD_SIGNATURE;
fc5871
+        // Either the signing key is unavailable, or the signature is
fc5871
+        // indeed bad. Must check signature status below.
fc5871
+        stillUndecidedIfSignatureIsBad = true;
fc5871
         useDecodedData = true;
fc5871
-        processSignature = false;
fc5871
+        processSignature = true;
fc5871
         break;
fc5871
       case RNPLib.RNP_ERROR_SIGNATURE_EXPIRED:
fc5871
         useDecodedData = true;
fc5871
         processSignature = false;
fc5871
         result.statusFlags |= EnigmailConstants.EXPIRED_SIGNATURE;
fc5871
@@ -1320,13 +1323,30 @@ var RNP = {
fc5871
           options.fromAddr,
fc5871
           options.msgDate,
fc5871
           verify_op,
fc5871
           result
fc5871
         );
fc5871
+
fc5871
+        if (
fc5871
+          (result.statusFlags &
fc5871
+            (EnigmailConstants.GOOD_SIGNATURE |
fc5871
+              EnigmailConstants.UNCERTAIN_SIGNATURE |
fc5871
+              EnigmailConstants.EXPIRED_SIGNATURE |
fc5871
+              EnigmailConstants.BAD_SIGNATURE)) !=
fc5871
+          0
fc5871
+        ) {
fc5871
+          // A decision was already made.
fc5871
+          stillUndecidedIfSignatureIsBad = false;
fc5871
+        }
fc5871
       }
fc5871
     }
fc5871
 
fc5871
+    if (stillUndecidedIfSignatureIsBad) {
fc5871
+      // We didn't find more details above, so conclude it's bad.
fc5871
+      result.statusFlags |= EnigmailConstants.BAD_SIGNATURE;
fc5871
+    }
fc5871
+
fc5871
     RNPLib.rnp_input_destroy(input_from_memory);
fc5871
     RNPLib.rnp_output_destroy(output_to_memory);
fc5871
     RNPLib.rnp_op_verify_destroy(verify_op);
fc5871
 
fc5871
     if (
fc5871
@@ -1458,10 +1478,12 @@ var RNP = {
fc5871
     let have_signer_key = false;
fc5871
     let use_signer_key = false;
fc5871
 
fc5871
     if (query_signer) {
fc5871
       if (RNPLib.rnp_op_verify_signature_get_key(sig, signer_key.address())) {
fc5871
+        // If sig_status isn't RNP_ERROR_KEY_NOT_FOUND then we must
fc5871
+        // be able to obtain the signer key.
fc5871
         throw new Error("rnp_op_verify_signature_get_key");
fc5871
       }
fc5871
 
fc5871
       have_signer_key = true;
fc5871
       use_signer_key = !this.isBadKey(signer_key);