1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-06 00:13:33 +00:00

Added client certificate auth support.

This commit is contained in:
Ylian Saint-Hilaire
2022-06-05 00:54:57 -07:00
parent 85657d2857
commit 91fad23547
12 changed files with 1211 additions and 1516 deletions

View File

@@ -124,11 +124,11 @@
<Compile Include="src\FileDialogMsgForm.Designer.cs"> <Compile Include="src\FileDialogMsgForm.Designer.cs">
<DependentUpon>FileDialogMsgForm.cs</DependentUpon> <DependentUpon>FileDialogMsgForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="src\ProxySettings.cs"> <Compile Include="src\ConnectionSettings.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="src\ProxySettings.Designer.cs"> <Compile Include="src\ConnectionSettings.Designer.cs">
<DependentUpon>ProxySettings.cs</DependentUpon> <DependentUpon>ConnectionSettings.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="src\ListViewExtended.cs"> <Compile Include="src\ListViewExtended.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
@@ -317,8 +317,8 @@
<EmbeddedResource Include="src\FileDialogMsgForm.resx"> <EmbeddedResource Include="src\FileDialogMsgForm.resx">
<DependentUpon>FileDialogMsgForm.cs</DependentUpon> <DependentUpon>FileDialogMsgForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="src\ProxySettings.resx"> <EmbeddedResource Include="src\ConnectionSettings.resx">
<DependentUpon>ProxySettings.cs</DependentUpon> <DependentUpon>ConnectionSettings.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="src\KVMViewerExtra.resx"> <EmbeddedResource Include="src\KVMViewerExtra.resx">
<DependentUpon>KVMViewerExtra.cs</DependentUpon> <DependentUpon>KVMViewerExtra.cs</DependentUpon>

View File

