1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

update makeKeyPair on crypto service to be generic

This commit is contained in:
Jacob Fink
2023-05-30 09:47:49 -04:00
parent 6dc454e5e7
commit 820c71d1a1
2 changed files with 8 additions and 5 deletions

View File

@@ -59,7 +59,7 @@ export abstract class CryptoService {
setPrivateKey: (encPrivateKey: string) => Promise<void>;
getPrivateKey: () => Promise<ArrayBuffer>;
getFingerprint: (fingerprintMaterial: string, publicKey?: ArrayBuffer) => Promise<string[]>;
makeKeyPair: (key?: UserSymKey) => Promise<[string, EncString]>;
makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, EncString]>;
clearKeyPair: (memoryOnly?: boolean, userId?: string) => Promise<void[]>;
makePinKey: (pin: string, salt: string, kdf: KdfType, kdfConfig: KdfConfig) => Promise<PinKey>;
clearPinProtectedKey: () => Promise<void>;

View File

@@ -613,11 +613,14 @@ export class CryptoService implements CryptoServiceAbstraction {
}
/**
* Generates a new keypair for the user
* @param key The user's symmetric key
* @returns A new keypair: [publicKey in Base64, protected privateKey]
* Generates a new keypair
* @param key A key to encrypt the private key with. If not provided,
* defaults to the user's symmetric key
* @returns A new keypair: [publicKey in Base64, encrypted privateKey]
*/
async makeKeyPair(key?: UserSymKey): Promise<[string, EncString]> {
async makeKeyPair(key?: SymmetricCryptoKey): Promise<[string, EncString]> {
key ||= await this.getUserKey();
const keyPair = await this.cryptoFunctionService.rsaGenerateKeyPair(2048);
const publicB64 = Utils.fromBufferToB64(keyPair[0]);
const privateEnc = await this.encrypt(keyPair[1], key);