Commit ae0844b2 authored by justcoding121's avatar justcoding121

resharper code cleanup

parent 6f166dbb
......@@ -3,7 +3,7 @@
namespace Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// A generic asynchronous event handler used by the proxy.
/// A generic asynchronous event handler used by the proxy.
/// </summary>
/// <typeparam name="TEventArgs">Event argument type.</typeparam>
/// <param name="sender">The proxy server instance.</param>
......
......@@ -4,7 +4,7 @@ using System.Threading;
namespace Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// This is used in transparent endpoint before authenticating client.
/// This is used in transparent endpoint before authenticating client.
/// </summary>
public class BeforeSslAuthenticateEventArgs : EventArgs
{
......@@ -16,19 +16,20 @@ namespace Titanium.Web.Proxy.EventArguments
}
/// <summary>
/// The server name indication hostname if available. Otherwise the generic certificate hostname of TransparentEndPoint.
/// The server name indication hostname if available. Otherwise the generic certificate hostname of
/// TransparentEndPoint.
/// </summary>
public string SniHostName { get; internal set; }
/// <summary>
/// Should we decrypt the SSL request?
/// If true we decrypt with fake certificate.
/// If false we relay the connection to the hostname mentioned in SniHostname.
/// Should we decrypt the SSL request?
/// If true we decrypt with fake certificate.
/// If false we relay the connection to the hostname mentioned in SniHostname.
/// </summary>
public bool DecryptSsl { get; set; } = true;
/// <summary>
/// Terminate the request abruptly by closing client/server connections.
/// Terminate the request abruptly by closing client/server connections.
/// </summary>
public void TerminateSession()
{
......
......@@ -3,7 +3,7 @@ using System;
namespace Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// Wraps the data sent/received by a proxy server instance.
/// Wraps the data sent/received by a proxy server instance.
/// </summary>
public class DataEventArgs : EventArgs
{
......@@ -15,17 +15,17 @@ namespace Titanium.Web.Proxy.EventArguments
}
/// <summary>
/// The buffer with data.
/// The buffer with data.
/// </summary>
public byte[] Buffer { get; }
/// <summary>
/// Offset in buffer from which valid data begins.
/// Offset in buffer from which valid data begins.
/// </summary>
public int Offset { get; }
/// <summary>
/// Length from offset in buffer with valid data.
/// Length from offset in buffer with valid data.
/// </summary>
public int Count { get; }
}
......
......@@ -4,7 +4,7 @@ using Titanium.Web.Proxy.Http;
namespace Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// Class that wraps the multipart sent request arguments.
/// Class that wraps the multipart sent request arguments.
/// </summary>
public class MultipartRequestPartSentEventArgs : EventArgs
{
......@@ -15,12 +15,12 @@ namespace Titanium.Web.Proxy.EventArguments
}
/// <summary>
/// Boundary.
/// Boundary.
/// </summary>
public string Boundary { get; }
/// <summary>
/// The header collection.
/// The header collection.
/// </summary>
public HeaderCollection Headers { get; }
}
......
......@@ -554,7 +554,7 @@ namespace Titanium.Web.Proxy.EventArguments
Respond(response);
}
/// <summary>
/// <summary>
/// Respond with given response object to client.
/// </summary>
/// <param name="response">The response object.</param>
......
......@@ -21,10 +21,10 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
protected readonly int BufferSize;
protected readonly ExceptionHandler ExceptionFunc;
internal readonly CancellationTokenSource CancellationTokenSource;
protected readonly ExceptionHandler ExceptionFunc;
/// <summary>
/// Constructor to initialize the proxy
/// </summary>
......@@ -100,17 +100,17 @@ namespace Titanium.Web.Proxy.EventArguments
public ExternalProxy CustomUpStreamProxyUsed { get; internal set; }
/// <summary>
/// Local endpoint via which we make the request.
/// Local endpoint via which we make the request.
/// </summary>
public ProxyEndPoint LocalEndPoint { get; }
/// <summary>
/// Is this a transparent endpoint?
/// Is this a transparent endpoint?
/// </summary>
public bool IsTransparent => LocalEndPoint is TransparentProxyEndPoint;
/// <summary>
/// The last exception that happened.
/// The last exception that happened.
/// </summary>
public Exception Exception { get; internal set; }
......@@ -129,12 +129,12 @@ namespace Titanium.Web.Proxy.EventArguments
}
/// <summary>
/// Fired when data is sent within this session to server/client.
/// Fired when data is sent within this session to server/client.
/// </summary>
public event EventHandler<DataEventArgs> DataSent;
/// <summary>
/// Fired when data is received within this session from client/server.
/// Fired when data is received within this session from client/server.
/// </summary>
public event EventHandler<DataEventArgs> DataReceived;
......
......@@ -6,7 +6,7 @@ using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// A class that wraps the state when a tunnel connect event happen for Explicit endpoints.
/// A class that wraps the state when a tunnel connect event happen for Explicit endpoints.
/// </summary>
public class TunnelConnectSessionEventArgs : SessionEventArgsBase
{
......@@ -20,8 +20,8 @@ namespace Titanium.Web.Proxy.EventArguments
}
/// <summary>
/// Should we decrypt the Ssl or relay it to server?
/// Default is true.
/// Should we decrypt the Ssl or relay it to server?
/// Default is true.
/// </summary>
public bool DecryptSsl { get; set; } = true;
......@@ -31,11 +31,12 @@ namespace Titanium.Web.Proxy.EventArguments
public bool DenyConnect { get; set; }
/// <summary>
/// Is this a connect request to secure HTTP server? Or is it to someother protocol.
/// Is this a connect request to secure HTTP server? Or is it to someother protocol.
/// </summary>
public bool IsHttpsConnect
{
get => isHttpsConnect ?? throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event");
get => isHttpsConnect ??
throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event");
internal set => isHttpsConnect = value;
}
}
......
......@@ -3,7 +3,7 @@ using System;
namespace Titanium.Web.Proxy
{
/// <summary>
/// A delegate to catch exceptions occuring in proxy.
/// A delegate to catch exceptions occuring in proxy.
/// </summary>
/// <param name="exception">The exception occurred in proxy.</param>
public delegate void ExceptionHandler(Exception exception);
......
......@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Exceptions
}
/// <summary>
/// The current session within which this error happened.
/// The current session within which this error happened.
/// </summary>
public SessionEventArgsBase Session { get; }
......
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
......@@ -90,7 +89,8 @@ namespace Titanium.Web.Proxy
}
//send the response
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response, cancellationToken: cancellationToken);
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response,
cancellationToken: cancellationToken);
return;
}
......@@ -99,13 +99,14 @@ namespace Titanium.Web.Proxy
await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc);
//send the response
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response, cancellationToken: cancellationToken);
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response,
cancellationToken: cancellationToken);
return;
}
//write back successfull CONNECT response
var response = ConnectResponse.CreateSuccessfullConnectResponse(version);
// Set ContentLength explicitly to properly handle HTTP 1.0
response.ContentLength = 0;
response.Headers.FixProxyHeaders();
......@@ -212,7 +213,8 @@ namespace Titanium.Web.Proxy
{
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await clientStream.ReadAsync(data, 0, available, cancellationToken);
await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken);
await connection.StreamWriter.WriteAsync(data, 0, available, true,
cancellationToken);
}
finally
{
......@@ -220,7 +222,8 @@ namespace Titanium.Web.Proxy
}
}
var serverHelloInfo = await SslTools.PeekServerHello(connection.Stream, cancellationToken);
var serverHelloInfo =
await SslTools.PeekServerHello(connection.Stream, cancellationToken);
((ConnectResponse)connectArgs.WebSession.Response).ServerHelloInfo = serverHelloInfo;
}
......@@ -242,13 +245,22 @@ namespace Titanium.Web.Proxy
{
// HTTP/2 Connection Preface
string line = await clientStreamReader.ReadLineAsync(cancellationToken);
if (line != string.Empty) throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
if (line != string.Empty)
{
throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
}
line = await clientStreamReader.ReadLineAsync(cancellationToken);
if (line != "SM") throw new Exception($"HTTP/2 Protocol violation. 'SM' expected, '{line}' received");
if (line != "SM")
{
throw new Exception($"HTTP/2 Protocol violation. 'SM' expected, '{line}' received");
}
line = await clientStreamReader.ReadLineAsync(cancellationToken);
if (line != string.Empty) throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
if (line != string.Empty)
{
throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
}
//create new connection
using (var connection = await GetServerConnection(connectArgs, true, cancellationToken))
......@@ -268,7 +280,8 @@ namespace Titanium.Web.Proxy
//Now create the request
await HandleHttpSessionRequest(endPoint, tcpClient, clientStream, clientStreamReader,
clientStreamWriter, cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest);
clientStreamWriter, cancellationTokenSource, connectHostname,
connectArgs?.WebSession.ConnectRequest);
}
catch (ProxyHttpException e)
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using StreamExtended;
......@@ -13,7 +10,8 @@ namespace Titanium.Web.Proxy.Extensions
{
internal static class SslExtensions
{
internal static readonly List<SslApplicationProtocol> Http11ProtocolAsList = new List<SslApplicationProtocol> { SslApplicationProtocol.Http11 };
internal static readonly List<SslApplicationProtocol> Http11ProtocolAsList =
new List<SslApplicationProtocol> { SslApplicationProtocol.Http11 };
internal static string GetServerName(this ClientHelloInfo clientHelloInfo)
{
......@@ -60,14 +58,18 @@ namespace Titanium.Web.Proxy.Extensions
return Http11ProtocolAsList;
}
internal static Task AuthenticateAsClientAsync(this SslStream sslStream, SslClientAuthenticationOptions option, CancellationToken token)
internal static Task AuthenticateAsClientAsync(this SslStream sslStream, SslClientAuthenticationOptions option,
CancellationToken token)
{
return sslStream.AuthenticateAsClientAsync(option.TargetHost, option.ClientCertificates, option.EnabledSslProtocols, option.CertificateRevocationCheckMode != X509RevocationMode.NoCheck);
return sslStream.AuthenticateAsClientAsync(option.TargetHost, option.ClientCertificates,
option.EnabledSslProtocols, option.CertificateRevocationCheckMode != X509RevocationMode.NoCheck);
}
internal static Task AuthenticateAsServerAsync(this SslStream sslStream, SslServerAuthenticationOptions options, CancellationToken token)
internal static Task AuthenticateAsServerAsync(this SslStream sslStream, SslServerAuthenticationOptions options,
CancellationToken token)
{
return sslStream.AuthenticateAsServerAsync(options.ServerCertificate, options.ClientCertificateRequired, options.EnabledSslProtocols, options.CertificateRevocationCheckMode != X509RevocationMode.NoCheck);
return sslStream.AuthenticateAsServerAsync(options.ServerCertificate, options.ClientCertificateRequired,
options.EnabledSslProtocols, options.CertificateRevocationCheckMode != X509RevocationMode.NoCheck);
}
#endif
}
......@@ -75,7 +77,8 @@ namespace Titanium.Web.Proxy.Extensions
#if !NETCOREAPP2_1
internal enum SslApplicationProtocol
{
Http11, Http2
Http11,
Http2
}
internal class SslClientAuthenticationOptions
......
......@@ -141,7 +141,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="clientStream">The client stream.</param>
/// <param name="expectedStart">The expected start.</param>
/// <returns>
/// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise
/// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise
/// </returns>
private static async Task<int> StartsWith(CustomBufferedStream clientStream, string expectedStart)
{
......
......@@ -35,7 +35,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="description">The HTTP status description.</param>
/// <param name="cancellationToken">Optional cancellation token for this async task.</param>
/// <returns>The Task.</returns>
internal Task WriteResponseStatusAsync(Version version, int code, string description, CancellationToken cancellationToken)
internal Task WriteResponseStatusAsync(Version version, int code, string description,
CancellationToken cancellationToken)
{
return WriteLineAsync(Response.CreateResponseLine(version, code, description), cancellationToken);
}
......
......@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Helpers
internal int BufferSize { get; }
/// <summary>
/// Writes a line async
/// Writes a line async
/// </summary>
/// <param name="cancellationToken">Optional cancellation token for this async task.</param>
/// <returns></returns>
......@@ -98,7 +98,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="flush"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
internal async Task WriteHeadersAsync(HeaderCollection headers, bool flush = true, CancellationToken cancellationToken = default)
internal async Task WriteHeadersAsync(HeaderCollection headers, bool flush = true,
CancellationToken cancellationToken = default)
{
foreach (var header in headers)
{
......@@ -121,7 +122,8 @@ namespace Titanium.Web.Proxy.Helpers
}
}
internal async Task WriteAsync(byte[] data, int offset, int count, bool flush, CancellationToken cancellationToken = default)
internal async Task WriteAsync(byte[] data, int offset, int count, bool flush,
CancellationToken cancellationToken = default)
{
await WriteAsync(data, offset, count, cancellationToken);
if (flush)
......@@ -202,7 +204,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onCopy"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task CopyBodyChunkedAsync(CustomBinaryReader reader, Action<byte[], int, int> onCopy, CancellationToken cancellationToken)
private async Task CopyBodyChunkedAsync(CustomBinaryReader reader, Action<byte[], int, int> onCopy,
CancellationToken cancellationToken)
{
while (true)
{
......@@ -242,7 +245,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onCopy"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task CopyBytesFromStream(CustomBinaryReader reader, long count, Action<byte[], int, int> onCopy, CancellationToken cancellationToken)
private async Task CopyBytesFromStream(CustomBinaryReader reader, long count, Action<byte[], int, int> onCopy,
CancellationToken cancellationToken)
{
var buffer = reader.Buffer;
long remainingBytes = count;
......@@ -276,7 +280,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="flush"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected async Task WriteAsync(RequestResponseBase requestResponse, bool flush = true, CancellationToken cancellationToken = default)
protected async Task WriteAsync(RequestResponseBase requestResponse, bool flush = true,
CancellationToken cancellationToken = default)
{
var body = requestResponse.CompressBodyAndUpdateContentLength();
await WriteHeadersAsync(requestResponse.Headers, flush, cancellationToken);
......
......@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Helpers
}
/// <summary>
/// <see href="https://msdn.microsoft.com/en-us/library/aa366896.aspx"/>
/// <see href="https://msdn.microsoft.com/en-us/library/aa366896.aspx" />
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct Tcp6Row
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.Helpers
namespace Titanium.Web.Proxy.Helpers
{
internal class Ref<T>
{
......@@ -21,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers
public override string ToString()
{
T value = Value;
var value = Value;
return value == null ? string.Empty : value.ToString();
}
......
using System;
using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Helpers
{
......@@ -19,7 +18,8 @@ namespace Titanium.Web.Proxy.Helpers
/// cache for Windows platform check
/// </summary>
/// <returns></returns>
private static readonly Lazy<bool> isRunningOnWindows = new Lazy<bool>(() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
private static readonly Lazy<bool> isRunningOnWindows =
new Lazy<bool>(() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif
......
......@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.Helpers
if (ipVersion == IpVersion.Ipv4)
{
NativeMethods.TcpRow* rowPtr = (NativeMethods.TcpRow*)(tcpTable + 4);
var rowPtr = (NativeMethods.TcpRow*)(tcpTable + 4);
for (int i = 0; i < rowCount; ++i)
{
......@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Helpers
}
else
{
NativeMethods.Tcp6Row* rowPtr = (NativeMethods.Tcp6Row*)(tcpTable + 4);
var rowPtr = (NativeMethods.Tcp6Row*)(tcpTable + 4);
for (int i = 0; i < rowCount; ++i)
{
......@@ -82,9 +82,9 @@ namespace Titanium.Web.Proxy.Helpers
}
/// <summary>
/// Converts 32-bit integer from native byte order (little-endian)
/// to network byte order for port,
/// switches 0th and 1st bytes, and 2nd and 3rd bytes
/// Converts 32-bit integer from native byte order (little-endian)
/// to network byte order for port,
/// switches 0th and 1st bytes, and 2nd and 3rd bytes
/// </summary>
/// <param name="port"></param>
/// <returns></returns>
......@@ -276,9 +276,11 @@ namespace Titanium.Web.Proxy.Helpers
//Now async relay all server=>client & client=>server data
var sendRelay =
CopyHttp2FrameAsync(clientStream, serverStream, onDataSend, bufferSize, connectionId, cancellationTokenSource.Token);
CopyHttp2FrameAsync(clientStream, serverStream, onDataSend, bufferSize, connectionId,
cancellationTokenSource.Token);
var receiveRelay =
CopyHttp2FrameAsync(serverStream, clientStream, onDataReceive, bufferSize, connectionId, cancellationTokenSource.Token);
CopyHttp2FrameAsync(serverStream, clientStream, onDataReceive, bufferSize, connectionId,
cancellationTokenSource.Token);
await Task.WhenAny(sendRelay, receiveRelay);
cancellationTokenSource.Cancel();
......@@ -302,7 +304,8 @@ namespace Titanium.Web.Proxy.Helpers
int length = (headerBuffer[0] << 16) + (headerBuffer[1] << 8) + headerBuffer[2];
byte type = headerBuffer[3];
byte flags = headerBuffer[4];
int streamId = ((headerBuffer[5] & 0x7f) << 24) + (headerBuffer[6] << 16) + (headerBuffer[7] << 8) + headerBuffer[8];
int streamId = ((headerBuffer[5] & 0x7f) << 24) + (headerBuffer[6] << 16) + (headerBuffer[7] << 8) +
headerBuffer[8];
read = await ForceRead(input, buffer, 0, length, cancellationToken);
if (read != length)
......@@ -321,7 +324,8 @@ namespace Titanium.Web.Proxy.Helpers
}
}
private static async Task<int> ForceRead(Stream input, byte[] buffer, int offset, int bytesToRead, CancellationToken cancellationToken)
private static async Task<int> ForceRead(Stream input, byte[] buffer, int offset, int bytesToRead,
CancellationToken cancellationToken)
{
int totalRead = 0;
while (bytesToRead > 0)
......
......@@ -8,7 +8,8 @@ namespace Titanium.Web.Proxy.Http
{
internal static class HeaderParser
{
internal static async Task ReadHeaders(CustomBinaryReader reader, HeaderCollection headerCollection, CancellationToken cancellationToken)
internal static async Task ReadHeaders(CustomBinaryReader reader, HeaderCollection headerCollection,
CancellationToken cancellationToken)
{
string tmpLine;
while (!string.IsNullOrEmpty(tmpLine = await reader.ReadLineAsync(cancellationToken)))
......
......@@ -80,7 +80,8 @@ namespace Titanium.Web.Proxy.Http
/// Prepare and send the http(s) request
/// </summary>
/// <returns></returns>
internal async Task SendRequest(bool enable100ContinueBehaviour, bool isTransparent, CancellationToken cancellationToken)
internal async Task SendRequest(bool enable100ContinueBehaviour, bool isTransparent,
CancellationToken cancellationToken)
{
var upstreamProxy = ServerConnection.UpStreamProxy;
......
......@@ -89,7 +89,7 @@ namespace Titanium.Web.Proxy.Http
}
/// <summary>
/// Does this request contain multipart/form-data?
/// Does this request contain multipart/form-data?
/// </summary>
public bool IsMultipartFormData => ContentType?.StartsWith("multipart/form-data") == true;
......
......@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
}
/// <summary>
/// The header text.
/// The header text.
/// </summary>
public abstract string HeaderText { get; }
......
......@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Models
public class ExplicitProxyEndPoint : ProxyEndPoint
{
/// <summary>
/// Constructor.
/// Constructor.
/// </summary>
/// <param name="ipAddress">Listening IP address.</param>
/// <param name="port">Listening port.</param>
......
......@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Models
public int Port { get; set; }
/// <summary>
/// returns data in Hostname:port format.
/// returns data in Hostname:port format.
/// </summary>
/// <returns></returns>
public override string ToString()
......
......@@ -22,11 +22,11 @@ namespace Titanium.Web.Proxy.Models
internal static readonly HttpHeader ProxyConnectionKeepAlive = new HttpHeader("Proxy-Connection", "keep-alive");
/// <summary>
/// Initialize a new instance.
/// </summary>
/// <param name="name">Header name.</param>
/// <param name="value">Header value.</param>
/// <summary>
/// Initialize a new instance.
/// </summary>
/// <param name="name">Header name.</param>
/// <param name="value">Header value.</param>
public HttpHeader(string name, string value)
{
if (string.IsNullOrEmpty(name))
......
......@@ -12,7 +12,7 @@ namespace Titanium.Web.Proxy.Models
public class TransparentProxyEndPoint : ProxyEndPoint
{
/// <summary>
/// Initialize a new instance.
/// Initialize a new instance.
/// </summary>
/// <param name="ipAddress">Listening Ip address.</param>
/// <param name="port">Listening port.</param>
......
......@@ -60,13 +60,18 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
///
/// </summary>
/// <param name="rootCertificateName"></param>
/// <param name="rootCertificateIssuerName"></param>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param>
/// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param>
/// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
/// <param name="exceptionFunc"></param>
internal CertificateManager(string rootCertificateName, string rootCertificateIssuerName,
bool userTrustRootCertificate, bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin,
......@@ -639,7 +644,10 @@ namespace Titanium.Web.Proxy.Network
/// named as "rootCert.pfx" (and will be saved in proxy dll directory).
/// </param>
/// <param name="password">Set a password for the .pfx file.</param>
/// <param name="overwritePfXFile">true : replace an existing .pfx file if password is incorect or if RootCertificate==null.</param>
/// <param name="overwritePfXFile">
/// true : replace an existing .pfx file if password is incorect or if
/// RootCertificate==null.
/// </param>
/// <param name="storageFlag"></param>
/// <returns>
/// true if succeeded, else false.
......@@ -765,9 +773,15 @@ namespace Titanium.Web.Proxy.Network
/// Also makes root certificate trusted based on provided parameters.
/// Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true.
/// </summary>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param>
/// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param>
/// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
public void EnsureRootCertificate(bool userTrustRootCertificate,
bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin = false)
{
......@@ -907,7 +921,7 @@ namespace Titanium.Web.Proxy.Network
}
/// <summary>
/// Clear the root certificate and cache.
/// Clear the root certificate and cache.
/// </summary>
public void ClearRootCertificate()
{
......
......@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using StreamExtended.Network;
......@@ -33,9 +32,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="externalProxy"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
internal async Task<TcpConnection> CreateClient(string remoteHostName, int remotePort,
List<SslApplicationProtocol> applicationProtocols, Version httpVersion, bool decryptSsl, bool isConnect,
ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy, CancellationToken cancellationToken)
internal async Task<TcpConnection> CreateClient(string remoteHostName, int remotePort,
List<SslApplicationProtocol> applicationProtocols, Version httpVersion, bool decryptSsl, bool isConnect,
ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy,
CancellationToken cancellationToken)
{
bool useUpstreamProxy = false;
......@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
var connectRequest = new ConnectRequest
{
OriginalUrl = $"{remoteHostName}:{remotePort}",
HttpVersion = httpVersion,
HttpVersion = httpVersion
};
connectRequest.Headers.AddHeader(KnownHeaders.Connection, KnownHeaders.ConnectionKeepAlive);
......@@ -87,7 +87,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
if (!string.IsNullOrEmpty(externalProxy.UserName) && externalProxy.Password != null)
{
connectRequest.Headers.AddHeader(HttpHeader.ProxyConnectionKeepAlive);
connectRequest.Headers.AddHeader(HttpHeader.GetProxyAuthorizationHeader(externalProxy.UserName, externalProxy.Password));
connectRequest.Headers.AddHeader(
HttpHeader.GetProxyAuthorizationHeader(externalProxy.UserName, externalProxy.Password));
}
await writer.WriteRequestAsync(connectRequest, cancellationToken: cancellationToken);
......
......@@ -20,14 +20,15 @@ namespace Titanium.Web.Proxy
{
/// <summary>
/// This object is the backbone of proxy. One can create as many instances as needed.
/// However care should be taken to avoid using the same listening ports across multiple instances.
/// However care should be taken to avoid using the same listening ports across multiple instances.
/// </summary>
public partial class ProxyServer : IDisposable
{
/// <summary>
/// HTTP & HTTPS scheme shorthands.
/// HTTP & HTTPS scheme shorthands.
/// </summary>
internal static readonly string UriSchemeHttp = Uri.UriSchemeHttp;
internal static readonly string UriSchemeHttps = Uri.UriSchemeHttps;
/// <summary>
......@@ -56,11 +57,17 @@ namespace Titanium.Web.Proxy
private WinHttpWebProxyFinder systemProxyResolver;
/// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters.
/// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param>
/// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param>
/// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false) : this(null, null, userTrustRootCertificate,
machineTrustRootCertificate, trustRootCertificateAsAdmin)
......@@ -68,13 +75,19 @@ namespace Titanium.Web.Proxy
}
/// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters.
/// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary>
/// <param name="rootCertificateName">Name of the root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of the root certificate issuer.</param>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param>
/// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param>
/// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false)
......@@ -590,7 +603,7 @@ namespace Titanium.Web.Proxy
}
/// <summary>
/// Gets the system up stream proxy.
/// Gets the system up stream proxy.
/// </summary>
private Task<ExternalProxy> GetSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs)
{
......@@ -599,7 +612,7 @@ namespace Titanium.Web.Proxy
}
/// <summary>
/// Act when a connection is received from client.
/// Act when a connection is received from client.
/// </summary>
private void OnAcceptConnection(IAsyncResult asyn)
{
......
......@@ -290,7 +290,8 @@ namespace Titanium.Web.Proxy
if (request.ExpectContinue)
{
args.WebSession.SetConnection(connection);
await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent, cancellationToken);
await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent,
cancellationToken);
}
//If 100 continue was the response inform that to the client
......@@ -316,7 +317,8 @@ namespace Titanium.Web.Proxy
if (!request.ExpectContinue)
{
args.WebSession.SetConnection(connection);
await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent, cancellationToken);
await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent,
cancellationToken);
}
//check if content-length is > 0
......@@ -359,7 +361,8 @@ namespace Titanium.Web.Proxy
/// <param name="isConnect"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task<TcpConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect, CancellationToken cancellationToken)
private async Task<TcpConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect,
CancellationToken cancellationToken)
{
ExternalProxy customUpStreamProxy = null;
......
......@@ -118,7 +118,8 @@ namespace Titanium.Web.Proxy
//Write body if exists
if (response.HasBody)
{
await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None, cancellationToken);
await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None,
cancellationToken);
}
}
}
......
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