Beispiel #1
0
        protected override byte[] HashFinal()
        {
            int bufferOffset = this.bufferPosition;

            byte[] buffer = this.internalDataBuffer;

            buffer[bufferOffset] = 1;
            bufferOffset        += 1;

            if ((BLOCKSIZE - 8) <= bufferOffset)
            {
                Array.Clear(buffer, bufferOffset, BLOCKSIZE - bufferOffset);

                this.ProcessBlock();
                bufferOffset = 0;
            }

            Array.Clear(buffer, bufferOffset, BLOCKSIZE - bufferOffset - 8);

            TigerHash.LongToBytes(((ulong)this.totalLength) << 3, buffer, BLOCKSIZE - 8);

            this.ProcessBlock();

            byte[] retval = new byte[24];

            TigerHash.LongToBytes(this.a, retval, 0);
            TigerHash.LongToBytes(this.b, retval, 8);
            TigerHash.LongToBytes(this.c, retval, 16);

            return(retval);
        }
Beispiel #2
0
        public static byte[] CalculateInitialVector(uint initialValue)
        {
            var thash = new TigerHash();
            var hash  = thash.ComputeHash(BitConverter.GetBytes(initialValue));

            thash.Clear();

            return(hash);
        }
Beispiel #3
0
        private static void DoIW5ServerAuth(object stateo)
        {
            var state = (ServerAuthstate)stateo;

            // obtain key auth
            try
            {
                var query  = Query.EQ("keyHash", (long)state.KeyData);
                var result = Database.AServerKeys.Find(query);

                if (result.Count() > 0)
                {
                    var keyEntry  = result.First();
                    var keyString = keyEntry.key;

                    var thash = new TigerHash();
                    var key   = thash.ComputeHash(Encoding.ASCII.GetBytes(keyString));

                    // generate iv
                    var ivBase = BitConverter.ToUInt32(DWCrypto.GenerateRandom(4), 0);
                    var iv     = DWCrypto.CalculateInitialVector(ivBase);

                    // blah
                    var globalKey = DWCrypto.GenerateRandom(24);

                    var gameTicket = DWTickets.BuildGameTicket(globalKey, state.GameID, "", 0); // 4: official
                    var lsgTicket  = DWTickets.BuildLSGTicket(globalKey, state.KeyData, 1, "");

                    var encryptedGameTicket = DWCrypto.Encrypt(iv, key, gameTicket);

                    var reply = state.Packet.MakeReply(13, true);
                    reply.BitBuffer.UseDataTypes = false;
                    reply.BitBuffer.WriteBoolean(false);
                    reply.BitBuffer.WriteUInt32(700);
                    reply.BitBuffer.WriteUInt32(ivBase);
                    reply.BitBuffer.WriteBytes(encryptedGameTicket);
                    reply.BitBuffer.WriteBytes(lsgTicket);
                    reply.Send(false);
                    return;
                }
            }
            catch (Exception e)
            {
                Log.Debug("Exception: " + e.ToString());
            }
        }
Beispiel #4
0
        private static void CreateIW5ServerKey(object stateo)
        {
            var state = (IW5ServerAuthstate)stateo;

            // obtain key auth
            try
            {
                Log.Debug("got a request for a new IW5 dedi key; seems fun to me");

                // actually the advanced RSA stuff should be used but that might be incompatible with the .NET implementation of RSA
                var passGen = new PasswordGenerator();
                passGen.Maximum = 20;
                passGen.Minimum = 20;
                var key = passGen.Generate();

                key = string.Format("X{0}-{1}-{2}-{3}-{4}", key.Substring(1, 3), key.Substring(4, 4), key.Substring(8, 4), key.Substring(12, 4), key.Substring(16, 4));

                var thash   = new TigerHash();
                var hash    = thash.ComputeHash(Encoding.ASCII.GetBytes(key));
                var keyHash = BitConverter.ToInt64(hash, 0);

                var keyEntry = new ServerKey();
                keyEntry.key     = key;
                keyEntry.keyHash = keyHash;
                keyEntry.unkInt  = new Random().Next();
                Database.AServerKeys.Save(keyEntry);

                var keyStuff = new byte[86];
                Array.Copy(Encoding.ASCII.GetBytes(key), keyStuff, key.Length);

                var obfuscationKey = "43FCB2ACF2D72593DD7CD1C69E0F03C07229F4C83166F7B05BA0C5FE3AA3A2D93EK2495783KDKN92939DK";
                var i = 0;

                foreach (var character in obfuscationKey)
                {
                    keyStuff[i] ^= (byte)character;
                    i++;
                }

                // generate iv
                var ivBase = BitConverter.ToUInt32(DWCrypto.GenerateRandom(4), 0);
                var iv     = DWCrypto.CalculateInitialVector(ivBase);

                // blah
                var globalKey = DWCrypto.GenerateRandom(24);

                var gameTicket = DWTickets.BuildGameTicket(globalKey, state.GameID, "", (byte)0); // 4: official
                var lsgTicket  = DWTickets.BuildLSGTicket(globalKey, (ulong)keyHash, 1, "");

                var encryptedGameTicket = DWCrypto.Encrypt(iv, hash, gameTicket);

                var reply = state.Packet.MakeReply(25, true);
                reply.BitBuffer.UseDataTypes = false;
                reply.BitBuffer.WriteBoolean(false);
                reply.BitBuffer.WriteUInt32(700);
                reply.BitBuffer.WriteUInt32(ivBase);
                reply.BitBuffer.WriteBytes(encryptedGameTicket);
                reply.BitBuffer.WriteBytes(lsgTicket);
                reply.BitBuffer.WriteBytes(keyStuff);
                reply.BitBuffer.WriteInt32(keyEntry.unkInt);

                reply.Send(false);
            }
            catch (Exception e)
            {
                Log.Debug("Exception: " + e.ToString());
            }
        }