Handle logbook key decryption failures gracefully by falling back to master key in getLogbookKey

This commit is contained in:
2026-05-28 21:34:46 +02:00
parent a9a649f840
commit 9d24f4b71a
+17 -12
View File
@@ -24,19 +24,24 @@ export async function getLogbookKey(logbookId: string): Promise<ArrayBuffer | nu
throw new Error('Master key not found. Please log in.') throw new Error('Master key not found. Please log in.')
} }
// Derive CryptoKey from user master key try {
const aesKey = await window.crypto.subtle.importKey( // Derive CryptoKey from user master key
'raw', const aesKey = await window.crypto.subtle.importKey(
masterKeyBytes, 'raw',
{ name: 'AES-GCM' }, masterKeyBytes,
false, { name: 'AES-GCM' },
['decrypt'] false,
) ['decrypt']
)
// Decrypt logbook key using User Master Key // Decrypt logbook key using User Master Key
const decrypted = await decryptBuffer(record.encryptedKey, record.iv, record.tag, aesKey) const decrypted = await decryptBuffer(record.encryptedKey, record.iv, record.tag, aesKey)
keyCache.set(logbookId, decrypted) keyCache.set(logbookId, decrypted)
return decrypted return decrypted
} catch (err) {
console.warn(`Failed to decrypt logbook key for ${logbookId}, returning null to allow fallback:`, err)
return null
}
} }
/** /**