Waste less stack.
[shishi.git] / tests / ticketset.c
blobaf90a1d38398708b4ed94db6ec51d365920fe8f0
1 /* ticketset.c Shishi ticketset self tests.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "utils.c"
23 #include <shishi.h>
25 static const char tkt1kdcrepb64[] =
26 "a4ICITCCAh2gAwIBBaEDAgELow8bDUpPU0VGU1NPTi5PUkekEDAOoAMCAQGhBzAF"
27 "GwNqYXOlggECYYH/MIH8oAMCAQWhDxsNSk9TRUZTU09OLk9SR6IiMCCgAwIBAaEZ"
28 "MBcbBmtyYnRndBsNSk9TRUZTU09OLk9SR6OBvzCBvKADAgEQoQMCAQGiga8Egayq"
29 "ttjMpRNM2iVVR5RjtMNH3i75hjnUiXQ7UeT7DMShJ5IxiBr09dggaZzTAHrBAvV8"
30 "5xON3p39rMpmCg9utizrxzT1JXruoGF/+ofuT7lEDfRr437QJD5WuOtlfmkM2i5s"
31 "2bGYZlHNdBonapJCcMeUSS45HEoM5iy0dK2JeaOliOVKTDpX9gOayKSIFYnuzIb+"
32 "cg1ATHm29ahK5AY+LU9E4v8Yj1/02srRuERApoHnMIHkoAMCARChAwIBBaKB1wSB"
33 "1AiMSoSQrE5FSE2CYpTOdLgVWRw/k1cqBtswVKRTdgj2As6WG6mhFczy7RF62GVM"
34 "6gJGNQRx1mAg0d5C7pNKRCgAZ2oQdJIGW6CLTy2L0LxM104HA0XrZ+zfFLKlZTOV"
35 "T85LIoSneI/yKNh3iYeVQwp6AdMRw6562fHMie22I4sy22wNVz1toTrKixILvoMy"
36 "eoD7ET43Y1eo0SeXj8LPmZyqLARBknl2ZvNcDpjWpI57QycHV28BhcvVPu72kObJ"
37 "/68tCNEJ8J+vHArpFA5V9BDsFcGs";
39 static const char tkt1enckdcreppartb64[] =
40 "eYGyMIGvoCMwIaADAgEQoRoEGPF/LFgc3IYq3+AZofutur+wsK5i6vSbN6EcMBow"
41 "GKADAgEAoREYDzE5NzAwMTAxMDAwMDAwWqIGAgTl7iQgpAcDBQAAQAAApREYDzIw"
42 "MDIxMjExMTM0MDU0WqcRGA8yMDAyMTIxMTEzNTczNFqpDxsNSk9TRUZTU09OLk9S"
43 "R6oiMCCgAwIBAaEZMBcbBmtyYnRndBsNSk9TRUZTU09OLk9SRw==";
45 static const char tkt1ticketb64[] =
46 "YYH/MIH8oAMCAQWhDxsNSk9TRUZTU09OLk9SR6IiMCCgAwIBAaEZMBcbBmtyYnRn"
47 "dBsNSk9TRUZTU09OLk9SR6OBvzCBvKADAgEQoQMCAQGiga8EgayqttjMpRNM2iVV"
48 "R5RjtMNH3i75hjnUiXQ7UeT7DMShJ5IxiBr09dggaZzTAHrBAvV85xON3p39rMpm"
49 "Cg9utizrxzT1JXruoGF/+ofuT7lEDfRr437QJD5WuOtlfmkM2i5s2bGYZlHNdBon"
50 "apJCcMeUSS45HEoM5iy0dK2JeaOliOVKTDpX9gOayKSIFYnuzIb+cg1ATHm29ahK"
51 "5AY+LU9E4v8Yj1/02srRuERA";
53 static const char tkt2kdcrepb64[] =
54 "bYICSjCCAkagAwIBBaEDAgENow8bDUpPU0VGU1NPTi5PUkekEDAOoAMCAQGhBzAF"
55 "GwNqYXOlggEYYYIBFDCCARCgAwIBBaEPGw1KT1NFRlNTT04uT1JHoiYwJKADAgEB"
56 "oR0wGxsEaG9zdBsTbGF0dGUuam9zZWZzc29uLm9yZ6OBzzCBzKADAgEQoQMCAQKi"
57 "gb8EgbzEU6KFfSSQg4xxSxJBp2QBtaNGyzawROAGFsztZcY+gl5K2ki6xDT10kCY"
58 "yfORXXXraoYIcwJl6EW8RGl4KKsZlZmNWuw0/mO4Gglga6sM06vQDs2TcSc8hWDJ"
59 "4I1vU6/WlKtwzNj0Cw+6fqyDJIt6PmRpUe/yGZe6hSQkrqgQuBhpAHZF4/aoWqOm"
60 "NufTdGa+5gHzqcEmQerWD8YhImeD+Xe5citg92XTPx2nHiNMBMmwgWJHf1Tjddiw"
61 "saaB+jCB96ADAgEQooHvBIHsmctkNNI2jJwUEdTe9o5WeHyTCWMSO9AA0luxjX2D"
62 "CR5kNOZuPx5YfHWHwKlqrOtwo1E0Cb7bpKHPUOWhhIGUXcV0z1ETSEOX8Ho3iIOc"
63 "8LSNVq8UqVf/wBnndLiljZveTbbu+YcFNbF7g+q2VDYffKgXsUi6HV2Ue7OGawvY"
64 "DxU7KDVpPWgitPGrNItdaJ1QVfVH+cXLdiqEV7RR+JOsFc8jkBxNOq/rx60Ga73F"
65 "urdXCqM1tz5T2QHgoI6y0HjGuEbjymFQfCt1hclIvu7EzWn29p2oZJUj1Vv7vpNz"
66 "tDy+gjC3uMYj7JGdoTg=";
68 static const char tkt2enckdcreppartb64[] =
69 "eoHJMIHGoCMwIaADAgEQoRoEGFS29KeMuXZDeqcEud/gWHln/db7bje26aEcMBow"
70 "GKADAgEAoREYDzE5NzAwMTAxMDAwMDAwWqIGAgScLHDdpAcDBQAAAAAApREYDzIw"
71 "MDIxMjExMTM0MDU0WqYRGA8yMDAyMTIxMTEzNDEwNFqnERgPMjAwMjEyMTExMzU3"
72 "MzRaqQ8bDUpPU0VGU1NPTi5PUkeqJjAkoAMCAQGhHTAbGwRob3N0GxNsYXR0ZS5q"
73 "b3NlZnNzb24ub3Jn";
75 static const char tkt2ticketb64[] =
76 "YYIBFDCCARCgAwIBBaEPGw1KT1NFRlNTT04uT1JHoiYwJKADAgEBoR0wGxsEaG9z"
77 "dBsTbGF0dGUuam9zZWZzc29uLm9yZ6OBzzCBzKADAgEQoQMCAQKigb8EgbzEU6KF"
78 "fSSQg4xxSxJBp2QBtaNGyzawROAGFsztZcY+gl5K2ki6xDT10kCYyfORXXXraoYI"
79 "cwJl6EW8RGl4KKsZlZmNWuw0/mO4Gglga6sM06vQDs2TcSc8hWDJ4I1vU6/WlKtw"
80 "zNj0Cw+6fqyDJIt6PmRpUe/yGZe6hSQkrqgQuBhpAHZF4/aoWqOmNufTdGa+5gHz"
81 "qcEmQerWD8YhImeD+Xe5citg92XTPx2nHiNMBMmwgWJHf1TjddiwsQ==";
83 int
84 main (int argc, char *argv[])
86 Shishi *handle;
87 Shishi_tkts *tktset;
88 Shishi_tkts_hint hint;
89 Shishi_tkt *t1, *t2, *t3;
90 Shishi_asn1 n1, n2, n3;
91 char buffer[BUFSIZ];
92 char buffer2[BUFSIZ];
93 char *p, *q;
94 int n, res;
97 if (strcmp (argv[argc - 1], "-v") == 0 ||
98 strcmp (argv[argc - 1], "--verbose") == 0)
99 verbose = 1;
100 else if (strcmp (argv[argc - 1], "-d") == 0 ||
101 strcmp (argv[argc - 1], "--debug") == 0)
102 debug = 1;
103 else if (strcmp (argv[argc - 1], "-b") == 0 ||
104 strcmp (argv[argc - 1], "--break-on-error") == 0)
105 break_on_error = 1;
106 else if (strcmp (argv[argc - 1], "-h") == 0 ||
107 strcmp (argv[argc - 1], "-?") == 0 ||
108 strcmp (argv[argc - 1], "--help") == 0)
110 printf ("Usage: %s [-vdbh?] [--verbose] [--debug] "
111 "[--break-on-error] [--help]\n", argv[0]);
112 return 1;
114 while (argc-- > 1);
116 handle = shishi ();
117 if (handle == NULL)
119 fail ("Could not initialize shishi\n");
120 return 1;
123 if (debug)
124 shishi_cfg (handle, strdup ("verbose"));
126 escapeprint (NULL, 0);
127 hexprint (NULL, 0);
128 binprint (NULL, 0);
130 /* shishi_tkts_default_file() */
131 p = strdup (shishi_tkts_default_file (handle));
132 if (debug)
133 printf ("shishi_tkts_default_file () => `%s'.\n", p ? p : "<null>");
134 if (p)
135 success ("shishi_tkts_default_file() OK\n");
136 else
137 fail ("shishi_tkts_default_file() failed\n");
139 /* shishi_tkts_default_file_set() */
140 shishi_tkts_default_file_set (handle, "foo");
141 q = strdup (shishi_tkts_default_file (handle));
142 if (debug)
143 printf ("shishi_tkts_default_file () => `%s'.\n", q ? q : "<null>");
144 if (q && strcmp (q, "foo") == 0)
145 success ("shishi_tkts_default_file_set() OK\n");
146 else
147 fail ("shishi_tkts_default_file_set() failed\n");
148 free (q);
150 /* shishi_tkts_default_file_set() */
151 shishi_tkts_default_file_set (handle, NULL);
152 q = strdup (shishi_tkts_default_file (handle));
153 if (debug)
154 printf ("shishi_tkts_default_file () => `%s'.\n", q ? q : "<null>");
155 if (p && q && strcmp (p, q) == 0)
156 success ("shishi_tkts_default_file_set() OK\n");
157 else
158 fail ("shishi_tkts_default_file_set() failed\n");
159 free (q);
160 free (p);
162 /* shishi_tkts () */
163 res = shishi_tkts (handle, &tktset);
164 if (res == SHISHI_OK)
165 success ("shishi_tkts() OK\n");
166 else
167 fail ("shishi_tkts() failed\n");
169 /* shishi_tkts_size () */
170 n = shishi_tkts_size (tktset);
171 if (debug)
172 printf ("shishi_tkts_size () => `%d'.\n", n);
173 if (n == 0)
174 success ("shishi_tkts_size() OK\n");
175 else
176 fail ("shishi_tkts_size() failed\n");
178 /* shishi_tkts_nth () */
179 t1 = shishi_tkts_nth (tktset, 0);
180 if (t1 == NULL)
181 success ("shishi_tkts_nth() OK\n");
182 else
183 fail ("shishi_tkts_nth() failed\n");
185 /* shishi_tkts_nth () */
186 t1 = shishi_tkts_nth (tktset, 42);
187 if (t1 == NULL)
188 success ("shishi_tkts_nth() OK\n");
189 else
190 fail ("shishi_tkts_nth() failed\n");
192 /* shishi_tkts_add () */
193 res = shishi_tkts_add (tktset, NULL);
194 if (res == SHISHI_INVALID_TICKET)
195 success ("shishi_tkts_add() OK\n");
196 else
197 fail ("shishi_tkts_add() failed\n");
199 /* shishi_tkts_remove () */
200 res = shishi_tkts_remove (tktset, 0);
201 if (res == SHISHI_OK)
202 success ("shishi_tkts_remove() OK\n");
203 else
204 fail ("shishi_tkts_remove() failed\n");
206 /* shishi_tkts_remove () */
207 res = shishi_tkts_remove (tktset, 42);
208 if (res == SHISHI_OK)
209 success ("shishi_tkts_remove() OK\n");
210 else
211 fail ("shishi_tkts_remove() failed\n");
213 /* shishi_tkts_remove () */
214 res = shishi_tkts_remove (NULL, 0);
215 if (res == SHISHI_INVALID_TKTS)
216 success ("shishi_tkts_remove() OK\n");
217 else
218 fail ("shishi_tkts_remove() failed\n");
220 /* create ticket */
221 n = shishi_from_base64 (buffer, tkt1ticketb64);
222 if (n == -1)
223 die ("shishi_from_base64() failed\n");
224 n1 = shishi_der2asn1_ticket (handle, buffer, n);
225 if (!n1)
226 die ("shishi_der2asn1_ticket() failed\n");
228 n = shishi_from_base64 (buffer, tkt1enckdcreppartb64);
229 if (n == -1)
230 die ("shishi_from_base64() failed\n");
231 n2 = shishi_der2asn1_encasreppart (handle, buffer, n);
232 if (!n2)
233 die ("shishi_der2asn1_encasreppart() failed\n");
235 n = shishi_from_base64 (buffer, tkt1kdcrepb64);
236 if (n == -1)
237 die ("shishi_from_base64() failed\n");
238 n3 = shishi_der2asn1_asrep (handle, buffer, n);
239 if (!n3)
240 die ("shishi_der2asn1_asrep() failed\n");
242 /* shishi_tkts_new() */
243 res = shishi_tkts_new (tktset, n1, n2, n3);
244 if (res == SHISHI_OK)
245 success ("shishi_tkts_new() OK\n");
246 else
247 fail ("shishi_tkts_new() failed\n");
249 /* shishi_tkts_size () */
250 n = shishi_tkts_size (tktset);
251 if (debug)
252 printf ("shishi_tkts_size () => `%d'.\n", n);
253 if (n == 1)
254 success ("shishi_tkts_size() OK\n");
255 else
256 fail ("shishi_tkts_size() failed\n");
258 /* shishi_tkts_nth () */
259 t1 = shishi_tkts_nth (tktset, 0);
260 if (debug)
262 shishi_tkt_pretty_print (t1, stdout);
263 printf ("t1=%p\n", t1);
265 if (t1)
266 success ("shishi_tkts_nth() OK\n");
267 else
268 fail ("shishi_tkts_nth() failed\n");
270 /* shishi_tkts_remove () */
271 res = shishi_tkts_remove (tktset, 0);
272 if (res == SHISHI_OK)
273 success ("shishi_tkts_remove() OK\n");
274 else
275 fail ("shishi_tkts_remove() failed\n");
277 /* shishi_tkts_size () */
278 n = shishi_tkts_size (tktset);
279 if (debug)
280 printf ("shishi_tkts_size () => `%d'.\n", n);
281 if (n == 0)
282 success ("shishi_tkts_size() OK\n");
283 else
284 fail ("shishi_tkts_size() failed\n");
286 /* shishi_tkts_nth () */
287 t2 = shishi_tkts_nth (tktset, 0);
288 if (t2 == NULL)
289 success ("shishi_tkts_nth() OK\n");
290 else
291 fail ("shishi_tkts_nth() failed\n");
293 /* shishi_tkts_add () */
294 res = shishi_tkts_add (tktset, t1);
295 if (res == SHISHI_OK)
296 success ("shishi_tkts_add() OK\n");
297 else
298 fail ("shishi_tkts_add() failed\n");
300 /* shishi_tkts_size () */
301 n = shishi_tkts_size (tktset);
302 if (debug)
303 printf ("shishi_tkts_size () => `%d'.\n", n);
304 if (n == 1)
305 success ("shishi_tkts_size() OK\n");
306 else
307 fail ("shishi_tkts_size() failed\n");
309 /* create ticket */
310 n = shishi_from_base64 (buffer, tkt2ticketb64);
311 if (n == -1)
312 die ("shishi_from_base64() failed\n");
313 n1 = shishi_der2asn1_ticket (handle, buffer, n);
314 if (!n1)
315 die ("shishi_der2asn1_ticket() failed\n");
317 n = shishi_from_base64 (buffer, tkt2enckdcreppartb64);
318 if (n == -1)
319 die ("shishi_from_base64() failed\n");
320 n2 = shishi_der2asn1_enctgsreppart (handle, buffer, n);
321 if (!n2)
322 die ("shishi_der2asn1_enctgsreppart() failed\n");
324 n = shishi_from_base64 (buffer, tkt2kdcrepb64);
325 if (n == -1)
326 die ("shishi_from_base64() failed\n");
327 n3 = shishi_der2asn1_tgsrep (handle, buffer, n);
328 if (!n3)
329 die ("shishi_der2asn1_kdcrep() failed\n");
331 /* shishi_tkts_new() */
332 res = shishi_tkts_new (tktset, n1, n2, n3);
333 if (res == SHISHI_OK)
334 success ("shishi_tkts_new() OK\n");
335 else
336 fail ("shishi_tkts_new() failed\n");
338 /* shishi_tkts_size () */
339 n = shishi_tkts_size (tktset);
340 if (debug)
341 printf ("shishi_tkts_size () => `%d'.\n", n);
342 if (n == 2)
343 success ("shishi_tkts_size() OK\n");
344 else
345 fail ("shishi_tkts_size() failed\n");
347 /* shishi_tkts_nth () */
348 t2 = shishi_tkts_nth (tktset, 1);
349 if (debug)
351 shishi_tkt_pretty_print (t2, stdout);
352 printf ("t2=%p\n", t2);
354 if (t2)
355 success ("shishi_tkts_nth() OK\n");
356 else
357 fail ("shishi_tkts_nth() failed\n");
359 /* shishi_tkts_find () */
360 memset (&hint, 0, sizeof (hint));
361 hint.server = "host/latte.josefsson.org";
362 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
363 t3 = shishi_tkts_find (tktset, &hint);
364 if (debug)
365 printf ("t3=%p\n", t3);
366 if (t3 == t2)
367 success ("shishi_tkts_find() for server OK\n");
368 else
369 fail ("shishi_tkts_find() for server failed\n");
371 /* shishi_tkts_find () */
372 memset (&hint, 0, sizeof (hint));
373 hint.server = "krbtgt/JOSEFSSON.ORG";
374 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
375 t3 = shishi_tkts_find (tktset, &hint);
376 if (t3 == t1)
377 success ("shishi_tkts_find() for server OK\n");
378 else
379 fail ("shishi_tkts_find() for server failed\n");
381 /* shishi_tkts_find () */
382 memset (&hint, 0, sizeof (hint));
383 hint.client = "jas";
384 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
385 t3 = shishi_tkts_find (tktset, &hint);
386 if (debug)
387 printf ("t3=%p\n", t3);
388 if (t3 == t1)
389 success ("shishi_tkts_find() for client OK\n");
390 else
391 fail ("shishi_tkts_find() for client failed\n");
393 /* shishi_tkts_find () */
394 memset (&hint, 0, sizeof (hint));
395 hint.client = "jas";
396 t3 = shishi_tkts_find (tktset, &hint);
397 if (debug)
398 printf ("t3=%p\n", t3);
399 if (t3 == NULL)
400 success ("shishi_tkts_find() for client OK\n");
401 else
402 fail ("shishi_tkts_find() for client failed\n");
404 res = shishi_tkts_to_file (tktset, "tktset.tmp");
405 if (res == SHISHI_OK)
406 success ("shishi_tkts_to_file() OK\n");
407 else
408 fail ("shishi_tkts_to_file() failed\n");
410 /* shishi_tkts_add () */
411 res = shishi_tkts_add (tktset, t2);
412 if (res == SHISHI_OK)
413 success ("shishi_tkts_add() OK\n");
414 else
415 fail ("shishi_tkts_add() failed\n");
417 /* shishi_tkts_add () */
418 res = shishi_tkts_add (tktset, t1);
419 if (res == SHISHI_OK)
420 success ("shishi_tkts_add() OK\n");
421 else
422 fail ("shishi_tkts_add() failed\n");
424 /* shishi_tkts_remove () */
425 res = shishi_tkts_remove (tktset, 1);
426 if (res == SHISHI_OK)
427 success ("shishi_tkts_remove() OK\n");
428 else
429 fail ("shishi_tkts_remove() failed\n");
431 /* shishi_tkts_remove () */
432 res = shishi_tkts_remove (tktset, 1);
433 if (res == SHISHI_OK)
434 success ("shishi_tkts_remove() OK\n");
435 else
436 fail ("shishi_tkts_remove() failed\n");
438 memset (&hint, 0, sizeof (hint));
439 hint.server = "host/latte.josefsson.org";
440 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
441 t3 = shishi_tkts_find (tktset, &hint);
442 if (t3 == NULL)
443 success ("shishi_tkts_find() for server OK\n");
444 else
445 fail ("shishi_tkts_find() for server failed\n");
447 memset (&hint, 0, sizeof (hint));
448 hint.server = "krbtgt/JOSEFSSON.ORG";
449 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
450 t3 = shishi_tkts_find (tktset, &hint);
451 if (t3 == t1)
452 success ("shishi_tkts_find() for server OK\n");
453 else
454 fail ("shishi_tkts_find() for server failed\n");
456 /* shishi_tkts_remove () */
457 res = shishi_tkts_remove (tktset, 0);
458 if (res == SHISHI_OK)
459 success ("shishi_tkts_remove() OK\n");
460 else
461 fail ("shishi_tkts_remove() failed\n");
463 /* shishi_tkts_remove () */
464 res = shishi_tkts_remove (tktset, 0);
465 if (res == SHISHI_OK)
466 success ("shishi_tkts_remove() OK\n");
467 else
468 fail ("shishi_tkts_remove() failed\n");
470 /* shishi_tkts_size () */
471 n = shishi_tkts_size (tktset);
472 if (debug)
473 printf ("shishi_tkts_size () => `%d'.\n", n);
474 if (n == 0)
475 success ("shishi_tkts_size() OK\n");
476 else
477 fail ("shishi_tkts_size() failed\n");
479 /* shishi_tkts_done () */
480 shishi_tkts_done (&tktset);
481 success ("shishi_tkts_done() OK\n");
483 shishi_tkt_done (t1);
484 success ("shishi_tkt_done (t1) OK\n");
485 shishi_tkt_done (t2);
486 success ("shishi_tkt_done (t2) OK\n");
488 /* shishi_tkts_done () */
489 shishi_tkts_done (NULL);
490 success ("shishi_tkts_done() OK\n");
492 /* shishi_tkts () */
493 res = shishi_tkts (handle, &tktset);
494 if (res == SHISHI_OK)
495 success ("shishi_tkts() OK\n");
496 else
497 fail ("shishi_tkts() failed\n");
499 /* shishi_tkts_from_file () */
500 res = shishi_tkts_from_file (tktset, "tktset.tmp");
501 if (res == SHISHI_OK)
502 success ("shishi_tkts_to_file() OK\n");
503 else
504 fail ("shishi_tkts_to_file() failed\n");
506 /* shishi_tkts_size () */
507 n = shishi_tkts_size (tktset);
508 if (debug)
509 printf ("shishi_tkts_size () => `%d'.\n", n);
510 if (n == 2)
511 success ("shishi_tkts_size() OK\n");
512 else
513 fail ("shishi_tkts_size() failed\n");
515 /* shishi_tkts_nth () */
516 t1 = shishi_tkts_nth (tktset, 0);
517 if (debug)
518 shishi_tkt_pretty_print (t1, stdout);
519 if (t1)
520 success ("shishi_tkts_nth() OK\n");
521 else
522 fail ("shishi_tkts_nth() failed\n");
524 /* shishi_tkts_nth () */
525 t2 = shishi_tkts_nth (tktset, 1);
526 if (debug)
527 shishi_tkt_pretty_print (t2, stdout);
528 if (t2)
529 success ("shishi_tkts_nth() OK\n");
530 else
531 fail ("shishi_tkts_nth() failed\n");
533 /* DER encode and compare tkt1 ticket */
534 res = shishi_a2d (handle, shishi_tkt_ticket (t1), buffer, &n);
535 if (res == SHISHI_OK)
536 success ("shishi_a2d() OK\n");
537 else
538 n = 0, fail ("shishi_a2d() failed\n");
540 shishi_to_base64 (buffer2, buffer, n, BUFSIZ);
541 if (strlen (buffer2) == strlen (tkt1ticketb64) &&
542 memcmp (buffer2, tkt1ticketb64, strlen (tkt1ticketb64)) == 0)
543 success ("Ticket read OK\n");
544 else
545 fail ("Ticket read failed\n");
547 /* DER encode and compare tkt1 enckdcreppart */
548 res = shishi_a2d (handle, shishi_tkt_enckdcreppart (t1), buffer, &n);
549 if (res == SHISHI_OK)
550 success ("shishi_a2d() OK\n");
551 else
552 n = 0, fail ("shishi_a2d() failed\n");
554 shishi_to_base64 (buffer2, buffer, n, BUFSIZ);
555 if (strlen (buffer2) == strlen (tkt1enckdcreppartb64) &&
556 memcmp (buffer2, tkt1enckdcreppartb64,
557 strlen (tkt1enckdcreppartb64)) == 0)
558 success ("EncKDCRepPart read OK\n");
559 else
560 fail ("EncKDCRepPart read failed\n");
562 /* DER encode and compare tkt1 kdcrep */
563 res = shishi_a2d (handle, shishi_tkt_kdcrep (t1), buffer, &n);
564 if (res == SHISHI_OK)
565 success ("shishi_a2d() OK\n");
566 else
567 n = 0, fail ("shishi_a2d() failed\n");
569 shishi_to_base64 (buffer2, buffer, n, BUFSIZ);
570 if (strlen (buffer2) == strlen (tkt1kdcrepb64) &&
571 memcmp (buffer2, tkt1kdcrepb64, strlen (tkt1kdcrepb64)) == 0)
572 success ("KDC-REP read OK\n");
573 else
574 fail ("KDC-REP read failed\n");
576 /* DER encode and compare tkt2 ticket */
577 res = shishi_a2d (handle, shishi_tkt_ticket (t2), buffer, &n);
578 if (res == SHISHI_OK)
579 success ("shishi_a2d() OK\n");
580 else
581 n = 0, fail ("shishi_a2d() failed\n");
583 shishi_to_base64 (buffer2, buffer, n, BUFSIZ);
584 if (strlen (buffer2) == strlen (tkt2ticketb64) &&
585 memcmp (buffer2, tkt2ticketb64, strlen (tkt2ticketb64)) == 0)
586 success ("Ticket 2 read OK\n");
587 else
588 fail ("Ticket 2 read failed\n");
590 /* DER encode and compare tkt2 enckdcreppart */
591 res = shishi_a2d (handle, shishi_tkt_enckdcreppart (t2), buffer, &n);
592 if (res == SHISHI_OK)
593 success ("shishi_a2d() OK\n");
594 else
595 n = 0, fail ("shishi_a2d() failed\n");
597 shishi_to_base64 (buffer2, buffer, n, BUFSIZ);
598 if (strlen (buffer2) == strlen (tkt2enckdcreppartb64) &&
599 memcmp (buffer2, tkt2enckdcreppartb64,
600 strlen (tkt2enckdcreppartb64)) == 0)
601 success ("EncKDCRepPart 2 read OK\n");
602 else
603 fail ("EncKDCRepPart 2 read failed\n");
605 /* DER encode and compare tkt2 kdcrep */
606 res = shishi_a2d (handle, shishi_tkt_kdcrep (t2), buffer, &n);
607 if (res == SHISHI_OK)
608 success ("shishi_a2d() OK\n");
609 else
610 n = 0, fail ("shishi_a2d() failed\n");
612 shishi_to_base64 (buffer2, buffer, n, BUFSIZ);
613 if (strlen (buffer2) == strlen (tkt2kdcrepb64) &&
614 memcmp (buffer2, tkt2kdcrepb64, strlen (tkt2kdcrepb64)) == 0)
615 success ("KDC-REP 2 read OK\n");
616 else
617 fail ("KDC-REP 2 read failed\n");
619 res = unlink ("tktset.tmp");
620 if (res == 0)
621 success ("unlink() OK\n");
622 else
623 fail ("unlink() failed\n");
625 shishi_tkt_done (t1);
626 success ("shishi_tkt_done (t1) OK\n");
627 shishi_tkt_done (t2);
628 success ("shishi_tkt_done (t2) OK\n");
630 /* shishi_tkts_done () */
631 shishi_tkts_done (&tktset);
632 success ("shishi_tkts_done() OK\n");
634 shishi_done (handle);
636 if (verbose)
637 printf ("Ticket set self tests done with %d errors\n", error_count);
639 return error_count ? 1 : 0;