private void RspHttpHandshakeReceive()
 {
     httpProxyState = new HttpProxyState(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 = "HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"RRR\"\r\n\r\n";
         dataSend += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN" +
                     " \"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">" +
                     "<HTML>" +
                     "  <HEAD>" +
                     "    <TITLE>Error</TITLE>" +
                     "    <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=ISO-8859-1\">" +
                     "  </HEAD>" +
                     "  <BODY><H1>407 Proxy Authentication Required.</H1></BODY>" +
                     "</HTML>";
         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 = "HTTP/1.1 200 Connection Established\r\n\r\n";
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
     }
 }
예제 #2
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 (httpProxyState != null)
                    {
                        RemoteSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
                        remoteHeaderSendBuffer = null;
                        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;
                        }
                    }
                }

                // 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();
            }
        }
예제 #3
0
 private void RspHttpHandshakeReceive()
 {
     command = 1; // Set TCP connect command
     httpProxyState = new HttpProxyState();
     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 == 0)
     {
         string dataSend = "HTTP/1.1 200 Connection Established\r\n\r\n";
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
     }
 }
예제 #4
0
 private void RspHttpHandshakeReceive()
 {
     command = 1; // Set TCP connect command
     httpProxyState = new HttpProxyState();
     httpProxyState.httpAuthString = httpAuthString;
     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 = "HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"SSR\"\r\n\r\n";
         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 = "HTTP/1.1 200 Connection Established\r\n\r\n";
         byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend);
         connection.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null);
     }
 }
예제 #5
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);
                        RemoteSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
                        if (remoteHeaderSendBuffer != null)
                        {
                            byte[] data = new byte[remoteHeaderSendBuffer.Length];
                            Array.Copy(remoteHeaderSendBuffer, data, data.Length);
                            connectionSendBufferList.Add(data);
                        }
                        //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();
            }
        }