public void TestNtlmTargetInfoEncode ()
		{
			var now = DateTime.Now.Ticks;

			var targetInfo = new TargetInfo {
				DomainName = "DOMAIN",
				ServerName = "SERVER",
				DnsDomainName = "domain.com",
				DnsServerName = "server.domain.com",
				Timestamp = now,
			};

			var encoded = targetInfo.Encode (true);
			var decoded = new TargetInfo (encoded, 0, encoded.Length, true);

			Assert.AreEqual (targetInfo.DnsDomainName, decoded.DnsDomainName, "DnsDomainName does not match.");
			Assert.AreEqual (targetInfo.DnsServerName, decoded.DnsServerName, "DnsServerName does not match.");
			Assert.AreEqual (targetInfo.DomainName, decoded.DomainName, "DomainName does not match.");
			Assert.AreEqual (targetInfo.ServerName, decoded.ServerName, "ServerName does not match.");
			Assert.AreEqual (targetInfo.Timestamp, decoded.Timestamp, "Timestamp does not match.");
		}
Beispiel #2
0
		void Decode (byte[] message, int startIndex, int length)
		{
			ValidateArguments (message, startIndex, length);

			Flags = (NtlmFlags) BitConverterLE.ToUInt32 (message, startIndex + 20);

			Buffer.BlockCopy (message, startIndex + 24, nonce, 0, 8);

			var targetNameLength = BitConverterLE.ToUInt16 (message, startIndex + 12);
			var targetNameOffset = BitConverterLE.ToUInt16 (message, startIndex + 16);

			if (targetNameLength > 0) {
				var encoding = (Flags & NtlmFlags.NegotiateOem) != 0 ? Encoding.UTF8 : Encoding.Unicode;

				TargetName = encoding.GetString (message, startIndex + targetNameOffset, targetNameLength);
			}

			// The Target Info block is optional.
			if (message.Length >= 48 && targetNameOffset >= 48) {
				var targetInfoLength = BitConverterLE.ToUInt16 (message, startIndex + 40);
				var targetInfoOffset = BitConverterLE.ToUInt16 (message, startIndex + 44);

				if (targetInfoLength > 0 && targetInfoOffset < message.Length && targetInfoLength <= (message.Length - targetInfoOffset)) {
					TargetInfo = new TargetInfo (message, startIndex + targetInfoOffset, targetInfoLength, (Flags & NtlmFlags.NegotiateUnicode) != 0);

					targetInfo = new byte[targetInfoLength];
					Buffer.BlockCopy (message, startIndex + targetInfoOffset, targetInfo, 0, targetInfoLength);
				}
			}
		}