Beispiel #1
0
        public void ParseTest4()
        {
            byte[] bytes = new byte[]
            {
                0x00, 0x01, 0x00, 0x60,                 //     Request type and message length
                0x21, 0x12, 0xa4, 0x42,                 //     Magic cookie
                0x78, 0xad, 0x34, 0x33,                 //  }
                0xc6, 0xad, 0x72, 0xc0,                 //  }  Transaction ID
                0x29, 0xda, 0x41, 0x2e,                 //  }
                0x00, 0x06, 0x00, 0x12,                 //     USERNAME attribute header
                0xe3, 0x83, 0x9e, 0xe3,                 //  }
                0x83, 0x88, 0xe3, 0x83,                 //  }
                0xaa, 0xe3, 0x83, 0x83,                 //  }  Username value (18 bytes) and padding (2 bytes)
                0xe3, 0x82, 0xaf, 0xe3,                 //  }
                0x82, 0xb9, 0x00, 0x00,                 //  }
                0x00, 0x15, 0x00, 0x1c,                 //     NONCE attribute header
                0x66, 0x2f, 0x2f, 0x34,                 //  }
                0x39, 0x39, 0x6b, 0x39,                 //  }
                0x35, 0x34, 0x64, 0x36,                 //  }
                0x4f, 0x4c, 0x33, 0x34,                 //  }  Nonce value
                0x6f, 0x4c, 0x39, 0x46,                 //  }
                0x53, 0x54, 0x76, 0x79,                 //  }
                0x36, 0x34, 0x73, 0x41,                 //  }
                0x00, 0x14, 0x00, 0x0b,                 //     REALM attribute header
                0x65, 0x78, 0x61, 0x6d,                 //  }
                0x70, 0x6c, 0x65, 0x2e,                 //  }  Realm value (11 bytes) and padding (1 byte)
                0x6f, 0x72, 0x67, 0x00,                 //  }
                0x00, 0x08, 0x00, 0x14,                 //     MESSAGE-INTEGRITY attribute header
                0xf6, 0x70, 0x24, 0x65,                 //  }
                0x6d, 0xd6, 0x4a, 0x3e,                 //  }
                0x02, 0xb8, 0xe0, 0x71,                 //  }  HMAC-SHA1 fingerprint
                0x2e, 0x85, 0xc9, 0xa2,                 //  }
                0x8c, 0xa8, 0x96, 0x66,                 //  }
            };

            string password = "******";
            string username = "******";
            string nonce    = "f//499k954d6OL34oL9FSTvy64sA";
            string realm    = "example.org";

            TurnMessage message = TurnMessage.Parse(bytes, TurnMessageRfc.Rfc5389);

            Assert.AreEqual(username, message.Username.Value);
            Assert.AreEqual(nonce, message.Nonce.Value);
            Assert.AreEqual(realm, message.Realm.Value);

            byte[] messageIntegrity = message.ComputeMessageIntegrity(password, true);

            Helpers.AreArrayEqual(messageIntegrity, message.MessageIntegrity.Value);
            Assert.IsTrue(message.IsMessageIntegrityValid(password, true));

            byte[] actual = message.GetBytes(password, true);
            Helpers.AreArrayEqual(bytes, actual);

            TurnMessage message2 = new TurnMessage()
            {
                MessageType      = MessageType.BindingRequest,
                TransactionId    = message.TransactionId,
                Username         = message.Username,
                Nonce            = message.Nonce,
                Realm            = message.Realm,
                MessageIntegrity = new MessageIntegrity(),
            };

            byte[] actual2 = message2.GetBytes(password, true);

            Helpers.AreArrayEqual(bytes, actual2);
        }