diff --git a/mRemoteNG/Connection/Protocol/PuttyBase.cs b/mRemoteNG/Connection/Protocol/PuttyBase.cs index a3240f621..e2577d64e 100644 --- a/mRemoteNG/Connection/Protocol/PuttyBase.cs +++ b/mRemoteNG/Connection/Protocol/PuttyBase.cs @@ -79,13 +79,16 @@ namespace mRemoteNG.Connection.Protocol if (PuttyProtocol == Putty_Protocol.ssh) { - var username = ""; - var password = ""; + + var username = InterfaceControl.Info?.Username ?? ""; + var password = InterfaceControl.Info?.Password ?? ""; + var domain = InterfaceControl.Info?.Domain ?? ""; + var UserViaAPI = InterfaceControl.Info?.UserViaAPI ?? ""; + // access secret server api if necessary - if (!string.IsNullOrEmpty(InterfaceControl.Info?.UserViaAPI)) - { - var domain = ""; // dummy + if (!string.IsNullOrEmpty(UserViaAPI)) { + try { ExternalConnectors.TSS.SecretServerInterface.FetchSecretFromServer("SSAPI:" + InterfaceControl.Info?.UserViaAPI, out username, out password, out domain); @@ -95,29 +98,34 @@ namespace mRemoteNG.Connection.Protocol Event_ErrorOccured(this, "Secret Server Interface Error: " + ex.Message, 0); } } - if (!string.IsNullOrEmpty(InterfaceControl.Info?.Username)) + + if (string.IsNullOrEmpty(username)) { - username = InterfaceControl.Info.Username; - } - else - { - // ReSharper disable once SwitchStatementMissingSomeCases switch (Settings.Default.EmptyCredentials) { case "windows": username = Environment.UserName; break; - case "custom": + case "custom" when !string.IsNullOrEmpty(Settings.Default.DefaultUsername): username = Settings.Default.DefaultUsername; break; + case "custom": + try + { + ExternalConnectors.TSS.SecretServerInterface.FetchSecretFromServer( + "SSAPI:" + Settings.Default.UserViaAPDefault, out username, out password, + out domain); + } + catch (Exception ex) + { + Event_ErrorOccured(this, "Secret Server Interface Error: " + ex.Message, 0); + } + break; } } + - if (!string.IsNullOrEmpty(InterfaceControl.Info?.Password)) - { - password = InterfaceControl.Info.Password; - } - else + if (string.IsNullOrEmpty(password)) { if (Settings.Default.EmptyCredentials == "custom") { diff --git a/mRemoteNG/Connection/Protocol/RDP/RdpProtocol6.cs b/mRemoteNG/Connection/Protocol/RDP/RdpProtocol6.cs index 9daf084d1..138732b40 100644 --- a/mRemoteNG/Connection/Protocol/RDP/RdpProtocol6.cs +++ b/mRemoteNG/Connection/Protocol/RDP/RdpProtocol6.cs @@ -463,9 +463,10 @@ namespace mRemoteNG.Connection.Protocol.RDP var userName = connectionInfo?.Username ?? ""; var password = connectionInfo?.Password ?? ""; var domain = connectionInfo?.Domain ?? ""; + var UserViaAPI = connectionInfo?.UserViaAPI ?? ""; // access secret server api if necessary - if (!string.IsNullOrEmpty(connectionInfo?.UserViaAPI)) + if (!string.IsNullOrEmpty(UserViaAPI)) { try { @@ -480,13 +481,26 @@ namespace mRemoteNG.Connection.Protocol.RDP if (string.IsNullOrEmpty(userName)) { - if (Settings.Default.EmptyCredentials == "windows") + switch (Settings.Default.EmptyCredentials) { - _rdpClient.UserName = Environment.UserName; - } - else if (Settings.Default.EmptyCredentials == "custom") - { - _rdpClient.UserName = Settings.Default.DefaultUsername; + case "windows": + _rdpClient.UserName = Environment.UserName; + break; + case "custom" when !string.IsNullOrEmpty(Settings.Default.DefaultUsername): + _rdpClient.UserName = Settings.Default.DefaultUsername; + break; + case "custom": + try + { + ExternalConnectors.TSS.SecretServerInterface.FetchSecretFromServer("SSAPI:" + Settings.Default.UserViaAPDefault, out userName, out password, out domain); + _rdpClient.UserName = userName; + } + catch (Exception ex) + { + Event_ErrorOccured(this, "Secret Server Interface Error: " + ex.Message, 0); + } + + break; } } else @@ -513,14 +527,12 @@ namespace mRemoteNG.Connection.Protocol.RDP if (string.IsNullOrEmpty(domain)) { - if (Settings.Default.EmptyCredentials == "windows") + _rdpClient.Domain = Settings.Default.EmptyCredentials switch { - _rdpClient.Domain = Environment.UserDomainName; - } - else if (Settings.Default.EmptyCredentials == "custom") - { - _rdpClient.Domain = Settings.Default.DefaultDomain; - } + "windows" => Environment.UserDomainName, + "custom" => Settings.Default.DefaultDomain, + _ => _rdpClient.Domain + }; } else { diff --git a/mRemoteNG/Properties/Settings.Designer.cs b/mRemoteNG/Properties/Settings.Designer.cs index 0761bdf3f..f439c9e42 100644 --- a/mRemoteNG/Properties/Settings.Designer.cs +++ b/mRemoteNG/Properties/Settings.Designer.cs @@ -3274,5 +3274,17 @@ namespace mRemoteNG.Properties { this["ConDefaultRDPStartProgramWorkDir"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string UserViaAPDefault { + get { + return ((string)(this["UserViaAPDefault"])); + } + set { + this["UserViaAPDefault"] = value; + } + } } } diff --git a/mRemoteNG/Properties/Settings.settings b/mRemoteNG/Properties/Settings.settings index 4e642cf65..4cf0a13c6 100644 --- a/mRemoteNG/Properties/Settings.settings +++ b/mRemoteNG/Properties/Settings.settings @@ -815,5 +815,8 @@ + + + \ No newline at end of file diff --git a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs index 7a11683ad..e7fd5d6ec 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs @@ -55,7 +55,7 @@ this.pnlDefaultCredentials.Controls.Add(this.radCredentialsWindows); this.pnlDefaultCredentials.Location = new System.Drawing.Point(3, 3); this.pnlDefaultCredentials.Name = "pnlDefaultCredentials"; - this.pnlDefaultCredentials.Size = new System.Drawing.Size(604, 167); + this.pnlDefaultCredentials.Size = new System.Drawing.Size(604, 200); this.pnlDefaultCredentials.TabIndex = 0; // // tableLayoutPanel1 @@ -77,7 +77,7 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(332, 82); + this.tableLayoutPanel1.Size = new System.Drawing.Size(332, 110); this.tableLayoutPanel1.TabIndex = 1; // // txtCredentialsUserViaAPI diff --git a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs index 50c6982f6..242efec25 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs @@ -54,6 +54,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages txtCredentialsPassword.Text = cryptographyProvider.Decrypt(Settings.Default.DefaultPassword, Runtime.EncryptionKey); txtCredentialsDomain.Text = Settings.Default.DefaultDomain; + txtCredentialsUserViaAPI.Text = Settings.Default.UserViaAPDefault; } public override void SaveSettings() @@ -76,6 +77,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages Settings.Default.DefaultPassword = cryptographyProvider.Encrypt(txtCredentialsPassword.Text, Runtime.EncryptionKey); Settings.Default.DefaultDomain = txtCredentialsDomain.Text; + Settings.Default.UserViaAPDefault = txtCredentialsUserViaAPI.Text; } private void radCredentialsCustom_CheckedChanged(object sender, EventArgs e) @@ -86,6 +88,8 @@ namespace mRemoteNG.UI.Forms.OptionsPages txtCredentialsUsername.Enabled = radCredentialsCustom.Checked; txtCredentialsPassword.Enabled = radCredentialsCustom.Checked; txtCredentialsDomain.Enabled = radCredentialsCustom.Checked; + txtCredentialsUserViaAPI.Enabled = radCredentialsCustom.Checked; + lblCredentialsUserViaAPI.Enabled = radCredentialsCustom.Checked; } } } \ No newline at end of file