Esempio n. 1
0
        /// <summary>
        ///     Constructs a packet with default values
        /// </summary>
        /// <typeparam name="T">Payload type</typeparam>
        /// <param name="payload">Payload</param>
        /// <returns>A Packet with default values</returns>
        public IEEE802_1x <T> Default <T>(T payload) where T : class, IPacket
        {
            var packet = new IEEE802_1x <T> {
                Payload = payload
            };

            packet.CorrectFields();
            return(packet);
        }
        public void CanValidatePTK()
        {
            var ptk = new byte[] { 0xea, 0x0e, 0x40, 0x46, 0x33, 0xc8, 0x02, 0x45, 0x03, 0x02, 0x86, 0x8c, 0xca, 0xa7, 0x49, 0xde
                                   , 0x5c, 0xba, 0x5a, 0xbc, 0xb2, 0x67, 0xe2, 0xde, 0x1d, 0x5e, 0x21, 0xe5, 0x7a, 0xcc, 0xd5, 0x07
                                   , 0x9b, 0x31, 0xe9, 0xff, 0x22, 0x0e, 0x13, 0x2a, 0xe4, 0xf6, 0xed, 0x9e, 0xf1, 0xac, 0xc8, 0x85
                                   , 0x45, 0x82, 0x5f, 0xc3, 0x2e, 0xe5, 0x59, 0x61, 0x39, 0x5a, 0xe4, 0x37, 0x34, 0xd6, 0xc1, 0x07
                                   , 0x98, 0xef, 0x5a, 0xfe, 0x42, 0xc0, 0x74, 0x26, 0x47, 0x18, 0x68, 0xa5, 0x77, 0xd4, 0xd1, 0x7e };

            var eapolFrameBytes = new byte[] { 0x01, 0x03, 0x00, 0x75, 0x02, 0x01, 0x0a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x59, 0x16, 0x8b, 0xc3, 0xa5, 0xdf, 0x18, 0xd7, 0x1e, 0xfb, 0x64, 0x23, 0xf3, 0x40, 0x08, 0x8d, 0xab, 0x9e, 0x1b, 0xa2, 0xbb, 0xc5, 0x86, 0x59, 0xe0, 0x7b, 0x37, 0x64, 0xb0, 0xde, 0x85, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x35, 0x53, 0x82, 0xb8, 0xa9, 0xb8, 0x06, 0xdc, 0xaf, 0x99, 0xcd, 0xaf, 0x56, 0x4e, 0xb6, 0x00, 0x16, 0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02, 0x01, 0x00 };

            IEEE802_1x <EapolKey> eapolKey = IEEE802_1xFactory.Instance.ParseAs(eapolFrameBytes) as IEEE802_1x <EapolKey>;

            eapolKey.PtkIsValid(ptk).Should().BeTrue();
        }
        /// <summary>
        ///     Checks whether the specified pairwise transit key is valid for the EAPoL key
        /// </summary>
        /// <param name="eapolKey">The EAPoL key to check against</param>
        /// <param name="ptk">The pairwise transit key to check</param>
        /// <returns>True if the key is valid, false if it is not</returns>
        public static bool PtkIsValid(IEEE802_1x <EapolKey> eapolKey, byte[] ptk)
        {
            var  tkip = (eapolKey.Payload.KeyInformation & 7) == 1;
            bool isValid;
            var  MIC = eapolKey.Payload.MIC;

            eapolKey.Payload.MIC = new byte[MIC.Length];

            try
            {
                HMAC hmac;
                var  key = ptk.Take(16).ToArray();

                if (tkip)
                {
#if DOTNET5_4
                    throw new System.Exception("The current version of System.Security.Cryptography.Algorithms is missing HMACMD5.");
#else
                    hmac = new HMACMD5(key);
#endif
                }
                else
                {
                    hmac = new HMACSHA1(key);
                }

                var computedHash = hmac.ComputeHash(eapolKey.ToArray());
                isValid = computedHash.Take(16).SequenceEqual(MIC.Take(16));
            }
            finally
            {
                eapolKey.Payload.MIC = MIC;
            }

            return(isValid);
        }
Esempio n. 4
0
 /// <summary>
 ///     Checks whether the specified pairwise transit key is valid for the EAPoL key
 /// </summary>
 /// <param name="eapolKey">The EAPoL key to check against</param>
 /// <param name="ptk">The pairwise transit key to check</param>
 /// <returns>True if the key is valid, false if it is not</returns>
 public static bool PtkIsValid(this IEEE802_1x <EapolKey> eapolKey, byte[] ptk)
 => IEEE802_11Crypto.PtkIsValid(eapolKey, ptk);