Esempio 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);
        }
Esempio n. 2
0
        public void Message_Integrity_And_Fingerprint_With_Data_Offset_In_Array()
        {
            byte[] bytes = new byte[]
            {
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // } Dummy data for testing offset
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }
                0xFF, 0xFF, 0xFF, 0xFF,                 // }

                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, 40, bytes.Length - 40, TurnMessageRfc.Rfc5389);

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

            Helpers.AreArrayEqual(messageIntegrity, message.MessageIntegrity.Value);

            Assert.AreEqual(message.ComputeFingerprint(), message.Fingerprint.Value);
        }
Esempio n. 3
0
        public void ParseTest1()
        {
            byte[] bytes = new byte[]
            {
                0x00, 0x01, 0x00, 0x58,                 //     Request 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, 0x10,                 //     SOFTWARE attribute header
                0x53, 0x54, 0x55, 0x4e,                 //  }
                0x20, 0x74, 0x65, 0x73,                 //  }  User-agent...
                0x74, 0x20, 0x63, 0x6c,                 //  }  ...name
                0x69, 0x65, 0x6e, 0x74,                 //  }
                0x00, 0x24, 0x00, 0x04,                 //     PRIORITY attribute header
                0x6e, 0x00, 0x01, 0xff,                 //     ICE priority value
                0x80, 0x29, 0x00, 0x08,                 //     ICE-CONTROLLED attribute header
                0x93, 0x2f, 0xf9, 0xb1,                 //  }  Pseudo-random tie breaker...
                0x51, 0x26, 0x3b, 0x36,                 //  }   ...for ICE control
                0x00, 0x06, 0x00, 0x09,                 //     USERNAME attribute header
                0x65, 0x76, 0x74, 0x6a,                 //  }
                0x3a, 0x68, 0x36, 0x76,                 //  }  Username (9 bytes) and padding (3 bytes)
                0x59, 0x20, 0x20, 0x20,                 //  }
                0x00, 0x08, 0x00, 0x14,                 //     MESSAGE-INTEGRITY attribute header
                0x9a, 0xea, 0xa7, 0x0c,                 //  }
                0xbf, 0xd8, 0xcb, 0x56,                 //  }
                0x78, 0x1e, 0xf2, 0xb5,                 //  }  HMAC-SHA1 fingerprint
                0xb2, 0xd3, 0xf2, 0x49,                 //  }
                0xc1, 0xb5, 0x71, 0xa2,                 //  }
                0x80, 0x28, 0x00, 0x04,                 //     FINGERPRINT attribute header
                0xe5, 0x7a, 0x3b, 0xcf,                 //     CRC32 fingerprint
            };

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

            Assert.AreEqual(@"evtj:h6vY", message.Username.Value);
            Assert.AreEqual(@"STUN test client", message.Software.Value);

            byte[] messageIntegrity = message.ComputeMessageIntegrity(@"VOkJxbRl1RmTxUk/WvJxBt", false);

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

            uint fingerprint = message.ComputeFingerprint();

            Assert.AreEqual(fingerprint, message.Fingerprint.Value);
        }
Esempio n. 4
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);
        }