Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
584af5de
Commit
584af5de
authored
Apr 29, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix build failure
parent
df1cad80
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
86 additions
and
48 deletions
+86
-48
CertificateHandler.cs
Titanium.Web.Proxy/CertificateHandler.cs
+10
-10
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+3
-3
RunTime.cs
Titanium.Web.Proxy/Helpers/RunTime.cs
+5
-3
ProxyAuthorizationHandler.cs
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+11
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+27
-19
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+14
-4
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+8
-5
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+8
-4
No files found.
Titanium.Web.Proxy/CertificateHandler.cs
View file @
584af5de
...
...
@@ -11,11 +11,11 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Call back to override server certificate validation
/// </summary>
/// <param name="sender"></param>
/// <param name="certificate"></param>
/// <param name="chain"></param>
/// <param name="sslPolicyErrors"></param>
/// <returns></returns>
/// <param name="sender">
The sender object.
</param>
/// <param name="certificate">
The remote certificate.
</param>
/// <param name="chain">
The certificate chain.
</param>
/// <param name="sslPolicyErrors">
Ssl policy errors
</param>
/// <returns>
Return true if valid certificate.
</returns>
internal
bool
ValidateServerCertificate
(
object
sender
,
X509Certificate
certificate
,
X509Chain
chain
,
SslPolicyErrors
sslPolicyErrors
)
{
...
...
@@ -47,11 +47,11 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Call back to select client certificate used for mutual authentication
/// </summary>
/// <param name="sender"></param>
/// <param name="targetHost"></param>
/// <param name="localCertificates"></param>
/// <param name="remoteCertificate"></param>
/// <param name="acceptableIssuers"></param>
/// <param name="sender">
The sender.
</param>
/// <param name="targetHost">
The remote hostname.
</param>
/// <param name="localCertificates">
Selected local certificates by SslStream.
</param>
/// <param name="remoteCertificate">
The remote certificate of server.
</param>
/// <param name="acceptableIssuers">
The acceptable issues for client certificate as listed by server.
</param>
/// <returns></returns>
internal
X509Certificate
SelectClientCertificate
(
object
sender
,
string
targetHost
,
X509CertificateCollection
localCertificates
,
...
...
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
584af5de
...
...
@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy
/// This is called when client is aware of proxy
/// So for HTTPS requests client would send CONNECT header to negotiate a secure tcp tunnel via proxy
/// </summary>
/// <param name="endPoint"></param>
/// <param name="tcpClient"></param>
/// <returns></returns>
/// <param name="endPoint">
The explicit endpoint.
</param>
/// <param name="tcpClient">
The client.
</param>
/// <returns>
The task.
</returns>
private
async
Task
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
var
cancellationTokenSource
=
new
CancellationTokenSource
();
...
...
Titanium.Web.Proxy/Helpers/RunTime.cs
View file @
584af5de
using
System
;
#if NETSTANDARD2_0
using
System.Runtime.InteropServices
;
#endif
namespace
Titanium.Web.Proxy.Helpers
{
/// <summary>
...
...
@@ -18,9 +21,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
/// <summary>
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
584af5de
...
...
@@ -13,8 +13,14 @@ namespace Titanium.Web.Proxy
{
public
partial
class
ProxyServer
{
/// <summary>
/// Callback to authorize clients of this proxy instance.
/// </summary>
/// <param name="session">The session event arguments.</param>
/// <returns>True if authorized.</returns>
private
async
Task
<
bool
>
CheckAuthorization
(
SessionEventArgsBase
session
)
{
//If we are not authorizing clients return true
if
(
AuthenticateUserFunc
==
null
)
{
return
true
;
...
...
@@ -70,6 +76,11 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// Create an authentication required response.
/// </summary>
/// <param name="description">Response description.</param>
/// <returns></returns>
private
Response
CreateAuthentication407Response
(
string
description
)
{
var
response
=
new
Response
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
584af5de
...
...
@@ -27,19 +27,22 @@ namespace Titanium.Web.Proxy
EnableWinAuth
&&
RunTime
.
IsWindows
&&
!
RunTime
.
IsRunningOnMono
;
/// <summary>
/// This is the core request handler method for a particular connection from client
/// This is the core request handler method for a particular connection from client
.
/// Will create new session (request/response) sequence until
/// client/server abruptly terminates connection or by normal HTTP termination
/// client/server abruptly terminates connection or by normal HTTP termination
.
/// </summary>
/// <param name="client"></param>
/// <param name="clientStream"></param>
/// <param name="clientStreamReader"></param>
/// <param name="clientStreamWriter"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="httpsConnectHostname"></param>
/// <param name="endPoint"></param>
/// <param name="connectRequest"></param>
/// <param name="isTransparentEndPoint"></param>
/// <param name="endPoint">The proxy endpoint.</param>
/// <param name="client">The client.</param>
/// <param name="clientStream">The client stream.</param>
/// <param name="clientStreamReader">The client stream reader.</param>
/// <param name="clientStreamWriter">The client stream writer.</param>
/// <param name="cancellationTokenSource">The cancellation token source for this async task.</param>
/// <param name="httpsConnectHostname">
/// The https hostname as appeared in CONNECT request if this is a HTTPS request from
/// explicit endpoint.
/// </param>
/// <param name="connectRequest">The Connect request if this is a HTTPS request from explicit endpoint.</param>
/// <param name="isTransparentEndPoint">Is this a request from transparent endpoint?</param>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClient
client
,
CustomBufferedStream
clientStream
,
CustomBinaryReader
clientStreamReader
,
...
...
@@ -272,9 +275,9 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Handle a specific session (request/response sequence)
/// </summary>
/// <param name="connection"></param>
/// <param name="args"></param>
/// <returns>
True if close the connection
</returns>
/// <param name="connection">
The tcp connection.
</param>
/// <param name="args">
The session event arguments.
</param>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
)
{
try
...
...
@@ -355,11 +358,11 @@ namespace Titanium.Web.Proxy
}
/// <summary>
/// Create a
Server Connection
/// Create a
server connection.
/// </summary>
/// <param name="args"></param>
/// <param name="isConnect"></param>
/// <param name="cancellationToken"></param>
/// <param name="args">
The session event arguments.
</param>
/// <param name="isConnect">
Is this a CONNECT request.
</param>
/// <param name="cancellationToken">
The cancellation token for this async task.
</param>
/// <returns></returns>
private
async
Task
<
TcpConnection
>
GetServerConnection
(
SessionEventArgsBase
args
,
bool
isConnect
,
CancellationToken
cancellationToken
)
...
...
@@ -385,7 +388,7 @@ namespace Titanium.Web.Proxy
}
/// <summary>
///
p
repare the request headers so that we can avoid encodings not parsable by this proxy
///
P
repare the request headers so that we can avoid encodings not parsable by this proxy
/// </summary>
/// <param name="requestHeaders"></param>
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
...
...
@@ -398,6 +401,11 @@ namespace Titanium.Web.Proxy
requestHeaders
.
FixProxyHeaders
();
}
/// <summary>
/// Invoke before request handler if it is set.
/// </summary>
/// <param name="args">The session event arguments.</param>
/// <returns></returns>
private
async
Task
InvokeBeforeRequest
(
SessionEventArgs
args
)
{
if
(
BeforeRequest
!=
null
)
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
584af5de
...
...
@@ -9,15 +9,15 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
namespace
Titanium.Web.Proxy
{
/// <summary>
/// Handle the response from server
/// Handle the response from server
.
/// </summary>
partial
class
ProxyServer
{
/// <summary>
/// Called asynchronously when a request was successfully and we received the response
/// Called asynchronously when a request was successfully and we received the response
.
/// </summary>
/// <param name="args"></param>
/// <returns>
true if client/server connection was terminated (and disposed)
</returns>
/// <param name="args">
The session event arguments.
</param>
/// <returns>
The task.
</returns>
private
async
Task
HandleHttpSessionResponse
(
SessionEventArgs
args
)
{
try
...
...
@@ -129,6 +129,11 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// Invoke before response if it is set.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private
async
Task
InvokeBeforeResponse
(
SessionEventArgs
args
)
{
if
(
BeforeResponse
!=
null
)
...
...
@@ -137,6 +142,11 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// Invoke after response if it is set.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private
async
Task
InvokeAfterResponse
(
SessionEventArgs
args
)
{
if
(
AfterResponse
!=
null
)
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
584af5de
...
...
@@ -17,11 +17,11 @@ namespace Titanium.Web.Proxy
partial
class
ProxyServer
{
/// <summary>
/// This is called when this proxy acts as a reverse proxy (like a real http server)
/// This is called when this proxy acts as a reverse proxy (like a real http server)
.
/// So for HTTPS requests we would start SSL negotiation right away without expecting a CONNECT request from client
/// </summary>
/// <param name="endPoint"></param>
/// <param name="tcpClient"></param>
/// <param name="endPoint">
The transparent endpoint.
</param>
/// <param name="tcpClient">
The client.
</param>
/// <returns></returns>
private
async
Task
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
...
...
@@ -44,8 +44,11 @@ namespace Titanium.Web.Proxy
{
httpsHostName
=
clientHelloInfo
.
GetServerName
()
??
endPoint
.
GenericCertificateName
;
var
args
=
new
BeforeSslAuthenticateEventArgs
(
cancellationTokenSource
);
args
.
SniHostName
=
httpsHostName
;
var
args
=
new
BeforeSslAuthenticateEventArgs
(
cancellationTokenSource
)
{
SniHostName
=
httpsHostName
};
await
endPoint
.
InvokeBeforeSslAuthenticate
(
this
,
args
,
ExceptionFunc
);
if
(
cancellationTokenSource
.
IsCancellationRequested
)
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
584af5de
...
...
@@ -13,7 +13,9 @@ namespace Titanium.Web.Proxy
{
public
partial
class
ProxyServer
{
//possible header names
/// <summary>
/// possible header names.
/// </summary>
private
static
readonly
HashSet
<
string
>
authHeaderNames
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
"WWW-Authenticate"
,
...
...
@@ -24,6 +26,9 @@ namespace Titanium.Web.Proxy
"KerberosAuthorization"
};
/// <summary>
/// supported authentication schemes.
/// </summary>
private
static
readonly
HashSet
<
string
>
authSchemes
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
"NTLM"
,
...
...
@@ -32,13 +37,12 @@ namespace Titanium.Web.Proxy
};
/// <summary>
/// Handle windows NTLM authentication
/// Can expand this for Kerberos in future
/// Handle windows NTLM/Kerberos authentication.
/// Note: NTLM/Kerberos cannot do a man in middle operation
/// we do for HTTPS requests.
/// As such we will be sending local credentials of current
/// User to server to authenticate requests.
/// To disable this set ProxyServer.EnableWinAuth to false
/// To disable this set ProxyServer.EnableWinAuth to false
.
/// </summary>
internal
async
Task
Handle401UnAuthorized
(
SessionEventArgs
args
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment