diff --git a/MeshCentralRouter.csproj b/MeshCentralRouter.csproj index 37b4228..b5e3456 100644 --- a/MeshCentralRouter.csproj +++ b/MeshCentralRouter.csproj @@ -124,11 +124,11 @@ FileDialogMsgForm.cs - + Form - - ProxySettings.cs + + ConnectionSettings.cs Component @@ -317,8 +317,8 @@ FileDialogMsgForm.cs - - ProxySettings.cs + + ConnectionSettings.cs KVMViewerExtra.cs diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 6fa5bdd..564cd38 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -619,6 +619,15 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to None. + /// + internal static string None { + get { + return ResourceManager.GetString("None", resourceCulture); + } + } + /// /// Looks up a localized string similar to No tools allowed. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 5b2a285..356d614 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -469,4 +469,7 @@ Version {0} + + None + \ No newline at end of file diff --git a/src/ProxySettings.Designer.cs b/src/ConnectionSettings.Designer.cs similarity index 65% rename from src/ProxySettings.Designer.cs rename to src/ConnectionSettings.Designer.cs index a2545a0..d216976 100644 --- a/src/ProxySettings.Designer.cs +++ b/src/ConnectionSettings.Designer.cs @@ -1,6 +1,6 @@ namespace MeshCentralRouter { - partial class ProxySettings + partial class ConnectionSettings { /// /// Required designer variable. @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProxySettings)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConnectionSettings)); this.okButton = new System.Windows.Forms.Button(); this.hostTextBox = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); @@ -42,16 +42,21 @@ this.groupBox1 = new System.Windows.Forms.GroupBox(); this.label2 = new System.Windows.Forms.Label(); this.authComboBox = new System.Windows.Forms.ComboBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.viewCertButton = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.clientCertificateComboBox = new System.Windows.Forms.ComboBox(); this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // okButton // this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.okButton.Location = new System.Drawing.Point(164, 203); - this.okButton.Margin = new System.Windows.Forms.Padding(2); + this.okButton.Location = new System.Drawing.Point(219, 345); + this.okButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.okButton.Name = "okButton"; - this.okButton.Size = new System.Drawing.Size(95, 23); + this.okButton.Size = new System.Drawing.Size(127, 28); this.okButton.TabIndex = 1; this.okButton.Text = "OK"; this.okButton.UseVisualStyleBackColor = true; @@ -61,30 +66,28 @@ // this.hostTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.hostTextBox.Location = new System.Drawing.Point(145, 39); - this.hostTextBox.Margin = new System.Windows.Forms.Padding(2); + this.hostTextBox.Location = new System.Drawing.Point(193, 48); + this.hostTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.hostTextBox.Name = "hostTextBox"; - this.hostTextBox.Size = new System.Drawing.Size(192, 20); + this.hostTextBox.Size = new System.Drawing.Size(260, 22); this.hostTextBox.TabIndex = 2; this.hostTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(6, 42); - this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Location = new System.Drawing.Point(8, 52); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(106, 13); + this.label1.Size = new System.Drawing.Size(141, 17); this.label1.TabIndex = 3; this.label1.Text = "Proxy Hostname:Port"; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(5, 93); - this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Location = new System.Drawing.Point(7, 114); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(55, 13); + this.label3.Size = new System.Drawing.Size(73, 17); this.label3.TabIndex = 7; this.label3.Text = "Username"; // @@ -92,20 +95,19 @@ // this.usernameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.usernameTextBox.Location = new System.Drawing.Point(145, 90); - this.usernameTextBox.Margin = new System.Windows.Forms.Padding(2); + this.usernameTextBox.Location = new System.Drawing.Point(193, 111); + this.usernameTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.usernameTextBox.Name = "usernameTextBox"; - this.usernameTextBox.Size = new System.Drawing.Size(192, 20); + this.usernameTextBox.Size = new System.Drawing.Size(260, 22); this.usernameTextBox.TabIndex = 6; this.usernameTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(6, 117); - this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Location = new System.Drawing.Point(8, 144); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(53, 13); + this.label4.Size = new System.Drawing.Size(69, 17); this.label4.TabIndex = 9; this.label4.Text = "Password"; // @@ -113,11 +115,11 @@ // this.passwordTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.passwordTextBox.Location = new System.Drawing.Point(145, 114); - this.passwordTextBox.Margin = new System.Windows.Forms.Padding(2); + this.passwordTextBox.Location = new System.Drawing.Point(193, 140); + this.passwordTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.passwordTextBox.Name = "passwordTextBox"; this.passwordTextBox.PasswordChar = '*'; - this.passwordTextBox.Size = new System.Drawing.Size(192, 20); + this.passwordTextBox.Size = new System.Drawing.Size(260, 22); this.passwordTextBox.TabIndex = 8; this.passwordTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); // @@ -126,9 +128,10 @@ this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.label5.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.label5.Location = new System.Drawing.Point(12, 7); + this.label5.Location = new System.Drawing.Point(16, 9); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(346, 44); + this.label5.Size = new System.Drawing.Size(461, 54); this.label5.TabIndex = 10; this.label5.Text = "By default, the system\'s proxy is used. You can override this by manually configu" + "ring your own proxy settings here.\r\n"; @@ -137,10 +140,10 @@ // manualProxyCheckBox // this.manualProxyCheckBox.AutoSize = true; - this.manualProxyCheckBox.Location = new System.Drawing.Point(145, 18); - this.manualProxyCheckBox.Margin = new System.Windows.Forms.Padding(2); + this.manualProxyCheckBox.Location = new System.Drawing.Point(193, 22); + this.manualProxyCheckBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.manualProxyCheckBox.Name = "manualProxyCheckBox"; - this.manualProxyCheckBox.Size = new System.Drawing.Size(131, 17); + this.manualProxyCheckBox.Size = new System.Drawing.Size(170, 21); this.manualProxyCheckBox.TabIndex = 11; this.manualProxyCheckBox.Text = "Manual Proxy Settings"; this.manualProxyCheckBox.UseVisualStyleBackColor = true; @@ -150,10 +153,10 @@ // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(263, 203); - this.cancelButton.Margin = new System.Windows.Forms.Padding(2); + this.cancelButton.Location = new System.Drawing.Point(351, 345); + this.cancelButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(95, 23); + this.cancelButton.Size = new System.Drawing.Size(127, 28); this.cancelButton.TabIndex = 12; this.cancelButton.Text = "Cancel"; this.cancelButton.UseVisualStyleBackColor = true; @@ -161,8 +164,7 @@ // // groupBox1 // - this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.authComboBox); @@ -173,9 +175,11 @@ this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.label3); - this.groupBox1.Location = new System.Drawing.Point(12, 54); + this.groupBox1.Location = new System.Drawing.Point(16, 66); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(342, 144); + this.groupBox1.Padding = new System.Windows.Forms.Padding(4); + this.groupBox1.Size = new System.Drawing.Size(461, 178); this.groupBox1.TabIndex = 13; this.groupBox1.TabStop = false; this.groupBox1.Text = "Proxy Settings"; @@ -183,10 +187,9 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(6, 67); - this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Location = new System.Drawing.Point(8, 82); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(104, 13); + this.label2.Size = new System.Drawing.Size(137, 17); this.label2.TabIndex = 13; this.label2.Text = "Proxy Authentication"; // @@ -199,33 +202,89 @@ this.authComboBox.Items.AddRange(new object[] { "None", "Basic Authentication"}); - this.authComboBox.Location = new System.Drawing.Point(145, 64); + this.authComboBox.Location = new System.Drawing.Point(193, 79); + this.authComboBox.Margin = new System.Windows.Forms.Padding(4); this.authComboBox.Name = "authComboBox"; - this.authComboBox.Size = new System.Drawing.Size(192, 21); + this.authComboBox.Size = new System.Drawing.Size(260, 24); this.authComboBox.TabIndex = 12; this.authComboBox.SelectedIndexChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); // - // ProxySettings + // groupBox2 + // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.Controls.Add(this.viewCertButton); + this.groupBox2.Controls.Add(this.label6); + this.groupBox2.Controls.Add(this.clientCertificateComboBox); + this.groupBox2.Location = new System.Drawing.Point(16, 251); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(461, 89); + this.groupBox2.TabIndex = 14; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Client Certificate"; + // + // viewCertButton + // + this.viewCertButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.viewCertButton.Enabled = false; + this.viewCertButton.Location = new System.Drawing.Point(326, 52); + this.viewCertButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.viewCertButton.Name = "viewCertButton"; + this.viewCertButton.Size = new System.Drawing.Size(127, 28); + this.viewCertButton.TabIndex = 16; + this.viewCertButton.Text = "VIew..."; + this.viewCertButton.UseVisualStyleBackColor = true; + this.viewCertButton.Click += new System.EventHandler(this.viewCertButton_Click); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(8, 25); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(71, 17); + this.label6.TabIndex = 15; + this.label6.Text = "Certificate"; + // + // clientCertificateComboBox + // + this.clientCertificateComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.clientCertificateComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.clientCertificateComboBox.Enabled = false; + this.clientCertificateComboBox.FormattingEnabled = true; + this.clientCertificateComboBox.Location = new System.Drawing.Point(193, 22); + this.clientCertificateComboBox.Margin = new System.Windows.Forms.Padding(4); + this.clientCertificateComboBox.Name = "clientCertificateComboBox"; + this.clientCertificateComboBox.Size = new System.Drawing.Size(260, 24); + this.clientCertificateComboBox.TabIndex = 14; + this.clientCertificateComboBox.SelectedIndexChanged += new System.EventHandler(this.clientCertificateComboBox_SelectedIndexChanged); + // + // ConnectionSettings // this.AcceptButton = this.okButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelButton; - this.ClientSize = new System.Drawing.Size(369, 237); + this.ClientSize = new System.Drawing.Size(492, 387); + this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.cancelButton); this.Controls.Add(this.label5); this.Controls.Add(this.okButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(2); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "ProxySettings"; + this.Name = "ConnectionSettings"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Proxy Settings"; + this.Text = "Connection Settings"; + this.Load += new System.EventHandler(this.ConnectionSettings_Load); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.ResumeLayout(false); } @@ -244,5 +303,9 @@ private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label2; private System.Windows.Forms.ComboBox authComboBox; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Button viewCertButton; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.ComboBox clientCertificateComboBox; } } \ No newline at end of file diff --git a/src/ConnectionSettings.cs b/src/ConnectionSettings.cs new file mode 100644 index 0000000..1ff0eb5 --- /dev/null +++ b/src/ConnectionSettings.cs @@ -0,0 +1,205 @@ +using System; +using System.Windows.Forms; +using System.Collections; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; + +namespace MeshCentralRouter +{ + public partial class ConnectionSettings : Form + { + public ConnectionSettings() + { + InitializeComponent(); + } + + private void ConnectionSettings_Load(object sender, EventArgs e) + { + // Setup connection settings values from the registry + manualProxyCheckBox.Checked = Settings.GetRegValue("ManualProxy", false); + string host = Settings.GetRegValue("ProxyHost", ""); + if (host != "") { host += ":" + Settings.GetRegValue("ProxyPort", 443); } + hostTextBox.Text = host; + authComboBox.SelectedIndex = Settings.GetRegValue("ProxyAuth", 0); + usernameTextBox.Text = Settings.GetRegValue("ProxyUsername", ""); + passwordTextBox.Text = Settings.GetRegValue("ProxyPassword", ""); + + // Setup list of possible client authentication certificates + using (X509Store CertificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser)) + { + // Open the certificate stores + CertificateStore.Open(OpenFlags.ReadOnly); + + // Load the list client authentication certificates + clientCertificateComboBox.Items.Add(new DropDownItem(Properties.Resources.None, 0, null)); + foreach (X509Certificate2 cert in CertificateStore.Certificates) + { + if (cert.HasPrivateKey) + { + bool clientAuthCert = false; + foreach (X509Extension ex in cert.Extensions) + { + if (ex.Oid.Value == "2.5.29.37") + { + X509EnhancedKeyUsageExtension exx = (X509EnhancedKeyUsageExtension)ex; + foreach (var usage in exx.EnhancedKeyUsages) + { + if (usage.Value == "1.3.6.1.5.5.7.3.2") { clientAuthCert = true; } + } + } + } + if (clientAuthCert) { clientCertificateComboBox.Items.Add(new DropDownItem(GetCertificateString(cert.Subject), 0, cert)); } + } + } + clientCertificateComboBox.SelectedIndex = 0; + clientCertificateComboBox.Enabled = (clientCertificateComboBox.Items.Count > 1); + + // Close the certificate stores + CertificateStore.Close(); + } + + // Select the client authentication cert + int selected = 0; + string clientCertThumbPrint = Settings.GetRegValue("ClientAuthCert", ""); + for (int i = 0; i < clientCertificateComboBox.Items.Count; i++) + { + DropDownItem item = (DropDownItem)clientCertificateComboBox.Items[i]; + X509Certificate2 cert = (X509Certificate2)item.Tag; + if ((cert != null) && (cert.Thumbprint == clientCertThumbPrint)) { selected = i; } + } + clientCertificateComboBox.SelectedIndex = selected; + + UpdateInfo(); + } + + private void UpdateInfo() + { + hostTextBox.Enabled = manualProxyCheckBox.Checked; + usernameTextBox.Enabled = passwordTextBox.Enabled = (manualProxyCheckBox.Checked && (authComboBox.SelectedIndex == 1)); + + bool ok = true; + if (manualProxyCheckBox.Checked == true) + { + string portStr = ""; + string hostStr = hostTextBox.Text; + int i = hostStr.IndexOf(':'); + if (i >= 0) { portStr = hostStr.Substring(i + 1); hostStr = hostStr.Substring(0, i); } + int port = 0; + int.TryParse(portStr, out port); + if ((hostStr.Length == 0) || (port < 1) || (port > 65535)) { ok = false; } + } + okButton.Enabled = ok; + } + + private void manualProxyCheckBox_CheckedChanged(object sender, EventArgs e) + { + UpdateInfo(); + } + + private void okButton_Click(object sender, EventArgs e) + { + // Save proxy settings + Settings.SetRegValue("ManualProxy", manualProxyCheckBox.Checked); + if (manualProxyCheckBox.Checked == true) { + string hostStr = hostTextBox.Text; + string portStr = ""; + int i = hostStr.IndexOf(':'); + if (i >= 0) { portStr = hostStr.Substring(i + 1); hostStr = hostStr.Substring(0, i); } + int port = 0; + int.TryParse(portStr, out port); + Settings.SetRegValue("ProxyHost", hostStr); + Settings.SetRegValue("ProxyPort", port); + Settings.SetRegValue("ProxyAuth", authComboBox.SelectedIndex); + Settings.SetRegValue("ProxyUsername", (authComboBox.SelectedIndex == 1) ? usernameTextBox.Text : ""); + Settings.SetRegValue("ProxyPassword", (authComboBox.SelectedIndex == 1) ? passwordTextBox.Text : ""); + } else { + Settings.SetRegValue("ProxyHost", ""); + Settings.SetRegValue("ProxyPort", ""); + Settings.SetRegValue("ProxyAuth", 0); + Settings.SetRegValue("ProxyUsername", ""); + Settings.SetRegValue("ProxyPassword", ""); + } + + // Save client authentication certificate setting + DropDownItem item = (DropDownItem)clientCertificateComboBox.SelectedItem; + X509Certificate2 cert = (X509Certificate2)item.Tag; + Settings.SetRegValue("ClientAuthCert", (cert == null) ? "" : cert.Thumbprint); + + DialogResult = DialogResult.OK; + } + + private void cancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + + private void viewCertButton_Click(object sender, EventArgs e) + { + DropDownItem selectedItem = (DropDownItem)clientCertificateComboBox.SelectedItem; + if ((selectedItem == null) || (selectedItem.Tag == null)) return; + X509Certificate2UI.DisplayCertificate((X509Certificate2)selectedItem.Tag); + } + + /// + /// This class is used to add items to DropDown combo boxes and still be able to reference the item quickly. + /// + public class DropDownItem + { + public string Text = null; + public object Tag = null; + public int Handle = 0; + public override string ToString() { return Text; } + + public DropDownItem() + { + } + + public DropDownItem(string Text, int Handle, object Tag) + { + this.Text = Text; + this.Handle = Handle; + this.Tag = Tag; + } + } + + public static Dictionary ParseCertificateSubject(string str) + { + string t = ""; + bool quotes = false; + Dictionary r = new Dictionary(); + foreach (char c in str) + { + if ((c == ',') && (quotes == false)) + { + if (t.Trim() != "") { int i = t.IndexOf('='); if (i > 0) { r[t.Substring(0, i).Trim()] = t.Substring(i + 1).Trim(); } } + t = ""; + } + else if (c == '\"') + { + if (quotes == false) { quotes = true; } else { quotes = false; } + t += c; + } + else + { + t += c; + } + } + if (t.Trim() != "") { int i = t.IndexOf('='); if (i > 0) { r[t.Substring(0, i).Trim()] = t.Substring(i + 1).Trim(); } } + return r; + } + + public static string GetCertificateString(string certDataStr) + { + Dictionary names = ParseCertificateSubject(certDataStr); + if (names.ContainsKey("CN")) return names["CN"]; + if (names.ContainsKey("O")) return names["O"]; + return "Unknown"; + } + + private void clientCertificateComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + DropDownItem selectedItem = (DropDownItem)clientCertificateComboBox.SelectedItem; + viewCertButton.Enabled = (selectedItem.Tag != null); + } + } +} diff --git a/src/ProxySettings.resx b/src/ConnectionSettings.resx similarity index 100% rename from src/ProxySettings.resx rename to src/ConnectionSettings.resx diff --git a/src/MainForm.Designer.cs b/src/MainForm.Designer.cs index 805e2ae..5fa8008 100644 --- a/src/MainForm.Designer.cs +++ b/src/MainForm.Designer.cs @@ -35,7 +35,7 @@ this.mainTabControl = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.panel1 = new System.Windows.Forms.Panel(); - this.proxySettings = new System.Windows.Forms.Button(); + this.connectionSettings = new System.Windows.Forms.Button(); this.installButton = new System.Windows.Forms.Button(); this.stateLabel = new System.Windows.Forms.Label(); this.label28 = new System.Windows.Forms.Label(); @@ -203,7 +203,7 @@ // // panel1 // - this.panel1.Controls.Add(this.proxySettings); + this.panel1.Controls.Add(this.connectionSettings); this.panel1.Controls.Add(this.installButton); this.panel1.Controls.Add(this.stateLabel); this.panel1.Controls.Add(this.label28); @@ -221,12 +221,12 @@ resources.ApplyResources(this.panel1, "panel1"); this.panel1.Name = "panel1"; // - // proxySettings + // connectionSettings // - resources.ApplyResources(this.proxySettings, "proxySettings"); - this.proxySettings.Name = "proxySettings"; - this.proxySettings.UseVisualStyleBackColor = true; - this.proxySettings.Click += new System.EventHandler(this.button1_Click); + resources.ApplyResources(this.connectionSettings, "connectionSettings"); + this.connectionSettings.Name = "connectionSettings"; + this.connectionSettings.UseVisualStyleBackColor = true; + this.connectionSettings.Click += new System.EventHandler(this.button1_Click); // // installButton // @@ -1146,7 +1146,7 @@ private System.Windows.Forms.ToolStripMenuItem askConsentToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem privacyBarToolStripMenuItem; private System.Windows.Forms.PictureBox pictureBox2; - private System.Windows.Forms.Button proxySettings; + private System.Windows.Forms.Button connectionSettings; private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem1; } diff --git a/src/MainForm.cs b/src/MainForm.cs index 3864878..a72c31e 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -337,7 +337,7 @@ namespace MeshCentralRouter if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png"))) { try { pictureBox2.Image = pictureBox6.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png")); showLicense = false; } catch (Exception) { } } if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png"))) { try { pictureBox3.Image = pictureBox4.Image = pictureBox5.Image = pictureBox7.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png")); showLicense = false; } catch (Exception) { } } licenseLinkLabel.Visible = showLicense; - proxySettings.Visible = true; + connectionSettings.Visible = true; try { if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt"))) @@ -583,7 +583,7 @@ namespace MeshCentralRouter serverurl = new Uri(urlstring); } catch (Exception) { } - meshcentral.connect(serverurl, null, null, null); + meshcentral.connect(serverurl, null, null, null, getClientAuthCertificate()); } else { @@ -593,12 +593,12 @@ namespace MeshCentralRouter string hostname = serverNameComboBox.Text.Substring(0, keyIndex); string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5); try { serverurl = new Uri("wss://" + hostname + "/control.ashx?key=" + loginkey); } catch (Exception) { } - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie, getClientAuthCertificate()); } else { try { serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx"); } catch (Exception) { } - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie, getClientAuthCertificate()); } } } @@ -645,7 +645,7 @@ namespace MeshCentralRouter string urlstring = "wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath + "?auth=" + getValueFromQueryString(authLoginUrl.Query, "c"); if (loginkey != null) { urlstring += ("&key=" + loginkey); } serverurl = new Uri(urlstring); - meshcentral.connect(serverurl, null, null, null); + meshcentral.connect(serverurl, null, null, null, getClientAuthCertificate()); } else { @@ -658,12 +658,12 @@ namespace MeshCentralRouter string hostname = serverNameComboBox.Text.Substring(0, keyIndex); string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5); try { serverurl = new Uri("wss://" + hostname + "/control.ashx?key=" + loginkey); } catch (Exception) { } - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie, getClientAuthCertificate()); } else { try { serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx"); } catch (Exception) { } - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie, getClientAuthCertificate()); } } } @@ -1411,16 +1411,16 @@ namespace MeshCentralRouter if (sendEmailToken == true) { sendEmailToken = false; - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**email**"); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**email**", getClientAuthCertificate()); } else if (sendSMSToken == true) { sendSMSToken = false; - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**sms**"); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**sms**", getClientAuthCertificate()); } else { - meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, tokenTextBox.Text.Replace(" ", "")); + meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, tokenTextBox.Text.Replace(" ", ""), getClientAuthCertificate()); } } @@ -2219,7 +2219,7 @@ namespace MeshCentralRouter private void button1_Click(object sender, EventArgs e) { - ProxySettings form = new ProxySettings(); + ConnectionSettings form = new ConnectionSettings(); if (form.ShowDialog(this) == DialogResult.OK) { } } @@ -2231,6 +2231,31 @@ namespace MeshCentralRouter } } + private X509Certificate2 getClientAuthCertificate() + { + X509Certificate2 r = null; + string clientCertThumbPrint = Settings.GetRegValue("ClientAuthCert", ""); + if (clientCertThumbPrint == "") return null; + + // Setup list of possible client authentication certificates + using (X509Store CertificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser)) + { + // Open the certificate stores + CertificateStore.Open(OpenFlags.ReadOnly); + + // Load the list of trusted root certificates + foreach (X509Certificate2 cert in CertificateStore.Certificates) + { + if ((cert.HasPrivateKey) && (cert.Thumbprint == clientCertThumbPrint)) { r = cert; } + } + + // Close the certificate stores + CertificateStore.Close(); + } + + return r; + } + /* private delegate void displayMessageHandler(string msg, int buttons, string extra, int progress); private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0) diff --git a/src/MainForm.resx b/src/MainForm.resx index da47e22..0a32c09 100644 --- a/src/MainForm.resx +++ b/src/MainForm.resx @@ -117,511 +117,46 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - mainPanel - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel5 - - - 0 - - - pictureBox1 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel5 - - - 1 - - - Fill - - - - 0, 0 - - - 492, 416 - - - - 8 - - - panel5 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 - - - mainTabControl - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mainPanel - - - 0 - - - Fill - - - 0, 65 - - - 492, 351 - - - 9 - - - mainPanel - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel5 - - - 0 - FlatButtons - - panel1 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage1 - - - 0 - - - 4, 25 - - - 3, 3, 3, 3 - - - 484, 322 - - - 0 - - - Login - - - tabPage1 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mainTabControl - - - 0 - - - panel2 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage2 - - - 0 - - - 4, 25 - - - 3, 3, 3, 3 - - - 484, 322 - - - 1 - - - Token - - - tabPage2 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mainTabControl - - - 1 - - - panel3 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage3 - - - 0 - - - 4, 25 - - - 484, 322 - - - 2 - - - Certificate - - - tabPage3 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mainTabControl - - - 2 - - - panel4 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage5 - - - 0 - - - 4, 25 - - - 484, 322 - - - 4 - - - Mappings - - - tabPage5 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mainTabControl - - - 3 - - - Fill - - - 0, 0 - - - 0, 0, 0, 0 - - - 492, 351 - - - 8 - - - False - - - mainTabControl - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mainPanel - - - 0 - - - proxySettings - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 0 - - - installButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 1 - - - stateLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 2 - - - label28 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 3 - - - label27 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 4 - - - label26 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 5 - - - passwordTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 6 - - - serverNameComboBox - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 7 - - - userNameTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 8 - - - licenseLinkLabel - - - System.Windows.Forms.LinkLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 9 - - - versionLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 10 - - - nextButton1 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 11 - - - pictureBox3 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 12 - - - label1 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 13 - - - pictureBox2 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel1 - - - 14 - - - Fill - - - 3, 3 - - - 478, 316 - - - 6 - - - panel1 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage1 - - - 0 - - + Bottom, Left - + NoControl - - 10, 286 + + + 13, 355 - - 95, 23 + + 4, 4, 4, 4 - + + 127, 28 + + + 106 - - Proxy... + + Settings... - + False - - proxySettings + + connectionSettings - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + panel1 - + 0 @@ -631,10 +166,13 @@ NoControl - 111, 286 + 148, 355 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 104 @@ -670,10 +208,13 @@ NoControl - 241, 225 + 321, 277 + + + 4, 0, 4, 0 - 88, 13 + 114, 17 19 @@ -703,10 +244,13 @@ NoControl - 238, 176 + 317, 217 + + + 4, 0, 4, 0 - 53, 13 + 69, 17 18 @@ -733,10 +277,13 @@ NoControl - 238, 135 + 317, 166 + + + 4, 0, 4, 0 - 55, 13 + 73, 17 17 @@ -763,10 +310,13 @@ NoControl - 238, 92 + 317, 113 + + + 4, 0, 4, 0 - 38, 13 + 50, 17 16 @@ -790,13 +340,16 @@ Top, Left, Right - 241, 192 + 321, 236 + + + 4, 4, 4, 4 - 214, 20 + 287, 22 102 @@ -820,10 +373,13 @@ meshcentral.com - 241, 110 + 321, 135 + + + 4, 4, 4, 4 - 214, 21 + 287, 24 100 @@ -844,10 +400,13 @@ Top, Left, Right - 241, 151 + 321, 186 + + + 4, 4, 4, 4 - 214, 20 + 287, 22 101 @@ -871,10 +430,13 @@ NoControl - 174, 260 + 235, 323 + + + 4, 0, 4, 0 - 303, 13 + 404, 16 103 @@ -907,10 +469,13 @@ NoControl - 3, 260 + 4, 323 + + + 4, 0, 4, 0 - 37, 13 + 47, 17 11 @@ -937,10 +502,13 @@ NoControl - 372, 286 + 499, 355 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 105 @@ -967,10 +535,13 @@ NoControl - 0, 278 + 0, 345 + + + 4, 4, 4, 4 - 478, 40 + 640, 49 StretchImage @@ -997,10 +568,13 @@ NoControl - 12, 9 + 16, 11 + + + 4, 0, 4, 0 - 454, 56 + 608, 69 6 @@ -1027,10 +601,13 @@ NoControl - 15, 68 + 20, 84 + + + 4, 4, 4, 4 - 217, 170 + 292, 212 Zoom @@ -1050,160 +627,61 @@ 14 - - tokenRememberCheckBox - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 0 - - - emailTokenButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 1 - - - smsTokenButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 2 - - - tokenEmailSentLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 3 - - - label3 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 4 - - - tokenTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 5 - - - pictureBox6 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 6 - - - backButton2 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 7 - - - nextButton2 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 8 - - - pictureBox4 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 9 - - - label2 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 10 - - + Fill - - 3, 3 + + 4, 4 - - 478, 316 + + 4, 4, 4, 4 - - 7 + + 640, 392 - - panel2 + + 6 - + + panel1 + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tabPage2 + + tabPage1 - + + 0 + + + 4, 28 + + + 4, 4, 4, 4 + + + 4, 4, 4, 4 + + + 648, 400 + + + 0 + + + Login + + + tabPage1 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainTabControl + + 0 @@ -1213,10 +691,13 @@ NoControl - 241, 221 + 321, 272 + + + 4, 4, 4, 4 - 131, 17 + 170, 21 204 @@ -1243,10 +724,13 @@ NoControl - 241, 177 + 321, 218 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 202 @@ -1273,10 +757,13 @@ NoControl - 342, 177 + 456, 218 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 203 @@ -1306,10 +793,13 @@ NoControl - 238, 182 + 317, 224 + + + 4, 0, 4, 0 - 55, 13 + 73, 17 21 @@ -1339,10 +829,13 @@ NoControl - 238, 135 + 317, 166 + + + 4, 0, 4, 0 - 38, 13 + 48, 17 19 @@ -1366,10 +859,13 @@ Top, Left, Right - 241, 151 + 321, 186 + + + 4, 4, 4, 4 - 214, 20 + 287, 22 201 @@ -1393,10 +889,13 @@ NoControl - 15, 68 + 20, 84 + + + 4, 4, 4, 4 - 217, 170 + 292, 212 Zoom @@ -1423,10 +922,13 @@ NoControl - 270, 286 + 363, 355 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 205 @@ -1453,10 +955,13 @@ NoControl - 372, 286 + 499, 355 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 206 @@ -1483,10 +988,13 @@ NoControl - 0, 278 + 0, 345 + + + 4, 4, 4, 4 - 478, 40 + 640, 49 StretchImage @@ -1513,10 +1021,13 @@ NoControl - 12, 9 + 16, 11 + + + 4, 0, 4, 0 - 454, 56 + 608, 69 6 @@ -1536,126 +1047,63 @@ 10 - - rememberCertCheckBox - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 0 - - - certDetailsTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 1 - - - certDetailsButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 2 - - - label4 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 3 - - - label5 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 4 - - - backButton3 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 5 - - - nextButton3 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 6 - - - pictureBox5 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 7 - - + Fill - - 0, 0 + + 4, 4 - - 484, 322 + + 4, 4, 4, 4 - - 8 + + 640, 392 - - panel3 + + 7 - + + panel2 + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tabPage3 + + tabPage2 - + 0 + + 4, 28 + + + 4, 4, 4, 4 + + + 4, 4, 4, 4 + + + 648, 400 + + + 1 + + + Token + + + tabPage2 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainTabControl + + + 1 + Bottom, Left @@ -1666,10 +1114,13 @@ NoControl - 208, 256 + 277, 319 + + + 4, 4, 4, 4 - 145, 17 + 190, 21 302 @@ -1693,7 +1144,10 @@ Top, Bottom, Left, Right - 15, 82 + 20, 101 + + + 4, 4, 4, 4 True @@ -1702,7 +1156,7 @@ Vertical - 450, 162 + 602, 202 25 @@ -1726,10 +1180,13 @@ NoControl - 14, 251 + 19, 313 + + + 4, 4, 4, 4 - 188, 23 + 251, 28 301 @@ -1759,10 +1216,13 @@ NoControl - 8, 6 + 11, 7 + + + 4, 0, 4, 0 - 468, 22 + 627, 27 23 @@ -1792,10 +1252,13 @@ NoControl - 12, 34 + 16, 42 + + + 4, 0, 4, 0 - 454, 45 + 608, 55 22 @@ -1822,10 +1285,13 @@ NoControl - 276, 291 + 371, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 303 @@ -1852,10 +1318,13 @@ NoControl - 378, 291 + 507, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 304 @@ -1882,10 +1351,13 @@ NoControl - 0, 282 + 0, 351 + + + 4, 4, 4, 4 - 484, 40 + 648, 49 StretchImage @@ -1905,114 +1377,60 @@ 7 - - menuLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 0 - - - searchTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 1 - - - devicesTabControl - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 2 - - - openWebSiteButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 3 - - - backButton5 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 4 - - - nextButton5 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 5 - - - pictureBox7 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 6 - - + Fill - + 0, 0 - - 484, 322 + + 4, 4, 4, 4 - + + 648, 400 + + 8 - - panel4 + + panel3 - + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tabPage5 + + tabPage3 - + 0 + + 4, 28 + + + 4, 4, 4, 4 + + + 648, 400 + + + 2 + + + Certificate + + + tabPage3 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainTabControl + + + 2 + Top, Right @@ -2022,8 +1440,50 @@ 613, 17 + + 218, 26 + + + Show &Group Names + + + 218, 26 + + + Show &Offline Devices + + + 215, 6 + + + 218, 26 + + + Sort by &Name + + + 218, 26 + + + Sort by G&roup + + + 215, 6 + + + 218, 26 + + + S&ettings... + + + 218, 26 + + + &Custom Apps... + - 186, 148 + 219, 172 mainContextMenuStrip @@ -2038,10 +1498,13 @@ NoControl - 454, 2 + 608, 2 + + + 4, 0, 4, 0 - 25, 25 + 31, 31 403 @@ -2061,56 +1524,17 @@ 0 - - 185, 22 - - - Show &Group Names - - - 185, 22 - - - Show &Offline Devices - - - 182, 6 - - - 185, 22 - - - Sort by &Name - - - 185, 22 - - - Sort by G&roup - - - 182, 6 - - - 185, 22 - - - S&ettings... - - - 185, 22 - - - &Custom Apps... - Top, Right - 306, 5 + 411, 6 + + + 4, 4, 4, 4 - 146, 20 + 193, 22 402 @@ -2133,165 +1557,12 @@ FlatButtons - - devicesTabPage - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesTabControl - - - 0 - - - portMapTabPage - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesTabControl - - - 1 - - - 3, 3 - - - 478, 279 - - - 401 - - - devicesTabControl - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 2 - - - devicesPanel - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesTabPage - - - 0 - - - 4, 25 - - - 3, 3, 3, 3 - - - 470, 250 - - - 0 - - - Devices - - - devicesTabPage - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesTabControl - - - 0 - Top, Bottom, Left, Right True - - cancelAutoCloseButton1 - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesPanel - - - 0 - - - devicesListView - - - MeshCentralRouter.ListViewExtended, MeshCentralRouter, Version=1.8.8179.27673, Culture=neutral, PublicKeyToken=null - - - devicesPanel - - - 1 - - - noSearchResultsLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesPanel - - - 2 - - - noDevicesLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesPanel - - - 3 - - - 0, 0 - - - 470, 248 - - - 50 - - - devicesPanel - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - devicesTabPage - - - 0 - Bottom, Left @@ -2299,10 +1570,13 @@ NoControl - 6, 199 + 8, 240 + + + 4, 4, 4, 4 - 168, 35 + 224, 43 405 @@ -2340,8 +1614,86 @@ 161, 56 + + Segoe UI, 9pt, style=Bold + + + 198, 24 + + + Add &Map... + + + 198, 24 + + + Add &Relay Map... + + + 195, 6 + + + 204, 26 + + + Ask Consent + Bar + + + 204, 26 + + + Ask Consent + + + 204, 26 + + + Privacy Bar + + + 198, 24 + + + Remote Desktop... + + + 198, 24 + + + Remote Files... + + + 198, 24 + + + HTTP + + + 198, 24 + + + HTTPS + + + 198, 24 + + + RDP + + + 198, 24 + + + SSH + + + 198, 24 + + + SCP + - 171, 208 + 199, 226 devicesContextMenuStrip @@ -2357,7 +1709,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADg - HQAAAk1TRnQBSQFMAgEBEAEAAQgBAQEIAQEBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA + HQAAAk1TRnQBSQFMAgEBEAEAARABAQEQAQEBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABUAMAAQEBAAEYBgABPP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AJYAA/0D+AP3A/sD/yEAA/0D+gP5 A/wD/xgAAfoB+wH6A/4qAAP9A/8tAAP7A88D1QPbA88D1AO+A9QYAAP8A90D4APjA90D4APUA+MSAAP8 AZEBjwF9AU4BaAEhAfQB9QH0JAAD/gPRA8YD+ioAAcYCxwHPAtAB2ALZA90DywPBA68DmgP3FQAD2APd @@ -2488,10 +1840,13 @@ - 10, 4 + 13, 5 + + + 4, 4, 4, 4 - 446, 210 + 593, 258 404 @@ -2503,7 +1858,7 @@ devicesListView - MeshCentralRouter.ListViewExtended, MeshCentralRouter, Version=1.8.8179.27673, Culture=neutral, PublicKeyToken=null + MeshCentralRouter.ListViewExtended, MeshCentralRouter, Version=1.8.8190.31143, Culture=neutral, PublicKeyToken=null devicesPanel @@ -2511,84 +1866,6 @@ 1 - - Segoe UI, 9pt, style=Bold - - - 170, 22 - - - Add &Map... - - - 170, 22 - - - Add &Relay Map... - - - 167, 6 - - - 170, 22 - - - Remote Desktop... - - - 171, 22 - - - Ask Consent + Bar - - - 171, 22 - - - Ask Consent - - - 171, 22 - - - Privacy Bar - - - 170, 22 - - - Remote Files... - - - 170, 22 - - - HTTP - - - 170, 22 - - - HTTPS - - - 170, 22 - - - RDP - - - 170, 22 - - - SSH - - - 170, 22 - - - SCP - Top, Left, Right @@ -2599,10 +1876,13 @@ NoControl - 2, 88 + 3, 108 + + + 4, 0, 4, 0 - 379, 52 + 503, 64 5 @@ -2638,10 +1918,13 @@ NoControl - 2, 88 + 3, 108 + + + 4, 0, 4, 0 - 379, 52 + 503, 64 4 @@ -2664,104 +1947,59 @@ 3 - - cancelAutoCloseButton2 + + 0, 0 - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 4, 4, 4, 4 - - portMapTabPage + + 628, 305 - - 0 + + 50 - - mapPanel + + devicesPanel - + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - portMapTabPage + + devicesTabPage - - 1 + + 0 - - settingsPictureBox + + 4, 28 - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 4, 4, 4, 4 - - portMapTabPage + + 4, 4, 4, 4 - - 2 + + 632, 315 - - helpPictureBox + + 0 - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Devices - - portMapTabPage + + devicesTabPage - - 3 - - - addButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - portMapTabPage - - - 4 - - - addRelayButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - portMapTabPage - - - 5 - - - 4, 25 - - - 3, 3, 3, 3 - - - 472, 253 - - - 1 - - - Mappings - - - portMapTabPage - - + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + devicesTabControl - - 1 + + 0 Bottom, Left @@ -2770,10 +2008,13 @@ NoControl - 4, 182 + 5, 217 + + + 4, 4, 4, 4 - 168, 35 + 224, 43 55 @@ -2802,39 +2043,6 @@ True - - noMapLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - mapPanel - - - 0 - - - 0, 0 - - - 472, 221 - - - 49 - - - mapPanel - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - portMapTabPage - - - 1 - Top, Left, Right @@ -2845,10 +2053,13 @@ NoControl - 6, 79 + 8, 97 + + + 4, 0, 4, 0 - 452, 52 + 595, 64 4 @@ -2873,6 +2084,30 @@ Click "Add" to get started. 0 + + 0, 0 + + + 4, 4, 4, 4 + + + 625, 264 + + + 49 + + + mapPanel + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + portMapTabPage + + + 1 + Bottom, Left @@ -2880,10 +2115,13 @@ Click "Add" to get started. NoControl - 1, 226 + 1, 271 + + + 4, 4, 4, 4 - 20, 20 + 27, 25 54 @@ -2907,10 +2145,13 @@ Click "Add" to get started. NoControl - 240, 226 + 317, 271 + + + 4, 4, 4, 4 - 20, 20 + 27, 25 5 @@ -2937,10 +2178,13 @@ Click "Add" to get started. NoControl - 372, 223 + 493, 267 + + + 4, 4, 4, 4 - 100, 23 + 133, 28 50 @@ -2970,10 +2214,13 @@ Click "Add" to get started. NoControl - 266, 223 + 352, 267 + + + 4, 4, 4, 4 - 100, 23 + 133, 28 52 @@ -2993,6 +2240,60 @@ Click "Add" to get started. 5 + + 4, 28 + + + 4, 4, 4, 4 + + + 4, 4, 4, 4 + + + 629, 311 + + + 1 + + + Mappings + + + portMapTabPage + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + devicesTabControl + + + 1 + + + 4, 4 + + + 4, 4, 4, 4 + + + 640, 347 + + + 401 + + + devicesTabControl + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel4 + + + 2 + Bottom, Left @@ -3000,10 +2301,13 @@ Click "Add" to get started. NoControl - 10, 291 + 13, 362 + + + 4, 4, 4, 4 - 109, 23 + 145, 28 406 @@ -3033,10 +2337,13 @@ Click "Add" to get started. NoControl - 276, 291 + 371, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 407 @@ -3063,10 +2370,13 @@ Click "Add" to get started. NoControl - 378, 291 + 507, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 408 @@ -3093,10 +2403,13 @@ Click "Add" to get started. NoControl - 0, 282 + 0, 351 + + + 4, 4, 4, 4 - 484, 40 + 648, 49 StretchImage @@ -3116,6 +2429,117 @@ Click "Add" to get started. 6 + + Fill + + + 0, 0 + + + 4, 4, 4, 4 + + + 648, 400 + + + 8 + + + panel4 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPage5 + + + 0 + + + 4, 28 + + + 4, 4, 4, 4 + + + 648, 400 + + + 4 + + + Mappings + + + tabPage5 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainTabControl + + + 3 + + + Fill + + + 0, 0 + + + 0, 0, 0, 0 + + + 656, 432 + + + 8 + + + False + + + mainTabControl + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainPanel + + + 0 + + + Fill + + + 0, 80 + + + 4, 4, 4, 4 + + + 656, 432 + + + 9 + + + mainPanel + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel5 + + + 0 + Top @@ -3125,8 +2549,11 @@ Click "Add" to get started. 0, 0 + + 4, 4, 4, 4 + - 492, 65 + 656, 80 Zoom @@ -3146,6 +2573,33 @@ Click "Add" to get started. 1 + + Fill + + + 0, 0 + + + 4, 4, 4, 4 + + + 656, 512 + + + 8 + + + panel5 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + 17, 17 @@ -3158,8 +2612,23 @@ Click "Add" to get started. 418, 17 + + 123, 24 + + + &Open... + + + 120, 6 + + + 123, 24 + + + E&xit + - 113, 54 + 124, 58 trayIconContextMenuStrip @@ -4864,29 +4333,41 @@ Click "Add" to get started. MeshCentral Router - - 112, 22 - - - &Open... - - - 109, 6 - - - 112, 22 - - - E&xit - 791, 17 905, 17 + + 193, 24 + + + &Open Mappings... + + + 193, 24 + + + &Save Mappings... + + + 190, 6 + + + 193, 24 + + + S&ettings... + + + 193, 24 + + + &Custom Apps... + - 169, 98 + 194, 106 mappingsContextMenuStrip @@ -4894,33 +4375,6 @@ Click "Add" to get started. System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 168, 22 - - - &Open Mappings... - - - 168, 22 - - - &Save Mappings... - - - 165, 6 - - - 168, 22 - - - S&ettings... - - - 168, 22 - - - &Custom Apps... - 1110, 17 @@ -4943,10 +4397,10 @@ Click "Add" to get started. True - 6, 13 + 8, 16 - 492, 416 + 656, 512 @@ -6642,6 +6096,9 @@ Click "Add" to get started. AADAPwAAwD8AAMA/AADAPwAA + + 4, 4, 4, 4 + MeshCentral Router diff --git a/src/MeshCentralServer.cs b/src/MeshCentralServer.cs index 192815b..66ccb1b 100644 --- a/src/MeshCentralServer.cs +++ b/src/MeshCentralServer.cs @@ -136,7 +136,7 @@ namespace MeshCentralRouter } // Starts the routing server, called when the start button is pressed - public void connect(Uri wsurl, string user, string pass, string token) + public void connect(Uri wsurl, string user, string pass, string token, X509Certificate2 clientAuthCert) { JSON.MaxJsonLength = 217483647; this.user = user; @@ -153,6 +153,7 @@ namespace MeshCentralRouter } wc = new webSocketClient(); + wc.clientAuthCert = clientAuthCert; wc.extraHeaders = extraHeaders; wc.onStateChanged += new webSocketClient.onStateChangedHandler(changeStateEx); wc.onStringData += new webSocketClient.onStringDataHandler(processServerData); diff --git a/src/ProxySettings.cs b/src/ProxySettings.cs deleted file mode 100644 index ce8ee20..0000000 --- a/src/ProxySettings.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Windows.Forms; - -namespace MeshCentralRouter -{ - public partial class ProxySettings : Form - { - public ProxySettings() - { - InitializeComponent(); - manualProxyCheckBox.Checked = Settings.GetRegValue("ManualProxy", false); - string host = Settings.GetRegValue("ProxyHost", ""); - if (host != "") { host += ":" + Settings.GetRegValue("ProxyPort", 443); } - hostTextBox.Text = host; - authComboBox.SelectedIndex = Settings.GetRegValue("ProxyAuth", 0); - usernameTextBox.Text = Settings.GetRegValue("ProxyUsername", ""); - passwordTextBox.Text = Settings.GetRegValue("ProxyPassword", ""); - UpdateInfo(); - } - - private void UpdateInfo() - { - hostTextBox.Enabled = manualProxyCheckBox.Checked; - usernameTextBox.Enabled = passwordTextBox.Enabled = (manualProxyCheckBox.Checked && (authComboBox.SelectedIndex == 1)); - - bool ok = true; - if (manualProxyCheckBox.Checked == true) - { - string portStr = ""; - string hostStr = hostTextBox.Text; - int i = hostStr.IndexOf(':'); - if (i >= 0) { portStr = hostStr.Substring(i + 1); hostStr = hostStr.Substring(0, i); } - int port = 0; - int.TryParse(portStr, out port); - if ((hostStr.Length == 0) || (port < 1) || (port > 65535)) { ok = false; } - } - okButton.Enabled = ok; - } - - private void manualProxyCheckBox_CheckedChanged(object sender, EventArgs e) - { - UpdateInfo(); - } - - private void okButton_Click(object sender, EventArgs e) - { - Settings.SetRegValue("ManualProxy", manualProxyCheckBox.Checked); - if (manualProxyCheckBox.Checked == true) { - string hostStr = hostTextBox.Text; - string portStr = ""; - int i = hostStr.IndexOf(':'); - if (i >= 0) { portStr = hostStr.Substring(i + 1); hostStr = hostStr.Substring(0, i); } - int port = 0; - int.TryParse(portStr, out port); - Settings.SetRegValue("ProxyHost", hostStr); - Settings.SetRegValue("ProxyPort", port); - Settings.SetRegValue("ProxyAuth", authComboBox.SelectedIndex); - Settings.SetRegValue("ProxyUsername", (authComboBox.SelectedIndex == 1) ? usernameTextBox.Text : ""); - Settings.SetRegValue("ProxyPassword", (authComboBox.SelectedIndex == 1) ? passwordTextBox.Text : ""); - } else { - Settings.SetRegValue("ProxyHost", ""); - Settings.SetRegValue("ProxyPort", ""); - Settings.SetRegValue("ProxyAuth", 0); - Settings.SetRegValue("ProxyUsername", ""); - Settings.SetRegValue("ProxyPassword", ""); - } - DialogResult = DialogResult.OK; - } - - private void cancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - } - } -} diff --git a/src/WebSocketClient.cs b/src/WebSocketClient.cs index d8c7410..e83e47e 100644 --- a/src/WebSocketClient.cs +++ b/src/WebSocketClient.cs @@ -75,6 +75,7 @@ namespace MeshCentralRouter public TLSCertificateCheck TLSCertCheck = TLSCertificateCheck.Verify; public X509Certificate2 tlsCert = null; public X509Certificate2 failedTlsCert = null; + public X509Certificate2 clientAuthCert = null; static public bool nativeWebSocketFirst = false; private SemaphoreSlim receiveLock = new SemaphoreSlim(1, 1); @@ -199,7 +200,8 @@ namespace MeshCentralRouter if (nativeWebSocketFirst) { try { ws = new ClientWebSocket(); } catch (Exception) { } } if (ws != null) { - // Use Windows native websockets + // Use Windows native websocket + if (clientAuthCert != null) { ws.Options.ClientCertificates.Add(clientAuthCert); } Log("Websocket (native) Start, URL=" + ((url == null) ? "(NULL)" : url.ToString())); if (extraHeaders != null) { foreach (var key in extraHeaders.Keys) { ws.Options.SetRequestHeader(key, extraHeaders[key]); } } Task t = ConnectAsync(url); @@ -304,11 +306,16 @@ namespace MeshCentralRouter { // Start TLS connection Log("Websocket TCP connected, doing TLS..."); - wsstream = new SslStream(wsclient.GetStream(), false, VerifyServerCertificate, null); + wsstream = new SslStream(wsclient.GetStream(), false, VerifyServerCertificate, LocalCertificateSelectionCallback); try { wsstream.BeginAuthenticateAsClient(url.Host, null, System.Security.Authentication.SslProtocols.Tls12, false, new AsyncCallback(OnTlsSetupSink), this); } catch (Exception) { Dispose(); } } } + private X509Certificate LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers) + { + return clientAuthCert; + } + private void OnProxyResponseSink(IAsyncResult ar) { if (wsrawstream == null) return; @@ -333,7 +340,7 @@ namespace MeshCentralRouter // All good, start TLS setup. readBufferLen = 0; Log("Websocket TCP connected, doing TLS..."); - wsstream = new SslStream(wsrawstream, false, VerifyServerCertificate, null); + wsstream = new SslStream(wsrawstream, false, VerifyServerCertificate, LocalCertificateSelectionCallback); try { wsstream.BeginAuthenticateAsClient(url.Host, null, System.Security.Authentication.SslProtocols.Tls12, false, new AsyncCallback(OnTlsSetupSink), this); } catch (Exception) { Dispose(); } } else