当前位置: 首页>>代码示例>>C#>>正文


C# IClient.AddPermission方法代码示例

本文整理汇总了C#中IClient.AddPermission方法的典型用法代码示例。如果您正苦于以下问题:C# IClient.AddPermission方法的具体用法?C# IClient.AddPermission怎么用?C# IClient.AddPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IClient的用法示例。


在下文中一共展示了IClient.AddPermission方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleAuthLogOnProof

        public static void HandleAuthLogOnProof(IClient client, IncomingAuthPacket packet)
        {
            Contract.Requires(client != null);
            Contract.Requires(packet != null);

            var clientPublicEphemeralA = packet.ReadBigInteger(32);
            // Client Proof.
            // SHA1 of { SHA1(Modulus) ^ SHA1(Generator), SHA1(USERNAME), salt, PublicA, PublicB, SessionKey }
            var clientResult = packet.ReadBigInteger(20);
            // SHA1 hash of the PublicA and HMACSHA1 of the contents of WoW.exe and unicows.dll. HMAC seed is the 16 bytes at the end of the challenge sent by the server.
            packet.ReadBytes(20); // these can safely be ignored, clientFileHash

            // the client tends to send 0, but just in case it's safer to implement this.
            var numKeys = packet.ReadByte();
            if (numKeys > 0)
            {
                // only initialize the array if we actually HAVE keys
                AuthLogonKey[] keys = new AuthLogonKey[numKeys];
                for (byte key = 0; key < numKeys; key++)
                {
                    var unk1 = packet.ReadInt16();
                    var unk2 = packet.ReadInt32();
                    var unk3 = packet.ReadBytes(4);
                    // SHA of { PublicA, PublicB, byte[20] unknown data }
                    var shaHash = packet.ReadBytes(20);
                    Contract.Assume(unk3.Length == 4);
                    Contract.Assume(shaHash.Length == 20);
                    keys[key] = new AuthLogonKey(unk1, unk2, unk3, shaHash);
                }
            }

            var securityFlags = (ExtraSecurityFlags)packet.ReadByte(); // can be safely ignored

            if (securityFlags.HasFlag(ExtraSecurityFlags.PIN))
            {
                packet.ReadBytes(16); // pinRandom
                packet.ReadBytes(20); // pinSha1
            }

            if (securityFlags.HasFlag(ExtraSecurityFlags.Matrix))
            {
                packet.ReadBytes(20); // matrixHmacResult
            }

            if (securityFlags.HasFlag(ExtraSecurityFlags.SecurityToken))
            {
                var tokenLength = packet.ReadByte();
                packet.ReadBytes(tokenLength); // token
            }

            SRPServer srpData = client.UserData.SRP;
            srpData.PublicEphemeralValueA = clientPublicEphemeralA;
            var success = srpData.Validator.IsClientProofValid(clientResult);
            if (success)
            {
                SendAuthenticationLogOnProofSuccess(client, srpData.Validator.ServerSessionKeyProof);
                client.AddPermission(new AuthenticatedPermission());
            }
            else
                SendAuthenticationLogOnProofFailure(client, AuthResult.FailUnknownAccount);
        }
开发者ID:madbroths,项目名称:Encore,代码行数:61,代码来源:AuthenticationHandler.cs

示例2: HandleReconnectProof

        public static void HandleReconnectProof(IClient client, IncomingAuthPacket packet)
        {
            // MD5 hash of { AccountName, byte[16] random data }
            BigInteger r1 = packet.ReadBigInteger(16);
            // SHA1 hash of { AccountName, MD5 from above, ReconnectProof, SessionKey }
            BigInteger r2 = packet.ReadBigInteger(20);
            // SHA1 hash of { MD5 from above, byte[16] of 0's }
            var r3 = packet.ReadBigInteger(20); // r3Data

            var numKeys = packet.ReadByte();
            if (numKeys > 0)
            {
                // only initialize the array if we actually HAVE keys
                AuthLogonKey[] keys = new AuthLogonKey[numKeys];
                for (byte key = 0; key < numKeys; key++)
                {
                    var unk1 = packet.ReadInt16();
                    var unk2 = packet.ReadInt32();
                    var unk3 = packet.ReadBytes(4);
                    var shaHash = packet.ReadBytes(20);
                    keys[key] = new AuthLogonKey(unk1, unk2, unk3, shaHash);
                }
            }

            SRPServer srpData = client.UserData.SRP;
            string username = client.UserData.Username;
            BigInteger rand = client.UserData.ReconnectRand;

            // TODO fetch this from the database (or some other persistent storage)
            //BigInteger sessionKey = null ?? new BigInteger(0);
            BigInteger hash = srpData.Hash(new HashDataBroker(Encoding.ASCII.GetBytes(username)), r1, rand);
            if (hash == r2)
            {
                SendReconnectProofSuccess(client);
                client.AddPermission(new AuthenticatedPermission());
            }
            else
                client.Disconnect();
        }
开发者ID:madbroths,项目名称:Encore,代码行数:39,代码来源:AuthenticationHandler.cs


注:本文中的IClient.AddPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。