Exemplo n.º 1
0
        public void ParseTest2()
        {
            byte[] bytes = new byte[]
            {
                0x01, 0x01, 0x00, 0x3c,                 //     Response type and message length
                0x21, 0x12, 0xa4, 0x42,                 //     Magic cookie
                0xb7, 0xe7, 0xa7, 0x01,                 //  }
                0xbc, 0x34, 0xd6, 0x86,                 //  }  Transaction ID
                0xfa, 0x87, 0xdf, 0xae,                 //  }
                0x80, 0x22, 0x00, 0x0b,                 //     SOFTWARE attribute header
                0x74, 0x65, 0x73, 0x74,                 //  }
                0x20, 0x76, 0x65, 0x63,                 //  }  UTF-8 server name
                0x74, 0x6f, 0x72, 0x20,                 //  }
                0x00, 0x20, 0x00, 0x08,                 //     XOR-MAPPED-ADDRESS attribute header
                0x00, 0x01, 0xa1, 0x47,                 //     Address family (IPv4) and xor'd mapped port number
                0xe1, 0x12, 0xa6, 0x43,                 //     Xor'd mapped IPv4 address
                0x00, 0x08, 0x00, 0x14,                 //     MESSAGE-INTEGRITY attribute header
                0x2b, 0x91, 0xf5, 0x99,                 //  }
                0xfd, 0x9e, 0x90, 0xc3,                 //  }
                0x8c, 0x74, 0x89, 0xf9,                 //  }  HMAC-SHA1 fingerprint
                0x2a, 0xf9, 0xba, 0x53,                 //  }
                0xf0, 0x6b, 0xe7, 0xd7,                 //  }
                0x80, 0x28, 0x00, 0x04,                 //     FINGERPRINT attribute header
                0xc0, 0x7d, 0x4c, 0x96,                 //     CRC32 fingerprint
            };

            string password = @"VOkJxbRl1RmTxUk/WvJxBt";

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

            Assert.AreEqual(@"test vector", message.Software.Value);
            Assert.AreEqual(@"192.0.2.1", message.XorMappedAddress.IpAddress.ToString());
            Assert.AreEqual(32853, message.XorMappedAddress.Port);

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

            Helpers.AreArrayEqual(messageIntegrity, message.MessageIntegrity.Value);
            Assert.AreEqual(0x3c, bytes[3]);

            uint fingerprint = message.ComputeFingerprint();

            Assert.AreEqual(fingerprint, message.Fingerprint.Value);

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

            TurnMessage message2 = new TurnMessage()
            {
                MessageType      = MessageType.BindingResponse,
                TransactionId    = message.TransactionId,
                Software         = message.Software,
                XorMappedAddress = message.XorMappedAddress,
                MessageIntegrity = new MessageIntegrity(),
                Fingerprint      = new Fingerprint(),
            };

            byte[] actual2 = message2.GetBytes(password, false, 0x20);

            Helpers.AreArrayEqual(bytes, actual2);
        }
Exemplo n.º 2
0
        private void SendTurn(TurnMessage message, ServerEndPoint local, IPEndPoint remote)
        {
            ServerAsyncEventArgs p;
            int offset;

            message.ComputeMessageLength();

            GetBuffer(local, remote, message.TotalMessageLength, out p, out offset);

            message.GetBytes(p.Buffer, offset, Authentificater.Key2);

            turnServer.SendAsync(p);
        }
Exemplo n.º 3
0
        private void SendMessage(Socket socket, TurnMessage message)
        {
            byte[] buffer1 = new byte[4096];

            message.ComputeMessageLength();
            message.GetBytes(buffer1, TcpFramingHeader.TcpFramingHeaderLength, key2);

            TcpFramingHeader.GetBytes(buffer1, 0, TcpFrameType.ControlMessage, message.TotalMessageLength);

            int size = TcpFramingHeader.TcpFramingHeaderLength + message.TotalMessageLength;

            if (socket.Send(buffer1, size, SocketFlags.None) != size)
            {
                throw new Exception("Send failed!");
            }
        }
