From 820c71d1a1b113da5e8bd4696366094799d04874 Mon Sep 17 00:00:00 2001 From: Jacob Fink Date: Tue, 30 May 2023 09:47:49 -0400 Subject: [PATCH] update makeKeyPair on crypto service to be generic --- .../src/platform/abstractions/crypto.service.ts | 2 +- libs/common/src/platform/services/crypto.service.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/common/src/platform/abstractions/crypto.service.ts b/libs/common/src/platform/abstractions/crypto.service.ts index 34451b8b784..f9bdbc32c50 100644 --- a/libs/common/src/platform/abstractions/crypto.service.ts +++ b/libs/common/src/platform/abstractions/crypto.service.ts @@ -59,7 +59,7 @@ export abstract class CryptoService { setPrivateKey: (encPrivateKey: string) => Promise; getPrivateKey: () => Promise; getFingerprint: (fingerprintMaterial: string, publicKey?: ArrayBuffer) => Promise; - makeKeyPair: (key?: UserSymKey) => Promise<[string, EncString]>; + makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, EncString]>; clearKeyPair: (memoryOnly?: boolean, userId?: string) => Promise; makePinKey: (pin: string, salt: string, kdf: KdfType, kdfConfig: KdfConfig) => Promise; clearPinProtectedKey: () => Promise; diff --git a/libs/common/src/platform/services/crypto.service.ts b/libs/common/src/platform/services/crypto.service.ts index b3443726d94..bed1218fddf 100644 --- a/libs/common/src/platform/services/crypto.service.ts +++ b/libs/common/src/platform/services/crypto.service.ts @@ -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);