Exemplo n.º 1
0
        public void ParseXORMappedAddressAttributeTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            byte[] stunAttribute = new byte[] { 0x00, 0x01, 0xe0, 0xda, 0xe1, 0xba, 0x85, 0x3f };

            STUNXORAddressAttribute xorAddressAttribute = new STUNXORAddressAttribute(STUNAttributeTypesEnum.XORMappedAddress, stunAttribute);

            Assert.Equal(49608, xorAddressAttribute.Port);
            Assert.Equal("192.168.33.125", xorAddressAttribute.Address.ToString());
        }
Exemplo n.º 2
0
        public void ParseCoturnSTUNResponseTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            byte[] stunResp = new byte[] { 0x01, 0x01, 0x00, 0x44, 0x21, 0x12, 0xa4, 0x42, 0x6b, 0x4c, 0xf3, 0x18, 0xd0, 0xa7, 0xf5, 0x40,
                                           0x97, 0x30, 0x3a, 0x27, 0x00, 0x20, 0x00, 0x08, 0x00, 0x01, 0x9e, 0x90, 0x1a, 0xb5, 0x08, 0xf3,
                                           0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0xbf, 0x82, 0x3b, 0xa7, 0xac, 0xb1, 0x80, 0x2b, 0x00, 0x08,
                                           0x00, 0x01, 0x0d, 0x96, 0x67, 0x1d, 0x42, 0xf3, 0x80, 0x22, 0x00, 0x1a, 0x43, 0x6f, 0x74, 0x75,
                                           0x72, 0x6e, 0x2d, 0x34, 0x2e, 0x35, 0x2e, 0x30, 0x2e, 0x33, 0x20, 0x27, 0x64, 0x61, 0x6e, 0x20,
                                           0x45, 0x69, 0x64, 0x65, 0x72, 0x27, 0x77, 0x75 };

            STUNMessage stunMessage = STUNMessage.ParseSTUNMessage(stunResp, stunResp.Length);

            STUNHeader stunHeader = stunMessage.Header;

            logger.LogDebug("Request type = " + stunHeader.MessageType + ".");
            logger.LogDebug("Length = " + stunHeader.MessageLength + ".");
            logger.LogDebug("Transaction ID = " + BitConverter.ToString(stunHeader.TransactionId) + ".");

            foreach (STUNAttribute attribute in stunMessage.Attributes)
            {
                if (attribute.AttributeType == STUNAttributeTypesEnum.MappedAddress)
                {
                    STUNAddressAttribute addressAttribute = new STUNAddressAttribute(attribute.Value);
                    logger.LogDebug(" " + attribute.AttributeType + " " + addressAttribute.Address + ":" + addressAttribute.Port + ".");

                    Assert.Equal("59.167.172.177", addressAttribute.Address.ToString());
                    Assert.Equal(49026, addressAttribute.Port);
                }
                else if (attribute.AttributeType == STUNAttributeTypesEnum.XORMappedAddress)
                {
                    STUNXORAddressAttribute xorAddressAttribute = new STUNXORAddressAttribute(STUNAttributeTypesEnum.XORMappedAddress, attribute.Value);
                    logger.LogDebug(" " + attribute.AttributeType + " " + xorAddressAttribute.Address + ":" + xorAddressAttribute.Port + ".");

                    Assert.Equal("59.167.172.177", xorAddressAttribute.Address.ToString());
                    Assert.Equal(49026, xorAddressAttribute.Port);
                }

                else
                {
                    logger.LogDebug(" " + attribute.AttributeType + " " + attribute.Value + ".");
                }
            }

            Assert.Equal(STUNMessageTypesEnum.BindingSuccessResponse, stunHeader.MessageType);
        }
Exemplo n.º 3
0
        public void PutXORMappedAddressAttributeToBufferTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            STUNXORAddressAttribute xorAddressAttribute = new STUNXORAddressAttribute(STUNAttributeTypesEnum.XORMappedAddress, 49608, IPAddress.Parse("192.168.33.125"));

            byte[] buffer = new byte[12];
            xorAddressAttribute.ToByteBuffer(buffer, 0);

            Assert.Equal(0x00, buffer[0]);
            Assert.Equal(0x20, buffer[1]);
            Assert.Equal(0x00, buffer[2]);
            Assert.Equal(0x08, buffer[3]);
            Assert.Equal(0x00, buffer[4]);
            Assert.Equal(0x01, buffer[5]);
            Assert.Equal(0xe0, buffer[6]);
            Assert.Equal(0xda, buffer[7]);
            Assert.Equal(0xe1, buffer[8]);
            Assert.Equal(0xba, buffer[9]);
            Assert.Equal(0x85, buffer[10]);
            Assert.Equal(0x3f, buffer[11]);
        }