mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
* move pinKeyEncryptedUserKey * move pinKeyEncryptedUserKeyEphemeral * remove comments, move docs * cleanup * use UserKeyDefinition * refactor methods * add migration * fix browser dependency * add tests for migration * rename to pinService * move state to PinService * add PinService dep to CryptoService * move protectedPin to state provider * update service deps * renaming * move decryptUserKeyWithPin to pinService * update service injection * move more methods our of crypto service * remove CryptoService dep from PinService and update service injection * remove cryptoService reference * add method to FakeMasterPasswordService * fix circular dependency * fix desktop service injection * update browser dependencies * add protectedPin to migrations * move storePinKey to pinService * update and clarify documentation * more jsdoc updates * update import paths * refactor isPinLockSet method * update state definitions * initialize service before injecting into other services * initialize service before injecting into other services (bw.ts) * update clearOn and do additional cleanup * clarify docs and naming * assign abstract & private methods, add clarity to decryptAndMigrateOldPinKeyEncryptedMasterKey() method * derived state (attempt) * fix typos * use accountService to get active user email * use constant userId * add derived state * add get and clear for oldPinKeyEncryptedMasterKey * require userId * move pinProtected * add clear methods * remove pinProtected from account.ts and replace methods * add methods to create and store pinKeyEncryptedUserKey * add pinProtected/oldPinKeyEncrypterMasterKey to migration * update migration tests * update migration rollback tests * update to systemService and decryptAndMigrate... method * remove old test * increase length of state definition name to meet test requirements * rename 'TRANSIENT' to 'EPHEMERAL' for consistency * fix tests for login strategies, vault-export, and fake MP service * more updates to login-strategy tests * write new tests for core pinKeyEncrypterUserKey methods and isPinSet * write new tests for pinProtected and oldPinKeyEncryptedMasterKey methods * minor test reformatting * update test for decryptUserKeyWithPin() * fix bug with oldPinKeyEncryptedMasterKey * fix tests for vault-timeout-settings.service * fix bitwarden-password-protected-importer test * fix login strategy tests and auth-request.service test * update pinService tests * fix crypto service tests * add jsdoc * fix test file import * update jsdocs for decryptAndMigrateOldPinKeyEncryptedMasterKey() * update error messages and jsdocs * add null checks, move userId retrievals * update migration tests * update stateService calls to require userId * update test for decryptUserKeyWithPin() * update oldPinKeyEncryptedMasterKey migration tests * more test updates * fix factory import * update tests for isPinSet() and createProtectedPin() * add test for makePinKey() * add test for createPinKeyEncryptedUserKey() * add tests for getPinLockType() * consolidate userId verification tests * add tests for storePinKeyEncryptedUserKey() * fix service dep * get email based on userId * use MasterPasswordService instead of internal * rename protectedPin to userKeyEncryptedPin * rename to pinKeyEncryptedUserKeyPersistent * update method params * fix CryptoService tests * jsdoc update * use EncString for userKeyEncryptedPin * remove comment * use cryptoFunctionService.compareFast() * update tests * cleanup, remove comments * resolve merge conflict * fix DI of MasterPasswordService * more DI fixes
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import { KdfConfig } from "../../auth/models/domain/kdf-config";
|
|
import { CsprngArray } from "../../types/csprng";
|
|
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
|
|
|
export abstract class KeyGenerationService {
|
|
/**
|
|
* Generates a key of the given length suitable for use in AES encryption
|
|
* @param bitLength Length of key.
|
|
* 256 bits = 32 bytes
|
|
* 512 bits = 64 bytes
|
|
* @returns Generated key.
|
|
*/
|
|
abstract createKey(bitLength: 256 | 512): Promise<SymmetricCryptoKey>;
|
|
/**
|
|
* Generates key material from CSPRNG and derives a 64 byte key from it.
|
|
* Uses HKDF, see {@link https://datatracker.ietf.org/doc/html/rfc5869 RFC 5869}
|
|
* for details.
|
|
* @param bitLength Length of key material.
|
|
* @param purpose Purpose for the key derivation function.
|
|
* Different purposes results in different keys, even with the same material.
|
|
* @param salt Optional. If not provided will be generated from CSPRNG.
|
|
* @returns An object containing the salt, key material, and derived key.
|
|
*/
|
|
abstract createKeyWithPurpose(
|
|
bitLength: 128 | 192 | 256 | 512,
|
|
purpose: string,
|
|
salt?: string,
|
|
): Promise<{ salt: string; material: CsprngArray; derivedKey: SymmetricCryptoKey }>;
|
|
/**
|
|
* Derives a 64 byte key from key material.
|
|
* @remark The key material should be generated from {@link createKey}, or {@link createKeyWithPurpose}.
|
|
* Uses HKDF, see {@link https://datatracker.ietf.org/doc/html/rfc5869 RFC 5869} for details.
|
|
* @param material key material.
|
|
* @param salt Salt for the key derivation function.
|
|
* @param purpose Purpose for the key derivation function.
|
|
* Different purposes results in different keys, even with the same material.
|
|
* @returns 64 byte derived key.
|
|
*/
|
|
abstract deriveKeyFromMaterial(
|
|
material: CsprngArray,
|
|
salt: string,
|
|
purpose: string,
|
|
): Promise<SymmetricCryptoKey>;
|
|
/**
|
|
* Derives a 32 byte key from a password using a key derivation function.
|
|
* @param password Password to derive the key from.
|
|
* @param salt Salt for the key derivation function.
|
|
* @param kdfConfig Configuration for the key derivation function.
|
|
* @returns 32 byte derived key.
|
|
*/
|
|
abstract deriveKeyFromPassword(
|
|
password: string | Uint8Array,
|
|
salt: string | Uint8Array,
|
|
kdfConfig: KdfConfig,
|
|
): Promise<SymmetricCryptoKey>;
|
|
|
|
/**
|
|
* Derives a 64 byte key from a 32 byte key using a key derivation function.
|
|
* @param key 32 byte key.
|
|
* @returns 64 byte derived key.
|
|
*/
|
|
abstract stretchKey(key: SymmetricCryptoKey): Promise<SymmetricCryptoKey>;
|
|
}
|