diff --git a/mRemoteV1/Config/Settings/SettingsLoader.cs b/mRemoteV1/Config/Settings/SettingsLoader.cs index 0680e07dd..d9cc3dbba 100644 --- a/mRemoteV1/Config/Settings/SettingsLoader.cs +++ b/mRemoteV1/Config/Settings/SettingsLoader.cs @@ -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) diff --git a/mRemoteV1/Config/Settings/SettingsSaver.cs b/mRemoteV1/Config/Settings/SettingsSaver.cs index 90be71668..d4943bac8 100644 --- a/mRemoteV1/Config/Settings/SettingsSaver.cs +++ b/mRemoteV1/Config/Settings/SettingsSaver.cs @@ -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(); diff --git a/mRemoteV1/Connection/DefaultConnectionInfo.cs b/mRemoteV1/Connection/DefaultConnectionInfo.cs index 2a23122e7..82eaaad9a 100644 --- a/mRemoteV1/Connection/DefaultConnectionInfo.cs +++ b/mRemoteV1/Connection/DefaultConnectionInfo.cs @@ -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) diff --git a/mRemoteV1/Credential/CredentialRecordTypeConverter.cs b/mRemoteV1/Credential/CredentialRecordTypeConverter.cs new file mode 100644 index 000000000..5276f1b97 --- /dev/null +++ b/mRemoteV1/Credential/CredentialRecordTypeConverter.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/mRemoteV1/Credential/ICredentialRecord.cs b/mRemoteV1/Credential/ICredentialRecord.cs index 82c3b0d2e..035e8386d 100644 --- a/mRemoteV1/Credential/ICredentialRecord.cs +++ b/mRemoteV1/Credential/ICredentialRecord.cs @@ -1,9 +1,11 @@ using System; +using System.ComponentModel; using System.Security; namespace mRemoteNG.Credential { + [TypeConverter(typeof(CredentialRecordTypeConverter))] public interface ICredentialRecord { Guid Id { get; } diff --git a/mRemoteV1/Properties/Settings.Designer.cs b/mRemoteV1/Properties/Settings.Designer.cs index 82b02e183..6e2a2b0f8 100644 --- a/mRemoteV1/Properties/Settings.Designer.cs +++ b/mRemoteV1/Properties/Settings.Designer.cs @@ -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; + } + } } } diff --git a/mRemoteV1/Properties/Settings.settings b/mRemoteV1/Properties/Settings.settings index 95c105d97..db4b8708d 100644 --- a/mRemoteV1/Properties/Settings.settings +++ b/mRemoteV1/Properties/Settings.settings @@ -110,15 +110,6 @@ - - - - - - - - - RDP @@ -593,5 +584,8 @@ False + + 00000000-0000-0000-0000-000000000000 + \ No newline at end of file diff --git a/mRemoteV1/UI/Forms/frmMain.cs b/mRemoteV1/UI/Forms/frmMain.cs index f898a35b2..7212fea0f 100644 --- a/mRemoteV1/UI/Forms/frmMain.cs +++ b/mRemoteV1/UI/Forms/frmMain.cs @@ -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; + } } } \ No newline at end of file diff --git a/mRemoteV1/app.config b/mRemoteV1/app.config index 18b333cfd..e97c4589b 100644 --- a/mRemoteV1/app.config +++ b/mRemoteV1/app.config @@ -142,15 +142,6 @@ - - - - - - - - - RDP @@ -613,6 +604,9 @@ False + + 00000000-0000-0000-0000-000000000000 + diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 15dfd69a5..d3bf3b3de 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -207,6 +207,7 @@ +