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

Commit 500cead

Browse files
authored
Merge pull request #720 from justcoding121/master
beta
2 parents bc6e381 + 11fdeac commit 500cead

9 files changed

+131
-12
lines changed

docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ <h5>Inherited Members</h5>
155155
<div>
156156
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a>
157157
</div>
158+
<div>
159+
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks">SessionEventArgsBase.IsSocks</a>
160+
</div>
158161
<div>
159162
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a>
160163
</div>

docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ <h5 class="propertyValue">Property Value</h5>
390390
<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>
391391
</span>
392392
<span class="small pull-right mobile-hide">
393-
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L146">View Source</a>
393+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L151">View Source</a>
394394
</span>
395395
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception*"></a>
396396
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception">Exception</h4>
@@ -478,6 +478,37 @@ <h5 class="propertyValue">Property Value</h5>
478478
</tr>
479479
</tbody>
480480
</table>
481+
<span class="small pull-right mobile-hide">
482+
<span class="divider">|</span>
483+
<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>
484+
</span>
485+
<span class="small pull-right mobile-hide">
486+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L146">View Source</a>
487+
</span>
488+
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks*"></a>
489+
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks">IsSocks</h4>
490+
<div class="markdown level1 summary"><p>Is this a SOCKS endpoint?</p>
491+
</div>
492+
<div class="markdown level1 conceptual"></div>
493+
<h5 class="decalaration">Declaration</h5>
494+
<div class="codewrapper">
495+
<pre><code class="lang-csharp hljs">public bool IsSocks { get; }</code></pre>
496+
</div>
497+
<h5 class="propertyValue">Property Value</h5>
498+
<table class="table table-bordered table-striped table-condensed">
499+
<thead>
500+
<tr>
501+
<th>Type</th>
502+
<th>Description</th>
503+
</tr>
504+
</thead>
505+
<tbody>
506+
<tr>
507+
<td><a class="xref" href="https://docs.microsoft.com/dotnet/api/system.boolean">Boolean</a></td>
508+
<td></td>
509+
</tr>
510+
</tbody>
511+
</table>
481512
<span class="small pull-right mobile-hide">
482513
<span class="divider">|</span>
483514
<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 @@ <h3 id="methods">Methods
702733
<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>
703734
</span>
704735
<span class="small pull-right mobile-hide">
705-
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L151">View Source</a>
736+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L156">View Source</a>
706737
</span>
707738
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose*"></a>
708739
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Dispose" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Dispose">Dispose()</h4>
@@ -718,7 +749,7 @@ <h5 class="decalaration">Declaration</h5>
718749
<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>
719750
</span>
720751
<span class="small pull-right mobile-hide">
721-
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L199">View Source</a>
752+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L204">View Source</a>
722753
</span>
723754
<a id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession_" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession*"></a>
724755
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_TerminateSession" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.TerminateSession">TerminateSession()</h4>
@@ -736,7 +767,7 @@ <h3 id="events">Events
736767
<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>
737768
</span>
738769
<span class="small pull-right mobile-hide">
739-
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L170">View Source</a>
770+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L175">View Source</a>
740771
</span>
741772
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataReceived" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataReceived">DataReceived</h4>
742773
<div class="markdown level1 summary"><p>Fired when data is received within this session from client/server.</p>
@@ -766,7 +797,7 @@ <h5 class="eventType">Event Type</h5>
766797
<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>
767798
</span>
768799
<span class="small pull-right mobile-hide">
769-
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L165">View Source</a>
800+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs/#L170">View Source</a>
770801
</span>
771802
<h4 id="Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_DataSent" data-uid="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.DataSent">DataSent</h4>
772803
<div class="markdown level1 summary"><p>Fired when data is sent within this session to server/client.</p>

docs/api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ <h5>Inherited Members</h5>
152152
<div>
153153
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent">SessionEventArgsBase.IsTransparent</a>
154154
</div>
155+
<div>
156+
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks">SessionEventArgsBase.IsSocks</a>
157+
</div>
155158
<div>
156159
<a class="xref" href="Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_Exception">SessionEventArgsBase.Exception</a>
157160
</div>

