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
+5
View File
@@ -24,6 +24,7 @@ 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.')
} }
try {
// Derive CryptoKey from user master key // Derive CryptoKey from user master key
const aesKey = await window.crypto.subtle.importKey( const aesKey = await window.crypto.subtle.importKey(
'raw', 'raw',
@@ -37,6 +38,10 @@ export async function getLogbookKey(logbookId: string): Promise<ArrayBuffer | nu
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
}
} }
/** /**