private void RspHttpHandshakeReceive()
 {
     httpProxyState = new HttpPraser(true);
     httpProxyState.httpAuthUser = _config.authUser;
     httpProxyState.httpAuthPass = _config.authPass;
     byte[] remoteHeaderSendBuffer = null;
     int err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref remoteHeaderSendBuffer);
     if (err == 1)
     {
         _local.BeginReceive(connetionRecvBuffer, 0, _firstPacket.Length, 0,
             new AsyncCallback(HttpHandshakeRecv), null);
     }
     else if (err == 2)
     {
         string dataSend = httpProxyState.Http407();
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null);
     }
     else if (err == 3)
     {
         Connect();
     }
     else if (err == 4)
     {
         Connect();
     }
     else if (err == 0)
     {
         string dataSend = httpProxyState.Http200();
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
     }
 }
예제 #2
0
        private void RspHttpHandshakeReceive()
        {
            command = 1; // Set TCP connect command
            if (httpProxyState == null)
            {
                httpProxyState = new HttpPraser();
            }
            else
            {
                command = 1;
            }
            if (Util.Utils.isMatchSubNet(((IPEndPoint)_connection.RemoteEndPoint).Address, "127.0.0.0/8"))
            {
                httpProxyState.httpAuthUser = "";
                httpProxyState.httpAuthPass = "";
            }
            else
            {
                httpProxyState.httpAuthUser = _config.authUser;
                httpProxyState.httpAuthPass = _config.authPass;
            }
            int err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref _remoteHeaderSendBuffer);

            if (err == 1)
            {
                _connection.BeginReceive(_connetionRecvBuffer, 0, _firstPacket.Length, 0,
                                         new AsyncCallback(HttpHandshakeRecv), null);
            }
            else if (err == 2)
            {
                string dataSend = httpProxyState.Http407();
                byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
                _connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null);
            }
            else if (err == 3)
            {
                Connect();
            }
            else if (err == 4)
            {
                Connect();
            }
            else if (err == 0)
            {
                string dataSend = httpProxyState.Http200();
                byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
                _connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
            }
            else if (err == 500)
            {
                string dataSend = httpProxyState.Http500();
                byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
                _connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null);
            }
        }
        private void Dispose()
        {
            _transfer = null;
            _IPRange  = null;

            _firstPacket   = null;
            _connection    = null;
            _connectionUDP = null;

            _connetionRecvBuffer    = null;
            _remoteHeaderSendBuffer = null;

            httpProxyState = null;
        }
예제 #4
0
            private void RspHttpHandshakeReceive()
            {
                if (httpProxyState == null)
                {
                    httpProxyState = new HttpPraser(true);
                }
                httpProxyState.httpAuthUser = _config.authUser;
                httpProxyState.httpAuthPass = _config.authPass;
                byte[] remoteHeaderSendBuffer = null;
                int    err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref remoteHeaderSendBuffer);

                if (err == 1)
                {
                    _local.BeginReceive(connetionRecvBuffer, 0, _firstPacket.Length, 0,
                                        new AsyncCallback(HttpHandshakeRecv), null);
                }
                else if (err == 2)
                {
                    string dataSend = httpProxyState.Http407();
                    byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
                    _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null);
                }
                else if (err == 3)
                {
                    Connect();
                }
                else if (err == 4)
                {
                    Connect();
                }
                else if (err == 0)
                {
                    string dataSend = httpProxyState.Http200();
                    byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
                    _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
                }
                else if (err == 500)
                {
                    string dataSend = httpProxyState.Http500();
                    byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
                    _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null);
                }
            }
예제 #5
0
 private void RspHttpHandshakeReceive()
 {
     command = 1; // Set TCP connect command
     if (httpProxyState == null)
     {
         httpProxyState = new HttpPraser();
     }
     if (Util.Utils.isMatchSubNet(((IPEndPoint)_connection.RemoteEndPoint).Address, "127.0.0.0/8"))
     {
         httpProxyState.httpAuthUser = "";
         httpProxyState.httpAuthPass = "";
     }
     else
     {
         httpProxyState.httpAuthUser = _config.authUser;
         httpProxyState.httpAuthPass = _config.authPass;
     }
     for (int i = 1; ; ++i)
     {
         int err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref _remoteHeaderSendBuffer);
         if (err == 1)
         {
             if (HttpHandshakeRecv())
             {
                 break;
             }
         }
         else if (err == 2)
         {
             string dataSend = httpProxyState.Http407();
             byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
             _connection.Send(httpData);
             if (HttpHandshakeRecv())
             {
                 break;
             }
         }
         else if (err == 3 || err == 4)
         {
             Connect();
             break;
         }
         else if (err == 0)
         {
             local_sendback_protocol = "http";
             Connect();
             break;
         }
         else if (err == 500)
         {
             string dataSend = httpProxyState.Http500();
             byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
             _connection.Send(httpData);
             if (HttpHandshakeRecv())
             {
                 break;
             }
         }
         if (i == 3)
         {
             Close();
             break;
         }
     }
 }
