Merge pull request #297 from Cyberboss/InvalidCertCPOverride

Fixes missing bad certificate override in Control Panel
This commit is contained in:
Jordan Brown
2017-11-01 18:12:29 -04:00
committed by GitHub
3 changed files with 34 additions and 35 deletions
+11 -13
View File
@@ -9,7 +9,6 @@ namespace TGCommandLine
class Program
{
static bool interactive = false;
static Interface currentInterface;
static Command.ExitCode RunCommandLine(IList<string> argsAsList)
{
@@ -97,17 +96,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;
}
@@ -161,10 +149,20 @@ namespace TGCommandLine
ReplaceInterface(new Interface());
Command.OutputProcVar.Value = Console.WriteLine;
if (args.Length != 0)
{
Interface.SetBadCertificateHandler((message) =>
{
foreach (var J in args)
if (J.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much
return true;
return false;
});
return (int)RunCommandLine(new List<string>(args));
}
Console.WriteLine("Type 'remote' to connect to a remote service");
//interactive mode
Interface.SetBadCertificateHandler(BadCertificateInteractive);
Console.WriteLine("Type 'remote' to connect to a remote service");
while (true)
{
Console.Write("Enter command: ");
+1
View File
@@ -19,6 +19,7 @@ namespace TGControlPanel
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Interface.SetBadCertificateHandler(BadCertificateHandler);
using(var L = new Login())
Application.Run(L);
}
+22 -22
View File
@@ -77,31 +77,11 @@ namespace TGServiceInterface
return query.ToList();
}
/// <summary>
/// Construct an <see cref="Interface"/> for a local connection
/// </summary>
public Interface() { }
/// <summary>
/// Construct an <see cref="Interface"/> for a remote connection
/// </summary>
/// <param name="address">The address of the remote server</param>
/// <param name="port">The port the remote server runs on</param>
/// <param name="username">Windows account username for the remote server</param>
/// <param name="password">Windows account password for the remote server</param>
public Interface(string address, ushort port, string username, string password)
{
HTTPSURL = address;
HTTPSPort = port;
HTTPSUsername = username;
HTTPSPassword = password;
}
/// <summary>
/// Sets the function called when a remote login fails due to the server having an invalid SSL cert
/// </summary>
/// <param name="handler">The <see cref="Func{T, TResult}"/> to be called when a remote login is attempted while the server posesses a bad certificate. Passed a <see cref="string"/> of error information about the and should return <see langword="true"/> if it the connection should be made anyway</param>
public void SetBadCertificateHandler(Func<string, bool> handler)
public static void SetBadCertificateHandler(Func<string, bool> handler)
{
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
{
@@ -123,11 +103,31 @@ 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 certificate failed to verify! Error: {2} Cert: {3}", ErrorMessage, cert.ToString());
return handler(ErrorMessage);
};
}
/// <summary>
/// Construct an <see cref="Interface"/> for a local connection
/// </summary>
public Interface() { }
/// <summary>
/// Construct an <see cref="Interface"/> for a remote connection
/// </summary>
/// <param name="address">The address of the remote server</param>
/// <param name="port">The port the remote server runs on</param>
/// <param name="username">Windows account username for the remote server</param>
/// <param name="password">Windows account password for the remote server</param>
public Interface(string address, ushort port, string username, string password)
{
HTTPSURL = address;
HTTPSPort = port;
HTTPSUsername = username;
HTTPSPassword = password;
}
/// <summary>
/// Closes all <see cref="ChannelFactory"/>s stored in <see cref="ChannelFactoryCache"/> and clears it
/// </summary>