Exemplo n.º 1
0
        static void AssertDecode(byte[] buffer, bool unicode)
        {
            var channelBinding = new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
            var timestamp      = DateTime.FromFileTimeUtc(132737136905945346);
            var targetInfo     = new NtlmTargetInfo(buffer, 0, buffer.Length, unicode);

            //var buffer1 = targetInfo.Encode (true);
            //var csharp = ToCSharpByteArrayInitializer ("NtlmTargetInfoUnorderedUnicode", buffer1);

            Assert.AreEqual("ServerName", targetInfo.ServerName);
            Assert.AreEqual("DomainName", targetInfo.DomainName);
            Assert.AreEqual("DnsServerName", targetInfo.DnsServerName);
            Assert.AreEqual("DnsDomainName", targetInfo.DnsDomainName);
            Assert.AreEqual("DnsTreeName", targetInfo.DnsTreeName);
            Assert.AreEqual(2, targetInfo.Flags, "Flags");
            Assert.AreEqual(timestamp.ToFileTimeUtc(), targetInfo.Timestamp, "Timestamp");
            //Assert.AreEqual ("SingleHost", targetInfo.SingleHost);
            Assert.AreEqual(16, targetInfo.ChannelBinding.Length, "ChannelBinding");

            for (int i = 0; i < channelBinding.Length; i++)
            {
                Assert.AreEqual(channelBinding[i], targetInfo.ChannelBinding[i], $"ChannelBinding[{i}]");
            }

            // Verify that re-encoding the target info results in an exact replica of the input.
            var encoded = targetInfo.Encode(unicode);

            Assert.AreEqual(buffer.Length, encoded.Length, "Re-encoded lengths do not match");

            for (int i = 0; i < buffer.Length; i++)
            {
                Assert.AreEqual(buffer[i], encoded[i], $"encoded[{i}]");
            }
        }
Exemplo n.º 2
0
        public void TestRemovingAttributes()
        {
            var channelBinding = new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
            var timestamp      = DateTime.FromFileTimeUtc(132737136905945346);
            var singleHost     = GenerateSingleHostData();
            var targetInfo     = new NtlmTargetInfo {
                ServerName     = "ServerName",
                DomainName     = "DomainName",
                SingleHost     = singleHost.Encode(),
                Flags          = 2,
                Timestamp      = timestamp.ToFileTimeUtc(),
                ChannelBinding = channelBinding
            };

            Assert.AreEqual("ServerName", targetInfo.ServerName);
            Assert.AreEqual("DomainName", targetInfo.DomainName);
            AssertSingleHost(singleHost, targetInfo.SingleHost, "SingleHost");
            Assert.AreEqual(2, targetInfo.Flags, "Flags");
            Assert.AreEqual(timestamp.ToFileTimeUtc(), targetInfo.Timestamp, "Timestamp");
            Assert.AreEqual(16, targetInfo.ChannelBinding.Length, "ChannelBinding");

            for (int i = 0; i < channelBinding.Length; i++)
            {
                Assert.AreEqual(channelBinding[i], targetInfo.ChannelBinding[i], $"ChannelBinding[{i}]");
            }

            targetInfo.ServerName = null;
            Assert.IsNull(targetInfo.ServerName, "SserverName remove attempt #1");
            targetInfo.ServerName = null;
            Assert.IsNull(targetInfo.ServerName, "ServerNamet remove attempt #2");

            targetInfo.SingleHost = null;
            Assert.IsNull(targetInfo.SingleHost, "SingleHost remove attempt #1");
            targetInfo.SingleHost = null;
            Assert.IsNull(targetInfo.SingleHost, "SingleHost remove attempt #2");

            targetInfo.Flags = null;
            Assert.IsNull(targetInfo.Flags, "Flags remove attempt #1");
            targetInfo.Flags = null;
            Assert.IsNull(targetInfo.Flags, "Flags remove attempt #2");

            targetInfo.Timestamp = null;
            Assert.IsNull(targetInfo.Timestamp, "Timestamp remove attempt #1");
            targetInfo.Timestamp = null;
            Assert.IsNull(targetInfo.Timestamp, "Timestamp remove attempt #2");

            targetInfo.ChannelBinding = null;
            Assert.IsNull(targetInfo.ChannelBinding, "ChannelBinding remove attempt #1");
            targetInfo.ChannelBinding = null;
            Assert.IsNull(targetInfo.ChannelBinding, "ChannelBinding remove attempt #2");
        }
Exemplo n.º 3
0
        public void TestUpdatingAttributes()
        {
            var channelBinding    = new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
            var timestamp         = DateTime.FromFileTimeUtc(132737136905945346);
            var updatedSingleHost = GenerateSingleHostData();
            var singleHost        = GenerateSingleHostData();
            var targetInfo        = new NtlmTargetInfo {
                ServerName     = "ServerName",
                DomainName     = "DomainName",
                SingleHost     = singleHost.Encode(),
                Flags          = 2,
                Timestamp      = timestamp.ToFileTimeUtc(),
                ChannelBinding = channelBinding
            };

            Assert.AreEqual("ServerName", targetInfo.ServerName);
            Assert.AreEqual("DomainName", targetInfo.DomainName);
            AssertSingleHost(singleHost, targetInfo.SingleHost, "SingleHost");
            Assert.AreEqual(2, targetInfo.Flags, "Flags");
            Assert.AreEqual(timestamp.ToFileTimeUtc(), targetInfo.Timestamp, "Timestamp");
            Assert.AreEqual(16, targetInfo.ChannelBinding.Length, "ChannelBinding");

            for (int i = 0; i < channelBinding.Length; i++)
            {
                Assert.AreEqual(channelBinding[i], targetInfo.ChannelBinding[i], $"ChannelBinding[{i}]");
            }

            targetInfo.ServerName = "NewServerName";
            Assert.AreEqual("NewServerName", targetInfo.ServerName, "Updated ServerName");

            targetInfo.SingleHost = updatedSingleHost.Encode();
            AssertSingleHost(updatedSingleHost, targetInfo.SingleHost, "Updated SingleHost");

            targetInfo.Flags = 1;
            Assert.AreEqual(1, targetInfo.Flags, "Updated Flags");

            targetInfo.Timestamp = 123456789;
            Assert.AreEqual(123456789, targetInfo.Timestamp, "Updated Timestamp");

            targetInfo.ChannelBinding = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
            Assert.AreEqual(20, targetInfo.ChannelBinding.Length, "Updated ChannelBinding");

            for (int i = 0; i < channelBinding.Length; i++)
            {
                Assert.AreEqual(i, targetInfo.ChannelBinding[i], $"Updated ChannelBinding[{i}]");
            }
        }