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
Show 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
...
@@ -11,11 +11,11 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Call back to override server certificate validation
/// Call back to override server certificate validation
/// </summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="sender">
The sender object.
</param>
/// <param name="certificate"></param>
/// <param name="certificate">
The remote certificate.
</param>
/// <param name="chain"></param>
/// <param name="chain">
The certificate chain.
</param>
/// <param name="sslPolicyErrors"></param>
/// <param name="sslPolicyErrors">
Ssl policy errors
</param>
/// <returns></returns>
/// <returns>
Return true if valid certificate.
</returns>
internal
bool
ValidateServerCertificate
(
object
sender
,
X509Certificate
certificate
,
X509Chain
chain
,
internal
bool
ValidateServerCertificate
(
object
sender
,
X509Certificate
certificate
,
X509Chain
chain
,
SslPolicyErrors
sslPolicyErrors
)
SslPolicyErrors
sslPolicyErrors
)
{
{
...
@@ -47,11 +47,11 @@ namespace Titanium.Web.Proxy
...
@@ -47,11 +47,11 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Call back to select client certificate used for mutual authentication
/// Call back to select client certificate used for mutual authentication
/// </summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="sender">
The sender.
</param>
/// <param name="targetHost"></param>
/// <param name="targetHost">
The remote hostname.
</param>
/// <param name="localCertificates"></param>
/// <param name="localCertificates">
Selected local certificates by SslStream.
</param>
/// <param name="remoteCertificate"></param>
/// <param name="remoteCertificate">
The remote certificate of server.
</param>
/// <param name="acceptableIssuers"></param>
/// <param name="acceptableIssuers">
The acceptable issues for client certificate as listed by server.
</param>
/// <returns></returns>
/// <returns></returns>
internal
X509Certificate
SelectClientCertificate
(
object
sender
,
string
targetHost
,
internal
X509Certificate
SelectClientCertificate
(
object
sender
,
string
targetHost
,
X509CertificateCollection
localCertificates
,
X509CertificateCollection
localCertificates
,
...
...
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
584af5de
...
@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy
...
@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy
/// This is called when client is aware of 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
/// So for HTTPS requests client would send CONNECT header to negotiate a secure tcp tunnel via proxy
/// </summary>
/// </summary>
/// <param name="endPoint"></param>
/// <param name="endPoint">
The explicit endpoint.
</param>
/// <param name="tcpClient"></param>
/// <param name="tcpClient">
The client.
</param>
/// <returns></returns>
/// <returns>
The task.
</returns>
private
async
Task
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
private
async
Task
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
{
var
cancellationTokenSource
=
new
CancellationTokenSource
();
var
cancellationTokenSource
=
new
CancellationTokenSource
();
...
...
Titanium.Web.Proxy/Helpers/RunTime.cs
View file @
584af5de
using
System
;
using
System
;
#if NETSTANDARD2_0
using
System.Runtime.InteropServices
;
#endif
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
/// <summary>
/// <summary>
...
@@ -18,9 +21,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -18,9 +21,8 @@ namespace Titanium.Web.Proxy.Helpers
/// cache for Windows platform check
/// cache for Windows platform check
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
private
static
readonly
Lazy
<
bool
>
isRunningOnWindows
=
private
static
readonly
Lazy
<
bool
>
isRunningOnWindows
new
Lazy
<
bool
>(()
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
));
=
new
Lazy
<
bool
>(()
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
));
#endif
#endif
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
584af5de
...
@@ -13,8 +13,14 @@ namespace Titanium.Web.Proxy
...
@@ -13,8 +13,14 @@ namespace Titanium.Web.Proxy
{
{
public
partial
class
ProxyServer
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
)
private
async
Task
<
bool
>
CheckAuthorization
(
SessionEventArgsBase
session
)
{
{
//If we are not authorizing clients return true
if
(
AuthenticateUserFunc
==
null
)
if
(
AuthenticateUserFunc
==
null
)
{
{
return
true
;
return
true
;
...
@@ -70,6 +76,11 @@ namespace Titanium.Web.Proxy
...
@@ -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
)
private
Response
CreateAuthentication407Response
(
string
description
)
{
{
var
response
=
new
Response
var
response
=
new
Response
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
584af5de
...
@@ -27,19 +27,22 @@ namespace Titanium.Web.Proxy
...
@@ -27,19 +27,22 @@ namespace Titanium.Web.Proxy
EnableWinAuth
&&
RunTime
.
IsWindows
&&
!
RunTime
.
IsRunningOnMono
;
EnableWinAuth
&&
RunTime
.
IsWindows
&&
!
RunTime
.
IsRunningOnMono
;
/// <summary>
/// <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
/// 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>
/// </summary>
/// <param name="client"></param>
/// <param name="endPoint">The proxy endpoint.</param>
/// <param name="clientStream"></param>
/// <param name="client">The client.</param>
/// <param name="clientStreamReader"></param>
/// <param name="clientStream">The client stream.</param>
/// <param name="clientStreamWriter"></param>
/// <param name="clientStreamReader">The client stream reader.</param>
/// <param name="cancellationTokenSource"></param>
/// <param name="clientStreamWriter">The client stream writer.</param>
/// <param name="httpsConnectHostname"></param>
/// <param name="cancellationTokenSource">The cancellation token source for this async task.</param>
/// <param name="endPoint"></param>
/// <param name="httpsConnectHostname">
/// <param name="connectRequest"></param>
/// The https hostname as appeared in CONNECT request if this is a HTTPS request from
/// <param name="isTransparentEndPoint"></param>
/// 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>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClient
client
,
private
async
Task
HandleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClient
client
,
CustomBufferedStream
clientStream
,
CustomBinaryReader
clientStreamReader
,
CustomBufferedStream
clientStream
,
CustomBinaryReader
clientStreamReader
,
...
@@ -272,9 +275,9 @@ namespace Titanium.Web.Proxy
...
@@ -272,9 +275,9 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Handle a specific session (request/response sequence)
/// Handle a specific session (request/response sequence)
/// </summary>
/// </summary>
/// <param name="connection"></param>
/// <param name="connection">
The tcp connection.
</param>
/// <param name="args"></param>
/// <param name="args">
The session event arguments.
</param>
/// <returns>
True if close the connection
</returns>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
)
private
async
Task
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
)
{
{
try
try
...
@@ -355,11 +358,11 @@ namespace Titanium.Web.Proxy
...
@@ -355,11 +358,11 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <summary>
/// Create a
Server Connection
/// Create a
server connection.
/// </summary>
/// </summary>
/// <param name="args"></param>
/// <param name="args">
The session event arguments.
</param>
/// <param name="isConnect"></param>
/// <param name="isConnect">
Is this a CONNECT request.
</param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken">
The cancellation token for this async task.
</param>
/// <returns></returns>
/// <returns></returns>
private
async
Task
<
TcpConnection
>
GetServerConnection
(
SessionEventArgsBase
args
,
bool
isConnect
,
private
async
Task
<
TcpConnection
>
GetServerConnection
(
SessionEventArgsBase
args
,
bool
isConnect
,
CancellationToken
cancellationToken
)
CancellationToken
cancellationToken
)
...
@@ -385,7 +388,7 @@ namespace Titanium.Web.Proxy
...
@@ -385,7 +388,7 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <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>
/// </summary>
/// <param name="requestHeaders"></param>
/// <param name="requestHeaders"></param>
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
...
@@ -398,6 +401,11 @@ namespace Titanium.Web.Proxy
...
@@ -398,6 +401,11 @@ namespace Titanium.Web.Proxy
requestHeaders
.
FixProxyHeaders
();
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
)
private
async
Task
InvokeBeforeRequest
(
SessionEventArgs
args
)
{
{
if
(
BeforeRequest
!=
null
)
if
(
BeforeRequest
!=
null
)
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
584af5de
...
@@ -9,15 +9,15 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
...
@@ -9,15 +9,15 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
/// <summary>
/// <summary>
/// Handle the response from server
/// Handle the response from server
.
/// </summary>
/// </summary>
partial
class
ProxyServer
partial
class
ProxyServer
{
{
/// <summary>
/// <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>
/// </summary>
/// <param name="args"></param>
/// <param name="args">
The session event arguments.
</param>
/// <returns>
true if client/server connection was terminated (and disposed)
</returns>
/// <returns>
The task.
</returns>
private
async
Task
HandleHttpSessionResponse
(
SessionEventArgs
args
)
private
async
Task
HandleHttpSessionResponse
(
SessionEventArgs
args
)
{
{
try
try
...
@@ -129,6 +129,11 @@ namespace Titanium.Web.Proxy
...
@@ -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
)
private
async
Task
InvokeBeforeResponse
(
SessionEventArgs
args
)
{
{
if
(
BeforeResponse
!=
null
)
if
(
BeforeResponse
!=
null
)
...
@@ -137,6 +142,11 @@ namespace Titanium.Web.Proxy
...
@@ -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
)
private
async
Task
InvokeAfterResponse
(
SessionEventArgs
args
)
{
{
if
(
AfterResponse
!=
null
)
if
(
AfterResponse
!=
null
)
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
584af5de
...
@@ -17,11 +17,11 @@ namespace Titanium.Web.Proxy
...
@@ -17,11 +17,11 @@ namespace Titanium.Web.Proxy
partial
class
ProxyServer
partial
class
ProxyServer
{
{
/// <summary>
/// <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
/// So for HTTPS requests we would start SSL negotiation right away without expecting a CONNECT request from client
/// </summary>
/// </summary>
/// <param name="endPoint"></param>
/// <param name="endPoint">
The transparent endpoint.
</param>
/// <param name="tcpClient"></param>
/// <param name="tcpClient">
The client.
</param>
/// <returns></returns>
/// <returns></returns>
private
async
Task
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
private
async
Task
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
{
...
@@ -44,8 +44,11 @@ namespace Titanium.Web.Proxy
...
@@ -44,8 +44,11 @@ namespace Titanium.Web.Proxy
{
{
httpsHostName
=
clientHelloInfo
.
GetServerName
()
??
endPoint
.
GenericCertificateName
;
httpsHostName
=
clientHelloInfo
.
GetServerName
()
??
endPoint
.
GenericCertificateName
;
var
args
=
new
BeforeSslAuthenticateEventArgs
(
cancellationTokenSource
);
var
args
=
new
BeforeSslAuthenticateEventArgs
(
cancellationTokenSource
)
args
.
SniHostName
=
httpsHostName
;
{
SniHostName
=
httpsHostName
};
await
endPoint
.
InvokeBeforeSslAuthenticate
(
this
,
args
,
ExceptionFunc
);
await
endPoint
.
InvokeBeforeSslAuthenticate
(
this
,
args
,
ExceptionFunc
);
if
(
cancellationTokenSource
.
IsCancellationRequested
)
if
(
cancellationTokenSource
.
IsCancellationRequested
)
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
584af5de
...
@@ -13,7 +13,9 @@ namespace Titanium.Web.Proxy
...
@@ -13,7 +13,9 @@ namespace Titanium.Web.Proxy
{
{
public
partial
class
ProxyServer
public
partial
class
ProxyServer
{
{
//possible header names
/// <summary>
/// possible header names.
/// </summary>
private
static
readonly
HashSet
<
string
>
authHeaderNames
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
private
static
readonly
HashSet
<
string
>
authHeaderNames
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
{
"WWW-Authenticate"
,
"WWW-Authenticate"
,
...
@@ -24,6 +26,9 @@ namespace Titanium.Web.Proxy
...
@@ -24,6 +26,9 @@ namespace Titanium.Web.Proxy
"KerberosAuthorization"
"KerberosAuthorization"
};
};
/// <summary>
/// supported authentication schemes.
/// </summary>
private
static
readonly
HashSet
<
string
>
authSchemes
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
private
static
readonly
HashSet
<
string
>
authSchemes
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
{
"NTLM"
,
"NTLM"
,
...
@@ -32,13 +37,12 @@ namespace Titanium.Web.Proxy
...
@@ -32,13 +37,12 @@ namespace Titanium.Web.Proxy
};
};
/// <summary>
/// <summary>
/// Handle windows NTLM authentication
/// Handle windows NTLM/Kerberos authentication.
/// Can expand this for Kerberos in future
/// Note: NTLM/Kerberos cannot do a man in middle operation
/// Note: NTLM/Kerberos cannot do a man in middle operation
/// we do for HTTPS requests.
/// we do for HTTPS requests.
/// As such we will be sending local credentials of current
/// As such we will be sending local credentials of current
/// User to server to authenticate requests.
/// User to server to authenticate requests.
/// To disable this set ProxyServer.EnableWinAuth to false
/// To disable this set ProxyServer.EnableWinAuth to false
.
/// </summary>
/// </summary>
internal
async
Task
Handle401UnAuthorized
(
SessionEventArgs
args
)
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