Пример #1
0
        // Socks5 method
        protected override async Task <bool> HandshakeAsync(NetworkStream browser, NetworkStream server)
        {
            byte[] buffer = new byte[BUFFER_SIZE];

            // From browser
            int readedSize = await browser.ReadAsync(buffer, 0, buffer.Length);

            RequestHandshake reqHand = new RequestHandshake(buffer, readedSize, BaseConstants.Methods.NO_AUTHENTICATION_REQUIRED);

            Console.WriteLine($"Read request handshake from client: {reqHand.ToString()}");

            // Socks5 Handshake with server
            await this.Socks5HandshakeAsync(server);

            // Socks5 Authentication with server
            if (await _authentication.RunAsync(server))
            {
                // To browser
                ReplyHandshake repHand = new ReplyHandshake(BaseConstants.Versions.SOCKS5,
                                                            BaseConstants.Methods.NO_AUTHENTICATION_REQUIRED);
                buffer = repHand.GenBuff();
                await browser.WriteAsync(buffer, 0, buffer.Length);

                Console.WriteLine($"Write reply to client: {repHand}");
                return(true);
            }
            return(false);
        }
 internal TcpListenerWebSocketContext(TcpClient client, bool secure)
 {
     _client   = client;
       _isSecure = secure;
       _stream   = WsStream.CreateServerStream(client, secure);
       _request  = RequestHandshake.Parse(_stream.ReadHandshake());
       _socket   = new WebSocket(this);
 }
Пример #3
0
 internal TcpListenerWebSocketContext(TcpClient client, bool secure)
 {
     _client   = client;
     _isSecure = secure;
     _stream   = WsStream.CreateServerStream(client, secure);
     _request  = RequestHandshake.Parse(_stream.ReadHandshake());
     _socket   = new WebSocket(this);
 }
Пример #4
0
        private async Task Socks5HandshakeAsync(NetworkStream server)
        {
            RequestHandshake reqHand = _handshakeCreator.Create();

            byte[] buffer = reqHand.GenBuff();
            await server.WriteAsync(buffer, 0, buffer.Length);

            Console.WriteLine($"Write new request handshake to server: {reqHand}");

            int readedLength = await server.ReadAsync(buffer, 0, buffer.Length);

            ReplyHandshake repHand = new ReplyHandshake(buffer, readedLength, _handshakeCreator.GetMethod());

            Console.WriteLine($"Read reply handshake from server: {repHand}");
        }