The XmlConnectionsSerializer now looks to its crypto provider for the value of KdfIterations. This insulates the function from global state (Settings)

This commit is contained in:
David Sparer
2016-10-19 18:00:14 -06:00
parent 98db923ac7
commit e11413eab8
4 changed files with 18 additions and 1 deletions

View File

@@ -70,6 +70,21 @@ namespace mRemoteNGTests.Config.Serializers
Assert.That(serializedEncryptionMode, Is.EqualTo(expectedModeAsString));
}
[TestCase(1000)]
[TestCase(1001)]
[TestCase(9999)]
[TestCase(10000)]
public void KeyDerivationIterationsSerialized(int kdfIterations)
{
var encryptor = new AeadCryptographyProvider {KeyDerivationIterations = kdfIterations};
_serializer = new XmlConnectionsSerializer(encryptor);
var serializedData = _serializer.Serialize(new ConnectionInfo());
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(serializedData);
var serializedIterations = xmlDoc.DocumentElement?.Attributes["KdfIterations"].Value;
Assert.That(serializedIterations, Is.EqualTo(kdfIterations.ToString()));
}
private ConnectionTreeModel SetupConnectionTreeModel()
{
/*

View File

@@ -75,6 +75,7 @@ namespace mRemoteNG.App
case ConnectionsSaver.Format.mRXML:
var factory = new CryptographyProviderFactory();
var cryptographyProvider = factory.CreateAeadCryptographyProvider(mRemoteNG.Settings.Default.EncryptionEngine, mRemoteNG.Settings.Default.EncryptionBlockCipherMode);
cryptographyProvider.KeyDerivationIterations = Settings.Default.EncryptionKeyDerivationIterations;
serializer = new XmlConnectionsSerializer(cryptographyProvider);
((XmlConnectionsSerializer) serializer).SaveFilter = saveFilter;
break;

View File

@@ -235,6 +235,7 @@ namespace mRemoteNG.Config.Connections
{
var factory = new CryptographyProviderFactory();
var cryptographyProvider = factory.CreateAeadCryptographyProvider(mRemoteNG.Settings.Default.EncryptionEngine, mRemoteNG.Settings.Default.EncryptionBlockCipherMode);
cryptographyProvider.KeyDerivationIterations = mRemoteNG.Settings.Default.EncryptionKeyDerivationIterations;
var xmlConnectionsSerializer = new XmlConnectionsSerializer(cryptographyProvider)
{
Export = Export,

View File

@@ -154,7 +154,7 @@ namespace mRemoteNG.Config.Serializers
_xmlTextWriter.WriteAttributeString("EncryptionEngine", "", cipherEngine ?? "");
var cipherMode = Enum.GetName(typeof(BlockCipherModes), _cryptographyProvider.CipherMode);
_xmlTextWriter.WriteAttributeString("BlockCipherMode", "", cipherMode ?? "");
_xmlTextWriter.WriteAttributeString("KdfIterations", "", mRemoteNG.Settings.Default.EncryptionKeyDerivationIterations.ToString());
_xmlTextWriter.WriteAttributeString("KdfIterations", "", _cryptographyProvider.KeyDerivationIterations.ToString());
_xmlTextWriter.WriteAttributeString("FullFileEncryption", "", UseFullEncryption.ToString());
if (Export)