Skip to content

Commit

Permalink
added detached signature verification?
Browse files Browse the repository at this point in the history
  • Loading branch information
martgil committed Oct 25, 2024
1 parent f2ea24f commit 7969a2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
public handleThunderbirdMessageParsing = async () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.acctEmail = (await BrowserMsg.send.bg.await.thunderbirdGetCurrentUser())!;
const emailBodyToParse = $('div.moz-text-plain').text().trim() || $('div.moz-text-html').text().trim();
const { processableAttachments: fcAttachments, from: from } = await BrowserMsg.send.bg.await.thunderbirdGetDownloadableAttachment();
const emailBodyToParse = $('div.moz-text-plain').text().trim() || $('div.moz-text-html').text().trim() || $('div.moz-text-flowed').text().trim();
const { processableAttachments: fcAttachments, from: signerEmail } = await BrowserMsg.send.bg.await.thunderbirdGetDownloadableAttachment();
if (Catch.isThunderbirdMail()) {
const parsedPubs = (await ContactStore.getOneWithAllPubkeys(undefined, from))?.sortedPubkeys ?? [];
const parsedPubs = (await ContactStore.getOneWithAllPubkeys(undefined, signerEmail))?.sortedPubkeys ?? [];
const verificationPubs = parsedPubs.map(key => KeyUtil.armor(key.pubkey));
if (this.resemblesAsciiArmoredMsg(emailBodyToParse)) {
await this.messageDecrypt(verificationPubs, this.emailBodyFromThunderbirdMail);
Expand Down Expand Up @@ -101,13 +101,13 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
let pgpBlockContent = '';
if (result.content) {
verificationStatus = result.match ? 'signed' : 'not signed';
if (result.signerLongids) {
if (!result.signerLongids.length) {
verificationStatus = `could not verify signature: missing pubkey ${result.signerLongids}`;
}
pgpBlockContent = result.content.toUtfStr();
} else if (result.error) {
verificationStatus = `could not verify signature: ${result.error}`;
pgpBlockContent = detachedSignatureParams?.plaintext || '';
pgpBlockContent = detachedSignatureParams?.plaintext || this.emailBodyFromThunderbirdMail;
}
const pgpBlock = this.generatePgpBlockTemplate('not encrypted', verificationStatus, pgpBlockContent);
$('body').html(pgpBlock); // xss-sanitized
Expand All @@ -122,10 +122,11 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
!this.emailBodyFromThunderbirdMail
) {
await this.messageDecrypt(verificationPubs, fcAttachment.data);
// detached signature verification
} else if (fcAttachment.treatAs === 'signature') {
const sigText = new TextDecoder('utf-8').decode(fcAttachment.data).trim();
if (this.resemblesSignedMsg(sigText)) {
await this.messageVerify(verificationPubs, { plaintext: emailBodyToParse, sigText });
await this.messageVerify(verificationPubs, { plaintext: emailBodyToParse, sigText: sigText.replace('\n=3D', '\n=') });
}
}
};
Expand Down
6 changes: 5 additions & 1 deletion extension/js/service_worker/bg-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ export class BgHandlers {
let from = '';
if (tab.id && message?.id) {
from = Str.parseEmail(message.author).email || '';
const attachments = await messenger.messages.listAttachments(message.id);
const mimeMsg = await messenger.messages.getFull(message.id);
let attachments = await messenger.messages.listAttachments(message.id);
const fcAttachments: Attachment[] = [];
if (mimeMsg.parts?.[0].contentType === 'multipart/signed' && mimeMsg.parts?.[0].parts?.length === 2) {
attachments = attachments.filter(file => file.contentType === 'application/pgp-signature');
}
// convert Thunderbird Attachments to FlowCrypt recognizable Attachments
for (const attachment of attachments) {
const file = await messenger.messages.getAttachmentFile(message.id, attachment.partName);
Expand Down

0 comments on commit 7969a2c

Please sign in to comment.