diff --git a/Examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs b/Examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs
new file mode 100644
index 000000000..86b06a857
--- /dev/null
+++ b/Examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Titanium.Web.Proxy.Examples.Basic.Helpers
+{
+ ///
+ /// Adapated from
+ /// http://stackoverflow.com/questions/13656846/how-to-programmatic-disable-c-sharp-console-applications-quick-edit-mode
+ ///
+ internal static class ConsoleHelper
+ {
+ const uint ENABLE_QUICK_EDIT = 0x0040;
+
+ // STD_INPUT_HANDLE (DWORD): -10 is the standard input device.
+ const int STD_INPUT_HANDLE = -10;
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ static extern IntPtr GetStdHandle(int nStdHandle);
+
+ [DllImport("kernel32.dll")]
+ static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
+
+ [DllImport("kernel32.dll")]
+ static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
+
+ internal static bool DisableQuickEditMode()
+ {
+
+ IntPtr consoleHandle = GetStdHandle(STD_INPUT_HANDLE);
+
+ // get current console mode
+ uint consoleMode;
+ if (!GetConsoleMode(consoleHandle, out consoleMode))
+ {
+ // ERROR: Unable to get console mode.
+ return false;
+ }
+
+ // Clear the quick edit bit in the mode flags
+ consoleMode &= ~ENABLE_QUICK_EDIT;
+
+ // set the new mode
+ if (!SetConsoleMode(consoleHandle, consoleMode))
+ {
+ // ERROR: Unable to set console mode
+ return false;
+ }
+
+ return true;
+ }
+ }
+}
diff --git a/Examples/Titanium.Web.Proxy.Examples.Basic/Program.cs b/Examples/Titanium.Web.Proxy.Examples.Basic/Program.cs
index 13cc0fe86..bbfb5a25f 100644
--- a/Examples/Titanium.Web.Proxy.Examples.Basic/Program.cs
+++ b/Examples/Titanium.Web.Proxy.Examples.Basic/Program.cs
@@ -1,5 +1,7 @@
using System;
+using System.Diagnostics;
using System.Runtime.InteropServices;
+using Titanium.Web.Proxy.Examples.Basic.Helpers;
namespace Titanium.Web.Proxy.Examples.Basic
{
@@ -9,11 +11,13 @@ public class Program
public static void Main(string[] args)
{
+ //fix console hang due to QuickEdit mode
+ ConsoleHelper.DisableQuickEditMode();
+
//On Console exit make sure we also exit the proxy
NativeMethods.Handler = ConsoleEventCallback;
NativeMethods.SetConsoleCtrlHandler(NativeMethods.Handler, true);
-
//Start proxy controller
controller.StartProxy();
@@ -50,5 +54,7 @@ internal static class NativeMethods
// Pinvoke
internal delegate bool ConsoleEventDelegate(int eventType);
+
}
-}
\ No newline at end of file
+
+}
diff --git a/Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs b/Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
index fe9f16c1c..c88d2c483 100644
--- a/Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+++ b/Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Net;
+using System.Net.Security;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Models;
@@ -47,18 +47,18 @@ public void StartProxy()
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example google.com and dropbox.com
- ExcludedHttpsHostNameRegex = new List() { "dropbox.com" }
+ ExcludedHttpsHostNameRegex = new List { "dropbox.com" }
//Include Https addresses you want to proxy (others will be excluded)
//for example github.com
- // IncludedHttpsHostNameRegex = new List() { "github.com" }
+ //IncludedHttpsHostNameRegex = new List { "github.com" }
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//Use self-issued generic certificate on all https requests
//Optimizes performance by not creating a certificate for each https-enabled domain
//Useful when certificate trust is not required by proxy clients
- // GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
+ //GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
//An explicit endpoint is where the client knows about the existence of a proxy
@@ -107,7 +107,7 @@ public void Stop()
//intecept & cancel redirect or update requests
public async Task OnRequest(object sender, SessionEventArgs e)
{
- Console.WriteLine("Active Client Connections:" + ((ProxyServer) sender).ClientConnectionCount);
+ Console.WriteLine("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
Console.WriteLine(e.WebSession.Request.Url);
//read request headers
@@ -150,7 +150,7 @@ public async Task OnRequest(object sender, SessionEventArgs e)
//Modify response
public async Task OnResponse(object sender, SessionEventArgs e)
{
- Console.WriteLine("Active Server Connections:" + (sender as ProxyServer).ServerConnectionCount);
+ Console.WriteLine("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
if (requestBodyHistory.ContainsKey(e.Id))
{
@@ -189,7 +189,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
public Task OnCertificateValidation(object sender, CertificateValidationEventArgs e)
{
//set IsValid to true/false based on Certificate Errors
- if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
+ if (e.SslPolicyErrors == SslPolicyErrors.None)
{
e.IsValid = true;
}
diff --git a/Examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj b/Examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
index 84c0b9f89..3ebd19cb6 100644
--- a/Examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
+++ b/Examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
@@ -55,6 +55,7 @@
+
diff --git a/Tests/Titanium.Web.Proxy.IntegrationTests/Properties/AssemblyInfo.cs b/Tests/Titanium.Web.Proxy.IntegrationTests/Properties/AssemblyInfo.cs
index e2f3d0432..2b5ed878b 100644
--- a/Tests/Titanium.Web.Proxy.IntegrationTests/Properties/AssemblyInfo.cs
+++ b/Tests/Titanium.Web.Proxy.IntegrationTests/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
diff --git a/Tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs b/Tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
index c9f07f40c..1f851580e 100644
--- a/Tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
+++ b/Tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
@@ -1,11 +1,12 @@
using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Diagnostics;
using System.Net;
+using System.Net.Http;
+using System.Net.Security;
using System.Threading.Tasks;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Models;
-using System.Net.Http;
-using System.Diagnostics;
namespace Titanium.Web.Proxy.IntegrationTests
{
@@ -13,7 +14,6 @@ namespace Titanium.Web.Proxy.IntegrationTests
public class SslTests
{
[TestMethod]
-
public void TestSsl()
{
//expand this to stress test to find
@@ -103,7 +103,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
public Task OnCertificateValidation(object sender, CertificateValidationEventArgs e)
{
//set IsValid to true/false based on Certificate Errors
- if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
+ if (e.SslPolicyErrors == SslPolicyErrors.None)
{
e.IsValid = true;
}
diff --git a/Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs b/Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
index 651142271..e4388e2e5 100644
--- a/Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
+++ b/Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
@@ -1,8 +1,8 @@
using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Titanium.Web.Proxy.Network;
-using System.Threading.Tasks;
-using System.Collections.Generic;
namespace Titanium.Web.Proxy.UnitTests
{
@@ -10,8 +10,7 @@ namespace Titanium.Web.Proxy.UnitTests
public class CertificateManagerTests
{
private static readonly string[] hostNames
- = new string[] { "facebook.com", "youtube.com", "google.com",
- "bing.com", "yahoo.com"};
+ = { "facebook.com", "youtube.com", "google.com", "bing.com", "yahoo.com" };
private readonly Random random = new Random();
@@ -36,16 +35,13 @@ public async Task Simple_Create_Certificate_Stress_Test()
var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
-
}));
-
}
}
await Task.WhenAll(tasks.ToArray());
mgr.StopClearIdleCertificates();
-
}
}
}
diff --git a/Titanium.Web.Proxy.sln.DotSettings b/Titanium.Web.Proxy.sln.DotSettings
index 1fc658854..5d870b7df 100644
--- a/Titanium.Web.Proxy.sln.DotSettings
+++ b/Titanium.Web.Proxy.sln.DotSettings
@@ -1,8 +1,21 @@
True
+ False
+ True
+ 240
BC
+ CN
+ DN
+ EKU
+ KU
+ MTA
+ OID
+ OIDS
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"><ElementKinds><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy>
\ No newline at end of file
+ <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"><ElementKinds><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy>
+ True
+ True
+ True
\ No newline at end of file
diff --git a/Titanium.Web.Proxy/CertificateHandler.cs b/Titanium.Web.Proxy/CertificateHandler.cs
index 134798937..b13ccfd82 100644
--- a/Titanium.Web.Proxy/CertificateHandler.cs
+++ b/Titanium.Web.Proxy/CertificateHandler.cs
@@ -1,8 +1,8 @@
using System;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
-using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
+using Titanium.Web.Proxy.Extensions;
namespace Titanium.Web.Proxy
{
@@ -32,17 +32,8 @@ internal bool ValidateServerCertificate(
SslPolicyErrors = sslPolicyErrors
};
-
- Delegate[] invocationList = ServerCertificateValidationCallback.GetInvocationList();
- Task[] handlerTasks = new Task[invocationList.Length];
-
- for (int i = 0; i < invocationList.Length; i++)
- {
- handlerTasks[i] = ((Func