mirror of
https://github.com/bitwarden/jslib
synced 2026-01-07 11:03:13 +00:00
[bug] Remove keySuffix storage option and split uses into unique methods
The keySuffix options don't work with saving serialized json as a storage object - use cases simply overwrite each other in state. This commit breaks Auto and Biometric keys into distinct storage items and adjusts logic accordingly.
This commit is contained in:
@@ -6,6 +6,7 @@ import { StateService } from 'jslib-common/abstractions/state.service';
|
||||
import { CryptoService } from 'jslib-common/services/crypto.service';
|
||||
|
||||
import { KeySuffixOptions } from 'jslib-common/enums/keySuffixOptions';
|
||||
import { StorageLocation } from 'jslib-common/enums/storageLocation';
|
||||
|
||||
export class ElectronCryptoService extends CryptoService {
|
||||
|
||||
@@ -30,7 +31,7 @@ export class ElectronCryptoService extends CryptoService {
|
||||
*/
|
||||
private async upgradeSecurelyStoredKey() {
|
||||
// attempt key upgrade, but if we fail just delete it. Keys will be stored property upon unlock anyway.
|
||||
const key = await this.stateService.getCryptoMasterKey();
|
||||
const key = await this.stateService.getCryptoMasterKey({ storageLocation: StorageLocation.Disk, useSecureStorage: true });
|
||||
|
||||
if (key == null) {
|
||||
return;
|
||||
@@ -38,16 +39,16 @@ export class ElectronCryptoService extends CryptoService {
|
||||
|
||||
try {
|
||||
if (await this.shouldStoreKey(KeySuffixOptions.Auto)) {
|
||||
await this.stateService.getCryptoMasterKeyB64({ keySuffix: KeySuffixOptions.Auto });
|
||||
await this.stateService.setCryptoMasterKeyAuto(key);
|
||||
}
|
||||
if (await this.shouldStoreKey(KeySuffixOptions.Biometric)) {
|
||||
await this.stateService.getCryptoMasterKey({ keySuffix: KeySuffixOptions.Biometric });
|
||||
await this.stateService.setCryptoMasterKeyBiometric(key);
|
||||
}
|
||||
} catch (e) {
|
||||
this.logService.error(`Encountered error while upgrading obsolete Bitwarden secure storage item:`);
|
||||
this.logService.error(e);
|
||||
}
|
||||
|
||||
await this.stateService.setCryptoMasterKey(null);
|
||||
await this.stateService.setCryptoMasterKey(null, { storageLocation: StorageLocation.Disk, useSecureStorage: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
const val = ipcRenderer.sendSync('keytar', {
|
||||
action: 'getPassword',
|
||||
key: key,
|
||||
keySuffix: options?.keySuffix ?? '',
|
||||
});
|
||||
return Promise.resolve(val != null ? JSON.parse(val) as T : null);
|
||||
}
|
||||
@@ -18,7 +17,6 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
const val = ipcRenderer.sendSync('keytar', {
|
||||
action: 'hasPassword',
|
||||
key: key,
|
||||
keySuffix: options?.keySuffix ?? '',
|
||||
});
|
||||
return Promise.resolve(!!val);
|
||||
}
|
||||
@@ -27,7 +25,6 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
ipcRenderer.sendSync('keytar', {
|
||||
action: 'setPassword',
|
||||
key: key,
|
||||
keySuffix: options?.keySuffix ?? '',
|
||||
value: JSON.stringify(obj),
|
||||
});
|
||||
return Promise.resolve();
|
||||
@@ -37,7 +34,6 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
ipcRenderer.sendSync('keytar', {
|
||||
action: 'deletePassword',
|
||||
key: key,
|
||||
keySuffix: options?.keySuffix ?? '',
|
||||
});
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user