예제 #6
0
        // 2 sides connection start
        private void StartPipe()
        {
            if (closed)
            {
                return;
            }
            try
            {
                // set mark
                connectionTCPIdle = true;
                connectionUDPIdle = true;
                remoteTCPIdle = true;
                remoteUDPIdle = true;
                remoteTDPIdle = true;

                remoteUDPRecvBufferLength = 0;
                SetObfsPlugin();

                ResetTimeout(TTL);

                // remote ready
                if (connectionUDP == null) // TCP
                {
                    if (server.tcp_over_udp &&
                        remoteTDP != null)
                    {
                        doRemoteTDPRecv();
                    }
                    else if (connectionSendBufferList != null && connectionSendBufferList.Count > 0)
                    {
                        foreach (byte[] buffer in connectionSendBufferList)
                        {
                            if (server.tcp_over_udp &&
                                    remoteTDP != null)
                            {
                                RemoteTDPSend(buffer, buffer.Length);
                            }
                            else
                            {
                                RemoteSend(buffer, buffer.Length);
                            }
                        }
                    }
                    else if (httpProxyState != null)
                    {
                        detector.OnSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
                        if (remoteHeaderSendBuffer != null)
                        {
                            byte[] data = new byte[remoteHeaderSendBuffer.Length];
                            Array.Copy(remoteHeaderSendBuffer, data, data.Length);
                            connectionSendBufferList.Add(data);
                            RemoteSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
                        }

                        //if (httpProxyState.httpProxy)
                        //{
                        //    byte[] buffer = new byte[0];
                        //    int buffer_len = 0;
                        //    httpProxyState.ParseHttpRequest(buffer, ref buffer_len);
                        //    if (remoteHeaderSendBuffer != null && remoteHeaderSendBuffer.Length > 0)
                        //    {
                        //        RemoteSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
                        //        byte[] data = new byte[remoteHeaderSendBuffer.Length];
                        //        Array.Copy(remoteHeaderSendBuffer, data, data.Length);
                        //        connectionSendBufferList.Add(data);
                        //    }
                        //}

                        remoteHeaderSendBuffer = null;
                        //if (!httpProxyState.httpProxy)
                        {
                            httpProxyState = null;
                        }
                    }
                }
                else // UDP
                {
                    if (
                        !server.udp_over_tcp &&
                        remoteUDP != null)
                    {
                        if (socks5RemotePort == 0)
                            CloseSocket(ref remote);
                        remoteHeaderSendBuffer = null;
                    }
                    else
                    {
                        if (remoteHeaderSendBuffer != null)
                        {
                            RemoteSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
                            remoteHeaderSendBuffer = null;
                        }
                    }
                }
                this.State = ConnectState.CONNECTED;

                // remote recv first
                doRemoteTCPRecv();
                doRemoteUDPRecv();

                // connection recv last
                doConnectionTCPRecv();
                doConnectionUDPRecv();
            }
            catch (Exception e)
            {
                LogSocketException(e);
                if (!Logging.LogSocketException(server.remarks, server.server, e))
                    Logging.LogUsefulException(e);
                this.Close();
            }
        }
예제 #7
0
 private void RspHttpHandshakeReceive()
 {
     command = 1; // Set TCP connect command
     if (httpProxyState == null)
     {
         httpProxyState = new HttpPraser();
     }
     if (Util.Utils.isMatchSubNet(((IPEndPoint)connection.RemoteEndPoint).Address, "127.0.0.0/8"))
     {
         httpProxyState.httpAuthUser = "";
     }
     else
     {
         httpProxyState.httpAuthUser = authUser;
         httpProxyState.httpAuthPass = authPass;
     }
     int err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref remoteHeaderSendBuffer);
     if (err == 1)
     {
         connection.BeginReceive(connetionRecvBuffer, 0, _firstPacket.Length, 0,
             new AsyncCallback(HttpHandshakeRecv), null);
     }
     else if (err == 2)
     {
         string dataSend = httpProxyState.Http407();
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null);
     }
     else if (err == 3)
     {
         Connect();
     }
     else if (err == 4)
     {
         Connect();
     }
     else if (err == 0)
     {
         string dataSend = httpProxyState.Http200();
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
     }
 }