Exemplo n.º 1
0
        public void HandleMcpeClientMagic(McpeClientMagic message)
        {
            IServerManager serverManager = _session.Server.ServerManager;
            IServer        server        = serverManager.GetServer();

            IMcpeMessageHandler messageHandler = server.CreatePlayer(_session, _playerInfo);

            _session.MessageHandler = messageHandler;             // Replace current message handler with real one.

            _session.MessageHandler.HandleMcpeClientMagic(null);
        }
Exemplo n.º 2
0
        public void TestRealDecrytp()
        {
            // YFtS5MGIU/UQ2w2n3RdqMoBcHOzqEQqISOyKD+W9Prk=

            using (RijndaelManaged rijAlg = new RijndaelManaged())
            {
                rijAlg.BlockSize    = 128;
                rijAlg.Padding      = PaddingMode.None;
                rijAlg.Mode         = CipherMode.CFB;
                rijAlg.FeedbackSize = 8;

                rijAlg.Key = Base64Url.Decode("Tv9JFj4vhftDXgcjpNWNocWZrVKaVpF+icEh51M8MvI=");
                rijAlg.IV  = rijAlg.Key.Take(16).ToArray();

                Assert.AreEqual(rijAlg.Key.Take(16).ToArray(), rijAlg.IV);

                // Create a decrytor to perform the stream transform.
                ICryptoTransform decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV);

                // Create the streams used for decryption.
                using (MemoryStream msDecrypt = new MemoryStream())
                {
                    byte[] buffer1 = SoapHexBinary.Parse("172e0592aba239d86b7ca2384cfad4e4fa5b883ff6db73931ecd").Value;
                    using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                    {
                        msDecrypt.Write(buffer1, 0, buffer1.Length);
                        msDecrypt.Position = 0;
                        byte[] checksum;
                        byte[] clearBytes;
                        using (var clearBuffer = new MemoryStream())
                        {
                            var buffer = new byte[1024];
                            var read   = csDecrypt.Read(buffer, 0, buffer.Length);
                            while (read > 0)
                            {
                                clearBuffer.Write(buffer, 0, read);
                                read = csDecrypt.Read(buffer, 0, buffer.Length);
                            }
                            csDecrypt.Flush();

                            var fullResult = clearBuffer.ToArray();
                            clearBytes = (byte[])fullResult.Take(fullResult.Length - 8).ToArray();
                            checksum   = fullResult.Skip(fullResult.Length - 8).ToArray();
                        }

                        Assert.AreEqual(6, clearBytes[0]);

                        Package message = PackageFactory.CreatePackage(clearBytes[0], clearBytes, "mcpe");
                        Assert.NotNull(message);
                        Assert.AreEqual(typeof(McpeBatch), message.GetType());

                        List <Package>  messages = HandleBatch((McpeBatch)message);
                        McpeClientMagic magic    = (McpeClientMagic)messages.FirstOrDefault();
                        Assert.AreEqual(typeof(McpeClientMagic), magic?.GetType());

                        //Hashing - Checksum - Validation
                        MemoryStream hashStream = new MemoryStream();
                        Assert.True(BitConverter.IsLittleEndian);
                        hashStream.Write(BitConverter.GetBytes(0L), 0, 8);
                        hashStream.Write(clearBytes, 0, clearBytes.Length);
                        hashStream.Write(rijAlg.Key, 0, rijAlg.Key.Length);
                        SHA256Managed crypt              = new SHA256Managed();
                        var           hashBuffer         = hashStream.ToArray();
                        byte[]        validationCheckSum = crypt.ComputeHash(hashBuffer, 0, hashBuffer.Length).Take(8).ToArray();
                        Assert.AreEqual(checksum, validationCheckSum);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void HandleMcpeClientMagic(McpeClientMagic message)
        {
            IServerManager serverManager = _session.Server.ServerManager;
            IServer server = serverManager.GetServer();

            IMcpeMessageHandler messageHandler = server.CreatePlayer(_session, _playerInfo);
            _session.MessageHandler = messageHandler; // Replace current message handler with real one.

            _session.MessageHandler.HandleMcpeClientMagic(null);
        }