docs/index.json

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/xrefmap.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,19 @@ references:
732732
isSpec: "True"
733733
fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsHttps
734734
nameWithType: SessionEventArgsBase.IsHttps
735+
- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
736+
name: IsSocks
737+
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks
738+
commentId: P:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
739+
fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
740+
nameWithType: SessionEventArgsBase.IsSocks
741+
- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks*
742+
name: IsSocks
743+
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsSocks_
744+
commentId: Overload:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
745+
isSpec: "True"
746+
fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsSocks
747+
nameWithType: SessionEventArgsBase.IsSocks
735748
- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.IsTransparent
736749
name: IsTransparent
737750
href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_IsTransparent

src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public bool EnableWinAuth
140140
/// </summary>
141141
public bool IsTransparent => ProxyEndPoint is TransparentProxyEndPoint;
142142

143+
/// <summary>
144+
/// Is this a SOCKS endpoint?
145+
/// </summary>
146+
public bool IsSocks => ProxyEndPoint is SocksProxyEndPoint;
147+
143148
/// <summary>
144149
/// The last exception that happened.
145150
/// </summary>

src/Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ await HeaderParser.ReadHeaders(clientStream, args.HttpClient.Request.Headers,
9090
request.Method = requestLine.Method;
9191
request.HttpVersion = requestLine.Version;
9292

93-
if (!args.IsTransparent)
93+
if (!args.IsTransparent && !args.IsSocks)
9494
{
9595
// proxy authorization check
9696
if (connectRequest == null && await checkAuthorization(args) == false)

src/Titanium.Web.Proxy/ResponseHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ await handleHttpSessionRequest(args, null, args.ClientConnection.NegotiatedAppli
9999

100100
response.Locked = true;
101101

102-
if (!args.IsTransparent)
102+
if (!args.IsTransparent && !args.IsSocks)
103103
{
104104
response.Headers.FixProxyHeaders();
105105
}

src/Titanium.Web.Proxy/SocksClientHandler.cs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Text;
23
using System.Threading;
34
using System.Threading.Tasks;
45
using Titanium.Web.Proxy.Extensions;
@@ -48,13 +49,76 @@ private async Task handleClient(SocksProxyEndPoint endPoint, TcpClientConnection
4849
}
4950
else if (buffer[0] == 5)
5051
{
51-
if (buffer[1] == 0 || buffer[2] != 0)
52+
int authenticationMethodCount = buffer[1];
53+
if (read < authenticationMethodCount + 2)
5254
{
5355
return;
5456
}
5557

56-
buffer[1] = 0;
58+
int acceptedMethod = 255;
59+
for (int i = 0; i < authenticationMethodCount; i++)
60+
{
61+
int method = buffer[i + 2];
62+
if (method == 0 && ProxyBasicAuthenticateFunc == null)
63+
{
64+
acceptedMethod = 0;
65+
break;
66+
}
67+
68+
if (method == 2)
69+
{
70+
acceptedMethod = 2;
71+
break;
72+
}
73+
}
74+
75+
buffer[1] = (byte)acceptedMethod;
5776
await stream.WriteAsync(buffer, 0, 2, cancellationToken);
77+
78+
if (acceptedMethod == 255)
79+
{
80+
// no acceptable method
81+
return;
82+
}
83+
84+
if (acceptedMethod == 2)
85+
{
86+
read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
87+
if (read < 3 || buffer[0] != 1)
88+
{
89+
// authentication version should be 1
90+
return;
91+
}
92+
93+
int userNameLength = buffer[1];
94+
if (read < 3 + userNameLength)
95+
{
96+
return;
97+
}
98+
99+
string userName = Encoding.ASCII.GetString(buffer, 2, userNameLength);
100+
101+
int passwordLength = buffer[2 + userNameLength];
102+
if (read < 3 + userNameLength + passwordLength)
103+
{
104+
return;
105+
}
106+
107+
string password = Encoding.ASCII.GetString(buffer, 3 + userNameLength, passwordLength);
108+
bool success = true;
109+
if (ProxySchemeAuthenticateFunc != null)
110+
{
111+
success = await ProxyBasicAuthenticateFunc.Invoke(null, userName, password);
112+
}
113+
114+
buffer[1] = success ? (byte)0 : (byte)1;
115+
await stream.WriteAsync(buffer, 0, 2, cancellationToken);
116+
if (!success)
117+
{
118+
return;
119+
}
120+
}
121+
58122
read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
59123
if (read < 10 || buffer[1] != 1)
60124
{

0 commit comments

Comments
 (0)