Exemple #1
0
 //
 // Summary:
 //     Initializes an implementation of the System.Security.Cryptography.HashAlgorithm
 //     class.
 public override void Initialize()
 {
     _md5.Initialize();
     _sha1.Initialize();
 }
Exemple #2
0
        /// <summary>
        /// Check for an upgrade to a web socket connection.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        private IWebSocketRequestHandler UpgradeToWebsocket(HttpRequest request, HttpResponse response)
        {
            // Check for required headers
            if (!(request.Headers.ContainsKey(HttpHeaders.Connection) && request.Headers[HttpHeaders.Connection].ToLower().Contains("upgrade")))
            {
                return(null);
            }
            if (!(request.Headers.ContainsKey(HttpHeaders.Upgrade) && request.Headers[HttpHeaders.Upgrade].ToLower().Contains("websocket")))
            {
                return(null);
            }
            if (!request.Headers.ContainsKey(SecWebSocketVersion))
            {
                return(null);
            }
            int version;

            if (!(int.TryParse(request.Headers[SecWebSocketVersion], out version) && (version == 13)))
            {
                return(null);
            }
            if (!request.Headers.ContainsKey(SecWebSocketKey))
            {
                return(null);
            }
            // Make sure we have a handler for the URI
            string partial;
            IWebSocketRequestHandler handler = m_server.GetHandlerForWebSocket(request.URI, out partial);

            if (handler == null)
            {
                return(null);
            }
            // Do we support the protocols requested?
            string protocol = null;

            if (request.Headers.ContainsKey(SecWebSocketProtocol))
            {
                foreach (string proto in request.Headers[SecWebSocketProtocol].Split(WebSocketProtocolSeparator))
                {
                    if (handler.WillAcceptRequest(partial, proto.Trim()))
                    {
                        protocol = proto.Trim();
                        break;
                    }
                }
            }
            else if (handler.WillAcceptRequest(partial, ""))
            {
                protocol = "";
            }
            if (protocol == null)
            {
                return(null);
            }
            // Finish the handshake
            byte[] security = Encoding.UTF8.GetBytes(request.Headers[SecWebSocketKey].Trim() + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

            sha1.Initialize();
            sha1.HashCore(security, 0, security.Length);
            security = sha1.HashFinal();
            response.Headers[SecWebSocketAccept]     = Convert.ToBase64String(security);
            response.Headers[HttpHeaders.Upgrade]    = "websocket";
            response.Headers[HttpHeaders.Connection] = "Upgrade";
            response.ResponseCode = HttpResponseCode.SwitchingProtocols;
            if (protocol.Length > 0)
            {
                response.Headers[SecWebSocketProtocol] = protocol;
            }
            // And we are done
            return(handler);
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            string Username = textBox1.Text;
            string Password = textBox2.Text;

            bool CanContinue = false;

            SHA1CryptoServiceProvider Crypto = new SHA1CryptoServiceProvider();

            Crypto.Initialize();

            Password = BitConverter.ToString(Crypto.ComputeHash(Encoding.UTF8.GetBytes(Password), 0, Encoding.UTF8.GetByteCount(Password))).Replace("-", "").ToLower();

            string Lang = listBox1.SelectedItem != null ? (string)listBox1.SelectedItem : "English";

            string RemoteServer = textBox3.Text;

            string cert = "";

            if (!UsingCertificateServer)
            {
                using (StreamWriter writer = new StreamWriter(cert + @"\ApsCert.pfx"))
                {
                    writer.WriteLine("Signature: ApsAuth");
                    writer.WriteLine("<?xml version=\"1.0\"?>");
                    writer.WriteLine("<ClientAuthCertificate xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
                    writer.WriteLine("<Username>" + Username + "</Username>");
                    writer.WriteLine("<Hash>" + Password + "</Hash>");
                    writer.WriteLine("<Sessionkey></Sessionkey>");
                    writer.WriteLine("</ClientAuthCertificate>");
                }

                CanContinue = true;
            }
            else
            {
                WebClient wc          = new WebClient();
                string    Certificate = wc.DownloadString(CertificateServerUrl + "?username="******"&passhash=" + Password);

                switch (Certificate)
                {
                case "ERR_INVALID_USERNAME":
                    MessageBox.Show("Error, your username is invalid");
                    break;

                case "ERR_INVALID_PASSWORD":
                    MessageBox.Show("Error, your password is invalid");
                    break;

                case "ERR_ACTIVE_BAN":
                    MessageBox.Show("Error, you are banned from the server");
                    break;

                default:
                    CanContinue = true;
                    break;
                }

                if (CanContinue)
                {
                    using (StreamWriter writer = new StreamWriter(cert + @"\ApsCert.pfx"))
                    {
                        writer.WriteLine("Signature: ApsAuth");
                        writer.Write(Certificate);
                    }
                }
            }

            if (CanContinue)
            {
                try
                {
                    Process process = new Process();
                    process.StartInfo.FileName  = "rift.exe";
                    process.StartInfo.Arguments = "-u " + Username + " -k " + cert + @"\ApsCert.pfx -l " + Lang + " -s " + RemoteServer;
                    process.Start();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error, the launcher must be placed in the game directory");
                }
            }
        }