From 690e9ffc4a22cdd299e07e793961096c0b233439 Mon Sep 17 00:00:00 2001 From: Jacob Fink Date: Tue, 20 Jun 2023 11:22:32 -0400 Subject: [PATCH] cleanup old TODOs, add missing crypto service parameters --- .../common/src/platform/services/crypto.service.ts | 14 ++++++++------ libs/common/src/platform/services/state.service.ts | 2 -- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/common/src/platform/services/crypto.service.ts b/libs/common/src/platform/services/crypto.service.ts index f9b555c10a..c5e66cba07 100644 --- a/libs/common/src/platform/services/crypto.service.ts +++ b/libs/common/src/platform/services/crypto.service.ts @@ -51,7 +51,7 @@ export class CryptoService implements CryptoServiceAbstraction { // Legacy support: encryption used to be done with the master key (derived from master password). // Users who have not migrated will have a null user key and must use the master key instead. - return await this.stateService.getCryptoMasterKey(); + return await this.getMasterKey(); } async setUserKey(key: UserSymKey, userId?: string): Promise { @@ -126,7 +126,6 @@ export class CryptoService implements CryptoServiceAbstraction { } async setUserSymKeyMasterKey(userSymKeyMasterKey: string, userId?: string): Promise { - // TODO(Jake): is this the best way to handle this from the identity token? await this.stateService.setUserSymKeyMasterKey(userSymKeyMasterKey, { userId: userId }); } @@ -135,7 +134,9 @@ export class CryptoService implements CryptoServiceAbstraction { } async getMasterKey(userId?: string): Promise { - return await this.stateService.getMasterKey({ userId: userId }); + let masterKey = await this.stateService.getMasterKey({ userId: userId }); + masterKey ||= (await this.stateService.getCryptoMasterKey({ userId: userId })) as MasterKey; + return masterKey; } async makeMasterKey( @@ -192,7 +193,6 @@ export class CryptoService implements CryptoServiceAbstraction { return null; } - // TODO(Jake): Do we want to set the user key here? return new SymmetricCryptoKey(decUserKey) as UserSymKey; } @@ -724,10 +724,12 @@ export class CryptoService implements CryptoServiceAbstraction { break; } case KeySuffixOptions.Pin: { - const protectedPin = await this.stateService.getProtectedPin(); + const protectedPin = await this.stateService.getProtectedPin({ userId: userId }); // This could cause a possible timing issue. Need to make sure the ephemeral key is set before // we set our user key - const userSymKeyPinEphemeral = await this.stateService.getUserSymKeyPinEphemeral(); + const userSymKeyPinEphemeral = await this.stateService.getUserSymKeyPinEphemeral({ + userId: userId, + }); shouldStoreKey = !!protectedPin && !userSymKeyPinEphemeral; break; } diff --git a/libs/common/src/platform/services/state.service.ts b/libs/common/src/platform/services/state.service.ts index 97fee6edbd..43fd5587f0 100644 --- a/libs/common/src/platform/services/state.service.ts +++ b/libs/common/src/platform/services/state.service.ts @@ -620,7 +620,6 @@ export class StateService< * so we can unlock with MP offline */ async getUserSymKeyMasterKey(options?: StorageOptions): Promise { - // TODO(Jake): defaultOnDiskOptions? Other's are saved in secure storage return ( await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions())) )?.keys.userSymKeyMasterKey; @@ -631,7 +630,6 @@ export class StateService< * so we can unlock with MP offline */ async setUserSymKeyMasterKey(value: string, options?: StorageOptions): Promise { - // TODO(Jake): defaultOnDiskOptions? Other's are saved in secure storage const account = await this.getAccount( this.reconcileOptions(options, await this.defaultOnDiskOptions()) );