From 066ab1bc32687228bddd4dbae872d64f621101c0 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Mon, 30 Mar 2026 19:15:02 +0200 Subject: [PATCH] debug: add diagnostic logging to 3DES S/MIME decrypt path Log legacy key import success/failure, CMS algorithm OIDs (content encryption + key transport), legacy key availability during decrypt attempts, and detailed error messages from both RSA-OAEP and RSAES-PKCS1-v1_5 decrypt paths. --- components/email/email-viewer.tsx | 7 ++++++- lib/smime/pkcs12-import.ts | 8 ++++++-- lib/smime/smime-decrypt.ts | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/components/email/email-viewer.tsx b/components/email/email-viewer.tsx index 04bf8c68..68af0db0 100644 --- a/components/email/email-viewer.tsx +++ b/components/email/email-viewer.tsx @@ -1546,7 +1546,12 @@ export function EmailViewer({ if (detection.type === 'enveloped-data') { // Encrypted message const { keyRecords, unlockedDecryptionKeys, unlockedLegacyDecryptionKeys } = smimeStore; - smimeDebug('[S/MIME] decrypt attempt:', { keyRecordCount: keyRecords.length, unlockedKeyCount: unlockedDecryptionKeys.size, keyRecordIds: keyRecords.map(k => k.id) }); + smimeDebug('[S/MIME] decrypt attempt:', { + keyRecordCount: keyRecords.length, + unlockedKeyCount: unlockedDecryptionKeys.size, + legacyKeyCount: unlockedLegacyDecryptionKeys.size, + keyRecordIds: keyRecords.map(k => k.id), + }); // Short-circuit: no keys imported at all if (keyRecords.length === 0) { diff --git a/lib/smime/pkcs12-import.ts b/lib/smime/pkcs12-import.ts index 3be315bc..a503e85d 100644 --- a/lib/smime/pkcs12-import.ts +++ b/lib/smime/pkcs12-import.ts @@ -298,8 +298,12 @@ export async function unlockPrivateKey( false, ['decrypt'], ); - } catch { - // webcrypto-liner may not be available or key format unsupported + console.debug('[S/MIME] legacy RSAES-PKCS1-v1_5 key imported successfully:', { + algorithm: legacyDecryptionKey.algorithm, + usages: legacyDecryptionKey.usages, + }); + } catch (err) { + console.warn('[S/MIME] legacy RSAES-PKCS1-v1_5 key import failed:', err); } } diff --git a/lib/smime/smime-decrypt.ts b/lib/smime/smime-decrypt.ts index 3a641687..3e3b3300 100644 --- a/lib/smime/smime-decrypt.ts +++ b/lib/smime/smime-decrypt.ts @@ -42,6 +42,18 @@ export async function smimeDecrypt(input: DecryptionInput): Promise + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (ri as any).value?.keyEncryptionAlgorithm?.algorithmId as string | undefined, + ); + console.debug('[S/MIME] CMS algorithms:', { + contentEncryption: contentEncOid, + keyTransport: recipientAlgs, + legacyKeysAvailable: legacyUnlockedKeys?.size ?? 0, + }); + // Find matching key records const matchedRecords = findMatchingKeyRecords(envelopedData, keyRecords); @@ -75,9 +87,11 @@ export async function smimeDecrypt(input: DecryptionInput): Promise