@@ -619,6 +619,15 @@ namespace MeshCentralRouter.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to None.
/// </summary>
internal static string None {
get {
return ResourceManager.GetString("None", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to No tools allowed. /// Looks up a localized string similar to No tools allowed.
/// </summary> /// </summary>

View File

@@ -469,4 +469,7 @@
<data name="Version" xml:space="preserve"> <data name="Version" xml:space="preserve">
<value>Version {0}</value> <value>Version {0}</value>
</data> </data>
<data name="None" xml:space="preserve">
<value>None</value>
</data>
</root> </root>

View File

@@ -1,6 +1,6 @@
namespace MeshCentralRouter namespace MeshCentralRouter
{ {
partial class ProxySettings partial class ConnectionSettings
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@@ -28,7 +28,7 @@
/// </summary> /// </summary>
private void InitializeComponent() 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.okButton = new System.Windows.Forms.Button();
this.hostTextBox = new System.Windows.Forms.TextBox(); this.hostTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
@@ -42,16 +42,21 @@
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.authComboBox = new System.Windows.Forms.ComboBox(); 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.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// okButton // okButton
// //
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(219, 345);
this.okButton.Margin = new System.Windows.Forms.Padding(2); this.okButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.okButton.Name = "okButton"; 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.TabIndex = 1;
this.okButton.Text = "OK"; this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true; 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) this.hostTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.hostTextBox.Location = new System.Drawing.Point(145, 39); this.hostTextBox.Location = new System.Drawing.Point(193, 48);
this.hostTextBox.Margin = new System.Windows.Forms.Padding(2); this.hostTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.hostTextBox.Name = "hostTextBox"; 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.TabIndex = 2;
this.hostTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); this.hostTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged);
// //
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 42); this.label1.Location = new System.Drawing.Point(8, 52);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1"; 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.TabIndex = 3;
this.label1.Text = "Proxy Hostname:Port"; this.label1.Text = "Proxy Hostname:Port";
// //
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(5, 93); this.label3.Location = new System.Drawing.Point(7, 114);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3"; 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.TabIndex = 7;
this.label3.Text = "Username"; 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) this.usernameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.usernameTextBox.Location = new System.Drawing.Point(145, 90); this.usernameTextBox.Location = new System.Drawing.Point(193, 111);
this.usernameTextBox.Margin = new System.Windows.Forms.Padding(2); this.usernameTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.usernameTextBox.Name = "usernameTextBox"; 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.TabIndex = 6;
this.usernameTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); this.usernameTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged);
// //
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 117); this.label4.Location = new System.Drawing.Point(8, 144);
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label4.Name = "label4"; 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.TabIndex = 9;
this.label4.Text = "Password"; 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) this.passwordTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.passwordTextBox.Location = new System.Drawing.Point(145, 114); this.passwordTextBox.Location = new System.Drawing.Point(193, 140);
this.passwordTextBox.Margin = new System.Windows.Forms.Padding(2); this.passwordTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.passwordTextBox.Name = "passwordTextBox"; this.passwordTextBox.Name = "passwordTextBox";
this.passwordTextBox.PasswordChar = '*'; 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.TabIndex = 8;
this.passwordTextBox.TextChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); 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) this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.label5.ImeMode = System.Windows.Forms.ImeMode.NoControl; 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.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.TabIndex = 10;
this.label5.Text = "By default, the system\'s proxy is used. You can override this by manually configu" + 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"; "ring your own proxy settings here.\r\n";
@@ -137,10 +140,10 @@
// manualProxyCheckBox // manualProxyCheckBox
// //
this.manualProxyCheckBox.AutoSize = true; this.manualProxyCheckBox.AutoSize = true;
this.manualProxyCheckBox.Location = new System.Drawing.Point(145, 18); this.manualProxyCheckBox.Location = new System.Drawing.Point(193, 22);
this.manualProxyCheckBox.Margin = new System.Windows.Forms.Padding(2); this.manualProxyCheckBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.manualProxyCheckBox.Name = "manualProxyCheckBox"; 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.TabIndex = 11;
this.manualProxyCheckBox.Text = "Manual Proxy Settings"; this.manualProxyCheckBox.Text = "Manual Proxy Settings";
this.manualProxyCheckBox.UseVisualStyleBackColor = true; 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.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.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(263, 203); this.cancelButton.Location = new System.Drawing.Point(351, 345);
this.cancelButton.Margin = new System.Windows.Forms.Padding(2); this.cancelButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cancelButton.Name = "cancelButton"; 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.TabIndex = 12;
this.cancelButton.Text = "Cancel"; this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.UseVisualStyleBackColor = true;
@@ -161,8 +164,7 @@
// //
// groupBox1 // groupBox1
// //
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.authComboBox); this.groupBox1.Controls.Add(this.authComboBox);
@@ -173,9 +175,11 @@
this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.label3); 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.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.TabIndex = 13;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Proxy Settings"; this.groupBox1.Text = "Proxy Settings";
@@ -183,10 +187,9 @@
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 67); this.label2.Location = new System.Drawing.Point(8, 82);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2"; 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.TabIndex = 13;
this.label2.Text = "Proxy Authentication"; this.label2.Text = "Proxy Authentication";
// //
@@ -199,33 +202,89 @@
this.authComboBox.Items.AddRange(new object[] { this.authComboBox.Items.AddRange(new object[] {
"None", "None",
"Basic Authentication"}); "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.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.TabIndex = 12;
this.authComboBox.SelectedIndexChanged += new System.EventHandler(this.manualProxyCheckBox_CheckedChanged); 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.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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton; 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.groupBox1);
this.Controls.Add(this.cancelButton); this.Controls.Add(this.cancelButton);
this.Controls.Add(this.label5); this.Controls.Add(this.label5);
this.Controls.Add(this.okButton); this.Controls.Add(this.okButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 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.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "ProxySettings"; this.Name = "ConnectionSettings";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 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.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -244,5 +303,9 @@
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox authComboBox; 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;
} }
} }

205
src/ConnectionSettings.cs Normal file
View File

@@ -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);
}
/// <summary>
/// This class is used to add items to DropDown combo boxes and still be able to reference the item quickly.
/// </summary>
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<string, string> ParseCertificateSubject(string str)
{
string t = "";
bool quotes = false;
Dictionary<string, string> r = new Dictionary<string, string>();
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<string, string> 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);
}
}
}

View File

@@ -35,7 +35,7 @@
this.mainTabControl = new System.Windows.Forms.TabControl(); this.mainTabControl = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.panel1 = new System.Windows.Forms.Panel(); 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.installButton = new System.Windows.Forms.Button();
this.stateLabel = new System.Windows.Forms.Label(); this.stateLabel = new System.Windows.Forms.Label();
this.label28 = new System.Windows.Forms.Label(); this.label28 = new System.Windows.Forms.Label();
@@ -203,7 +203,7 @@
// //
// panel1 // panel1
// //
this.panel1.Controls.Add(this.proxySettings); this.panel1.Controls.Add(this.connectionSettings);
this.panel1.Controls.Add(this.installButton); this.panel1.Controls.Add(this.installButton);
this.panel1.Controls.Add(this.stateLabel); this.panel1.Controls.Add(this.stateLabel);
this.panel1.Controls.Add(this.label28); this.panel1.Controls.Add(this.label28);
@@ -221,12 +221,12 @@
resources.ApplyResources(this.panel1, "panel1"); resources.ApplyResources(this.panel1, "panel1");
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
// //
// proxySettings // connectionSettings
// //
resources.ApplyResources(this.proxySettings, "proxySettings"); resources.ApplyResources(this.connectionSettings, "connectionSettings");
this.proxySettings.Name = "proxySettings"; this.connectionSettings.Name = "connectionSettings";
this.proxySettings.UseVisualStyleBackColor = true; this.connectionSettings.UseVisualStyleBackColor = true;
this.proxySettings.Click += new System.EventHandler(this.button1_Click); this.connectionSettings.Click += new System.EventHandler(this.button1_Click);
// //
// installButton // installButton
// //
@@ -1146,7 +1146,7 @@
private System.Windows.Forms.ToolStripMenuItem askConsentToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem askConsentToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem privacyBarToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem privacyBarToolStripMenuItem;
private System.Windows.Forms.PictureBox pictureBox2; 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 customAppsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem1;
} }

View File

@@ -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\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) { } } 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; licenseLinkLabel.Visible = showLicense;
proxySettings.Visible = true; connectionSettings.Visible = true;
try try
{ {
if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt"))) if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt")))
@@ -583,7 +583,7 @@ namespace MeshCentralRouter
serverurl = new Uri(urlstring); serverurl = new Uri(urlstring);
} }
catch (Exception) { } catch (Exception) { }
meshcentral.connect(serverurl, null, null, null); meshcentral.connect(serverurl, null, null, null, getClientAuthCertificate());
} }
else else
{ {
@@ -593,12 +593,12 @@ namespace MeshCentralRouter
string hostname = serverNameComboBox.Text.Substring(0, keyIndex); string hostname = serverNameComboBox.Text.Substring(0, keyIndex);
string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5); string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5);
try { serverurl = new Uri("wss://" + hostname + "/control.ashx?key=" + loginkey); } catch (Exception) { } 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 else
{ {
try { serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx"); } catch (Exception) { } 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"); string urlstring = "wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath + "?auth=" + getValueFromQueryString(authLoginUrl.Query, "c");
if (loginkey != null) { urlstring += ("&key=" + loginkey); } if (loginkey != null) { urlstring += ("&key=" + loginkey); }
serverurl = new Uri(urlstring); serverurl = new Uri(urlstring);
meshcentral.connect(serverurl, null, null, null); meshcentral.connect(serverurl, null, null, null, getClientAuthCertificate());
} }
else else
{ {
@@ -658,12 +658,12 @@ namespace MeshCentralRouter
string hostname = serverNameComboBox.Text.Substring(0, keyIndex); string hostname = serverNameComboBox.Text.Substring(0, keyIndex);
string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5); string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5);
try { serverurl = new Uri("wss://" + hostname + "/control.ashx?key=" + loginkey); } catch (Exception) { } 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 else
{ {
try { serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx"); } catch (Exception) { } 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) if (sendEmailToken == true)
{ {
sendEmailToken = false; sendEmailToken = false;
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**email**"); meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**email**", getClientAuthCertificate());
} }
else if (sendSMSToken == true) else if (sendSMSToken == true)
{ {
sendSMSToken = false; sendSMSToken = false;
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**sms**"); meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**sms**", getClientAuthCertificate());
} }
else 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) private void button1_Click(object sender, EventArgs e)
{ {
ProxySettings form = new ProxySettings(); ConnectionSettings form = new ConnectionSettings();
if (form.ShowDialog(this) == DialogResult.OK) { } 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 delegate void displayMessageHandler(string msg, int buttons, string extra, int progress);
private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0) private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0)

File diff suppressed because it is too large Load Diff

View File

@@ -136,7 +136,7 @@ namespace MeshCentralRouter
} }
// Starts the routing server, called when the start button is pressed // 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; JSON.MaxJsonLength = 217483647;
this.user = user; this.user = user;
@@ -153,6 +153,7 @@ namespace MeshCentralRouter
} }
wc = new webSocketClient(); wc = new webSocketClient();
wc.clientAuthCert = clientAuthCert;
wc.extraHeaders = extraHeaders; wc.extraHeaders = extraHeaders;
wc.onStateChanged += new webSocketClient.onStateChangedHandler(changeStateEx); wc.onStateChanged += new webSocketClient.onStateChangedHandler(changeStateEx);
wc.onStringData += new webSocketClient.onStringDataHandler(processServerData); wc.onStringData += new webSocketClient.onStringDataHandler(processServerData);

View File

@@ -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;
}
}
}

View File

@@ -75,6 +75,7 @@ namespace MeshCentralRouter
public TLSCertificateCheck TLSCertCheck = TLSCertificateCheck.Verify; public TLSCertificateCheck TLSCertCheck = TLSCertificateCheck.Verify;
public X509Certificate2 tlsCert = null; public X509Certificate2 tlsCert = null;
public X509Certificate2 failedTlsCert = null; public X509Certificate2 failedTlsCert = null;
public X509Certificate2 clientAuthCert = null;
static public bool nativeWebSocketFirst = false; static public bool nativeWebSocketFirst = false;
private SemaphoreSlim receiveLock = new SemaphoreSlim(1, 1); private SemaphoreSlim receiveLock = new SemaphoreSlim(1, 1);
@@ -199,7 +200,8 @@ namespace MeshCentralRouter
if (nativeWebSocketFirst) { try { ws = new ClientWebSocket(); } catch (Exception) { } } if (nativeWebSocketFirst) { try { ws = new ClientWebSocket(); } catch (Exception) { } }
if (ws != null) 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())); 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]); } } if (extraHeaders != null) { foreach (var key in extraHeaders.Keys) { ws.Options.SetRequestHeader(key, extraHeaders[key]); } }
Task t = ConnectAsync(url); Task t = ConnectAsync(url);
@@ -304,11 +306,16 @@ namespace MeshCentralRouter
{ {
// Start TLS connection // Start TLS connection
Log("Websocket TCP connected, doing TLS..."); 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(); } 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) private void OnProxyResponseSink(IAsyncResult ar)
{ {
if (wsrawstream == null) return; if (wsrawstream == null) return;
@@ -333,7 +340,7 @@ namespace MeshCentralRouter
// All good, start TLS setup. // All good, start TLS setup.
readBufferLen = 0; readBufferLen = 0;
Log("Websocket TCP connected, doing TLS..."); 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(); } try { wsstream.BeginAuthenticateAsClient(url.Host, null, System.Security.Authentication.SslProtocols.Tls12, false, new AsyncCallback(OnTlsSetupSink), this); } catch (Exception) { Dispose(); }
} }
else else