Unverified Commit 3a62c35e authored by honfika's avatar honfika Committed by GitHub

Merge pull request #723 from justcoding121/master

stable
parents 3461257d 6db82ba8
...@@ -15,6 +15,7 @@ Kindly report only issues/bugs here. For programming help or questions use [Stac ...@@ -15,6 +15,7 @@ Kindly report only issues/bugs here. For programming help or questions use [Stac
* View/modify/redirect/block requests and responses * View/modify/redirect/block requests and responses
* Supports mutual SSL authentication, proxy authentication & automatic upstream proxy detection * Supports mutual SSL authentication, proxy authentication & automatic upstream proxy detection
* Kerberos/NTLM authentication over HTTP protocols for windows domain * Kerberos/NTLM authentication over HTTP protocols for windows domain
* SOCKS4/5 Proxy support
### Installation ### Installation
Install by [nuget](https://www.nuget.org/packages/Titanium.Web.Proxy) Install by [nuget](https://www.nuget.org/packages/Titanium.Web.Proxy)
...@@ -29,21 +30,21 @@ For stable releases on [stable branch](https://github.com/justcoding121/Titanium ...@@ -29,21 +30,21 @@ For stable releases on [stable branch](https://github.com/justcoding121/Titanium
Supports Supports
* .Net Standard 2.0 or above * .NET Standard 2.0 or above
* .Net Framework 4.6.1 or above * .NET Framework 4.5 or above
### Development environment ### Development environment
#### Windows #### Windows
* Visual Studio Code as IDE for .NET core * Visual Studio Code as IDE for .NET Core
* Visual Studio 2017/2019 as IDE for .NET framework/.NET core * Visual Studio 2019 as IDE for .NET Framework/.NET Core
#### Mac OS #### Mac OS
* Visual Studio Code as IDE for .NET core * Visual Studio Code as IDE for .NET Core
* Visual Studio 2017 as IDE for Mono * Visual Studio 2019 as IDE for Mono
#### Linux #### Linux
* Visual Studio Code as IDE for .NET core * Visual Studio Code as IDE for .NET Core
* Mono develop as IDE for Mono * Mono develop as IDE for Mono
### Usage ### Usage
...@@ -191,7 +192,7 @@ public async Task OnResponse(object sender, SessionEventArgs e) ...@@ -191,7 +192,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
{ {
if (e.HttpClient.Response.ResponseStatusCode == "200") if (e.HttpClient.Response.ResponseStatusCode == "200")
{ {
if (e.HttpClient.Response.ContentType!=null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html")) if (e.HttpClient.Response.ContentType != null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html"))
{ {
byte[] bodyBytes = await e.GetResponseBody(); byte[] bodyBytes = await e.GetResponseBody();
await e.SetResponseBody(bodyBytes); await e.SetResponseBody(bodyBytes);
...@@ -202,7 +203,7 @@ public async Task OnResponse(object sender, SessionEventArgs e) ...@@ -202,7 +203,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
} }
} }
if (e.UserData!=null) if (e.UserData != null)
{ {
// access request from UserData property where we stored it in RequestHandler // access request from UserData property where we stored it in RequestHandler
var request = (Request)e.UserData; var request = (Request)e.UserData;
...@@ -216,14 +217,14 @@ public Task OnCertificateValidation(object sender, CertificateValidationEventArg ...@@ -216,14 +217,14 @@ public Task OnCertificateValidation(object sender, CertificateValidationEventArg
if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None) if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
e.IsValid = true; e.IsValid = true;
return Task.FromResult(0); return Task.CompletedTask;
} }
// Allows overriding default client certificate selection logic during mutual authentication // Allows overriding default client certificate selection logic during mutual authentication
public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs e) public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs e)
{ {
// set e.clientCertificate to override // set e.clientCertificate to override
return Task.FromResult(0); return Task.CompletedTask;
} }
``` ```
### Note to contributors ### Note to contributors
......
...@@ -155,6 +155,9 @@ or when server terminates connection from proxy.</p> ...@@ -155,6 +155,9 @@ or when server terminates connection from proxy.</p>
<div> <div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a> <a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a>
</div> </div>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks">SessionEventArgsBase.IsSocks</a>
</div>
<div> <div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a> <a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a>
</div> </div>
......
...@@ -390,7 +390,7 @@ public IPEndPoint ClientEndPoint { get; }</code></pre> ...@@ -390,7 +390,7 @@ public IPEndPoint ClientEndPoint { get; }</code></pre>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception%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_EventArguments_SessionEventArgsBase_Exception.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception%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>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L146">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L151">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception*"></a> <a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception*"></a>
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception">Exception</h4> <h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception">Exception</h4>
...@@ -478,6 +478,37 @@ public IPEndPoint ClientEndPoint { get; }</code></pre> ...@@ -478,6 +478,37 @@ public IPEndPoint ClientEndPoint { get; }</code></pre>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<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_EventArguments_SessionEventArgsBase_IsSocks.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks%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/EventArguments/SessionEventArgsBase.cs/#L146">View Source</a>
</span>
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks*"></a>
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks">IsSocks</h4>
<div class="markdown level1 summary"><p>Is this a SOCKS endpoint?</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public bool IsSocks { get; }</code></pre>
</div>
<h5 class="propertyValue">Property Value</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="xref" href="https://docs.microsoft.com/dotnet/api/system.boolean">Boolean</a></td>
<td></td>
</tr>
</tbody>
</table>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<span class="divider">|</span> <span class="divider">|</span>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsTransparent%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_EventArguments_SessionEventArgsBase_IsTransparent.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsTransparent%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>
...@@ -702,7 +733,7 @@ public HttpWebClient WebSession { get; }</code></pre> ...@@ -702,7 +733,7 @@ public HttpWebClient WebSession { get; }</code></pre>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose%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_EventArguments_SessionEventArgsBase_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose%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>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L151">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L156">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose*"></a> <a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose*"></a>
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose">Dispose()</h4> <h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose">Dispose()</h4>
...@@ -718,7 +749,7 @@ public HttpWebClient WebSession { get; }</code></pre> ...@@ -718,7 +749,7 @@ public HttpWebClient WebSession { get; }</code></pre>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession%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_EventArguments_SessionEventArgsBase_TerminateSession.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession%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>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L199">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L204">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession*"></a> <a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession*"></a>
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession">TerminateSession()</h4> <h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession">TerminateSession()</h4>
...@@ -736,7 +767,7 @@ public HttpWebClient WebSession { get; }</code></pre> ...@@ -736,7 +767,7 @@ public HttpWebClient WebSession { get; }</code></pre>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataReceived.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataReceived%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_EventArguments_SessionEventArgsBase_DataReceived.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataReceived%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>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L170">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L175">View Source</a>
</span> </span>
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataReceived" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataReceived">DataReceived</h4> <h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataReceived" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataReceived">DataReceived</h4>
<div class="markdown level1 summary"><p>Fired when data is received within this session from client/server.</p> <div class="markdown level1 summary"><p>Fired when data is received within this session from client/server.</p>
...@@ -766,7 +797,7 @@ public HttpWebClient WebSession { get; }</code></pre> ...@@ -766,7 +797,7 @@ public HttpWebClient WebSession { get; }</code></pre>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataSent.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataSent%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_EventArguments_SessionEventArgsBase_DataSent.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataSent%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>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L165">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L170">View Source</a>
</span> </span>
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataSent" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataSent">DataSent</h4> <h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataSent" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataSent">DataSent</h4>
<div class="markdown level1 summary"><p>Fired when data is sent within this session to server/client.</p> <div class="markdown level1 summary"><p>Fired when data is sent within this session to server/client.</p>
......
...@@ -152,6 +152,9 @@ ...@@ -152,6 +152,9 @@
<div> <div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a> <a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a>
</div> </div>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks">SessionEventArgsBase.IsSocks</a>
</div>
<div> <div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a> <a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a>
</div> </div>
......
...@@ -108,6 +108,10 @@ ...@@ -108,6 +108,10 @@
Default.</p> Default.</p>
</td> </td>
</tr> </tr>
<tr>
<td id="Titanium_Web_Proxy_Network_CertificateEngine_BouncyCastleFast">BouncyCastleFast</td>
<td></td>
</tr>
<tr> <tr>
<td id="Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows">DefaultWindows</td> <td id="Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows">DefaultWindows</td>
<td><p>Uses Windows Certification Generation API and only valid in Windows OS. <td><p>Uses Windows Certification Generation API and only valid in Windows OS.
......
This diff is collapsed.
...@@ -732,6 +732,19 @@ references: ...@@ -732,6 +732,19 @@ references:
isSpec: "True" isSpec: "True"
fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsHttps fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsHttps
nameWithType: SessionEventArgsBase.IsHttps nameWithType: SessionEventArgsBase.IsHttps
- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
name: IsSocks
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks
commentId: P:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
nameWithType: SessionEventArgsBase.IsSocks
- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks*
name: IsSocks
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks_
commentId: Overload:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
isSpec: "True"
fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
nameWithType: SessionEventArgsBase.IsSocks
- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsTransparent - uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsTransparent
name: IsTransparent name: IsTransparent
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent
...@@ -2900,6 +2913,12 @@ references: ...@@ -2900,6 +2913,12 @@ references:
commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle
fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle
nameWithType: CertificateEngine.BouncyCastle nameWithType: CertificateEngine.BouncyCastle
- uid: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
name: BouncyCastleFast
href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_BouncyCastleFast
commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
nameWithType: CertificateEngine.BouncyCastleFast
- uid: Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows - uid: Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows
name: DefaultWindows name: DefaultWindows
href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows
......
...@@ -44,6 +44,10 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -44,6 +44,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
}; };
proxyServer.ForwardToUpstreamGateway = true; proxyServer.ForwardToUpstreamGateway = true;
proxyServer.CertificateManager.SaveFakeCertificates = true; proxyServer.CertificateManager.SaveFakeCertificates = true;
//proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) =>
//{
// return true;
//};
// this is just to show the functionality, provided implementations use junk value // this is just to show the functionality, provided implementations use junk value
//proxyServer.GetCustomUpStreamProxyFunc = onGetCustomUpStreamProxyFunc; //proxyServer.GetCustomUpStreamProxyFunc = onGetCustomUpStreamProxyFunc;
...@@ -94,8 +98,11 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -94,8 +98,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("localhost", 8888); //proxyServer.UpStreamHttpsProxy = new ExternalProxy("localhost", 8888);
// SOCKS proxy // SOCKS proxy
//proxyServer.UpStreamHttpProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 }; //proxyServer.UpStreamHttpProxy = new ExternalProxy("127.0.0.1", 1080)
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 }; // { ProxyType = ExternalProxyType.Socks5, UserName = "User1", Password = "Pass" };
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("127.0.0.1", 1080)
// { ProxyType = ExternalProxyType.Socks5, UserName = "User1", Password = "Pass" };
//var socksEndPoint = new SocksProxyEndPoint(IPAddress.Any, 1080, true) //var socksEndPoint = new SocksProxyEndPoint(IPAddress.Any, 1080, true)
//{ //{
...@@ -167,6 +174,12 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -167,6 +174,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectRequest) + ":" + hostname); e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectRequest) + ":" + hostname);
await writeToConsole("Tunnel to: " + hostname); await writeToConsole("Tunnel to: " + hostname);
var clientLocalIp = e.ClientLocalEndPoint.Address;
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
{
e.HttpClient.UpStreamEndPoint = new IPEndPoint(clientLocalIp, 0);
}
if (hostname.Contains("dropbox.com")) if (hostname.Contains("dropbox.com"))
{ {
// Exclude Https addresses you don't want to proxy // Exclude Https addresses you don't want to proxy
...@@ -212,7 +225,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -212,7 +225,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
{ {
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri); e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);
return Task.FromResult(false); return Task.CompletedTask;
} }
// intercept & cancel redirect or update requests // intercept & cancel redirect or update requests
...@@ -356,7 +369,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -356,7 +369,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
e.IsValid = true; e.IsValid = true;
} }
return Task.FromResult(0); return Task.CompletedTask;
} }
/// <summary> /// <summary>
...@@ -370,7 +383,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -370,7 +383,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
// set e.clientCertificate to override // set e.clientCertificate to override
return Task.FromResult(0); return Task.CompletedTask;
} }
private async Task writeToConsole(string message, ConsoleColor? consoleColor = null) private async Task writeToConsole(string message, ConsoleColor? consoleColor = null)
......
...@@ -21,7 +21,7 @@ namespace WindowsServiceExample ...@@ -21,7 +21,7 @@ namespace WindowsServiceExample
{ {
// we do all this in here so we can reload settings with a simple restart // we do all this in here so we can reload settings with a simple restart
_proxyServerInstance = new ProxyServer(); _proxyServerInstance = new ProxyServer(false);
if (Properties.Settings.Default.ListeningPort <= 0 || if (Properties.Settings.Default.ListeningPort <= 0 ||
Properties.Settings.Default.ListeningPort > 65535) Properties.Settings.Default.ListeningPort > 65535)
......
...@@ -53,7 +53,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -53,7 +53,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
BufferPool = server.BufferPool; BufferPool = server.BufferPool;
ExceptionFunc = server.ExceptionFunc; ExceptionFunc = server.ExceptionFunc;
TimeLine["Session Created"] = DateTime.Now; TimeLine["Session Created"] = DateTime.UtcNow;
CancellationTokenSource = cancellationTokenSource; CancellationTokenSource = cancellationTokenSource;
...@@ -140,6 +140,11 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -140,6 +140,11 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary> /// </summary>
public bool IsTransparent => ProxyEndPoint is TransparentProxyEndPoint; public bool IsTransparent => ProxyEndPoint is TransparentProxyEndPoint;
/// <summary>
/// Is this a SOCKS endpoint?
/// </summary>
public bool IsSocks => ProxyEndPoint is SocksProxyEndPoint;
/// <summary> /// <summary>
/// The last exception that happened. /// The last exception that happened.
/// </summary> /// </summary>
......
...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy.Http
/// <param name="serverConnection">Instance of <see cref="TcpServerConnection" /></param> /// <param name="serverConnection">Instance of <see cref="TcpServerConnection" /></param>
internal void SetConnection(TcpServerConnection serverConnection) internal void SetConnection(TcpServerConnection serverConnection)
{ {
serverConnection.LastAccess = DateTime.Now; serverConnection.LastAccess = DateTime.UtcNow;
connection = serverConnection; connection = serverConnection;
} }
......
...@@ -44,7 +44,6 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -44,7 +44,6 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// Makes the certificate. /// Makes the certificate.
/// </summary> /// </summary>
/// <param name="sSubjectCn">The s subject cn.</param> /// <param name="sSubjectCn">The s subject cn.</param>
/// <param name="isRoot">if set to <c>true</c> [is root].</param>
/// <param name="signingCert">The signing cert.</param> /// <param name="signingCert">The signing cert.</param>
/// <returns>X509Certificate2 instance.</returns> /// <returns>X509Certificate2 instance.</returns>
public X509Certificate2 MakeCertificate(string sSubjectCn, X509Certificate2? signingCert = null) public X509Certificate2 MakeCertificate(string sSubjectCn, X509Certificate2? signingCert = null)
......
...@@ -105,7 +105,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -105,7 +105,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
// KeyLength // KeyLength
const int keyLength = 2048; const int keyLength = 2048;
var now = DateTime.Now; var now = DateTime.UtcNow;
var graceTime = now.AddDays(graceDays); var graceTime = now.AddDays(graceDays);
var certificate = makeCertificate(sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime, var certificate = makeCertificate(sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
now.AddDays(validDays), signingCertificate); now.AddDays(validDays), signingCertificate);
......
...@@ -24,6 +24,8 @@ namespace Titanium.Web.Proxy.Network ...@@ -24,6 +24,8 @@ namespace Titanium.Web.Proxy.Network
/// </summary> /// </summary>
BouncyCastle = 0, BouncyCastle = 0,
BouncyCastleFast = 2,
/// <summary> /// <summary>
/// Uses Windows Certification Generation API and only valid in Windows OS. /// Uses Windows Certification Generation API and only valid in Windows OS.
/// Observed to be faster than BouncyCastle. /// Observed to be faster than BouncyCastle.
...@@ -68,9 +70,19 @@ namespace Titanium.Web.Proxy.Network ...@@ -68,9 +70,19 @@ namespace Titanium.Web.Proxy.Network
{ {
if (certEngineValue == null) if (certEngineValue == null)
{ {
certEngineValue = engine == CertificateEngine.BouncyCastle switch (engine)
? (ICertificateMaker)new BCCertificateMaker(ExceptionFunc) {
: new WinCertificateMaker(ExceptionFunc); case CertificateEngine.BouncyCastle:
certEngineValue = new BCCertificateMaker(ExceptionFunc);
break;
case CertificateEngine.BouncyCastleFast:
certEngineValue = new BCCertificateMakerFast(ExceptionFunc);
break;
case CertificateEngine.DefaultWindows:
default:
certEngineValue = new WinCertificateMaker(ExceptionFunc);
break;
}
} }
return certEngineValue; return certEngineValue;
...@@ -459,7 +471,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -459,7 +471,7 @@ namespace Titanium.Web.Proxy.Network
// check in cache first // check in cache first
if (cachedCertificates.TryGetValue(certificateName, out var cached)) if (cachedCertificates.TryGetValue(certificateName, out var cached))
{ {
cached.LastAccess = DateTime.Now; cached.LastAccess = DateTime.UtcNow;
return cached.Certificate; return cached.Certificate;
} }
...@@ -498,7 +510,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -498,7 +510,7 @@ namespace Titanium.Web.Proxy.Network
var cancellationToken = clearCertificatesTokenSource.Token; var cancellationToken = clearCertificatesTokenSource.Token;
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested)
{ {
var cutOff = DateTime.Now.AddMinutes(-CertificateCacheTimeOutMinutes); var cutOff = DateTime.UtcNow.AddMinutes(-CertificateCacheTimeOutMinutes);
var outdated = cachedCertificates.Where(x => x.Value.LastAccess < cutOff).ToList(); var outdated = cachedCertificates.Where(x => x.Value.LastAccess < cutOff).ToList();
......
...@@ -241,7 +241,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -241,7 +241,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
if (cache.TryGetValue(cacheKey, out var existingConnections)) if (cache.TryGetValue(cacheKey, out var existingConnections))
{ {
// +3 seconds for potential delay after getting connection // +3 seconds for potential delay after getting connection
var cutOff = DateTime.Now.AddSeconds(-proxyServer.ConnectionTimeOutSeconds + 3); var cutOff = DateTime.UtcNow.AddSeconds(-proxyServer.ConnectionTimeOutSeconds + 3);
while (existingConnections.Count > 0) while (existingConnections.Count > 0)
{ {
if (existingConnections.TryDequeue(out var recentConnection)) if (existingConnections.TryDequeue(out var recentConnection))
...@@ -350,7 +350,7 @@ retry: ...@@ -350,7 +350,7 @@ retry:
if (sessionArgs != null) if (sessionArgs != null)
{ {
sessionArgs.TimeLine["Dns Resolved"] = DateTime.Now; sessionArgs.TimeLine["Dns Resolved"] = DateTime.UtcNow;
} }
Array.Sort(ipAddresses, (x, y) => x.AddressFamily.CompareTo(y.AddressFamily)); Array.Sort(ipAddresses, (x, y) => x.AddressFamily.CompareTo(y.AddressFamily));
...@@ -458,7 +458,7 @@ retry: ...@@ -458,7 +458,7 @@ retry:
if (newUpstreamProxy != null) if (newUpstreamProxy != null)
{ {
sessionArgs.CustomUpStreamProxyUsed = newUpstreamProxy; sessionArgs.CustomUpStreamProxyUsed = newUpstreamProxy;
sessionArgs.TimeLine["Retrying Upstream Proxy Connection"] = DateTime.Now; sessionArgs.TimeLine["Retrying Upstream Proxy Connection"] = DateTime.UtcNow;
return await createServerConnection(remoteHostName, remotePort, httpVersion, isHttps, sslProtocol, applicationProtocols, isConnect, proxyServer, sessionArgs, upStreamEndPoint, externalProxy, cacheKey, cancellationToken); return await createServerConnection(remoteHostName, remotePort, httpVersion, isHttps, sslProtocol, applicationProtocols, isConnect, proxyServer, sessionArgs, upStreamEndPoint, externalProxy, cacheKey, cancellationToken);
} }
} }
...@@ -468,7 +468,7 @@ retry: ...@@ -468,7 +468,7 @@ retry:
if (sessionArgs != null) if (sessionArgs != null)
{ {
sessionArgs.TimeLine["Connection Established"] = DateTime.Now; sessionArgs.TimeLine["Connection Established"] = DateTime.UtcNow;
} }
await proxyServer.InvokeServerConnectionCreateEvent(tcpServerSocket); await proxyServer.InvokeServerConnectionCreateEvent(tcpServerSocket);
...@@ -532,7 +532,7 @@ retry: ...@@ -532,7 +532,7 @@ retry:
if (sessionArgs != null) if (sessionArgs != null)
{ {
sessionArgs.TimeLine["HTTPS Established"] = DateTime.Now; sessionArgs.TimeLine["HTTPS Established"] = DateTime.UtcNow;
} }
} }
} }
...@@ -570,7 +570,7 @@ retry: ...@@ -570,7 +570,7 @@ retry:
return; return;
} }
connection.LastAccess = DateTime.Now; connection.LastAccess = DateTime.UtcNow;
try try
{ {
...@@ -634,7 +634,7 @@ retry: ...@@ -634,7 +634,7 @@ retry:
{ {
try try
{ {
var cutOff = DateTime.Now.AddSeconds(-Server.ConnectionTimeOutSeconds); var cutOff = DateTime.UtcNow.AddSeconds(-Server.ConnectionTimeOutSeconds);
foreach (var item in cache) foreach (var item in cache)
{ {
var queue = item.Value; var queue = item.Value;
......
...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
Version version, IExternalProxy? upStreamProxy, IPEndPoint? upStreamEndPoint, string cacheKey) Version version, IExternalProxy? upStreamProxy, IPEndPoint? upStreamEndPoint, string cacheKey)
{ {
TcpSocket = tcpSocket; TcpSocket = tcpSocket;
LastAccess = DateTime.Now; LastAccess = DateTime.UtcNow;
this.proxyServer = proxyServer; this.proxyServer = proxyServer;
this.proxyServer.UpdateServerConnectionCount(true); this.proxyServer.UpdateServerConnectionCount(true);
Stream = stream; Stream = stream;
......
...@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security ...@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
Credentials = new Common.SecurityHandle(0); Credentials = new Common.SecurityHandle(0);
Context = new Common.SecurityHandle(0); Context = new Common.SecurityHandle(0);
LastSeen = DateTime.Now; LastSeen = DateTime.UtcNow;
AuthState = WinAuthState.UNAUTHORIZED; AuthState = WinAuthState.UNAUTHORIZED;
} }
...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security ...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
internal void UpdatePresence() internal void UpdatePresence()
{ {
LastSeen = DateTime.Now; LastSeen = DateTime.UtcNow;
} }
} }
} }
...@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy ...@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy
request.Method = requestLine.Method; request.Method = requestLine.Method;
request.HttpVersion = requestLine.Version; request.HttpVersion = requestLine.Version;
if (!args.IsTransparent) if (!args.IsTransparent && !args.IsSocks)
{ {
// proxy authorization check // proxy authorization check
if (connectRequest == null && await checkAuthorization(args) == false) if (connectRequest == null && await checkAuthorization(args) == false)
...@@ -279,7 +279,7 @@ namespace Titanium.Web.Proxy ...@@ -279,7 +279,7 @@ namespace Titanium.Web.Proxy
// set the connection and send request headers // set the connection and send request headers
args.HttpClient.SetConnection(connection); args.HttpClient.SetConnection(connection);
args.TimeLine["Connection Ready"] = DateTime.Now; args.TimeLine["Connection Ready"] = DateTime.UtcNow;
if (args.HttpClient.Request.UpgradeToWebSocket) if (args.HttpClient.Request.UpgradeToWebSocket)
{ {
...@@ -335,7 +335,7 @@ namespace Titanium.Web.Proxy ...@@ -335,7 +335,7 @@ namespace Titanium.Web.Proxy
} }
} }
args.TimeLine["Request Sent"] = DateTime.Now; args.TimeLine["Request Sent"] = DateTime.UtcNow;
// parse and send response // parse and send response
await handleHttpSessionResponse(args); await handleHttpSessionResponse(args);
...@@ -374,7 +374,7 @@ namespace Titanium.Web.Proxy ...@@ -374,7 +374,7 @@ namespace Titanium.Web.Proxy
/// <returns></returns> /// <returns></returns>
private async Task onBeforeRequest(SessionEventArgs args) private async Task onBeforeRequest(SessionEventArgs args)
{ {
args.TimeLine["Request Received"] = DateTime.Now; args.TimeLine["Request Received"] = DateTime.UtcNow;
if (BeforeRequest != null) if (BeforeRequest != null)
{ {
......
...@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy ...@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy
await args.HttpClient.ReceiveResponse(cancellationToken); await args.HttpClient.ReceiveResponse(cancellationToken);
} }
args.TimeLine["Response Received"] = DateTime.Now; args.TimeLine["Response Received"] = DateTime.UtcNow;
var response = args.HttpClient.Response; var response = args.HttpClient.Response;
args.ReRequest = false; args.ReRequest = false;
...@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy ...@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
response.Locked = true; response.Locked = true;
if (!args.IsTransparent) if (!args.IsTransparent && !args.IsSocks)
{ {
response.Headers.FixProxyHeaders(); response.Headers.FixProxyHeaders();
} }
...@@ -122,7 +122,7 @@ namespace Titanium.Web.Proxy ...@@ -122,7 +122,7 @@ namespace Titanium.Web.Proxy
} }
} }
args.TimeLine["Response Sent"] = DateTime.Now; args.TimeLine["Response Sent"] = DateTime.UtcNow;
} }
/// <summary> /// <summary>
......
using System; using System;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Extensions;
...@@ -48,13 +49,76 @@ namespace Titanium.Web.Proxy ...@@ -48,13 +49,76 @@ namespace Titanium.Web.Proxy
} }
else if (buffer[0] == 5) else if (buffer[0] == 5)
{ {
if (buffer[1] == 0 || buffer[2] != 0) int authenticationMethodCount = buffer[1];
if (read < authenticationMethodCount + 2)
{ {
return; return;
} }
buffer[1] = 0; int acceptedMethod = 255;
for (int i = 0; i < authenticationMethodCount; i++)
{
int method = buffer[i + 2];
if (method == 0 && ProxyBasicAuthenticateFunc == null)
{
acceptedMethod = 0;
break;
}
if (method == 2)
{
acceptedMethod = 2;
break;
}
}
buffer[1] = (byte)acceptedMethod;
await stream.WriteAsync(buffer, 0, 2, cancellationToken); await stream.WriteAsync(buffer, 0, 2, cancellationToken);
if (acceptedMethod == 255)
{
// no acceptable method
return;
}
if (acceptedMethod == 2)
{
read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
if (read < 3 || buffer[0] != 1)
{
// authentication version should be 1
return;
}
int userNameLength = buffer[1];
if (read < 3 + userNameLength)
{
return;
}
string userName = Encoding.ASCII.GetString(buffer, 2, userNameLength);
int passwordLength = buffer[2 + userNameLength];
if (read < 3 + userNameLength + passwordLength)
{
return;
}
string password = Encoding.ASCII.GetString(buffer, 3 + userNameLength, passwordLength);
bool success = true;
if (ProxySchemeAuthenticateFunc != null)
{
success = await ProxyBasicAuthenticateFunc.Invoke(null, userName, password);
}
buffer[1] = success ? (byte)0 : (byte)1;
await stream.WriteAsync(buffer, 0, 2, cancellationToken);
if (!success)
{
return;
}
}
read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken); read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
if (read < 10 || buffer[1] != 1) if (read < 10 || buffer[1] != 1)
{ {
......
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