1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

makeKeyFromPin in background context

This commit is contained in:
Kyle Spearrin
2019-03-05 16:36:11 -05:00
parent 39f3a0788d
commit cc27f98aae
3 changed files with 15 additions and 5 deletions

View File

@@ -310,6 +310,18 @@ export class CryptoService implements CryptoServiceAbstraction {
return new SymmetricCryptoKey(key);
}
async makeKeyFromPin(pin: string, salt: string, kdf: KdfType, kdfIterations: number):
Promise<SymmetricCryptoKey> {
const pinProtectedKey = await this.storageService.get<string>(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();