@@ -145,6 +145,23 @@ public static async Task PerformSocks5HandshakeAsync(Stream stream, EndPoint end
145
145
}
146
146
}
147
147
148
+ private static void CreateGreetingRequest ( byte [ ] buffer , bool useAuth )
149
+ {
150
+ buffer [ 0 ] = ProtocolVersion5 ;
151
+
152
+ if ( ! useAuth )
153
+ {
154
+ buffer [ 1 ] = 1 ;
155
+ buffer [ 2 ] = MethodNoAuth ;
156
+ }
157
+ else
158
+ {
159
+ buffer [ 1 ] = 2 ;
160
+ buffer [ 2 ] = MethodNoAuth ;
161
+ buffer [ 3 ] = MethodUsernamePassword ;
162
+ }
163
+ }
164
+
148
165
private static void ReadGreetingResponse ( Stream stream , byte [ ] buffer , bool useAuth , Socks5AuthenticationSettings authenticationSettings , CancellationToken cancellationToken )
149
166
{
150
167
stream . ReadBytes ( buffer , 0 , 2 , cancellationToken ) ;
@@ -270,7 +287,11 @@ private static int CreateConnectRequest(byte[] buffer, string targetHost, int ta
270
287
private static int ReadConnectResponse ( byte [ ] buffer , CancellationToken cancellationToken )
271
288
{
272
289
VerifyProtocolVersion ( buffer [ 0 ] ) ;
273
- VerifySockSuccess ( buffer [ 1 ] ) ;
290
+
291
+ if ( buffer [ 1 ] != Socks5Success )
292
+ {
293
+ throw new IOException ( $ "SOCKS5 connect failed") ;
294
+ }
274
295
275
296
return buffer [ 3 ] switch
276
297
{
@@ -281,23 +302,6 @@ private static int ReadConnectResponse(byte[] buffer, CancellationToken cancella
281
302
} ;
282
303
}
283
304
284
- private static void CreateGreetingRequest ( byte [ ] buffer , bool useAuth )
285
- {
286
- buffer [ 0 ] = ProtocolVersion5 ;
287
-
288
- if ( ! useAuth )
289
- {
290
- buffer [ 1 ] = 1 ;
291
- buffer [ 2 ] = MethodNoAuth ;
292
- }
293
- else
294
- {
295
- buffer [ 1 ] = 2 ;
296
- buffer [ 2 ] = MethodNoAuth ;
297
- buffer [ 3 ] = MethodUsernamePassword ;
298
- }
299
- }
300
-
301
305
private static void VerifyProtocolVersion ( byte version )
302
306
{
303
307
if ( version != ProtocolVersion5 )
@@ -306,14 +310,6 @@ private static void VerifyProtocolVersion(byte version)
306
310
}
307
311
}
308
312
309
- private static void VerifySockSuccess ( byte value ) //TODO Need to check this
310
- {
311
- if ( value != Socks5Success )
312
- {
313
- throw new IOException ( $ "SOCKS5 connect failed") ;
314
- }
315
- }
316
-
317
313
private static byte EncodeString ( string input , byte [ ] buffer , int offset , string parameterName )
318
314
{
319
315
try
0 commit comments