diff --git a/src/abstractions/crypto.service.ts b/src/abstractions/crypto.service.ts index 889500c40f..3ee45f1bc1 100644 --- a/src/abstractions/crypto.service.ts +++ b/src/abstractions/crypto.service.ts @@ -30,6 +30,7 @@ export abstract class CryptoService { clearKeys: () => Promise; toggleKey: () => Promise; makeKey: (password: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise; + makeKeyFromPin: (pin: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise; makeShareKey: () => Promise<[CipherString, SymmetricCryptoKey]>; makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, CipherString]>; makePinKey: (pin: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise; diff --git a/src/angular/components/lock.component.ts b/src/angular/components/lock.component.ts index 419124f038..31493ac872 100644 --- a/src/angular/components/lock.component.ts +++ b/src/angular/components/lock.component.ts @@ -66,12 +66,9 @@ export class LockComponent implements OnInit { this.doContinue(); } } else { - const pinProtectedKey = await this.storageService.get(ConstantsService.pinProtectedKey); - const protectedKeyCs = new CipherString(pinProtectedKey); - const pinKey = await this.cryptoService.makePinKey(this.pin, this.email, kdf, kdfIterations); - const decKey = await this.cryptoService.decryptToBytes(protectedKeyCs, pinKey); + const key = await this.cryptoService.makeKeyFromPin(this.pin, this.email, kdf, kdfIterations); failed = false; - await this.setKeyAndContinue(new SymmetricCryptoKey(decKey)); + await this.setKeyAndContinue(key); } } catch { failed = true; diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 865ec3bfc1..b2da1ce532 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -310,6 +310,18 @@ export class CryptoService implements CryptoServiceAbstraction { return new SymmetricCryptoKey(key); } + async makeKeyFromPin(pin: string, salt: string, kdf: KdfType, kdfIterations: number): + Promise { + const pinProtectedKey = await this.storageService.get(ConstantsService.pinProtectedKey); + if (pinProtectedKey == null) { + throw new Error('No PIN protected key found.'); + } + const protectedKeyCs = new CipherString(pinProtectedKey); + const pinKey = await this.makePinKey(pin, salt, kdf, kdfIterations); + const decKey = await this.decryptToBytes(protectedKeyCs, pinKey); + return new SymmetricCryptoKey(decKey); + } + async makeShareKey(): Promise<[CipherString, SymmetricCryptoKey]> { const shareKey = await this.cryptoFunctionService.randomBytes(64); const publicKey = await this.getPublicKey();