From 5ddb4887fb332bf43c15080ae23f3cc5f847de0c Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sun, 17 Sep 2017 23:56:02 -0400 Subject: [PATCH 1/4] Makes MakeLocalConnection() used --- TGCommandLine/Program.cs | 6 +++--- TGControlPanel/Login.cs | 2 +- TGServiceInterface/Server.cs | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index 6c1e5f9aef..2d60af356b 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -149,12 +149,12 @@ namespace TGCommandLine if (res != null) { Console.WriteLine("Unable to connect: " + res); - Server.SetRemoteLoginInformation(null, 0, null, null); + Server.MakeLocalConnection(); } else if (!Server.Authenticate()) { Console.WriteLine("Authentication error: Username/password/windows identity is not authorized! Returning to local mode..."); - Server.SetRemoteLoginInformation(null, 0, null, null); + Server.MakeLocalConnection(); } else { @@ -163,7 +163,7 @@ namespace TGCommandLine } break; case "disconnect": - Server.SetRemoteLoginInformation(null, 0, null, null); + Server.MakeLocalConnection(); Console.WriteLine("Switch to local mode"); break; case "quit": diff --git a/TGControlPanel/Login.cs b/TGControlPanel/Login.cs index d37e5a6c8b..b6292425df 100644 --- a/TGControlPanel/Login.cs +++ b/TGControlPanel/Login.cs @@ -28,7 +28,7 @@ namespace TGControlPanel private void LocalLoginButton_Click(object sender, EventArgs e) { - Server.SetRemoteLoginInformation(null, 0, null, null); + Server.MakeLocalConnection(); VerifyAndConnect(); } diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 31360754ff..855250dfb2 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -43,7 +43,8 @@ namespace TGServiceInterface public static void MakeLocalConnection() { HTTPSURL = null; - } + HTTPSPassword = null; + } /// /// Set the interface to look for services on a remote computer @@ -56,7 +57,7 @@ namespace TGServiceInterface HTTPSPort = port; HTTPSUsername = username; HTTPSPassword = password; - } + } /// /// Returns the requested server component interface. This does not guarantee a successful connection @@ -91,12 +92,12 @@ namespace TGServiceInterface { outChannel.Credentials.UserName.UserName = HTTPSUsername; outChannel.Credentials.UserName.Password = HTTPSPassword; - } + } #if DEBUG - //allow self signed certs in debug mode - ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true; + //allow self signed certs in debug mode + ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true; #endif - return outChannel.CreateChannel(); + return outChannel.CreateChannel(); } /// From d655a31bdb068e4a1c1a18a740247c2d1d1565da Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 18 Sep 2017 00:19:55 -0400 Subject: [PATCH 2/4] Added prompts for SSL failures --- TGCommandLine/Program.cs | 29 +++++++-- TGControlPanel/Program.cs | 114 +++++++++++++++++++---------------- TGServiceInterface/Server.cs | 33 ++++++++-- 3 files changed, 116 insertions(+), 60 deletions(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index 2d60af356b..df5fbee814 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -56,9 +56,9 @@ namespace TGCommandLine } if (badConnectionString) - { - Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address:port"); - return ExitCode.BadCommand; + { + Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address:port"); + return ExitCode.BadCommand; } var res = Server.VerifyConnection(); @@ -113,11 +113,30 @@ namespace TGCommandLine return result; } + static bool BadCertificateInteractive(string message) + { + Console.WriteLine(message); + Console.Write("Do you wish to continue? NOT RECCOMENDED! (y/N): "); + var result = Console.ReadLine().Trim().ToLower(); + return result == "y" || result == "yes"; + } + static int Main(string[] args) { Command.OutputProcVar.Value = Console.WriteLine; - if (args.Length != 0) - return (int)RunCommandLine(new List(args)); + if (args.Length != 0) + { + Server.SetBadCertificateHandler((message) => { + foreach (var I in args) + if (I.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much + return true; + return false; + }); + //allow self signed certs in debug mode + return (int)RunCommandLine(new List(args)); + } + + Server.SetBadCertificateHandler(BadCertificateInteractive); Console.WriteLine("Type 'remote' to connect to a remote service"); //interactive mode diff --git a/TGControlPanel/Program.cs b/TGControlPanel/Program.cs index 55de52accf..43ff631518 100644 --- a/TGControlPanel/Program.cs +++ b/TGControlPanel/Program.cs @@ -5,58 +5,70 @@ using TGServiceInterface; namespace TGControlPanel { - static class Program - { - [STAThread] - static void Main(string [] args) - { - try - { - if (Properties.Settings.Default.UpgradeRequired) - { - Properties.Settings.Default.Upgrade(); - Properties.Settings.Default.UpgradeRequired = false; - Properties.Settings.Default.Save(); - } - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Login()); - } - catch (Exception e) - { - ServiceDisconnectException(e); - } - finally - { - Properties.Settings.Default.Save(); - } - } + static class Program + { + [STAThread] + static void Main(string[] args) + { + Server.SetBadCertificateHandler(BadCertificateHandler); + try + { + if (Properties.Settings.Default.UpgradeRequired) + { + Properties.Settings.Default.Upgrade(); + Properties.Settings.Default.UpgradeRequired = false; + Properties.Settings.Default.Save(); + } + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Login()); + } + catch (Exception e) + { + ServiceDisconnectException(e); + } + finally + { + Properties.Settings.Default.Save(); + } + } + static bool SSLErrorPromptResult = false; + static bool BadCertificateHandler(string message) + { + if (!SSLErrorPromptResult) + { + var result = MessageBox.Show(message + " IT IS HIGHLY RECCOMENDED YOU DO NOT PROCEED! Continue?", "SSL Error", MessageBoxButtons.YesNo) == DialogResult.Yes; + SSLErrorPromptResult = result; + return result; + } + return true; + } - public static void ServiceDisconnectException(Exception e) - { - MessageBox.Show("An unhandled exception occurred. This usually means we lost connection to the service. Error" + e.ToString()); - } + public static void ServiceDisconnectException(Exception e) + { + MessageBox.Show("An unhandled exception occurred. This usually means we lost connection to the service. Error" + e.ToString()); + } - public static string TextPrompt(string caption, string text) - { - Form prompt = new Form() - { - Width = 500, - Height = 150, - FormBorderStyle = FormBorderStyle.FixedDialog, - Text = caption, - StartPosition = FormStartPosition.CenterScreen - }; - Label textLabel = new Label() { Left = 50, Top = 20, Text = text, AutoSize = true }; - TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 }; - Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; - confirmation.Click += (sender, e) => { prompt.Close(); }; - prompt.Controls.Add(textBox); - prompt.Controls.Add(confirmation); - prompt.Controls.Add(textLabel); - prompt.AcceptButton = confirmation; + public static string TextPrompt(string caption, string text) + { + Form prompt = new Form() + { + Width = 500, + Height = 150, + FormBorderStyle = FormBorderStyle.FixedDialog, + Text = caption, + StartPosition = FormStartPosition.CenterScreen + }; + Label textLabel = new Label() { Left = 50, Top = 20, Text = text, AutoSize = true }; + TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 }; + Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; + confirmation.Click += (sender, e) => { prompt.Close(); }; + prompt.Controls.Add(textBox); + prompt.Controls.Add(confirmation); + prompt.Controls.Add(textLabel); + prompt.AcceptButton = confirmation; - return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : null; - } - } + return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : null; + } + } } diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 855250dfb2..866bde3d54 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Net.Security; using System.ServiceModel; namespace TGServiceInterface { @@ -37,6 +38,34 @@ namespace TGServiceInterface /// static string HTTPSPassword; + + public static void SetBadCertificateHandler(Func handler) + { + ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => + { + string ErrorMessage; + switch (error) + { + case SslPolicyErrors.None: + return true; + case SslPolicyErrors.RemoteCertificateChainErrors: + ErrorMessage = "There are certificate chain errors."; + break; + case SslPolicyErrors.RemoteCertificateNameMismatch: + ErrorMessage = "The certificate name does not match."; + break; + case SslPolicyErrors.RemoteCertificateNotAvailable: + ErrorMessage = "The certificate doesn't exist in the trust store."; + break; + default: + ErrorMessage = "An unknown error occurred."; + break; + } + ErrorMessage = String.Format("The certificate failed to verify for {0}:{1}. {2} {3}", HTTPSURL, HTTPSPort, ErrorMessage, cert.ToString()); + return handler(ErrorMessage); + }; + } + /// /// Set the interface to look for services on the current computer /// @@ -93,10 +122,6 @@ namespace TGServiceInterface outChannel.Credentials.UserName.UserName = HTTPSUsername; outChannel.Credentials.UserName.Password = HTTPSPassword; } -#if DEBUG - //allow self signed certs in debug mode - ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true; -#endif return outChannel.CreateChannel(); } From a7d8d58f2b4afc0a504fe8f8352651a190e796a6 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 18 Sep 2017 00:21:34 -0400 Subject: [PATCH 3/4] It's always fucking tabs --- TGCommandLine/Program.cs | 44 ++++++------ TGControlPanel/Program.cs | 126 +++++++++++++++++------------------ TGServiceInterface/Server.cs | 62 ++++++++--------- 3 files changed, 116 insertions(+), 116 deletions(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index df5fbee814..9e00cf3df7 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -56,9 +56,9 @@ namespace TGCommandLine } if (badConnectionString) - { - Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address:port"); - return ExitCode.BadCommand; + { + Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address:port"); + return ExitCode.BadCommand; } var res = Server.VerifyConnection(); @@ -113,30 +113,30 @@ namespace TGCommandLine return result; } - static bool BadCertificateInteractive(string message) - { - Console.WriteLine(message); - Console.Write("Do you wish to continue? NOT RECCOMENDED! (y/N): "); - var result = Console.ReadLine().Trim().ToLower(); - return result == "y" || result == "yes"; - } + static bool BadCertificateInteractive(string message) + { + Console.WriteLine(message); + Console.Write("Do you wish to continue? NOT RECCOMENDED! (y/N): "); + var result = Console.ReadLine().Trim().ToLower(); + return result == "y" || result == "yes"; + } static int Main(string[] args) { Command.OutputProcVar.Value = Console.WriteLine; - if (args.Length != 0) - { - Server.SetBadCertificateHandler((message) => { - foreach (var I in args) - if (I.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much - return true; - return false; - }); - //allow self signed certs in debug mode - return (int)RunCommandLine(new List(args)); - } + if (args.Length != 0) + { + Server.SetBadCertificateHandler((message) => { + foreach (var I in args) + if (I.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much + return true; + return false; + }); + //allow self signed certs in debug mode + return (int)RunCommandLine(new List(args)); + } - Server.SetBadCertificateHandler(BadCertificateInteractive); + Server.SetBadCertificateHandler(BadCertificateInteractive); Console.WriteLine("Type 'remote' to connect to a remote service"); //interactive mode diff --git a/TGControlPanel/Program.cs b/TGControlPanel/Program.cs index 43ff631518..280b4f0d54 100644 --- a/TGControlPanel/Program.cs +++ b/TGControlPanel/Program.cs @@ -5,70 +5,70 @@ using TGServiceInterface; namespace TGControlPanel { - static class Program - { - [STAThread] - static void Main(string[] args) - { - Server.SetBadCertificateHandler(BadCertificateHandler); - try - { - if (Properties.Settings.Default.UpgradeRequired) - { - Properties.Settings.Default.Upgrade(); - Properties.Settings.Default.UpgradeRequired = false; - Properties.Settings.Default.Save(); - } - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Login()); - } - catch (Exception e) - { - ServiceDisconnectException(e); - } - finally - { - Properties.Settings.Default.Save(); - } - } - static bool SSLErrorPromptResult = false; - static bool BadCertificateHandler(string message) - { - if (!SSLErrorPromptResult) - { - var result = MessageBox.Show(message + " IT IS HIGHLY RECCOMENDED YOU DO NOT PROCEED! Continue?", "SSL Error", MessageBoxButtons.YesNo) == DialogResult.Yes; - SSLErrorPromptResult = result; - return result; - } - return true; - } + static class Program + { + [STAThread] + static void Main(string[] args) + { + Server.SetBadCertificateHandler(BadCertificateHandler); + try + { + if (Properties.Settings.Default.UpgradeRequired) + { + Properties.Settings.Default.Upgrade(); + Properties.Settings.Default.UpgradeRequired = false; + Properties.Settings.Default.Save(); + } + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Login()); + } + catch (Exception e) + { + ServiceDisconnectException(e); + } + finally + { + Properties.Settings.Default.Save(); + } + } + static bool SSLErrorPromptResult = false; + static bool BadCertificateHandler(string message) + { + if (!SSLErrorPromptResult) + { + var result = MessageBox.Show(message + " IT IS HIGHLY RECCOMENDED YOU DO NOT PROCEED! Continue?", "SSL Error", MessageBoxButtons.YesNo) == DialogResult.Yes; + SSLErrorPromptResult = result; + return result; + } + return true; + } - public static void ServiceDisconnectException(Exception e) - { - MessageBox.Show("An unhandled exception occurred. This usually means we lost connection to the service. Error" + e.ToString()); - } + public static void ServiceDisconnectException(Exception e) + { + MessageBox.Show("An unhandled exception occurred. This usually means we lost connection to the service. Error" + e.ToString()); + } - public static string TextPrompt(string caption, string text) - { - Form prompt = new Form() - { - Width = 500, - Height = 150, - FormBorderStyle = FormBorderStyle.FixedDialog, - Text = caption, - StartPosition = FormStartPosition.CenterScreen - }; - Label textLabel = new Label() { Left = 50, Top = 20, Text = text, AutoSize = true }; - TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 }; - Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; - confirmation.Click += (sender, e) => { prompt.Close(); }; - prompt.Controls.Add(textBox); - prompt.Controls.Add(confirmation); - prompt.Controls.Add(textLabel); - prompt.AcceptButton = confirmation; + public static string TextPrompt(string caption, string text) + { + Form prompt = new Form() + { + Width = 500, + Height = 150, + FormBorderStyle = FormBorderStyle.FixedDialog, + Text = caption, + StartPosition = FormStartPosition.CenterScreen + }; + Label textLabel = new Label() { Left = 50, Top = 20, Text = text, AutoSize = true }; + TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 }; + Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; + confirmation.Click += (sender, e) => { prompt.Close(); }; + prompt.Controls.Add(textBox); + prompt.Controls.Add(confirmation); + prompt.Controls.Add(textLabel); + prompt.AcceptButton = confirmation; - return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : null; - } - } + return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : null; + } + } } diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 866bde3d54..5b8b73ed8e 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -39,32 +39,32 @@ namespace TGServiceInterface static string HTTPSPassword; - public static void SetBadCertificateHandler(Func handler) - { - ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => - { - string ErrorMessage; - switch (error) - { - case SslPolicyErrors.None: - return true; - case SslPolicyErrors.RemoteCertificateChainErrors: - ErrorMessage = "There are certificate chain errors."; - break; - case SslPolicyErrors.RemoteCertificateNameMismatch: - ErrorMessage = "The certificate name does not match."; - break; - case SslPolicyErrors.RemoteCertificateNotAvailable: - ErrorMessage = "The certificate doesn't exist in the trust store."; - break; - default: - ErrorMessage = "An unknown error occurred."; - break; - } - ErrorMessage = String.Format("The certificate failed to verify for {0}:{1}. {2} {3}", HTTPSURL, HTTPSPort, ErrorMessage, cert.ToString()); - return handler(ErrorMessage); - }; - } + public static void SetBadCertificateHandler(Func handler) + { + ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => + { + string ErrorMessage; + switch (error) + { + case SslPolicyErrors.None: + return true; + case SslPolicyErrors.RemoteCertificateChainErrors: + ErrorMessage = "There are certificate chain errors."; + break; + case SslPolicyErrors.RemoteCertificateNameMismatch: + ErrorMessage = "The certificate name does not match."; + break; + case SslPolicyErrors.RemoteCertificateNotAvailable: + ErrorMessage = "The certificate doesn't exist in the trust store."; + break; + default: + ErrorMessage = "An unknown error occurred."; + break; + } + ErrorMessage = String.Format("The certificate failed to verify for {0}:{1}. {2} {3}", HTTPSURL, HTTPSPort, ErrorMessage, cert.ToString()); + return handler(ErrorMessage); + }; + } /// /// Set the interface to look for services on the current computer @@ -72,8 +72,8 @@ namespace TGServiceInterface public static void MakeLocalConnection() { HTTPSURL = null; - HTTPSPassword = null; - } + HTTPSPassword = null; + } /// /// Set the interface to look for services on a remote computer @@ -86,7 +86,7 @@ namespace TGServiceInterface HTTPSPort = port; HTTPSUsername = username; HTTPSPassword = password; - } + } /// /// Returns the requested server component interface. This does not guarantee a successful connection @@ -121,8 +121,8 @@ namespace TGServiceInterface { outChannel.Credentials.UserName.UserName = HTTPSUsername; outChannel.Credentials.UserName.Password = HTTPSPassword; - } - return outChannel.CreateChannel(); + } + return outChannel.CreateChannel(); } /// From 816741ad8cf765201c2f549d3d2f79a2e628b58c Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 18 Sep 2017 00:25:13 -0400 Subject: [PATCH 4/4] Further sanity --- TGCommandLine/Program.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index 9e00cf3df7..2f5967f724 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -113,12 +113,16 @@ namespace TGCommandLine return result; } + static bool AcceptedBadCert = false; static bool BadCertificateInteractive(string message) { + if (AcceptedBadCert) + return true; Console.WriteLine(message); Console.Write("Do you wish to continue? NOT RECCOMENDED! (y/N): "); var result = Console.ReadLine().Trim().ToLower(); - return result == "y" || result == "yes"; + AcceptedBadCert = result == "y" || result == "yes"; + return AcceptedBadCert; } static int Main(string[] args) @@ -169,11 +173,13 @@ namespace TGCommandLine { Console.WriteLine("Unable to connect: " + res); Server.MakeLocalConnection(); + AcceptedBadCert = false; } else if (!Server.Authenticate()) { Console.WriteLine("Authentication error: Username/password/windows identity is not authorized! Returning to local mode..."); Server.MakeLocalConnection(); + AcceptedBadCert = false; } else {