public void HandleMcpeClientToServerHandshake(McpeClientToServerHandshake 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. if (_playerInfo.ProtocolVersion < 111) { Log.Warn($"Wrong version ({_playerInfo.ProtocolVersion}) of Minecraft. Upgrade to join this server."); _session.Disconnect($"Wrong version ({_playerInfo.ProtocolVersion}) of Minecraft. Upgrade to join this server."); return; } if (Config.GetProperty("ForceXBLAuthentication", false) && _playerInfo.CertificateData.ExtraData.Xuid == null) { Log.Warn($"You must authenticate to XBOX Live to join this server."); _session.Disconnect(Config.GetProperty("ForceXBLLogin", "You must authenticate to XBOX Live to join this server.")); return; } _session.MessageHandler.HandleMcpeClientToServerHandshake(null); }
public void HandleMcpeClientToServerHandshake(McpeClientToServerHandshake 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.HandleMcpeClientToServerHandshake(null); }
public void HandleMcpeClientToServerHandshake(McpeClientToServerHandshake message) { if (message == null) { message = new McpeClientToServerHandshake(); var bytes = message.Encode(); WriteBytes(bytes); } else { WritePackage(message); } }
public new void InitiateEncryption(byte[] serverKey, byte[] randomKeyToken) { try { ECPublicKeyParameters remotePublicKey = (ECPublicKeyParameters) PublicKeyFactory.CreateKey(serverKey); ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.Init(Session.CryptoContext.ClientKey.Private); byte[] secret; using (var sha = SHA256.Create()) { secret = sha.ComputeHash(randomKeyToken.Concat(agreement.CalculateAgreement(remotePublicKey).ToByteArrayUnsigned()).ToArray()); } // Create a decrytor to perform the stream transform. IBufferedCipher decryptor = CipherUtilities.GetCipher("AES/CFB8/NoPadding"); decryptor.Init(false, new ParametersWithIV(new KeyParameter(secret), secret.Take(16).ToArray())); IBufferedCipher encryptor = CipherUtilities.GetCipher("AES/CFB8/NoPadding"); encryptor.Init(true, new ParametersWithIV(new KeyParameter(secret), secret.Take(16).ToArray())); Session.CryptoContext = new CryptoContext { Decryptor = decryptor, Encryptor = encryptor, UseEncryption = true, Key = secret }; Thread.Sleep(1250); McpeClientToServerHandshake magic = new McpeClientToServerHandshake(); SendPacket(magic); } catch (Exception e) { Log.Error("Initiate encryption", e); } }
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(McpeWrapper), message.GetType()); List <Package> messages = HandleBatch((McpeWrapper)message); McpeClientToServerHandshake magic = (McpeClientToServerHandshake)messages.FirstOrDefault(); Assert.AreEqual(typeof(McpeClientToServerHandshake), 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); } } } }