diff --git a/TGControlPanel/App.config b/TGControlPanel/App.config
index c486f0c3e1..4482a045a4 100644
--- a/TGControlPanel/App.config
+++ b/TGControlPanel/App.config
@@ -35,6 +35,15 @@
38607
+
+ False
+
+
+
+
+
+
+
diff --git a/TGControlPanel/Login.Designer.cs b/TGControlPanel/Login.Designer.cs
index 3702be9df3..ab89ca606b 100644
--- a/TGControlPanel/Login.Designer.cs
+++ b/TGControlPanel/Login.Designer.cs
@@ -40,15 +40,16 @@
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.PortSelector = new System.Windows.Forms.NumericUpDown();
+ this.SavePasswordCheckBox = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.PortSelector)).BeginInit();
this.SuspendLayout();
//
// LocalLoginButton
//
this.LocalLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.LocalLoginButton.Location = new System.Drawing.Point(87, 12);
+ this.LocalLoginButton.Location = new System.Drawing.Point(102, 12);
this.LocalLoginButton.Name = "LocalLoginButton";
- this.LocalLoginButton.Size = new System.Drawing.Size(188, 25);
+ this.LocalLoginButton.Size = new System.Drawing.Size(157, 25);
this.LocalLoginButton.TabIndex = 13;
this.LocalLoginButton.Text = "Connect to Local Service";
this.LocalLoginButton.UseVisualStyleBackColor = true;
@@ -91,9 +92,9 @@
// RemoteLoginButton
//
this.RemoteLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.RemoteLoginButton.Location = new System.Drawing.Point(87, 200);
+ this.RemoteLoginButton.Location = new System.Drawing.Point(102, 200);
this.RemoteLoginButton.Name = "RemoteLoginButton";
- this.RemoteLoginButton.Size = new System.Drawing.Size(188, 25);
+ this.RemoteLoginButton.Size = new System.Drawing.Size(157, 25);
this.RemoteLoginButton.TabIndex = 18;
this.RemoteLoginButton.Text = "Connect to Remote Service";
this.RemoteLoginButton.UseVisualStyleBackColor = true;
@@ -162,12 +163,24 @@
0});
this.PortSelector.Name = "PortSelector";
this.PortSelector.Size = new System.Drawing.Size(80, 20);
- this.PortSelector.TabIndex = 23;
+ this.PortSelector.TabIndex = 16;
this.PortSelector.Value = new decimal(new int[] {
1,
0,
0,
0});
+ //
+ // SavePasswordCheckBox
+ //
+ this.SavePasswordCheckBox.AutoSize = true;
+ this.SavePasswordCheckBox.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242)))));
+ this.SavePasswordCheckBox.Location = new System.Drawing.Point(265, 205);
+ this.SavePasswordCheckBox.Name = "SavePasswordCheckBox";
+ this.SavePasswordCheckBox.Size = new System.Drawing.Size(100, 17);
+ this.SavePasswordCheckBox.TabIndex = 23;
+ this.SavePasswordCheckBox.Text = "Save Password";
+ this.SavePasswordCheckBox.UseVisualStyleBackColor = true;
+ this.SavePasswordCheckBox.CheckedChanged += new System.EventHandler(this.SavePasswordCheckBox_CheckedChanged);
//
// Login
//
@@ -175,6 +188,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34)))));
this.ClientSize = new System.Drawing.Size(374, 237);
+ this.Controls.Add(this.SavePasswordCheckBox);
this.Controls.Add(this.PortSelector);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
@@ -211,5 +225,6 @@
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.NumericUpDown PortSelector;
- }
+ private System.Windows.Forms.CheckBox SavePasswordCheckBox;
+ }
}
\ No newline at end of file
diff --git a/TGControlPanel/Login.cs b/TGControlPanel/Login.cs
index b6292425df..96489f597a 100644
--- a/TGControlPanel/Login.cs
+++ b/TGControlPanel/Login.cs
@@ -9,11 +9,19 @@ namespace TGControlPanel
public Login()
{
InitializeComponent();
- IPTextBox.Text = Properties.Settings.Default.RemoteIP;
var Config = Properties.Settings.Default;
+ IPTextBox.Text = Config.RemoteIP;
UsernameTextBox.Text = Config.RemoteUsername;
PortSelector.Value = Config.RemotePort;
AcceptButton = RemoteLoginButton;
+ if(Config.RemoteDefault)
+ RemoteLoginButton.TabIndex = 0; //make this the first thing selected when loading
+ var decrypted = Helpers.DecryptData(Config.RemotePassword, Config.RemoteEntropy);
+ if (decrypted != null)
+ {
+ PasswordTextBox.Text = decrypted;
+ SavePasswordCheckBox.Checked = true;
+ }
}
private void RemoteLoginButton_Click(object sender, EventArgs e)
@@ -21,14 +29,27 @@ namespace TGControlPanel
IPTextBox.Text = IPTextBox.Text.Trim();
UsernameTextBox.Text = UsernameTextBox.Text.Trim();
Server.SetRemoteLoginInformation(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text);
- Properties.Settings.Default.RemoteIP = IPTextBox.Text;
- Properties.Settings.Default.RemoteUsername = UsernameTextBox.Text;
+ var Config = Properties.Settings.Default;
+ Config.RemoteIP = IPTextBox.Text;
+ Config.RemoteUsername = UsernameTextBox.Text;
+ if (SavePasswordCheckBox.Checked)
+ {
+ Config.RemotePassword = Helpers.EncryptData(PasswordTextBox.Text, out string entrop);
+ Config.RemoteEntropy = entrop;
+ }
+ else
+ {
+ Config.RemotePassword = null;
+ Config.RemoteEntropy = null;
+ }
+ Config.RemoteDefault = true;
VerifyAndConnect();
}
private void LocalLoginButton_Click(object sender, EventArgs e)
{
Server.MakeLocalConnection();
+ Properties.Settings.Default.RemoteDefault = false;
VerifyAndConnect();
}
@@ -49,5 +70,15 @@ namespace TGControlPanel
new Main().ShowDialog();
Close();
}
+
+ private void SavePasswordCheckBox_CheckedChanged(object sender, EventArgs e)
+ {
+ if (!SavePasswordCheckBox.Checked)
+ {
+ var Config = Properties.Settings.Default;
+ Config.RemotePassword = null;
+ Config.RemoteEntropy = null;
+ }
+ }
}
}
diff --git a/TGControlPanel/Properties/Settings.Designer.cs b/TGControlPanel/Properties/Settings.Designer.cs
index 0374631b7f..e3448811d3 100644
--- a/TGControlPanel/Properties/Settings.Designer.cs
+++ b/TGControlPanel/Properties/Settings.Designer.cs
@@ -106,5 +106,41 @@ namespace TGControlPanel.Properties {
this["RemotePort"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ public bool RemoteDefault {
+ get {
+ return ((bool)(this["RemoteDefault"]));
+ }
+ set {
+ this["RemoteDefault"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string RemotePassword {
+ get {
+ return ((string)(this["RemotePassword"]));
+ }
+ set {
+ this["RemotePassword"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string RemoteEntropy {
+ get {
+ return ((string)(this["RemoteEntropy"]));
+ }
+ set {
+ this["RemoteEntropy"] = value;
+ }
+ }
}
}
diff --git a/TGControlPanel/Properties/Settings.settings b/TGControlPanel/Properties/Settings.settings
index 1e46d94a5a..75fb36e555 100644
--- a/TGControlPanel/Properties/Settings.settings
+++ b/TGControlPanel/Properties/Settings.settings
@@ -23,5 +23,14 @@
38607
+
+ False
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TGServerService/Chat.cs b/TGServerService/Chat.cs
index 3d9ac45b74..12ced80fa9 100644
--- a/TGServerService/Chat.cs
+++ b/TGServerService/Chat.cs
@@ -167,9 +167,7 @@ namespace TGServerService
var rawdata = new JavaScriptSerializer().Serialize(infosList);
var Config = Properties.Settings.Default;
- byte[] plaintext = Encoding.UTF8.GetBytes(rawdata);
-
- Config.ChatProviderData = Program.EncryptData(plaintext, out string entrp);
+ Config.ChatProviderData = Helpers.EncryptData(rawdata, out string entrp);
Config.ChatProviderEntropy = entrp;
}
@@ -191,12 +189,12 @@ namespace TGServerService
if (rawdata == "NEEDS INITIALIZING")
return new List() { new TGIRCSetupInfo(), new TGDiscordSetupInfo() };
- byte[] plaintext;
+ string plaintext;
try
{
- plaintext = Program.DecryptData(rawdata, Config.ChatProviderEntropy);
+ plaintext = Helpers.DecryptData(rawdata, Config.ChatProviderEntropy);
- var lists = new JavaScriptSerializer().Deserialize>>(Encoding.UTF8.GetString(plaintext));
+ var lists = new JavaScriptSerializer().Deserialize>>(plaintext);
var output = new List(lists.Count);
var foundirc = 0;
var founddiscord = 0;
diff --git a/TGServerService/Program.cs b/TGServerService/Program.cs
index 44c29e9269..d4822ea533 100644
--- a/TGServerService/Program.cs
+++ b/TGServerService/Program.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Security.Cryptography;
namespace TGServerService
{
@@ -61,24 +60,6 @@ namespace TGServerService
}
}
- public static string EncryptData(byte[] data, out string sentropy)
- {
- // Generate additional entropy (will be used as the Initialization vector)
- byte[] entropy = new byte[20];
- using (var rng = new RNGCryptoServiceProvider())
- rng.GetBytes(entropy);
-
- byte[] ciphertext = ProtectedData.Protect(data, entropy, DataProtectionScope.CurrentUser);
-
- sentropy = Convert.ToBase64String(entropy, 0, entropy.Length);
- return Convert.ToBase64String(ciphertext, 0, ciphertext.Length);
- }
-
- public static byte[] DecryptData(string data, string entropy)
- {
- return ProtectedData.Unprotect(Convert.FromBase64String(data), Convert.FromBase64String(entropy), DataProtectionScope.CurrentUser);
- }
-
public static void CopyDirectory(string sourceDirName, string destDirName, IList ignore = null, bool ignoreIfNotExists = false)
{
// If the destination directory doesn't exist, create it.
diff --git a/TGServerService/TGServerService.csproj b/TGServerService/TGServerService.csproj
index be99d0143d..c4c6aa7583 100644
--- a/TGServerService/TGServerService.csproj
+++ b/TGServerService/TGServerService.csproj
@@ -71,7 +71,6 @@
-
diff --git a/TGServiceInterface/Helpers.cs b/TGServiceInterface/Helpers.cs
new file mode 100644
index 0000000000..6d8e3e0f70
--- /dev/null
+++ b/TGServiceInterface/Helpers.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace TGServiceInterface
+{
+ public static class Helpers
+ {
+ public static string EncryptData(string data, out string sentropy)
+ {
+ // Generate additional entropy (will be used as the Initialization vector)
+ byte[] entropy = new byte[20];
+ using (var rng = new RNGCryptoServiceProvider())
+ rng.GetBytes(entropy);
+
+ byte[] ciphertext = ProtectedData.Protect(Encoding.UTF8.GetBytes(data), entropy, DataProtectionScope.CurrentUser);
+
+ sentropy = Convert.ToBase64String(entropy, 0, entropy.Length);
+ return Convert.ToBase64String(ciphertext, 0, ciphertext.Length);
+ }
+
+ public static string DecryptData(string data, string entropy)
+ {
+ try
+ {
+ return Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(data), Convert.FromBase64String(entropy), DataProtectionScope.CurrentUser));
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/TGServiceInterface/TGServiceInterface.csproj b/TGServiceInterface/TGServiceInterface.csproj
index 864ffc9a7b..a098c77c14 100644
--- a/TGServiceInterface/TGServiceInterface.csproj
+++ b/TGServiceInterface/TGServiceInterface.csproj
@@ -40,6 +40,7 @@
+
@@ -52,6 +53,7 @@
+