Commit 477a3d24 authored by justcoding121's avatar justcoding121 Committed by justcoding121

#246 Create less certificates

parent e261513c
......@@ -13,7 +13,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
private readonly ProxyServer proxyServer;
//share requestBody outside handlers
private readonly Dictionary<Guid, string> requestBodyHistory = new Dictionary<Guid, string>();
//Using a dictionary is not a good idea since it can cause memory overflow
//ideally the data should be moved out of memory
//private readonly Dictionary<Guid, string> requestBodyHistory
// = new Dictionary<Guid, string>();
public ProxyTestController()
{
......@@ -124,7 +127,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
string bodyString = await e.GetRequestBodyAsString();
await e.SetRequestBodyString(bodyString);
requestBodyHistory[e.Id] = bodyString;
//requestBodyHistory[e.Id] = bodyString;
}
////To cancel a request with a custom HTML content
......@@ -152,11 +155,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
Console.WriteLine("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
if (requestBodyHistory.ContainsKey(e.Id))
{
//access request body by looking up the shared dictionary using requestId
var requestBody = requestBodyHistory[e.Id];
}
//if (requestBodyHistory.ContainsKey(e.Id))
//{
// //access request body by looking up the shared dictionary using requestId
// var requestBody = requestBodyHistory[e.Id];
//}
//read response headers
var responseHeaders = e.WebSession.Response.ResponseHeaders;
......
......@@ -4,7 +4,7 @@ using Titanium.Web.Proxy.Shared;
namespace Titanium.Web.Proxy.Helpers
{
internal static class HeaderHelper
internal static class HttpHelper
{
private static readonly Encoding defaultEncoding = Encoding.GetEncoding("ISO-8859-1");
......@@ -50,5 +50,40 @@ namespace Titanium.Web.Proxy.Helpers
//return default if not specified
return defaultEncoding;
}
/// <summary>
/// Tries to get root domain from a given hostname
/// Adapted from below answer
/// https://stackoverflow.com/questions/16473838/get-domain-name-of-a-url-in-c-sharp-net
/// </summary>
/// <param name="hostname"></param>
/// <returns></returns>
internal static string GetWildCardDomainName(string hostname)
{
/*all needed domain in lower case*/
/*for now just hard code most common ones */
string[] col = { ".com", ".net", ".org", ".cn",
".co.uk", ".co.in", ".co.us" };
foreach (string name in col)
{
if (hostname.EndsWith(name))
{
int idx = hostname.LastIndexOf(name);
int sec = hostname.Substring(0, idx - 1).LastIndexOf('.');
if(hostname.Substring(0, sec + 1).Contains("."))
{
var rootDomain = hostname.Substring(sec + 1);
return "*." + rootDomain;
}
break;
}
}
//return as it is
return hostname;
}
}
}
......@@ -113,8 +113,10 @@ namespace Titanium.Web.Proxy
{
sslStream = new SslStream(clientStream);
var certName = HttpHelper.GetWildCardDomainName(httpRemoteUri.Host);
var certificate = endPoint.GenericCertificate ??
CertificateManager.CreateCertificate(httpRemoteUri.Host, false);
CertificateManager.CreateCertificate(certName, false);
//Successfully managed to authenticate the client using the fake certificate
await sslStream.AuthenticateAsServerAsync(certificate, false,
......
......@@ -74,7 +74,7 @@
<Compile Include="EventArguments\CertificateValidationEventArgs.cs" />
<Compile Include="Extensions\ByteArrayExtensions.cs" />
<Compile Include="Extensions\FuncExtensions.cs" />
<Compile Include="Helpers\HeaderHelper.cs" />
<Compile Include="Helpers\HttpHelper.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Helpers\BufferPool.cs" />
<Compile Include="Helpers\CustomBufferedStream.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment