saving and loading default credential now works

This commit is contained in:
David Sparer
2017-01-26 16:11:56 -07:00
parent dd9f76f73b
commit bc225f9656
10 changed files with 83 additions and 77 deletions

View File

@@ -46,7 +46,6 @@ namespace mRemoteNG.Config.Settings
SetPuttyPath();
SetShowSystemTrayIcon();
SetAutoSave();
SetConDefaultPassword();
LoadPanelsFromXml();
LoadExternalAppsFromXml();
SetAlwaysShowPanelTabs();
@@ -62,12 +61,6 @@ namespace mRemoteNG.Config.Settings
}
}
private static void SetConDefaultPassword()
{
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
mRemoteNG.Settings.Default.ConDefaultPassword = cryptographyProvider.Decrypt(mRemoteNG.Settings.Default.ConDefaultPassword, Runtime.EncryptionKey);
}
private static void SetAlwaysShowPanelTabs()
{
if (mRemoteNG.Settings.Default.AlwaysShowPanelTabs)

View File

@@ -4,7 +4,6 @@ using System.Text;
using System.Windows.Forms;
using System.Xml;
using mRemoteNG.App.Info;
using mRemoteNG.Security.SymmetricEncryption;
using mRemoteNG.Tools;
using mRemoteNG.UI.Forms;
using static mRemoteNG.App.Runtime;
@@ -60,11 +59,6 @@ namespace mRemoteNG.Config.Settings
mRemoteNG.Settings.Default.QuickyTBParentDock = with1.tsQuickConnect.Parent.Dock.ToString();
}
mRemoteNG.Settings.Default.QuickyTBVisible = with1.tsQuickConnect.Visible;
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
mRemoteNG.Settings.Default.ConDefaultPassword =
cryptographyProvider.Encrypt(Convert.ToString(mRemoteNG.Settings.Default.ConDefaultPassword), EncryptionKey);
mRemoteNG.Settings.Default.Save();
SavePanelsToXML();

View File

@@ -26,15 +26,14 @@ namespace mRemoteNG.Connection
{
var propertyFromSource = typeof(TSource).GetProperty(propertyNameMutator(property.Name));
var valueFromSource = propertyFromSource.GetValue(sourceInstance, null);
var descriptor = TypeDescriptor.GetProperties(Instance)[property.Name];
var converter = descriptor.Converter;
if (converter != null && converter.CanConvertFrom(valueFromSource.GetType()))
property.SetValue(Instance, converter.ConvertFrom(valueFromSource), null);
else
property.SetValue(Instance, valueFromSource, null);
var typeConverter = TypeDescriptor.GetConverter(property.PropertyType);
if (typeConverter.CanConvertFrom(valueFromSource.GetType()))
property.SetValue(Instance, typeConverter.ConvertFrom(valueFromSource), null);
}
catch (Exception ex)
{
Runtime.MessageCollector?.AddExceptionStackTrace($"Error loading default connectioninfo property {property.Name}", ex);
}
catch { }
}
}
@@ -48,7 +47,9 @@ namespace mRemoteNG.Connection
{
var propertyFromDestination = typeof(TDestination).GetProperty(propertyNameMutator(property.Name));
var localValue = property.GetValue(Instance, null);
var convertedValue = Convert.ChangeType(localValue, propertyFromDestination.PropertyType);
var typeConverter = TypeDescriptor.GetConverter(property.PropertyType);
if (!typeConverter.CanConvertTo(propertyFromDestination.PropertyType)) continue;
var convertedValue = typeConverter.ConvertTo(localValue, propertyFromDestination.PropertyType);
propertyFromDestination.SetValue(destinationInstance, convertedValue, null);
}
catch (Exception ex)

View File

@@ -0,0 +1,44 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using mRemoteNG.App;
namespace mRemoteNG.Credential
{
public class CredentialRecordTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(Guid) ||
base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(Guid) ||
destinationType == typeof(ICredentialRecord) ||
base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is ICredentialRecord && destinationType == typeof(Guid))
return ((ICredentialRecord) value).Id;
if (value is ICredentialRecord && destinationType == typeof(ICredentialRecord))
return value;
return base.ConvertTo(context, culture, value, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is Guid)
{
var matchedCredentials = Runtime.CredentialManager.GetCredentialRecords().Where(record => record.Id.Equals(value)).ToArray();
return matchedCredentials.Any() ? matchedCredentials.First() : null;
}
return base.ConvertFrom(context, culture, value);
}
}
}

