makeKeyFromPin in background context
This commit is contained in:
parent
39f3a0788d
commit
cc27f98aae
|
@ -30,6 +30,7 @@ export abstract class CryptoService {
|
||||||
clearKeys: () => Promise<any>;
|
clearKeys: () => Promise<any>;
|
||||||
toggleKey: () => Promise<any>;
|
toggleKey: () => Promise<any>;
|
||||||
makeKey: (password: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise<SymmetricCryptoKey>;
|
makeKey: (password: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise<SymmetricCryptoKey>;
|
||||||
|
makeKeyFromPin: (pin: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise<SymmetricCryptoKey>;
|
||||||
makeShareKey: () => Promise<[CipherString, SymmetricCryptoKey]>;
|
makeShareKey: () => Promise<[CipherString, SymmetricCryptoKey]>;
|
||||||
makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, CipherString]>;
|
makeKeyPair: (key?: SymmetricCryptoKey) => Promise<[string, CipherString]>;
|
||||||
makePinKey: (pin: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise<SymmetricCryptoKey>;
|
makePinKey: (pin: string, salt: string, kdf: KdfType, kdfIterations: number) => Promise<SymmetricCryptoKey>;
|
||||||
|
|
|
@ -66,12 +66,9 @@ export class LockComponent implements OnInit {
|
||||||
this.doContinue();
|
this.doContinue();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const pinProtectedKey = await this.storageService.get<string>(ConstantsService.pinProtectedKey);
|
const key = await this.cryptoService.makeKeyFromPin(this.pin, this.email, kdf, kdfIterations);
|
||||||
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);
|
|
||||||
failed = false;
|
failed = false;
|
||||||
await this.setKeyAndContinue(new SymmetricCryptoKey(decKey));
|
await this.setKeyAndContinue(key);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
failed = true;
|
failed = true;
|
||||||
|
|
|
@ -310,6 +310,18 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||||
return new SymmetricCryptoKey(key);
|
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]> {
|
async makeShareKey(): Promise<[CipherString, SymmetricCryptoKey]> {
|
||||||
const shareKey = await this.cryptoFunctionService.randomBytes(64);
|
const shareKey = await this.cryptoFunctionService.randomBytes(64);
|
||||||
const publicKey = await this.getPublicKey();
|
const publicKey = await this.getPublicKey();
|
||||||
|
|
Loading…
Reference in New Issue