Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #720 from justcoding121/master
Browse files Browse the repository at this point in the history
beta
  • Loading branch information
honfika authored Dec 26, 2019
2 parents bc6e381 + 11fdeac commit 500cead
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a>
</div>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks">SessionEventArgsBase.IsSocks</a>
</div>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ <h5 class="propertyValue">Property Value</h5>
<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 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>
<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>
Expand Down Expand Up @@ -478,6 +478,37 @@ <h5 class="propertyValue">Property Value</h5>
</tr>
</tbody>
</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="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>
Expand Down Expand Up @@ -702,7 +733,7 @@ <h3 id="methods">Methods
<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 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>
<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>
Expand All @@ -718,7 +749,7 @@ <h5 class="decalaration">Declaration</h5>
<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 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>
<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>
Expand All @@ -736,7 +767,7 @@ <h3 id="events">Events
<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 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>
<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>
Expand Down Expand Up @@ -766,7 +797,7 @@ <h5 class="eventType">Event Type</h5>
<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 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>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a>
</div>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks">SessionEventArgsBase.IsSocks</a>
</div>
<div>
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a>
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions docs/xrefmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,19 @@ references:
isSpec: "True"
fullName: Titanium.Web.Proxy.EventArguments.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
name: IsTransparent
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent
Expand Down
5 changes: 5 additions & 0 deletions src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public bool EnableWinAuth
/// </summary>
public bool IsTransparent => ProxyEndPoint is TransparentProxyEndPoint;

/// <summary>
/// Is this a SOCKS endpoint?
/// </summary>
public bool IsSocks => ProxyEndPoint is SocksProxyEndPoint;

/// <summary>
/// The last exception that happened.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ await HeaderParser.ReadHeaders(clientStream, args.HttpClient.Request.Headers,
request.Method = requestLine.Method;
request.HttpVersion = requestLine.Version;

if (!args.IsTransparent)
if (!args.IsTransparent && !args.IsSocks)
{
// proxy authorization check
if (connectRequest == null && await checkAuthorization(args) == false)
Expand Down
2 changes: 1 addition & 1 deletion src/Titanium.Web.Proxy/ResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ await handleHttpSessionRequest(args, null, args.ClientConnection.NegotiatedAppli

response.Locked = true;

if (!args.IsTransparent)
if (!args.IsTransparent && !args.IsSocks)
{
response.Headers.FixProxyHeaders();
}
Expand Down
68 changes: 66 additions & 2 deletions src/Titanium.Web.Proxy/SocksClientHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Titanium.Web.Proxy.Extensions;
Expand Down Expand Up @@ -48,13 +49,76 @@ private async Task handleClient(SocksProxyEndPoint endPoint, TcpClientConnection
}
else if (buffer[0] == 5)
{
if (buffer[1] == 0 || buffer[2] != 0)
int authenticationMethodCount = buffer[1];
if (read < authenticationMethodCount + 2)
{
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);

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);
if (read < 10 || buffer[1] != 1)
{
Expand Down

0 comments on commit 500cead

Please sign in to comment.