Skip to content

Commit 7969a2c

Browse files
committed
added detached signature verification?
1 parent f2ea24f commit 7969a2c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

extension/js/content_scripts/webmail/thunderbird/thunderbird-element-replacer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
3131
public handleThunderbirdMessageParsing = async () => {
3232
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3333
this.acctEmail = (await BrowserMsg.send.bg.await.thunderbirdGetCurrentUser())!;
34-
const emailBodyToParse = $('div.moz-text-plain').text().trim() || $('div.moz-text-html').text().trim();
35-
const { processableAttachments: fcAttachments, from: from } = await BrowserMsg.send.bg.await.thunderbirdGetDownloadableAttachment();
34+
const emailBodyToParse = $('div.moz-text-plain').text().trim() || $('div.moz-text-html').text().trim() || $('div.moz-text-flowed').text().trim();
35+
const { processableAttachments: fcAttachments, from: signerEmail } = await BrowserMsg.send.bg.await.thunderbirdGetDownloadableAttachment();
3636
if (Catch.isThunderbirdMail()) {
37-
const parsedPubs = (await ContactStore.getOneWithAllPubkeys(undefined, from))?.sortedPubkeys ?? [];
37+
const parsedPubs = (await ContactStore.getOneWithAllPubkeys(undefined, signerEmail))?.sortedPubkeys ?? [];
3838
const verificationPubs = parsedPubs.map(key => KeyUtil.armor(key.pubkey));
3939
if (this.resemblesAsciiArmoredMsg(emailBodyToParse)) {
4040
await this.messageDecrypt(verificationPubs, this.emailBodyFromThunderbirdMail);
@@ -101,13 +101,13 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
101101
let pgpBlockContent = '';
102102
if (result.content) {
103103
verificationStatus = result.match ? 'signed' : 'not signed';
104-
if (result.signerLongids) {
104+
if (!result.signerLongids.length) {
105105
verificationStatus = `could not verify signature: missing pubkey ${result.signerLongids}`;
106106
}
107107
pgpBlockContent = result.content.toUtfStr();
108108
} else if (result.error) {
109109
verificationStatus = `could not verify signature: ${result.error}`;
110-
pgpBlockContent = detachedSignatureParams?.plaintext || '';
110+
pgpBlockContent = detachedSignatureParams?.plaintext || this.emailBodyFromThunderbirdMail;
111111
}
112112
const pgpBlock = this.generatePgpBlockTemplate('not encrypted', verificationStatus, pgpBlockContent);
113113
$('body').html(pgpBlock); // xss-sanitized
@@ -122,10 +122,11 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
122122
!this.emailBodyFromThunderbirdMail
123123
) {
124124
await this.messageDecrypt(verificationPubs, fcAttachment.data);
125+
// detached signature verification
125126
} else if (fcAttachment.treatAs === 'signature') {
126127
const sigText = new TextDecoder('utf-8').decode(fcAttachment.data).trim();
127128
if (this.resemblesSignedMsg(sigText)) {
128-
await this.messageVerify(verificationPubs, { plaintext: emailBodyToParse, sigText });
129+
await this.messageVerify(verificationPubs, { plaintext: emailBodyToParse, sigText: sigText.replace('\n=3D', '\n=') });
129130
}
130131
}
131132
};

extension/js/service_worker/bg-handlers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ export class BgHandlers {
170170
let from = '';
171171
if (tab.id && message?.id) {
172172
from = Str.parseEmail(message.author).email || '';
173-
const attachments = await messenger.messages.listAttachments(message.id);
173+
const mimeMsg = await messenger.messages.getFull(message.id);
174+
let attachments = await messenger.messages.listAttachments(message.id);
174175
const fcAttachments: Attachment[] = [];
176+
if (mimeMsg.parts?.[0].contentType === 'multipart/signed' && mimeMsg.parts?.[0].parts?.length === 2) {
177+
attachments = attachments.filter(file => file.contentType === 'application/pgp-signature');
178+
}
175179
// convert Thunderbird Attachments to FlowCrypt recognizable Attachments
176180
for (const attachment of attachments) {
177181
const file = await messenger.messages.getAttachmentFile(message.id, attachment.partName);

0 commit comments

Comments
 (0)