mirror of
https://github.com/bitwarden/browser
synced 2025-12-30 15:13:32 +00:00
memory stored pinProtectedKey
This commit is contained in:
@@ -110,7 +110,7 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
}
|
||||
|
||||
@sequentialize(() => 'getEncKey')
|
||||
async getEncKey(): Promise<SymmetricCryptoKey> {
|
||||
async getEncKey(key: SymmetricCryptoKey = null): Promise<SymmetricCryptoKey> {
|
||||
if (this.encKey != null) {
|
||||
return this.encKey;
|
||||
}
|
||||
@@ -120,7 +120,9 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
return null;
|
||||
}
|
||||
|
||||
const key = await this.getKey();
|
||||
if (key == null) {
|
||||
key = await this.getKey();
|
||||
}
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -315,13 +317,16 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
return new SymmetricCryptoKey(key);
|
||||
}
|
||||
|
||||
async makeKeyFromPin(pin: string, salt: string, kdf: KdfType, kdfIterations: number):
|
||||
async makeKeyFromPin(pin: string, salt: string, kdf: KdfType, kdfIterations: number,
|
||||
protectedKeyCs: CipherString = null):
|
||||
Promise<SymmetricCryptoKey> {
|
||||
const pinProtectedKey = await this.storageService.get<string>(ConstantsService.pinProtectedKey);
|
||||
if (pinProtectedKey == null) {
|
||||
throw new Error('No PIN protected key found.');
|
||||
if (protectedKeyCs == null) {
|
||||
const pinProtectedKey = await this.storageService.get<string>(ConstantsService.pinProtectedKey);
|
||||
if (pinProtectedKey == null) {
|
||||
throw new Error('No PIN protected key found.');
|
||||
}
|
||||
protectedKeyCs = new CipherString(pinProtectedKey);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -11,8 +11,10 @@ import { SearchService } from '../abstractions/search.service';
|
||||
import { StorageService } from '../abstractions/storage.service';
|
||||
import { UserService } from '../abstractions/user.service';
|
||||
|
||||
import { CipherString } from '../models/domain/cipherString';
|
||||
|
||||
export class LockService implements LockServiceAbstraction {
|
||||
pinLocked = false;
|
||||
pinProtectedKey: CipherString = null;
|
||||
|
||||
private inited = false;
|
||||
|
||||
@@ -37,9 +39,6 @@ export class LockService implements LockServiceAbstraction {
|
||||
|
||||
async isLocked(): Promise<boolean> {
|
||||
const hasKey = await this.cryptoService.hasKey();
|
||||
if (hasKey && this.pinLocked) {
|
||||
return true;
|
||||
}
|
||||
return !hasKey;
|
||||
}
|
||||
|
||||
@@ -85,18 +84,6 @@ export class LockService implements LockServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (allowSoftLock) {
|
||||
const pinSet = await this.isPinLockSet();
|
||||
if (pinSet[0]) {
|
||||
this.pinLocked = true;
|
||||
this.messagingService.send('locked');
|
||||
if (this.lockedCallback != null) {
|
||||
await this.lockedCallback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this.cryptoService.clearKey(),
|
||||
this.cryptoService.clearOrgKeys(true),
|
||||
@@ -126,6 +113,7 @@ export class LockService implements LockServiceAbstraction {
|
||||
}
|
||||
|
||||
clear(): Promise<any> {
|
||||
this.pinProtectedKey = null;
|
||||
return this.storageService.remove(ConstantsService.protectedPin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export class SystemService implements SystemServiceAbstraction {
|
||||
}
|
||||
|
||||
startProcessReload(): void {
|
||||
if (this.lockService.pinLocked || this.reloadInterval != null) {
|
||||
if (this.lockService.pinProtectedKey != null || this.reloadInterval != null) {
|
||||
return;
|
||||
}
|
||||
this.cancelProcessReload();
|
||||
|
||||
Reference in New Issue
Block a user