Exemplo n.º 4
0
        public void MS_Message_Integrity_With_Data_Offset_In_Array()
        {
            var key2 = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            var created = new TurnMessage()
            {
                MessageType   = MessageType.AllocateRequest,
                TransactionId = TransactionId.Generate(),
                MagicCookie   = new MagicCookie(),
                MsVersion     = new MsVersion()
                {
                    Value = 1,
                },
                MsUsername = new MsUsername()
                {
                    Value = new byte[52],
                },
                Nonce = new Nonce(TurnMessageRfc.MsTurn)
                {
                    Value = "17938999-C63D-41cd-87A4-FE80975F03BA",
                },
                Realm = new Realm(TurnMessageRfc.MsTurn)
                {
                    Value = "test.test",
                },
                MessageIntegrity = new MessageIntegrity(),
            };

            int offset = 120;
            var buffer = new byte[4096];

            created.ComputeMessageLength();
            created.GetBytes(buffer, offset, key2);

            var parsed = TurnMessage.Parse(buffer, offset, created.TotalMessageLength, TurnMessageRfc.MsTurn);

            Assert.IsTrue(parsed.IsValidMessageIntegrity(key2));
        }
Exemplo n.º 5
0
        public void MsTurnMessageTest6()
        {
            byte[] expected = new byte[]
            {
                0x01, 0x15, 0x00, 0xA9,
                0x1B, 0xE1, 0x64, 0x3C,
                0x91, 0x14, 0x00, 0x00,
                0x1B, 0xE1, 0x64, 0x3C,
                0x91, 0x14, 0x00, 0x00,
                0x00, 0x0F, 0x00, 0x04,
                0x72, 0xC6, 0x4B, 0xC6,
                0x00, 0x12, 0x00, 0x08,
                0x00, 0x01, 0x61, 0x4F,
                0xD5, 0x1B, 0x5D, 0x66,
                0x00, 0x13, 0x00, 0x91,
                0x00, 0x8F, 0x80, 0xC8,
                0x00, 0x09, 0x36, 0x15,
                0xDA, 0x97, 0x70, 0x3F,
                0x62, 0xFD, 0x22, 0x6C,
                0x49, 0x35, 0x03, 0xAA,
                0x99, 0xC4, 0x96, 0x3D,
                0x05, 0xFE, 0x10, 0xE8,
                0xFF, 0xEC, 0x9D, 0x6F,
                0xA2, 0x26, 0x44, 0x7C,
                0x40, 0xE5, 0x7C, 0xB0,
                0xAB, 0x2A, 0xA4, 0x66,
                0x1F, 0x5E, 0x74, 0x25,
                0x56, 0x3A, 0x0D, 0x64,
                0x8D, 0xBD, 0x8D, 0xFB,
                0xF4, 0x81, 0xA3, 0xED,
                0x60, 0x35, 0x2B, 0x01,
                0x7E, 0xC4, 0xF8, 0x6D,
                0xF0, 0x26, 0xBD, 0xFF,
                0xF3, 0x31, 0xA7, 0xA7,
                0xDC, 0xAF, 0x89, 0x9C,
                0xFA, 0xC1, 0xC7, 0x3E,
                0xC0, 0x65, 0x53, 0x9C,
                0x90, 0xDD, 0xAF, 0xCC,
                0x02, 0x2E, 0xF0, 0xF3,
                0xB9, 0xAA, 0x5D, 0xB6,
                0x07, 0xB5, 0x17, 0x2A,
                0xDE, 0xF0, 0x23, 0x52,
                0x01, 0x7F, 0xD3, 0xE6,
                0x16, 0xB1, 0xF2, 0x90,
                0x16, 0x5A, 0x79, 0xD6,
                0xE9, 0xC9, 0xB8, 0x5F,
                0x53, 0xE0, 0x25, 0x63,
                0x5B, 0x09, 0x80, 0x00,
                0x00, 0x05, 0x01, 0x85,
                0xBA, 0x35, 0xA0, 0xC8,
                0x79, 0xF7, 0xED, 0x47,
                0x91,
            };

            TurnMessage message = new TurnMessage()
            {
                IsAttributePaddingDisabled = true,
                MessageType   = MessageType.DataIndication,
                TransactionId = new TransactionId(expected, 4),

                MagicCookie = new MagicCookie(),

                RemoteAddress = new RemoteAddress()
                {
                    IpEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("213.27.93.102"), 24911),
                },

                Data = new Data()
                {
                    Value = new byte[]
                    {
                        0x00, 0x8F, 0x80, 0xC8,
                        0x00, 0x09, 0x36, 0x15,
                        0xDA, 0x97, 0x70, 0x3F,
                        0x62, 0xFD, 0x22, 0x6C,
                        0x49, 0x35, 0x03, 0xAA,
                        0x99, 0xC4, 0x96, 0x3D,
                        0x05, 0xFE, 0x10, 0xE8,
                        0xFF, 0xEC, 0x9D, 0x6F,
                        0xA2, 0x26, 0x44, 0x7C,
                        0x40, 0xE5, 0x7C, 0xB0,
                        0xAB, 0x2A, 0xA4, 0x66,
                        0x1F, 0x5E, 0x74, 0x25,
                        0x56, 0x3A, 0x0D, 0x64,
                        0x8D, 0xBD, 0x8D, 0xFB,
                        0xF4, 0x81, 0xA3, 0xED,
                        0x60, 0x35, 0x2B, 0x01,
                        0x7E, 0xC4, 0xF8, 0x6D,
                        0xF0, 0x26, 0xBD, 0xFF,
                        0xF3, 0x31, 0xA7, 0xA7,
                        0xDC, 0xAF, 0x89, 0x9C,
                        0xFA, 0xC1, 0xC7, 0x3E,
                        0xC0, 0x65, 0x53, 0x9C,
                        0x90, 0xDD, 0xAF, 0xCC,
                        0x02, 0x2E, 0xF0, 0xF3,
                        0xB9, 0xAA, 0x5D, 0xB6,
                        0x07, 0xB5, 0x17, 0x2A,
                        0xDE, 0xF0, 0x23, 0x52,
                        0x01, 0x7F, 0xD3, 0xE6,
                        0x16, 0xB1, 0xF2, 0x90,
                        0x16, 0x5A, 0x79, 0xD6,
                        0xE9, 0xC9, 0xB8, 0x5F,
                        0x53, 0xE0, 0x25, 0x63,
                        0x5B, 0x09, 0x80, 0x00,
                        0x00, 0x05, 0x01, 0x85,
                        0xBA, 0x35, 0xA0, 0xC8,
                        0x79, 0xF7, 0xED, 0x47,
                        0x91,
                    }
                },
            };

            byte[] bytes = message.GetBytes(null);

            Helpers.AreArrayEqual(expected, bytes);
        }
Exemplo n.º 6
0
        public void MsTurnMessageTest5()
        {
            byte[] bytes = new byte[]
            {
                0x00, 0x03, 0x00, 0x9B,
                0x4A, 0x07, 0x32, 0x01,
                0x52, 0x11, 0xE9, 0x94,
                0xAE, 0x02, 0x4A, 0x13,
                0x8A, 0xA2, 0x0D, 0x26,
                0x00, 0x0F, 0x00, 0x04,
                0x72, 0xC6, 0x4B, 0xC6,
                0x80, 0x08, 0x00, 0x04,
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x06, 0x00, 0x34,
                0x01, 0x00, 0x00, 0x20,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x4C, 0x6F, 0x67, 0x2E,
                0x88, 0xC2, 0xF8, 0xDE,
                0xB8, 0x4E, 0x72, 0x65,
                0x5C, 0x43, 0x31, 0x49,
                0x07, 0x94, 0x46, 0xC2,
                0x19, 0x77, 0x73, 0x92,
                0xE0, 0x24, 0x03, 0x08,
                0x1D, 0x86, 0x27, 0xA8,
                0x50, 0x45, 0x1D, 0xB5,
                0x41, 0x8E, 0xC6, 0xCA,
                0x00, 0x14, 0x00, 0x24,
                0x61, 0x34, 0x31, 0x66,
                0x37, 0x61, 0x63, 0x35,
                0x2D, 0x38, 0x32, 0x37,
                0x64, 0x2D, 0x34, 0x30,
                0x65, 0x37, 0x2D, 0x38,
                0x35, 0x31, 0x33, 0x2D,
                0x63, 0x35, 0x66, 0x36,
                0x39, 0x31, 0x65, 0x35,
                0x66, 0x61, 0x64, 0x34,
                0x00, 0x15, 0x00, 0x0F,
                0x6F, 0x66, 0x66, 0x69,
                0x63, 0x65, 0x73, 0x69,
                0x70, 0x2E, 0x6C, 0x6F,
                0x63, 0x61, 0x6C, 0x00,
                0x08, 0x00, 0x14, 0xE3,
                0xB3, 0x88, 0x94, 0x79,
                0x3B, 0x28, 0x3A, 0x34,
                0x67, 0xA4, 0x46, 0xAD,
                0xD5, 0x6C, 0xD0, 0xE6,
                0xA7, 0x50, 0x90,
            };

            byte[] key2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };

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

            message.MessageIntegrity = new MessageIntegrity();

            message.ComputeMessageLength();

            int offset   = 25;
            int length64 = offset + message.TotalMessageLength;

            if (length64 % 64 != 0)
            {
                length64 += 64 - length64 % 64;
            }
            byte[] bytes2 = new byte[length64];

            message.GetBytes(bytes2, offset, key2);

            Helpers.AreArrayEqual(bytes, 0, bytes2, offset);
        }
