media: fix relay candidate raddr and rport
[siplcs.git] / src / core / sip-sec-ntlm-tests.c
blob15bead37b9710f9b472ca8603f39153a4fadb9b9
1 /**
2 * @file sipe-sec-ntlm-tests.c
4 * pidgin-sipe
6 * Copyright (C) 2011-12 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2010 pier11 <pier11@operamail.com>
8 * Copyright (C) 2008 Novell, Inc.
10 * Implemented with reference to the follow documentation:
11 * - http://davenport.sourceforge.net/ntlm.html
12 * - MS-NLMP: http://msdn.microsoft.com/en-us/library/cc207842.aspx
13 * - MS-SIP : http://msdn.microsoft.com/en-us/library/cc246115.aspx
15 * Please use "make tests" to build & run them!
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
36 #include <stdlib.h>
38 #include <glib.h>
39 #include <glib/gprintf.h>
41 #include "sipmsg.h"
42 #include "sipe-sign.h"
43 #define _SIPE_COMPILING_TESTS
44 #include "sip-sec-ntlm.c"
46 #include "uuid.h"
48 static int successes = 0;
49 static int failures = 0;
51 gboolean sip_sec_ntlm_tests(void);
53 static void assert_equal(const char * expected, gpointer got, int len, gboolean stringify)
55 const gchar * res = (gchar *) got;
56 gchar to_str[len*2 + 1];
58 if (stringify) {
59 const guint8 *bin = got;
60 int i, j;
61 for (i = 0, j = 0; i < len; i++, j+=2) {
62 g_sprintf(&to_str[j], "%02X", (bin[i]&0xff));
64 len *= 2;
65 res = to_str;
68 printf("expected: %s\n", expected);
69 printf("received: %s\n", res);
71 if (g_ascii_strncasecmp(expected, res, len) == 0) {
72 successes++;
73 printf("PASSED\n");
74 } else {
75 failures++;
76 printf("FAILED\n");
80 /* NOTE: both values are expected to be in host byte order! */
81 static void assert_equal_guint32(guint32 expected, guint32 got)
83 printf("expected: %08X\n", expected);
84 printf("received: %08X\n", got);
86 if (expected == got) {
87 successes++;
88 printf("PASSED\n");
89 } else {
90 failures++;
91 printf("FAILED\n");
95 gboolean sip_sec_ntlm_tests(void)
97 const char *password;
98 const char *user;
99 const char *domain;
100 const guchar *client_challenge;
101 const guchar *nonce;
102 const guchar *exported_session_key;
103 const guchar *text;
104 guchar md4 [16];
105 guchar md5 [16];
106 guchar hmac_md5 [16];
107 guint32 flags;
108 guchar response_key_lm [16];
109 guchar response_key_nt [16];
110 guchar nt_challenge_response [24];
111 guchar lm_challenge_response [24];
112 guchar session_base_key [16];
113 guchar key_exchange_key [16];
114 guchar encrypted_random_session_key [16];
115 guint32 crc;
116 guchar client_seal_key [16];
117 guchar client_sign_key [16];
118 guchar server_sign_key [16];
119 guchar server_seal_key [16];
120 guint32 mac [4];
121 guchar text_enc [18 + 12];
122 struct sipmsg *msg;
123 struct sipmsg_breakdown msgbd;
124 gchar *msg_str;
125 const char *password2;
126 const char *user2;
127 const char *domain2;
128 const char *host2;
129 const char *type2_hex;
130 const char *type3_hex;
131 const char *request;
132 const char *response;
133 const gchar *request_sig;
134 const gchar *response_sig;
136 printf ("Starting Tests\n");
138 /* Initialization for crypto backend (test mode) */
139 sipe_crypto_init(FALSE);
141 /* Initialization for NTLM */
142 sip_sec_init__ntlm();
144 /* These tests are from the MS-SIPE document */
146 password = "Password";
147 user = "User";
148 domain = "Domain";
149 client_challenge = (guchar *)"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa";
150 /* server challenge */
151 nonce = (guchar *)"\x01\x23\x45\x67\x89\xab\xcd\xef";
152 /* 16 bytes */
153 exported_session_key = (guchar *)"\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55";
154 text = (guchar *)"\x50\x00\x6c\x00\x61\x00\x69\x00\x6e\x00\x74\x00\x65\x00\x78\x00\x74\x00"; //P·l·a·i·n·t·e·x·t·
157 ////// internal Cyphers tests ///////
158 printf ("\nTesting MD4()\n");
159 MD4 ((const unsigned char *)"message digest", 14, md4);
160 assert_equal("D9130A8164549FE818874806E1C7014B", md4, 16, TRUE);
162 printf ("\nTesting MD5()\n");
163 MD5 ((const unsigned char *)"message digest", 14, md5);
164 assert_equal("F96B697D7CB7938D525A2F31AAF161D0", md5, 16, TRUE);
166 printf ("\nTesting HMAC_MD5()\n");
167 HMAC_MD5 ((const unsigned char *)"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16, (const unsigned char *)"Hi There", 8, hmac_md5);
168 assert_equal("9294727A3638BB1C13F48EF8158BFC9D", hmac_md5, 16, TRUE);
171 ////// NTLMv1 (without Extended Session Security) ///////
172 use_ntlm_v2 = FALSE;
174 flags = 0
175 | NTLMSSP_NEGOTIATE_KEY_EXCH
176 | NTLMSSP_NEGOTIATE_56
177 | NTLMSSP_NEGOTIATE_128
178 | NTLMSSP_NEGOTIATE_VERSION
179 | NTLMSSP_TARGET_TYPE_SERVER
180 | NTLMSSP_NEGOTIATE_ALWAYS_SIGN
181 | NTLMSSP_NEGOTIATE_NTLM
182 | NTLMSSP_NEGOTIATE_SEAL
183 | NTLMSSP_NEGOTIATE_SIGN
184 | NTLMSSP_NEGOTIATE_OEM
185 | NTLMSSP_NEGOTIATE_UNICODE;
187 printf ("\n\nTesting Negotiation Flags\n");
188 assert_equal_guint32(0xE2028233, flags);
190 printf ("\n\nTesting LMOWFv1()\n");
191 LMOWFv1 (password, user, domain, response_key_lm);
192 assert_equal("E52CAC67419A9A224A3B108F3FA6CB6D", response_key_lm, 16, TRUE);
194 printf ("\n\nTesting NTOWFv1()\n");
195 NTOWFv1 (password, user, domain, response_key_nt);
196 assert_equal("A4F49C406510BDCAB6824EE7C30FD852", response_key_nt, 16, TRUE);
198 printf ("\n\nTesting LM Response Generation\n");
199 printf ("Testing NT Response Generation\n");
200 printf ("Testing Session Base Key\n");
202 compute_response(flags,
203 response_key_nt,
204 response_key_lm,
205 nonce,
206 client_challenge,
208 NULL, /* target_info */
209 0, /* target_info_len */
210 lm_challenge_response, /* out */
211 nt_challenge_response, /* out */
212 session_base_key); /* out */
214 assert_equal("98DEF7B87F88AA5DAFE2DF779688A172DEF11C7D5CCDEF13", lm_challenge_response, 24, TRUE);
215 assert_equal("67C43011F30298A2AD35ECE64F16331C44BDBED927841F94", nt_challenge_response, 24, TRUE);
216 assert_equal("D87262B0CDE4B1CB7499BECCCDF10784", session_base_key, 16, TRUE);
218 printf ("\n\nTesting Key Exchange Key\n");
219 KXKEY(flags, session_base_key, lm_challenge_response, nonce, key_exchange_key);
220 assert_equal("D87262B0CDE4B1CB7499BECCCDF10784", key_exchange_key, 16, TRUE);
222 printf ("\n\nTesting Encrypted Session Key Generation\n");
223 RC4K (key_exchange_key, 16, exported_session_key, 16, encrypted_random_session_key);
224 assert_equal("518822B1B3F350C8958682ECBB3E3CB7", encrypted_random_session_key, 16, TRUE);
226 printf ("\n\nTesting CRC32\n");
227 crc = CRC32((char*)text, 18);
228 assert_equal_guint32(0x93AA847D, crc);
230 printf ("\n\nTesting Encryption\n");
232 //SEALKEY (flags, exported_session_key, TRUE, client_seal_key);
233 guchar buff [18 + 12];
234 guint32 to_enc [3];
236 memcpy(buff, text, 18);
237 to_enc[0] = GUINT32_TO_LE(0); // random pad
238 to_enc[1] = GUINT32_TO_LE(crc);
239 to_enc[2] = GUINT32_TO_LE(0); // zero
240 memcpy(buff+18, (gchar *)to_enc, 12);
241 RC4K (exported_session_key, 16, buff, 18 + 12, text_enc);
242 //The point is to not reinitialize rc4 cypher
243 // 0 crc 0 (zero)
244 assert_equal("56FE04D861F9319AF0D7238A2E3B4D457FB8" "45C844E5" "09DCD1DF" "2E459D36", text_enc, 18 + 12, TRUE);
247 printf ("\n\nTesting MAC\n");
249 // won't work in the case with sealing because RC4 is re-initialized inside.
250 // MAC (flags, (gchar*)text, 18, (guchar*)exported_session_key, 16, (guchar*)exported_session_key,16, 0x00000000, 0, mac);
251 guint32 enc [3];
252 guint32 mac2 [4];
254 memcpy((gchar *)enc, text_enc+18, 12);
255 mac2 [0] = GUINT32_TO_LE(1); // version
256 mac2 [1] = enc [0];
257 mac2 [2] = enc [1];
258 mac2 [3] = enc [2] ^ (GUINT32_TO_LE(0)); // ^ seq
259 assert_equal("0100000045C844E509DCD1DF2E459D36", (guchar*)mac2, 16, TRUE);
263 ////// EXTENDED_SESSIONSECURITY ///////
264 use_ntlm_v2 = FALSE;
265 flags = 0
266 | NTLMSSP_NEGOTIATE_56
267 | NTLMSSP_NEGOTIATE_VERSION
268 | NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY
269 | NTLMSSP_TARGET_TYPE_SERVER
270 | NTLMSSP_NEGOTIATE_ALWAYS_SIGN
271 | NTLMSSP_NEGOTIATE_NTLM
272 | NTLMSSP_NEGOTIATE_SEAL
273 | NTLMSSP_NEGOTIATE_SIGN
274 | NTLMSSP_NEGOTIATE_OEM
275 | NTLMSSP_NEGOTIATE_UNICODE;
277 printf ("\n\n(Extended session security) Testing Negotiation Flags\n");
278 assert_equal_guint32(0x820A8233, flags);
280 /* NTOWFv1() is not different from the above test for the same */
282 printf ("\n\n(Extended session security) Testing LM Response\n");
283 printf ("(Extended session security) Testing NT Response\n");
284 printf ("(Extended session security) Testing Session Base Key\n");
285 compute_response(flags,
286 response_key_nt,
287 response_key_lm,
288 nonce,
289 client_challenge,
291 NULL, /* target_info */
292 0, /* target_info_len */
293 lm_challenge_response, /* out */
294 nt_challenge_response, /* out */
295 session_base_key); /* out */
297 assert_equal("AAAAAAAAAAAAAAAA00000000000000000000000000000000", lm_challenge_response, 24, TRUE);
298 assert_equal("7537F803AE367128CA458204BDE7CAF81E97ED2683267232", nt_challenge_response, 24, TRUE);
299 assert_equal("D87262B0CDE4B1CB7499BECCCDF10784", session_base_key, 16, TRUE);
301 printf ("\n\n(Extended session security) Testing Key Exchange Key\n");
302 KXKEY(flags, session_base_key, lm_challenge_response, nonce, key_exchange_key);
303 assert_equal("EB93429A8BD952F8B89C55B87F475EDC", key_exchange_key, 16, TRUE);
305 printf ("\n\n(Extended session security) SIGNKEY\n");
306 SIGNKEY (key_exchange_key, TRUE, client_sign_key);
307 assert_equal("60E799BE5C72FC92922AE8EBE961FB8D", client_sign_key, 16, TRUE);
309 printf ("\n\n(Extended session security) SEALKEY\n");
310 SEALKEY (flags, key_exchange_key, TRUE, client_seal_key);
311 assert_equal("04DD7F014D8504D265A25CC86A3A7C06", client_seal_key, 16, TRUE);
313 printf ("\n\n(Extended session security) Testing Encryption\n");
314 RC4K (client_seal_key, 16, text, 18, text_enc);
315 assert_equal("A02372F6530273F3AA1EB90190CE5200C99D", text_enc, 18, TRUE);
317 printf ("\n\n(Extended session security) Testing MAC\n");
318 MAC (flags, (gchar*)text,18, client_sign_key,16, client_seal_key,16, 0, 0, mac);
319 assert_equal("01000000FF2AEB52F681793A00000000", mac, 16, TRUE);
322 ////// NTLMv2 ///////
323 use_ntlm_v2 = TRUE;
324 flags = 0
325 | NTLMSSP_NEGOTIATE_KEY_EXCH
326 | NTLMSSP_NEGOTIATE_56
327 | NTLMSSP_NEGOTIATE_128
328 | NTLMSSP_NEGOTIATE_VERSION
329 | NTLMSSP_NEGOTIATE_TARGET_INFO
330 | NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY
331 | NTLMSSP_TARGET_TYPE_SERVER
332 | NTLMSSP_NEGOTIATE_ALWAYS_SIGN
333 | NTLMSSP_NEGOTIATE_NTLM
334 | NTLMSSP_NEGOTIATE_SEAL
335 | NTLMSSP_NEGOTIATE_SIGN
336 | NTLMSSP_NEGOTIATE_OEM
337 | NTLMSSP_NEGOTIATE_UNICODE;
339 printf ("\n\nTesting (NTLMv2) Negotiation Flags\n");
340 assert_equal_guint32(0xE28A8233, flags);
342 printf ("\n\nTesting NTOWFv2()\n");
343 NTOWFv2 (password, user, domain, response_key_nt);
344 NTOWFv2 (password, user, domain, response_key_lm);
345 assert_equal("0C868A403BFD7A93A3001EF22EF02E3F", response_key_nt, 16, TRUE);
348 printf ("\n\nTesting (NTLMv2) LM Response Generation\n");
349 printf ("Testing (NTLMv2) NT Response Generation and Session Base Key\n");
351 Challenge:
352 4e544c4d53535000020000000c000c003800000033828ae20123456789abcdef00000000000000002400240044000000060070170000000f53006500720076006500720002000c0044006f006d00610069006e0001000c0053006500720076006500720000000000
354 NTLMSSP_NEGOTIATE_UNICODE
355 NTLMSSP_NEGOTIATE_OEM
356 NTLMSSP_NEGOTIATE_SIGN
357 NTLMSSP_NEGOTIATE_SEAL
358 NTLMSSP_NEGOTIATE_NTLM
359 NTLMSSP_NEGOTIATE_ALWAYS_SIGN
360 NTLMSSP_TARGET_TYPE_SERVER
361 NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY
362 NTLMSSP_NEGOTIATE_TARGET_INFO
363 NTLMSSP_NEGOTIATE_VERSION
364 NTLMSSP_NEGOTIATE_128
365 NTLMSSP_NEGOTIATE_KEY_EXCH
366 NTLMSSP_NEGOTIATE_56
367 target_name.len : 12
368 target_name.maxlen: 12
369 target_name.offset: 56
370 target_info.len : 36
371 target_info.maxlen: 36
372 target_info.offset: 68
373 product: 6.0.6000 (Windows Vista, Windows Server 2008, Windows 7 or Windows Server 2008 R2)
374 ntlm_revision_current: 0x0F (NTLMSSP_REVISION_W2K3)
375 target_name: Server
376 MsvAvNbDomainName: Domain
377 MsvAvNbComputerName: Server
379 target_name:
380 530065007200760065007200
381 target_info:
382 02000c0044006f006d00610069006e0001000c0053006500720076006500720000000000
384 Response:
385 4e544c4d5353500003000000180018006c00000054005400840000000c000c00480000000800080054000000100010005c00000010001000d8000000358288e20501280a0000000f44006f006d00610069006e00550073006500720043004f004d005000550054004500520086c35097ac9cec102554764a57cccc19aaaaaaaaaaaaaaaa68cd0ab851e51c96aabc927bebef6a1c01010000000000000000000000000000aaaaaaaaaaaaaaaa0000000002000c0044006f006d00610069006e0001000c005300650072007600650072000000000000000000c5dad2544fc9799094ce1ce90bc9d03e
390 const guint64 time_val = 0;
391 const guint8 target_info [] = {
392 0x02, 0x00, 0x0C, 0x00, //NetBIOS Domain name, 4 bytes
393 0x44, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6E, 0x00, //D.o.m.a.i.n. 12bytes
394 0x01, 0x00, 0x0C, 0x00, //NetBIOS Server name, 4 bytes
395 0x53, 0x00, 0x65, 0x00, 0x72, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00, //S.e.r.v.e.r. 12bytes
396 0x00, 0x00, 0x00, 0x00, //Av End, 4 bytes
398 const int target_info_len = 32+4;
399 int ntlmssp_nt_resp_len = (16 + (32+target_info_len));
400 guchar nt_challenge_response_v2 [ntlmssp_nt_resp_len];
402 compute_response(flags,
403 response_key_nt,
404 response_key_lm,
405 nonce,
406 client_challenge,
407 time_val,
408 target_info, /* target_info */
409 target_info_len, /* target_info_len */
410 lm_challenge_response, /* out */
411 nt_challenge_response_v2, /* out */
412 session_base_key); /* out */
414 assert_equal("86C35097AC9CEC102554764A57CCCC19AAAAAAAAAAAAAAAA", lm_challenge_response, 24, TRUE);
415 assert_equal("68CD0AB851E51C96AABC927BEBEF6A1C", nt_challenge_response_v2, 16, TRUE);
416 /* the ref string is taken from binary dump of AUTHENTICATE_MESSAGE */
417 assert_equal("68CD0AB851E51C96AABC927BEBEF6A1C01010000000000000000000000000000AAAAAAAAAAAAAAAA0000000002000C0044006F006D00610069006E0001000C005300650072007600650072000000000000000000", nt_challenge_response_v2, ntlmssp_nt_resp_len, TRUE);
418 assert_equal("8DE40CCADBC14A82F15CB0AD0DE95CA3", session_base_key, 16, TRUE);
421 printf ("\n\nTesting (NTLMv2) Encrypted Session Key\n");
422 // key_exchange_key = session_base_key for NTLMv2
423 KXKEY(flags, session_base_key, lm_challenge_response, nonce, key_exchange_key);
424 //RC4 encryption of the RandomSessionKey with the KeyExchangeKey:
425 RC4K (key_exchange_key, 16, exported_session_key, 16, encrypted_random_session_key);
426 assert_equal("C5DAD2544FC9799094CE1CE90BC9D03E", encrypted_random_session_key, 16, TRUE);
428 printf ("\n\nTesting (NTLMv2) SIGNKEY\n");
429 SIGNKEY (exported_session_key, TRUE, client_sign_key);
430 assert_equal("4788DC861B4782F35D43FD98FE1A2D39", client_sign_key, 16, TRUE);
432 printf ("\n\nTesting (NTLMv2) SEALKEY\n");
433 SEALKEY (flags, exported_session_key, TRUE, client_seal_key);
434 assert_equal("59F600973CC4960A25480A7C196E4C58", client_seal_key, 16, TRUE);
436 printf ("\n\nTesting (NTLMv2) Encryption\n");
437 RC4K (client_seal_key, 16, text, 18, text_enc);
438 assert_equal("54E50165BF1936DC996020C1811B0F06FB5F", text_enc, 18, TRUE);
440 // printf ("\n\nTesting (NTLMv2) Encryption\n");
441 //const guchar text2 [] = {0x50, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00
442 // , 0x70, 0x35, 0x28, 0x51, 0xf2, 0x56, 0x43, 0x09}; //P·l·a·i·n·t·e·x·t·
443 //guchar text_enc2 [18+8];
444 // RC4K (client_seal_key, 16, text2, 18+8, text_enc2);
445 // assert_equal("54E50165BF1936DC996020C1811B0F06FB5F", text_enc2, 18+8, TRUE);
447 printf ("\n\nTesting (NTLMv2) MAC (without RC4, as we don't keep its handle yet)\n");
448 MAC (flags & ~NTLMSSP_NEGOTIATE_KEY_EXCH, (gchar*)text,18, client_sign_key,16, client_seal_key,16, 0, 0, mac);
449 assert_equal("0100000070352851F256430900000000", mac, 16, TRUE);
452 /* End tests from the MS-SIPE document */
455 ////// davenport tests ///////
456 // Test from http://davenport.sourceforge.net/ntlm.html#ntlm1Signing
458 const gchar *text_j = "jCIFS";
459 printf ("\n\n(davenport) Testing Signature Algorithm\n");
461 guchar sk [] = {0x01, 0x02, 0x03, 0x04, 0x05, 0xe5, 0x38, 0xb0};
462 MAC (NEGOTIATE_FLAGS_CONNLESS & ~NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY, text_j, strlen(text_j), sk, 8, sk,8, 0x00090178, 0, mac);
463 assert_equal("0100000078010900397420FE0E5A0F89", mac, 16, TRUE);
466 // Tests from http://davenport.sourceforge.net/ntlm.html#ntlm2Signing
467 printf ("\n\n(davenport) SIGNKEY\n");
469 const guchar master_key [] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00};
470 SIGNKEY (master_key, TRUE, client_sign_key);
471 assert_equal("F7F97A82EC390F9C903DAC4F6ACEB132", client_sign_key, 16, TRUE);
473 printf ("\n\n(davenport) Testing MAC - no Key Exchange flag\n");
474 MAC (flags & ~NTLMSSP_NEGOTIATE_KEY_EXCH, text_j, strlen(text_j), client_sign_key, 16, client_sign_key,16, 0, 0, mac);
475 assert_equal("010000000A003602317A759A00000000", mac, 16, TRUE);
480 ////// SIPE internal tests ///////
481 // Verify signature of SIPE message received from OCS 2007 after authenticating with pidgin-sipe
482 printf ("\n\nTesting MS-SIPE Example Message Signing\n");
484 char * msg2;
485 char * msg1 = "<NTLM><0878F41B><1><SIP Communications Service><ocs1.ocs.provo.novell.com><8592g5DCBa1694i5887m0D0Bt2247b3F38xAE9Fx><3><REGISTER><sip:gabriel@ocs.provo.novell.com><2947328781><B816D65C2300A32CFA6D371F2AF537FD><900><200>";
486 guchar exported_session_key2 [] = { 0x5F, 0x02, 0x91, 0x53, 0xBC, 0x02, 0x50, 0x58, 0x96, 0x95, 0x48, 0x61, 0x5E, 0x70, 0x99, 0xBA };
488 MAC (NEGOTIATE_FLAGS_CONNLESS & ~NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY,
489 msg1, strlen(msg1), exported_session_key2, 16, exported_session_key2,16, 0, 100, mac);
490 assert_equal("0100000000000000BF2E52667DDF6DED", mac, 16, TRUE);
492 // Verify parsing of message and signature verification
493 printf ("\n\nTesting MS-SIPE Example Message Parsing, Signing, and Verification\n(Authentication Protocol Version 2)\n");
494 msg2 = "SIP/2.0 200 OK\r\nms-keep-alive: UAS; tcp=no; hop-hop=yes; end-end=no; timeout=300\r\nAuthentication-Info: NTLM rspauth=\"0100000000000000BF2E52667DDF6DED\", srand=\"0878F41B\", snum=\"1\", opaque=\"4452DFB0\", qop=\"auth\", targetname=\"ocs1.ocs.provo.novell.com\", realm=\"SIP Communications Service\"\r\nFrom: \"Gabriel Burt\"<sip:gabriel@ocs.provo.novell.com>;tag=2947328781;epid=1234567890\r\nTo: <sip:gabriel@ocs.provo.novell.com>;tag=B816D65C2300A32CFA6D371F2AF537FD\r\nCall-ID: 8592g5DCBa1694i5887m0D0Bt2247b3F38xAE9Fx\r\nCSeq: 3 REGISTER\r\nVia: SIP/2.0/TLS 164.99.194.49:10409;branch=z9hG4bKE0E37DBAF252C3255BAD;received=164.99.195.20;ms-received-port=10409;ms-received-cid=1E00\r\nContact: <sip:164.99.195.20:10409;transport=tls;ms-received-cid=1E00>;expires=900\r\nExpires: 900\r\nAllow-Events: vnd-microsoft-provisioning,vnd-microsoft-roaming-contacts,vnd-microsoft-roaming-ACL,presence,presence.wpending,vnd-microsoft-roaming-self,vnd-microsoft-provisioning-v2\r\nSupported: adhoclist\r\nServer: RTC/3.0\r\nSupported: com.microsoft.msrtc.presence\r\nContent-Length: 0\r\n\r\n";
495 msg = sipmsg_parse_msg(msg2);
497 memset(&msgbd, 0, sizeof(struct sipmsg_breakdown));
498 msgbd.msg = msg;
499 sipmsg_breakdown_parse(&msgbd, "SIP Communications Service", "ocs1.ocs.provo.novell.com", NULL);
500 msg_str = sipmsg_breakdown_get_string(2, &msgbd);
501 sip_sec_ntlm_sipe_signature_make (NEGOTIATE_FLAGS_CONNLESS & ~NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY,
502 msg_str, 0, exported_session_key2, exported_session_key2, mac);
503 sipmsg_breakdown_free(&msgbd);
504 assert_equal ("0100000000000000BF2E52667DDF6DED", mac, 16, TRUE);
505 /* sig = buff_to_hex_str((guint8 *)mac, 16); */
509 ////// real Communicator 2007 R2 tests //////
510 ////// Recreated/verifyed real authentication communication between
511 ////// Communicator 2007 R2 and Office Communications Server 2007 R2
512 ////// with SIPE NTLMv2 implementation.
514 password2 = "Pa$$word";
515 user2 = "User";
516 domain2 = "COSMO";
517 host2 = "COSMO-OCS-R2";
519 //Challenge:
520 //const char *type2 = "TlRMTVNTUAACAAAAAAAAADgAAADzgpji3Ruq9OfiGNEAAAAAAAAAAJYAlgA4AAAABQLODgAAAA8CAAoAQwBPAFMATQBPAAEAGABDAE8AUwBNAE8ALQBPAEMAUwAtAFIAMgAEABYAYwBvAHMAbQBvAC4AbABvAGMAYQBsAAMAMABjAG8AcwBtAG8ALQBvAGMAcwAtAHIAMgAuAGMAbwBzAG0AbwAuAGwAbwBjAGEAbAAFABYAYwBvAHMAbQBvAC4AbABvAGMAYQBsAAAAAAA=";
521 //in hex (base64 decoded):
522 type2_hex = "4E544C4D53535000020000000000000038000000F38298E2DD1BAAF4E7E218D1000000000000000096009600380000000502CE0E0000000F02000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C0000000000";
524 Message (length 206):
525 NTLMSSP_NEGOTIATE_UNICODE
526 NTLMSSP_NEGOTIATE_OEM
527 NTLMSSP_NEGOTIATE_SIGN
528 NTLMSSP_NEGOTIATE_SEAL
529 NTLMSSP_NEGOTIATE_DATAGRAM
530 NTLMSSP_NEGOTIATE_LM_KEY
531 NTLMSSP_NEGOTIATE_NTLM
532 NTLMSSP_NEGOTIATE_ALWAYS_SIGN
533 NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY
534 NTLMSSP_NEGOTIATE_IDENTIFY
535 NTLMSSP_NEGOTIATE_TARGET_INFO
536 NTLMSSP_NEGOTIATE_VERSION
537 NTLMSSP_NEGOTIATE_128
538 NTLMSSP_NEGOTIATE_KEY_EXCH
539 NTLMSSP_NEGOTIATE_56
540 server_challenge: DD1BAAF4E7E218D1
541 target_name.len : 0
542 target_name.maxlen: 0
543 target_name.offset: 56
544 target_info.len : 150
545 target_info.maxlen: 150
546 target_info.offset: 56
547 product: 5.2.3790 (Windows Server 2003)
548 ntlm_revision_current: 0x0F (NTLMSSP_REVISION_W2K3)
549 target_info raw: 02000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C0000000000
550 MsvAvNbDomainName: COSMO
551 MsvAvNbComputerName: COSMO-OCS-R2
552 MsvAvDnsDomainName: cosmo.local
553 MsvAvDnsComputerName: cosmo-ocs-r2.cosmo.local
554 MsvAvDnsTreeName: cosmo.local
558 //Response:
559 //const char *type3 = "TlRMTVNTUAADAAAAGAAYAHIAAADGAMYAigAAAAoACgBIAAAACAAIAFIAAAAYABgAWgAAABAAEABQAQAAVYKYYgUCzg4AAAAPQwBPAFMATQBPAFUAcwBlAHIAQwBPAFMATQBPAC0ATwBDAFMALQBSADIAoeku/k4Hi/fFwASazGFmwtauh1yw/apBjcDIAK527KYG0rn769BHMQEBAAAAAAAAWVGaFye5ygHWrodcsP2qQQAAAAACAAoAQwBPAFMATQBPAAEAGABDAE8AUwBNAE8ALQBPAEMAUwAtAFIAMgAEABYAYwBvAHMAbQBvAC4AbABvAGMAYQBsAAMAMABjAG8AcwBtAG8ALQBvAGMAcwAtAHIAMgAuAGMAbwBzAG0AbwAuAGwAbwBjAGEAbAAFABYAYwBvAHMAbQBvAC4AbABvAGMAYQBsAAAAAAAAAAAAMctznhyoCkmFkeiueXEV5A==";
560 //in hex (base64 decoded):
561 type3_hex = "4E544C4D53535000030000001800180072000000C600C6008A0000000A000A00480000000800080052000000180018005A0000001000100050010000558298620502CE0E0000000F43004F0053004D004F00550073006500720043004F0053004D004F002D004F00430053002D0052003200A1E92EFE4E078BF7C5C0049ACC6166C2D6AE875CB0FDAA418DC0C800AE76ECA606D2B9FBEBD04731010100000000000059519A1727B9CA01D6AE875CB0FDAA410000000002000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C00000000000000000031CB739E1CA80A498591E8AE797115E4";
563 Message (length 352):
564 NTLMSSP_NEGOTIATE_UNICODE
565 NTLMSSP_REQUEST_TARGET
566 NTLMSSP_NEGOTIATE_SIGN
567 NTLMSSP_NEGOTIATE_DATAGRAM
568 NTLMSSP_NEGOTIATE_NTLM
569 NTLMSSP_NEGOTIATE_ALWAYS_SIGN
570 NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY
571 NTLMSSP_NEGOTIATE_IDENTIFY
572 NTLMSSP_NEGOTIATE_TARGET_INFO
573 NTLMSSP_NEGOTIATE_VERSION
574 NTLMSSP_NEGOTIATE_128
575 NTLMSSP_NEGOTIATE_KEY_EXCH
576 lm_resp.len : 24
577 lm_resp.maxlen: 24
578 lm_resp.offset: 114
579 nt_resp.len : 198
580 nt_resp.maxlen: 198
581 nt_resp.offset: 138
582 domain.len : 10
583 domain.maxlen: 10
584 domain.offset: 72
585 user.len : 8
586 user.maxlen: 8
587 user.offset: 82
588 host.len : 24
589 host.maxlen: 24
590 host.offset: 90
591 session_key.len : 16
592 session_key.maxlen: 16
593 session_key.offset: 336
594 product: 5.2.3790 (Windows Server 2003)
595 ntlm_revision_current: 0x0F (NTLMSSP_REVISION_W2K3)
596 lm_resp: A1E92EFE4E078BF7C5C0049ACC6166C2D6AE875CB0FDAA41
597 nt_resp raw: 8DC0C800AE76ECA606D2B9FBEBD04731010100000000000059519A1727B9CA01D6AE875CB0FDAA410000000002000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C000000000000000000
598 nt_resp: 8DC0C800AE76ECA606D2B9FBEBD04731
599 target_info raw: 02000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C0000000000
600 response_version: 1
601 hi_response_version: 1
602 time: 59519A1727B9CA01 - Mon Mar 01 10:08:08 2010
603 client_challenge: D6AE875CB0FDAA41
604 MsvAvNbDomainName: COSMO
605 MsvAvNbComputerName: COSMO-OCS-R2
606 MsvAvDnsDomainName: cosmo.local
607 MsvAvDnsComputerName: cosmo-ocs-r2.cosmo.local
608 MsvAvDnsTreeName: cosmo.local
609 ----------- end of nt_resp v2 -----------
610 domain: COSMO
611 user: User
612 host: COSMO-OCS-R2
613 session_key: 31CB739E1CA80A498591E8AE797115E4
616 request =
617 "REGISTER sip:cosmo.local SIP/2.0\r\n"
618 "Via: SIP/2.0/TLS 192.168.172.6:12723\r\n"
619 "Max-Forwards: 70\r\n"
620 "From: <sip:user@cosmo.local>;tag=3e49177a52;epid=c8ca638a15\r\n"
621 "To: <sip:user@cosmo.local>\r\n"
622 "Call-ID: 4037df9284354df39065195bd57a4b14\r\n"
623 "CSeq: 3 REGISTER\r\n"
624 "Contact: <sip:192.168.172.6:12723;transport=tls;ms-opaque=fad3dfab32>;methods=\"INVITE, MESSAGE, INFO, OPTIONS, BYE, CANCEL, NOTIFY, ACK, REFER, BENOTIFY\";proxy=replace;+sip.instance=\"<urn:uuid:34D859DB-6585-5F91-A3B4-DE853C15347D>\"\r\n"
625 "User-Agent: UCCAPI/3.5.6907.0 OC/3.5.6907.0 (Microsoft Office Communicator 2007 R2)\r\n"
626 "Supported: gruu-10, adhoclist, msrtc-event-categories\r\n"
627 "Supported: ms-forking\r\n"
628 "ms-keep-alive: UAC;hop-hop=yes\r\n"
629 "Event: registration\r\n"
630 "Proxy-Authorization: NTLM qop=\"auth\", realm=\"SIP Communications Service\", opaque=\"2BDBAC9D\", targetname=\"cosmo-ocs-r2.cosmo.local\", version=4, gssapi-data=\"TlRMTVNTUAADAAAAGAAYAHIAAADGAMYAigAAAAoACgBIAAAACAAIAFIAAAAYABgAWgAAABAAEABQAQAAVYKYYgUCzg4AAAAPQwBPAFMATQBPAFUAcwBlAHIAQwBPAFMATQBPAC0ATwBDAFMALQBSADIAoeku/k4Hi/fFwASazGFmwtauh1yw/apBjcDIAK527KYG0rn769BHMQEBAAAAAAAAWVGaFye5ygHWrodcsP2qQQAAAAACAAoAQwBPAFMATQBPAAEAGABDAE8AUwBNAE8ALQBPAEMAUwAtAFIAMgAEABYAYwBvAHMAbQBvAC4AbABvAGMAYQBsAAMAMABjAG8AcwBtAG8ALQBvAGMAcwAtAHIAMgAuAGMAbwBzAG0AbwAuAGwAbwBjAGEAbAAFABYAYwBvAHMAbQBvAC4AbABvAGMAYQBsAAAAAAAAAAAAMctznhyoCkmFkeiueXEV5A==\", crand=\"13317733\", cnum=\"1\", response=\"0100000029618e9651b65a7764000000\"\r\n"
631 "Content-Length: 0\r\n"
632 "\r\n";
634 request_sig = "<NTLM><13317733><1><SIP Communications Service><cosmo-ocs-r2.cosmo.local><4037df9284354df39065195bd57a4b14><3><REGISTER><sip:user@cosmo.local><3e49177a52><sip:user@cosmo.local><><><><>";
635 //Signature:
636 //0100000029618e9651b65a7764000000
638 response =
639 "SIP/2.0 200 OK\r\n"
640 "ms-keep-alive: UAS; tcp=no; hop-hop=yes; end-end=no; timeout=300\r\n"
641 "Authentication-Info: NTLM rspauth=\"01000000E615438A917661BE64000000\", srand=\"9616454F\", snum=\"1\", opaque=\"2BDBAC9D\", qop=\"auth\", targetname=\"cosmo-ocs-r2.cosmo.local\", realm=\"SIP Communications Service\"\r\n"
642 "From: \"User\"<sip:user@cosmo.local>;tag=3e49177a52;epid=c8ca638a15\r\n"
643 "To: <sip:user@cosmo.local>;tag=5E61CCD925D17E043D9A74835A88F664\r\n"
644 "Call-ID: 4037df9284354df39065195bd57a4b14\r\n"
645 "CSeq: 3 REGISTER\r\n"
646 "Via: SIP/2.0/TLS 192.168.172.6:12723;ms-received-port=12723;ms-received-cid=2600\r\n"
647 "Contact: <sip:192.168.172.6:12723;transport=tls;ms-opaque=fad3dfab32;ms-received-cid=2600>;expires=7200;+sip.instance=\"<urn:uuid:34d859db-6585-5f91-a3b4-de853c15347d>\";gruu=\"sip:user@cosmo.local;opaque=user:epid:21nYNIVlkV-jtN6FPBU0fQAA;gruu\"\r\n"
648 "Expires: 7200\r\n"
649 "presence-state: register-action=\"added\"\r\n"
650 "Allow-Events: vnd-microsoft-provisioning,vnd-microsoft-roaming-contacts,vnd-microsoft-roaming-ACL,presence,presence.wpending,vnd-microsoft-roaming-self,vnd-microsoft-provisioning-v2\r\n"
651 "Supported: adhoclist\r\n"
652 "Server: RTC/3.5\r\n"
653 "Supported: msrtc-event-categories\r\n"
654 "Content-Length: 0\r\n"
655 "\r\n";
657 response_sig = "<NTLM><9616454F><1><SIP Communications Service><cosmo-ocs-r2.cosmo.local><4037df9284354df39065195bd57a4b14><3><REGISTER><sip:user@cosmo.local><3e49177a52><sip:user@cosmo.local><5E61CCD925D17E043D9A74835A88F664><><><7200><200>";
658 //Signature:
659 //01000000E615438A917661BE64000000
661 use_ntlm_v2 = TRUE;
662 flags = 0
663 | NTLMSSP_NEGOTIATE_UNICODE
664 | NTLMSSP_REQUEST_TARGET
665 | NTLMSSP_NEGOTIATE_SIGN
666 | NTLMSSP_NEGOTIATE_DATAGRAM
667 | NTLMSSP_NEGOTIATE_NTLM
668 | NTLMSSP_NEGOTIATE_ALWAYS_SIGN
669 | NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY
670 | NTLMSSP_NEGOTIATE_IDENTIFY
671 | NTLMSSP_NEGOTIATE_TARGET_INFO
672 | NTLMSSP_NEGOTIATE_VERSION
673 | NTLMSSP_NEGOTIATE_128
674 | NTLMSSP_NEGOTIATE_KEY_EXCH;
676 /* global struct */
677 test_version.product_major_version = 5;
678 test_version.product_minor_version = 2;
679 test_version.product_build = GUINT16_FROM_LE(3790);
680 test_version.ntlm_revision_current = 0x0F;
682 NTOWFv2 (password2, user2, domain2, response_key_nt);
683 NTOWFv2 (password2, user2, domain2, response_key_lm);
686 int ntlmssp_nt_resp_len;
687 int target_info2_len;
688 guint8 *nonce2;
689 guint8 *target_info2;
690 guint64 *buff2;
691 /* buff2 points to correctly aligned memory. Disable alignment check */
692 hex_str_to_buff("59519A1727B9CA01", (void *)&buff2);
693 /* global var */
694 test_time_val = GUINT64_FROM_LE(*buff2);
695 g_free(buff2);
696 buff2 = NULL;
698 target_info2_len = hex_str_to_buff("02000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C0000000000", &target_info2);
700 hex_str_to_buff("DD1BAAF4E7E218D1", &nonce2);
702 /* buff2 points to correctly aligned memory. Disable alignment check */
703 hex_str_to_buff("D6AE875CB0FDAA41", (void *)&buff2);
704 /* global buff */
705 memcpy(test_client_challenge, buff2, 8);
706 g_free(buff2);
708 ntlmssp_nt_resp_len = (16 + (32+target_info2_len));
710 guchar nt_challenge_response_v2_2 [ntlmssp_nt_resp_len];
712 printf ("\n\nTesting (NTLMv2 / OC 2007 R2) LM Response Generation\n");
713 printf ( "Testing (NTLMv2 / OC 2007 R2) NT Response Generation\n");
714 compute_response(flags,
715 response_key_nt,
716 response_key_lm,
717 nonce2,
718 test_client_challenge,
719 test_time_val,
720 target_info2, /* target_info */
721 target_info2_len, /* target_info_len */
722 lm_challenge_response, /* out */
723 nt_challenge_response_v2_2, /* out */
724 session_base_key); /* out */
725 g_free(target_info2);
727 assert_equal("A1E92EFE4E078BF7C5C0049ACC6166C2D6AE875CB0FDAA41", lm_challenge_response, 24, TRUE);
728 assert_equal("8DC0C800AE76ECA606D2B9FBEBD04731", nt_challenge_response_v2_2, 16, TRUE);
729 /* the ref string is taken from binary dump of AUTHENTICATE_MESSAGE */
730 assert_equal("8DC0C800AE76ECA606D2B9FBEBD04731010100000000000059519A1727B9CA01D6AE875CB0FDAA410000000002000A0043004F0053004D004F000100180043004F0053004D004F002D004F00430053002D00520032000400160063006F0073006D006F002E006C006F00630061006C000300300063006F0073006D006F002D006F00630073002D00720032002E0063006F0073006D006F002E006C006F00630061006C000500160063006F0073006D006F002E006C006F00630061006C000000000000000000", nt_challenge_response_v2_2, ntlmssp_nt_resp_len, TRUE);
733 KXKEY(flags, session_base_key, lm_challenge_response, nonce2, key_exchange_key);
734 g_free(nonce2);
738 //as in the Type3 message
740 guint8 *encrypted_random_session_key2;
741 hex_str_to_buff("31CB739E1CA80A498591E8AE797115E4", &encrypted_random_session_key2);
742 /* global buff - test_random_session_key */
743 //decoding exported_session_key
744 RC4K (key_exchange_key, 16, encrypted_random_session_key2, 16, test_random_session_key);
745 g_free(encrypted_random_session_key2);
748 SIGNKEY (test_random_session_key, TRUE, client_sign_key);
749 SEALKEY (flags, test_random_session_key, TRUE, client_seal_key);
750 SIGNKEY (test_random_session_key, FALSE, server_sign_key);
751 SEALKEY (flags, test_random_session_key, FALSE, server_seal_key);
753 printf ("\n\nTesting (NTLMv2 / OC 2007 R2) Message Parsing, Signing, and Verification\nClient request\n(Authentication Protocol version 4)\n");
754 msg = sipmsg_parse_msg(request);
755 memset(&msgbd, 0, sizeof(struct sipmsg_breakdown));
756 msgbd.msg = msg;
757 sipmsg_breakdown_parse(&msgbd, "SIP Communications Service", "cosmo-ocs-r2.cosmo.local", NULL);
758 msg_str = sipmsg_breakdown_get_string(4, &msgbd);
759 assert_equal (request_sig, (guchar *)msg_str, strlen(request_sig), FALSE);
760 sip_sec_ntlm_sipe_signature_make (flags, msg_str, 0, client_sign_key, client_seal_key, mac);
761 sipmsg_breakdown_free(&msgbd);
762 assert_equal ("0100000029618e9651b65a7764000000", mac, 16, TRUE);
763 /* sig = buff_to_hex_str((guint8 *)mac, 16); */
765 printf ("\n\nTesting (NTLMv2 / OC 2007 R2) Message Parsing, Signing, and Verification\nServer response\n(Authentication Protocol version 4)\n");
766 msg = sipmsg_parse_msg(response);
767 memset(&msgbd, 0, sizeof(struct sipmsg_breakdown));
768 msgbd.msg = msg;
769 sipmsg_breakdown_parse(&msgbd, "SIP Communications Service", "cosmo-ocs-r2.cosmo.local", NULL);
770 msg_str = sipmsg_breakdown_get_string(4, &msgbd);
771 assert_equal (response_sig, (guchar *)msg_str, strlen(response_sig), FALSE);
772 // server keys here
773 sip_sec_ntlm_sipe_signature_make (flags, msg_str, 0, server_sign_key, server_seal_key, mac);
774 sipmsg_breakdown_free(&msgbd);
775 assert_equal ("01000000E615438A917661BE64000000", mac, 16, TRUE);
776 /* sig = buff_to_hex_str((guint8 *)mac, 16); */
778 printf ("\n\nTesting (NTLMv2 / OC 2007 R2) MAC - client signing\n");
779 MAC (flags, (gchar*)request_sig,strlen(request_sig), client_sign_key,16, client_seal_key,16, 0, 100, mac);
780 assert_equal("0100000029618e9651b65a7764000000", mac, 16, TRUE);
782 printf ("\n\nTesting (NTLMv2 / OC 2007 R2) MAC - server's verifying\n");
783 MAC (flags, (gchar*)response_sig,strlen(response_sig), server_sign_key,16, server_seal_key,16, 0, 100, mac);
784 assert_equal("01000000E615438A917661BE64000000", mac, 16, TRUE);
786 printf ("\n\nTesting (NTLMv2 / OC 2007 R2) Type3 generation test\n");
788 guchar *client_sign_key2;
789 guchar *server_sign_key2;
790 guchar *client_seal_key2;
791 guchar *server_seal_key2;
793 guchar *server_challenge = NULL;
794 guint64 time_val2 = 0;
795 guchar *target_info3 = NULL;
796 int target_info3_len = 0;
797 guint32 flags2;
798 SipSecBuffer in_buff;
799 SipSecBuffer out_buff;
801 in_buff.length = hex_str_to_buff(type2_hex, (guint8 **)&(in_buff.value));
803 sip_sec_ntlm_parse_challenge(in_buff,
804 &flags2, /* out */
805 &server_challenge,
806 &time_val2,
807 &target_info3,
808 &target_info3_len);
810 sip_sec_ntlm_gen_authenticate(&client_sign_key2,
811 &server_sign_key2,
812 &client_seal_key2,
813 &server_seal_key2,
814 user2,
815 password2,
816 host2,
817 domain2,
818 server_challenge,
819 test_time_val,
820 target_info3,
821 target_info3_len,
823 &out_buff,
824 &flags2);
826 g_free(server_challenge);
827 g_free(target_info3);
829 assert_equal(type3_hex, out_buff.value, out_buff.length, TRUE);
832 printf ("\n\nTesting Authentication Algorithm's v4 Signature String\n");
834 char *response_symbian =
835 "SIP/2.0 180 Ringing\r\n"
836 "Authentication-Info: NTLM rspauth=\"010000003EA8D688BA51D5CD64000000\", srand=\"1B6D47A1\", snum=\"11\", opaque=\"357E6F72\", qop=\"auth\", targetname=\"LOC-COMPANYT-FE03.COMPANY.COM\", realm=\"SIP Communications Service\"\r\n"
837 "Via: SIP/2.0/tls 192.168.44.10:50230;received=10.117.245.254;ms-received-port=50230;ms-received-cid=37ABE00\r\n"
838 "FROM: \"Sender\"<sip:sender@company.com>;tag=2420628112;epid=54392f1bbf01\r\n"
839 "TO: \"recipient\"<sip:recipient@company.com>;tag=7aee15546a;epid=3102EB8BD1\r\n"
840 "CSEQ: 1 INVITE\r\n"
841 "CALL-ID: 41CEg82ECa0AC8i3DD7mE673t9CF4b19DAxF780x\r\n"
842 "RECORD-ROUTE: <sip:LOC-COMPANYT-OCSR2P01.COMPANY.COM:5061;transport=tls;ms-fe=LOC-COMPANYT-FE03.COMPANY.COM;opaque=state:F:T:Eu:Ci.R37abe00;lr;ms-route-sig=gdOGgL7NiL3hv_oBc0NdrJOxZk_r-8naq-k_DtpgAA>\r\n"
843 "CONTACT: <sip:recipient@company.com;opaque=user:epid:-gLwenLTVVqy-Ak8TJn1ZAAA;gruu>;text;audio;video\r\n"
844 "CONTENT-LENGTH: 0\r\n"
845 "SUPPORTED: gruu-10\r\n"
846 "ALLOW: UPDATE\r\n"
847 "P-ASSERTED-IDENTITY: \"recipient\"<SIP:recipient@company.com>\r\n"
848 "SERVER: RTCC/3.5.0.0 MCXService/3.5.0.0 communicator.NOKIAS60R2.JVP.EN_US/1.0.6875.0\r\n"
849 "\r\n";
851 response_sig = "<NTLM><1B6D47A1><11><SIP Communications Service><LOC-COMPANYT-FE03.COMPANY.COM><41CEg82ECa0AC8i3DD7mE673t9CF4b19DAxF780x><1><INVITE><sip:sender@company.com><2420628112><sip:recipient@company.com><7aee15546a><SIP:recipient@company.com><><><180>";
853 msg = sipmsg_parse_msg(response_symbian);
854 memset(&msgbd, 0, sizeof(struct sipmsg_breakdown));
855 msgbd.msg = msg;
856 sipmsg_breakdown_parse(&msgbd, "SIP Communications Service", "LOC-COMPANYT-FE03.COMPANY.COM", NULL);
857 msg_str = sipmsg_breakdown_get_string(4, &msgbd);
859 assert_equal (response_sig, (guchar *)msg_str, strlen(response_sig), FALSE);
861 sipmsg_breakdown_free(&msgbd);
864 ////// UUID tests ///////
865 /* begin tests from MS-SIPRE */
867 const char *testEpid = "01010101";
868 const char *expectedUUID = "4b1682a8-f968-5701-83fc-7c6741dc6697";
869 gchar *calcUUID = generateUUIDfromEPID(testEpid);
871 printf("\n\nTesting MS-SIPRE UUID derivation\n");
873 assert_equal(expectedUUID, (guchar *) calcUUID, strlen(expectedUUID), FALSE);
874 g_free(calcUUID);
877 /* end tests from MS-SIPRE */
879 printf ("\nFinished With Tests; %d successs %d failures\n", successes, failures);
881 sip_sec_destroy__ntlm();
883 return(failures == 0);
887 Local Variables:
888 mode: c
889 c-file-style: "bsd"
890 indent-tabs-mode: t
891 tab-width: 8
892 End: