From d2ca46b6f5bfc5114e89e04a2951eb74e92d4e23 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Mon, 14 Jun 2021 14:03:13 -0500 Subject: [PATCH] Add get key from storage for ensuring biometric browser integration (#408) --- common/src/abstractions/crypto.service.ts | 1 + common/src/services/crypto.service.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/src/abstractions/crypto.service.ts b/common/src/abstractions/crypto.service.ts index 6ebedd3b2c..f26479fe10 100644 --- a/common/src/abstractions/crypto.service.ts +++ b/common/src/abstractions/crypto.service.ts @@ -15,6 +15,7 @@ export abstract class CryptoService { setEncPrivateKey: (encPrivateKey: string) => Promise<{}>; setOrgKeys: (orgs: ProfileOrganizationResponse[]) => Promise<{}>; getKey: (keySuffix?: KeySuffixOptions) => Promise; + getKeyFromStorage: (keySuffix: KeySuffixOptions) => Promise; getKeyHash: () => Promise; getEncKey: (key?: SymmetricCryptoKey) => Promise; getPublicKey: () => Promise; diff --git a/common/src/services/crypto.service.ts b/common/src/services/crypto.service.ts index fd3c129bb1..23330c943d 100644 --- a/common/src/services/crypto.service.ts +++ b/common/src/services/crypto.service.ts @@ -100,7 +100,18 @@ export class CryptoService implements CryptoServiceAbstraction { if (this.key != null) { return this.key; } + keySuffix ||= 'auto'; + const symmetricKey = await this.getKeyFromStorage(keySuffix); + + if (symmetricKey != null) { + this.setKey(symmetricKey); + } + + return symmetricKey; + } + + async getKeyFromStorage(keySuffix: KeySuffixOptions): Promise { const key = await this.retrieveKeyFromStorage(keySuffix); if (key != null) { @@ -112,10 +123,9 @@ export class CryptoService implements CryptoServiceAbstraction { return null; } - this.setKey(symmetricKey); + return symmetricKey; } - - return key == null ? null : this.key; + return null; } async getKeyHash(): Promise {