diff --git a/src/pages/credentials/index.tsx b/src/pages/credentials/index.tsx index acb14a441..6d2811c61 100644 --- a/src/pages/credentials/index.tsx +++ b/src/pages/credentials/index.tsx @@ -56,7 +56,7 @@ export default function Credentials() { const kek = await libsodium.deriveKey(await libsodium.fromString(passphrase), await libsodium.fromB64(keyAttributes.kekSalt)); - if (await cryptoWorker.verifyHash(keyAttributes.kekHash, kek)) { + if (await cryptoWorker.verifyHash(await libsodium.fromB64(keyAttributes.kekHash), kek)) { const key = await libsodium.decrypt( await libsodium.fromB64(keyAttributes.encryptedKey), await libsodium.fromB64(keyAttributes.keyDecryptionNonce), diff --git a/src/utils/crypto/libsodium.ts b/src/utils/crypto/libsodium.ts index e8273ff49..0e4235b4a 100644 --- a/src/utils/crypto/libsodium.ts +++ b/src/utils/crypto/libsodium.ts @@ -44,19 +44,11 @@ export async function decrypt(data: Uint8Array, nonce: Uint8Array, key: Uint8Arr return sodium.crypto_secretbox_open_easy(data, nonce, key); } -// TODO(https://github.com/firstfloorsoftware/flutter_sodium/issues/46) -export async function verifyHash(hash: string, input: Uint8Array) { - var sanitizedHash = ""; - for (var index = 0; index < hash.length; index++) { - if (hash.charCodeAt(index) == 0) { - sanitizedHash += "\uFFFD"; - break; - } else { - sanitizedHash += hash.charAt(index); - } - } +export async function verifyHash(hash: Uint8Array, input: Uint8Array) { await sodium.ready; - return (sodium.crypto_pwhash_str_verify(sanitizedHash, input) == 0); + return sodium.crypto_pwhash_str_verify( + sodium.to_string(hash), + input); } export async function hash(input: string | Uint8Array) {