View File

@@ -1,9 +1,11 @@
using System;
using System.ComponentModel;
using System.Security;
namespace mRemoteNG.Credential
{
[TypeConverter(typeof(CredentialRecordTypeConverter))]
public interface ICredentialRecord
{
Guid Id { get; }

View File

@@ -455,42 +455,6 @@ namespace mRemoteNG {
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ConDefaultUsername {
get {
return ((string)(this["ConDefaultUsername"]));
}
set {
this["ConDefaultUsername"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ConDefaultPassword {
get {
return ((string)(this["ConDefaultPassword"]));
}
set {
this["ConDefaultPassword"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ConDefaultDomain {
get {
return ((string)(this["ConDefaultDomain"]));
}
set {
this["ConDefaultDomain"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("RDP")]
@@ -2386,5 +2350,17 @@ namespace mRemoteNG {
this["InhDefaultCredentialRecord"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")]
public global::System.Guid ConDefaultCredentialRecord {
get {
return ((global::System.Guid)(this["ConDefaultCredentialRecord"]));
}
set {
this["ConDefaultCredentialRecord"] = value;
}
}
}
}

View File

@@ -110,15 +110,6 @@
<Setting Name="ConDefaultDescription" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ConDefaultUsername" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ConDefaultPassword" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ConDefaultDomain" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ConDefaultProtocol" Type="System.String" Scope="User">
<Value Profile="(Default)">RDP</Value>
</Setting>
@@ -593,5 +584,8 @@
<Setting Name="InhDefaultCredentialRecord" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ConDefaultCredentialRecord" Type="System.Guid" Scope="User">
<Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -213,7 +213,7 @@ namespace mRemoteNG.UI.Forms
}
LoadCredentials();
LoadDefaultConnectionCredentials();
Runtime.LoadConnections();
Windows.TreePanel.Focus();
@@ -1355,5 +1355,12 @@ namespace mRemoteNG.UI.Forms
credentialSaver.Save(_credentialManager.GetCredentialRecords(), "tempEncryptionKey".ConvertToSecureString());
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, $"Saved credentials to file: {_credentialFilePath}", true);
}
private void LoadDefaultConnectionCredentials()
{
var defaultCredId = Settings.Default.ConDefaultCredentialRecord;
var matchedCredentials = Runtime.CredentialManager.GetCredentialRecords().Where(record => record.Id.Equals(defaultCredId)).ToArray();
DefaultConnectionInfo.Instance.CredentialRecord = matchedCredentials.Any() ? matchedCredentials.First() : null;
}
}
}

View File

@@ -142,15 +142,6 @@
<setting name="ConDefaultDescription" serializeAs="String">
<value />
</setting>
<setting name="ConDefaultUsername" serializeAs="String">
<value />
</setting>
<setting name="ConDefaultPassword" serializeAs="String">
<value />
</setting>
<setting name="ConDefaultDomain" serializeAs="String">
<value />
</setting>
<setting name="ConDefaultProtocol" serializeAs="String">
<value>RDP</value>
</setting>
@@ -613,6 +604,9 @@
<setting name="InhDefaultCredentialRecord" serializeAs="String">
<value>False</value>
</setting>
<setting name="ConDefaultCredentialRecord" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
</mRemoteNG.Settings>
</userSettings>
<applicationSettings>

View File

@@ -207,6 +207,7 @@
<Compile Include="Credential\CredentialRecord.cs" />
<Compile Include="Credential\CredentialListBase.cs" />
<Compile Include="Credential\CredentialRecordCatalog.cs" />
<Compile Include="Credential\CredentialRecordTypeConverter.cs" />
<Compile Include="Credential\ICredentialRecord.cs" />
<Compile Include="Credential\ICredentialProviderCatalog.cs" />
<Compile Include="Credential\ICredentialProvider.cs" />