Files
mRemoteNG/mRemoteV1/Config/Serializers/ConnectionSerializers/Xml/XmlRootNodeSerializer.cs

34 lines
1.8 KiB
C#

using System.Xml.Linq;
using mRemoteNG.Security;
using mRemoteNG.Tree.Root;
namespace mRemoteNG.Config.Serializers.Xml
{
public class XmlRootNodeSerializer
{
public XElement SerializeRootNodeInfo(RootNodeInfo rootNodeInfo, ICryptographyProvider cryptographyProvider, bool fullFileEncryption = false)
{
XNamespace xmlNamespace = "http://mremoteng.org";
var element = new XElement(xmlNamespace + "Connections");
element.Add(new XAttribute(XNamespace.Xmlns+"mrng", xmlNamespace));
element.Add(new XAttribute(XName.Get("Name"), rootNodeInfo.Name));
element.Add(new XAttribute(XName.Get("Export"), "false"));
element.Add(new XAttribute(XName.Get("EncryptionEngine"), cryptographyProvider.CipherEngine));
element.Add(new XAttribute(XName.Get("BlockCipherMode"), cryptographyProvider.CipherMode));
element.Add(new XAttribute(XName.Get("KdfIterations"), cryptographyProvider.KeyDerivationIterations));
element.Add(new XAttribute(XName.Get("FullFileEncryption"), fullFileEncryption.ToString().ToLowerInvariant()));
element.Add(CreateProtectedAttribute(rootNodeInfo, cryptographyProvider));
element.Add(new XAttribute(XName.Get("ConfVersion"), "2.6"));
return element;
}
private XAttribute CreateProtectedAttribute(RootNodeInfo rootNodeInfo, ICryptographyProvider cryptographyProvider)
{
var attribute = new XAttribute(XName.Get("Protected"), "");
var plainText = rootNodeInfo.Password ? "ThisIsProtected" : "ThisIsNotProtected";
var encryptionPassword = rootNodeInfo.PasswordString.ConvertToSecureString();
attribute.Value = cryptographyProvider.Encrypt(plainText, encryptionPassword);
return attribute;
}
}
}