Skip to content

Commit 910ed44

Browse files
committed
[FIX] vault: show clear message on wrong unlock password
Raise a clear message instead of raw OperationError when entering a wrong password.
1 parent 4301392 commit 910ed44

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

vault/static/src/backend/vault.esm.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,23 @@ const vaultService = {
341341
this.iterations
342342
);
343343

344-
this.keys = {
345-
publicKey: await vault_utils.load_public_key(params.public),
346-
privateKey: await vault_utils.load_private_key(
344+
let private_key = null;
345+
try {
346+
private_key = await vault_utils.load_private_key(
347347
params.private,
348348
pass,
349349
params.iv
350-
),
350+
);
351+
} catch (error) {
352+
console.error(error);
353+
throw new Error(
354+
_t("The entered password is wrong. Please try again.")
355+
);
356+
}
357+
358+
this.keys = {
359+
publicKey: await vault_utils.load_public_key(params.public),
360+
privateKey: private_key,
351361
};
352362

353363
this.time = new Date();

vault/static/tests/vault_tests.esm.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ QUnit.module(
112112
assert.deepEqual(master_key, tmp);
113113
});
114114

115+
QUnit.test("vault: Test wrong password", async function (assert) {
116+
assert.expect(1);
117+
118+
const key = await utils.generate_key_pair();
119+
const iv = utils.generate_bytes(10);
120+
const salt = utils.generate_bytes(10);
121+
122+
const wrapper = await utils.derive_key("test", salt, 4000);
123+
const exported = await utils.export_private_key(
124+
key.privateKey,
125+
wrapper,
126+
iv
127+
);
128+
129+
const wrong = await utils.derive_key("wrong", salt, 4000);
130+
await assert.rejects(
131+
utils.load_private_key(exported, wrong, utils.toBase64(iv))
132+
);
133+
});
134+
115135
QUnit.test("vault: Test vault class", async function (assert) {
116136
assert.expect(12);
117137

0 commit comments

Comments
 (0)