mirror of
https://github.com/bitwarden/jslib
synced 2025-12-23 19:53:55 +00:00
Add backwards compatability for new local hashing method (#407)
* Add backwards compatability for existing keyHash * Minor changes for review comments
This commit is contained in:
@@ -141,6 +141,25 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
return keyHash == null ? null : this.keyHash;
|
||||
}
|
||||
|
||||
async compareAndUpdateKeyHash(masterPassword: string, key: SymmetricCryptoKey): Promise<boolean> {
|
||||
const storedKeyHash = await this.getKeyHash();
|
||||
if (masterPassword != null && storedKeyHash != null) {
|
||||
const localKeyHash = await this.hashPassword(masterPassword, key, HashPurpose.LocalAuthorization);
|
||||
if (localKeyHash != null && storedKeyHash === localKeyHash) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: remove serverKeyHash check in 1-2 releases after everyone's keyHash has been updated
|
||||
const serverKeyHash = await this.hashPassword(masterPassword, key, HashPurpose.ServerAuthorization);
|
||||
if (serverKeyHash != null && storedKeyHash === serverKeyHash) {
|
||||
await this.setKeyHash(localKeyHash);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@sequentialize(() => 'getEncKey')
|
||||
async getEncKey(key: SymmetricCryptoKey = null): Promise<SymmetricCryptoKey> {
|
||||
if (this.encKey != null) {
|
||||
|
||||
Reference in New Issue
Block a user