Exemplo n.º 7
0
        public void MsTurnMessageTest2()
        {
            byte[] bytes = new byte[]
            {
                0x00, 0x03, 0x00, 0x9B,
                0x4A, 0x07, 0x32, 0x01,
                0x52, 0x11, 0xE9, 0x94,
                0xAE, 0x02, 0x4A, 0x13,
                0x8A, 0xA2, 0x0D, 0x26,
                0x00, 0x0F, 0x00, 0x04,
                0x72, 0xC6, 0x4B, 0xC6,
                0x80, 0x08, 0x00, 0x04,
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x06, 0x00, 0x34,
                0x01, 0x00, 0x00, 0x20,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x4C, 0x6F, 0x67, 0x2E,
                0x88, 0xC2, 0xF8, 0xDE,
                0xB8, 0x4E, 0x72, 0x65,
                0x5C, 0x43, 0x31, 0x49,
                0x07, 0x94, 0x46, 0xC2,
                0x19, 0x77, 0x73, 0x92,
                0xE0, 0x24, 0x03, 0x08,
                0x1D, 0x86, 0x27, 0xA8,
                0x50, 0x45, 0x1D, 0xB5,
                0x41, 0x8E, 0xC6, 0xCA,
                0x00, 0x14, 0x00, 0x24,
                0x61, 0x34, 0x31, 0x66,
                0x37, 0x61, 0x63, 0x35,
                0x2D, 0x38, 0x32, 0x37,
                0x64, 0x2D, 0x34, 0x30,
                0x65, 0x37, 0x2D, 0x38,
                0x35, 0x31, 0x33, 0x2D,
                0x63, 0x35, 0x66, 0x36,
                0x39, 0x31, 0x65, 0x35,
                0x66, 0x61, 0x64, 0x34,
                0x00, 0x15, 0x00, 0x0F,
                0x6F, 0x66, 0x66, 0x69,
                0x63, 0x65, 0x73, 0x69,
                0x70, 0x2E, 0x6C, 0x6F,
                0x63, 0x61, 0x6C, 0x00,
                0x08, 0x00, 0x14, 0xE3,
                0xB3, 0x88, 0x94, 0x79,
                0x3B, 0x28, 0x3A, 0x34,
                0x67, 0xA4, 0x46, 0xAD,
                0xD5, 0x6C, 0xD0, 0xE6,
                0xA7, 0x50, 0x90,
            };

            byte[] key1  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };
            byte[] key2  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };
            string nonce = "a41f7ac5-827d-40e7-8513-c5f691e5fad4";
            string realm = "officesip.local";

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

            Assert.AreEqual(MessageType.AllocateRequest, message.MessageType);
            Assert.AreEqual(nonce, message.Nonce.Value);
            Assert.AreEqual(realm, message.Realm.Value);
            Assert.IsTrue(message.IsValidMsUsername(key1));
            Assert.IsTrue(message.IsValidMessageIntegrity(key2), @"IsValidMessageIntegrity failed.");

            message.MessageIntegrity = new MessageIntegrity();
            Helpers.AreArrayEqual(bytes, message.GetBytes(key2));
        }
