public void TestNtlmType1MessageEncode() { var type1 = new Type1Message("Workstation", "Domain", new Version(5, 0, 2195)); var encoded = type1.Encode(); string actual, expected; expected = HexEncode(NtlmType1EncodedMessage); actual = HexEncode(encoded); Assert.AreEqual(expected, actual, "The encoded Type1Message did not match the expected result."); }
/// <summary> /// Parses the server's challenge token and returns the next challenge response. /// </summary> /// <remarks> /// Parses the server's challenge token and returns the next challenge response. /// </remarks> /// <returns>The next challenge response.</returns> /// <param name="token">The server's challenge token.</param> /// <param name="startIndex">The index into the token specifying where the server's challenge begins.</param> /// <param name="length">The length of the server's challenge.</param> /// <exception cref="System.InvalidOperationException"> /// The SASL mechanism is already authenticated. /// </exception> /// <exception cref="SaslException"> /// An error has occurred while parsing the server's challenge token. /// </exception> protected override byte[] Challenge(byte[] token, int startIndex, int length) { if (IsAuthenticated) { throw new InvalidOperationException(); } string userName = Credentials.UserName; string domain = Credentials.Domain; MessageBase message; if (string.IsNullOrEmpty(domain)) { int index = userName.IndexOf('\\'); if (index == -1) { index = userName.IndexOf('/'); } if (index >= 0) { domain = userName.Substring(0, index); userName = userName.Substring(index + 1); } } switch (state) { case LoginState.Initial: message = new Type1Message(Workstation, domain); state = LoginState.Challenge; break; case LoginState.Challenge: var password = Credentials.Password ?? string.Empty; message = GetChallengeResponse(userName, password, token, startIndex, length); IsAuthenticated = true; break; default: throw new IndexOutOfRangeException("state"); } return(message.Encode()); }