Browse Source

P4TB-394: Avoid a second passphrase prompt after the prompt is cancelled.

master
Jörg Knobloch 1 year ago
parent
commit
8b68a4b8b1
1 changed files with 25 additions and 2 deletions
  1. +25
    -2
      addon/content/pEpForThunderbird.js

+ 25
- 2
addon/content/pEpForThunderbird.js View File

@ -47,6 +47,9 @@ class pEpForThunderbird extends pEp {
// Cheap caching scheme follows.
this.currentHeaderMessage = null;
this.currentMimePartMessage = null;
this.currentHeaderMessageNoPassphrase = null;
this.currentMimePartMessageNoPassphrase = null;
this.timeNoPassphrase = null;
this.currentHeaderMimeMessage = null;
this.currentMimePartMimeMessage = null;
this.currentMessage = null; // Decrypted pEp message.
@ -753,6 +756,15 @@ class pEpForThunderbird extends pEp {
return this.currentMessage;
}
if (msgHdr == this.currentHeaderMessageNoPassphrase &&
mimePart == this.currentMimePartMessageNoPassphrase &&
Date.now() - this.timeNoPassphrase < 1000) {
// We've come here a second time in less than a second for the same message.
// Likely a click onto the message first triggered the PGP Proxy to request it
// and then `updateMessagePanel()` requested it again.
throw new Error("Necessary passphrase not supplied");
}
this.log.info(`getDecryptedMessage will ${mimeText ? "NOT " : ""}call readMailFromURI()`);
if (!mimeText) {
mimeText = this.readMailFromURI(msgUri);
@ -778,8 +790,17 @@ class pEpForThunderbird extends pEp {
message.bcc = message.bcc && message.bcc.map((addr) => makeIdentity(addr));
// Decrypt.
let decryptedPromise = this.cache_decrypt_message(message);
this.currentMessage = this.synchronise(decryptedPromise);
try {
let decryptedPromise = this.cache_decrypt_message(message);
this.currentMessage = this.synchronise(decryptedPromise);
} catch (ex) {
if (ex.message == "Necessary passphrase not supplied") {
this.currentHeaderMessageNoPassphrase = (msgHdr == "no-header") ? null : msgHdr;
this.currentMimePartMessageNoPassphrase = mimePart;
this.timeNoPassphrase = Date.now();
}
throw ex;
}
// Copy some headers from the original to the new message.
// Starting with https://pep-security.lu/dev/repos/pEp_for_Thunderbird/rev/d3c752abce8c
@ -819,6 +840,8 @@ class pEpForThunderbird extends pEp {
this.currentHeaderMessage = (msgHdr == "no-header") ? null : msgHdr;
this.currentMimePartMessage = mimePart;
this.currentHeaderMessageNoPassphrase = null;
this.currentMimePartMessageNoPassphrase = null;
return this.currentMessage;
}


Loading…
Cancel
Save