Ejemplo n.º 1
0
        public void Handle(BotMessage botMessage)
        {
            var      msg = botMessage.Message as HelloAckSynMessage;
            PeerInfo peerInfo;

            if (!_peerList.TryGet(botMessage.Header.EndPoint, out peerInfo))
            {
                return;
            }

            peerInfo.BotId         = botMessage.Header.BotId;
            peerInfo.EncryptionKey = DHKeyExchange.CalculateSharedKey(msg.PublicKey, BotIdentifier.PrivateKey);
            peerInfo.Handshaked    = true;
            peerInfo.BotVersion    = msg.BotVersion;
            peerInfo.CfgVersion    = msg.CfgVersion;
            if (_peerList.TryRegister(peerInfo))
            {
                var reply = new HelloAckMessage
                {
                    BotVersion = 1,
                    CfgVersion = 1,
                    Peers      = _peerList.Recent().ToArray()
                };
                _messageManager.Send(reply, botMessage.Header.BotId, botMessage.Header.CorrelationId);

                _versionManager.CheckAgentVersion(msg.BotVersion, botMessage.Header.BotId);
                _versionManager.CheckConfigurationFileVersion(msg.CfgVersion, botMessage.Header.BotId);
            }
        }
Ejemplo n.º 2
0
        static BotIdentifier()
        {
            var info  = SystemInfo.GetSystemInfoSummary();
            var bytes = Encoding.ASCII.GetBytes(info);
            var md5   = MD5.Create();
            var hash  = md5.ComputeHash(bytes);

            Id         = new BotIdentifier(hash);
            PrivateKey = DHKeyExchange.GetPrivateKey();
            PublicKey  = DHKeyExchange.GetPublicKey(PrivateKey);
        }
        public void Handle(BotMessage botMessage)
        {
            var msg      = botMessage.Message as HelloSynMessage;
            var endpoint = botMessage.Header.EndPoint;

            var peerInfo = new PeerInfo(botMessage.Header.BotId, endpoint);

            if (_peerList.TryRegister(peerInfo))
            {
                peerInfo.EncryptionKey = DHKeyExchange.CalculateSharedKey(msg.PublicKey, BotIdentifier.PrivateKey);

                var reply = new HelloAckSynMessage {
                    BotVersion = 1,
                    CfgVersion = 1,
                    PublicKey  = BotIdentifier.PublicKey,
                };
                _messageManager.Send(reply, botMessage.Header.BotId, botMessage.Header.CorrelationId);
            }
        }
Ejemplo n.º 4
0
        private void OnReceive(BufferData data)
        {
            var packet = new ClientKeyPacket();

            packet.Read(data.GetReader());

            DHKeyExchange.GenerateServerK(PrivateKey, packet.B, K);

            var key = new byte[64];

            K.WriteToBigEndian(key, 0, key.Length);

            GameCryptManager.Initialize(Data, key);

            Socket.Send(new ClientKeyOkPacket());

            Cleanup();

            Manager.ExchangeDone(this);
        }
Ejemplo n.º 5
0
        public LoginClient(LoginManager manager, LengthedSocket socket)
        {
            Manager = manager;

            Socket             = socket;
            Socket.AutoReceive = false;
            Socket.OnReceive  += OnReceive;
            Socket.OnError    += OnError;

            DHKeyExchange.GeneratePrivateAndPublicA(PrivateKey, PublicKey);

            Socket.Send(new ServerKeyPacket
            {
                PublicKey = PublicKey,
                Prime     = DHKeyExchange.ConstantPrime,
                Generator = DHKeyExchange.ConstantGenerator
            });

            Socket.OnEncrypt += OnEncrypt;
            Socket.ReceiveAsync();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ulong mod = 0;
            ulong gen = 0;
            ulong p1  = 0;
            ulong p2  = 0;

            do
            {
                Console.Write("\nGen: ");

                try {
                    gen = Convert.ToUInt64(Console.ReadLine());
                } catch (System.Exception) {
                    Console.WriteLine("Gen must be >= 2");
                }
            } while (gen < 2);

            do
            {
                Console.Write("\nMod: ");

                try {
                    mod = Convert.ToUInt64(Console.ReadLine());
                } catch (System.Exception) {
                    Console.WriteLine("Mod must be prime");
                }
            } while (mod < 2);

            do
            {
                Console.Write("\nP1 Private Key: ");

                try {
                    p1 = Convert.ToUInt64(Console.ReadLine());
                } catch (System.Exception) {
                    Console.WriteLine("Private key must be >= 2");
                }
            } while (p1 < 2);

            do
            {
                Console.Write("\nP2 Private Key: ");

                try {
                    p2 = Convert.ToUInt64(Console.ReadLine());
                } catch (System.Exception) {
                    Console.WriteLine("Private key must be >= 2");
                }
            } while (p2 < 2);

            DHKeyExchange p1 = new DHKeyExchange(mod, gen, p1);
            DHKeyExchange p2 = new DHKeyExchange(mod, gen, p2, otherPart: p1);

            Console.WriteLine("Mod: {0}", p1.Mod);
            Console.WriteLine("Generator: {0}", p1.Gen);
            Console.WriteLine("Party 1 Public: {0}", p1.PublicKey);
            Console.WriteLine("Party 1 Private: {0}", p1.PrivateKey);
            Console.WriteLine("Party 1 Secret : {0}", p1.Secret);
            Console.WriteLine("Party 2 Public: {0}", p2.PublicKey);
            Console.WriteLine("Party 2 Private: {0}", p2.PrivateKey);
            Console.WriteLine("Party 2 Secret : {0}", p2.Secret);
        }
Ejemplo n.º 7
0
 private async Task HandlePacket(BbTcpPacket packet)
 {
     if (packet is BbTcpPacket_Hello_Ans && m_bRequestedHello)
     {
         m_bRequestedHello = false;
         BbTcpPacket_Hello_Ans hello_ans = (BbTcpPacket_Hello_Ans)packet;
         ServerName = hello_ans.Desc;
         ServerGUID = hello_ans.ServerGUID;
         ServerMinProtocolVersion = hello_ans.MinSupportedVersion;
         m_bRequiresPassword      = hello_ans.RequiresPassword;
         UsedProtocolVersion      = (byte)Math.Min(hello_ans.MaxSupportedVersion, BBProtocol.CURRENT_PROTOCOL_VERSION);
         if (UsedProtocolVersion < hello_ans.MinSupportedVersion || UsedProtocolVersion < BBProtocol.MIN_PROTOCOL_VERSION)
         {
             ProtocolIncompatible = true;
             Log.w(TAG, "Server supported protocol versions incompatible - " + ServerName);
             Disconnect(false, true);
         }
         SupportsScreenCapture = hello_ans.SupportsScreenCapture;
         IsProVersion          = hello_ans.IsProVersion;
         Log.d(TAG, "Received Hello Answer from " + ServerName + " Protocol Version: " + UsedProtocolVersion + " Needs Password: "******"Got Pong");
     }
     else if (packet is BbTcpPacket_EncryptionACK crypt)
     {
         await ContinueEncryptionNegotiation(crypt);
     }
     else if (packet is BbTcpPacket_Encryption_AuthAns auth)
     {
         if (m_abyTestedSharedSecret != null)
         {
             if (auth.ErrorCode == 0)
             {
                 Log.d(TAG, "DH+Auth negotiated encryption key for session is: " + BitConverter.ToString(m_abyTestedSharedSecret));
                 m_sendStreamCipher.Init(m_abyTestedSharedSecret);
                 m_recvStreamCipher.Init(m_abyTestedSharedSecret);
                 m_bAuthentificated          = true;
                 m_abyTestedSharedSecret     = null;
                 m_dhKeyExchange             = null;
                 m_requestedEncryptionMethod = EEncryptionMethod.NONE;
                 Log.d(TAG, "Password accepted, DH+Auth Encryption negotiation finished, transmissions will now be encrypted with " + m_sendStreamCipher.Algorithm);
                 Attach();
             }
             else
             {
                 Log.w(TAG, "Challenge failed - Password rejected. Trying again.");
                 m_abyTestedSharedSecret = null;
                 await Authenticate(true);
             }
         }
         else
         {
             Log.e(TAG, "Unexpected/Unrequested Encryption_AuthAns packet");
             Disconnect(false, false);
         }
     }
     else if (packet is BbTcpPacket_Attach_Ans attach_ans && m_bRequestedAttach)
     {
         m_bRequestedAttach = false;
         if (attach_ans.AttachResult == EAttachResult.ACCEPTED)
         {
             Attached    = true;
             WasAttached = true;
             ConnectedTime.Start();
             Connecting = false;
             ConnectionChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EState.CONNECTED, SessionID));
             Log.d(TAG, "Attached to " + ServerName);
         }
         else
         {
             Log.d(TAG, "Cannot Attach to " + ServerName + " Error: " + attach_ans.AttachResult);
             Disconnect(false, false);
         }
     }