From 63c78f986d4bb5368ef90136aa211267dcd5b8f0 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sat, 18 May 2019 15:10:08 -0500 Subject: [PATCH] added button to test encryption settings on the security page --- .../Config/Connections/XmlConnectionsSaver.cs | 23 ++-- .../Xml/XmlConnectionSerializerFactory.cs | 33 ++++++ .../Resources/Language/Language.Designer.cs | 29 ++++- mRemoteV1/Resources/Language/Language.resx | 9 ++ .../OptionsPages/SecurityPage.Designer.cs | 109 ++++++++++-------- .../UI/Forms/OptionsPages/SecurityPage.cs | 35 ++++++ mRemoteV1/mRemoteV1.csproj | 1 + 7 files changed, 180 insertions(+), 59 deletions(-) create mode 100644 mRemoteV1/Config/Serializers/ConnectionSerializers/Xml/XmlConnectionSerializerFactory.cs diff --git a/mRemoteV1/Config/Connections/XmlConnectionsSaver.cs b/mRemoteV1/Config/Connections/XmlConnectionsSaver.cs index c9d9352d..b7cea279 100644 --- a/mRemoteV1/Config/Connections/XmlConnectionsSaver.cs +++ b/mRemoteV1/Config/Connections/XmlConnectionsSaver.cs @@ -32,19 +32,16 @@ namespace mRemoteNG.Config.Connections try { var cryptographyProvider = new CryptoProviderFactoryFromSettings().Build(); - var connectionNodeSerializer = new XmlConnectionNodeSerializer27( - cryptographyProvider, - connectionTreeModel - .RootNodes.OfType() - .First().PasswordString - .ConvertToSecureString(), - _saveFilter); - var xmlConnectionsSerializer = - new XmlConnectionsSerializer(cryptographyProvider, connectionNodeSerializer) - { - UseFullEncryption = mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile - }; - var xml = xmlConnectionsSerializer.Serialize(connectionTreeModel); + var serializerFactory = new XmlConnectionSerializerFactory(); + + var xmlConnectionsSerializer = serializerFactory.Build( + cryptographyProvider, + connectionTreeModel, + _saveFilter, + mRemoteNG.Settings.Default.EncryptCompleteConnectionsFile); + + var rootNode = connectionTreeModel.RootNodes.OfType().First(); + var xml = xmlConnectionsSerializer.Serialize(rootNode); var fileDataProvider = new FileDataProviderWithRollingBackup(_connectionFileName); fileDataProvider.Save(xml); diff --git a/mRemoteV1/Config/Serializers/ConnectionSerializers/Xml/XmlConnectionSerializerFactory.cs b/mRemoteV1/Config/Serializers/ConnectionSerializers/Xml/XmlConnectionSerializerFactory.cs new file mode 100644 index 00000000..c8dbf362 --- /dev/null +++ b/mRemoteV1/Config/Serializers/ConnectionSerializers/Xml/XmlConnectionSerializerFactory.cs @@ -0,0 +1,33 @@ +using System.Linq; +using mRemoteNG.Connection; +using mRemoteNG.Security; +using mRemoteNG.Tree; +using mRemoteNG.Tree.Root; + +namespace mRemoteNG.Config.Serializers.Xml +{ + public class XmlConnectionSerializerFactory + { + public ISerializer Build( + ICryptographyProvider cryptographyProvider, + ConnectionTreeModel connectionTreeModel, + SaveFilter saveFilter = null, + bool useFullEncryption = false) + { + var encryptionKey = connectionTreeModel + .RootNodes.OfType() + .First().PasswordString + .ConvertToSecureString(); + + var connectionNodeSerializer = new XmlConnectionNodeSerializer27( + cryptographyProvider, + encryptionKey, + saveFilter ?? new SaveFilter()); + + return new XmlConnectionsSerializer(cryptographyProvider, connectionNodeSerializer) + { + UseFullEncryption = useFullEncryption + }; + } + } +} diff --git a/mRemoteV1/Resources/Language/Language.Designer.cs b/mRemoteV1/Resources/Language/Language.Designer.cs index 462d965e..4bf02569 100644 --- a/mRemoteV1/Resources/Language/Language.Designer.cs +++ b/mRemoteV1/Resources/Language/Language.Designer.cs @@ -19,7 +19,7 @@ namespace mRemoteNG { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Language { @@ -186,6 +186,24 @@ namespace mRemoteNG { } } + /// + /// Looks up a localized string similar to Encryption Test. + /// + internal static string EncryptionTest { + get { + return ResourceManager.GetString("EncryptionTest", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Encrypting {0} entries using {1}/{2} and {3} iterations took {4} seconds.. + /// + internal static string EncryptionTestResultMessage { + get { + return ResourceManager.GetString("EncryptionTestResultMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Environment. /// @@ -7984,6 +8002,15 @@ namespace mRemoteNG { } } + /// + /// Looks up a localized string similar to Test Settings. + /// + internal static string TestSettings { + get { + return ResourceManager.GetString("TestSettings", resourceCulture); + } + } + /// /// Looks up a localized string similar to An unhandled exception has occurred. /// diff --git a/mRemoteV1/Resources/Language/Language.resx b/mRemoteV1/Resources/Language/Language.resx index cf45009c..62072629 100644 --- a/mRemoteV1/Resources/Language/Language.resx +++ b/mRemoteV1/Resources/Language/Language.resx @@ -2793,4 +2793,13 @@ Development Channel includes Alphas, Betas & Release Candidates. Environment + + Encrypting {0} entries using {1}/{2} and {3} iterations took {4} seconds. + + + Encryption Test + + + Test Settings + \ No newline at end of file diff --git a/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.Designer.cs b/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.Designer.cs index ef4c347b..497ef280 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.Designer.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.Designer.cs @@ -34,12 +34,13 @@ this.labelBlockCipher = new mRemoteNG.UI.Controls.Base.NGLabel(); this.comboBoxBlockCipher = new mRemoteNG.UI.Controls.Base.NGComboBox(); this.groupAdvancedSecurityOptions = new mRemoteNG.UI.Controls.Base.NGGroupBox(); - this.numberBoxKdfIterations = new mRemoteNG.UI.Controls.Base.NGNumericUpDown(); - this.labelKdfIterations = new mRemoteNG.UI.Controls.Base.NGLabel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.btnTestSettings = new mRemoteNG.UI.Controls.Base.NGButton(); + this.labelKdfIterations = new mRemoteNG.UI.Controls.Base.NGLabel(); + this.numberBoxKdfIterations = new mRemoteNG.UI.Controls.Base.NGNumericUpDown(); this.groupAdvancedSecurityOptions.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numberBoxKdfIterations)).BeginInit(); this.tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numberBoxKdfIterations)).BeginInit(); this.SuspendLayout(); // // chkEncryptCompleteFile @@ -60,7 +61,7 @@ this.comboBoxEncryptionEngine.Dock = System.Windows.Forms.DockStyle.Fill; this.comboBoxEncryptionEngine.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxEncryptionEngine.FormattingEnabled = true; - this.comboBoxEncryptionEngine.Location = new System.Drawing.Point(223, 3); + this.comboBoxEncryptionEngine.Location = new System.Drawing.Point(190, 3); this.comboBoxEncryptionEngine.Name = "comboBoxEncryptionEngine"; this.comboBoxEncryptionEngine.Size = new System.Drawing.Size(131, 21); this.comboBoxEncryptionEngine.Sorted = true; @@ -72,7 +73,7 @@ this.labelEncryptionEngine.Dock = System.Windows.Forms.DockStyle.Fill; this.labelEncryptionEngine.Location = new System.Drawing.Point(3, 0); this.labelEncryptionEngine.Name = "labelEncryptionEngine"; - this.labelEncryptionEngine.Size = new System.Drawing.Size(214, 26); + this.labelEncryptionEngine.Size = new System.Drawing.Size(181, 27); this.labelEncryptionEngine.TabIndex = 0; this.labelEncryptionEngine.Text = "Encryption Engine"; this.labelEncryptionEngine.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -81,9 +82,9 @@ // this.labelBlockCipher.AutoSize = true; this.labelBlockCipher.Dock = System.Windows.Forms.DockStyle.Fill; - this.labelBlockCipher.Location = new System.Drawing.Point(3, 26); + this.labelBlockCipher.Location = new System.Drawing.Point(3, 27); this.labelBlockCipher.Name = "labelBlockCipher"; - this.labelBlockCipher.Size = new System.Drawing.Size(214, 26); + this.labelBlockCipher.Size = new System.Drawing.Size(181, 27); this.labelBlockCipher.TabIndex = 2; this.labelBlockCipher.Text = "Block Cipher Mode"; this.labelBlockCipher.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -94,21 +95,69 @@ this.comboBoxBlockCipher.Dock = System.Windows.Forms.DockStyle.Fill; this.comboBoxBlockCipher.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxBlockCipher.FormattingEnabled = true; - this.comboBoxBlockCipher.Location = new System.Drawing.Point(223, 29); + this.comboBoxBlockCipher.Location = new System.Drawing.Point(190, 30); this.comboBoxBlockCipher.Name = "comboBoxBlockCipher"; this.comboBoxBlockCipher.Size = new System.Drawing.Size(131, 21); - this.comboBoxBlockCipher.TabIndex = 3; + this.comboBoxBlockCipher.TabIndex = 2; // // groupAdvancedSecurityOptions // this.groupAdvancedSecurityOptions.Controls.Add(this.tableLayoutPanel1); this.groupAdvancedSecurityOptions.Location = new System.Drawing.Point(3, 30); this.groupAdvancedSecurityOptions.Name = "groupAdvancedSecurityOptions"; - this.groupAdvancedSecurityOptions.Size = new System.Drawing.Size(604, 112); + this.groupAdvancedSecurityOptions.Size = new System.Drawing.Size(604, 134); this.groupAdvancedSecurityOptions.TabIndex = 1; this.groupAdvancedSecurityOptions.TabStop = false; this.groupAdvancedSecurityOptions.Text = "Advanced Security Options"; // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.AutoSize = true; + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.Controls.Add(this.labelKdfIterations, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.numberBoxKdfIterations, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.labelBlockCipher, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.comboBoxEncryptionEngine, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.labelEncryptionEngine, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.comboBoxBlockCipher, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.btnTestSettings, 1, 3); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left; + this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 18); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 4; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(324, 113); + this.tableLayoutPanel1.TabIndex = 2; + // + // btnTestSettings + // + this.btnTestSettings._mice = mRemoteNG.UI.Controls.Base.NGButton.MouseState.OUT; + this.btnTestSettings.AutoSize = true; + this.btnTestSettings.Dock = System.Windows.Forms.DockStyle.Right; + this.btnTestSettings.Location = new System.Drawing.Point(240, 85); + this.btnTestSettings.Name = "btnTestSettings"; + this.btnTestSettings.Size = new System.Drawing.Size(81, 25); + this.btnTestSettings.TabIndex = 4; + this.btnTestSettings.Text = "Test Settings"; + this.btnTestSettings.UseVisualStyleBackColor = true; + this.btnTestSettings.Click += new System.EventHandler(this.BtnTestSettings_Click); + // + // labelKdfIterations + // + this.labelKdfIterations.AutoSize = true; + this.labelKdfIterations.Dock = System.Windows.Forms.DockStyle.Fill; + this.labelKdfIterations.Location = new System.Drawing.Point(3, 54); + this.labelKdfIterations.Name = "labelKdfIterations"; + this.labelKdfIterations.Size = new System.Drawing.Size(181, 28); + this.labelKdfIterations.TabIndex = 4; + this.labelKdfIterations.Text = "Key Derivation Function Iterations"; + this.labelKdfIterations.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // // numberBoxKdfIterations // this.numberBoxKdfIterations.Dock = System.Windows.Forms.DockStyle.Fill; @@ -117,7 +166,7 @@ 0, 0, 0}); - this.numberBoxKdfIterations.Location = new System.Drawing.Point(223, 55); + this.numberBoxKdfIterations.Location = new System.Drawing.Point(190, 57); this.numberBoxKdfIterations.Maximum = new decimal(new int[] { 50000, 0, @@ -130,7 +179,7 @@ 0}); this.numberBoxKdfIterations.Name = "numberBoxKdfIterations"; this.numberBoxKdfIterations.Size = new System.Drawing.Size(131, 22); - this.numberBoxKdfIterations.TabIndex = 5; + this.numberBoxKdfIterations.TabIndex = 3; this.numberBoxKdfIterations.ThousandsSeparator = true; this.numberBoxKdfIterations.Value = new decimal(new int[] { 1000, @@ -138,38 +187,6 @@ 0, 0}); // - // labelKdfIterations - // - this.labelKdfIterations.AutoSize = true; - this.labelKdfIterations.Dock = System.Windows.Forms.DockStyle.Fill; - this.labelKdfIterations.Location = new System.Drawing.Point(3, 52); - this.labelKdfIterations.Name = "labelKdfIterations"; - this.labelKdfIterations.Size = new System.Drawing.Size(214, 26); - this.labelKdfIterations.TabIndex = 4; - this.labelKdfIterations.Text = "Key Derivation Function Iterations"; - this.labelKdfIterations.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // - // tableLayoutPanel1 - // - this.tableLayoutPanel1.ColumnCount = 2; - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 220F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tableLayoutPanel1.Controls.Add(this.labelKdfIterations, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.numberBoxKdfIterations, 1, 2); - this.tableLayoutPanel1.Controls.Add(this.labelBlockCipher, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.comboBoxEncryptionEngine, 1, 0); - this.tableLayoutPanel1.Controls.Add(this.labelEncryptionEngine, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.comboBoxBlockCipher, 1, 1); - this.tableLayoutPanel1.Location = new System.Drawing.Point(6, 21); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 4; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(357, 81); - this.tableLayoutPanel1.TabIndex = 2; - // // SecurityPage // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -179,9 +196,10 @@ this.Name = "SecurityPage"; this.Size = new System.Drawing.Size(610, 490); this.groupAdvancedSecurityOptions.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.numberBoxKdfIterations)).EndInit(); + this.groupAdvancedSecurityOptions.PerformLayout(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numberBoxKdfIterations)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -198,5 +216,6 @@ private Controls.Base.NGNumericUpDown numberBoxKdfIterations; private Controls.Base.NGLabel labelKdfIterations; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private Controls.Base.NGButton btnTestSettings; } } diff --git a/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.cs b/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.cs index 2aca2c0c..cf240151 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/SecurityPage.cs @@ -1,6 +1,12 @@ using System; using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Windows.Forms; +using mRemoteNG.App; +using mRemoteNG.Config.Serializers.Xml; using mRemoteNG.Security; +using mRemoteNG.Security.Factories; namespace mRemoteNG.UI.Forms.OptionsPages { @@ -30,6 +36,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages labelEncryptionEngine.Text = Language.strEncryptionEngine; labelKdfIterations.Text = Language.strEncryptionKeyDerivationIterations; groupAdvancedSecurityOptions.Text = Language.strAdvancedSecurityOptions; + btnTestSettings.Text = Language.TestSettings; } public override void LoadSettings() @@ -62,5 +69,33 @@ namespace mRemoteNG.UI.Forms.OptionsPages { comboBoxBlockCipher.DataSource = Enum.GetValues(typeof(BlockCipherModes)); } + + private void BtnTestSettings_Click(object sender, EventArgs e) + { + var connectionTree = Runtime.ConnectionsService.ConnectionTreeModel; + if (!connectionTree.RootNodes.Any()) + return; + + var engine = (BlockCipherEngines) comboBoxEncryptionEngine.SelectedItem; + var mode = (BlockCipherModes) comboBoxBlockCipher.SelectedItem; + var cryptographyProvider = new CryptoProviderFactory(engine, mode).Build(); + cryptographyProvider.KeyDerivationIterations = (int) numberBoxKdfIterations.Value; + + var serializerFactory = new XmlConnectionSerializerFactory(); + var serializer = serializerFactory.Build(cryptographyProvider, connectionTree, useFullEncryption: chkEncryptCompleteFile.Checked); + var nodeCount = connectionTree.GetRecursiveChildList().Count; + + var timer = Stopwatch.StartNew(); + var rootNode = connectionTree.RootNodes.First(); + serializer.Serialize(rootNode); + timer.Stop(); + + MessageBox.Show(this, + string.Format(Language.EncryptionTestResultMessage, + nodeCount, engine, mode, numberBoxKdfIterations.Value, timer.Elapsed.TotalSeconds), + Language.EncryptionTest, + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } } } \ No newline at end of file diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index e5b4be9a..4fab83af 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -172,6 +172,7 @@ +