From 2aa303d17e8457d15d660151477331b418e22d7a Mon Sep 17 00:00:00 2001 From: Jacob Fink Date: Thu, 8 Jun 2023 16:13:25 -0400 Subject: [PATCH] fix crypto calls for key connector and vault timeout settings --- .../src/auth/services/key-connector.service.ts | 17 +++++++++-------- .../vaultTimeoutSettings.service.ts | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/common/src/auth/services/key-connector.service.ts b/libs/common/src/auth/services/key-connector.service.ts index 00f40e3c573..b8c6c807e1d 100644 --- a/libs/common/src/auth/services/key-connector.service.ts +++ b/libs/common/src/auth/services/key-connector.service.ts @@ -45,8 +45,8 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { async migrateUser() { const organization = await this.getManagingOrganization(); - const key = await this.cryptoService.getKey(); - const keyConnectorRequest = new KeyConnectorUserKeyRequest(key.encKeyB64); + const masterKey = await this.cryptoService.getMasterKey(); + const keyConnectorRequest = new KeyConnectorUserKeyRequest(masterKey.encKeyB64); try { await this.apiService.postUserKeyToKeyConnector( @@ -88,17 +88,18 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { const password = await this.cryptoFunctionService.randomBytes(64); const kdfConfig = new KdfConfig(kdfIterations, kdfMemory, kdfParallelism); - const k = await this.cryptoService.makeKey( + const masterKey = await this.cryptoService.makeMasterKey( Utils.fromBufferToB64(password), await this.tokenService.getEmail(), kdf, kdfConfig ); - const keyConnectorRequest = new KeyConnectorUserKeyRequest(k.encKeyB64); - await this.cryptoService.setKey(k); + const keyConnectorRequest = new KeyConnectorUserKeyRequest(masterKey.encKeyB64); + await this.cryptoService.setMasterKey(masterKey); - const encKey = await this.cryptoService.makeEncKey(k); - await this.cryptoService.setEncKey(encKey[1].encryptedString); + const userKey = await this.cryptoService.makeUserSymKey(masterKey); + await this.cryptoService.setUserKey(userKey[0]); + await this.cryptoService.setUserSymKeyMasterKey(userKey[1].encryptedString); const [pubKey, privKey] = await this.cryptoService.makeKeyPair(); @@ -110,7 +111,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { const keys = new KeysRequest(pubKey, privKey.encryptedString); const setPasswordRequest = new SetKeyConnectorKeyRequest( - encKey[1].encryptedString, + userKey[1].encryptedString, kdf, kdfConfig, orgId, diff --git a/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts b/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts index 23d57e923f0..1aef2a4457e 100644 --- a/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts +++ b/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts @@ -113,6 +113,6 @@ export class VaultTimeoutSettingsService implements VaultTimeoutSettingsServiceA await this.stateService.setEverBeenUnlocked(false, { userId: userId }); await this.stateService.setUserSymKeyPinEphemeral(null, { userId: userId }); await this.stateService.setProtectedPin(null, { userId: userId }); - await this.stateService.setDecryptedPinProtected(null, { userId: userId }); + await this.cryptoService.clearOldPinKeys(userId); } }