mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-24 12:06:15 +01:00
hasKey helper
This commit is contained in:
parent
6aa922f380
commit
eda99e4f12
@ -15,6 +15,7 @@ export abstract class CryptoService {
|
||||
getPrivateKey: () => Promise<ArrayBuffer>;
|
||||
getOrgKeys: () => Promise<Map<string, SymmetricCryptoKey>>;
|
||||
getOrgKey: (orgId: string) => Promise<SymmetricCryptoKey>;
|
||||
hasKey: () => Promise<boolean>;
|
||||
clearKey: () => Promise<any>;
|
||||
clearKeyHash: () => Promise<any>;
|
||||
clearEncKey: (memoryOnly?: boolean) => Promise<any>;
|
||||
|
@ -192,6 +192,10 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
return orgKeys.get(orgId);
|
||||
}
|
||||
|
||||
async hasKey(): Promise<boolean> {
|
||||
return (await this.getKey()) != null;
|
||||
}
|
||||
|
||||
clearKey(): Promise<any> {
|
||||
this.key = this.legacyEtmKey = null;
|
||||
return this.secureStorageService.remove(Keys.key);
|
||||
@ -282,13 +286,6 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
*/
|
||||
}
|
||||
|
||||
async stretchKey(key: SymmetricCryptoKey): Promise<SymmetricCryptoKey> {
|
||||
const newKey = new Uint8Array(64);
|
||||
newKey.set(await this.hkdfExpand(key.key, Utils.fromUtf8ToArray('enc'), 32));
|
||||
newKey.set(await this.hkdfExpand(key.key, Utils.fromUtf8ToArray('mac'), 32), 32);
|
||||
return new SymmetricCryptoKey(newKey.buffer);
|
||||
}
|
||||
|
||||
async encrypt(plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey): Promise<CipherString> {
|
||||
if (plainValue == null) {
|
||||
return Promise.resolve(null);
|
||||
@ -594,6 +591,13 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
return key;
|
||||
}
|
||||
|
||||
private async stretchKey(key: SymmetricCryptoKey): Promise<SymmetricCryptoKey> {
|
||||
const newKey = new Uint8Array(64);
|
||||
newKey.set(await this.hkdfExpand(key.key, Utils.fromUtf8ToArray('enc'), 32));
|
||||
newKey.set(await this.hkdfExpand(key.key, Utils.fromUtf8ToArray('mac'), 32), 32);
|
||||
return new SymmetricCryptoKey(newKey.buffer);
|
||||
}
|
||||
|
||||
// ref: https://tools.ietf.org/html/rfc5869
|
||||
private async hkdfExpand(prk: ArrayBuffer, info: Uint8Array, size: number) {
|
||||
const hashLen = 32; // sha256
|
||||
|
Loading…
Reference in New Issue
Block a user