Handle logbook key decryption failures gracefully by falling back to master key in getLogbookKey
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user