mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
added secure text box
This commit is contained in:
28
mRemoteNGTests/NUnitExtensions/SecureTextBoxTester.cs
Normal file
28
mRemoteNGTests/NUnitExtensions/SecureTextBoxTester.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.UI.Controls;
|
||||
using NUnit.Extensions.Forms;
|
||||
|
||||
|
||||
namespace mRemoteNGTests.NUnitExtensions
|
||||
{
|
||||
public class SecureTextBoxTester : ControlTester
|
||||
{
|
||||
public SecureTextBoxTester(string name, string formName) : base(name, formName)
|
||||
{
|
||||
}
|
||||
|
||||
public SecureTextBoxTester(string name, Form form) : base(name, form)
|
||||
{
|
||||
}
|
||||
|
||||
public SecureTextBoxTester(string name) : base(name)
|
||||
{
|
||||
}
|
||||
|
||||
public SecureTextBoxTester(ControlTester tester, int index) : base(tester, index)
|
||||
{
|
||||
}
|
||||
|
||||
public SecureTextBox Properties => (SecureTextBox) Control;
|
||||
}
|
||||
}
|
||||
61
mRemoteNGTests/UI/Controls/SecureTextBoxTestForm.Designer.cs
generated
Normal file
61
mRemoteNGTests/UI/Controls/SecureTextBoxTestForm.Designer.cs
generated
Normal file
@@ -0,0 +1,61 @@
|
||||
using mRemoteNG.UI.Controls;
|
||||
|
||||
namespace mRemoteNGTests.UI.Controls
|
||||
{
|
||||
partial class SecureTextBoxTestForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.secureTextBox1 = new mRemoteNG.UI.Controls.SecureTextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// secureTextBox1
|
||||
//
|
||||
this.secureTextBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.secureTextBox1.Name = "secureTextBox1";
|
||||
this.secureTextBox1.ShortcutsEnabled = false;
|
||||
this.secureTextBox1.Size = new System.Drawing.Size(232, 20);
|
||||
this.secureTextBox1.TabIndex = 0;
|
||||
//
|
||||
// SecureTextBoxTestForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(256, 45);
|
||||
this.Controls.Add(this.secureTextBox1);
|
||||
this.Name = "SecureTextBoxTestForm";
|
||||
this.Text = "SecureTextBoxTestForm";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal SecureTextBox secureTextBox1;
|
||||
}
|
||||
}
|
||||
13
mRemoteNGTests/UI/Controls/SecureTextBoxTestForm.cs
Normal file
13
mRemoteNGTests/UI/Controls/SecureTextBoxTestForm.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace mRemoteNGTests.UI.Controls
|
||||
{
|
||||
public partial class SecureTextBoxTestForm : Form
|
||||
{
|
||||
public SecureTextBoxTestForm()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
mRemoteNGTests/UI/Controls/SecureTextBoxTestForm.resx
Normal file
120
mRemoteNGTests/UI/Controls/SecureTextBoxTestForm.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
35
mRemoteNGTests/UI/Controls/SecureTextBoxTests.cs
Normal file
35
mRemoteNGTests/UI/Controls/SecureTextBoxTests.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using mRemoteNG.Security;
|
||||
using mRemoteNGTests.NUnitExtensions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace mRemoteNGTests.UI.Controls
|
||||
{
|
||||
public class SecureTextBoxTests
|
||||
{
|
||||
private SecureTextBoxTestForm _testForm;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_testForm = new SecureTextBoxTestForm();
|
||||
_testForm.Show();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_testForm.Close();
|
||||
while (_testForm.Disposing) { }
|
||||
_testForm = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TextboxInputGetsAddedToSecureString()
|
||||
{
|
||||
var textBox = new SecureTextBoxTester(_testForm.secureTextBox1.Name);
|
||||
const string textToSend = "abc123";
|
||||
textBox.Properties.Text = textToSend;
|
||||
Assert.That(textBox.Properties.SecureString.ConvertToUnsecureString(), Is.EqualTo(textToSend));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,7 @@
|
||||
<Compile Include="Credential\CredentialRecordTests.cs" />
|
||||
<Compile Include="Credential\CredentialListBaseTests.cs" />
|
||||
<Compile Include="IntegrationTests\XmlSerializationLifeCycleTests.cs" />
|
||||
<Compile Include="NUnitExtensions\SecureTextBoxTester.cs" />
|
||||
<Compile Include="Security\Authentication\PasswordAuthenticatorTests.cs" />
|
||||
<Compile Include="Security\KeyDerivation\Pkcs5S2KeyGeneratorTests.cs" />
|
||||
<Compile Include="Security\SecureStringExtensionsTests.cs" />
|
||||
@@ -166,6 +167,13 @@
|
||||
<Compile Include="Tree\RootNodeInfoTests.cs" />
|
||||
<Compile Include="Tree\ClickHandlers\SwitchToConnectionClickHandlerTests.cs" />
|
||||
<Compile Include="Tree\SelectedConnectionDeletionConfirmerTests.cs" />
|
||||
<Compile Include="UI\Controls\SecureTextBoxTestForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UI\Controls\SecureTextBoxTestForm.designer.cs">
|
||||
<DependentUpon>SecureTextBoxTestForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\Controls\SecureTextBoxTests.cs" />
|
||||
<Compile Include="UI\Controls\TestForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -191,6 +199,9 @@
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="UI\Controls\SecureTextBoxTestForm.resx">
|
||||
<DependentUpon>SecureTextBoxTestForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="UI\Controls\TestForm.resx">
|
||||
<DependentUpon>TestForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
36
mRemoteV1/UI/Controls/SecureTextBox.Designer.cs
generated
Normal file
36
mRemoteV1/UI/Controls/SecureTextBox.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace mRemoteNG.UI.Controls
|
||||
{
|
||||
partial class SecureTextBox
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
23
mRemoteV1/UI/Controls/SecureTextBox.cs
Normal file
23
mRemoteV1/UI/Controls/SecureTextBox.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Security;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.Security;
|
||||
|
||||
|
||||
namespace mRemoteNG.UI.Controls
|
||||
{
|
||||
public partial class SecureTextBox : TextBox
|
||||
{
|
||||
public SecureString SecureString { get; private set; } = new SecureString();
|
||||
|
||||
public SecureTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
TextChanged += SecureTextBox_TextChanged;
|
||||
}
|
||||
|
||||
private void SecureTextBox_TextChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
SecureString = Text.ConvertToSecureString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,6 +269,12 @@
|
||||
<Compile Include="UI\Controls\QuickConnectComboBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UI\Controls\SecureTextBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UI\Controls\SecureTextBox.Designer.cs">
|
||||
<DependentUpon>SecureTextBox.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\Controls\StatusImageList.cs" />
|
||||
<Compile Include="UI\Controls\ToolStripSplitButton.cs">
|
||||
<SubType>Component</SubType>
|
||||
|
||||
Reference in New Issue
Block a user