xref: /netbsd-src/crypto/external/bsd/heimdal/dist/lib/ntlm/test_ntlm.c (revision d3273b5b76f5afaafe308cead5511dbb8df8c5e9)
1 /*	$NetBSD: test_ntlm.c,v 1.2 2017/01/28 21:31:49 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
5  * (Royal Institute of Technology, Stockholm, Sweden).
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of KTH nor the names of its contributors may be
20  *    used to endorse or promote products derived from this software without
21  *    specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "config.h"
37 
38 #include <stdio.h>
39 #include <err.h>
40 #include <krb5/roken.h>
41 #include <krb5/getarg.h>
42 
43 #include <krb5/krb5-types.h> /* or <inttypes.h> */
44 #include <krb5/heimntlm.h>
45 
46 static int dumpdata_flag;
47 
48 static int
test_parse(void)49 test_parse(void)
50 {
51     const char *user = "foo",
52 	*domain = "mydomain",
53 	*hostname = "myhostname",
54 	*password = "digestpassword",
55 	*target = "DOMAIN";
56     struct ntlm_type1 type1;
57     struct ntlm_type2 type2;
58     struct ntlm_type3 type3;
59     struct ntlm_buf data;
60     int ret, flags;
61 
62     memset(&type1, 0, sizeof(type1));
63 
64     type1.flags = NTLM_NEG_UNICODE|NTLM_NEG_TARGET|NTLM_NEG_NTLM|NTLM_NEG_VERSION;
65     type1.domain = rk_UNCONST(domain);
66     type1.hostname = rk_UNCONST(hostname);
67     type1.os[0] = 0;
68     type1.os[1] = 0;
69 
70     ret = heim_ntlm_encode_type1(&type1, &data);
71     if (ret)
72 	errx(1, "heim_ntlm_encode_type1");
73 
74     memset(&type1, 0, sizeof(type1));
75 
76     if (dumpdata_flag)
77 	rk_dumpdata("ntlm-type1", data.data, data.length);
78 
79     ret = heim_ntlm_decode_type1(&data, &type1);
80     free(data.data);
81     if (ret)
82 	errx(1, "heim_ntlm_encode_type1");
83 
84     if (strcmp(type1.domain, domain) != 0)
85 	errx(1, "parser got domain wrong: %s", type1.domain);
86 
87     if (strcmp(type1.hostname, hostname) != 0)
88 	errx(1, "parser got hostname wrong: %s", type1.hostname);
89 
90     heim_ntlm_free_type1(&type1);
91 
92     /*
93      *
94      */
95 
96     memset(&type2, 0, sizeof(type2));
97 
98     flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
99     type2.flags = flags;
100 
101     memset(type2.challenge, 0x7f, sizeof(type2.challenge));
102     type2.targetname = rk_UNCONST(target);
103     type2.targetinfo.data = NULL;
104     type2.targetinfo.length = 0;
105 
106     ret = heim_ntlm_encode_type2(&type2, &data);
107     if (ret)
108 	errx(1, "heim_ntlm_encode_type2");
109 
110     memset(&type2, 0, sizeof(type2));
111 
112     if (dumpdata_flag)
113 	rk_dumpdata("ntlm-type2", data.data, data.length);
114 
115     ret = heim_ntlm_decode_type2(&data, &type2);
116     free(data.data);
117     if (ret)
118 	errx(1, "heim_ntlm_decode_type2");
119 
120     heim_ntlm_free_type2(&type2);
121 
122     /*
123      *
124      */
125 
126     memset(&type3, 0, sizeof(type3));
127 
128     type3.flags = flags;
129     type3.username = rk_UNCONST(user);
130     type3.targetname = rk_UNCONST(target);
131     type3.ws = rk_UNCONST("workstation");
132 
133     {
134 	struct ntlm_buf key;
135 	heim_ntlm_nt_key(password, &key);
136 
137 	heim_ntlm_calculate_ntlm1(key.data, key.length,
138 				  type2.challenge,
139 				  &type3.ntlm);
140 	free(key.data);
141     }
142 
143     ret = heim_ntlm_encode_type3(&type3, &data, NULL);
144     if (ret)
145 	errx(1, "heim_ntlm_encode_type3");
146 
147     free(type3.ntlm.data);
148 
149     memset(&type3, 0, sizeof(type3));
150 
151     if (dumpdata_flag)
152 	rk_dumpdata("ntlm-type3", data.data, data.length);
153 
154     ret = heim_ntlm_decode_type3(&data, 1, &type3);
155     free(data.data);
156     if (ret)
157 	errx(1, "heim_ntlm_decode_type3");
158 
159     if (strcmp("workstation", type3.ws) != 0)
160 	errx(1, "type3 ws wrong");
161 
162     if (strcmp(target, type3.targetname) != 0)
163 	errx(1, "type3 targetname wrong");
164 
165     if (strcmp(user, type3.username) != 0)
166 	errx(1, "type3 username wrong");
167 
168 
169     heim_ntlm_free_type3(&type3);
170 
171     /*
172      * NTLMv2
173      */
174 
175     memset(&type2, 0, sizeof(type2));
176 
177     flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
178     type2.flags = flags;
179 
180     memset(type2.challenge, 0x7f, sizeof(type2.challenge));
181     type2.targetname = rk_UNCONST(target);
182     type2.targetinfo.data = "\x00\x00";
183     type2.targetinfo.length = 2;
184 
185     ret = heim_ntlm_encode_type2(&type2, &data);
186     if (ret)
187 	errx(1, "heim_ntlm_encode_type2");
188 
189     memset(&type2, 0, sizeof(type2));
190 
191     ret = heim_ntlm_decode_type2(&data, &type2);
192     free(data.data);
193     if (ret)
194 	errx(1, "heim_ntlm_decode_type2");
195 
196     heim_ntlm_free_type2(&type2);
197 
198     return 0;
199 }
200 
201 static int
test_keys(void)202 test_keys(void)
203 {
204     const char
205 	*username = "test",
206 	*password = "test1234",
207 	*target = "TESTNT";
208     const unsigned char
209 	serverchallenge[8] = "\x67\x7f\x1c\x55\x7a\x5e\xe9\x6c";
210     struct ntlm_buf infotarget, infotarget2, answer, key;
211     unsigned char ntlmv2[16], ntlmv2_1[16];
212     int ret;
213 
214     infotarget.length = 70;
215     infotarget.data =
216 	"\x02\x00\x0c\x00\x54\x00\x45\x00\x53\x00\x54\x00\x4e\x00\x54\x00"
217 	"\x01\x00\x0c\x00\x4d\x00\x45\x00\x4d\x00\x42\x00\x45\x00\x52\x00"
218 	"\x03\x00\x1e\x00\x6d\x00\x65\x00\x6d\x00\x62\x00\x65\x00\x72\x00"
219 	    "\x2e\x00\x74\x00\x65\x00\x73\x00\x74\x00\x2e\x00\x63\x00\x6f"
220 	    "\x00\x6d\x00"
221 	"\x00\x00\x00\x00";
222 
223     answer.length = 0;
224     answer.data = NULL;
225 
226     heim_ntlm_nt_key(password, &key);
227 
228     ret = heim_ntlm_calculate_ntlm2(key.data,
229 				    key.length,
230 				    username,
231 				    target,
232 				    serverchallenge,
233 				    &infotarget,
234 				    ntlmv2,
235 				    &answer);
236     if (ret)
237 	errx(1, "heim_ntlm_calculate_ntlm2");
238 
239     ret = heim_ntlm_verify_ntlm2(key.data,
240 				 key.length,
241 				 username,
242 				 target,
243 				 0,
244 				 serverchallenge,
245 				 &answer,
246 				 &infotarget2,
247 				 ntlmv2_1);
248     if (ret)
249 	errx(1, "heim_ntlm_verify_ntlm2");
250 
251     if (memcmp(ntlmv2, ntlmv2_1, sizeof(ntlmv2)) != 0)
252 	errx(1, "ntlm master key not same");
253 
254     if (infotarget.length > infotarget2.length)
255 	errx(1, "infotarget length");
256 
257     if (memcmp(infotarget.data, infotarget2.data, infotarget.length) != 0)
258 	errx(1, "infotarget not the same");
259 
260     free(key.data);
261     free(answer.data);
262     free(infotarget2.data);
263 
264     return 0;
265 }
266 
267 static int
test_ntlm2_session_resp(void)268 test_ntlm2_session_resp(void)
269 {
270     int ret;
271     struct ntlm_buf lm, ntlm;
272 
273     const unsigned char lm_resp[24] =
274 	"\xff\xff\xff\x00\x11\x22\x33\x44"
275 	"\x00\x00\x00\x00\x00\x00\x00\x00"
276 	"\x00\x00\x00\x00\x00\x00\x00\x00";
277     const unsigned char ntlm2_sess_resp[24] =
278 	"\x10\xd5\x50\x83\x2d\x12\xb2\xcc"
279 	"\xb7\x9d\x5a\xd1\xf4\xee\xd3\xdf"
280 	"\x82\xac\xa4\xc3\x68\x1d\xd4\x55";
281 
282     const unsigned char client_nonce[8] =
283 	"\xff\xff\xff\x00\x11\x22\x33\x44";
284     const unsigned char server_challenge[8] =
285 	"\x01\x23\x45\x67\x89\xab\xcd\xef";
286 
287     const unsigned char ntlm_hash[16] =
288 	"\xcd\x06\xca\x7c\x7e\x10\xc9\x9b"
289 	"\x1d\x33\xb7\x48\x5a\x2e\xd8\x08";
290 
291     ret = heim_ntlm_calculate_ntlm2_sess(client_nonce,
292 					 server_challenge,
293 					 ntlm_hash,
294 					 &lm,
295 					 &ntlm);
296     if (ret)
297 	errx(1, "heim_ntlm_calculate_ntlm2_sess_resp");
298 
299     if (lm.length != 24 || memcmp(lm.data, lm_resp, 24) != 0)
300 	errx(1, "lm_resp wrong");
301     if (ntlm.length != 24 || memcmp(ntlm.data, ntlm2_sess_resp, 24) != 0)
302 	errx(1, "ntlm2_sess_resp wrong");
303 
304     free(lm.data);
305     free(ntlm.data);
306 
307 
308     return 0;
309 }
310 
311 static int
test_ntlmv2(void)312 test_ntlmv2(void)
313 {
314     unsigned char type3[413] =
315 	"\x4e\x54\x4c\x4d\x53\x53\x50\x00\x03\x00\x00\x00\x18\x00\x18\x00"
316 	"\x80\x00\x00\x00\x9e\x00\x9e\x00\x98\x00\x00\x00\x14\x00\x14\x00"
317 	"\x48\x00\x00\x00\x10\x00\x10\x00\x5c\x00\x00\x00\x14\x00\x14\x00"
318 	"\x6c\x00\x00\x00\x00\x00\x00\x00\x36\x01\x00\x00\x05\x82\x88\xa2"
319 	"\x05\x01\x28\x0a\x00\x00\x00\x0f\x43\x00\x4f\x00\x4c\x00\x4c\x00"
320 	"\x45\x00\x59\x00\x2d\x00\x58\x00\x50\x00\x34\x00\x54\x00\x45\x00"
321 	"\x53\x00\x54\x00\x55\x00\x53\x00\x45\x00\x52\x00\x43\x00\x4f\x00"
322 	"\x4c\x00\x4c\x00\x45\x00\x59\x00\x2d\x00\x58\x00\x50\x00\x34\x00"
323 	"\x2f\x96\xec\x0a\xf7\x9f\x2e\x24\xba\x09\x48\x10\xa5\x22\xd4\xe1"
324 	"\x16\x6a\xca\x58\x74\x9a\xc1\x4f\x54\x6f\xee\x40\x96\xce\x43\x6e"
325 	"\xdf\x99\x20\x71\x6c\x9a\xda\x2a\x01\x01\x00\x00\x00\x00\x00\x00"
326 	"\x8d\xc0\x57\xc9\x79\x5e\xcb\x01\x16\x6a\xca\x58\x74\x9a\xc1\x4f"
327 	"\x00\x00\x00\x00\x02\x00\x14\x00\x4e\x00\x55\x00\x54\x00\x43\x00"
328 	"\x52\x00\x41\x00\x43\x00\x4b\x00\x45\x00\x52\x00\x01\x00\x14\x00"
329 	"\x4e\x00\x55\x00\x54\x00\x43\x00\x52\x00\x41\x00\x43\x00\x4b\x00"
330 	"\x45\x00\x52\x00\x04\x00\x12\x00\x61\x00\x70\x00\x70\x00\x6c\x00"
331 	"\x65\x00\x2e\x00\x63\x00\x6f\x00\x6d\x00\x03\x00\x20\x00\x68\x00"
332 	"\x75\x00\x6d\x00\x6d\x00\x65\x00\x6c\x00\x2e\x00\x61\x00\x70\x00"
333 	"\x70\x00\x6c\x00\x65\x00\x2e\x00\x63\x00\x6f\x00\x6d\x00\x00\x00"
334 	"\x00\x00\x00\x00\x00\x00\x00\x57\x00\x69\x00\x6e\x00\x64\x00\x6f"
335 	"\x00\x77\x00\x73\x00\x20\x00\x32\x00\x30\x00\x30\x00\x32\x00\x20"
336 	"\x00\x53\x00\x65\x00\x72\x00\x76\x00\x69\x00\x63\x00\x65\x00\x20"
337 	"\x00\x50\x00\x61\x00\x63\x00\x6b\x00\x20\x00\x33\x00\x20\x00\x32"
338 	"\x00\x36\x00\x30\x00\x30\x00\x00\x00\x57\x00\x69\x00\x6e\x00\x64"
339 	"\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32\x00\x30\x00\x30\x00\x32"
340 	"\x00\x20\x00\x35\x00\x2e\x00\x31\x00\x00\x00\x00\x00";
341     const unsigned char challenge[8] =
342 	"\xe4\x9c\x6a\x12\xe1\xbd\xde\x6a";
343     unsigned char sessionkey[16];
344 
345     const char key[16] = "\xD1\x83\x98\x3E\xAE\xA7\xBE\x99\x59\xC8\xF4\xC1\x98\xED\x0E\x68";
346 
347     struct ntlm_buf data;
348     struct ntlm_type3 t3;
349     int ret;
350 
351     struct ntlm_targetinfo ti;
352 
353     unsigned char timsg[114] =
354 	"\002\000\024\000N\000U\000T\000C\000R\000A\000C\000K\000E\000R\000\001\000\024\000N\000U\000T\000C\000R\000A\000C\000K\000E\000R\000\004\000\022\000a\000p\000p\000l\000e\000.\000c\000o\000m\000\003\000 \000h\000u\000m\000m\000e\000l\000.\000a\000p\000p\000l\000e\000.\000c\000o\000m\000\000\000\000\000\000\000\000";
355 
356 
357     data.data = type3;
358     data.length = sizeof(type3);
359 
360     ret = heim_ntlm_decode_type3(&data, 1, &t3);
361     if (ret)
362 	errx(1, "heim_ntlm_decode_type3");
363 
364     memset(&ti, 0, sizeof(ti));
365 
366     data.data = timsg;
367     data.length = sizeof(timsg);
368 
369     ret = heim_ntlm_decode_targetinfo(&data, 1, &ti);
370     if (ret)
371 	return ret;
372 
373     ret = heim_ntlm_verify_ntlm2(key, sizeof(key),
374 				 t3.username,
375 				 t3.targetname,
376 				 1285615547,
377 				 challenge,
378 				 &t3.ntlm,
379 				 &data,
380 				 sessionkey);
381     if (ret)
382 	errx(1, "verify_ntlmv2");
383 
384     if (sizeof(timsg) != data.length || memcmp(timsg, data.data, sizeof(timsg)) != 0)
385 	errx(1, "target info wrong: %d != %d",
386 	     (int)sizeof(timsg), (int)data.length);
387 
388     heim_ntlm_free_type3(&t3);
389     heim_ntlm_free_targetinfo(&ti);
390 
391     return 0;
392 }
393 
394 static int
test_targetinfo(void)395 test_targetinfo(void)
396 {
397     struct ntlm_targetinfo ti;
398     struct ntlm_buf buf;
399     const char *dnsservername = "dnsservername";
400     const char *targetname = "targetname";
401     const char z16[16] = { 0 };
402     int ret;
403 
404     memset(&ti, 0, sizeof(ti));
405 
406     ti.dnsservername = rk_UNCONST(dnsservername);
407     ti.avflags = 1;
408     ti.targetname = rk_UNCONST(targetname);
409     ti.channel_bindings.data = rk_UNCONST(z16);
410     ti.channel_bindings.length = sizeof(z16);
411 
412     ret = heim_ntlm_encode_targetinfo(&ti, 1, &buf);
413     if (ret)
414 	return ret;
415 
416     memset(&ti, 0, sizeof(ti));
417 
418     ret = heim_ntlm_decode_targetinfo(&buf, 1, &ti);
419     if (ret)
420 	return ret;
421 
422     if (ti.dnsservername == NULL ||
423 	strcmp(ti.dnsservername, dnsservername) != 0)
424 	errx(1, "ti.dnshostname != %s", dnsservername);
425     if (ti.avflags != 1)
426 	errx(1, "ti.avflags != 1");
427     if (ti.targetname == NULL ||
428 	strcmp(ti.targetname, targetname) != 0)
429 	errx(1, "ti.targetname != %s", targetname);
430 
431     if (ti.channel_bindings.length != sizeof(z16) ||
432 	memcmp(ti.channel_bindings.data, z16, sizeof(z16)) != 0)
433 	errx(1, "ti.channel_bindings != Z(16)");
434 
435     heim_ntlm_free_targetinfo(&ti);
436 
437     return 0;
438 }
439 
440 static int
test_string2key(void)441 test_string2key(void)
442 {
443     const char *pw = "山田";
444     struct ntlm_buf buf;
445 
446     unsigned char key[16] = {
447 	0xc6, 0x5d, 0xc7, 0x61, 0xa1, 0x34, 0x17, 0xa1,
448 	0x17, 0x08, 0x9c, 0x1b, 0xb0, 0x0d, 0x0f, 0x19
449     };
450 
451     if (heim_ntlm_nt_key(pw, &buf) != 0)
452 	errx(1, "heim_ntlmv_nt_key(jp)");
453 
454     if (buf.length != 16 || memcmp(buf.data, key, 16) != 0)
455 	errx(1, "compare failed");
456 
457     heim_ntlm_free_buf(&buf);
458 
459     return 0;
460 }
461 
462 static int
test_jp(void)463 test_jp(void)
464 {
465     char buf2[220] =
466 	"\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x06\x00\x06\x00"
467 	"\x38\x00\x00\x00\x05\x02\x89\x62\x62\x94\xb1\xf3\x56\x80\xb0\xf9"
468 	"\x00\x00\x00\x00\x00\x00\x00\x00\x9e\x00\x9e\x00\x3e\x00\x00\x00"
469 	"\x06\x01\xb0\x1d\x00\x00\x00\x0f\x43\x00\x4f\x00\x53\x00\x02\x00"
470 	"\x06\x00\x43\x00\x4f\x00\x53\x00\x01\x00\x12\x00\x43\x00\x4f\x00"
471 	"\x53\x00\x57\x00\x49\x00\x4e\x00\x37\x00\x4a\x00\x50\x00\x04\x00"
472 	"\x1a\x00\x63\x00\x6f\x00\x73\x00\x2e\x00\x61\x00\x70\x00\x70\x00"
473 	"\x6c\x00\x65\x00\x2e\x00\x63\x00\x6f\x00\x6d\x00\x03\x00\x2e\x00"
474 	"\x63\x00\x6f\x00\x73\x00\x77\x00\x69\x00\x6e\x00\x37\x00\x6a\x00"
475 	"\x70\x00\x2e\x00\x63\x00\x6f\x00\x73\x00\x2e\x00\x61\x00\x70\x00"
476 	"\x70\x00\x6c\x00\x65\x00\x2e\x00\x63\x00\x6f\x00\x6d\x00\x05\x00"
477 	"\x1a\x00\x63\x00\x6f\x00\x73\x00\x2e\x00\x61\x00\x70\x00\x70\x00"
478 	"\x6c\x00\x65\x00\x2e\x00\x63\x00\x6f\x00\x6d\x00\x07\x00\x08\x00"
479 	"\x94\x51\xf0\xbd\xdc\x61\xcb\x01\x00\x00\x00\x00";
480 
481     char buf3[362] =
482 	"\x4e\x54\x4c\x4d\x53\x53\x50\x00\x03\x00\x00\x00\x18\x00\x18\x00"
483 	"\x74\x00\x00\x00\xce\x00\xce\x00\x8c\x00\x00\x00\x1a\x00\x1a\x00"
484 	"\x40\x00\x00\x00\x04\x00\x04\x00\x5a\x00\x00\x00\x16\x00\x16\x00"
485 	"\x5e\x00\x00\x00\x10\x00\x10\x00\x5a\x01\x00\x00\x05\x02\x89\x62"
486 	"\x31\x00\x37\x00\x2e\x00\x32\x00\x30\x00\x31\x00\x2e\x00\x35\x00"
487 	"\x37\x00\x2e\x00\x31\x00\x32\x00\x31\x00\x71\x5c\x30\x75\x77\x00"
488 	"\x6f\x00\x72\x00\x6b\x00\x73\x00\x74\x00\x61\x00\x74\x00\x69\x00"
489 	"\x6f\x00\x6e\x00\xab\xad\xeb\x72\x01\xd4\x5f\xdf\x59\x07\x5f\xa9"
490 	"\xfd\x54\x98\x2d\xfa\x17\xbb\xf1\x3c\x8f\xf5\x20\xe6\x8f\xd7\x0a"
491 	"\xc9\x19\x3e\x94\x61\x31\xdb\x0f\x55\xe8\xe2\x53\x01\x01\x00\x00"
492 	"\x00\x00\x00\x00\x00\x06\x3e\x30\xe4\x61\xcb\x01\x71\x98\x10\x6b"
493 	"\x4c\x82\xec\xb3\x00\x00\x00\x00\x02\x00\x06\x00\x43\x00\x4f\x00"
494 	"\x53\x00\x01\x00\x12\x00\x43\x00\x4f\x00\x53\x00\x57\x00\x49\x00"
495 	"\x4e\x00\x37\x00\x4a\x00\x50\x00\x04\x00\x1a\x00\x63\x00\x6f\x00"
496 	"\x73\x00\x2e\x00\x61\x00\x70\x00\x70\x00\x6c\x00\x65\x00\x2e\x00"
497 	"\x63\x00\x6f\x00\x6d\x00\x03\x00\x2e\x00\x63\x00\x6f\x00\x73\x00"
498 	"\x77\x00\x69\x00\x6e\x00\x37\x00\x6a\x00\x70\x00\x2e\x00\x63\x00"
499 	"\x6f\x00\x73\x00\x2e\x00\x61\x00\x70\x00\x70\x00\x6c\x00\x65\x00"
500 	"\x2e\x00\x63\x00\x6f\x00\x6d\x00\x05\x00\x1a\x00\x63\x00\x6f\x00"
501 	"\x73\x00\x2e\x00\x61\x00\x70\x00\x70\x00\x6c\x00\x65\x00\x2e\x00"
502 	"\x63\x00\x6f\x00\x6d\x00\x07\x00\x08\x00\xab\xec\xcc\x30\xe4\x61"
503 	"\xcb\x01\x00\x00\x00\x00\x00\x00\x00\x00\xbc\x2e\xba\x3f\xd1\xb1"
504 	"\xa7\x70\x00\x9d\x55\xa0\x59\x74\x2b\x78";
505 
506 
507     struct ntlm_type2 type2;
508     struct ntlm_type3 type3;
509     struct ntlm_buf data;
510     int ret;
511 
512     data.length = sizeof(buf2);
513     data.data = buf2;
514 
515     memset(&type2, 0, sizeof(type2));
516 
517     ret = heim_ntlm_decode_type2(&data, &type2);
518     if (ret)
519 	errx(1, "heim_ntlm_decode_type2(jp): %d", ret);
520 
521     data.data = NULL;
522     data.length = 0;
523 
524     ret = heim_ntlm_encode_type2(&type2, &data);
525     if (ret)
526 	errx(1, "heim_ntlm_encode_type2(jp): %d", ret);
527 
528     heim_ntlm_free_type2(&type2);
529     heim_ntlm_free_buf(&data);
530 
531     data.length = sizeof(buf3);
532     data.data = buf3;
533 
534     memset(&type3, 0, sizeof(type3));
535 
536     ret = heim_ntlm_decode_type3(&data, 1, &type3);
537     if (ret)
538 	errx(1, "heim_ntlm_decode_type2(jp): %d", ret);
539 
540     data.data = NULL;
541     data.length = 0;
542 
543     ret = heim_ntlm_encode_type3(&type3, &data, NULL);
544     if (ret)
545 	errx(1, "heim_ntlm_decode_type2(jp): %d", ret);
546 
547     heim_ntlm_free_type3(&type3);
548     heim_ntlm_free_buf(&data);
549 
550     return 0;
551 }
552 
553 
554 static int verbose_flag = 0;
555 static int version_flag = 0;
556 static int help_flag	= 0;
557 
558 static struct getargs args[] = {
559     {"verbose",	0,	arg_flag,	&verbose_flag, "verbose printing", NULL },
560     {"version",	0,	arg_flag,	&version_flag, "print version", NULL },
561     {"help",	0,	arg_flag,	&help_flag,  NULL, NULL }
562 };
563 
564 static void
usage(int ret)565 usage (int ret)
566 {
567     arg_printusage (args, sizeof(args)/sizeof(*args),
568 		    NULL, "");
569     exit (ret);
570 }
571 
572 int
main(int argc,char ** argv)573 main(int argc, char **argv)
574 {
575     int ret = 0, optidx = 0;
576 
577     setprogname(argv[0]);
578 
579     if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
580 	usage(1);
581 
582     if (help_flag)
583 	usage (0);
584 
585     if(version_flag){
586 	print_version(NULL);
587 	exit(0);
588     }
589 
590     if (verbose_flag)
591 	printf("test_parse\n");
592     ret |= test_parse();
593 
594     if (verbose_flag)
595 	printf("test_keys\n");
596     ret |= test_keys();
597 
598     if (verbose_flag)
599 	printf("test_ntlm2_session_resp\n");
600     ret |= test_ntlm2_session_resp();
601 
602     if (verbose_flag)
603 	printf("test_targetinfo\n");
604     ret |= test_targetinfo();
605 
606     if (verbose_flag)
607 	printf("test_ntlmv2\n");
608     ret |= test_ntlmv2();
609 
610     if (verbose_flag)
611 	printf("test_string2key\n");
612     ret |= test_string2key();
613 
614     if (verbose_flag)
615 	printf("test_jp\n");
616     ret |= test_jp();
617 
618     return ret;
619 }
620