1 //
2 // Mono.Security.Protocol.Ntlm.ChallengeResponseTest
3 //
4 // Author:
5 //	Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell (http://www.novell.com)
9 //
10 
11 using System;
12 using System.Text;
13 
14 using Mono.Security.Protocol.Ntlm;
15 using NUnit.Framework;
16 
17 namespace MonoTests.Mono.Security.Protocol.Ntlm {
18 
19 	[TestFixture]
20 	public class ChallengeResponseTest {
21 
22 		[Test]
23 		// Example from http://www.innovation.ch/java/ntlm.html
BeeblebroxSrvNonce()24 		public void BeeblebroxSrvNonce ()
25 		{
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");
30 			}
31 		}
32 
33 		[Test]
34 		// Example from http://packetstormsecurity.nl/Crackers/NT/l0phtcrack/l0phtcrack2.5-readme.html
L0phtCrack()35 		public void L0phtCrack ()
36 		{
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");
41 			}
42 		}
43 
44 		[Test]
NullPassword()45 		public void NullPassword ()
46 		{
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");
52 			}
53 		}
54 
55 		[Test]
EmptyPassword()56 		public void EmptyPassword ()
57 		{
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");
63 			}
64 		}
65 
66 		[Test]
NoPropertiesOutput()67 		public void NoPropertiesOutput ()
68 		{
69 			ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
70 			// no out!
71 			Assert.IsNull (ntlm.Password, "Password");
72 			Assert.IsNull (ntlm.Challenge, "Challenge");
73 		}
74 
75 		[Test]
76 		[ExpectedException (typeof (ArgumentNullException))]
Challenge_Null()77 		public void Challenge_Null ()
78 		{
79 			ChallengeResponse ntlm = new ChallengeResponse ();
80 			ntlm.Challenge = null;
81 		}
82 
83 		[Test]
84 		[ExpectedException (typeof (ObjectDisposedException))]
Password_Disposed()85 		public void Password_Disposed ()
86 		{
87 			ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
88 			ntlm.Dispose ();
89 			ntlm.Password = "Mini";
90 		}
91 
92 		[Test]
93 		[ExpectedException (typeof (ObjectDisposedException))]
Challenge_Disposed()94 		public void Challenge_Disposed ()
95 		{
96 			ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
97 			ntlm.Dispose ();
98 			ntlm.Challenge = new byte [8];
99 		}
100 
101 		[Test]
102 		[ExpectedException (typeof (ObjectDisposedException))]
NT_Disposed()103 		public void NT_Disposed ()
104 		{
105 			ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
106 			ntlm.Dispose ();
107 			Assert.IsNotNull (ntlm.NT, "NT");
108 		}
109 
110 		[Test]
111 		[ExpectedException (typeof (ObjectDisposedException))]
LM_Disposed()112 		public void LM_Disposed ()
113 		{
114 			ChallengeResponse ntlm = new ChallengeResponse ("Mono", new byte [8]);
115 			ntlm.Dispose ();
116 			Assert.IsNotNull (ntlm.LM, "LM");
117 		}
118 	}
119 }
120