Exemplo n.º 1
0
        public static void HandlePacketEncryptionResponse(Client client, EncryptionKeyResponse packet)
        {
            client.SharedKey = PacketCryptography.Decrypt(packet.SharedSecret);

            RijndaelManaged recv = PacketCryptography.GenerateAES(client.SharedKey);
            RijndaelManaged send = PacketCryptography.GenerateAES(client.SharedKey);

            client.Decrypter = recv.CreateDecryptor();

            byte[] packetToken = PacketCryptography.Decrypt(packet.VerifyToken);

            if (!packetToken.SequenceEqual(PacketCryptography.VerifyToken))
            {
                client.Kick("Wrong token");
                return;
            }

            client.Send_Sync_Packet(new EncryptionKeyResponse());

            client.Encrypter = send.CreateEncryptor();
        }
Exemplo n.º 2
0
        public static bool IsAuthenticated(Client client)
        {
            if (client.Server.UseOfficalAuthentication)
            {
                try
                {
                    var uri = new Uri(
                        String.Format(
                            "http://session.minecraft.net/game/checkserver.jsp?user={0}&serverId={1}",
                            client.Username,
                            // As per http://mc.kev009.com/Protocol_Encryption
                            PacketCryptography.JavaHexDigest(Encoding.UTF8.GetBytes(client.ConnectionId)
                                                             .Concat(client.SharedKey)
                                                             .Concat(PacketCryptography.PublicKeyToAsn1(client.Server.ServerKey))
                                                             .ToArray())
                            ));

                    string authenticated = Http.GetHttpResponse(uri);
                    if (authenticated != "YES")
                    {
                        client.Kick("Authentication failed");
                        return(false);
                    }
                }
                catch (Exception exc)
                {
                    client.Kick("Error while authenticating...");
                    client.Logger.Log(exc);
                    return(false);
                }

                return(true);
            }

            return(true);
        }