From 6be8f428ca356be0011bbff6e123dd20b152b84b Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 1 Nov 2017 15:23:53 -0400 Subject: [PATCH] Fix bad certificate handling --- TGCommandLine/Program.cs | 19 +++++++++---------- TGControlPanel/Program.cs | 1 + TGServiceInterface/Interface.cs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index d396240b4b..9c5cfd3472 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -102,16 +102,6 @@ namespace TGCommandLine static void ReplaceInterface(Interface I) { - if (!interactive) - I.SetBadCertificateHandler((message) => - { - foreach (var J in Environment.GetCommandLineArgs()) - if (J.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much - return true; - return false; - }); - else - I.SetBadCertificateHandler(BadCertificateInteractive); currentInterface = I; ConsoleCommand.Interface = I; InstanceRootCommand.currentInterface = I; @@ -192,6 +182,7 @@ namespace TGCommandLine { var argsAsList = new List(args); for (var I = 0; I < argsAsList.Count - 1; ++I) + { if (argsAsList[I].ToLower() == "--instance") { if (!CheckInstanceConnectivity(args[I + 1], true)) @@ -199,10 +190,18 @@ namespace TGCommandLine argsAsList.RemoveRange(I, 2); break; } + else if (argsAsList[I].ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much + { + argsAsList.RemoveAt(I); + --I; + Interface.SetBadCertificateHandler(_ => false); + } + } return (int)RunCommandLine(argsAsList); } //interactive mode + Interface.SetBadCertificateHandler(BadCertificateInteractive); Console.WriteLine("Type 'instance' to connect to a server instance"); Console.WriteLine("Type 'remote' to connect to a remote service"); diff --git a/TGControlPanel/Program.cs b/TGControlPanel/Program.cs index 1b96f7ff6d..3ee2151668 100644 --- a/TGControlPanel/Program.cs +++ b/TGControlPanel/Program.cs @@ -19,6 +19,7 @@ namespace TGControlPanel } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + Interface.SetBadCertificateHandler(BadCertificateHandler); var login = new Login(); login.Show(); Application.Run(); diff --git a/TGServiceInterface/Interface.cs b/TGServiceInterface/Interface.cs index 9a84730eff..15a3c4cc93 100644 --- a/TGServiceInterface/Interface.cs +++ b/TGServiceInterface/Interface.cs @@ -174,7 +174,7 @@ namespace TGServiceInterface /// Sets the function called when a remote login fails due to the server having an invalid SSL cert /// /// The to be called when a remote login is attempted while the server posesses a bad certificate. Passed a of error information about the and should return if it the connection should be made anyway - public void SetBadCertificateHandler(Func handler) + public static void SetBadCertificateHandler(Func handler) { ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => { @@ -196,7 +196,7 @@ namespace TGServiceInterface ErrorMessage = "An unknown error occurred."; break; } - ErrorMessage = String.Format("The certificate failed to verify for {0}:{1}. {2} {3}", HTTPSURL, HTTPSPort, ErrorMessage, cert.ToString()); + ErrorMessage = String.Format("The server's certificate failed to verify! Error: {0} Cert: {1}", ErrorMessage, cert.ToString()); return handler(ErrorMessage); }; }