Commit a8497ab2 authored by Honfika's avatar Honfika

space between // and text in comments (except when it is a commented code)

parent bbd6f9b5
......@@ -9,10 +9,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
public static void Main(string[] args)
{
//fix console hang due to QuickEdit mode
// fix console hang due to QuickEdit mode
ConsoleHelper.DisableQuickEditMode();
//Start proxy controller
// Start proxy controller
controller.StartProxy();
Console.WriteLine("Hit any key to exit..");
......
......@@ -17,8 +17,8 @@ namespace Titanium.Web.Proxy.IntegrationTests
//disable this test until CI is prepared to handle
public void TestSsl()
{
//expand this to stress test to find
//why in long run proxy becomes unresponsive as per issue #184
// expand this to stress test to find
// why in long run proxy becomes unresponsive as per issue #184
string testUrl = "https://google.com";
int proxyPort = 8086;
var proxy = new ProxyTestController();
......@@ -62,8 +62,8 @@ namespace Titanium.Web.Proxy.IntegrationTests
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, proxyPort, true);
//An explicit endpoint is where the client knows about the existance of a proxy
//So client sends request in a proxy friendly manner
// An explicit endpoint is where the client knows about the existance of a proxy
// So client sends request in a proxy friendly manner
proxyServer.AddEndPoint(explicitEndPoint);
proxyServer.Start();
......@@ -84,14 +84,14 @@ namespace Titanium.Web.Proxy.IntegrationTests
proxyServer.Stop();
}
//intecept & cancel, redirect or update requests
// intecept & cancel, redirect or update requests
public async Task OnRequest(object sender, SessionEventArgs e)
{
Debug.WriteLine(e.WebSession.Request.Url);
await Task.FromResult(0);
}
//Modify response
// Modify response
public async Task OnResponse(object sender, SessionEventArgs e)
{
await Task.FromResult(0);
......@@ -104,7 +104,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
/// <param name="e"></param>
public Task OnCertificateValidation(object sender, CertificateValidationEventArgs e)
{
//set IsValid to true/false based on Certificate Errors
// set IsValid to true/false based on Certificate Errors
if (e.SslPolicyErrors == SslPolicyErrors.None)
{
e.IsValid = true;
......@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
/// <param name="e"></param>
public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs e)
{
//set e.clientCertificate to override
// set e.clientCertificate to override
return Task.FromResult(0);
}
......
......@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy.UnitTests
{
tasks.AddRange(hostNames.Select(host => Task.Run(() =>
{
//get the connection
// get the connection
var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
})));
......@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.UnitTests
mgr.StopClearIdleCertificates();
}
//uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
// uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
[TestMethod]
public async Task Simple_Create_Win_Certificate_Test()
{
......@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.UnitTests
{
tasks.AddRange(hostNames.Select(host => Task.Run(() =>
{
//get the connection
// get the connection
var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
})));
......
......@@ -19,7 +19,7 @@ namespace Titanium.Web.Proxy
internal bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
//if user callback is registered then do it
// if user callback is registered then do it
if (ServerCertificateValidationCallback != null)
{
var args = new CertificateValidationEventArgs
......@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy
SslPolicyErrors = sslPolicyErrors
};
//why is the sender null?
// why is the sender null?
ServerCertificateValidationCallback.InvokeAsync(this, args, exceptionFunc).Wait();
return args.IsValid;
}
......@@ -39,8 +39,8 @@ namespace Titanium.Web.Proxy
return true;
}
//By default
//do not allow this client to communicate with unauthenticated servers.
// By default
// do not allow this client to communicate with unauthenticated servers.
return false;
}
......@@ -77,7 +77,7 @@ namespace Titanium.Web.Proxy
clientCertificate = localCertificates[0];
}
//If user call back is registered
// If user call back is registered
if (ClientCertificateSelectionCallback != null)
{
var args = new CertificateSelectionEventArgs
......@@ -89,7 +89,7 @@ namespace Titanium.Web.Proxy
ClientCertificate = clientCertificate
};
//why is the sender null?
// why is the sender null?
ClientCertificateSelectionCallback.InvokeAsync(this, args, exceptionFunc).Wait();
return args.ClientCertificate;
}
......
......@@ -43,10 +43,10 @@ namespace Titanium.Web.Proxy
string connectHostname = null;
TunnelConnectSessionEventArgs connectArgs = null;
//Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if (await HttpHelper.IsConnectMethod(clientStream) == 1)
{
//read the first line HTTP command
// read the first line HTTP command
string httpCmd = await clientStream.ReadLineAsync(cancellationToken);
if (string.IsNullOrEmpty(httpCmd))
{
......@@ -74,7 +74,7 @@ namespace Titanium.Web.Proxy
await endPoint.InvokeBeforeTunnelConnectRequest(this, connectArgs, ExceptionFunc);
//filter out excluded host names
// filter out excluded host names
bool decryptSsl = endPoint.DecryptSsl && connectArgs.DecryptSsl;
if (connectArgs.DenyConnect)
......@@ -89,7 +89,7 @@ namespace Titanium.Web.Proxy
};
}
//send the response
// send the response
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response,
cancellationToken: cancellationToken);
return;
......@@ -99,13 +99,13 @@ namespace Titanium.Web.Proxy
{
await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc);
//send the response
// send the response
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response,
cancellationToken: cancellationToken);
return;
}
//write back successfull CONNECT response
// write back successfull CONNECT response
var response = ConnectResponse.CreateSuccessfullConnectResponse(version);
// Set ContentLength explicitly to properly handle HTTP 1.0
......@@ -153,7 +153,7 @@ namespace Titanium.Web.Proxy
var certificate = endPoint.GenericCertificate ??
await CertificateManager.CreateCertificateAsync(certName);
//Successfully managed to authenticate the client using the fake certificate
// Successfully managed to authenticate the client using the fake certificate
var options = new SslServerAuthenticationOptions();
if (http2Supproted)
{
......@@ -170,7 +170,7 @@ namespace Titanium.Web.Proxy
options.CertificateRevocationCheckMode = X509RevocationMode.NoCheck;
await sslStream.AuthenticateAsServerAsync(options, cancellationToken);
//HTTPS server created - we can now decrypt the client's traffic
// HTTPS server created - we can now decrypt the client's traffic
clientStream = new CustomBufferedStream(sslStream, BufferSize);
clientStreamWriter = new HttpResponseWriter(clientStream, BufferSize);
......@@ -193,10 +193,10 @@ namespace Titanium.Web.Proxy
throw new Exception("Session was terminated by user.");
}
//Hostname is excluded or it is not an HTTPS connect
// Hostname is excluded or it is not an HTTPS connect
if (!decryptSsl || !isClientHello)
{
//create new connection
// create new connection
using (var connection = await GetServerConnection(connectArgs, true, cancellationToken))
{
if (isClientHello)
......@@ -204,7 +204,7 @@ namespace Titanium.Web.Proxy
int available = clientStream.Available;
if (available > 0)
{
//send the buffered data
// send the buffered data
var data = BufferPool.GetBuffer(BufferSize);
try
......@@ -260,7 +260,7 @@ namespace Titanium.Web.Proxy
throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
}
//create new connection
// create new connection
using (var connection = await GetServerConnection(connectArgs, true, cancellationToken))
{
await connection.StreamWriter.WriteLineAsync("PRI * HTTP/2.0", cancellationToken);
......@@ -276,7 +276,7 @@ namespace Titanium.Web.Proxy
}
}
//Now create the request
// Now create the request
await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest);
}
......
......@@ -21,13 +21,13 @@ namespace Titanium.Web.Proxy.Helpers
{
try
{
//return default if not specified
// return default if not specified
if (contentType == null)
{
return defaultEncoding;
}
//extract the encoding by finding the charset
// extract the encoding by finding the charset
var parameters = contentType.Split(ProxyConstants.SemiColonSplit);
foreach (string parameter in parameters)
{
......@@ -51,11 +51,11 @@ namespace Titanium.Web.Proxy.Helpers
}
catch
{
//parsing errors
// parsing errors
// ignored
}
//return default if not specified
// return default if not specified
return defaultEncoding;
}
......@@ -63,7 +63,7 @@ namespace Titanium.Web.Proxy.Helpers
{
if (contentType != null)
{
//extract the boundary
// extract the boundary
var parameters = contentType.Split(ProxyConstants.SemiColonSplit);
foreach (string parameter in parameters)
{
......@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy.Helpers
}
}
//return null if not specified
// return null if not specified
return null;
}
......@@ -94,14 +94,14 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
internal static string GetWildCardDomainName(string hostname)
{
//only for subdomains we need wild card
//example www.google.com or gstatic.google.com
//but NOT for google.com
// only for subdomains we need wild card
// example www.google.com or gstatic.google.com
// but NOT for google.com
if (hostname.Split(ProxyConstants.DotSplit).Length > 2)
{
int idx = hostname.IndexOf(ProxyConstants.DotSplit);
//issue #352
// issue #352
if (hostname.Substring(0, idx).Contains("-"))
{
return hostname;
......@@ -111,7 +111,7 @@ namespace Titanium.Web.Proxy.Helpers
return "*." + rootDomain;
}
//return as it is
// return as it is
return hostname;
}
......
......@@ -165,19 +165,19 @@ namespace Titanium.Web.Proxy.Helpers
internal Task CopyBodyAsync(ICustomStreamReader streamReader, bool isChunked, long contentLength,
Action<byte[], int, int> onCopy, CancellationToken cancellationToken)
{
//For chunked request we need to read data as they arrive, until we reach a chunk end symbol
// For chunked request we need to read data as they arrive, until we reach a chunk end symbol
if (isChunked)
{
return CopyBodyChunkedAsync(streamReader, onCopy, cancellationToken);
}
//http 1.0 or the stream reader limits the stream
// http 1.0 or the stream reader limits the stream
if (contentLength == -1)
{
contentLength = long.MaxValue;
}
//If not chunked then its easy just read the amount of bytes mentioned in content length header
// If not chunked then its easy just read the amount of bytes mentioned in content length header
return CopyBytesFromStream(streamReader, contentLength, onCopy, cancellationToken);
}
......@@ -230,7 +230,7 @@ namespace Titanium.Web.Proxy.Helpers
await WriteLineAsync(cancellationToken);
//chunk trail
// chunk trail
await reader.ReadLineAsync(cancellationToken);
if (chunkSize == 0)
......
......@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
return false;
};
//On Console exit make sure we also exit the proxy
// On Console exit make sure we also exit the proxy
NativeMethods.SetConsoleCtrlHandler(NativeMethods.Handler, true);
}
}
......
......@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy.Helpers
var taskCompletionSource = new TaskCompletionSource<bool>();
cancellationTokenSource.Token.Register(() => taskCompletionSource.TrySetResult(true));
//Now async relay all server=>client & client=>server data
// Now async relay all server=>client & client=>server data
var clientBuffer = BufferPool.GetBuffer(bufferSize);
var serverBuffer = BufferPool.GetBuffer(bufferSize);
try
......@@ -217,7 +217,7 @@ namespace Titanium.Web.Proxy.Helpers
CancellationTokenSource cancellationTokenSource,
ExceptionHandler exceptionFunc)
{
//Now async relay all server=>client & client=>server data
// Now async relay all server=>client & client=>server data
var sendRelay =
clientStream.CopyToAsync(serverStream, onDataSend, bufferSize, cancellationTokenSource.Token);
var receiveRelay =
......@@ -273,7 +273,7 @@ namespace Titanium.Web.Proxy.Helpers
CancellationTokenSource cancellationTokenSource, Guid connectionId,
ExceptionHandler exceptionFunc)
{
//Now async relay all server=>client & client=>server data
// Now async relay all server=>client & client=>server data
var sendRelay =
CopyHttp2FrameAsync(clientStream, serverStream, onDataSend, bufferSize, connectionId,
cancellationTokenSource.Token);
......
......@@ -296,7 +296,7 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
internal void FixProxyHeaders()
{
//If proxy-connection close was returned inform to close the connection
// If proxy-connection close was returned inform to close the connection
string proxyHeader = GetHeaderValueOrNull(KnownHeaders.ProxyConnection);
RemoveHeader(KnownHeaders.ProxyConnection);
......
......@@ -89,13 +89,13 @@ namespace Titanium.Web.Proxy.Http
var writer = ServerConnection.StreamWriter;
//prepare the request & headers
// prepare the request & headers
await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method,
useUpstreamProxy || isTransparent ? Request.OriginalUrl : Request.RequestUri.PathAndQuery,
Request.HttpVersion), cancellationToken);
//Send Authentication to Upstream proxy if needed
// Send Authentication to Upstream proxy if needed
if (!isTransparent && upstreamProxy != null
&& ServerConnection.IsHttps == false
&& !string.IsNullOrEmpty(upstreamProxy.UserName)
......@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Http
.WriteToStreamAsync(writer, cancellationToken);
}
//write request headers
// write request headers
foreach (var header in Request.Headers)
{
if (isTransparent || header.Name != KnownHeaders.ProxyAuthorization)
......@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy.Http
Response.ParseResponseLine(httpStatus, out _, out int responseStatusCode,
out string responseStatusDescription);
//find if server is willing for expect continue
// find if server is willing for expect continue
if (responseStatusCode == (int)HttpStatusCode.Continue
&& responseStatusDescription.EqualsIgnoreCase("continue"))
{
......@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Http
/// <returns></returns>
internal async Task ReceiveResponse(CancellationToken cancellationToken)
{
//return if this is already read
// return if this is already read
if (Response.StatusCode != 0)
{
return;
......@@ -172,16 +172,16 @@ namespace Titanium.Web.Proxy.Http
Response.StatusCode = statusCode;
Response.StatusDescription = statusDescription;
//For HTTP 1.1 comptibility server may send expect-continue even if not asked for it in request
// For HTTP 1.1 comptibility server may send expect-continue even if not asked for it in request
if (Response.StatusCode == (int)HttpStatusCode.Continue
&& Response.StatusDescription.EqualsIgnoreCase("continue"))
{
//Read the next line after 100-continue
// Read the next line after 100-continue
Response.Is100Continue = true;
Response.StatusCode = 0;
await ServerConnection.Stream.ReadLineAsync(cancellationToken);
//now receive response
// now receive response
await ReceiveResponse(cancellationToken);
return;
}
......@@ -189,17 +189,17 @@ namespace Titanium.Web.Proxy.Http
if (Response.StatusCode == (int)HttpStatusCode.ExpectationFailed
&& Response.StatusDescription.EqualsIgnoreCase("expectation failed"))
{
//read next line after expectation failed response
// read next line after expectation failed response
Response.ExpectationFailed = true;
Response.StatusCode = 0;
await ServerConnection.Stream.ReadLineAsync(cancellationToken);
//now receive response
// now receive response
await ReceiveResponse(cancellationToken);
return;
}
//Read the response headers in to unique and non-unique header collections
// Read the response headers in to unique and non-unique header collections
await HeaderParser.ReadHeaders(ServerConnection.Stream, Response.Headers, cancellationToken);
}
......
......@@ -43,19 +43,19 @@ namespace Titanium.Web.Proxy.Http
{
long contentLength = ContentLength;
//If content length is set to 0 the request has no body
// If content length is set to 0 the request has no body
if (contentLength == 0)
{
return false;
}
//Has body only if request is chunked or content length >0
// Has body only if request is chunked or content length >0
if (IsChunked || contentLength > 0)
{
return true;
}
//has body if POST and when version is http/1.0
// has body if POST and when version is http/1.0
if (Method == "POST" && HttpVersion == HttpHeader.Version10)
{
return true;
......@@ -157,7 +157,7 @@ namespace Titanium.Web.Proxy.Http
return;
}
//GET request don't have a request body to read
// GET request don't have a request body to read
if (!HasBody)
{
throw new BodyNotFoundException("Request don't have a body. " +
......@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Http
internal static void ParseRequestLine(string httpCmd, out string httpMethod, out string httpUrl,
out Version version)
{
//break up the line into three components (method, remote URL & Http Version)
// break up the line into three components (method, remote URL & Http Version)
var httpCmdSplit = httpCmd.Split(ProxyConstants.SpaceSplit, 3);
if (httpCmdSplit.Length < 2)
......@@ -197,7 +197,7 @@ namespace Titanium.Web.Proxy.Http
throw new Exception("Invalid HTTP request line: " + httpCmd);
}
//Find the request Verb
// Find the request Verb
httpMethod = httpCmdSplit[0];
if (!IsAllUpper(httpMethod))
{
......@@ -206,7 +206,7 @@ namespace Titanium.Web.Proxy.Http
httpUrl = httpCmdSplit[1];
//parse the HTTP version
// parse the HTTP version
version = HttpHeader.Version11;
if (httpCmdSplit.Length == 3)
{
......
......@@ -140,7 +140,7 @@ namespace Titanium.Web.Proxy.Http
BodyInternal = value;
bodyString = null;
//If there is a content length header update it
// If there is a content length header update it
UpdateContentLength();
}
}
......
......@@ -47,21 +47,21 @@ namespace Titanium.Web.Proxy.Http
{
long contentLength = ContentLength;
//If content length is set to 0 the response has no body
// If content length is set to 0 the response has no body
if (contentLength == 0)
{
return false;
}
//Has body only if response is chunked or content length >0
//If none are true then check if connection:close header exist, if so write response until server or client terminates the connection
// Has body only if response is chunked or content length >0
// If none are true then check if connection:close header exist, if so write response until server or client terminates the connection
if (IsChunked || contentLength > 0 || !KeepAlive)
{
return true;
}
//has response if connection:keep-alive header exist and when version is http/1.0
//Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
// has response if connection:keep-alive header exist and when version is http/1.0
// Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
if (KeepAlive && HttpVersion == HttpHeader.Version10)
{
return true;
......
......@@ -19,8 +19,8 @@ namespace Titanium.Web.Proxy.Http.Responses
#if NET45
StatusDescription = HttpWorkerRequest.GetStatusDescription(StatusCode);
#else
//todo: this is not really correct, status description should contain spaces, too
//see: https://tools.ietf.org/html/rfc7231#section-6.1
// todo: this is not really correct, status description should contain spaces, too
// see: https://tools.ietf.org/html/rfc7231#section-6.1
StatusDescription = status.ToString();
#endif
}
......
......@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
if (hostName != null)
{
//add subject alternative names
// add subject alternative names
var subjectAlternativeNames = new Asn1Encodable[] { new GeneralName(GeneralName.DnsName, hostName) };
var subjectAlternativeNamesExtension = new DerSequence(subjectAlternativeNames);
......
......@@ -64,7 +64,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
typeSignerCertificate = Type.GetTypeFromProgID("X509Enrollment.CSignerCertificate");
typeX509Enrollment = Type.GetTypeFromProgID("X509Enrollment.CX509Enrollment");
//for alternative names
// for alternative names
typeAltNamesCollection = Type.GetTypeFromProgID("X509Enrollment.CAlternativeNames");
typeExtNames = Type.GetTypeFromProgID("X509Enrollment.CX509ExtensionAlternativeNames");
typeCAlternativeName = Type.GetTypeFromProgID("X509Enrollment.CAlternativeName");
......@@ -192,7 +192,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
if (!isRoot)
{
//add alternative names
// add alternative names
// https://forums.iis.net/t/1180823.aspx
var altNameCollection = Activator.CreateInstance(typeAltNamesCollection);
......@@ -284,15 +284,19 @@ namespace Titanium.Web.Proxy.Network.Certificate
cancellationToken).Result;
}
//Subject
// Subject
string fullSubject = $"CN={sSubjectCN}";
//Sig Algo
// Sig Algo
const string hashAlgo = "SHA256";
//Grace Days
// Grace Days
const int graceDays = -366;
//ValiDays
// ValiDays
const int validDays = 1825;
//KeyLength
// KeyLength
const int keyLength = 2048;
var graceTime = DateTime.Now.AddDays(graceDays);
......
......@@ -141,7 +141,7 @@ namespace Titanium.Web.Proxy.Network
get => engine;
set
{
//For Mono (or Non-Windows) only Bouncy Castle is supported
// For Mono (or Non-Windows) only Bouncy Castle is supported
if (!RunTime.IsWindows || RunTime.IsRunningOnMono)
{
value = CertificateEngine.BouncyCastle;
......@@ -333,8 +333,8 @@ namespace Titanium.Web.Proxy.Network
var x509Store = new X509Store(storeName, storeLocation);
//TODO
//also it should do not duplicate if certificate already exists
// todo
// also it should do not duplicate if certificate already exists
try
{
x509Store.Open(OpenFlags.ReadWrite);
......@@ -428,7 +428,7 @@ namespace Titanium.Web.Proxy.Network
{
certificate = MakeCertificate(certificateName, false);
//store as cache
// store as cache
Task.Run(() =>
{
try
......@@ -447,7 +447,7 @@ namespace Titanium.Web.Proxy.Network
{
certificate = new X509Certificate2(certificatePath, string.Empty, StorageFlag);
}
//if load failed create again
// if load failed create again
catch
{
certificate = MakeCertificate(certificateName, false);
......@@ -474,21 +474,21 @@ namespace Titanium.Web.Proxy.Network
/// <returns></returns>
internal async Task<X509Certificate2> CreateCertificateAsync(string certificateName)
{
//check in cache first
// check in cache first
if (certificateCache.TryGetValue(certificateName, out var cached))
{
cached.LastAccess = DateTime.Now;
return cached.Certificate;
}
//handle burst requests with same certificate name
//by checking for existing task for same certificate name
// handle burst requests with same certificate name
// by checking for existing task for same certificate name
if (pendingCertificateCreationTasks.TryGetValue(certificateName, out var task))
{
return await task;
}
//run certificate creation task & add it to pending tasks
// run certificate creation task & add it to pending tasks
task = Task.Run(() =>
{
var result = CreateCertificate(certificateName, false);
......@@ -504,7 +504,7 @@ namespace Titanium.Web.Proxy.Network
});
pendingCertificateCreationTasks.TryAdd(certificateName, task);
//cleanup pending tasks & return result
// cleanup pending tasks & return result
var certificate = await task;
pendingCertificateCreationTasks.TryRemove(certificateName, out task);
......@@ -528,7 +528,7 @@ namespace Titanium.Web.Proxy.Network
certificateCache.TryRemove(cache.Key, out _);
}
//after a minute come back to check for outdated certificates in cache
// after a minute come back to check for outdated certificates in cache
await Task.Delay(1000 * 60);
}
}
......@@ -659,20 +659,20 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
public void TrustRootCertificate(bool machineTrusted = false)
{
//currentUser\personal
// currentUser\personal
InstallCertificate(StoreName.My, StoreLocation.CurrentUser);
if (!machineTrusted)
{
//currentUser\Root
// currentUser\Root
InstallCertificate(StoreName.Root, StoreLocation.CurrentUser);
}
else
{
//current system
// current system
InstallCertificate(StoreName.My, StoreLocation.LocalMachine);
//this adds to both currentUser\Root & currentMachine\Root
// this adds to both currentUser\Root & currentMachine\Root
InstallCertificate(StoreName.Root, StoreLocation.LocalMachine);
}
}
......@@ -689,13 +689,13 @@ namespace Titanium.Web.Proxy.Network
return false;
}
//currentUser\Personal
// currentUser\Personal
InstallCertificate(StoreName.My, StoreLocation.CurrentUser);
string pfxFileName = Path.GetTempFileName();
File.WriteAllBytes(pfxFileName, RootCertificate.Export(X509ContentType.Pkcs12, PfxPassword));
//currentUser\Root, currentMachine\Personal & currentMachine\Root
// currentUser\Root, currentMachine\Personal & currentMachine\Root
var info = new ProcessStartInfo
{
FileName = "certutil.exe",
......@@ -804,20 +804,20 @@ namespace Titanium.Web.Proxy.Network
/// <param name="machineTrusted">Should also remove from machine store?</param>
public void RemoveTrustedRootCertificate(bool machineTrusted = false)
{
//currentUser\personal
// currentUser\personal
UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, RootCertificate);
if (!machineTrusted)
{
//currentUser\Root
// currentUser\Root
UninstallCertificate(StoreName.Root, StoreLocation.CurrentUser, RootCertificate);
}
else
{
//current system
// current system
UninstallCertificate(StoreName.My, StoreLocation.LocalMachine, RootCertificate);
//this adds to both currentUser\Root & currentMachine\Root
// this adds to both currentUser\Root & currentMachine\Root
UninstallCertificate(StoreName.Root, StoreLocation.LocalMachine, RootCertificate);
}
}
......@@ -833,7 +833,7 @@ namespace Titanium.Web.Proxy.Network
return false;
}
//currentUser\Personal
// currentUser\Personal
UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, RootCertificate);
var infos = new List<ProcessStartInfo>();
......@@ -855,7 +855,7 @@ namespace Titanium.Web.Proxy.Network
infos.AddRange(
new List<ProcessStartInfo>
{
//currentMachine\Personal
// currentMachine\Personal
new ProcessStartInfo
{
FileName = "certutil.exe",
......@@ -866,7 +866,7 @@ namespace Titanium.Web.Proxy.Network
ErrorDialog = false,
WindowStyle = ProcessWindowStyle.Hidden
},
//currentUser\Personal & currentMachine\Personal
// currentUser\Personal & currentMachine\Personal
new ProcessStartInfo
{
FileName = "certutil.exe",
......
......@@ -39,13 +39,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
bool useUpstreamProxy = false;
//check if external proxy is set for HTTP/HTTPS
// check if external proxy is set for HTTP/HTTPS
if (externalProxy != null &&
!(externalProxy.HostName == remoteHostName && externalProxy.Port == remotePort))
{
useUpstreamProxy = true;
//check if we need to ByPass
// check if we need to ByPass
if (externalProxy.BypassLocalhost && NetworkHelper.IsLocalIpAddress(remoteHostName))
{
useUpstreamProxy = false;
......@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
tcpClient = new TcpClient(upStreamEndPoint);
//If this proxy uses another external proxy then create a tunnel request for HTTP/HTTPS connections
// If this proxy uses another external proxy then create a tunnel request for HTTP/HTTPS connections
if (useUpstreamProxy)
{
await tcpClient.ConnectAsync(externalProxy.HostName, externalProxy.Port);
......
......@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
internal int ulVersion;
internal int cBuffers;
internal IntPtr pBuffers; //Point to SecBuffer
internal IntPtr pBuffers; // Point to SecBuffer
internal SecurityBufferDesciption(int bufferSize)
{
......@@ -206,12 +206,12 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
for (int index = 0; index < cBuffers; index++)
{
//The bits were written out the following order:
//int cbBuffer;
//int BufferType;
//pvBuffer;
// The bits were written out the following order:
// int cbBuffer;
// int BufferType;
// pvBuffer;
//What we need to do here is to grab a hold of the pvBuffer allocate by the individual
//SecBuffer and release it...
// SecBuffer and release it...
int currentOffset = index * Marshal.SizeOf(typeof(Buffer));
var secBufferpvBuffer = Marshal.ReadIntPtr(pBuffers,
currentOffset + Marshal.SizeOf(typeof(int)) + Marshal.SizeOf(typeof(int)));
......@@ -249,11 +249,11 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
for (int index = 0; index < cBuffers; index++)
{
//The bits were written out the following order:
//int cbBuffer;
//int BufferType;
//pvBuffer;
//What we need to do here calculate the total number of bytes we need to copy...
// The bits were written out the following order:
// int cbBuffer;
// int BufferType;
// pvBuffer;
// What we need to do here calculate the total number of bytes we need to copy...
int currentOffset = index * Marshal.SizeOf(typeof(Buffer));
bytesToAllocate += Marshal.ReadInt32(pBuffers, currentOffset);
}
......@@ -262,12 +262,12 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
for (int index = 0, bufferIndex = 0; index < cBuffers; index++)
{
//The bits were written out the following order:
//int cbBuffer;
//int BufferType;
//pvBuffer;
//Now iterate over the individual buffers and put them together into a
//byte array...
// The bits were written out the following order:
// int cbBuffer;
// int BufferType;
// pvBuffer;
// Now iterate over the individual buffers and put them together into a
// byte array...
int currentOffset = index * Marshal.SizeOf(typeof(Buffer));
int bytesToCopy = Marshal.ReadInt32(pBuffers, currentOffset);
var secBufferpvBuffer = Marshal.ReadIntPtr(pBuffers,
......
......@@ -69,25 +69,25 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
if (message == null)
{
throw new ArgumentNullException("message");
throw new ArgumentNullException(nameof(message));
}
if (message.Length < 12)
{
string msg = "Minimum Type3 message length is 12 bytes.";
throw new ArgumentOutOfRangeException("message", message.Length, msg);
throw new ArgumentOutOfRangeException(nameof(message), message.Length, msg);
}
if (!CheckHeader(message))
{
string msg = "Invalid Type3 message header.";
throw new ArgumentException(msg, "message");
throw new ArgumentException(msg, nameof(message));
}
if (LittleEndian.ToUInt16(message, 56) != message.Length)
{
string msg = "Invalid Type3 message length.";
throw new ArgumentException(msg, "message");
throw new ArgumentException(msg, nameof(message));
}
if (message.Length >= 64)
......
......@@ -31,7 +31,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
byte[] token;
//null for initial call
// null for initial call
var serverToken = new SecurityBufferDesciption();
var clientToken = new SecurityBufferDesciption(MaximumTokenSize);
......@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
byte[] token;
//user server challenge
// user server challenge
var serverToken = new SecurityBufferDesciption(serverChallenge);
var clientToken = new SecurityBufferDesciption(MaximumTokenSize);
......@@ -156,7 +156,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
authStates.Remove(cache.Key);
}
//after a minute come back to check for outdated certificates in cache
// after a minute come back to check for outdated certificates in cache
await Task.Delay(1000 * 60);
}
......@@ -206,44 +206,44 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
#region Native calls to secur32.dll
[DllImport("secur32.dll", SetLastError = true)]
private static extern int InitializeSecurityContext(ref SecurityHandle phCredential, //PCredHandle
IntPtr phContext, //PCtxtHandle
private static extern int InitializeSecurityContext(ref SecurityHandle phCredential, // PCredHandle
IntPtr phContext, // PCtxtHandle
string pszTargetName,
int fContextReq,
int reserved1,
int targetDataRep,
ref SecurityBufferDesciption pInput, //PSecBufferDesc SecBufferDesc
ref SecurityBufferDesciption pInput, // PSecBufferDesc SecBufferDesc
int reserved2,
out SecurityHandle phNewContext, //PCtxtHandle
out SecurityBufferDesciption pOutput, //PSecBufferDesc SecBufferDesc
out uint pfContextAttr, //managed ulong == 64 bits!!!
out SecurityInteger ptsExpiry); //PTimeStamp
out SecurityHandle phNewContext, // PCtxtHandle
out SecurityBufferDesciption pOutput, // PSecBufferDesc SecBufferDesc
out uint pfContextAttr, // managed ulong == 64 bits!!!
out SecurityInteger ptsExpiry); // PTimeStamp
[DllImport("secur32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int InitializeSecurityContext(ref SecurityHandle phCredential, //PCredHandle
ref SecurityHandle phContext, //PCtxtHandle
private static extern int InitializeSecurityContext(ref SecurityHandle phCredential, // PCredHandle
ref SecurityHandle phContext, // PCtxtHandle
string pszTargetName,
int fContextReq,
int reserved1,
int targetDataRep,
ref SecurityBufferDesciption secBufferDesc, //PSecBufferDesc SecBufferDesc
ref SecurityBufferDesciption secBufferDesc, // PSecBufferDesc SecBufferDesc
int reserved2,
out SecurityHandle phNewContext, //PCtxtHandle
out SecurityBufferDesciption pOutput, //PSecBufferDesc SecBufferDesc
out uint pfContextAttr, //managed ulong == 64 bits!!!
out SecurityInteger ptsExpiry); //PTimeStamp
out SecurityHandle phNewContext, // PCtxtHandle
out SecurityBufferDesciption pOutput, // PSecBufferDesc SecBufferDesc
out uint pfContextAttr, // managed ulong == 64 bits!!!
out SecurityInteger ptsExpiry); // PTimeStamp
[DllImport("secur32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern int AcquireCredentialsHandle(
string pszPrincipal, //SEC_CHAR*
string pszPackage, //SEC_CHAR* //"Kerberos","NTLM","Negotiative"
string pszPrincipal, // SEC_CHAR*
string pszPackage, // SEC_CHAR* // "Kerberos","NTLM","Negotiative"
int fCredentialUse,
IntPtr pAuthenticationId, //_LUID AuthenticationID,//pvLogonID, //PLUID
IntPtr pAuthData, //PVOID
int pGetKeyFn, //SEC_GET_KEY_FN
IntPtr pvGetKeyArgument, //PVOID
ref SecurityHandle phCredential, //SecHandle //PCtxtHandle ref
ref SecurityInteger ptsExpiry); //PTimeStamp //TimeStamp ref
IntPtr pAuthenticationId, // _LUID AuthenticationID,//pvLogonID, // PLUID
IntPtr pAuthData, // PVOID
int pGetKeyFn, // SEC_GET_KEY_FN
IntPtr pvGetKeyArgument, // PVOID
ref SecurityHandle phCredential, // SecHandle // PCtxtHandle ref
ref SecurityInteger ptsExpiry); // PTimeStamp // TimeStamp ref
#endregion
}
......
......@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy
/// <returns>True if authorized.</returns>
private async Task<bool> CheckAuthorization(SessionEventArgsBase session)
{
//If we are not authorizing clients return true
// If we are not authorizing clients return true
if (AuthenticateUserFunc == null)
{
return true;
......@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy
if (headerValueParts.Length != 2 ||
!headerValueParts[0].EqualsIgnoreCase(KnownHeaders.ProxyAuthorizationBasic))
{
//Return not authorized
// Return not authorized
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
return false;
}
......@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy
int colonIndex = decoded.IndexOf(':');
if (colonIndex == -1)
{
//Return not authorized
// Return not authorized
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
return false;
}
......@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy
ExceptionFunc(new ProxyAuthorizationException("Error whilst authorizing request", session, e,
httpHeaders));
//Return not authorized
// Return not authorized
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
return false;
}
......
......@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy
bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false)
{
//default values
// default values
ConnectionTimeOutSeconds = 60;
ProxyEndPoints = new List<ProxyEndPoint>();
......@@ -357,7 +357,7 @@ namespace Titanium.Web.Proxy
{
CertificateManager.EnsureRootCertificate();
//If certificate was trusted by the machine
// If certificate was trusted by the machine
if (!CertificateManager.CertValidated)
{
protocolType = protocolType & ~ProxyProtocolType.Https;
......@@ -365,7 +365,7 @@ namespace Titanium.Web.Proxy
}
}
//clear any settings previously added
// clear any settings previously added
if (isHttp)
{
ProxyEndPoints.OfType<ExplicitProxyEndPoint>().ToList().ForEach(x => x.IsSystemHttpProxy = false);
......@@ -472,8 +472,8 @@ namespace Titanium.Web.Proxy
CertificateManager.EnsureRootCertificate();
}
//clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
//due to non gracious proxy shutdown before or something else
// clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
// due to non gracious proxy shutdown before or something else
if (systemProxySettingsManager != null && RunTime.IsWindows)
{
var proxyInfo = systemProxySettingsManager.GetProxyInfoFromRegistry();
......@@ -622,7 +622,7 @@ namespace Titanium.Web.Proxy
try
{
//based on end point type call appropriate request handlers
// based on end point type call appropriate request handlers
tcpClient = endPoint.Listener.EndAcceptTcpClient(asyn);
}
catch (ObjectDisposedException)
......@@ -634,7 +634,7 @@ namespace Titanium.Web.Proxy
}
catch
{
//Other errors are discarded to keep proxy running
// Other errors are discarded to keep proxy running
}
if (tcpClient != null)
......
......@@ -51,8 +51,8 @@ namespace Titanium.Web.Proxy
try
{
//Loop through each subsequest request on this particular client connection
//(assuming HTTP connection is kept alive by client)
// Loop through each subsequest request on this particular client connection
// (assuming HTTP connection is kept alive by client)
while (true)
{
// read the request line
......@@ -76,7 +76,7 @@ namespace Titanium.Web.Proxy
Request.ParseRequestLine(httpCmd, out string httpMethod, out string httpUrl,
out var version);
//Read the request headers in to unique and non-unique header collections
// Read the request headers in to unique and non-unique header collections
await HeaderParser.ReadHeaders(clientStream, args.WebSession.Request.Headers,
cancellationToken);
......@@ -124,12 +124,12 @@ namespace Titanium.Web.Proxy
if (!args.IsTransparent)
{
//proxy authorization check
// proxy authorization check
if (httpsConnectHostname == null && await CheckAuthorization(args) == false)
{
await InvokeBeforeResponse(args);
//send the response
// send the response
await clientStreamWriter.WriteResponseAsync(args.WebSession.Response,
cancellationToken: cancellationToken);
return;
......@@ -139,9 +139,9 @@ namespace Titanium.Web.Proxy
request.Host = request.RequestUri.Authority;
}
//if win auth is enabled
//we need a cache of request body
//so that we can send it after authentication in WinAuthHandler.cs
// if win auth is enabled
// we need a cache of request body
// so that we can send it after authentication in WinAuthHandler.cs
if (isWindowsAuthenticationEnabledAndSupported && request.HasBody)
{
await args.GetRequestBody(cancellationToken);
......@@ -149,14 +149,14 @@ namespace Titanium.Web.Proxy
request.OriginalHasBody = request.HasBody;
//If user requested interception do it
// If user requested interception do it
await InvokeBeforeRequest(args);
var response = args.WebSession.Response;
if (request.CancelRequest)
{
//syphon out the request body from client before setting the new body
// syphon out the request body from client before setting the new body
await args.SyphonOutBodyAsync(true, cancellationToken);
await HandleHttpSessionResponse(args);
......@@ -169,7 +169,7 @@ namespace Titanium.Web.Proxy
continue;
}
//create a new connection if hostname/upstream end point changes
// create a new connection if hostname/upstream end point changes
if (serverConnection != null
&& (!serverConnection.HostName.Equals(request.RequestUri.Host,
StringComparison.OrdinalIgnoreCase)
......@@ -185,10 +185,10 @@ namespace Titanium.Web.Proxy
serverConnection = await GetServerConnection(args, false, cancellationToken);
}
//if upgrading to websocket then relay the requet without reading the contents
// if upgrading to websocket then relay the requet without reading the contents
if (request.UpgradeToWebSocket)
{
//prepare the prefix content
// prepare the prefix content
await serverConnection.StreamWriter.WriteLineAsync(httpCmd, cancellationToken);
await serverConnection.StreamWriter.WriteHeadersAsync(request.Headers,
cancellationToken: cancellationToken);
......@@ -210,7 +210,7 @@ namespace Titanium.Web.Proxy
cancellationToken: cancellationToken);
}
//If user requested call back then do it
// If user requested call back then do it
if (!args.WebSession.Response.Locked)
{
await InvokeBeforeResponse(args);
......@@ -224,7 +224,7 @@ namespace Titanium.Web.Proxy
return;
}
//construct the web request that we are going to issue on behalf of the client.
// construct the web request that we are going to issue on behalf of the client.
await HandleHttpSessionRequestInternal(serverConnection, args);
if (args.WebSession.ServerConnection == null)
......@@ -232,7 +232,7 @@ namespace Titanium.Web.Proxy
return;
}
//if connection is closing exit
// if connection is closing exit
if (!response.KeepAlive)
{
return;
......@@ -282,8 +282,8 @@ namespace Titanium.Web.Proxy
var body = request.CompressBodyAndUpdateContentLength();
//if expect continue is enabled then send the headers first
//and see if server would return 100 conitinue
// if expect continue is enabled then send the headers first
// and see if server would return 100 conitinue
if (request.ExpectContinue)
{
args.WebSession.SetConnection(serverConnection);
......@@ -291,7 +291,7 @@ namespace Titanium.Web.Proxy
cancellationToken);
}
//If 100 continue was the response inform that to the client
// If 100 continue was the response inform that to the client
if (Enable100ContinueBehaviour)
{
var clientStreamWriter = args.ProxyClient.ClientStreamWriter;
......@@ -310,7 +310,7 @@ namespace Titanium.Web.Proxy
}
}
//If expect continue is not enabled then set the connectio and send request headers
// If expect continue is not enabled then set the connectio and send request headers
if (!request.ExpectContinue)
{
args.WebSession.SetConnection(serverConnection);
......@@ -318,7 +318,7 @@ namespace Titanium.Web.Proxy
cancellationToken);
}
//check if content-length is > 0
// check if content-length is > 0
if (request.ContentLength > 0)
{
if (request.IsBodyRead)
......@@ -339,7 +339,7 @@ namespace Titanium.Web.Proxy
}
}
//If not expectation failed response was returned by server then parse response
// If not expectation failed response was returned by server then parse response
if (!request.ExpectationFailed)
{
await HandleHttpSessionResponse(args);
......
......@@ -23,13 +23,13 @@ namespace Titanium.Web.Proxy
try
{
var cancellationToken = args.CancellationTokenSource.Token;
//read response & headers from server
// read response & headers from server
await args.WebSession.ReceiveResponse(cancellationToken);
var response = args.WebSession.Response;
args.ReRequest = false;
//check for windows authentication
// check for windows authentication
if (isWindowsAuthenticationEnabledAndSupported)
{
if (response.StatusCode == (int)HttpStatusCode.Unauthorized)
......@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy
response.OriginalHasBody = response.HasBody;
//if user requested call back then do it
// if user requested call back then do it
if (!response.Locked)
{
await InvokeBeforeResponse(args);
......@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy
if (!response.TerminateResponse)
{
//syphon out the response body from server before setting the new body
// syphon out the response body from server before setting the new body
await args.SyphonOutBodyAsync(false, cancellationToken);
}
else
......@@ -73,11 +73,11 @@ namespace Titanium.Web.Proxy
return;
}
//if user requested to send request again
//likely after making modifications from User Response Handler
// if user requested to send request again
// likely after making modifications from User Response Handler
if (args.ReRequest)
{
//clear current response
// clear current response
await args.ClearResponse(cancellationToken);
await HandleHttpSessionRequestInternal(args.WebSession.ServerConnection, args);
return;
......@@ -85,7 +85,7 @@ namespace Titanium.Web.Proxy
response.Locked = true;
//Write back to client 100-conitinue response if that's what server returned
// Write back to client 100-conitinue response if that's what server returned
if (response.Is100Continue)
{
await clientStreamWriter.WriteResponseStatusAsync(response.HttpVersion,
......@@ -110,12 +110,12 @@ namespace Titanium.Web.Proxy
}
else
{
//Write back response status to client
// Write back response status to client
await clientStreamWriter.WriteResponseStatusAsync(response.HttpVersion, response.StatusCode,
response.StatusDescription, cancellationToken);
await clientStreamWriter.WriteHeadersAsync(response.Headers, cancellationToken: cancellationToken);
//Write body if exists
// Write body if exists
if (response.HasBody)
{
await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None,
......
......@@ -69,10 +69,10 @@ namespace Titanium.Web.Proxy
string certName = HttpHelper.GetWildCardDomainName(httpsHostName);
var certificate = await CertificateManager.CreateCertificateAsync(certName);
//Successfully managed to authenticate the client using the fake certificate
// Successfully managed to authenticate the client using the fake certificate
await sslStream.AuthenticateAsServerAsync(certificate, false, SslProtocols.Tls, false);
//HTTPS server created - we can now decrypt the client's traffic
// HTTPS server created - we can now decrypt the client's traffic
clientStream = new CustomBufferedStream(sslStream, BufferSize);
clientStreamWriter = new HttpResponseWriter(clientStream, BufferSize);
......@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
}
else
{
//create new connection
// create new connection
var connection = new TcpClient(UpStreamEndPoint);
await connection.ConnectAsync(httpsHostName, endPoint.Port);
connection.ReceiveTimeout = ConnectionTimeOutSeconds * 1000;
......@@ -123,8 +123,8 @@ namespace Titanium.Web.Proxy
}
}
//HTTPS server created - we can now decrypt the client's traffic
//Now create the request
// HTTPS server created - we can now decrypt the client's traffic
// Now create the request
await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
cancellationTokenSource, isHttps ? httpsHostName : null, null);
}
......
......@@ -19,7 +19,8 @@ namespace Titanium.Web.Proxy
private static readonly HashSet<string> authHeaderNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"WWW-Authenticate",
//IIS 6.0 messed up names below
// IIS 6.0 messed up names below
"WWWAuthenticate",
"NTLMAuthorization",
"NegotiateAuthorization",
......@@ -51,7 +52,7 @@ namespace Titanium.Web.Proxy
var response = args.WebSession.Response;
//check in non-unique headers first
// check in non-unique headers first
var header = response.Headers.NonUniqueHeaders.FirstOrDefault(x => authHeaderNames.Contains(x.Key));
if (!header.Equals(new KeyValuePair<string, List<HttpHeader>>()))
......@@ -66,12 +67,12 @@ namespace Titanium.Web.Proxy
x => authSchemes.Any(y => x.Value.StartsWith(y, StringComparison.OrdinalIgnoreCase)));
}
//check in unique headers
// check in unique headers
if (authHeader == null)
{
headerName = null;
//check in non-unique headers first
// check in non-unique headers first
var uHeader = response.Headers.Headers.FirstOrDefault(x => authHeaderNames.Contains(x.Key));
if (!uHeader.Equals(new KeyValuePair<string, HttpHeader>()))
......@@ -104,26 +105,26 @@ namespace Titanium.Web.Proxy
var request = args.WebSession.Request;
//clear any existing headers to avoid confusing bad servers
// clear any existing headers to avoid confusing bad servers
request.Headers.RemoveHeader(KnownHeaders.Authorization);
//initial value will match exactly any of the schemes
// initial value will match exactly any of the schemes
if (scheme != null)
{
string clientToken = WinAuthHandler.GetInitialAuthToken(request.Host, scheme, args.Id);
string auth = string.Concat(scheme, clientToken);
//replace existing authorization header if any
// replace existing authorization header if any
request.Headers.SetOrAddHeaderValue(KnownHeaders.Authorization, auth);
//don't need to send body for Authorization request
// don't need to send body for Authorization request
if (request.HasBody)
{
request.ContentLength = 0;
}
}
//challenge value will start with any of the scheme selected
// challenge value will start with any of the scheme selected
else
{
scheme = authSchemes.First(x =>
......@@ -135,19 +136,19 @@ namespace Titanium.Web.Proxy
string auth = string.Concat(scheme, clientToken);
//there will be an existing header from initial client request
// there will be an existing header from initial client request
request.Headers.SetOrAddHeaderValue(KnownHeaders.Authorization, auth);
//send body for final auth request
// send body for final auth request
if (request.OriginalHasBody)
{
request.ContentLength = request.Body.Length;
}
}
//Need to revisit this.
//Should we cache all Set-Cokiee headers from server during auth process
//and send it to client after auth?
// Need to revisit this.
// Should we cache all Set-Cokiee headers from server during auth process
// and send it to client after auth?
// Let ResponseHandler send the updated request
args.ReRequest = true;
......
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