xref: /minix3/crypto/external/bsd/heimdal/dist/lib/krb5/test_pac.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: test_pac.c,v 1.1.1.2 2014/04/24 12:45:51 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc  * Copyright (c) 2006 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc  * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc  * All rights reserved.
7ebfedea0SLionel Sambuc  *
8ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
9ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
10ebfedea0SLionel Sambuc  * are met:
11ebfedea0SLionel Sambuc  *
12ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
13ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
14ebfedea0SLionel Sambuc  *
15ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18ebfedea0SLionel Sambuc  *
19ebfedea0SLionel Sambuc  * 3. Neither the name of the Institute nor the names of its contributors
20ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
21ebfedea0SLionel Sambuc  *    without specific prior written permission.
22ebfedea0SLionel Sambuc  *
23ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ebfedea0SLionel Sambuc  * SUCH DAMAGE.
34ebfedea0SLionel Sambuc  */
35ebfedea0SLionel Sambuc 
36ebfedea0SLionel Sambuc #include "krb5_locl.h"
37ebfedea0SLionel Sambuc 
38ebfedea0SLionel Sambuc /*
39ebfedea0SLionel Sambuc  * This PAC and keys are copied (with permission) from Samba torture
40ebfedea0SLionel Sambuc  * regression test suite, they where created by Andrew Bartlet.
41ebfedea0SLionel Sambuc  */
42ebfedea0SLionel Sambuc 
43ebfedea0SLionel Sambuc static const unsigned char saved_pac[] = {
44ebfedea0SLionel Sambuc 	0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00,
45ebfedea0SLionel Sambuc 	0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
46ebfedea0SLionel Sambuc 	0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
47ebfedea0SLionel Sambuc 	0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
48ebfedea0SLionel Sambuc 	0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
49ebfedea0SLionel Sambuc 	0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x30, 0xdf, 0xa6, 0xcb,
50ebfedea0SLionel Sambuc 	0x4f, 0x7d, 0xc5, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff,
51ebfedea0SLionel Sambuc 	0xff, 0xff, 0xff, 0x7f, 0xc0, 0x3c, 0x4e, 0x59, 0x62, 0x73, 0xc5, 0x01, 0xc0, 0x3c, 0x4e, 0x59,
52ebfedea0SLionel Sambuc 	0x62, 0x73, 0xc5, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x16, 0x00, 0x16, 0x00,
53ebfedea0SLionel Sambuc 	0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
54ebfedea0SLionel Sambuc 	0x0c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
55ebfedea0SLionel Sambuc 	0x14, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x02, 0x00, 0x65, 0x00, 0x00, 0x00,
56ebfedea0SLionel Sambuc 	0xed, 0x03, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x02, 0x00,
57ebfedea0SLionel Sambuc 	0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x16, 0x00, 0x20, 0x00, 0x02, 0x00, 0x16, 0x00, 0x18, 0x00,
59ebfedea0SLionel Sambuc 	0x24, 0x00, 0x02, 0x00, 0x28, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60ebfedea0SLionel Sambuc 	0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62ebfedea0SLionel Sambuc 	0x01, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
64ebfedea0SLionel Sambuc 	0x57, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, 0x46, 0x00, 0x49, 0x00, 0x4e, 0x00,
65ebfedea0SLionel Sambuc 	0x41, 0x00, 0x4c, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69ebfedea0SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
70ebfedea0SLionel Sambuc 	0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x57, 0x00, 0x32, 0x00,
71ebfedea0SLionel Sambuc 	0x30, 0x00, 0x30, 0x00, 0x33, 0x00, 0x46, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x41, 0x00, 0x4c, 0x00,
72ebfedea0SLionel Sambuc 	0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x57, 0x00, 0x49, 0x00,
73ebfedea0SLionel Sambuc 	0x4e, 0x00, 0x32, 0x00, 0x4b, 0x00, 0x33, 0x00, 0x54, 0x00, 0x48, 0x00, 0x49, 0x00, 0x4e, 0x00,
74ebfedea0SLionel Sambuc 	0x4b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
75ebfedea0SLionel Sambuc 	0x15, 0x00, 0x00, 0x00, 0x11, 0x2f, 0xaf, 0xb5, 0x90, 0x04, 0x1b, 0xec, 0x50, 0x3b, 0xec, 0xdc,
76ebfedea0SLionel Sambuc 	0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
77ebfedea0SLionel Sambuc 	0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78ebfedea0SLionel Sambuc 	0x80, 0x66, 0x28, 0xea, 0x37, 0x80, 0xc5, 0x01, 0x16, 0x00, 0x77, 0x00, 0x32, 0x00, 0x30, 0x00,
79ebfedea0SLionel Sambuc 	0x30, 0x00, 0x33, 0x00, 0x66, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x24, 0x00,
80ebfedea0SLionel Sambuc 	0x76, 0xff, 0xff, 0xff, 0x37, 0xd5, 0xb0, 0xf7, 0x24, 0xf0, 0xd6, 0xd4, 0xec, 0x09, 0x86, 0x5a,
81ebfedea0SLionel Sambuc 	0xa0, 0xe8, 0xc3, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x76, 0xff, 0xff, 0xff, 0xb4, 0xd8, 0xb8, 0xfe,
82ebfedea0SLionel Sambuc 	0x83, 0xb3, 0x13, 0x3f, 0xfc, 0x5c, 0x41, 0xad, 0xe2, 0x64, 0x83, 0xe0, 0x00, 0x00, 0x00, 0x00
83ebfedea0SLionel Sambuc };
84ebfedea0SLionel Sambuc 
85ebfedea0SLionel Sambuc static int type_1_length = 472;
86ebfedea0SLionel Sambuc 
87ebfedea0SLionel Sambuc static const krb5_keyblock kdc_keyblock = {
88ebfedea0SLionel Sambuc     ETYPE_ARCFOUR_HMAC_MD5,
89ebfedea0SLionel Sambuc     { 16, "\xB2\x86\x75\x71\x48\xAF\x7F\xD2\x52\xC5\x36\x03\xA1\x50\xB7\xE7" }
90ebfedea0SLionel Sambuc };
91ebfedea0SLionel Sambuc 
92ebfedea0SLionel Sambuc static const krb5_keyblock member_keyblock = {
93ebfedea0SLionel Sambuc     ETYPE_ARCFOUR_HMAC_MD5,
94ebfedea0SLionel Sambuc     { 16, "\xD2\x17\xFA\xEA\xE5\xE6\xB5\xF9\x5C\xCC\x94\x07\x7A\xB8\xA5\xFC" }
95ebfedea0SLionel Sambuc };
96ebfedea0SLionel Sambuc 
97ebfedea0SLionel Sambuc static time_t authtime = 1120440609;
98ebfedea0SLionel Sambuc static const char *user = "w2003final$";
99ebfedea0SLionel Sambuc 
100ebfedea0SLionel Sambuc /*
101ebfedea0SLionel Sambuc  * This pac from Christan Krause
102ebfedea0SLionel Sambuc  */
103ebfedea0SLionel Sambuc 
104ebfedea0SLionel Sambuc static const unsigned char saved_pac2[] =
105ebfedea0SLionel Sambuc     "\x05\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\xc8\x01\x00\x00"
106ebfedea0SLionel Sambuc     "\x58\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x18\x00\x00\x00"
107ebfedea0SLionel Sambuc     "\x20\x02\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x70\x00\x00\x00"
108ebfedea0SLionel Sambuc     "\x38\x02\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x14\x00\x00\x00"
109ebfedea0SLionel Sambuc     "\xa8\x02\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x14\x00\x00\x00"
110ebfedea0SLionel Sambuc     "\xc0\x02\x00\x00\x00\x00\x00\x00\x01\x10\x08\x00\xcc\xcc\xcc\xcc"
111ebfedea0SLionel Sambuc     "\xb8\x01\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x7d\xee\x09\x76"
112ebfedea0SLionel Sambuc     "\xf2\x39\xc9\x01\xff\xff\xff\xff\xff\xff\xff\x7f\xff\xff\xff\xff"
113ebfedea0SLionel Sambuc     "\xff\xff\xff\x7f\x6d\x49\x38\x62\xf2\x39\xc9\x01\x6d\x09\xa2\x8c"
114ebfedea0SLionel Sambuc     "\xbb\x3a\xc9\x01\xff\xff\xff\xff\xff\xff\xff\x7f\x0e\x00\x0e\x00"
115ebfedea0SLionel Sambuc     "\x04\x00\x02\x00\x10\x00\x10\x00\x08\x00\x02\x00\x00\x00\x00\x00"
116ebfedea0SLionel Sambuc     "\x0c\x00\x02\x00\x00\x00\x00\x00\x10\x00\x02\x00\x00\x00\x00\x00"
117ebfedea0SLionel Sambuc     "\x14\x00\x02\x00\x00\x00\x00\x00\x18\x00\x02\x00\x02\x01\x00\x00"
118ebfedea0SLionel Sambuc     "\x52\x04\x00\x00\x01\x02\x00\x00\x03\x00\x00\x00\x1c\x00\x02\x00"
119ebfedea0SLionel Sambuc     "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
120ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x10\x00\x12\x00\x20\x00\x02\x00\x0e\x00\x10\x00"
121ebfedea0SLionel Sambuc     "\x24\x00\x02\x00\x28\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00"
122ebfedea0SLionel Sambuc     "\x10\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
123ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
124ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
125ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00"
126ebfedea0SLionel Sambuc     "\x6f\x00\x70\x00\x65\x00\x6e\x00\x6d\x00\x73\x00\x70\x00\x00\x00"
127ebfedea0SLionel Sambuc     "\x08\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x6f\x00\x70\x00"
128ebfedea0SLionel Sambuc     "\x65\x00\x6e\x00\x20\x00\x6d\x00\x73\x00\x70\x00\x00\x00\x00\x00"
129ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
130ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
131ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00"
132ebfedea0SLionel Sambuc     "\x60\x04\x00\x00\x07\x00\x00\x00\x01\x02\x00\x00\x07\x00\x00\x00"
133ebfedea0SLionel Sambuc     "\x5e\x04\x00\x00\x07\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00"
134ebfedea0SLionel Sambuc     "\x08\x00\x00\x00\x43\x00\x48\x00\x4b\x00\x52\x00\x2d\x00\x41\x00"
135ebfedea0SLionel Sambuc     "\x44\x00\x53\x00\x08\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00"
136ebfedea0SLionel Sambuc     "\x4d\x00\x53\x00\x50\x00\x2d\x00\x41\x00\x44\x00\x53\x00\x00\x00"
137ebfedea0SLionel Sambuc     "\x04\x00\x00\x00\x01\x04\x00\x00\x00\x00\x00\x05\x15\x00\x00\x00"
138ebfedea0SLionel Sambuc     "\x91\xad\xdc\x4c\x63\xb8\xb5\x48\xd5\x53\xd2\xd1\x00\x00\x00\x00"
139ebfedea0SLionel Sambuc     "\x00\x66\xeb\x75\xf2\x39\xc9\x01\x0e\x00\x6f\x00\x70\x00\x65\x00"
140ebfedea0SLionel Sambuc     "\x6e\x00\x6d\x00\x73\x00\x70\x00\x38\x00\x10\x00\x28\x00\x48\x00"
141ebfedea0SLionel Sambuc     "\x00\x00\x00\x00\x00\x00\x00\x00\x6f\x00\x70\x00\x65\x00\x6e\x00"
142ebfedea0SLionel Sambuc     "\x6d\x00\x73\x00\x70\x00\x40\x00\x6d\x00\x73\x00\x70\x00\x2d\x00"
143ebfedea0SLionel Sambuc     "\x61\x00\x64\x00\x73\x00\x2e\x00\x70\x00\x65\x00\x70\x00\x70\x00"
144ebfedea0SLionel Sambuc     "\x65\x00\x72\x00\x63\x00\x6f\x00\x6e\x00\x2e\x00\x64\x00\x65\x00"
145ebfedea0SLionel Sambuc     "\x4d\x00\x53\x00\x50\x00\x2d\x00\x41\x00\x44\x00\x53\x00\x2e\x00"
146ebfedea0SLionel Sambuc     "\x50\x00\x45\x00\x50\x00\x50\x00\x45\x00\x52\x00\x43\x00\x4f\x00"
147ebfedea0SLionel Sambuc     "\x4e\x00\x2e\x00\x44\x00\x45\x00\x76\xff\xff\xff\xb3\x56\x15\x29"
148ebfedea0SLionel Sambuc     "\x37\xc6\x5c\xf7\x97\x35\xfa\xec\x59\xe8\x96\xa0\x00\x00\x00\x00"
149ebfedea0SLionel Sambuc     "\x76\xff\xff\xff\x50\x71\xa2\xb1\xa3\x64\x82\x5c\xfd\x23\xea\x3b"
150ebfedea0SLionel Sambuc     "\xb0\x19\x12\xd4\x00\x00\x00\x00";
151ebfedea0SLionel Sambuc 
152ebfedea0SLionel Sambuc 
153ebfedea0SLionel Sambuc static const krb5_keyblock member_keyblock2 = {
154ebfedea0SLionel Sambuc     ETYPE_DES_CBC_MD5,
155ebfedea0SLionel Sambuc     { 8, "\x9e\x37\x83\x25\x4a\x7f\xf2\xf8" }
156ebfedea0SLionel Sambuc };
157ebfedea0SLionel Sambuc 
158ebfedea0SLionel Sambuc static time_t authtime2 = 1225304188;
159ebfedea0SLionel Sambuc static const char *user2 = "openmsp";
160ebfedea0SLionel Sambuc 
161ebfedea0SLionel Sambuc 
162ebfedea0SLionel Sambuc 
163ebfedea0SLionel Sambuc int
main(int argc,char ** argv)164ebfedea0SLionel Sambuc main(int argc, char **argv)
165ebfedea0SLionel Sambuc {
166ebfedea0SLionel Sambuc     krb5_error_code ret;
167ebfedea0SLionel Sambuc     krb5_context context;
168ebfedea0SLionel Sambuc     krb5_pac pac;
169ebfedea0SLionel Sambuc     krb5_data data;
170ebfedea0SLionel Sambuc     krb5_principal p, p2;
171ebfedea0SLionel Sambuc 
172ebfedea0SLionel Sambuc     ret = krb5_init_context(&context);
173ebfedea0SLionel Sambuc     if (ret)
174ebfedea0SLionel Sambuc 	errx(1, "krb5_init_contex");
175ebfedea0SLionel Sambuc 
176ebfedea0SLionel Sambuc     krb5_enctype_enable(context, ETYPE_DES_CBC_MD5);
177ebfedea0SLionel Sambuc 
178ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, user,
179ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_NO_REALM, &p);
180ebfedea0SLionel Sambuc     if (ret)
181ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
182ebfedea0SLionel Sambuc 
183ebfedea0SLionel Sambuc     ret = krb5_pac_parse(context, saved_pac, sizeof(saved_pac), &pac);
184ebfedea0SLionel Sambuc     if (ret)
185ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_parse");
186ebfedea0SLionel Sambuc 
187ebfedea0SLionel Sambuc     ret = krb5_pac_verify(context, pac, authtime, p,
188ebfedea0SLionel Sambuc 			   &member_keyblock, &kdc_keyblock);
189ebfedea0SLionel Sambuc     if (ret)
190ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_verify");
191ebfedea0SLionel Sambuc 
192ebfedea0SLionel Sambuc     ret = _krb5_pac_sign(context, pac, authtime, p,
193ebfedea0SLionel Sambuc 			 &member_keyblock, &kdc_keyblock, &data);
194ebfedea0SLionel Sambuc     if (ret)
195ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "_krb5_pac_sign");
196ebfedea0SLionel Sambuc 
197ebfedea0SLionel Sambuc     krb5_pac_free(context, pac);
198ebfedea0SLionel Sambuc 
199ebfedea0SLionel Sambuc     ret = krb5_pac_parse(context, data.data, data.length, &pac);
200ebfedea0SLionel Sambuc     krb5_data_free(&data);
201ebfedea0SLionel Sambuc     if (ret)
202ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_parse 2");
203ebfedea0SLionel Sambuc 
204ebfedea0SLionel Sambuc     ret = krb5_pac_verify(context, pac, authtime, p,
205ebfedea0SLionel Sambuc 			   &member_keyblock, &kdc_keyblock);
206ebfedea0SLionel Sambuc     if (ret)
207ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_verify 2");
208ebfedea0SLionel Sambuc 
209ebfedea0SLionel Sambuc     /* make a copy and try to reproduce it */
210ebfedea0SLionel Sambuc     {
211ebfedea0SLionel Sambuc 	uint32_t *list;
212ebfedea0SLionel Sambuc 	size_t len, i;
213ebfedea0SLionel Sambuc 	krb5_pac pac2;
214ebfedea0SLionel Sambuc 
215ebfedea0SLionel Sambuc 	ret = krb5_pac_init(context, &pac2);
216ebfedea0SLionel Sambuc 	if (ret)
217ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_init");
218ebfedea0SLionel Sambuc 
219ebfedea0SLionel Sambuc 	/* our two user buffer plus the three "system" buffers */
220ebfedea0SLionel Sambuc 	ret = krb5_pac_get_types(context, pac, &len, &list);
221ebfedea0SLionel Sambuc 	if (ret)
222ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_get_types");
223ebfedea0SLionel Sambuc 
224ebfedea0SLionel Sambuc 	for (i = 0; i < len; i++) {
225ebfedea0SLionel Sambuc 	    /* skip server_cksum, privsvr_cksum, and logon_name */
226ebfedea0SLionel Sambuc 	    if (list[i] == 6 || list[i] == 7 || list[i] == 10)
227ebfedea0SLionel Sambuc 		continue;
228ebfedea0SLionel Sambuc 
229ebfedea0SLionel Sambuc 	    ret = krb5_pac_get_buffer(context, pac, list[i], &data);
230ebfedea0SLionel Sambuc 	    if (ret)
231ebfedea0SLionel Sambuc 		krb5_err(context, 1, ret, "krb5_pac_get_buffer");
232ebfedea0SLionel Sambuc 
233ebfedea0SLionel Sambuc 	    if (list[i] == 1) {
234ebfedea0SLionel Sambuc 		if (type_1_length != data.length)
235ebfedea0SLionel Sambuc 		    krb5_errx(context, 1, "type 1 have wrong length: %lu",
236ebfedea0SLionel Sambuc 			      (unsigned long)data.length);
237ebfedea0SLionel Sambuc 	    } else
238ebfedea0SLionel Sambuc 		krb5_errx(context, 1, "unknown type %lu",
239ebfedea0SLionel Sambuc 			  (unsigned long)list[i]);
240ebfedea0SLionel Sambuc 
241ebfedea0SLionel Sambuc 	    ret = krb5_pac_add_buffer(context, pac2, list[i], &data);
242ebfedea0SLionel Sambuc 	    if (ret)
243ebfedea0SLionel Sambuc 		krb5_err(context, 1, ret, "krb5_pac_add_buffer");
244ebfedea0SLionel Sambuc 	    krb5_data_free(&data);
245ebfedea0SLionel Sambuc 	}
246ebfedea0SLionel Sambuc 	free(list);
247ebfedea0SLionel Sambuc 
248ebfedea0SLionel Sambuc 	ret = _krb5_pac_sign(context, pac2, authtime, p,
249ebfedea0SLionel Sambuc 			     &member_keyblock, &kdc_keyblock, &data);
250ebfedea0SLionel Sambuc 	if (ret)
251ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "_krb5_pac_sign 4");
252ebfedea0SLionel Sambuc 
253ebfedea0SLionel Sambuc 	krb5_pac_free(context, pac2);
254ebfedea0SLionel Sambuc 
255ebfedea0SLionel Sambuc 	ret = krb5_pac_parse(context, data.data, data.length, &pac2);
256ebfedea0SLionel Sambuc 	krb5_data_free(&data);
257ebfedea0SLionel Sambuc 	if (ret)
258ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_parse 4");
259ebfedea0SLionel Sambuc 
260ebfedea0SLionel Sambuc 	ret = krb5_pac_verify(context, pac2, authtime, p,
261ebfedea0SLionel Sambuc 			      &member_keyblock, &kdc_keyblock);
262ebfedea0SLionel Sambuc 	if (ret)
263ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_verify 4");
264ebfedea0SLionel Sambuc 
265ebfedea0SLionel Sambuc 	krb5_pac_free(context, pac2);
266ebfedea0SLionel Sambuc     }
267ebfedea0SLionel Sambuc 
268ebfedea0SLionel Sambuc     krb5_pac_free(context, pac);
269ebfedea0SLionel Sambuc 
270ebfedea0SLionel Sambuc     /*
271ebfedea0SLionel Sambuc      * check pac from Christian
272ebfedea0SLionel Sambuc      */
273ebfedea0SLionel Sambuc 
274ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, user2,
275ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_NO_REALM, &p2);
276ebfedea0SLionel Sambuc     if (ret)
277ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
278ebfedea0SLionel Sambuc 
279ebfedea0SLionel Sambuc     ret = krb5_pac_parse(context, saved_pac2, sizeof(saved_pac2) -1, &pac);
280ebfedea0SLionel Sambuc     if (ret)
281ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_parse");
282ebfedea0SLionel Sambuc 
283ebfedea0SLionel Sambuc     ret = krb5_pac_verify(context, pac, authtime2, p2,
284ebfedea0SLionel Sambuc 			   &member_keyblock2, NULL);
285ebfedea0SLionel Sambuc     if (ret)
286ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_verify c1");
287ebfedea0SLionel Sambuc 
288ebfedea0SLionel Sambuc     krb5_pac_free(context, pac);
289ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
290ebfedea0SLionel Sambuc 
291ebfedea0SLionel Sambuc     /*
292ebfedea0SLionel Sambuc      * Test empty free
293ebfedea0SLionel Sambuc      */
294ebfedea0SLionel Sambuc 
295ebfedea0SLionel Sambuc     ret = krb5_pac_init(context, &pac);
296ebfedea0SLionel Sambuc     if (ret)
297ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_init");
298ebfedea0SLionel Sambuc     krb5_pac_free(context, pac);
299ebfedea0SLionel Sambuc 
300ebfedea0SLionel Sambuc     /*
301ebfedea0SLionel Sambuc      * Test add remove buffer
302ebfedea0SLionel Sambuc      */
303ebfedea0SLionel Sambuc 
304ebfedea0SLionel Sambuc     ret = krb5_pac_init(context, &pac);
305ebfedea0SLionel Sambuc     if (ret)
306ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_init");
307ebfedea0SLionel Sambuc 
308ebfedea0SLionel Sambuc     {
309ebfedea0SLionel Sambuc 	const krb5_data cdata = { 2, "\x00\x01" } ;
310ebfedea0SLionel Sambuc 
311ebfedea0SLionel Sambuc 	ret = krb5_pac_add_buffer(context, pac, 1, &cdata);
312ebfedea0SLionel Sambuc 	if (ret)
313ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_add_buffer");
314ebfedea0SLionel Sambuc     }
315ebfedea0SLionel Sambuc     {
316ebfedea0SLionel Sambuc 	ret = krb5_pac_get_buffer(context, pac, 1, &data);
317ebfedea0SLionel Sambuc 	if (ret)
318ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_get_buffer");
319ebfedea0SLionel Sambuc 	if (data.length != 2 || memcmp(data.data, "\x00\x01", 2) != 0)
320ebfedea0SLionel Sambuc 	    krb5_errx(context, 1, "krb5_pac_get_buffer data not the same");
321ebfedea0SLionel Sambuc 	krb5_data_free(&data);
322ebfedea0SLionel Sambuc     }
323ebfedea0SLionel Sambuc 
324ebfedea0SLionel Sambuc     {
325ebfedea0SLionel Sambuc 	const krb5_data cdata = { 2, "\x02\x00" } ;
326ebfedea0SLionel Sambuc 
327ebfedea0SLionel Sambuc 	ret = krb5_pac_add_buffer(context, pac, 2, &cdata);
328ebfedea0SLionel Sambuc 	if (ret)
329ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_add_buffer");
330ebfedea0SLionel Sambuc     }
331ebfedea0SLionel Sambuc     {
332ebfedea0SLionel Sambuc 	ret = krb5_pac_get_buffer(context, pac, 1, &data);
333ebfedea0SLionel Sambuc 	if (ret)
334ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_get_buffer");
335ebfedea0SLionel Sambuc 	if (data.length != 2 || memcmp(data.data, "\x00\x01", 2) != 0)
336ebfedea0SLionel Sambuc 	    krb5_errx(context, 1, "krb5_pac_get_buffer data not the same");
337ebfedea0SLionel Sambuc 	krb5_data_free(&data);
338ebfedea0SLionel Sambuc 	/* */
339ebfedea0SLionel Sambuc 	ret = krb5_pac_get_buffer(context, pac, 2, &data);
340ebfedea0SLionel Sambuc 	if (ret)
341ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_get_buffer");
342ebfedea0SLionel Sambuc 	if (data.length != 2 || memcmp(data.data, "\x02\x00", 2) != 0)
343ebfedea0SLionel Sambuc 	    krb5_errx(context, 1, "krb5_pac_get_buffer data not the same");
344ebfedea0SLionel Sambuc 	krb5_data_free(&data);
345ebfedea0SLionel Sambuc     }
346ebfedea0SLionel Sambuc 
347ebfedea0SLionel Sambuc     ret = _krb5_pac_sign(context, pac, authtime, p,
348ebfedea0SLionel Sambuc 			 &member_keyblock, &kdc_keyblock, &data);
349ebfedea0SLionel Sambuc     if (ret)
350ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "_krb5_pac_sign");
351ebfedea0SLionel Sambuc 
352ebfedea0SLionel Sambuc     krb5_pac_free(context, pac);
353ebfedea0SLionel Sambuc 
354ebfedea0SLionel Sambuc     ret = krb5_pac_parse(context, data.data, data.length, &pac);
355ebfedea0SLionel Sambuc     krb5_data_free(&data);
356ebfedea0SLionel Sambuc     if (ret)
357ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_parse 3");
358ebfedea0SLionel Sambuc 
359ebfedea0SLionel Sambuc     ret = krb5_pac_verify(context, pac, authtime, p,
360ebfedea0SLionel Sambuc 			   &member_keyblock, &kdc_keyblock);
361ebfedea0SLionel Sambuc     if (ret)
362ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_pac_verify 3");
363ebfedea0SLionel Sambuc 
364ebfedea0SLionel Sambuc     {
365ebfedea0SLionel Sambuc 	uint32_t *list;
366ebfedea0SLionel Sambuc 	size_t len;
367ebfedea0SLionel Sambuc 
368ebfedea0SLionel Sambuc 	/* our two user buffer plus the three "system" buffers */
369ebfedea0SLionel Sambuc 	ret = krb5_pac_get_types(context, pac, &len, &list);
370ebfedea0SLionel Sambuc 	if (ret)
371ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "krb5_pac_get_types");
372ebfedea0SLionel Sambuc 	if (len != 5)
373ebfedea0SLionel Sambuc 	    krb5_errx(context, 1, "list wrong length");
374ebfedea0SLionel Sambuc 	free(list);
375ebfedea0SLionel Sambuc     }
376ebfedea0SLionel Sambuc 
377ebfedea0SLionel Sambuc     krb5_pac_free(context, pac);
378ebfedea0SLionel Sambuc 
379ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
380ebfedea0SLionel Sambuc     krb5_free_context(context);
381ebfedea0SLionel Sambuc 
382ebfedea0SLionel Sambuc     return 0;
383ebfedea0SLionel Sambuc }
384