mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
[PM-22611] Require userid for masterKey methods on the key service (#15663)
* Require userId on targeted methods. * update method consumers * unit tests
This commit is contained in:
@@ -163,11 +163,14 @@ export abstract class KeyService {
|
||||
*/
|
||||
abstract clearStoredUserKey(keySuffix: KeySuffixOptions, userId: string): Promise<void>;
|
||||
/**
|
||||
* @throws Error when userId is null and no active user
|
||||
* Retrieves the user's master key if it is in state, or derives it from the provided password
|
||||
* @param password The user's master password that will be used to derive a master key if one isn't found
|
||||
* @param userId The desired user
|
||||
* @throws Error when userId is null/undefined.
|
||||
* @throws Error when email or Kdf configuration cannot be found for the user.
|
||||
* @returns The user's master key if it exists, or a newly derived master key.
|
||||
*/
|
||||
abstract getOrDeriveMasterKey(password: string, userId?: string): Promise<MasterKey>;
|
||||
abstract getOrDeriveMasterKey(password: string, userId: UserId): Promise<MasterKey>;
|
||||
/**
|
||||
* Generates a master key from the provided password
|
||||
* @param password The user's master password
|
||||
@@ -175,7 +178,7 @@ export abstract class KeyService {
|
||||
* @param KdfConfig The user's key derivation function configuration
|
||||
* @returns A master key derived from the provided password
|
||||
*/
|
||||
abstract makeMasterKey(password: string, email: string, KdfConfig: KdfConfig): Promise<MasterKey>;
|
||||
abstract makeMasterKey(password: string, email: string, kdfConfig: KdfConfig): Promise<MasterKey>;
|
||||
/**
|
||||
* Encrypts the existing (or provided) user key with the
|
||||
* provided master key
|
||||
@@ -191,24 +194,25 @@ export abstract class KeyService {
|
||||
* Creates a master password hash from the user's master password. Can
|
||||
* be used for local authentication or for server authentication depending
|
||||
* on the hashPurpose provided.
|
||||
* @throws Error when password is null or key is null and no active user or active user have no master key
|
||||
* @param password The user's master password
|
||||
* @param key The user's master key or active's user master key.
|
||||
* @param hashPurpose The iterations to use for the hash
|
||||
* @param hashPurpose The iterations to use for the hash. Defaults to {@link HashPurpose.ServerAuthorization}.
|
||||
* @throws Error when password is null/undefined or key is null/undefined.
|
||||
* @returns The user's master password hash
|
||||
*/
|
||||
abstract hashMasterKey(
|
||||
password: string,
|
||||
key: MasterKey | null,
|
||||
key: MasterKey,
|
||||
hashPurpose?: HashPurpose,
|
||||
): Promise<string>;
|
||||
/**
|
||||
* Compares the provided master password to the stored password hash.
|
||||
* @param masterPassword The user's master password
|
||||
* @param key The user's master key
|
||||
* @param masterKey The user's master key
|
||||
* @param userId The id of the user to do the operation for.
|
||||
* @returns True if the provided master password matches either the stored
|
||||
* key hash or the server key hash
|
||||
* @throws Error when master key is null/undefined.
|
||||
* @returns True if the derived master password hash matches the stored
|
||||
* key hash, false otherwise.
|
||||
*/
|
||||
abstract compareKeyHash(
|
||||
masterPassword: string,
|
||||
|
||||
Reference in New Issue
Block a user