Add.
[shishi.git] / tests / ticketset.c
blob485acdb33f3ffc9308798b48a7c66989b2a9c290
1 /* ticketset.c Shishi ticketset self tests.
2 * Copyright (C) 2002, 2003, 2004, 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "utils.c"
24 static const char tkt1kdcrepb64[] =
25 "a4ICITCCAh2gAwIBBaEDAgELow8bDUpPU0VGU1NPTi5PUkekEDAOoAMCAQGhBzAF"
26 "GwNqYXOlggECYYH/MIH8oAMCAQWhDxsNSk9TRUZTU09OLk9SR6IiMCCgAwIBAaEZ"
27 "MBcbBmtyYnRndBsNSk9TRUZTU09OLk9SR6OBvzCBvKADAgEQoQMCAQGiga8Egayq"
28 "ttjMpRNM2iVVR5RjtMNH3i75hjnUiXQ7UeT7DMShJ5IxiBr09dggaZzTAHrBAvV8"
29 "5xON3p39rMpmCg9utizrxzT1JXruoGF/+ofuT7lEDfRr437QJD5WuOtlfmkM2i5s"
30 "2bGYZlHNdBonapJCcMeUSS45HEoM5iy0dK2JeaOliOVKTDpX9gOayKSIFYnuzIb+"
31 "cg1ATHm29ahK5AY+LU9E4v8Yj1/02srRuERApoHnMIHkoAMCARChAwIBBaKB1wSB"
32 "1AiMSoSQrE5FSE2CYpTOdLgVWRw/k1cqBtswVKRTdgj2As6WG6mhFczy7RF62GVM"
33 "6gJGNQRx1mAg0d5C7pNKRCgAZ2oQdJIGW6CLTy2L0LxM104HA0XrZ+zfFLKlZTOV"
34 "T85LIoSneI/yKNh3iYeVQwp6AdMRw6562fHMie22I4sy22wNVz1toTrKixILvoMy"
35 "eoD7ET43Y1eo0SeXj8LPmZyqLARBknl2ZvNcDpjWpI57QycHV28BhcvVPu72kObJ"
36 "/68tCNEJ8J+vHArpFA5V9BDsFcGs";
38 static const char tkt1enckdcreppartb64[] =
39 "eYGyMIGvoCMwIaADAgEQoRoEGPF/LFgc3IYq3+AZofutur+wsK5i6vSbN6EcMBow"
40 "GKADAgEAoREYDzE5NzAwMTAxMDAwMDAwWqIGAgTl7iQgpAcDBQAAQAAApREYDzIw"
41 "MDIxMjExMTM0MDU0WqcRGA8yMDAyMTIxMTEzNTczNFqpDxsNSk9TRUZTU09OLk9S"
42 "R6oiMCCgAwIBAaEZMBcbBmtyYnRndBsNSk9TRUZTU09OLk9SRw==";
44 static const char tkt1ticketb64[] =
45 "YYH/MIH8oAMCAQWhDxsNSk9TRUZTU09OLk9SR6IiMCCgAwIBAaEZMBcbBmtyYnRn"
46 "dBsNSk9TRUZTU09OLk9SR6OBvzCBvKADAgEQoQMCAQGiga8EgayqttjMpRNM2iVV"
47 "R5RjtMNH3i75hjnUiXQ7UeT7DMShJ5IxiBr09dggaZzTAHrBAvV85xON3p39rMpm"
48 "Cg9utizrxzT1JXruoGF/+ofuT7lEDfRr437QJD5WuOtlfmkM2i5s2bGYZlHNdBon"
49 "apJCcMeUSS45HEoM5iy0dK2JeaOliOVKTDpX9gOayKSIFYnuzIb+cg1ATHm29ahK"
50 "5AY+LU9E4v8Yj1/02srRuERA";
52 static const char tkt2kdcrepb64[] =
53 "bYICSjCCAkagAwIBBaEDAgENow8bDUpPU0VGU1NPTi5PUkekEDAOoAMCAQGhBzAF"
54 "GwNqYXOlggEYYYIBFDCCARCgAwIBBaEPGw1KT1NFRlNTT04uT1JHoiYwJKADAgEB"
55 "oR0wGxsEaG9zdBsTbGF0dGUuam9zZWZzc29uLm9yZ6OBzzCBzKADAgEQoQMCAQKi"
56 "gb8EgbzEU6KFfSSQg4xxSxJBp2QBtaNGyzawROAGFsztZcY+gl5K2ki6xDT10kCY"
57 "yfORXXXraoYIcwJl6EW8RGl4KKsZlZmNWuw0/mO4Gglga6sM06vQDs2TcSc8hWDJ"
58 "4I1vU6/WlKtwzNj0Cw+6fqyDJIt6PmRpUe/yGZe6hSQkrqgQuBhpAHZF4/aoWqOm"
59 "NufTdGa+5gHzqcEmQerWD8YhImeD+Xe5citg92XTPx2nHiNMBMmwgWJHf1Tjddiw"
60 "saaB+jCB96ADAgEQooHvBIHsmctkNNI2jJwUEdTe9o5WeHyTCWMSO9AA0luxjX2D"
61 "CR5kNOZuPx5YfHWHwKlqrOtwo1E0Cb7bpKHPUOWhhIGUXcV0z1ETSEOX8Ho3iIOc"
62 "8LSNVq8UqVf/wBnndLiljZveTbbu+YcFNbF7g+q2VDYffKgXsUi6HV2Ue7OGawvY"
63 "DxU7KDVpPWgitPGrNItdaJ1QVfVH+cXLdiqEV7RR+JOsFc8jkBxNOq/rx60Ga73F"
64 "urdXCqM1tz5T2QHgoI6y0HjGuEbjymFQfCt1hclIvu7EzWn29p2oZJUj1Vv7vpNz"
65 "tDy+gjC3uMYj7JGdoTg=";
67 static const char tkt2enckdcreppartb64[] =
68 "eoHJMIHGoCMwIaADAgEQoRoEGFS29KeMuXZDeqcEud/gWHln/db7bje26aEcMBow"
69 "GKADAgEAoREYDzE5NzAwMTAxMDAwMDAwWqIGAgScLHDdpAcDBQAAAAAApREYDzIw"
70 "MDIxMjExMTM0MDU0WqYRGA8yMDAyMTIxMTEzNDEwNFqnERgPMjAwMjEyMTExMzU3"
71 "MzRaqQ8bDUpPU0VGU1NPTi5PUkeqJjAkoAMCAQGhHTAbGwRob3N0GxNsYXR0ZS5q"
72 "b3NlZnNzb24ub3Jn";
74 static const char tkt2ticketb64[] =
75 "YYIBFDCCARCgAwIBBaEPGw1KT1NFRlNTT04uT1JHoiYwJKADAgEBoR0wGxsEaG9z"
76 "dBsTbGF0dGUuam9zZWZzc29uLm9yZ6OBzzCBzKADAgEQoQMCAQKigb8EgbzEU6KF"
77 "fSSQg4xxSxJBp2QBtaNGyzawROAGFsztZcY+gl5K2ki6xDT10kCYyfORXXXraoYI"
78 "cwJl6EW8RGl4KKsZlZmNWuw0/mO4Gglga6sM06vQDs2TcSc8hWDJ4I1vU6/WlKtw"
79 "zNj0Cw+6fqyDJIt6PmRpUe/yGZe6hSQkrqgQuBhpAHZF4/aoWqOmNufTdGa+5gHz"
80 "qcEmQerWD8YhImeD+Xe5citg92XTPx2nHiNMBMmwgWJHf1TjddiwsQ==";
82 void
83 test (Shishi * handle)
85 Shishi_tkts *tktset;
86 Shishi_tkts_hint hint;
87 Shishi_tkt *t1, *t2, *t3;
88 Shishi_asn1 tkt1asn1, tkt1asn2, tkt1asn3;
89 Shishi_asn1 tkt2asn1, tkt2asn2, tkt2asn3;
90 char buffer[BUFSIZ];
91 char buffer2[BUFSIZ];
92 char *buf;
93 char *p, *q;
94 size_t n;
95 int res;
97 /* shishi_tkts_default_file() */
98 p = strdup (shishi_tkts_default_file (handle));
99 if (debug)
100 printf ("shishi_tkts_default_file () => `%s'.\n", p ? p : "<null>");
101 if (p)
102 success ("shishi_tkts_default_file() OK\n");
103 else
104 fail ("shishi_tkts_default_file() failed\n");
106 /* shishi_tkts_default_file_set() */
107 shishi_tkts_default_file_set (handle, "foo");
108 q = strdup (shishi_tkts_default_file (handle));
109 if (debug)
110 printf ("shishi_tkts_default_file () => `%s'.\n", q ? q : "<null>");
111 if (q && strcmp (q, "foo") == 0)
112 success ("shishi_tkts_default_file_set() OK\n");
113 else
114 fail ("shishi_tkts_default_file_set() failed\n");
115 free (q);
117 /* shishi_tkts_default_file_set() */
118 shishi_tkts_default_file_set (handle, NULL);
119 q = strdup (shishi_tkts_default_file (handle));
120 if (debug)
121 printf ("shishi_tkts_default_file () => `%s'.\n", q ? q : "<null>");
122 if (p && q && strcmp (p, q) == 0)
123 success ("shishi_tkts_default_file_set() OK\n");
124 else
125 fail ("shishi_tkts_default_file_set() failed\n");
126 free (q);
127 free (p);
129 /* shishi_tkts () */
130 res = shishi_tkts (handle, &tktset);
131 if (res == SHISHI_OK)
132 success ("shishi_tkts() OK\n");
133 else
134 fail ("shishi_tkts() failed\n");
136 /* shishi_tkts_size () */
137 n = shishi_tkts_size (tktset);
138 if (debug)
139 printf ("shishi_tkts_size () => `%d'.\n", n);
140 if (n == 0)
141 success ("shishi_tkts_size() OK\n");
142 else
143 fail ("shishi_tkts_size() failed\n");
145 /* shishi_tkts_nth () */
146 t1 = shishi_tkts_nth (tktset, 0);
147 if (t1 == NULL)
148 success ("shishi_tkts_nth() OK\n");
149 else
150 fail ("shishi_tkts_nth() failed\n");
152 /* shishi_tkts_nth () */
153 t1 = shishi_tkts_nth (tktset, 42);
154 if (t1 == NULL)
155 success ("shishi_tkts_nth() OK\n");
156 else
157 fail ("shishi_tkts_nth() failed\n");
159 /* shishi_tkts_add () */
160 res = shishi_tkts_add (tktset, NULL);
161 if (res == SHISHI_INVALID_TICKET)
162 success ("shishi_tkts_add() OK\n");
163 else
164 fail ("shishi_tkts_add() failed\n");
166 /* shishi_tkts_remove () */
167 res = shishi_tkts_remove (tktset, 0);
168 if (res == SHISHI_OK)
169 success ("shishi_tkts_remove() OK\n");
170 else
171 fail ("shishi_tkts_remove() failed\n");
173 /* shishi_tkts_remove () */
174 res = shishi_tkts_remove (tktset, 42);
175 if (res == SHISHI_OK)
176 success ("shishi_tkts_remove() OK\n");
177 else
178 fail ("shishi_tkts_remove() failed\n");
180 /* shishi_tkts_remove () */
181 res = shishi_tkts_remove (NULL, 0);
182 if (res == SHISHI_INVALID_TKTS)
183 success ("shishi_tkts_remove() OK\n");
184 else
185 fail ("shishi_tkts_remove() failed\n");
187 /* create ticket */
188 n = BUFSIZ;
189 if (!base64_decode (tkt1ticketb64, strlen (tkt1ticketb64), buffer, &n))
190 fail ("base64_decode() failed\n");
191 tkt1asn1 = shishi_der2asn1_ticket (handle, buffer, n);
192 if (!tkt1asn1)
193 fail ("shishi_der2asn1_ticket() failed\n");
195 n = BUFSIZ;
196 if (!base64_decode (tkt1enckdcreppartb64, strlen (tkt1enckdcreppartb64),
197 buffer, &n))
198 fail ("base64_decode() failed\n");
199 tkt1asn2 = shishi_der2asn1_encasreppart (handle, buffer, n);
200 if (!tkt1asn2)
201 fail ("shishi_der2asn1_encasreppart() failed\n");
203 n = BUFSIZ;
204 if (!base64_decode (tkt1kdcrepb64, strlen (tkt1kdcrepb64),
205 buffer, &n))
206 fail ("base64_decode() failed\n");
207 tkt1asn3 = shishi_der2asn1_asrep (handle, buffer, n);
208 if (!tkt1asn3)
209 fail ("shishi_der2asn1_asrep() failed\n");
211 /* shishi_tkts_new() */
212 res = shishi_tkts_new (tktset, tkt1asn1, tkt1asn2, tkt1asn3);
213 if (res == SHISHI_OK)
214 success ("shishi_tkts_new() OK\n");
215 else
216 fail ("shishi_tkts_new() failed\n");
218 /* shishi_tkts_size () */
219 n = shishi_tkts_size (tktset);
220 if (debug)
221 printf ("shishi_tkts_size () => `%d'.\n", n);
222 if (n == 1)
223 success ("shishi_tkts_size() OK\n");
224 else
225 fail ("shishi_tkts_size() failed\n");
227 /* shishi_tkts_nth () */
228 t1 = shishi_tkts_nth (tktset, 0);
229 if (debug)
231 shishi_tkt_pretty_print (t1, stdout);
232 printf ("t1=%p\n", t1);
234 if (t1)
235 success ("shishi_tkts_nth() OK\n");
236 else
237 fail ("shishi_tkts_nth() failed\n");
239 /* shishi_tkts_remove () */
240 res = shishi_tkts_remove (tktset, 0);
241 if (res == SHISHI_OK)
242 success ("shishi_tkts_remove() OK\n");
243 else
244 fail ("shishi_tkts_remove() failed\n");
246 /* shishi_tkts_size () */
247 n = shishi_tkts_size (tktset);
248 if (debug)
249 printf ("shishi_tkts_size () => `%d'.\n", n);
250 if (n == 0)
251 success ("shishi_tkts_size() OK\n");
252 else
253 fail ("shishi_tkts_size() failed\n");
255 /* shishi_tkts_nth () */
256 t2 = shishi_tkts_nth (tktset, 0);
257 if (t2 == NULL)
258 success ("shishi_tkts_nth() OK\n");
259 else
260 fail ("shishi_tkts_nth() failed\n");
262 /* shishi_tkts_add () */
263 res = shishi_tkts_add (tktset, t1);
264 if (res == SHISHI_OK)
265 success ("shishi_tkts_add() OK\n");
266 else
267 fail ("shishi_tkts_add() failed\n");
269 /* shishi_tkts_size () */
270 n = shishi_tkts_size (tktset);
271 if (debug)
272 printf ("shishi_tkts_size () => `%d'.\n", n);
273 if (n == 1)
274 success ("shishi_tkts_size() OK\n");
275 else
276 fail ("shishi_tkts_size() failed\n");
278 /* create ticket */
279 n = BUFSIZ;
280 if (!base64_decode (tkt2ticketb64, strlen (tkt2ticketb64),
281 buffer, &n))
282 fail ("base64_decode() failed\n");
283 tkt2asn1 = shishi_der2asn1_ticket (handle, buffer, n);
284 if (!tkt2asn1)
285 fail ("shishi_der2asn1_ticket() failed\n");
287 n = BUFSIZ;
288 if (!base64_decode (tkt2enckdcreppartb64, strlen (tkt2enckdcreppartb64),
289 buffer, &n))
290 fail ("base64_decode() failed\n");
291 tkt2asn2 = shishi_der2asn1_enctgsreppart (handle, buffer, n);
292 if (!tkt2asn2)
293 fail ("shishi_der2asn1_enctgsreppart() failed\n");
295 n = BUFSIZ;
296 if (!base64_decode (tkt2kdcrepb64, strlen (tkt2kdcrepb64),
297 buffer, &n))
298 fail ("base64_decode() failed\n");
299 tkt2asn3 = shishi_der2asn1_tgsrep (handle, buffer, n);
300 if (!tkt2asn3)
301 fail ("shishi_der2asn1_kdcrep() failed\n");
303 /* shishi_tkts_new() */
304 res = shishi_tkts_new (tktset, tkt2asn1, tkt2asn2, tkt2asn3);
305 if (res == SHISHI_OK)
306 success ("shishi_tkts_new() OK\n");
307 else
308 fail ("shishi_tkts_new() failed\n");
310 /* shishi_tkts_size () */
311 n = shishi_tkts_size (tktset);
312 if (debug)
313 printf ("shishi_tkts_size () => `%d'.\n", n);
314 if (n == 2)
315 success ("shishi_tkts_size() OK\n");
316 else
317 fail ("shishi_tkts_size() failed\n");
319 /* shishi_tkts_nth () */
320 t2 = shishi_tkts_nth (tktset, 1);
321 if (debug)
323 shishi_tkt_pretty_print (t2, stdout);
324 printf ("t2=%p\n", t2);
326 if (t2)
327 success ("shishi_tkts_nth() OK\n");
328 else
329 fail ("shishi_tkts_nth() failed\n");
331 /* shishi_tkts_find () */
332 memset (&hint, 0, sizeof (hint));
333 hint.server = "host/latte.josefsson.org";
334 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
335 t3 = shishi_tkts_find (tktset, &hint);
336 if (debug)
337 printf ("t3=%p\n", t3);
338 if (t3 == t2)
339 success ("shishi_tkts_find() for server OK\n");
340 else
341 fail ("shishi_tkts_find() for server failed\n");
343 /* shishi_tkts_find () */
344 memset (&hint, 0, sizeof (hint));
345 hint.server = "krbtgt/JOSEFSSON.ORG";
346 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
347 t3 = shishi_tkts_find (tktset, &hint);
348 if (t3 == t1)
349 success ("shishi_tkts_find() for server OK\n");
350 else
351 fail ("shishi_tkts_find() for server failed\n");
353 /* shishi_tkts_find () */
354 memset (&hint, 0, sizeof (hint));
355 hint.client = "jas";
356 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
357 t3 = shishi_tkts_find (tktset, &hint);
358 if (debug)
359 printf ("t3=%p\n", t3);
360 if (t3 == t1)
361 success ("shishi_tkts_find() for client OK\n");
362 else
363 fail ("shishi_tkts_find() for client failed\n");
365 /* shishi_tkts_find () */
366 memset (&hint, 0, sizeof (hint));
367 hint.client = "jas";
368 t3 = shishi_tkts_find (tktset, &hint);
369 if (debug)
370 printf ("t3=%p\n", t3);
371 if (t3 == NULL)
372 success ("shishi_tkts_find() for client OK\n");
373 else
374 fail ("shishi_tkts_find() for client failed\n");
376 res = shishi_tkts_to_file (tktset, "tktset.tmp");
377 if (res == SHISHI_OK)
378 success ("shishi_tkts_to_file() OK\n");
379 else
380 fail ("shishi_tkts_to_file() failed\n");
382 /* shishi_tkts_add () */
383 res = shishi_tkts_add (tktset, t2);
384 if (res == SHISHI_OK)
385 success ("shishi_tkts_add() OK\n");
386 else
387 fail ("shishi_tkts_add() failed\n");
389 /* shishi_tkts_add () */
390 res = shishi_tkts_add (tktset, t1);
391 if (res == SHISHI_OK)
392 success ("shishi_tkts_add() OK\n");
393 else
394 fail ("shishi_tkts_add() failed\n");
396 /* shishi_tkts_remove () */
397 res = shishi_tkts_remove (tktset, 1);
398 if (res == SHISHI_OK)
399 success ("shishi_tkts_remove() OK\n");
400 else
401 fail ("shishi_tkts_remove() failed\n");
403 /* shishi_tkts_remove () */
404 res = shishi_tkts_remove (tktset, 1);
405 if (res == SHISHI_OK)
406 success ("shishi_tkts_remove() OK\n");
407 else
408 fail ("shishi_tkts_remove() failed\n");
410 memset (&hint, 0, sizeof (hint));
411 hint.server = "host/latte.josefsson.org";
412 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
413 t3 = shishi_tkts_find (tktset, &hint);
414 if (t3 == NULL)
415 success ("shishi_tkts_find() for server OK\n");
416 else
417 fail ("shishi_tkts_find() for server failed\n");
419 memset (&hint, 0, sizeof (hint));
420 hint.server = "krbtgt/JOSEFSSON.ORG";
421 hint.flags = SHISHI_TKTSHINTFLAGS_ACCEPT_EXPIRED;
422 t3 = shishi_tkts_find (tktset, &hint);
423 if (t3 == t1)
424 success ("shishi_tkts_find() for server OK\n");
425 else
426 fail ("shishi_tkts_find() for server failed\n");
428 /* shishi_tkts_remove () */
429 res = shishi_tkts_remove (tktset, 0);
430 if (res == SHISHI_OK)
431 success ("shishi_tkts_remove() OK\n");
432 else
433 fail ("shishi_tkts_remove() failed\n");
435 /* shishi_tkts_remove () */
436 res = shishi_tkts_remove (tktset, 0);
437 if (res == SHISHI_OK)
438 success ("shishi_tkts_remove() OK\n");
439 else
440 fail ("shishi_tkts_remove() failed\n");
442 /* shishi_tkts_size () */
443 n = shishi_tkts_size (tktset);
444 if (debug)
445 printf ("shishi_tkts_size () => `%d'.\n", n);
446 if (n == 0)
447 success ("shishi_tkts_size() OK\n");
448 else
449 fail ("shishi_tkts_size() failed\n");
451 /* shishi_tkts_done () */
452 shishi_tkts_done (&tktset);
453 success ("shishi_tkts_done() OK\n");
455 shishi_tkt_done (t1);
456 success ("shishi_tkt_done (t1) OK\n");
457 shishi_tkt_done (t2);
458 success ("shishi_tkt_done (t2) OK\n");
460 /* shishi_tkts_done () */
461 shishi_tkts_done (NULL);
462 success ("shishi_tkts_done() OK\n");
464 /* shishi_tkts () */
465 res = shishi_tkts (handle, &tktset);
466 if (res == SHISHI_OK)
467 success ("shishi_tkts() OK\n");
468 else
469 fail ("shishi_tkts() failed\n");
471 /* shishi_tkts_from_file () */
472 res = shishi_tkts_from_file (tktset, "tktset.tmp");
473 if (res == SHISHI_OK)
474 success ("shishi_tkts_to_file() OK\n");
475 else
476 fail ("shishi_tkts_to_file() failed\n");
478 /* shishi_tkts_size () */
479 n = shishi_tkts_size (tktset);
480 if (debug)
481 printf ("shishi_tkts_size () => `%d'.\n", n);
482 if (n == 2)
483 success ("shishi_tkts_size() OK\n");
484 else
485 fail ("shishi_tkts_size() failed\n");
487 /* shishi_tkts_nth () */
488 t1 = shishi_tkts_nth (tktset, 0);
489 if (debug)
490 shishi_tkt_pretty_print (t1, stdout);
491 if (t1)
492 success ("shishi_tkts_nth() OK\n");
493 else
494 fail ("shishi_tkts_nth() failed\n");
496 /* shishi_tkts_nth () */
497 t2 = shishi_tkts_nth (tktset, 1);
498 if (debug)
499 shishi_tkt_pretty_print (t2, stdout);
500 if (t2)
501 success ("shishi_tkts_nth() OK\n");
502 else
503 fail ("shishi_tkts_nth() failed\n");
505 /* DER encode and compare tkt1 ticket */
506 res = shishi_asn1_to_der (handle, shishi_tkt_ticket (t1), &buf, &n);
507 if (res == SHISHI_OK)
508 success ("shishi_asn1_to_der() OK\n");
509 else
510 n = 0, fail ("shishi_asn1_to_der() failed\n");
512 base64_encode (buf, n, buffer2, BUFSIZ);
513 free (buf);
514 if (strlen (buffer2) == strlen (tkt1ticketb64) &&
515 memcmp (buffer2, tkt1ticketb64, strlen (tkt1ticketb64)) == 0)
516 success ("Ticket read OK\n");
517 else
518 fail ("Ticket read failed\n");
520 /* DER encode and compare tkt1 enckdcreppart */
521 res = shishi_asn1_to_der (handle, shishi_tkt_enckdcreppart (t1), &buf, &n);
522 if (res == SHISHI_OK)
523 success ("shishi_asn1_to_der() OK\n");
524 else
525 n = 0, fail ("shishi_asn1_to_der() failed\n");
527 base64_encode (buf, n, buffer2, BUFSIZ);
528 free (buf);
529 if (strlen (buffer2) == strlen (tkt1enckdcreppartb64) &&
530 memcmp (buffer2, tkt1enckdcreppartb64,
531 strlen (tkt1enckdcreppartb64)) == 0)
532 success ("EncKDCRepPart read OK\n");
533 else
534 fail ("EncKDCRepPart read failed\n");
536 /* DER encode and compare tkt1 kdcrep */
537 res = shishi_asn1_to_der (handle, shishi_tkt_kdcrep (t1), &buf, &n);
538 if (res == SHISHI_OK)
539 success ("shishi_asn1_to_der() OK\n");
540 else
541 n = 0, fail ("shishi_asn1_to_der() failed\n");
543 base64_encode (buf, n, buffer2, BUFSIZ);
544 free (buf);
545 if (strlen (buffer2) == strlen (tkt1kdcrepb64) &&
546 memcmp (buffer2, tkt1kdcrepb64, strlen (tkt1kdcrepb64)) == 0)
547 success ("KDC-REP read OK\n");
548 else
549 fail ("KDC-REP read failed\n");
551 /* DER encode and compare tkt2 ticket */
552 res = shishi_asn1_to_der (handle, shishi_tkt_ticket (t2), &buf, &n);
553 if (res == SHISHI_OK)
554 success ("shishi_asn1_to_der() OK\n");
555 else
556 n = 0, fail ("shishi_asn1_to_der() failed\n");
558 base64_encode (buf, n, buffer2, BUFSIZ);
559 free (buf);
560 if (strlen (buffer2) == strlen (tkt2ticketb64) &&
561 memcmp (buffer2, tkt2ticketb64, strlen (tkt2ticketb64)) == 0)
562 success ("Ticket 2 read OK\n");
563 else
564 fail ("Ticket 2 read failed\n");
566 /* DER encode and compare tkt2 enckdcreppart */
567 res = shishi_asn1_to_der (handle, shishi_tkt_enckdcreppart (t2), &buf, &n);
568 if (res == SHISHI_OK)
569 success ("shishi_asn1_to_der() OK\n");
570 else
571 n = 0, fail ("shishi_asn1_to_der() failed\n");
573 base64_encode (buf, n, buffer2, BUFSIZ);
574 free (buf);
575 if (strlen (buffer2) == strlen (tkt2enckdcreppartb64) &&
576 memcmp (buffer2, tkt2enckdcreppartb64,
577 strlen (tkt2enckdcreppartb64)) == 0)
578 success ("EncKDCRepPart 2 read OK\n");
579 else
580 fail ("EncKDCRepPart 2 read failed\n");
582 /* DER encode and compare tkt2 kdcrep */
583 res = shishi_asn1_to_der (handle, shishi_tkt_kdcrep (t2), &buf, &n);
584 if (res == SHISHI_OK)
585 success ("shishi_asn1_to_der() OK\n");
586 else
587 n = 0, fail ("shishi_asn1_to_der() failed\n");
589 base64_encode (buf, n, buffer2, BUFSIZ);
590 free (buf);
591 if (strlen (buffer2) == strlen (tkt2kdcrepb64) &&
592 memcmp (buffer2, tkt2kdcrepb64, strlen (tkt2kdcrepb64)) == 0)
593 success ("KDC-REP 2 read OK\n");
594 else
595 fail ("KDC-REP 2 read failed\n");
597 res = unlink ("tktset.tmp");
598 if (res == 0)
599 success ("unlink() OK\n");
600 else
601 fail ("unlink() failed\n");
603 shishi_tkt_done (t1);
604 success ("shishi_tkt_done (t1) OK\n");
605 shishi_tkt_done (t2);
606 success ("shishi_tkt_done (t2) OK\n");
608 /* shishi_tkts_done () */
609 shishi_tkts_done (&tktset);
610 success ("shishi_tkts_done() OK\n");
612 shishi_asn1_done (handle, tkt1asn1);
613 shishi_asn1_done (handle, tkt1asn2);
614 shishi_asn1_done (handle, tkt1asn3);
615 shishi_asn1_done (handle, tkt2asn1);
616 shishi_asn1_done (handle, tkt2asn2);
617 shishi_asn1_done (handle, tkt2asn3);