when decrypting xml cred repos, we must be able to decrypt the auth header

This commit is contained in:
David Sparer
2017-04-14 15:09:30 -06:00
parent 37b9e46e96
commit 4fa68e3bb0

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Security;
using System.Xml.Linq;
using mRemoteNG.Credential;
using mRemoteNG.Security;
using mRemoteNG.Security.Factories;
namespace mRemoteNG.Config.Serializers.CredentialSerializer
@@ -30,6 +31,7 @@ namespace mRemoteNG.Config.Serializers.CredentialSerializer
if (string.IsNullOrEmpty(xml)) return xml;
var xdoc = XDocument.Parse(xml);
var cryptoProvider = new CryptoProviderFactoryFromXml(xdoc.Root).Build();
DecryptAuthHeader(xdoc.Root, cryptoProvider, key);
foreach (var credentialElement in xdoc.Descendants())
{
var passwordAttribute = credentialElement.Attribute("Password");
@@ -39,5 +41,13 @@ namespace mRemoteNG.Config.Serializers.CredentialSerializer
}
return xdoc.ToString();
}
private void DecryptAuthHeader(XElement rootElement, ICryptographyProvider cryptographyProvider, SecureString key)
{
var authAttribute = rootElement.Attribute("Auth");
if (authAttribute == null)
throw new EncryptionException("Could not find Auth header in the XML repository root element.");
cryptographyProvider.Decrypt(authAttribute.Value, key);
}
}
}