tests: vault locking (#2394)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { EncryptionProviderInterface } from './../../Encryption/EncryptionProviderInterface'
|
||||
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { KeySystemPasswordType, VaultListingInterface } from '@standardnotes/models'
|
||||
import { KeySystemKeyManagerInterface } from '../../KeySystem/KeySystemKeyManagerInterface'
|
||||
|
||||
export class ValidateVaultPassword implements SyncUseCaseInterface<boolean> {
|
||||
constructor(
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
) {}
|
||||
|
||||
execute(vault: VaultListingInterface, password: string): Result<boolean> {
|
||||
if (vault.keyPasswordType !== KeySystemPasswordType.UserInputted) {
|
||||
throw new Error('Vault uses randomized password and cannot be validated with password')
|
||||
}
|
||||
|
||||
const rootKey = this.keys.getPrimaryKeySystemRootKey(vault.systemIdentifier)
|
||||
|
||||
if (!rootKey) {
|
||||
return Result.ok(false)
|
||||
}
|
||||
|
||||
const derivedRootKey = this.encryption.deriveUserInputtedKeySystemRootKey({
|
||||
keyParams: vault.rootKeyParams,
|
||||
userInputtedPassword: password,
|
||||
})
|
||||
|
||||
return Result.ok(rootKey.isEqual(derivedRootKey))
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { GetVaultItems } from './../Vault/UseCase/GetVaultItems'
|
||||
import { RemoveItemsFromMemory } from './../Storage/UseCase/RemoveItemsFromMemory'
|
||||
import { GetVaults } from '../Vault/UseCase/GetVaults'
|
||||
import { KeySystemPasswordType, KeySystemRootKeyStorageMode, VaultListingInterface } from '@standardnotes/models'
|
||||
import { VaultLockServiceInterface } from './VaultLockServiceInterface'
|
||||
@@ -22,6 +24,8 @@ export class VaultLockService
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
private _getVaults: GetVaults,
|
||||
private _decryptErroredPayloads: DecryptErroredPayloads,
|
||||
private _removeItemsFromMemory: RemoveItemsFromMemory,
|
||||
private _getVaultItems: GetVaultItems,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
@@ -40,6 +44,8 @@ export class VaultLockService
|
||||
;(this.keys as unknown) = undefined
|
||||
;(this._getVaults as unknown) = undefined
|
||||
;(this._decryptErroredPayloads as unknown) = undefined
|
||||
;(this._removeItemsFromMemory as unknown) = undefined
|
||||
;(this._getVaultItems as unknown) = undefined
|
||||
|
||||
this.lockMap.clear()
|
||||
}
|
||||
@@ -68,6 +74,9 @@ export class VaultLockService
|
||||
|
||||
await this.keys.wipeVaultKeysFromMemory(vault)
|
||||
|
||||
const vaultItems = this._getVaultItems.execute(vault).getValue()
|
||||
await this._removeItemsFromMemory.execute(vaultItems)
|
||||
|
||||
this.lockMap.set(vault.uuid, true)
|
||||
|
||||
void this.notifyEventSync(VaultLockServiceEvent.VaultLocked, { vault })
|
||||
|
||||
Reference in New Issue
Block a user