mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 09:49:24 +02:00
feat(credential): expose key name for varies password-related operations
This commit is contained in:
parent
755061ef18
commit
6db5d8eb74
1 changed files with 11 additions and 4 deletions
|
@ -55,8 +55,14 @@ async function deriveAesKey(password: string, salt?: Uint8Array<ArrayBuffer>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class PasswordIncorrectError extends Error {
|
class PasswordIncorrectError extends Error {
|
||||||
constructor() {
|
#keyName: string | undefined;
|
||||||
|
get keyName() {
|
||||||
|
return this.#keyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(keyName: string | undefined) {
|
||||||
super("Password incorrect");
|
super("Password incorrect");
|
||||||
|
this.#keyName = keyName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +84,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage {
|
||||||
privateKey: Uint8Array<ArrayBuffer>,
|
privateKey: Uint8Array<ArrayBuffer>,
|
||||||
name: string | undefined,
|
name: string | undefined,
|
||||||
): Promise<undefined> {
|
): Promise<undefined> {
|
||||||
const password = await this.#requestPassword("save");
|
const password = await this.#requestPassword("save", name);
|
||||||
const { salt, aesKey } = await deriveAesKey(password);
|
const { salt, aesKey } = await deriveAesKey(password);
|
||||||
|
|
||||||
const iv = new Uint8Array(AesIvLength);
|
const iv = new Uint8Array(AesIvLength);
|
||||||
|
@ -118,7 +124,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage {
|
||||||
new Uint8ArrayExactReadable(serialized),
|
new Uint8ArrayExactReadable(serialized),
|
||||||
);
|
);
|
||||||
|
|
||||||
const password = await this.#requestPassword("load");
|
const password = await this.#requestPassword("load", name);
|
||||||
const { aesKey } = await deriveAesKey(
|
const { aesKey } = await deriveAesKey(
|
||||||
password,
|
password,
|
||||||
bundle.pbkdf2Salt as Uint8Array<ArrayBuffer>,
|
bundle.pbkdf2Salt as Uint8Array<ArrayBuffer>,
|
||||||
|
@ -147,7 +153,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof DOMException && e.name === "OperationError") {
|
if (e instanceof DOMException && e.name === "OperationError") {
|
||||||
yield new PasswordIncorrectError();
|
yield new PasswordIncorrectError(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +168,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage {
|
||||||
export namespace TangoPasswordProtectedStorage {
|
export namespace TangoPasswordProtectedStorage {
|
||||||
export type RequestPassword = (
|
export type RequestPassword = (
|
||||||
reason: "save" | "load",
|
reason: "save" | "load",
|
||||||
|
name: string | undefined,
|
||||||
) => MaybePromiseLike<string>;
|
) => MaybePromiseLike<string>;
|
||||||
|
|
||||||
export type PasswordIncorrectError = typeof PasswordIncorrectError;
|
export type PasswordIncorrectError = typeof PasswordIncorrectError;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue