public bool HandlePacket(Peer peer, byte[] data)
        {
            var keyCheck = new KeyCheck(data);
            var userId   = _game.Blowfish.Decrypt(keyCheck.checkId);

            if (userId != keyCheck.userId)
            {
                return(false);
            }

            var playerNo = 0;

            foreach (var p in _playerManager.GetPlayers())
            {
                var player = p.Item2;
                if (player.UserId == userId)
                {
                    if (player.Peer != null)
                    {
                        _logger.LogCoreWarning("Ignoring new player " + userId + ", already connected!");
                        return(false);
                    }

                    //TODO: add at least port or smth
                    p.Item1     = peer.Address.port;
                    player.Peer = peer;
                    var  response = new KeyCheck(keyCheck.userId, playerNo);
                    bool bRet     = _game.PacketHandlerManager.sendPacket(peer, response, Channel.CHL_HANDSHAKE);
                    //handleGameNumber(player, peer, _game);//Send 0x91 Packet?
                    return(true);
                }
                ++playerNo;
            }
            return(false);
        }
Beispiel #2
0
        Test_PKV_licence_key_generation_and_verification_with_random_key_bytes_key_byte_qty_and_verification_key_byte_selection()
        {
            var pkvLicenceKey = new KeyGenerator();

            var pkvKeyCheck = new KeyCheck();

            for (var i = 0; i < 10000; i++)
            {
                var randomKeyByteSetsLength = new Random().Next(2, 400);

                var keyByteSets = new KeyByteSet[randomKeyByteSetsLength];

                for (var j = 0; j < randomKeyByteSetsLength; j++)
                {
                    var random = new Random();

                    var kbs = new KeyByteSet
                              (
                        j + 1,
                        (byte)random.Next(0, 256),
                        (byte)random.Next(0, 256),
                        (byte)random.Next(0, 256)
                              );

                    keyByteSets[j] = kbs;
                }

                // Select a random key byte set to test key verification with

                var kbs1 = keyByteSets[new Random().Next(0, randomKeyByteSetsLength)];
                var kbs2 = keyByteSets[new Random().Next(0, randomKeyByteSetsLength)];

                // The check project also uses a class called KeyByteSet, but with
                // separate name spacing to achieve single self contained dll

                var keyByteSet1 =
                    new KeyByteSet(kbs1.KeyByteNo, kbs1.KeyByteA, kbs1.KeyByteB,
                                   kbs1.KeyByteC); // Change no to test others
                var keyByteSet2 = new KeyByteSet(kbs2.KeyByteNo, kbs2.KeyByteA, kbs2.KeyByteB, kbs2.KeyByteC);

                var seed = new Random().Next(0, int.MaxValue);

                var key = pkvLicenceKey.MakeKey(seed, keyByteSets);

                // Check that check sum validation passes

                Assert.IsTrue(pkvKeyCheck.CheckKeyChecksum(key, keyByteSets.Length));

                // Check using full check method

                Assert.IsTrue(pkvKeyCheck.CheckKey(
                                  key,
                                  new[] { keyByteSet1, keyByteSet2 },
                                  keyByteSets.Length,
                                  null
                                  ) == LicenseKeyResult.KeyGood, "Failed on iteration " + i
                              );
            }
        }
Beispiel #3
0
        private void OnConnect(byte[] blowfishKey)
        {
            Console.WriteLine("[{0}] Connected to server.", "Maufeat");
            var keyCheck = KeyCheck.Create(_mySummonerId, _blowfish.Encrypt_ECB(_mySummonerId), blowfishKey);
            var keyBytes = Deserialize <KeyCheck>(keyCheck);

            Send(keyBytes, Channel.Handshake);
        }
Beispiel #4
0
        private void OnConnect(byte[] blowfishKey)
        {
            Log.Write("[{0}] Connected to server.", _credentials.summonerName);
            var keyCheck = KeyCheck.Create(_mySummonerId, _blowfish.Encrypt_ECB(_mySummonerId), blowfishKey);
            var keyBytes = Deserialize <KeyCheck>(keyCheck);

            Log.PacketLog(keyBytes, 0, keyBytes.Length);
            Send(keyBytes, Channel.Handshake);
        }
Beispiel #5
0
        protected override void Unpack(Unpacker unpacker)
        {
            base.Unpack(unpacker);

            if (unpacker.UnpackBool())
            {
                KeyCheck = new KeyCheck(unpacker);
            }
        }
Beispiel #6
0
        public void KeyCheck_OnValidResponse_ReturnObjects()
        {
            // arrange
            var          secrets            = SpiClientTestUtils.SetTestSecrets("3DFC835E5A24C63F3DD04E0BCC54FDBB441339A4D26589D1558D2C10A18AEE4F", "F2AEAC7AA7776D7178F0AC4F0F6D4EF1B5F22630EA93C309620E44ABA5A82D32");
            const string keyResponseJsonStr = @"{""enc"":""6A45A1F6E746CCE3FA470BEAC479F79783C03331DE10A795A859F6D5564168C956557BCCD3EDA55BBEACF34916269537"",""hmac"":""75B56FE4978AC9A22B2D56DDF952983CE8BECE1B6CEC8A7EEEE6ABF9CA2CB471""}";

            // act
            var msg     = Message.FromJson(keyResponseJsonStr, secrets);
            var request = new KeyCheck(msg);

            // assert
            Assert.Equal(msg.EventName, "key_check");
            Assert.Equal(request.ConfirmationCode, msg.IncomingHmac.Substring(0, 6));
        }
Beispiel #7
0
        /// <summary>
        /// Store core instance and initialize blocks
        /// </summary>
        /// <param name="core">Kotsh instance</param>
        public Block(Manager core)
        {
            // Store instance
            this.core = core;

            // Start instances
            this.Request    = new Request(this);
            this.Parse      = new Parse(this);
            this.KeyCheck   = new KeyCheck(this);
            this.Selenium   = new Selenium(this);
            this.StringUtil = new StringUtil(this);
            this.Dictionary = new Dictionary(this);
            this.Source     = new Source(this);
        }
Beispiel #8
0
        public IList <int> GetMatchingIx(KeyCheck eval, int bytes)
        {
            var result = new List <int>();

            var ix = RESERVED_SECTORS - 1;

            while ((ix = Next(ix)) > 0)
            {
                var one = Read(ix, bytes);
                if (eval(one))
                {
                    result.Add(ix);
                }
            }

            return(result);
        }
Beispiel #9
0
        public IList <KeyValuePair <int, byte[]> > GetMatching(KeyCheck eval, int bytes)
        {
            var result = new List <KeyValuePair <int, byte[]> >();

            var ix = RESERVED_SECTORS - 1;

            while ((ix = Next(ix)) > 0)
            {
                var one = Read(ix, bytes);
                if (eval(one))
                {
                    result.Add(new KeyValuePair <int, byte[]>(ix, Read(ix)));
                }
            }

            return(result);
        }
Beispiel #10
0
        public unsafe bool HandlePacket(ENetPeer *peer, byte[] data, Game game)
        {
            // players[0].Item1 = peer->address.host; //temp
            //   players[0].Item2.setPeer(enetEvent.peer);

            var keyCheck = new KeyCheck(data);
            var userId   = (long)BlowFishCS.BlowFishCS.Decrypt2(game.getBlowfish(), (ulong)keyCheck.checkId);

            if (userId != keyCheck.userId)
            {
                return(false);
            }

            var playerNo = 0;

            foreach (var p in game.getPlayers())
            {
                var player = p.Item2;
                if (player.userId == userId)
                {
                    if (player.getPeer() != null)
                    {
                        Logger.LogCoreWarning("Ignoring new player " + userId + ", already connected!");
                        return(false);
                    }

                    //TODO: add at least port or smth
                    p.Item1 = peer->address.host;
                    player.setPeer(peer);
                    var  response = new KeyCheck(keyCheck.userId, playerNo);
                    bool bRet     = PacketHandlerManager.getInstace().sendPacket(peer, response, Channel.CHL_HANDSHAKE);
                    handleGameNumber(player, peer, null);//Send 0x91 Packet?
                    return(true);
                }
                ++playerNo;
            }
            return(false);
        }
Beispiel #11
0
        private void Run()
        {
            KeyCheck key  = new KeyCheck();
            string   text = null;

            while (_run)
            {
                string keys = key.GetKey();
                //LogFile.WriteData("RunThread..."+keys, "c:\\tmp\\A");


                if (!string.IsNullOrEmpty(keys))
                {
                    text += keys;
                    text  = text.Replace("_enter_", "\n");
                    if (text.IndexOf("\n") > -1)
                    {
                        _code = text;
                        text  = null;
                    }
                }
                Thread.Sleep(10);
            }
        }
Beispiel #12
0
        public void Test_pkv_licence_key_generation_and_verification()
        {
            var pkvLicenceKey = new KeyGenerator();

            var pkvKeyCheck = new KeyCheck();

            var key = string.Empty;

            KeyByteSet[] keyByteSets =
            {
                new KeyByteSet(1,  58,   6,  97),
                new KeyByteSet(2,  96, 254,  23),
                new KeyByteSet(3,  11, 185,  69),
                new KeyByteSet(4,   2,  93,  41),
                new KeyByteSet(5,  62,   4, 234),
                new KeyByteSet(6, 200,  56,  49),
                new KeyByteSet(7,  89,  45, 142),
                new KeyByteSet(8,   6,  88, 32)
            };

            // Change these to a random key byte set from the above array to test key verification with

            var kbs1 = keyByteSets[3];
            var kbs2 = keyByteSets[7];
            var kbs3 = keyByteSets[4];

            // The check project also uses a class called KeyByteSet, but with
            // separate name spacing to achieve single self contained dll

            var keyByteSet1 =
                new KeyByteSet(kbs1.KeyByteNo, kbs1.KeyByteA, kbs1.KeyByteB, kbs1.KeyByteC); // Change no to test others
            var keyByteSet2 = new KeyByteSet(kbs2.KeyByteNo, kbs2.KeyByteA, kbs2.KeyByteB, kbs2.KeyByteC);
            var keyByteSet3 = new KeyByteSet(kbs3.KeyByteNo, kbs3.KeyByteA, kbs3.KeyByteB, kbs3.KeyByteC);

            for (var i = 0; i < 10000; i++)
            {
                var seed = new Random().Next(0, int.MaxValue);

                key = pkvLicenceKey.MakeKey(seed, keyByteSets);

                // Check that check sum validation passes
                Assert.IsTrue(pkvKeyCheck.CheckKeyChecksum(key, keyByteSets.Length));

                // Check using full check method
                Assert.IsTrue(pkvKeyCheck.CheckKey(
                                  key,
                                  new[] { keyByteSet1, keyByteSet2, keyByteSet3 },
                                  keyByteSets.Length,
                                  null
                                  ) == LicenseKeyResult.KeyGood, "Failed on iteration " + i
                              );

                // Check that erroneous check sum validation fails
                Assert.IsFalse(pkvKeyCheck.CheckKeyChecksum(key.Remove(23, 1) + "A",
                                                            keyByteSets.Length)); // Change key by replacing 17th char
            }

            // Check a few random inputs
            Assert.IsFalse(pkvKeyCheck.CheckKey("adcsadrewf",
                                                new[] { keyByteSet1, keyByteSet2 },
                                                keyByteSets.Length,
                                                null) == LicenseKeyResult.KeyGood
                           );
            Assert.IsFalse(pkvKeyCheck.CheckKey("",
                                                new[] { keyByteSet1, keyByteSet2 },
                                                keyByteSets.Length,
                                                null) == LicenseKeyResult.KeyGood
                           );
            Assert.IsFalse(pkvKeyCheck.CheckKey("123",
                                                new[] { keyByteSet1, keyByteSet2 },
                                                keyByteSets.Length,
                                                null) == LicenseKeyResult.KeyGood
                           );
            Assert.IsFalse(pkvKeyCheck.CheckKey("*()",
                                                new[] { keyByteSet1, keyByteSet2 },
                                                keyByteSets.Length,
                                                null) == LicenseKeyResult.KeyGood
                           );
            Assert.IsFalse(pkvKeyCheck.CheckKey("dasdasdasgdjwqidqiwd21887127eqwdaishxckjsabcxjkabskdcbq2e81y12e8712",
                                                new[] { keyByteSet1, keyByteSet2 },
                                                keyByteSets.Length,
                                                null) == LicenseKeyResult.KeyGood
                           );
        }
Beispiel #13
0
 protected void placeTrigger(KeyCheck check)
 {
     triggers.Add(check);
 }
Beispiel #14
0
 public ClientKeyCheckResponseMessage(long requestCode, KeyCheck keyCheck) : this()
 {
     SetRequestCode(requestCode);
     KeyCheck = keyCheck;
 }