2 // Mono.Security.Protocol.Ntlm.ChallengeResponseTest
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell (http://www.novell.com)
14 using Mono.Security.Protocol.Ntlm;
15 using NUnit.Framework;
17 namespace MonoTests.Mono.Security.Protocol.Ntlm {
20 public class ChallengeResponseTest {
23 // Example from http://www.innovation.ch/java/ntlm.html
24 public void BeeblebroxSrvNonce ()
26 byte[] SrvNonce = Encoding.ASCII.GetBytes ("SrvNonce");
27 using (ChallengeResponse ntlm = new ChallengeResponse ("Beeblebrox", SrvNonce)) {
28 Assert.AreEqual ("E0-E0-0D-E3-10-4A-1B-F2-05-3F-07-C7-DD-A8-2D-3C-48-9A-E9-89-E1-B0-00-D3", BitConverter.ToString (ntlm.NT), "NT");
29 Assert.AreEqual ("AD-87-CA-6D-EF-E3-46-85-B9-C4-3C-47-7A-8C-42-D6-00-66-7D-68-92-E7-E8-97", BitConverter.ToString (ntlm.LM), "LM");
34 // Example from http://packetstormsecurity.nl/Crackers/NT/l0phtcrack/l0phtcrack2.5-readme.html
35 public void L0phtCrack ()
37 byte[] SrvNonce = new byte [8] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
38 using (ChallengeResponse ntlm = new ChallengeResponse ("WELCOME", SrvNonce)) {
39 Assert.AreEqual ("7A-CE-90-85-AB-CC-37-59-38-0B-1C-68-62-E3-98-C3-C0-EF-9C-FC-22-E8-A2-C2", BitConverter.ToString (ntlm.NT), "NT");
40 Assert.AreEqual ("CA-12-00-72-3C-41-D5-77-AB-18-C7-64-C6-DE-F3-4F-A6-1B-FA-06-71-EA-5F-C8", BitConverter.ToString (ntlm.LM), "LM");
45 public void NullPassword ()
47 byte[] SrvNonce = new byte [8] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
48 using (ChallengeResponse ntlm = new ChallengeResponse (null, SrvNonce)) {
49 Assert.AreEqual ("4A-FD-81-EC-01-87-E8-8D-97-77-8D-F7-93-C6-DA-D4-F0-3A-36-63-66-9D-20-1C", BitConverter.ToString (ntlm.NT), "NT");
50 // note the last 8 bytes... they are the same as the previous unit test ;-)
51 Assert.AreEqual ("0A-39-2B-11-CF-05-2B-02-6D-65-CF-F5-68-BD-E4-15-A6-1B-FA-06-71-EA-5F-C8", BitConverter.ToString (ntlm.LM), "LM");
56 public void EmptyPassword ()
58 byte[] SrvNonce = new byte [8] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
59 using (ChallengeResponse ntlm = new ChallengeResponse (String.Empty, SrvNonce)) {
60 // same as the previous one as this is the same (null/empty) password expressed diffently
61 Assert.AreEqual ("4A-FD-81-EC-01-87-E8-8D-97-77-8D-F7-93-C6-DA-D4-F0-3A-36-63-66-9D-20-1C", BitConverter.ToString (ntlm.NT), "NT");
62 Assert.AreEqual ("0A-39-2B-11-CF-05-2B-02-6D-65-CF-F5-68-BD-E4-15-A6-1B-FA-06-71-EA-5F-C8", BitConverter.ToString (ntlm.LM), "LM");
67 public void NoPropertiesOutput ()
69 ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
71 Assert.IsNull (ntlm.Password, "Password");
72 Assert.IsNull (ntlm.Challenge, "Challenge");
76 [ExpectedException (typeof (ArgumentNullException))]
77 public void Challenge_Null ()
79 ChallengeResponse ntlm = new ChallengeResponse ();
80 ntlm.Challenge = null;
84 [ExpectedException (typeof (ObjectDisposedException))]
85 public void Password_Disposed ()
87 ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
89 ntlm.Password = "Mini";
93 [ExpectedException (typeof (ObjectDisposedException))]
94 public void Challenge_Disposed ()
96 ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
98 ntlm.Challenge = new byte [8];
102 [ExpectedException (typeof (ObjectDisposedException))]
103 public void NT_Disposed ()
105 ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
107 Assert.IsNotNull (ntlm.NT, "NT");
111 [ExpectedException (typeof (ObjectDisposedException))]
112 public void LM_Disposed ()
114 ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
116 Assert.IsNotNull (ntlm.LM, "LM");