Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/Titanium.Web.Proxy.Examples.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ internal static class NativeMethods
// Pinvoke
internal delegate bool ConsoleEventDelegate(int eventType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:" + ((ProxyServer) sender).ServerConnectionCount);
Console.WriteLine("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);

if (requestBodyHistory.ContainsKey(e.Id))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.UnitTests
public class CertificateManagerTests
{
private static readonly string[] hostNames
= { "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();

Expand All @@ -35,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();

}
}
}
1 change: 1 addition & 0 deletions Titanium.Web.Proxy.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">240</s:Int64>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CN/@EntryIndexedValue">CN</s:String>
Expand Down
2 changes: 1 addition & 1 deletion Titanium.Web.Proxy/Http/HeaderParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static async Task ReadHeaders(CustomBinaryReader reader,
{
var existing = headers[newHeader.Name];

var nonUniqueHeaders = new List<HttpHeader> {existing, newHeader};
var nonUniqueHeaders = new List<HttpHeader> { existing, newHeader };

nonUniqueResponseHeaders.Add(newHeader.Name, nonUniqueHeaders);
headers.Remove(newHeader.Name);
Expand Down
34 changes: 17 additions & 17 deletions Titanium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private X509Certificate2 MakeCertificate(bool isRoot, string subject, string ful
}

var x500CertDN = Activator.CreateInstance(typeX500DN);
var typeValue = new object[] {fullSubject, 0};
var typeValue = new object[] { fullSubject, 0 };
typeX500DN.InvokeMember("Encode", BindingFlags.InvokeMethod, null, x500CertDN, typeValue);

var x500RootCertDN = Activator.CreateInstance(typeX500DN);
Expand All @@ -110,16 +110,16 @@ private X509Certificate2 MakeCertificate(bool isRoot, string subject, string ful
if (sharedPrivateKey == null)
{
sharedPrivateKey = Activator.CreateInstance(typeX509PrivateKey);
typeValue = new object[] {sProviderName};
typeValue = new object[] { sProviderName };
typeX509PrivateKey.InvokeMember("ProviderName", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);
typeValue[0] = 2;
typeX509PrivateKey.InvokeMember("ExportPolicy", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);
typeValue = new object[] {isRoot ? 2 : 1};
typeValue = new object[] { isRoot ? 2 : 1 };
typeX509PrivateKey.InvokeMember("KeySpec", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);

if (!isRoot)
{
typeValue = new object[] {176};
typeValue = new object[] { 176 };
typeX509PrivateKey.InvokeMember("KeyUsage", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);
}

Expand Down Expand Up @@ -149,9 +149,9 @@ private X509Certificate2 MakeCertificate(bool isRoot, string subject, string ful

var requestCert = Activator.CreateInstance(typeRequestCert);

typeValue = new[] {1, sharedPrivateKey, string.Empty};
typeValue = new[] { 1, sharedPrivateKey, string.Empty };
typeRequestCert.InvokeMember("InitializeFromPrivateKey", BindingFlags.InvokeMethod, null, requestCert, typeValue);
typeValue = new[] {x500CertDN};
typeValue = new[] { x500CertDN };
typeRequestCert.InvokeMember("Subject", BindingFlags.PutDispProperty, null, requestCert, typeValue);
typeValue[0] = x500RootCertDN;
typeRequestCert.InvokeMember("Issuer", BindingFlags.PutDispProperty, null, requestCert, typeValue);
Expand Down Expand Up @@ -186,14 +186,14 @@ private X509Certificate2 MakeCertificate(bool isRoot, string subject, string ful
var extNames = Activator.CreateInstance(typeExtNames);
var altDnsNames = Activator.CreateInstance(typeCAlternativeName);

typeValue = new object[] {3, subject};
typeValue = new object[] { 3, subject };
typeCAlternativeName.InvokeMember("InitializeFromString", BindingFlags.InvokeMethod, null, altDnsNames, typeValue);

typeValue = new[] {altDnsNames};
typeValue = new[] { altDnsNames };
typeAltNamesCollection.InvokeMember("Add", BindingFlags.InvokeMethod, null, altNameCollection, typeValue);


typeValue = new[] {altNameCollection};
typeValue = new[] { altNameCollection };
typeExtNames.InvokeMember("InitializeEncode", BindingFlags.InvokeMethod, null, extNames, typeValue);

typeValue[0] = extNames;
Expand All @@ -204,27 +204,27 @@ private X509Certificate2 MakeCertificate(bool isRoot, string subject, string ful
{
var signerCertificate = Activator.CreateInstance(typeSignerCertificate);

typeValue = new object[] {0, 0, 12, signingCertificate.Thumbprint};
typeValue = new object[] { 0, 0, 12, signingCertificate.Thumbprint };
typeSignerCertificate.InvokeMember("Initialize", BindingFlags.InvokeMethod, null, signerCertificate, typeValue);
typeValue = new[] {signerCertificate};
typeValue = new[] { signerCertificate };
typeRequestCert.InvokeMember("SignerCertificate", BindingFlags.PutDispProperty, null, requestCert, typeValue);
}
else
{
var basicConstraints = Activator.CreateInstance(typeBasicConstraints);

typeValue = new object[] {"true", "0"};
typeValue = new object[] { "true", "0" };
typeBasicConstraints.InvokeMember("InitializeEncode", BindingFlags.InvokeMethod, null, basicConstraints, typeValue);
typeValue = new[] {basicConstraints};
typeValue = new[] { basicConstraints };
typeX509Extensions.InvokeMember("Add", BindingFlags.InvokeMethod, null, certificate, typeValue);
}

oid = Activator.CreateInstance(typeOID);

typeValue = new object[] {1, 0, 0, hashAlg};
typeValue = new object[] { 1, 0, 0, hashAlg };
typeOID.InvokeMember("InitializeFromAlgorithmName", BindingFlags.InvokeMethod, null, oid, typeValue);

typeValue = new[] {oid};
typeValue = new[] { oid };
typeRequestCert.InvokeMember("HashAlgorithm", BindingFlags.PutDispProperty, null, requestCert, typeValue);
typeRequestCert.InvokeMember("Encode", BindingFlags.InvokeMethod, null, requestCert, null);

Expand All @@ -244,10 +244,10 @@ private X509Certificate2 MakeCertificate(bool isRoot, string subject, string ful
typeValue[0] = 0;

var createCertRequest = typeX509Enrollment.InvokeMember("CreateRequest", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
typeValue = new[] {2, createCertRequest, 0, string.Empty};
typeValue = new[] { 2, createCertRequest, 0, string.Empty };

typeX509Enrollment.InvokeMember("InstallResponse", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
typeValue = new object[] {null, 0, 1};
typeValue = new object[] { null, 0, 1 };

try
{
Expand Down
2 changes: 1 addition & 1 deletion Titanium.Web.Proxy/Network/CertificateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ internal virtual X509Certificate2 CreateCertificate(string certificateName, bool
}
if (certificate != null && !certificateCache.ContainsKey(certificateName))
{
certificateCache.Add(certificateName, new CachedCertificate {Certificate = certificate});
certificateCache.Add(certificateName, new CachedCertificate { Certificate = certificate });
}
}
else
Expand Down
4 changes: 3 additions & 1 deletion Titanium.Web.Proxy/Network/Tcp/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public void Dispose()
TcpClient.Close();
}
}
catch { }
catch
{
}
}
}
}
4 changes: 2 additions & 2 deletions Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal async Task<TcpConnection> CreateClient(ProxyServer server,
await client.ConnectAsync(externalHttpsProxy.HostName, externalHttpsProxy.Port);
stream = new CustomBufferedStream(client.GetStream(), server.BufferSize);

using (var writer = new StreamWriter(stream, Encoding.ASCII, server.BufferSize, true) {NewLine = ProxyConstants.NewLine})
using (var writer = new StreamWriter(stream, Encoding.ASCII, server.BufferSize, true) { NewLine = ProxyConstants.NewLine })
{
await writer.WriteLineAsync($"CONNECT {remoteHostName}:{remotePort} HTTP/{httpVersion}");
await writer.WriteLineAsync($"Host: {remoteHostName}:{remotePort}");
Expand All @@ -75,7 +75,7 @@ internal async Task<TcpConnection> CreateClient(ProxyServer server,
{
var result = await reader.ReadLineAsync();

if (!new[] {"200 OK", "connection established"}.Any(s => result.ContainsIgnoreCase(s)))
if (!new[] { "200 OK", "connection established" }.Any(s => result.ContainsIgnoreCase(s)))
{
throw new Exception("Upstream proxy failed to create a secure tunnel");
}
Expand Down
4 changes: 2 additions & 2 deletions Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private async Task SendAuthentication407Response(StreamWriter clientStreamWriter
{
ResponseHeaders = new Dictionary<string, HttpHeader>
{
{"Proxy-Authenticate", new HttpHeader("Proxy-Authenticate", "Basic realm=\"TitaniumProxy\"")},
{"Proxy-Connection", new HttpHeader("Proxy-Connection", "close")}
{ "Proxy-Authenticate", new HttpHeader("Proxy-Authenticate", "Basic realm=\"TitaniumProxy\"") },
{ "Proxy-Connection", new HttpHeader("Proxy-Connection", "close") }
}
};
await WriteResponseHeaders(clientStreamWriter, response);
Expand Down
4 changes: 3 additions & 1 deletion Titanium.Web.Proxy/ProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ private void OnAcceptConnection(IAsyncResult asyn)
tcpClient.Close();
}
}
catch { }
catch
{
}
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ await TcpHelper.SendRaw(this,
{
Dispose(clientStream, clientStreamReader, clientStreamWriter, null);
}

}
}

Expand Down Expand Up @@ -224,7 +223,7 @@ await sslStream.AuthenticateAsServerAsync(certificate, false,

//Now create the request
disposed = await HandleHttpSessionRequest(tcpClient, httpCmd, clientStream, clientStreamReader, clientStreamWriter,
endPoint.EnableSsl ? endPoint.GenericCertificateName : null, endPoint, null);
endPoint.EnableSsl ? endPoint.GenericCertificateName : null, endPoint, null);

if (!disposed)
{
Expand Down
1 change: 0 additions & 1 deletion Titanium.Web.Proxy/ResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ private void Dispose(Stream clientStream,
serverConnection.Dispose();
Interlocked.Decrement(ref ServerConnectionCountField);
}

}
}
}
6 changes: 3 additions & 3 deletions Titanium.Web.Proxy/Shared/ProxyConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Titanium.Web.Proxy.Shared
/// </summary>
internal class ProxyConstants
{
internal static readonly char[] SpaceSplit = {' '};
internal static readonly char[] ColonSplit = {':'};
internal static readonly char[] SemiColonSplit = {';'};
internal static readonly char[] SpaceSplit = { ' ' };
internal static readonly char[] ColonSplit = { ':' };
internal static readonly char[] SemiColonSplit = { ';' };

internal static readonly byte[] NewLineBytes = Encoding.ASCII.GetBytes(NewLine);

Expand Down