public void SerializeThenDeserialize() { var serializedContent = _serializer.Serialize(_originalModel); var deserializedModel = _deserializer.Deserialize(serializedContent); var nodeNamesFromDeserializedModel = deserializedModel.GetRecursiveChildList().Select(node => node.Name); var nodeNamesFromOriginalModel = _originalModel.GetRecursiveChildList().Select(node => node.Name); Assert.That(nodeNamesFromDeserializedModel, Is.EquivalentTo(nodeNamesFromOriginalModel)); }
public void ChildNestingSerializedCorrectly() { var serializedConnections = _serializer.Serialize(_connectionTreeModel); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(serializedConnections); var nodeCon4 = xmlDoc.DocumentElement?.SelectSingleNode("Node[@Name='folder2']/Node[@Name='folder3']/Node[@Name='con4']"); Assert.That(nodeCon4, Is.Not.Null); }
public void SerializeThenDeserialize() { var originalModel = SetupConnectionTreeModel(); var serializedContent = _serializer.Serialize(originalModel); _deserializer = new XmlConnectionsDeserializer(serializedContent); var deserializedModel = _deserializer.Deserialize(); var nodeNamesFromDeserializedModel = deserializedModel.GetRecursiveChildList().Select(node => node.Name); var nodeNamesFromOriginalModel = originalModel.GetRecursiveChildList().Select(node => node.Name); Assert.That(nodeNamesFromDeserializedModel, Is.EquivalentTo(nodeNamesFromOriginalModel)); }
public void Save(ConnectionTreeModel connectionTreeModel, string propertyNameTrigger = "") { try { var cryptographyProvider = new CryptoProviderFactoryFromSettings().Build(); var connectionNodeSerializer = new XmlConnectionNodeSerializer27( cryptographyProvider, connectionTreeModel .RootNodes.OfType <RootNodeInfo>() .First().PasswordString .ConvertToSecureString(), _saveFilter); var xmlConnectionsSerializer = new XmlConnectionsSerializer(cryptographyProvider, connectionNodeSerializer) { UseFullEncryption = mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile }; var xml = xmlConnectionsSerializer.Serialize(connectionTreeModel); var fileDataProvider = new FileDataProviderWithRollingBackup(_connectionFileName); fileDataProvider.Save(xml); } catch (Exception ex) { Runtime.MessageCollector?.AddExceptionStackTrace("SaveToXml failed", ex); } }
public void ValidateSchema() { var sb = new StringBuilder(); var xml = _serializer.Serialize(_connectionTreeModel); var schemaFileName = $"mremoteng_confcons_v{_serializer.Version.Major}_{_serializer.Version.Minor}.xsd"; var schemaFile = GetTargetPath(schemaFileName); _xmlReaderSettings.Schemas.Add("http://mremoteng.org", schemaFile); _xmlReaderSettings.ValidationEventHandler += (sender, args) => { sb.AppendLine($"{args.Severity}: {args.Message}"); }; using (var stream = GenerateStreamFromString(xml)) { var reader = XmlReader.Create(stream, _xmlReaderSettings); while (reader.Read()) { ; } } Assert.That(sb.ToString(), Is.Empty); }
public void SerializeAndDeserializeWithCustomKdfIterationsValue() { var cryptoProvider = new CryptographyProviderFactory().CreateAeadCryptographyProvider(BlockCipherEngines.AES, BlockCipherModes.GCM); cryptoProvider.KeyDerivationIterations = 5000; _serializer = new XmlConnectionsSerializer(cryptoProvider); var originalModel = SetupConnectionTreeModel(); var serializedContent = _serializer.Serialize(originalModel); _deserializer = new XmlConnectionsDeserializer(serializedContent); var deserializedModel = _deserializer.Deserialize(); var nodeNamesFromDeserializedModel = deserializedModel.GetRecursiveChildList().Select(node => node.Name); var nodeNamesFromOriginalModel = originalModel.GetRecursiveChildList().Select(node => node.Name); Assert.That(nodeNamesFromDeserializedModel, Is.EquivalentTo(nodeNamesFromOriginalModel)); }
private XDocument CreateTestData(ConnectionInfo connectionInfo) { var rootNode = new RootNodeInfo(RootNodeType.Connection) { PasswordString = _key.ConvertToUnsecureString() }; rootNode.AddChild(connectionInfo); var nodeSerializer = new XmlConnectionNodeSerializer27(_cryptographyProvider, _key, new SaveFilter()); var serializer = new XmlConnectionsSerializer(_cryptographyProvider, nodeSerializer); var serializedData = serializer.Serialize(rootNode); return(XDocument.Parse(serializedData)); }
public void SerializerRespectsSaveFilterSettings(string attributeName, string expectedValue) { var connectionNodeSerializer = new XmlConnectionNodeSerializer27( _cryptographyProvider, _connectionTreeModel.RootNodes.OfType <RootNodeInfo>().First().PasswordString.ConvertToSecureString(), new SaveFilter(true)); var serializer = new XmlConnectionsSerializer(_cryptographyProvider, connectionNodeSerializer); var connectionInfo = new ConnectionInfo { Name = "myConnection", Inheritance = { AutomaticResize = true } }; var serializedConnections = serializer.Serialize(connectionInfo); var xdoc = XDocument.Parse(serializedConnections); var attributeValue = xdoc.Root?.Element("Node")?.Attribute(attributeName)?.Value; Assert.That(attributeValue, Is.EqualTo(expectedValue)); }
public void SerializeAndDeserializeWithCustomKdfIterationsValue() { var cryptoProvider = _cryptoFactory.Build(); cryptoProvider.KeyDerivationIterations = 5000; var nodeSerializer = new XmlConnectionNodeSerializer27( cryptoProvider, _originalModel.RootNodes.OfType <RootNodeInfo>().First().PasswordString.ConvertToSecureString(), new SaveFilter()); _serializer = new XmlConnectionsSerializer(cryptoProvider, nodeSerializer); var serializedContent = _serializer.Serialize(_originalModel); var deserializedModel = _deserializer.Deserialize(serializedContent); var nodeNamesFromDeserializedModel = deserializedModel.GetRecursiveChildList().Select(node => node.Name); var nodeNamesFromOriginalModel = _originalModel.GetRecursiveChildList().Select(node => node.Name); Assert.That(nodeNamesFromDeserializedModel, Is.EquivalentTo(nodeNamesFromOriginalModel)); }
private void SaveToXml() { try { var xmlConnectionsSerializer = new XmlConnectionsSerializer() { Export = Export, SaveSecurity = SaveSecurity }; var xml = xmlConnectionsSerializer.Serialize(ConnectionTreeModel); var fileDataProvider = new FileDataProviderWithBackup(ConnectionFileName); fileDataProvider.Save(xml); } catch (Exception ex) { Runtime.MessageCollector.AddExceptionStackTrace("SaveToXml failed", ex); } }
private void SaveToXml() { try { var xmlConnectionsSerializer = new XmlConnectionsSerializer() { Export = Export, SaveFilter = SaveFilter, UseFullEncryption = mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile }; var xml = xmlConnectionsSerializer.Serialize(ConnectionTreeModel); var fileDataProvider = new FileDataProviderWithBackup(ConnectionFileName); fileDataProvider.Save(xml); } catch (Exception ex) { Runtime.MessageCollector.AddExceptionStackTrace("SaveToXml failed", ex); } }
private void SaveToXml() { try { 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, SaveFilter = SaveFilter, UseFullEncryption = mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile }; var xml = xmlConnectionsSerializer.Serialize(ConnectionTreeModel); var fileDataProvider = new FileDataProviderWithBackup(ConnectionFileName); fileDataProvider.Save(xml); } catch (Exception ex) { Runtime.MessageCollector.AddExceptionStackTrace("SaveToXml failed", ex); } }