Exemplo n.º 8
0
        public void MsTurnMessageTest()
        {
            byte[] bytes = new byte[]
            {
                //0x00, 0x04, 0x23, 0x1E,
                //0xE6, 0x2D, 0x50, 0x18,
                //0x3F, 0x87, 0xF0, 0x9A,
                //0x00, 0x00, 0x02, 0x00,
                //0x00, 0xB1,
                0x00, 0x03,
                0x00, 0x9D, 0x30, 0xB8,
                0xC9, 0xC7, 0xAF, 0xFC,
                0xF4, 0xA2, 0x4D, 0xDB,
                0x6E, 0x2A, 0x0A, 0xE0,
                0xEA, 0x5D, 0x00, 0x0F,
                0x00, 0x04, 0x72, 0xC6,
                0x4B, 0xC6, 0x80, 0x08,
                0x00, 0x04, 0x00, 0x00,
                0x00, 0x01, 0x00, 0x06,
                0x00, 0x34, 0x01, 0x00,
                0x00, 0x20, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x4C, 0x6F,
                0x67, 0x2E, 0x88, 0xC2,
                0xF8, 0xDE, 0xB8, 0x4E,
                0x72, 0x65, 0x5C, 0x43,
                0x31, 0x49, 0x07, 0x94,
                0x46, 0xC2, 0x19, 0x77,
                0x73, 0x92, 0xE0, 0x24,
                0x03, 0x08, 0x1D, 0x86,
                0x27, 0xA8, 0x50, 0x45,
                0x1D, 0xB5, 0x41, 0x8E,
                0xC6, 0xCA, 0x00, 0x14,
                0x00, 0x26, 0x62, 0x62,
                0x30, 0x30, 0x65, 0x65,
                0x30, 0x32, 0x2D, 0x31,
                0x62, 0x38, 0x38, 0x2D,
                0x34, 0x31, 0x39, 0x35,
                0x2D, 0x39, 0x38, 0x34,
                0x34, 0x2D, 0x39, 0x38,
                0x36, 0x39, 0x64, 0x37,
                0x38, 0x39, 0x30, 0x33,
                0x62, 0x61, 0x78, 0x78,
                0x00, 0x15, 0x00, 0x0F,
                0x6F, 0x66, 0x66, 0x69,
                0x63, 0x65, 0x73, 0x69,
                0x70, 0x2E, 0x6C, 0x6F,
                0x63, 0x61, 0x6C,
                0x00, 0x08, 0x00, 0x14,                 //     MESSAGE-INTEGRITY attribute header
                0x29,                                   //  }
                0x48, 0x38, 0xD7, 0x37,                 //  }
                0x62, 0xB1, 0x26, 0x70,                 //  }  HMAC-SHA1
                0x95, 0xA3, 0x13, 0xAF,                 //  }
                0xA3, 0xBE, 0x78, 0x86,                 //  }
                0xFE, 0x53, 0x08,                       //  }
            };

            byte[] key1           = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };
            byte[] key2           = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };
            string nonce          = "bb00ee02-1b88-4195-9844-9869d78903baxx";
            string realm          = "officesip.local";
            string usernameBase64 = @"AQAAIAAAAAAAAAAATG9nLojC+N64TnJlXEMxSQeURsIZd3OS4CQDCB2GJ6hQRR21QY7Gyg==";
            string passwordBase64 = @"oUU0sl7OCLQNpLUYuI1cX7OAwXE=";

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

            Assert.AreEqual(MessageType.AllocateRequest, message.MessageType);
            Assert.AreEqual(nonce, message.Nonce.Value);
            Assert.AreEqual(realm, message.Realm.Value);
            Assert.AreEqual(usernameBase64, Convert.ToBase64String(message.MsUsername.Value));
            Assert.IsTrue(message.IsValidMsUsername(key1));
            Assert.AreEqual(passwordBase64, Convert.ToBase64String(message.ComputeMsPasswordBytes(key2)));
            Assert.IsTrue(message.IsValidMessageIntegrity(key2), @"IsValidMessageIntegrity failed.");

            message.MessageIntegrity = new MessageIntegrity();
            Helpers.AreArrayEqual(bytes, message.GetBytes(key2));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public void ParseTest3()
        {
            byte[] bytes = new byte[]
            {
                0x01, 0x01, 0x00, 0x48,                 //     Response type and message length
                0x21, 0x12, 0xa4, 0x42,                 //     Magic cookie
                0xb7, 0xe7, 0xa7, 0x01,                 //  }
                0xbc, 0x34, 0xd6, 0x86,                 //  }  Transaction ID
                0xfa, 0x87, 0xdf, 0xae,                 //  }
                0x80, 0x22, 0x00, 0x0b,                 //     SOFTWARE attribute header
                0x74, 0x65, 0x73, 0x74,                 //  }
                0x20, 0x76, 0x65, 0x63,                 //  }  UTF-8 server name
                0x74, 0x6f, 0x72, 0x20,                 //  }
                0x00, 0x20, 0x00, 0x14,                 //     XOR-MAPPED-ADDRESS attribute header
                0x00, 0x02, 0xa1, 0x47,                 //     Address family (IPv6) and xor'd mapped port number
                0x01, 0x13, 0xa9, 0xfa,                 //  }
                0xa5, 0xd3, 0xf1, 0x79,                 //  }  Xor'd mapped IPv6 address
                0xbc, 0x25, 0xf4, 0xb5,                 //  }
                0xbe, 0xd2, 0xb9, 0xd9,                 //  }
                0x00, 0x08, 0x00, 0x14,                 //     MESSAGE-INTEGRITY attribute header
                0xa3, 0x82, 0x95, 0x4e,                 //  }
                0x4b, 0xe6, 0x7b, 0xf1,                 //  }
                0x17, 0x84, 0xc9, 0x7c,                 //  }  HMAC-SHA1 fingerprint
                0x82, 0x92, 0xc2, 0x75,                 //  }
                0xbf, 0xe3, 0xed, 0x41,                 //  }
                0x80, 0x28, 0x00, 0x04,                 //     FINGERPRINT attribute header
                0xc8, 0xfb, 0x0b, 0x4c,                 //     CRC32 fingerprint
            };

            string password = @"VOkJxbRl1RmTxUk/WvJxBt";

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

            Assert.AreEqual(@"test vector", message.Software.Value);
            Assert.AreEqual(@"2001:db8:1234:5678:11:2233:4455:6677", message.XorMappedAddress.IpAddress.ToString());
            Assert.AreEqual(32853, message.XorMappedAddress.Port);

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

            Helpers.AreArrayEqual(messageIntegrity, message.MessageIntegrity.Value);
            Assert.AreEqual(0x48, bytes[3]);

            uint fingerprint = message.ComputeFingerprint();

            Assert.AreEqual(fingerprint, message.Fingerprint.Value);

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

            TurnMessage message2 = new TurnMessage()
            {
                MessageType      = MessageType.BindingResponse,
                TransactionId    = message.TransactionId,
                Software         = message.Software,
                XorMappedAddress = message.XorMappedAddress,
                MessageIntegrity = new MessageIntegrity(),
                Fingerprint      = new Fingerprint(),
            };

            byte[] actual2 = message2.GetBytes(password, false, 0x20);

            Helpers.AreArrayEqual(bytes, actual2);
        }