private static void HandleSslConnect(ConnectToRemoteState state)
        {
            var connectStreamWriter = new StreamWriter(state.ClientStream);
            connectStreamWriter.WriteLine("HTTP/1.0 200 Connection established");
            connectStreamWriter.WriteLine("Timestamp: {0}", DateTime.Now);
            connectStreamWriter.WriteLine("Proxy-agent: GOS Proxy Service");
            connectStreamWriter.WriteLine();
            connectStreamWriter.Flush();

            var sslStream = new SslStream(state.ClientStream, false);
            try
            {
                var certProvider = new CertificateProvider();

                bool created;
                var certificate = certProvider.LoadOrCreateCertificate(state.RemoteHost, out created);
                sslStream.AuthenticateAsServer(certificate, false, SslProtocols.Tls | SslProtocols.Ssl3 | SslProtocols.Ssl2, true);
            }
            catch (Exception ex)
            {
                WriteLog(state.Session, 0, "ERR", ex.Message);
                sslStream.Close();
                state.ClientStream.Close();
                connectStreamWriter.Close();
                return;
            }

            var nstate = new ClientConnectionState
            {
                Session = state.Session,
                Client = state.Client,
                ClientStream = sslStream,
                ClientStreamBase = (NetworkStream)state.ClientStream,
                Buffer = new byte[Globals.BufferSize],
                MessageStream = new MemoryStream(),
                IsSsl = true,
            };

            try
            {
                sslStream.BeginRead(nstate.Buffer, 0, nstate.Buffer.Length, ReadFromClient.Run, nstate);
            }
            catch (Exception ex)
            {
                WriteLog(state.Session, 0, "ERR", ex.Message);
                sslStream.Close();
                state.ClientStream.Close();
            }
        }