Commit 4e203c3a authored by jmh76's avatar jmh76

Merge remote-tracking branch 'upstream/master'

parents 5cb49c70 352de4a8
......@@ -165,19 +165,19 @@
</h3>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_Exceptions_ProxyConnectException_ConnectEventArgs.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_Exceptions_ProxyConnectException_Session.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/Exceptions/ProxyConnectException.cs/#L29">View Source</a>
</span>
<a id="Titanium_Web_Proxy_Exceptions_ProxyConnectException_ConnectEventArgs_" data-uid="Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs*"></a>
<h4 id="Titanium_Web_Proxy_Exceptions_ProxyConnectException_ConnectEventArgs" data-uid="Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs">ConnectEventArgs</h4>
<a id="Titanium_Web_Proxy_Exceptions_ProxyConnectException_Session_" data-uid="Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session*"></a>
<h4 id="Titanium_Web_Proxy_Exceptions_ProxyConnectException_Session" data-uid="Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session">Session</h4>
<div class="markdown level1 summary"><p>Gets session info associated to the exception.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public TunnelConnectSessionEventArgs ConnectEventArgs { get; }</code></pre>
<pre><code class="lang-csharp hljs">public SessionEventArgsBase Session { get; }</code></pre>
</div>
<h5 class="propertyValue">Property Value</h5>
<table class="table table-bordered table-striped table-condensed">
......@@ -189,12 +189,12 @@
</thead>
<tbody>
<tr>
<td><a class="xref" href="Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html">TunnelConnectSessionEventArgs</a></td>
<td><a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html">SessionEventArgsBase</a></td>
<td></td>
</tr>
</tbody>
</table>
<h5 id="Titanium_Web_Proxy_Exceptions_ProxyConnectException_ConnectEventArgs_remarks">Remarks</h5>
<h5 id="Titanium_Web_Proxy_Exceptions_ProxyConnectException_Session_remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This object properties should not be edited.</p>
</div>
<h3 id="implements">Implements</h3>
......
......@@ -165,19 +165,19 @@
</h3>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_Exceptions_ProxyHttpException_SessionEventArgs.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_Exceptions_ProxyHttpException_Session.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/Exceptions/ProxyHttpException.cs/#L29">View Source</a>
</span>
<a id="Titanium_Web_Proxy_Exceptions_ProxyHttpException_SessionEventArgs_" data-uid="Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs*"></a>
<h4 id="Titanium_Web_Proxy_Exceptions_ProxyHttpException_SessionEventArgs" data-uid="Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs">SessionEventArgs</h4>
<a id="Titanium_Web_Proxy_Exceptions_ProxyHttpException_Session_" data-uid="Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session*"></a>
<h4 id="Titanium_Web_Proxy_Exceptions_ProxyHttpException_Session" data-uid="Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session">Session</h4>
<div class="markdown level1 summary"><p>Gets session info associated to the exception.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public SessionEventArgs SessionEventArgs { get; }</code></pre>
<pre><code class="lang-csharp hljs">public SessionEventArgs Session { get; }</code></pre>
</div>
<h5 class="propertyValue">Property Value</h5>
<table class="table table-bordered table-striped table-condensed">
......@@ -194,7 +194,7 @@
</tr>
</tbody>
</table>
<h5 id="Titanium_Web_Proxy_Exceptions_ProxyHttpException_SessionEventArgs_remarks">Remarks</h5>
<h5 id="Titanium_Web_Proxy_Exceptions_ProxyHttpException_Session_remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This object properties should not be edited.</p>
</div>
<h3 id="implements">Implements</h3>
......
......@@ -67,7 +67,7 @@
"api/Titanium.Web.Proxy.Exceptions.ProxyConnectException.html": {
"href": "api/Titanium.Web.Proxy.Exceptions.ProxyConnectException.html",
"title": "Class ProxyConnectException | Titanium Web Proxy",
"keywords": "Class ProxyConnectException Proxy Connection exception. Inheritance Object Exception ProxyException ProxyConnectException Implements ISerializable _Exception Inherited Members Exception.GetBaseException() Exception.ToString() Exception.GetObjectData(SerializationInfo, StreamingContext) Exception.GetType() Exception.Message Exception.Data Exception.InnerException Exception.TargetSite Exception.StackTrace Exception.HelpLink Exception.Source Exception.HResult Exception.SerializeObjectState Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Exceptions Assembly : Titanium.Web.Proxy.dll Syntax public class ProxyConnectException : ProxyException, ISerializable, _Exception Properties | Improve this Doc View Source ConnectEventArgs Gets session info associated to the exception. Declaration public TunnelConnectSessionEventArgs ConnectEventArgs { get; } Property Value Type Description TunnelConnectSessionEventArgs Remarks This object properties should not be edited. Implements System.Runtime.Serialization.ISerializable System.Runtime.InteropServices._Exception"
"keywords": "Class ProxyConnectException Proxy Connection exception. Inheritance Object Exception ProxyException ProxyConnectException Implements ISerializable _Exception Inherited Members Exception.GetBaseException() Exception.ToString() Exception.GetObjectData(SerializationInfo, StreamingContext) Exception.GetType() Exception.Message Exception.Data Exception.InnerException Exception.TargetSite Exception.StackTrace Exception.HelpLink Exception.Source Exception.HResult Exception.SerializeObjectState Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Exceptions Assembly : Titanium.Web.Proxy.dll Syntax public class ProxyConnectException : ProxyException, ISerializable, _Exception Properties | Improve this Doc View Source Session Gets session info associated to the exception. Declaration public SessionEventArgsBase Session { get; } Property Value Type Description SessionEventArgsBase Remarks This object properties should not be edited. Implements System.Runtime.Serialization.ISerializable System.Runtime.InteropServices._Exception"
},
"api/Titanium.Web.Proxy.Exceptions.ProxyException.html": {
"href": "api/Titanium.Web.Proxy.Exceptions.ProxyException.html",
......@@ -77,7 +77,7 @@
"api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html": {
"href": "api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html",
"title": "Class ProxyHttpException | Titanium Web Proxy",
"keywords": "Class ProxyHttpException Proxy HTTP exception. Inheritance Object Exception ProxyException ProxyHttpException Implements ISerializable _Exception Inherited Members Exception.GetBaseException() Exception.ToString() Exception.GetObjectData(SerializationInfo, StreamingContext) Exception.GetType() Exception.Message Exception.Data Exception.InnerException Exception.TargetSite Exception.StackTrace Exception.HelpLink Exception.Source Exception.HResult Exception.SerializeObjectState Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Exceptions Assembly : Titanium.Web.Proxy.dll Syntax public class ProxyHttpException : ProxyException, ISerializable, _Exception Properties | Improve this Doc View Source SessionEventArgs Gets session info associated to the exception. Declaration public SessionEventArgs SessionEventArgs { get; } Property Value Type Description SessionEventArgs Remarks This object properties should not be edited. Implements System.Runtime.Serialization.ISerializable System.Runtime.InteropServices._Exception"
"keywords": "Class ProxyHttpException Proxy HTTP exception. Inheritance Object Exception ProxyException ProxyHttpException Implements ISerializable _Exception Inherited Members Exception.GetBaseException() Exception.ToString() Exception.GetObjectData(SerializationInfo, StreamingContext) Exception.GetType() Exception.Message Exception.Data Exception.InnerException Exception.TargetSite Exception.StackTrace Exception.HelpLink Exception.Source Exception.HResult Exception.SerializeObjectState Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Exceptions Assembly : Titanium.Web.Proxy.dll Syntax public class ProxyHttpException : ProxyException, ISerializable, _Exception Properties | Improve this Doc View Source Session Gets session info associated to the exception. Declaration public SessionEventArgs Session { get; } Property Value Type Description SessionEventArgs Remarks This object properties should not be edited. Implements System.Runtime.Serialization.ISerializable System.Runtime.InteropServices._Exception"
},
"api/Titanium.Web.Proxy.Exceptions.ServerConnectionException.html": {
"href": "api/Titanium.Web.Proxy.Exceptions.ServerConnectionException.html",
......
......@@ -797,19 +797,19 @@ references:
commentId: T:Titanium.Web.Proxy.Exceptions.ProxyConnectException
fullName: Titanium.Web.Proxy.Exceptions.ProxyConnectException
nameWithType: ProxyConnectException
- uid: Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs
name: ConnectEventArgs
href: api/Titanium.Web.Proxy.Exceptions.ProxyConnectException.html#Titanium_Web_Proxy_Exceptions_ProxyConnectException_ConnectEventArgs
commentId: P:Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs
fullName: Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs
nameWithType: ProxyConnectException.ConnectEventArgs
- uid: Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs*
name: ConnectEventArgs
href: api/Titanium.Web.Proxy.Exceptions.ProxyConnectException.html#Titanium_Web_Proxy_Exceptions_ProxyConnectException_ConnectEventArgs_
commentId: Overload:Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs
isSpec: "True"
fullName: Titanium.Web.Proxy.Exceptions.ProxyConnectException.ConnectEventArgs
nameWithType: ProxyConnectException.ConnectEventArgs
- uid: Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session
name: Session
href: api/Titanium.Web.Proxy.Exceptions.ProxyConnectException.html#Titanium_Web_Proxy_Exceptions_ProxyConnectException_Session
commentId: P:Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session
fullName: Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session
nameWithType: ProxyConnectException.Session
- uid: Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session*
name: Session
href: api/Titanium.Web.Proxy.Exceptions.ProxyConnectException.html#Titanium_Web_Proxy_Exceptions_ProxyConnectException_Session_
commentId: Overload:Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session
isSpec: "True"
fullName: Titanium.Web.Proxy.Exceptions.ProxyConnectException.Session
nameWithType: ProxyConnectException.Session
- uid: Titanium.Web.Proxy.Exceptions.ProxyException
name: ProxyException
href: api/Titanium.Web.Proxy.Exceptions.ProxyException.html
......@@ -841,19 +841,19 @@ references:
commentId: T:Titanium.Web.Proxy.Exceptions.ProxyHttpException
fullName: Titanium.Web.Proxy.Exceptions.ProxyHttpException
nameWithType: ProxyHttpException
- uid: Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs
name: SessionEventArgs
href: api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html#Titanium_Web_Proxy_Exceptions_ProxyHttpException_SessionEventArgs
commentId: P:Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs
fullName: Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs
nameWithType: ProxyHttpException.SessionEventArgs
- uid: Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs*
name: SessionEventArgs
href: api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html#Titanium_Web_Proxy_Exceptions_ProxyHttpException_SessionEventArgs_
commentId: Overload:Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs
- uid: Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session
name: Session
href: api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html#Titanium_Web_Proxy_Exceptions_ProxyHttpException_Session
commentId: P:Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session
fullName: Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session
nameWithType: ProxyHttpException.Session
- uid: Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session*
name: Session
href: api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html#Titanium_Web_Proxy_Exceptions_ProxyHttpException_Session_
commentId: Overload:Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session
isSpec: "True"
fullName: Titanium.Web.Proxy.Exceptions.ProxyHttpException.SessionEventArgs
nameWithType: ProxyHttpException.SessionEventArgs
fullName: Titanium.Web.Proxy.Exceptions.ProxyHttpException.Session
nameWithType: ProxyHttpException.Session
- uid: Titanium.Web.Proxy.Exceptions.ServerConnectionException
name: ServerConnectionException
href: api/Titanium.Web.Proxy.Exceptions.ServerConnectionException.html
......
......@@ -13,11 +13,11 @@ namespace Titanium.Web.Proxy.Exceptions
/// </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(
/// <param name="session">Instance of <see cref="EventArguments.TunnelConnectSessionEventArgs" /> associated to the exception</param>
internal ProxyConnectException(string message, Exception innerException, SessionEventArgsBase session) : base(
message, innerException)
{
ConnectEventArgs = connectEventArgs;
Session = session;
}
/// <summary>
......@@ -26,6 +26,6 @@ namespace Titanium.Web.Proxy.Exceptions
/// <remarks>
/// This object properties should not be edited.
/// </remarks>
public TunnelConnectSessionEventArgs ConnectEventArgs { get; }
public SessionEventArgsBase Session { get; }
}
}
......@@ -13,11 +13,11 @@ namespace Titanium.Web.Proxy.Exceptions
/// </summary>
/// <param name="message">Message for this exception</param>
/// <param name="innerException">Associated inner exception</param>
/// <param name="sessionEventArgs">Instance of <see cref="EventArguments.SessionEventArgs" /> associated to the exception</param>
internal ProxyHttpException(string message, Exception innerException, SessionEventArgs sessionEventArgs) : base(
/// <param name="session">Instance of <see cref="EventArguments.SessionEventArgs" /> associated to the exception</param>
internal ProxyHttpException(string message, Exception innerException, SessionEventArgs session) : base(
message, innerException)
{
SessionEventArgs = sessionEventArgs;
Session = session;
}
/// <summary>
......@@ -26,6 +26,6 @@ namespace Titanium.Web.Proxy.Exceptions
/// <remarks>
/// This object properties should not be edited.
/// </remarks>
public SessionEventArgs SessionEventArgs { get; }
public SessionEventArgs Session { get; }
}
}
......@@ -41,11 +41,13 @@ namespace Titanium.Web.Proxy
bool closeServerConnection = false;
bool calledRequestHandler = false;
SslStream sslStream = null;
try
{
string connectHostname = null;
TunnelConnectSessionEventArgs connectArgs = null;
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if (await HttpHelper.IsConnectMethod(clientStream) == 1)
......@@ -150,8 +152,6 @@ namespace Titanium.Web.Proxy
await tcpConnectionFactory.Release(connection, true);
}
SslStream sslStream = null;
if (EnableTcpServerConnectionPrefetch)
{
//don't pass cancellation token here
......@@ -161,13 +161,13 @@ namespace Titanium.Web.Proxy
cancellationToken: CancellationToken.None);
}
X509Certificate2 certificate = null;
try
{
sslStream = new SslStream(clientStream);
sslStream = new SslStream(clientStream, true);
string certName = HttpHelper.GetWildCardDomainName(connectHostname);
var certificate = endPoint.GenericCertificate ??
certificate = endPoint.GenericCertificate ??
await CertificateManager.CreateServerCertificate(certName);
// Successfully managed to authenticate the client using the fake certificate
......@@ -197,9 +197,9 @@ namespace Titanium.Web.Proxy
}
catch (Exception e)
{
sslStream?.Dispose();
var certname = certificate?.GetNameInfo(X509NameType.SimpleName, false);
throw new ProxyConnectException(
$"Could'nt authenticate client '{connectHostname}' with fake certificate.", e, connectArgs);
$"Couldn't authenticate host '{connectHostname}' with certificate '{certname}'.", e, connectArgs);
}
if (await HttpHelper.IsConnectMethod(clientStream) == -1)
......@@ -350,6 +350,7 @@ namespace Titanium.Web.Proxy
await tcpConnectionFactory.Release(prefetchConnectionTask, closeServerConnection);
}
sslStream?.Dispose();
clientStream.Dispose();
if (!cancellationTokenSource.IsCancellationRequested)
......
......@@ -4,6 +4,7 @@ using System.IO;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using StreamExtended;
......@@ -34,6 +35,8 @@ namespace Titanium.Web.Proxy
var clientStream = new CustomBufferedStream(clientConnection.GetStream(), BufferPool, BufferSize);
var clientStreamWriter = new HttpResponseWriter(clientStream, BufferPool, BufferSize);
SslStream sslStream = null;
try
{
var clientHelloInfo = await SslTools.PeekClientHello(clientStream, BufferPool, cancellationToken);
......@@ -60,18 +63,17 @@ namespace Titanium.Web.Proxy
if (endPoint.DecryptSsl && args.DecryptSsl)
{
SslStream sslStream = null;
//do client authentication using fake certificate
//do client authentication using certificate
X509Certificate2 certificate = null;
try
{
sslStream = new SslStream(clientStream);
sslStream = new SslStream(clientStream, true);
string certName = HttpHelper.GetWildCardDomainName(httpsHostName);
var certificate = endPoint.GenericCertificate ??
certificate = endPoint.GenericCertificate ??
await CertificateManager.CreateServerCertificate(certName);
// Successfully managed to authenticate the client using the fake certificate
// Successfully managed to authenticate the client using the certificate
await sslStream.AuthenticateAsServerAsync(certificate, false, SslProtocols.Tls, false);
// HTTPS server created - we can now decrypt the client's traffic
......@@ -81,10 +83,16 @@ namespace Titanium.Web.Proxy
}
catch (Exception e)
{
sslStream?.Dispose();
var certname = certificate?.GetNameInfo(X509NameType.SimpleName, false);
var session = new SessionEventArgs(this, endPoint, cancellationTokenSource)
{
ProxyClient = { Connection = clientConnection },
HttpClient = { ConnectRequest = null }
};
throw new ProxyConnectException(
$"Could'nt authenticate client '{httpsHostName}' with fake certificate.", e, null);
$"Couldn't authenticate host '{httpsHostName}' with certificate '{certname}'.", e, session);
}
}
else
{
......@@ -150,8 +158,9 @@ namespace Titanium.Web.Proxy
}
finally
{
sslStream?.Dispose();
clientStream.Dispose();
if (!cancellationTokenSource.IsCancellationRequested)
{
cancellationTokenSource.Cancel();
......
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