public DatabaseSettingsViewModel(IDatabaseSettingsProvider settingsProvider) { this.settingsProvider = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider)); if (KdfGuid.Equals(AesParameters.AesUuid)) { this._aesParams = this.settingsProvider.KdfParameters as AesParameters; DebugHelper.Assert(this._aesParams != null); this._argonParams = new Argon2Parameters(2, 64, 100); } else { DebugHelper.Assert(KdfGuid.Equals(Argon2Parameters.Argon2Uuid)); this._argonParams = this.settingsProvider.KdfParameters as Argon2Parameters; DebugHelper.Assert(this._argonParams != null); this._aesParams = new AesParameters(6000); } }
public async Task UpgradeCipherSettings() { DateTime lastPasswordChange = this.document.Metadata.MasterKeyChanged.Value; Assert.AreEqual(EncryptionAlgorithm.Aes, this.settingsVm.Cipher, "AES should be the encryption algorithm before the test starts"); this.writer.Cipher = EncryptionAlgorithm.ChaCha20; Assert.IsInstanceOfType(this.settingsVm.GetKdfParameters(), typeof(AesParameters), "AES should be the KDF before the test starts according to the VM"); Assert.IsInstanceOfType(this.writer.KdfParameters, typeof(AesParameters), "AES should be the KDF before the test starts according to the KdbxWriter"); this.settingsVm.KdfGuid = Argon2Parameters.Argon2Uuid; this.settingsVm.ArgonParallelism = 3; this.settingsVm.ArgonBlockCount = 24; this.settingsVm.KdfIterations = 2; Assert.IsInstanceOfType(this.writer.KdfParameters, typeof(Argon2Parameters), "Changes to the settings VM should be reflected in the KdbxWriter"); Assert.IsTrue(await this.persistenceService.Save(this.document)); KdbxReader reader = new KdbxReader(); using (IRandomAccessStream stream = await this.saveFile.AsIStorageFile.OpenReadAsync()) { await reader.ReadHeaderAsync(stream, CancellationToken.None); Assert.AreEqual(EncryptionAlgorithm.ChaCha20, reader.HeaderData.Cipher, "New reader should have the correct cipher"); Argon2Parameters argonParams = reader.HeaderData.KdfParameters as Argon2Parameters; Assert.IsNotNull(argonParams, "Database should have properly persisted with Argon2"); Assert.AreEqual(3, (int)argonParams.Parallelism, "Argon2 parallelism should have been persisted correctly"); Assert.AreEqual(24, (int)argonParams.BlockCount, "Argon2 block count should have been persisted correctly"); Assert.AreEqual(2, (int)argonParams.Iterations, "Argon2 iteration count should have been persisted correctly"); KdbxDecryptionResult decryption = await reader.DecryptFileAsync(stream, this.dbPassword, this.dbKeyFile, CancellationToken.None); Assert.AreEqual(KdbxParserCode.Success, decryption.Result.Code); KdbxDocument document = decryption.GetDocument(); Assert.AreEqual(lastPasswordChange, document.Metadata.MasterKeyChanged.Value, "MasterKeyChanged timestamp should not have changed"); } }
public static IPBKDFArgon2NotBuiltIn CreatePBKDFArgon2(byte[] password, Argon2Parameters parameters) => new PBKDFArgon2NotBuiltIn(password, parameters);