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
5f65f4d7
Commit
5f65f4d7
authored
May 01, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small exception handling improvement
parent
c3dd0f09
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
19 deletions
+73
-19
ProxyConnectException.cs
Titanium.Web.Proxy/Exceptions/ProxyConnectException.cs
+31
-0
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+7
-8
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+2
-8
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+13
-0
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+20
-3
No files found.
Titanium.Web.Proxy/Exceptions/ProxyConnectException.cs
0 → 100644
View file @
5f65f4d7
using
System
;
using
Titanium.Web.Proxy.EventArguments
;
namespace
Titanium.Web.Proxy.Exceptions
{
/// <summary>
/// Proxy Connection exception.
/// </summary>
public
class
ProxyConnectException
:
ProxyException
{
/// <summary>
/// Instantiate new instance
/// </summary>
/// <param name="message">Message for this exception</param>
/// <param name="innerException">Associated inner exception</param>
/// <param name="connectEventArgs">Instance of <see cref="EventArguments.TunnelConnectSessionEventArgs" /> associated to the exception</param>
internal
ProxyConnectException
(
string
message
,
Exception
innerException
,
TunnelConnectSessionEventArgs
connectEventArgs
)
:
base
(
message
,
innerException
)
{
ConnectEventArgs
=
connectEventArgs
;
}
/// <summary>
/// Gets session info associated to the exception.
/// </summary>
/// <remarks>
/// This object properties should not be edited.
/// </remarks>
public
TunnelConnectSessionEventArgs
ConnectEventArgs
{
get
;
}
}
}
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
5f65f4d7
...
@@ -177,10 +177,9 @@ namespace Titanium.Web.Proxy
...
@@ -177,10 +177,9 @@ namespace Titanium.Web.Proxy
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
ExceptionFunc
(
new
Exception
(
$"Could'nt authenticate client '
{
connectHostname
}
' with fake certificate."
,
e
));
sslStream
?.
Dispose
();
sslStream
?.
Dispose
();
return
;
throw
new
ProxyConnectException
(
$"Could'nt authenticate client '
{
connectHostname
}
' with fake certificate."
,
e
,
connectArgs
);
}
}
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
-
1
)
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
-
1
)
...
@@ -282,21 +281,21 @@ namespace Titanium.Web.Proxy
...
@@ -282,21 +281,21 @@ namespace Titanium.Web.Proxy
clientStreamWriter
,
cancellationTokenSource
,
connectHostname
,
clientStreamWriter
,
cancellationTokenSource
,
connectHostname
,
connectArgs
?.
WebSession
.
ConnectRequest
);
connectArgs
?.
WebSession
.
ConnectRequest
);
}
}
catch
(
Proxy
Http
Exception
e
)
catch
(
ProxyException
e
)
{
{
ExceptionFunc
(
e
);
OnException
(
clientStream
,
e
);
}
}
catch
(
IOException
e
)
catch
(
IOException
e
)
{
{
ExceptionFunc
(
new
Exception
(
"Connection was aborted"
,
e
));
OnException
(
clientStream
,
new
Exception
(
"Connection was aborted"
,
e
));
}
}
catch
(
SocketException
e
)
catch
(
SocketException
e
)
{
{
ExceptionFunc
(
new
Exception
(
"Could not connect"
,
e
));
OnException
(
clientStream
,
new
Exception
(
"Could not connect"
,
e
));
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
ExceptionFunc
(
new
Exception
(
"Error occured in whilst handling the client"
,
e
));
OnException
(
clientStream
,
new
Exception
(
"Error occured in whilst handling the client"
,
e
));
}
}
finally
finally
{
{
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
5f65f4d7
...
@@ -327,10 +327,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -327,10 +327,7 @@ namespace Titanium.Web.Proxy.Network
{
{
if
(
RootCertificate
==
null
)
if
(
RootCertificate
==
null
)
{
{
exceptionFunc
(
exceptionFunc
(
new
Exception
(
"Could not install certificate as it is null or empty."
));
new
Exception
(
"Could not install certificate"
+
" as it is null or empty."
));
return
;
return
;
}
}
...
@@ -368,10 +365,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -368,10 +365,7 @@ namespace Titanium.Web.Proxy.Network
{
{
if
(
certificate
==
null
)
if
(
certificate
==
null
)
{
{
exceptionFunc
(
exceptionFunc
(
new
Exception
(
"Could not remove certificate as it is null or empty."
));
new
Exception
(
"Could not remove certificate"
+
" as it is null or empty."
));
return
;
return
;
}
}
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
5f65f4d7
...
@@ -7,6 +7,7 @@ using System.Security.Authentication;
...
@@ -7,6 +7,7 @@ using System.Security.Authentication;
using
System.Security.Cryptography.X509Certificates
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers.WinHttp
;
using
Titanium.Web.Proxy.Helpers.WinHttp
;
...
@@ -663,6 +664,18 @@ namespace Titanium.Web.Proxy
...
@@ -663,6 +664,18 @@ namespace Titanium.Web.Proxy
}
}
}
}
private
void
OnException
(
CustomBufferedStream
clientStream
,
Exception
exception
)
{
#if DEBUG
if
(
clientStream
is
DebugCustomBufferedStream
debugStream
)
{
debugStream
.
LogException
(
exception
);
}
#endif
ExceptionFunc
(
exception
);
}
/// <summary>
/// <summary>
/// Quit listening on the given end point.
/// Quit listening on the given end point.
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
5f65f4d7
using
System
;
using
System
;
using
System.IO
;
using
System.Net.Security
;
using
System.Net.Security
;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Security.Authentication
;
using
System.Security.Authentication
;
...
@@ -8,6 +9,7 @@ using StreamExtended;
...
@@ -8,6 +9,7 @@ using StreamExtended;
using
StreamExtended.Helpers
;
using
StreamExtended.Helpers
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
...
@@ -77,10 +79,9 @@ namespace Titanium.Web.Proxy
...
@@ -77,10 +79,9 @@ namespace Titanium.Web.Proxy
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
ExceptionFunc
(
new
Exception
(
$"Could'nt authenticate client '
{
httpsHostName
}
' with fake certificate."
,
e
));
sslStream
?.
Dispose
();
sslStream
?.
Dispose
();
return
;
throw
new
ProxyConnectException
(
$"Could'nt authenticate client '
{
httpsHostName
}
' with fake certificate."
,
e
,
null
);
}
}
}
}
else
else
...
@@ -127,6 +128,22 @@ namespace Titanium.Web.Proxy
...
@@ -127,6 +128,22 @@ namespace Titanium.Web.Proxy
await
HandleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
clientStreamWriter
,
await
HandleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
clientStreamWriter
,
cancellationTokenSource
,
isHttps
?
httpsHostName
:
null
,
null
,
true
);
cancellationTokenSource
,
isHttps
?
httpsHostName
:
null
,
null
,
true
);
}
}
catch
(
ProxyException
e
)
{
OnException
(
clientStream
,
e
);
}
catch
(
IOException
e
)
{
OnException
(
clientStream
,
new
Exception
(
"Connection was aborted"
,
e
));
}
catch
(
SocketException
e
)
{
OnException
(
clientStream
,
new
Exception
(
"Could not connect"
,
e
));
}
catch
(
Exception
e
)
{
OnException
(
clientStream
,
new
Exception
(
"Error occured in whilst handling the client"
,
e
));
}
finally
finally
{
{
clientStream
.
Dispose
();
clientStream
.
Dispose
();
...
...
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