Fix.
[shishi.git] / tests / ticketset.c
blob8a51a0560c5d90fea901c8c0c1211d75c14e34c0
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 size_t n;
95 int res;
98 if (strcmp (argv[argc - 1], "-v") == 0 ||
99 strcmp (argv[argc - 1], "--verbose") == 0)
100 verbose = 1;
101 else if (strcmp (argv[argc - 1], "-d") == 0 ||
102 strcmp (argv[argc - 1], "--debug") == 0)
103 debug = 1;
104 else if (strcmp (argv[argc - 1], "-b") == 0 ||
105 strcmp (argv[argc - 1], "--break-on-error") == 0)
106 break_on_error = 1;
107 else if (strcmp (argv[argc - 1], "-h") == 0 ||
108 strcmp (argv[argc - 1], "-?") == 0 ||
109 strcmp (argv[argc - 1], "--help") == 0)
111 printf ("Usage: %s [-vdbh?] [--verbose] [--debug] "
112 "[--break-on-error] [--help]\n", argv[0]);
113 return 1;
115 while (argc-- > 1);
117 handle = shishi ();
118 if (handle == NULL)
120 fail ("Could not initialize shishi\n");
121 return 1;
124 if (debug)
125 shishi_cfg (handle, strdup ("verbose"));
127 escapeprint (NULL, 0);
128 hexprint (NULL, 0);
129 binprint (NULL, 0);
131 /* shishi_tkts_default_file() */
132 p = strdup (shishi_tkts_default_file (handle));
133 if (debug)
134 printf ("shishi_tkts_default_file () => `%s'.\n", p ? p : "<null>");
135 if (p)
136 success ("shishi_tkts_default_file() OK\n");
137 else
138 fail ("shishi_tkts_default_file() failed\n");
140 /* shishi_tkts_default_file_set() */
141 shishi_tkts_default_file_set (handle, "foo");
142 q = strdup (shishi_tkts_default_file (handle));
143 if (debug)
144 printf ("shishi_tkts_default_file () => `%s'.\n", q ? q : "<null>");
145 if (q && strcmp (q, "foo") == 0)
146 success ("shishi_tkts_default_file_set() OK\n");
147 else
148 fail ("shishi_tkts_default_file_set() failed\n");
149 free (q);
151 /* shishi_tkts_default_file_set() */
152 shishi_tkts_default_file_set (handle, NULL);
153 q = strdup (shishi_tkts_default_file (handle));
154 if (debug)
155 printf ("shishi_tkts_default_file () => `%s'.\n", q ? q : "<null>");
156 if (p && q && strcmp (p, q) == 0)
157 success ("shishi_tkts_default_file_set() OK\n");
158 else
159 fail ("shishi_tkts_default_file_set() failed\n");
160 free (q);
161 free (p);
163 /* shishi_tkts () */
164 res = shishi_tkts (handle, &tktset);
165 if (res == SHISHI_OK)
166 success ("shishi_tkts() OK\n");
167 else
168 fail ("shishi_tkts() failed\n");
170 /* shishi_tkts_size () */
171 n = shishi_tkts_size (tktset);
172 if (debug)
173 printf ("shishi_tkts_size () => `%d'.\n", n);
174 if (n == 0)
175 success ("shishi_tkts_size() OK\n");
176 else
177 fail ("shishi_tkts_size() failed\n");
179 /* shishi_tkts_nth () */
180 t1 = shishi_tkts_nth (tktset, 0);
181 if (t1 == NULL)
182 success ("shishi_tkts_nth() OK\n");
183 else
184 fail ("shishi_tkts_nth() failed\n");
186 /* shishi_tkts_nth () */
187 t1 = shishi_tkts_nth (tktset, 42);
188 if (t1 == NULL)
189 success ("shishi_tkts_nth() OK\n");
190 else
191 fail ("shishi_tkts_nth() failed\n");
193 /* shishi_tkts_add () */
194 res = shishi_tkts_add (tktset, NULL);
195 if (res == SHISHI_INVALID_TICKET)
196 success ("shishi_tkts_add() OK\n");
197 else
198 fail ("shishi_tkts_add() failed\n");
200 /* shishi_tkts_remove () */
201 res = shishi_tkts_remove (tktset, 0);
202 if (res == SHISHI_OK)
203 success ("shishi_tkts_remove() OK\n");
204 else
205 fail ("shishi_tkts_remove() failed\n");
207 /* shishi_tkts_remove () */
208 res = shishi_tkts_remove (tktset, 42);
209 if (res == SHISHI_OK)
210 success ("shishi_tkts_remove() OK\n");
211 else
212 fail ("shishi_tkts_remove() failed\n");
214 /* shishi_tkts_remove () */
215 res = shishi_tkts_remove (NULL, 0);
216 if (res == SHISHI_INVALID_TKTS)
217 success ("shishi_tkts_remove() OK\n");
218 else
219 fail ("shishi_tkts_remove() failed\n");
221 /* create ticket */
222 n = base64_from (buffer, tkt1ticketb64);
223 if (n == -1)
224 fail ("base64_from() failed\n");
225 n1 = shishi_der2asn1_ticket (handle, buffer, n);
226 if (!n1)
227 fail ("shishi_der2asn1_ticket() failed\n");
229 n = base64_from (buffer, tkt1enckdcreppartb64);
230 if (n == -1)
231 fail ("base64_from() failed\n");
232 n2 = shishi_der2asn1_encasreppart (handle, buffer, n);
233 if (!n2)
234 fail ("shishi_der2asn1_encasreppart() failed\n");
236 n = base64_from (buffer, tkt1kdcrepb64);
237 if (n == -1)
238 fail ("base64_from() failed\n");
239 n3 = shishi_der2asn1_asrep (handle, buffer, n);
240 if (!n3)
241 fail ("shishi_der2asn1_asrep() failed\n");
243 /* shishi_tkts_new() */
244 res = shishi_tkts_new (tktset, n1, n2, n3);
245 if (res == SHISHI_OK)
246 success ("shishi_tkts_new() OK\n");
247 else
248 fail ("shishi_tkts_new() failed\n");
250 /* shishi_tkts_size () */
251 n = shishi_tkts_size (tktset);
252 if (debug)
253 printf ("shishi_tkts_size () => `%d'.\n", n);
254 if (n == 1)
255 success ("shishi_tkts_size() OK\n");
256 else
257 fail ("shishi_tkts_size() failed\n");
259 /* shishi_tkts_nth () */
260 t1 = shishi_tkts_nth (tktset, 0);
261 if (debug)
263 shishi_tkt_pretty_print (t1, stdout);
264 printf ("t1=%p\n", t1);
266 if (t1)
267 success ("shishi_tkts_nth() OK\n");
268 else
269 fail ("shishi_tkts_nth() failed\n");
271 /* shishi_tkts_remove () */
272 res = shishi_tkts_remove (tktset, 0);
273 if (res == SHISHI_OK)
274 success ("shishi_tkts_remove() OK\n");
275 else
276 fail ("shishi_tkts_remove() failed\n");
278 /* shishi_tkts_size () */
279 n = shishi_tkts_size (tktset);
280 if (debug)
281 printf ("shishi_tkts_size () => `%d'.\n", n);
282 if (n == 0)
283 success ("shishi_tkts_size() OK\n");
284 else
285 fail ("shishi_tkts_size() failed\n");
287 /* shishi_tkts_nth () */
288 t2 = shishi_tkts_nth (tktset, 0);
289 if (t2 == NULL)
290 success ("shishi_tkts_nth() OK\n");
291 else
292 fail ("shishi_tkts_nth() failed\n");
294 /* shishi_tkts_add () */
295 res = shishi_tkts_add (tktset, t1);
296 if (res == SHISHI_OK)
297 success ("shishi_tkts_add() OK\n");
298 else
299 fail ("shishi_tkts_add() failed\n");
301 /* shishi_tkts_size () */
302 n = shishi_tkts_size (tktset);
303 if (debug)
304 printf ("shishi_tkts_size () => `%d'.\n", n);
305 if (n == 1)
306 success ("shishi_tkts_size() OK\n");
307 else
308 fail ("shishi_tkts_size() failed\n");
310 /* create ticket */
311 n = base64_from (buffer, tkt2ticketb64);
312 if (n == -1)
313 fail ("base64_from() failed\n");
314 n1 = shishi_der2asn1_ticket (handle, buffer, n);
315 if (!n1)
316 fail ("shishi_der2asn1_ticket() failed\n");
318 n = base64_from (buffer, tkt2enckdcreppartb64);
319 if (n == -1)
320 fail ("base64_from() failed\n");
321 n2 = shishi_der2asn1_enctgsreppart (handle, buffer, n);
322 if (!n2)
323 fail ("shishi_der2asn1_enctgsreppart() failed\n");
325 n = base64_from (buffer, tkt2kdcrepb64);
326 if (n == -1)
327 fail ("base64_from() failed\n");
328 n3 = shishi_der2asn1_tgsrep (handle, buffer, n);
329 if (!n3)
330 fail ("shishi_der2asn1_kdcrep() failed\n");
332 /* shishi_tkts_new() */
333 res = shishi_tkts_new (tktset, n1, n2, n3);
334 if (res == SHISHI_OK)
335 success ("shishi_tkts_new() OK\n");
336 else
337 fail ("shishi_tkts_new() failed\n");
339 /* shishi_tkts_size () */
340 n = shishi_tkts_size (tktset);
341 if (debug)
342 printf ("shishi_tkts_size () => `%d'.\n", n);
343 if (n == 2)
344 success ("shishi_tkts_size() OK\n");
345 else
346 fail ("shishi_tkts_size() failed\n");
348 /* shishi_tkts_nth () */
349 t2 = shishi_tkts_nth (tktset, 1);
350 if (debug)
352 shishi_tkt_pretty_print (t2, stdout);
353 printf ("t2=%p\n", t2);
355 if (t2)
356 success ("shishi_tkts_nth() OK\n");
357 else
358 fail ("shishi_tkts_nth() failed\n");
360 /* shishi_tkts_find () */
361 memset (&hint, 0, sizeof (hint));
362 hint.server = "host/latte.josefsson.org";
363 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
364 t3 = shishi_tkts_find (tktset, &hint);
365 if (debug)
366 printf ("t3=%p\n", t3);
367 if (t3 == t2)
368 success ("shishi_tkts_find() for server OK\n");
369 else
370 fail ("shishi_tkts_find() for server failed\n");
372 /* shishi_tkts_find () */
373 memset (&hint, 0, sizeof (hint));
374 hint.server = "krbtgt/JOSEFSSON.ORG";
375 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
376 t3 = shishi_tkts_find (tktset, &hint);
377 if (t3 == t1)
378 success ("shishi_tkts_find() for server OK\n");
379 else
380 fail ("shishi_tkts_find() for server failed\n");
382 /* shishi_tkts_find () */
383 memset (&hint, 0, sizeof (hint));
384 hint.client = "jas";
385 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
386 t3 = shishi_tkts_find (tktset, &hint);
387 if (debug)
388 printf ("t3=%p\n", t3);
389 if (t3 == t1)
390 success ("shishi_tkts_find() for client OK\n");
391 else
392 fail ("shishi_tkts_find() for client failed\n");
394 /* shishi_tkts_find () */
395 memset (&hint, 0, sizeof (hint));
396 hint.client = "jas";
397 t3 = shishi_tkts_find (tktset, &hint);
398 if (debug)
399 printf ("t3=%p\n", t3);
400 if (t3 == NULL)
401 success ("shishi_tkts_find() for client OK\n");
402 else
403 fail ("shishi_tkts_find() for client failed\n");
405 res = shishi_tkts_to_file (tktset, "tktset.tmp");
406 if (res == SHISHI_OK)
407 success ("shishi_tkts_to_file() OK\n");
408 else
409 fail ("shishi_tkts_to_file() failed\n");
411 /* shishi_tkts_add () */
412 res = shishi_tkts_add (tktset, t2);
413 if (res == SHISHI_OK)
414 success ("shishi_tkts_add() OK\n");
415 else
416 fail ("shishi_tkts_add() failed\n");
418 /* shishi_tkts_add () */
419 res = shishi_tkts_add (tktset, t1);
420 if (res == SHISHI_OK)
421 success ("shishi_tkts_add() OK\n");
422 else
423 fail ("shishi_tkts_add() failed\n");
425 /* shishi_tkts_remove () */
426 res = shishi_tkts_remove (tktset, 1);
427 if (res == SHISHI_OK)
428 success ("shishi_tkts_remove() OK\n");
429 else
430 fail ("shishi_tkts_remove() failed\n");
432 /* shishi_tkts_remove () */
433 res = shishi_tkts_remove (tktset, 1);
434 if (res == SHISHI_OK)
435 success ("shishi_tkts_remove() OK\n");
436 else
437 fail ("shishi_tkts_remove() failed\n");
439 memset (&hint, 0, sizeof (hint));
440 hint.server = "host/latte.josefsson.org";
441 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
442 t3 = shishi_tkts_find (tktset, &hint);
443 if (t3 == NULL)
444 success ("shishi_tkts_find() for server OK\n");
445 else
446 fail ("shishi_tkts_find() for server failed\n");
448 memset (&hint, 0, sizeof (hint));
449 hint.server = "krbtgt/JOSEFSSON.ORG";
450 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
451 t3 = shishi_tkts_find (tktset, &hint);
452 if (t3 == t1)
453 success ("shishi_tkts_find() for server OK\n");
454 else
455 fail ("shishi_tkts_find() for server failed\n");
457 /* shishi_tkts_remove () */
458 res = shishi_tkts_remove (tktset, 0);
459 if (res == SHISHI_OK)
460 success ("shishi_tkts_remove() OK\n");
461 else
462 fail ("shishi_tkts_remove() failed\n");
464 /* shishi_tkts_remove () */
465 res = shishi_tkts_remove (tktset, 0);
466 if (res == SHISHI_OK)
467 success ("shishi_tkts_remove() OK\n");
468 else
469 fail ("shishi_tkts_remove() failed\n");
471 /* shishi_tkts_size () */
472 n = shishi_tkts_size (tktset);
473 if (debug)
474 printf ("shishi_tkts_size () => `%d'.\n", n);
475 if (n == 0)
476 success ("shishi_tkts_size() OK\n");
477 else
478 fail ("shishi_tkts_size() failed\n");
480 /* shishi_tkts_done () */
481 shishi_tkts_done (&tktset);
482 success ("shishi_tkts_done() OK\n");
484 shishi_tkt_done (t1);
485 success ("shishi_tkt_done (t1) OK\n");
486 shishi_tkt_done (t2);
487 success ("shishi_tkt_done (t2) OK\n");
489 /* shishi_tkts_done () */
490 shishi_tkts_done (NULL);
491 success ("shishi_tkts_done() OK\n");
493 /* shishi_tkts () */
494 res = shishi_tkts (handle, &tktset);
495 if (res == SHISHI_OK)
496 success ("shishi_tkts() OK\n");
497 else
498 fail ("shishi_tkts() failed\n");
500 /* shishi_tkts_from_file () */
501 res = shishi_tkts_from_file (tktset, "tktset.tmp");
502 if (res == SHISHI_OK)
503 success ("shishi_tkts_to_file() OK\n");
504 else
505 fail ("shishi_tkts_to_file() failed\n");
507 /* shishi_tkts_size () */
508 n = shishi_tkts_size (tktset);
509 if (debug)
510 printf ("shishi_tkts_size () => `%d'.\n", n);
511 if (n == 2)
512 success ("shishi_tkts_size() OK\n");
513 else
514 fail ("shishi_tkts_size() failed\n");
516 /* shishi_tkts_nth () */
517 t1 = shishi_tkts_nth (tktset, 0);
518 if (debug)
519 shishi_tkt_pretty_print (t1, stdout);
520 if (t1)
521 success ("shishi_tkts_nth() OK\n");
522 else
523 fail ("shishi_tkts_nth() failed\n");
525 /* shishi_tkts_nth () */
526 t2 = shishi_tkts_nth (tktset, 1);
527 if (debug)
528 shishi_tkt_pretty_print (t2, stdout);
529 if (t2)
530 success ("shishi_tkts_nth() OK\n");
531 else
532 fail ("shishi_tkts_nth() failed\n");
534 /* DER encode and compare tkt1 ticket */
535 n = sizeof (buffer);
536 res = shishi_a2d (handle, shishi_tkt_ticket (t1), buffer, &n);
537 if (res == SHISHI_OK)
538 success ("shishi_a2d() OK\n");
539 else
540 n = 0, fail ("shishi_a2d() failed\n");
542 base64_to (buffer2, buffer, n, BUFSIZ);
543 if (strlen (buffer2) == strlen (tkt1ticketb64) &&
544 memcmp (buffer2, tkt1ticketb64, strlen (tkt1ticketb64)) == 0)
545 success ("Ticket read OK\n");
546 else
547 fail ("Ticket read failed\n");
549 /* DER encode and compare tkt1 enckdcreppart */
550 n = sizeof (buffer);
551 res = shishi_a2d (handle, shishi_tkt_enckdcreppart (t1), buffer, &n);
552 if (res == SHISHI_OK)
553 success ("shishi_a2d() OK\n");
554 else
555 n = 0, fail ("shishi_a2d() failed\n");
557 base64_to (buffer2, buffer, n, BUFSIZ);
558 if (strlen (buffer2) == strlen (tkt1enckdcreppartb64) &&
559 memcmp (buffer2, tkt1enckdcreppartb64,
560 strlen (tkt1enckdcreppartb64)) == 0)
561 success ("EncKDCRepPart read OK\n");
562 else
563 fail ("EncKDCRepPart read failed\n");
565 /* DER encode and compare tkt1 kdcrep */
566 n = sizeof (buffer);
567 res = shishi_a2d (handle, shishi_tkt_kdcrep (t1), buffer, &n);
568 if (res == SHISHI_OK)
569 success ("shishi_a2d() OK\n");
570 else
571 n = 0, fail ("shishi_a2d() failed\n");
573 base64_to (buffer2, buffer, n, BUFSIZ);
574 if (strlen (buffer2) == strlen (tkt1kdcrepb64) &&
575 memcmp (buffer2, tkt1kdcrepb64, strlen (tkt1kdcrepb64)) == 0)
576 success ("KDC-REP read OK\n");
577 else
578 fail ("KDC-REP read failed\n");
580 /* DER encode and compare tkt2 ticket */
581 n = sizeof (buffer);
582 res = shishi_a2d (handle, shishi_tkt_ticket (t2), buffer, &n);
583 if (res == SHISHI_OK)
584 success ("shishi_a2d() OK\n");
585 else
586 n = 0, fail ("shishi_a2d() failed\n");
588 base64_to (buffer2, buffer, n, BUFSIZ);
589 if (strlen (buffer2) == strlen (tkt2ticketb64) &&
590 memcmp (buffer2, tkt2ticketb64, strlen (tkt2ticketb64)) == 0)
591 success ("Ticket 2 read OK\n");
592 else
593 fail ("Ticket 2 read failed\n");
595 /* DER encode and compare tkt2 enckdcreppart */
596 n = sizeof (buffer);
597 res = shishi_a2d (handle, shishi_tkt_enckdcreppart (t2), buffer, &n);
598 if (res == SHISHI_OK)
599 success ("shishi_a2d() OK\n");
600 else
601 n = 0, fail ("shishi_a2d() failed\n");
603 base64_to (buffer2, buffer, n, BUFSIZ);
604 if (strlen (buffer2) == strlen (tkt2enckdcreppartb64) &&
605 memcmp (buffer2, tkt2enckdcreppartb64,
606 strlen (tkt2enckdcreppartb64)) == 0)
607 success ("EncKDCRepPart 2 read OK\n");
608 else
609 fail ("EncKDCRepPart 2 read failed\n");
611 /* DER encode and compare tkt2 kdcrep */
612 n = sizeof (buffer);
613 res = shishi_a2d (handle, shishi_tkt_kdcrep (t2), buffer, &n);
614 if (res == SHISHI_OK)
615 success ("shishi_a2d() OK\n");
616 else
617 n = 0, fail ("shishi_a2d() failed\n");
619 base64_to (buffer2, buffer, n, BUFSIZ);
620 if (strlen (buffer2) == strlen (tkt2kdcrepb64) &&
621 memcmp (buffer2, tkt2kdcrepb64, strlen (tkt2kdcrepb64)) == 0)
622 success ("KDC-REP 2 read OK\n");
623 else
624 fail ("KDC-REP 2 read failed\n");
626 res = unlink ("tktset.tmp");
627 if (res == 0)
628 success ("unlink() OK\n");
629 else
630 fail ("unlink() failed\n");
632 shishi_tkt_done (t1);
633 success ("shishi_tkt_done (t1) OK\n");
634 shishi_tkt_done (t2);
635 success ("shishi_tkt_done (t2) OK\n");
637 /* shishi_tkts_done () */
638 shishi_tkts_done (&tktset);
639 success ("shishi_tkts_done() OK\n");
641 shishi_done (handle);
643 if (verbose)
644 printf ("Ticket set self tests done with %d errors\n", error_count);
646 return error_count ? 1 : 0;