From 711d643d6872c9dafb7a174c7b61d9bb1af88b31 Mon Sep 17 00:00:00 2001 From: Jacob Fink Date: Tue, 30 May 2023 11:24:12 -0400 Subject: [PATCH] add new memory concept to crypto service calls in cli --- apps/cli/src/auth/commands/login.command.ts | 9 ++++++--- apps/cli/src/vault/create.command.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/cli/src/auth/commands/login.command.ts b/apps/cli/src/auth/commands/login.command.ts index 764827259b8..3ecf7f94a2f 100644 --- a/apps/cli/src/auth/commands/login.command.ts +++ b/apps/cli/src/auth/commands/login.command.ts @@ -475,8 +475,8 @@ export class LoginCommand { /** * Collect new master password and hint from the CLI. The collected password - * is validated against any applicable master password policies and a new encryption - * key is generated + * is validated against any applicable master password policies, a new master + * key is generated, and we use it to re-encrypt the user symmetric key * @param prompt - Message that is displayed during the initial prompt * @param error */ @@ -576,7 +576,10 @@ export class LoginCommand { const newPasswordHash = await this.cryptoService.hashPassword(masterPassword, newMasterKey); // Grab user's symmetric key - const userSymKey = await this.cryptoService.getUserKey(); + const userSymKey = await this.cryptoService.getUserKeyFromMemory(); + if (!userSymKey) { + throw new Error("User key not found."); + } // Re-encrypt user's symmetric key with new master key const newUserSymKey = await this.cryptoService.encryptUserSymKeyWithMasterKey( diff --git a/apps/cli/src/vault/create.command.ts b/apps/cli/src/vault/create.command.ts index 7f3c31bb8aa..2927f6867f9 100644 --- a/apps/cli/src/vault/create.command.ts +++ b/apps/cli/src/vault/create.command.ts @@ -126,7 +126,7 @@ export class CreateCommand { return Response.error("Premium status is required to use this feature."); } - const userSymKey = await this.cryptoService.getUserKey(); + const userSymKey = await this.cryptoService.getUserKeyFromMemory(); if (userSymKey == null) { return Response.error( "You must update your encryption key before you can use this feature. " +