added button to test encryption settings on the security page

This commit is contained in:
David Sparer
2019-05-18 15:10:08 -05:00
parent 57d8b0c803
commit 63c78f986d
7 changed files with 180 additions and 59 deletions

View File

@@ -32,19 +32,16 @@ namespace mRemoteNG.Config.Connections
try
{
var cryptographyProvider = new CryptoProviderFactoryFromSettings().Build();
var connectionNodeSerializer = new XmlConnectionNodeSerializer27(
cryptographyProvider,
connectionTreeModel
.RootNodes.OfType<RootNodeInfo>()
.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<RootNodeInfo>().First();
var xml = xmlConnectionsSerializer.Serialize(rootNode);
var fileDataProvider = new FileDataProviderWithRollingBackup(_connectionFileName);
fileDataProvider.Save(xml);

View File

@@ -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<ConnectionInfo, string> Build(
ICryptographyProvider cryptographyProvider,
ConnectionTreeModel connectionTreeModel,
SaveFilter saveFilter = null,
bool useFullEncryption = false)
{
var encryptionKey = connectionTreeModel
.RootNodes.OfType<RootNodeInfo>()
.First().PasswordString
.ConvertToSecureString();
var connectionNodeSerializer = new XmlConnectionNodeSerializer27(
cryptographyProvider,
encryptionKey,
saveFilter ?? new SaveFilter());
return new XmlConnectionsSerializer(cryptographyProvider, connectionNodeSerializer)
{
UseFullEncryption = useFullEncryption
};
}
}
}

View File

@@ -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 {
}
}
/// <summary>
/// Looks up a localized string similar to Encryption Test.
/// </summary>
internal static string EncryptionTest {
get {
return ResourceManager.GetString("EncryptionTest", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Encrypting {0} entries using {1}/{2} and {3} iterations took {4} seconds..
/// </summary>
internal static string EncryptionTestResultMessage {
get {
return ResourceManager.GetString("EncryptionTestResultMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Environment.
/// </summary>
@@ -7984,6 +8002,15 @@ namespace mRemoteNG {
}
}
/// <summary>
/// Looks up a localized string similar to Test Settings.
/// </summary>
internal static string TestSettings {
get {
return ResourceManager.GetString("TestSettings", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An unhandled exception has occurred.
/// </summary>

View File

@@ -2793,4 +2793,13 @@ Development Channel includes Alphas, Betas &amp; Release Candidates.</value>
<data name="Environment" xml:space="preserve">
<value>Environment</value>
</data>
<data name="EncryptionTestResultMessage" xml:space="preserve">
<value>Encrypting {0} entries using {1}/{2} and {3} iterations took {4} seconds.</value>
</data>
<data name="EncryptionTest" xml:space="preserve">
<value>Encryption Test</value>
</data>
<data name="TestSettings" xml:space="preserve">
<value>Test Settings</value>
</data>
</root>

View File

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

View File

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

View File

@@ -172,6 +172,7 @@
<Compile Include="Config\Serializers\ConnectionSerializers\MsSql\LocalConnectionPropertiesModel.cs" />
<Compile Include="Config\Serializers\ConnectionSerializers\MsSql\LocalConnectionPropertiesXmlSerializer.cs" />
<Compile Include="Config\Serializers\ConnectionSerializers\MsSql\SqlConnectionListMetaData.cs" />
<Compile Include="Config\Serializers\ConnectionSerializers\Xml\XmlConnectionSerializerFactory.cs" />
<Compile Include="Config\Serializers\ConnectionSerializers\Xml\XmlExtensions.cs" />
<Compile Include="Config\Serializers\CredentialProviderSerializer\CredentialRepositoryListDeserializer.cs" />
<Compile Include="Config\CredentialRepositoryListLoader.cs" />