Branch data Line data Source code
1 : : /* asn1.c --- Utilities to manipulate RFC 1510 ASN.1 types.
2 : : * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Simon Josefsson
3 : : *
4 : : * This file is part of Shishi.
5 : : *
6 : : * Shishi is free software; you can redistribute it and/or modify it it
7 : : * under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * Shishi is distributed in the hope that it will be useful, but but
12 : : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : * General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 : : * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 : : * Floor, Boston, MA 02110-1301, USA
20 : : *
21 : : */
22 : :
23 : : /* Normally internal.h pulls in config.h, but since internal.h also
24 : : pulls in shishi.h, and we need to pull in libtasn1.h before
25 : : shishi.h to get Shishi_asn1 definition correct, we need to pull in
26 : : config.h here to avoid libtasn1.h pulling in system header files
27 : : without having parsed config.h first. */
28 : : #include <config.h>
29 : : #include <libtasn1.h>
30 : : #include "internal.h"
31 : : #include "asn1.h"
32 : :
33 : : #define ASN1NAME "KerberosV5Spec2."
34 : :
35 : : /* Generated by asn1Parser from ASN.1 module. */
36 : : extern const ASN1_ARRAY_TYPE shishi_asn1_tab[];
37 : :
38 : : /* Prototype in asn1.h, used by init.c. */
39 : : int
40 : 14 : _shishi_asn1_init (Shishi * handle)
41 : : {
42 : 14 : char errorDescription[MAX_ERROR_DESCRIPTION_SIZE] = "";
43 : : int asn1_result;
44 : :
45 [ - + ]: 14 : if (!asn1_check_version (ASN1_VERSION))
46 : : {
47 : 0 : shishi_warn (handle, "asn1_check-version(%s) failed: %s",
48 : : ASN1_VERSION, asn1_check_version (NULL));
49 : 0 : return SHISHI_ASN1_ERROR;
50 : : }
51 : :
52 [ - + ]: 14 : if (!asn1_check_version ("0.2.5"))
53 : 0 : shishi_warn (handle, "libtasn1 >= 0.2.5 preferred, you may see bugs.");
54 : :
55 : 14 : asn1_result = asn1_array2tree (shishi_asn1_tab,
56 : 14 : &handle->asn1, errorDescription);
57 [ - + ]: 14 : if (asn1_result != ASN1_SUCCESS)
58 : : {
59 : 0 : shishi_warn (handle, "asn1_array2tree() failed: %s\n",
60 : : asn1_strerror (asn1_result));
61 : 0 : shishi_warn (handle, "%s", errorDescription);
62 : 0 : return SHISHI_ASN1_ERROR;
63 : : }
64 : :
65 : 14 : return SHISHI_OK;
66 : : }
67 : :
68 : : int
69 : 21 : shishi_asn1_number_of_elements (Shishi * handle, Shishi_asn1 node,
70 : : const char *field, size_t * n)
71 : : {
72 : : int rc;
73 : : int tmp;
74 : :
75 : 21 : rc = asn1_number_of_elements (node, field, &tmp);
76 : 21 : *n = tmp;
77 [ - + ]: 21 : if (rc != ASN1_SUCCESS)
78 : : {
79 [ # # ]: 0 : if (rc == ASN1_ELEMENT_NOT_FOUND)
80 : 0 : return SHISHI_ASN1_NO_ELEMENT;
81 : : else
82 : 0 : return SHISHI_ASN1_ERROR;
83 : : }
84 : :
85 : 21 : return SHISHI_OK;
86 : : }
87 : :
88 : : int
89 : 0 : shishi_asn1_empty_p (Shishi * handle, Shishi_asn1 node, const char *field)
90 : : {
91 : : int rc;
92 : : int datalen;
93 : :
94 : 0 : datalen = 0;
95 : 0 : rc = asn1_read_value (node, field, NULL, &datalen);
96 [ # # ]: 0 : if (rc == ASN1_VALUE_NOT_FOUND)
97 : 0 : return 1;
98 : :
99 : 0 : return 0;
100 : : }
101 : :
102 : : /**
103 : : * shishi_asn1_read_inline:
104 : : * @handle: shishi handle as allocated by shishi_init().
105 : : * @node: ASN.1 variable to read field from.
106 : : * @field: name of field in @node to read.
107 : : * @data: pre-allocated output buffer that will hold ASN.1 field data.
108 : : * @datalen: on input, maximum size of output buffer,
109 : : * on output, actual size of output buffer.
110 : : *
111 : : * Extract data stored in a ASN.1 field into a fixed size buffer
112 : : * allocated by caller.
113 : : *
114 : : * Note that since it is difficult to predict the length of the field,
115 : : * it is often better to use shishi_asn1_read() instead.
116 : : *
117 : : * Return value: Returns SHISHI_OK if successful,
118 : : * SHISHI_ASN1_NO_ELEMENT if the element do not exist,
119 : : * SHISHI_ASN1_NO_VALUE if the field has no value, ot
120 : : * SHISHI_ASN1_ERROR otherwise.
121 : : **/
122 : : int
123 : 124 : shishi_asn1_read_inline (Shishi * handle, Shishi_asn1 node,
124 : : const char *field, char *data, size_t * datalen)
125 : : {
126 : : int rc;
127 : :
128 : 124 : rc = asn1_read_value (node, field, (unsigned char *) data, (int *) datalen);
129 [ - + ]: 124 : if (rc != ASN1_SUCCESS)
130 : : {
131 : 0 : shishi_error_set (handle, asn1_strerror (rc));
132 [ # # ]: 0 : if (rc == ASN1_ELEMENT_NOT_FOUND)
133 : 0 : return SHISHI_ASN1_NO_ELEMENT;
134 [ # # ]: 0 : else if (rc == ASN1_VALUE_NOT_FOUND)
135 : 0 : return SHISHI_ASN1_NO_VALUE;
136 : : else
137 : 0 : return SHISHI_ASN1_ERROR;
138 : : }
139 : :
140 : 124 : return SHISHI_OK;
141 : : }
142 : :
143 : : /**
144 : : * shishi_asn1_read:
145 : : * @handle: shishi handle as allocated by shishi_init().
146 : : * @node: ASN.1 variable to read field from.
147 : : * @field: name of field in @node to read.
148 : : * @data: newly allocated output buffer that will hold ASN.1 field data.
149 : : * @datalen: actual size of output buffer.
150 : : *
151 : : * Extract data stored in a ASN.1 field into a newly allocated buffer.
152 : : * The buffer will always be zero terminated, even though @datalen
153 : : * will not include the added zero.
154 : : *
155 : : * Return value: Returns SHISHI_OK if successful,
156 : : * SHISHI_ASN1_NO_ELEMENT if the element do not exist,
157 : : * SHISHI_ASN1_NO_VALUE if the field has no value, ot
158 : : * SHISHI_ASN1_ERROR otherwise.
159 : : **/
160 : : int
161 : 92 : shishi_asn1_read (Shishi * handle,
162 : : Shishi_asn1 node, const char *field,
163 : : char **data, size_t * datalen)
164 : : {
165 : : int rc;
166 : 92 : int len = 0;
167 : :
168 : 92 : rc = asn1_read_value (node, field, NULL, &len);
169 [ + - + + ]: 92 : if (rc != ASN1_SUCCESS && rc != ASN1_MEM_ERROR)
170 : : {
171 : 3 : shishi_error_set (handle, asn1_strerror (rc));
172 [ + - ]: 3 : if (rc == ASN1_ELEMENT_NOT_FOUND)
173 : 3 : return SHISHI_ASN1_NO_ELEMENT;
174 [ # # ]: 0 : else if (rc == ASN1_VALUE_NOT_FOUND)
175 : 0 : return SHISHI_ASN1_NO_VALUE;
176 : : else
177 : 0 : return SHISHI_ASN1_ERROR;
178 : : }
179 : :
180 [ + - ]: 89 : if (data)
181 : : {
182 : 89 : size_t dlen = (size_t) len;
183 : :
184 : 89 : *data = xmalloc (len + 1);
185 : :
186 [ + - ]: 89 : if (len > 0)
187 : : {
188 : 89 : rc = shishi_asn1_read_inline (handle, node, field, *data, &dlen);
189 [ - + ]: 89 : if (rc != SHISHI_OK)
190 : 0 : return rc;
191 : : }
192 : :
193 : 89 : (*data)[len] = '\0';
194 : : }
195 : :
196 [ + - ]: 89 : if (datalen)
197 : 89 : *datalen = (size_t) len;
198 : :
199 : 92 : return SHISHI_OK;
200 : : }
201 : :
202 : : /**
203 : : * shishi_asn1_read_optional:
204 : : * @handle: shishi handle as allocated by shishi_init().
205 : : * @node: ASN.1 variable to read field from.
206 : : * @field: name of field in @node to read.
207 : : * @data: newly allocated output buffer that will hold ASN.1 field data.
208 : : * @datalen: actual size of output buffer.
209 : : *
210 : : * Extract data stored in a ASN.1 field into a newly allocated buffer.
211 : : * If the field does not exist (i.e., SHISHI_ASN1_NO_ELEMENT), this
212 : : * function set datalen to 0 and succeeds. Can be useful to read
213 : : * ASN.1 fields which are marked OPTIONAL in the grammar, if you want
214 : : * to avoid special error handling in your code.
215 : : *
216 : : * Return value: Returns SHISHI_OK if successful,
217 : : * SHISHI_ASN1_NO_VALUE if the field has no value, ot
218 : : * SHISHI_ASN1_ERROR otherwise.
219 : : **/
220 : : int
221 : 6 : shishi_asn1_read_optional (Shishi * handle,
222 : : Shishi_asn1 node, const char *field,
223 : : char **data, size_t * datalen)
224 : : {
225 : : int rc;
226 : :
227 : 6 : rc = shishi_asn1_read (handle, node, field, data, datalen);
228 [ + + - + ]: 6 : if (rc != SHISHI_OK && rc != SHISHI_ASN1_NO_ELEMENT)
229 : 0 : return rc;
230 : :
231 [ + + ]: 6 : if (rc == SHISHI_ASN1_NO_ELEMENT)
232 [ + - ]: 3 : if (datalen)
233 : 3 : *datalen = 0;
234 : :
235 : 6 : return SHISHI_OK;
236 : : }
237 : :
238 : : #define C2I(buf) ((buf[3] & 0xFF) | \
239 : : ((buf[2] & 0xFF) << 8) | \
240 : : ((buf[1] & 0xFF) << 16) | \
241 : : ((buf[0] & 0xFF) << 24))
242 : :
243 : : int
244 : 20 : shishi_asn1_read_int32 (Shishi * handle, Shishi_asn1 node,
245 : : const char *field, int32_t * i)
246 : : {
247 : : char buf[4];
248 : : size_t buflen;
249 : : int rc;
250 : :
251 : 20 : memset (buf, 0, sizeof (buf));
252 : 20 : buflen = sizeof (buf);
253 : 20 : rc = shishi_asn1_read_inline (handle, node, field, buf, &buflen);
254 [ - + ]: 20 : if (rc != SHISHI_OK)
255 : 0 : return rc;
256 : :
257 [ + + ]: 20 : if (buflen < 4)
258 : : {
259 : 14 : memset (buf, 0, sizeof (buf));
260 : 14 : rc = shishi_asn1_read_inline (handle, node, field,
261 : 14 : &buf[4 - buflen], &buflen);
262 [ - + ]: 14 : if (rc != SHISHI_OK)
263 : 0 : return rc;
264 : : }
265 : 20 : *i = C2I (buf);
266 : :
267 : 20 : return SHISHI_OK;
268 : : }
269 : :
270 : : int
271 : 8 : shishi_asn1_read_uint32 (Shishi * handle, Shishi_asn1 node,
272 : : const char *field, uint32_t * i)
273 : : {
274 : 8 : return shishi_asn1_read_int32 (handle, node, field, (int32_t *) i);
275 : : }
276 : :
277 : : int
278 : 0 : shishi_asn1_read_integer (Shishi * handle, Shishi_asn1 node,
279 : : const char *field, int *i)
280 : : {
281 : 0 : return shishi_asn1_read_int32 (handle, node, field, (int32_t *) i);
282 : : }
283 : :
284 : : int
285 : 28 : shishi_asn1_read_bitstring (Shishi * handle, Shishi_asn1 node,
286 : : const char *field, uint32_t * flags)
287 : : {
288 : : char *buf;
289 : : size_t buflen;
290 : : size_t i;
291 : : int res;
292 : :
293 : 28 : res = shishi_asn1_read (handle, node, field, &buf, &buflen);
294 [ - + ]: 28 : if (res != SHISHI_OK)
295 : 0 : return res;
296 : :
297 [ - + ]: 28 : if (buflen < 4)
298 : 0 : return SHISHI_ASN1_ERROR;
299 : :
300 : 28 : *flags = 0;
301 [ + + ]: 140 : for (i = 0; i < 4; i++)
302 : : {
303 : 336 : *flags |= (((buf[i] >> 7) & 0x01) |
304 : 112 : ((buf[i] >> 5) & 0x02) |
305 : 112 : ((buf[i] >> 3) & 0x04) |
306 : 112 : ((buf[i] >> 1) & 0x08) |
307 : 112 : ((buf[i] << 1) & 0x10) |
308 : 112 : ((buf[i] << 3) & 0x20) |
309 : 224 : ((buf[i] << 5) & 0x40) | ((buf[i] << 7) & 0x80)) << (8 * i);
310 : : }
311 : :
312 : 28 : return SHISHI_OK;
313 : : }
314 : :
315 : : int
316 : 163 : shishi_asn1_write (Shishi * handle, Shishi_asn1 node,
317 : : const char *field, const char *data, size_t datalen)
318 : : {
319 : : int rc;
320 : :
321 : 163 : rc = asn1_write_value (node, field,
322 : : (const unsigned char *) data, (int) datalen);
323 [ - + ]: 163 : if (rc != ASN1_SUCCESS)
324 : : {
325 : 0 : shishi_error_set (handle, asn1_strerror (rc));
326 : 0 : return SHISHI_ASN1_ERROR;
327 : : }
328 : :
329 : 163 : return SHISHI_OK;
330 : : }
331 : :
332 : : int
333 : 11 : shishi_asn1_write_uint32 (Shishi * handle, Shishi_asn1 node,
334 : : const char *field, uint32_t n)
335 : : {
336 : : char *buf;
337 : : int res;
338 : :
339 : 11 : asprintf (&buf, "%lu", (unsigned long) n);
340 : 11 : res = shishi_asn1_write (handle, node, field, buf, 0);
341 : 11 : free (buf);
342 [ - + ]: 11 : if (res != SHISHI_OK)
343 : 0 : return res;
344 : :
345 : 11 : return SHISHI_OK;
346 : : }
347 : :
348 : : int
349 : 19 : shishi_asn1_write_int32 (Shishi * handle, Shishi_asn1 node,
350 : : const char *field, int32_t n)
351 : : {
352 : : char *buf;
353 : : int res;
354 : :
355 : 19 : asprintf (&buf, "%ld", (signed long) n);
356 : 19 : res = shishi_asn1_write (handle, node, field, buf, 0);
357 : 19 : free (buf);
358 [ - + ]: 19 : if (res != SHISHI_OK)
359 : 0 : return res;
360 : :
361 : 19 : return SHISHI_OK;
362 : : }
363 : :
364 : : int
365 : 6 : shishi_asn1_write_integer (Shishi * handle, Shishi_asn1 node,
366 : : const char *field, int n)
367 : : {
368 : 6 : return shishi_asn1_write_int32 (handle, node, field, (int32_t) n);
369 : : }
370 : :
371 : : int
372 : 6 : shishi_asn1_write_bitstring (Shishi * handle, Shishi_asn1 node,
373 : : const char *field, uint32_t flags)
374 : : {
375 : : char buf[4];
376 : : size_t i;
377 : : int res;
378 : :
379 : : /* XXX
380 : : Cannot handle bit strings longer than 32 bits.
381 : : Currently not needed though. */
382 : :
383 [ + + ]: 30 : for (i = 0; i < 4; i++)
384 : : {
385 : 192 : buf[i] = ((((flags >> (8 * i)) >> 7) & 0x01) |
386 : 24 : (((flags >> (8 * i)) >> 5) & 0x02) |
387 : 24 : (((flags >> (8 * i)) >> 3) & 0x04) |
388 : 24 : (((flags >> (8 * i)) >> 1) & 0x08) |
389 : 24 : (((flags >> (8 * i)) << 1) & 0x10) |
390 : 24 : (((flags >> (8 * i)) << 3) & 0x20) |
391 : 24 : (((flags >> (8 * i)) << 5) & 0x40) |
392 : 24 : (((flags >> (8 * i)) << 7) & 0x80));
393 : : }
394 : :
395 : 6 : res = shishi_asn1_write (handle, node, field, buf, 32);
396 [ - + ]: 6 : if (res != SHISHI_OK)
397 : 0 : return res;
398 : :
399 : 6 : return SHISHI_OK;
400 : : }
401 : :
402 : : /**
403 : : * shishi_asn1_done:
404 : : * @handle: shishi handle as allocated by shishi_init().
405 : : * @node: ASN.1 node to dellocate.
406 : : *
407 : : * Deallocate resources associated with ASN.1 structure. Note that
408 : : * the node must not be used after this call.
409 : : **/
410 : : void
411 : 30 : shishi_asn1_done (Shishi * handle, Shishi_asn1 node)
412 : : {
413 : :
414 : : int rc;
415 : :
416 [ + - ]: 30 : if (node)
417 : : {
418 : 30 : rc = asn1_delete_structure (&node);
419 [ - + ]: 30 : if (rc != ASN1_SUCCESS)
420 : 0 : shishi_error_printf (handle, "Cannot dellocate ASN.1 structure: %s",
421 : : asn1_strerror (rc));
422 : : }
423 : 30 : }
424 : :
425 : : static Shishi_asn1
426 : 12 : asn1_new (Shishi * handle, const char *field, const char *name)
427 : : {
428 : 12 : ASN1_TYPE node = ASN1_TYPE_EMPTY;
429 : : int res;
430 : :
431 : 12 : res = asn1_create_element (handle->asn1, field, &node);
432 [ - + ]: 12 : if (res != ASN1_SUCCESS)
433 : : {
434 : 0 : shishi_error_set (handle, asn1_strerror (res));
435 : 0 : return NULL;
436 : : }
437 : :
438 : 12 : return (Shishi_asn1) node;
439 : : }
440 : :
441 : : /**
442 : : * shishi_asn1_pa_enc_ts_enc:
443 : : * @handle: shishi handle as allocated by shishi_init().
444 : : *
445 : : * Create new ASN.1 structure for PA-ENC-TS-ENC.
446 : : *
447 : : * Return value: Returns ASN.1 structure.
448 : : **/
449 : : Shishi_asn1
450 : 0 : shishi_asn1_pa_enc_ts_enc (Shishi * handle)
451 : : {
452 : 0 : return asn1_new (handle, ASN1NAME "PA-ENC-TS-ENC", "PA-ENC-TS-ENC");
453 : : }
454 : :
455 : : /**
456 : : * shishi_asn1_encrypteddata:
457 : : * @handle: shishi handle as allocated by shishi_init().
458 : : *
459 : : * Create new ASN.1 structure for EncryptedData
460 : : *
461 : : * Return value: Returns ASN.1 structure.
462 : : **/
463 : : Shishi_asn1
464 : 0 : shishi_asn1_encrypteddata (Shishi * handle)
465 : : {
466 : 0 : return asn1_new (handle, ASN1NAME "EncryptedData", "EncryptedData");
467 : : }
468 : :
469 : : /**
470 : : * shishi_asn1_padata:
471 : : * @handle: shishi handle as allocated by shishi_init().
472 : : *
473 : : * Create new ASN.1 structure for PA-DATA.
474 : : *
475 : : * Return value: Returns ASN.1 structure.
476 : : **/
477 : : Shishi_asn1
478 : 0 : shishi_asn1_padata (Shishi * handle)
479 : : {
480 : 0 : return asn1_new (handle, ASN1NAME "PA-DATA", "PA-DATA");
481 : : }
482 : :
483 : : /**
484 : : * shishi_asn1_methoddata:
485 : : * @handle: shishi handle as allocated by shishi_init().
486 : : *
487 : : * Create new ASN.1 structure for METHOD-DATA.
488 : : *
489 : : * Return value: Returns ASN.1 structure.
490 : : **/
491 : : Shishi_asn1
492 : 0 : shishi_asn1_methoddata (Shishi * handle)
493 : : {
494 : 0 : return asn1_new (handle, ASN1NAME "METHOD-DATA", "METHOD-DATA");
495 : : }
496 : :
497 : : /**
498 : : * shishi_asn1_etype_info:
499 : : * @handle: shishi handle as allocated by shishi_init().
500 : : *
501 : : * Create new ASN.1 structure for ETYPE-INFO.
502 : : *
503 : : * Return value: Returns ASN.1 structure.
504 : : **/
505 : : Shishi_asn1
506 : 0 : shishi_asn1_etype_info (Shishi * handle)
507 : : {
508 : 0 : return asn1_new (handle, ASN1NAME "ETYPE-INFO", "ETYPE-INFO");
509 : : }
510 : :
511 : : /**
512 : : * shishi_asn1_etype_info2:
513 : : * @handle: shishi handle as allocated by shishi_init().
514 : : *
515 : : * Create new ASN.1 structure for ETYPE-INFO2.
516 : : *
517 : : * Return value: Returns ASN.1 structure.
518 : : **/
519 : : Shishi_asn1
520 : 0 : shishi_asn1_etype_info2 (Shishi * handle)
521 : : {
522 : 0 : return asn1_new (handle, ASN1NAME "ETYPE-INFO2", "ETYPE-INFO2");
523 : : }
524 : :
525 : : /**
526 : : * shishi_asn1_asreq:
527 : : * @handle: shishi handle as allocated by shishi_init().
528 : : *
529 : : * Create new ASN.1 structure for AS-REQ.
530 : : *
531 : : * Return value: Returns ASN.1 structure.
532 : : **/
533 : : Shishi_asn1
534 : 0 : shishi_asn1_asreq (Shishi * handle)
535 : : {
536 : 0 : return asn1_new (handle, ASN1NAME "AS-REQ", "KDC-REQ");
537 : : }
538 : :
539 : : /**
540 : : * shishi_asn1_asrep:
541 : : * @handle: shishi handle as allocated by shishi_init().
542 : : *
543 : : * Create new ASN.1 structure for AS-REP.
544 : : *
545 : : * Return value: Returns ASN.1 structure.
546 : : **/
547 : : Shishi_asn1
548 : 2 : shishi_asn1_asrep (Shishi * handle)
549 : : {
550 : 2 : return asn1_new (handle, ASN1NAME "AS-REP", "KDC-REP");
551 : : }
552 : :
553 : : /**
554 : : * shishi_asn1_tgsreq:
555 : : * @handle: shishi handle as allocated by shishi_init().
556 : : *
557 : : * Create new ASN.1 structure for TGS-REQ.
558 : : *
559 : : * Return value: Returns ASN.1 structure.
560 : : **/
561 : : Shishi_asn1
562 : 0 : shishi_asn1_tgsreq (Shishi * handle)
563 : : {
564 : 0 : return asn1_new (handle, ASN1NAME "TGS-REQ", "KDC-REQ");
565 : : }
566 : :
567 : : /**
568 : : * shishi_asn1_tgsrep:
569 : : * @handle: shishi handle as allocated by shishi_init().
570 : : *
571 : : * Create new ASN.1 structure for TGS-REP.
572 : : *
573 : : * Return value: Returns ASN.1 structure.
574 : : **/
575 : : Shishi_asn1
576 : 0 : shishi_asn1_tgsrep (Shishi * handle)
577 : : {
578 : 0 : return asn1_new (handle, ASN1NAME "TGS-REP", "KDC-REP");
579 : : }
580 : :
581 : : /**
582 : : * shishi_asn1_apreq:
583 : : * @handle: shishi handle as allocated by shishi_init().
584 : : *
585 : : * Create new ASN.1 structure for AP-REQ.
586 : : *
587 : : * Return value: Returns ASN.1 structure.
588 : : **/
589 : : Shishi_asn1
590 : 0 : shishi_asn1_apreq (Shishi * handle)
591 : : {
592 : 0 : return asn1_new (handle, ASN1NAME "AP-REQ", "AP-REQ");
593 : : }
594 : :
595 : : /**
596 : : * shishi_asn1_aprep:
597 : : * @handle: shishi handle as allocated by shishi_init().
598 : : *
599 : : * Create new ASN.1 structure for AP-REP.
600 : : *
601 : : * Return value: Returns ASN.1 structure.
602 : : **/
603 : : Shishi_asn1
604 : 0 : shishi_asn1_aprep (Shishi * handle)
605 : : {
606 : 0 : return asn1_new (handle, ASN1NAME "AP-REP", "AP-REP");
607 : : }
608 : :
609 : : /**
610 : : * shishi_asn1_encapreppart:
611 : : * @handle: shishi handle as allocated by shishi_init().
612 : : *
613 : : * Create new ASN.1 structure for AP-REP.
614 : : *
615 : : * Return value: Returns ASN.1 structure.
616 : : **/
617 : : Shishi_asn1
618 : 0 : shishi_asn1_encapreppart (Shishi * handle)
619 : : {
620 : 0 : return asn1_new (handle, ASN1NAME "EncAPRepPart", "EncAPRepPart");
621 : : }
622 : :
623 : : /**
624 : : * shishi_asn1_ticket:
625 : : * @handle: shishi handle as allocated by shishi_init().
626 : : *
627 : : * Create new ASN.1 structure for Ticket.
628 : : *
629 : : * Return value: Returns ASN.1 structure.
630 : : **/
631 : : Shishi_asn1
632 : 2 : shishi_asn1_ticket (Shishi * handle)
633 : : {
634 : 2 : return asn1_new (handle, ASN1NAME "Ticket", "Ticket");
635 : : }
636 : :
637 : : /**
638 : : * shishi_asn1_encticketpart:
639 : : * @handle: shishi handle as allocated by shishi_init().
640 : : *
641 : : * Create new ASN.1 structure for EncTicketPart.
642 : : *
643 : : * Return value: Returns ASN.1 structure.
644 : : **/
645 : : Shishi_asn1
646 : 2 : shishi_asn1_encticketpart (Shishi * handle)
647 : : {
648 : 2 : return asn1_new (handle, ASN1NAME "EncTicketPart", "EncTicketPart");
649 : : }
650 : :
651 : : /**
652 : : * shishi_asn1_authenticator:
653 : : * @handle: shishi handle as allocated by shishi_init().
654 : : *
655 : : * Create new ASN.1 structure for Authenticator.
656 : : *
657 : : * Return value: Returns ASN.1 structure.
658 : : **/
659 : : Shishi_asn1
660 : 1 : shishi_asn1_authenticator (Shishi * handle)
661 : : {
662 : 1 : return asn1_new (handle, ASN1NAME "Authenticator", "Authenticator");
663 : : }
664 : :
665 : : /**
666 : : * shishi_asn1_enckdcreppart:
667 : : * @handle: shishi handle as allocated by shishi_init().
668 : : *
669 : : * Create new ASN.1 structure for EncKDCRepPart.
670 : : *
671 : : * Return value: Returns ASN.1 structure.
672 : : **/
673 : : Shishi_asn1
674 : 0 : shishi_asn1_enckdcreppart (Shishi * handle)
675 : : {
676 : 0 : return asn1_new (handle, ASN1NAME "EncKDCRepPart", "EncKDCRepPart");
677 : : }
678 : :
679 : : /**
680 : : * shishi_asn1_encasreppart:
681 : : * @handle: shishi handle as allocated by shishi_init().
682 : : *
683 : : * Create new ASN.1 structure for EncASRepPart.
684 : : *
685 : : * Return value: Returns ASN.1 structure.
686 : : **/
687 : : Shishi_asn1
688 : 2 : shishi_asn1_encasreppart (Shishi * handle)
689 : : {
690 : 2 : return asn1_new (handle, ASN1NAME "EncASRepPart", "EncKDCRepPart");
691 : : }
692 : :
693 : : /**
694 : : * shishi_asn1_krberror:
695 : : * @handle: shishi handle as allocated by shishi_init().
696 : : *
697 : : * Create new ASN.1 structure for KRB-ERROR.
698 : : *
699 : : * Return value: Returns ASN.1 structure.
700 : : **/
701 : : Shishi_asn1
702 : 0 : shishi_asn1_krberror (Shishi * handle)
703 : : {
704 : 0 : return asn1_new (handle, ASN1NAME "KRB-ERROR", "KRB-ERROR");
705 : : }
706 : :
707 : : /**
708 : : * shishi_asn1_krbsafe:
709 : : * @handle: shishi handle as allocated by shishi_init().
710 : : *
711 : : * Create new ASN.1 structure for KRB-SAFE.
712 : : *
713 : : * Return value: Returns ASN.1 structure.
714 : : **/
715 : : Shishi_asn1
716 : 1 : shishi_asn1_krbsafe (Shishi * handle)
717 : : {
718 : 1 : return asn1_new (handle, ASN1NAME "KRB-SAFE", "KRB-SAFE");
719 : : }
720 : :
721 : : /**
722 : : * shishi_asn1_priv:
723 : : * @handle: shishi handle as allocated by shishi_init().
724 : : *
725 : : * Create new ASN.1 structure for KRB-PRIV.
726 : : *
727 : : * Return value: Returns ASN.1 structure.
728 : : **/
729 : : Shishi_asn1
730 : 1 : shishi_asn1_priv (Shishi * handle)
731 : : {
732 : 1 : return asn1_new (handle, ASN1NAME "KRB-PRIV", "KRB-PRIV");
733 : : }
734 : :
735 : : /**
736 : : * shishi_asn1_encprivpart:
737 : : * @handle: shishi handle as allocated by shishi_init().
738 : : *
739 : : * Create new ASN.1 structure for EncKrbPrivPart.
740 : : *
741 : : * Return value: Returns ASN.1 structure.
742 : : **/
743 : : Shishi_asn1
744 : 1 : shishi_asn1_encprivpart (Shishi * handle)
745 : : {
746 : 1 : return asn1_new (handle, ASN1NAME "EncKrbPrivPart", "EncKrbPrivPart");
747 : : }
748 : :
749 : : /**
750 : : * shishi_asn1_to_der_field:
751 : : * @handle: shishi handle as allocated by shishi_init().
752 : : * @node: ASN.1 data that have field to extract.
753 : : * @field: name of field in @node to extract.
754 : : * @der: output array that holds DER encoding of @field in @node.
755 : : * @len: output variable with length of @der output array.
756 : : *
757 : : * Extract newly allocated DER representation of specified ASN.1 field.
758 : : *
759 : : * Return value: Returns SHISHI_OK if successful, or SHISHI_ASN1_ERROR
760 : : * if DER encoding fails (common reasons for this is that the ASN.1
761 : : * is missing required values).
762 : : **/
763 : : int
764 : 31 : shishi_asn1_to_der_field (Shishi * handle, Shishi_asn1 node,
765 : : const char *field, char **der, size_t * len)
766 : : {
767 : 31 : char errorDescription[MAX_ERROR_DESCRIPTION_SIZE] = "";
768 : 31 : int mylen = 0;
769 : : int rc;
770 : :
771 : 31 : rc = asn1_der_coding (node, field, NULL, &mylen, errorDescription);
772 [ - + ]: 31 : if (rc != ASN1_MEM_ERROR)
773 : : {
774 : 0 : shishi_error_set (handle, errorDescription);
775 : 0 : return SHISHI_ASN1_ERROR;
776 : : }
777 : :
778 : 31 : *der = xmalloc (mylen);
779 : :
780 : 31 : rc = asn1_der_coding (node, field, *der, &mylen, errorDescription);
781 [ - + ]: 31 : if (rc != ASN1_SUCCESS)
782 : : {
783 : 0 : shishi_error_set (handle, errorDescription);
784 : 0 : return SHISHI_ASN1_ERROR;
785 : : }
786 : :
787 [ - + ]: 31 : if (strcmp (field, "req-body") == 0)
788 : : {
789 : : unsigned char class;
790 : : int derlen, derlen2;
791 : : unsigned long tag;
792 : : signed long lenlen;
793 : :
794 : : /* XXX when encoding a field inside a SEQUENCE, libtasn1 appear
795 : : to include the tag from the SEQUENCE in the encoding of a
796 : : particular field. This appear wrong, so we frob it here.
797 : : This typically happens when encoding req-body in KDC-REQ for
798 : : TGS checksums. */
799 : :
800 : 0 : rc = asn1_get_tag_der ((unsigned char *) *der, mylen, &class,
801 : : &derlen, &tag);
802 [ # # ]: 0 : if (rc != ASN1_SUCCESS)
803 : : {
804 : 0 : shishi_error_set (handle, errorDescription);
805 : 0 : return SHISHI_ASN1_ERROR;
806 : : }
807 : :
808 : 0 : lenlen = asn1_get_length_der ((unsigned char *) *der + derlen,
809 : : mylen - derlen, &derlen2);
810 [ # # ]: 0 : if (lenlen < 0)
811 : 0 : return SHISHI_ASN1_ERROR;
812 : :
813 [ # # ]: 0 : if (derlen + derlen2 < mylen)
814 : : {
815 : 0 : mylen -= derlen + derlen2;
816 : 0 : memmove (*der, *der + derlen + derlen2, mylen);
817 : : }
818 : : }
819 : :
820 : 31 : *len = mylen;
821 : :
822 : 31 : return SHISHI_OK;
823 : : }
824 : :
825 : : /**
826 : : * shishi_asn1_to_der:
827 : : * @handle: shishi handle as allocated by shishi_init().
828 : : * @node: ASN.1 data to convert to DER.
829 : : * @der: output array that holds DER encoding of @node.
830 : : * @len: output variable with length of @der output array.
831 : : *
832 : : * Extract newly allocated DER representation of specified ASN.1 data.
833 : : *
834 : : * Return value: Returns SHISHI_OK if successful, or SHISHI_ASN1_ERROR
835 : : * if DER encoding fails (common reasons for this is that the ASN.1
836 : : * is missing required values).
837 : : **/
838 : : int
839 : 31 : shishi_asn1_to_der (Shishi * handle, Shishi_asn1 node, char **der,
840 : : size_t * len)
841 : : {
842 : 31 : return shishi_asn1_to_der_field (handle, node, "", der, len);
843 : : }
844 : :
845 : : static Shishi_asn1
846 : 21 : der2asn1 (Shishi * handle,
847 : : const char *fieldname,
848 : : const char *nodename, const char *der, size_t derlen)
849 : : {
850 : 21 : char errorDescription[MAX_ERROR_DESCRIPTION_SIZE] = "";
851 : 21 : Shishi_asn1 structure = NULL;
852 : 21 : int asn1_result = ASN1_SUCCESS;
853 : :
854 : 21 : asn1_result = asn1_create_element (handle->asn1, fieldname, &structure);
855 [ - + ]: 21 : if (asn1_result != ASN1_SUCCESS)
856 : : {
857 : 0 : shishi_error_set (handle, asn1_strerror (asn1_result));
858 : 0 : return NULL;
859 : : }
860 : :
861 : 21 : asn1_result = asn1_der_decoding (&structure, (const unsigned char *) der,
862 : : (int) derlen, errorDescription);
863 [ + + ]: 21 : if (asn1_result != ASN1_SUCCESS)
864 : : {
865 : 2 : asn1_delete_structure (&structure);
866 : 2 : shishi_error_set (handle, errorDescription);
867 : 2 : return NULL;
868 : : }
869 : :
870 : 21 : return structure;
871 : : }
872 : :
873 : : /**
874 : : * shishi_asn1_msgtype:
875 : : * @handle: shishi handle as allocated by shishi_init().
876 : : * @node: ASN.1 type to get msg type for.
877 : : *
878 : : * Determine msg-type of ASN.1 type of a packet. Currently this uses
879 : : * the msg-type field instead of the APPLICATION tag, but this may be
880 : : * changed in the future.
881 : : *
882 : : * Return value: Returns msg-type of ASN.1 type, 0 on failure.
883 : : **/
884 : : Shishi_msgtype
885 : 0 : shishi_asn1_msgtype (Shishi * handle, Shishi_asn1 node)
886 : : {
887 : : asn1_retCode rc;
888 : : uint32_t msgtype;
889 : :
890 : : /* XXX Use APPLICATION tag instead. */
891 : 0 : rc = shishi_asn1_read_uint32 (handle, node, "msg-type", &msgtype);
892 [ # # ]: 0 : if (rc != SHISHI_OK)
893 : 0 : return 0;
894 : :
895 : 0 : return msgtype;
896 : : }
897 : :
898 : : /**
899 : : * shishi_der_msgtype:
900 : : * @handle: shishi handle as allocated by shishi_init().
901 : : * @der: input character array with DER encoding.
902 : : * @derlen: length of input character array with DER encoding.
903 : : *
904 : : * Determine msg-type of DER coded data of a packet.
905 : : *
906 : : * Return value: Returns msg-type of DER data, 0 on failure.
907 : : **/
908 : : Shishi_msgtype
909 : 0 : shishi_der_msgtype (Shishi * handle, const char *der, size_t derlen)
910 : : {
911 : : /* XXX Doesn't handle APPLICATION TAGS > 31. */
912 [ # # ][ # # ]: 0 : if (derlen > 1 && *der >= 0x60 && (unsigned char) *der <= 0x7F)
[ # # ]
913 : 0 : return *der - 0x60;
914 : : else
915 : 0 : return 0;
916 : : }
917 : :
918 : : /**
919 : : * shishi_der2asn1:
920 : : * @handle: shishi handle as allocated by shishi_init().
921 : : * @der: input character array with DER encoding.
922 : : * @derlen: length of input character array with DER encoding.
923 : : *
924 : : * Convert arbitrary DER data of a packet to a ASN.1 type.
925 : : *
926 : : * Return value: Returns newly allocate ASN.1 corresponding to DER
927 : : * data, or %NULL on failure.
928 : : **/
929 : : Shishi_asn1
930 : 0 : shishi_der2asn1 (Shishi * handle, const char *der, size_t derlen)
931 : : {
932 : 0 : Shishi_asn1 node = NULL;
933 : :
934 [ # # # # # : 0 : switch (shishi_der_msgtype (handle, der, derlen))
# # # # #
# ]
935 : : {
936 : : case SHISHI_MSGTYPE_AS_REQ:
937 : 0 : node = shishi_der2asn1_asreq (handle, der, derlen);
938 : 0 : break;
939 : :
940 : : case SHISHI_MSGTYPE_AS_REP:
941 : 0 : node = shishi_der2asn1_asrep (handle, der, derlen);
942 : 0 : break;
943 : :
944 : : case SHISHI_MSGTYPE_TGS_REQ:
945 : 0 : node = shishi_der2asn1_tgsreq (handle, der, derlen);
946 : 0 : break;
947 : :
948 : : case SHISHI_MSGTYPE_TGS_REP:
949 : 0 : node = shishi_der2asn1_tgsrep (handle, der, derlen);
950 : 0 : break;
951 : :
952 : : case SHISHI_MSGTYPE_AP_REQ:
953 : 0 : node = shishi_der2asn1_apreq (handle, der, derlen);
954 : 0 : break;
955 : :
956 : : case SHISHI_MSGTYPE_AP_REP:
957 : 0 : node = shishi_der2asn1_aprep (handle, der, derlen);
958 : 0 : break;
959 : :
960 : : case SHISHI_MSGTYPE_SAFE:
961 : 0 : node = shishi_der2asn1_krbsafe (handle, der, derlen);
962 : 0 : break;
963 : :
964 : : case SHISHI_MSGTYPE_PRIV:
965 : 0 : node = shishi_der2asn1_priv (handle, der, derlen);
966 : 0 : break;
967 : :
968 : : case SHISHI_MSGTYPE_CRED:
969 : : /* node = shishi_der2asn1_cred (handle, der, derlen); */
970 : 0 : break;
971 : :
972 : : case SHISHI_MSGTYPE_ERROR:
973 : 0 : node = shishi_der2asn1_krberror (handle, der, derlen);
974 : 0 : break;
975 : :
976 : : case SHISHI_MSGTYPE_RESERVED16:
977 : : case SHISHI_MSGTYPE_RESERVED17:
978 : : default:
979 : 0 : node = NULL;
980 : : break;
981 : : }
982 : :
983 : 0 : return node;
984 : : }
985 : :
986 : : /**
987 : : * shishi_der2asn1_padata:
988 : : * @handle: shishi handle as allocated by shishi_init().
989 : : * @der: input character array with DER encoding.
990 : : * @derlen: length of input character array with DER encoding.
991 : : *
992 : : * Decode DER encoding of PA-DATA and create a ASN.1 structure.
993 : : *
994 : : * Return value: Returns ASN.1 structure corresponding to DER data.
995 : : **/
996 : : Shishi_asn1
997 : 0 : shishi_der2asn1_padata (Shishi * handle, const char *der, size_t derlen)
998 : : {
999 : 0 : return der2asn1 (handle, ASN1NAME "PA-DATA", "PA-DATA", der, derlen);
1000 : : }
1001 : :
1002 : : /**
1003 : : * shishi_der2asn1_methoddata:
1004 : : * @handle: shishi handle as allocated by shishi_init().
1005 : : * @der: input character array with DER encoding.
1006 : : * @derlen: length of input character array with DER encoding.
1007 : : *
1008 : : * Decode DER encoding of METHOD-DATA and create a ASN.1 structure.
1009 : : *
1010 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1011 : : **/
1012 : : Shishi_asn1
1013 : 0 : shishi_der2asn1_methoddata (Shishi * handle, const char *der, size_t derlen)
1014 : : {
1015 : 0 : return der2asn1 (handle, ASN1NAME "METHOD-DATA", "METHOD-DATA", der,
1016 : : derlen);
1017 : : }
1018 : :
1019 : : /**
1020 : : * shishi_der2asn1_etype_info:
1021 : : * @handle: shishi handle as allocated by shishi_init().
1022 : : * @der: input character array with DER encoding.
1023 : : * @derlen: length of input character array with DER encoding.
1024 : : *
1025 : : * Decode DER encoding of ETYPE-INFO and create a ASN.1 structure.
1026 : : *
1027 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1028 : : **/
1029 : : Shishi_asn1
1030 : 0 : shishi_der2asn1_etype_info (Shishi * handle, const char *der, size_t derlen)
1031 : : {
1032 : 0 : return der2asn1 (handle, ASN1NAME "ETYPE-INFO", "ETYPE-INFO", der, derlen);
1033 : : }
1034 : :
1035 : : /**
1036 : : * shishi_der2asn1_etype_info2:
1037 : : * @handle: shishi handle as allocated by shishi_init().
1038 : : * @der: input character array with DER encoding.
1039 : : * @derlen: length of input character array with DER encoding.
1040 : : *
1041 : : * Decode DER encoding of ETYPE-INFO2 and create a ASN.1 structure.
1042 : : *
1043 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1044 : : **/
1045 : : Shishi_asn1
1046 : 0 : shishi_der2asn1_etype_info2 (Shishi * handle, const char *der, size_t derlen)
1047 : : {
1048 : 0 : return der2asn1 (handle, ASN1NAME "ETYPE-INFO2", "ETYPE-INFO2", der,
1049 : : derlen);
1050 : : }
1051 : :
1052 : : /**
1053 : : * shishi_der2asn1_ticket:
1054 : : * @handle: shishi handle as allocated by shishi_init().
1055 : : * @der: input character array with DER encoding.
1056 : : * @derlen: length of input character array with DER encoding.
1057 : : *
1058 : : * Decode DER encoding of Ticket and create a ASN.1 structure.
1059 : : *
1060 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1061 : : **/
1062 : : Shishi_asn1
1063 : 6 : shishi_der2asn1_ticket (Shishi * handle, const char *der, size_t derlen)
1064 : : {
1065 : 6 : return der2asn1 (handle, ASN1NAME "Ticket", "Ticket", der, derlen);
1066 : : }
1067 : :
1068 : : /**
1069 : : * shishi_der2asn1_encticketpart:
1070 : : * @handle: shishi handle as allocated by shishi_init().
1071 : : * @der: input character array with DER encoding.
1072 : : * @derlen: length of input character array with DER encoding.
1073 : : *
1074 : : * Decode DER encoding of EncTicketPart and create a ASN.1 structure.
1075 : : *
1076 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1077 : : **/
1078 : : Shishi_asn1
1079 : 0 : shishi_der2asn1_encticketpart (Shishi * handle, const char *der,
1080 : : size_t derlen)
1081 : : {
1082 : 0 : return der2asn1 (handle, ASN1NAME "EncTicketPart", "EncTicketPart",
1083 : : der, derlen);
1084 : : }
1085 : :
1086 : : /**
1087 : : * shishi_der2asn1_asreq:
1088 : : * @handle: shishi handle as allocated by shishi_init().
1089 : : * @der: input character array with DER encoding.
1090 : : * @derlen: length of input character array with DER encoding.
1091 : : *
1092 : : * Decode DER encoding of AS-REQ and create a ASN.1 structure.
1093 : : *
1094 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1095 : : **/
1096 : : Shishi_asn1
1097 : 1 : shishi_der2asn1_asreq (Shishi * handle, const char *der, size_t derlen)
1098 : : {
1099 : 1 : return der2asn1 (handle, ASN1NAME "AS-REQ", "KDC-REQ", der, derlen);
1100 : : }
1101 : :
1102 : : /**
1103 : : * shishi_der2asn1_tgsreq:
1104 : : * @handle: shishi handle as allocated by shishi_init().
1105 : : * @der: input character array with DER encoding.
1106 : : * @derlen: length of input character array with DER encoding.
1107 : : *
1108 : : * Decode DER encoding of TGS-REQ and create a ASN.1 structure.
1109 : : *
1110 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1111 : : **/
1112 : : Shishi_asn1
1113 : 0 : shishi_der2asn1_tgsreq (Shishi * handle, const char *der, size_t derlen)
1114 : : {
1115 : 0 : return der2asn1 (handle, ASN1NAME "TGS-REQ", "KDC-REQ", der, derlen);
1116 : : }
1117 : :
1118 : : /**
1119 : : * shishi_der2asn1_asrep:
1120 : : * @handle: shishi handle as allocated by shishi_init().
1121 : : * @der: input character array with DER encoding.
1122 : : * @derlen: length of input character array with DER encoding.
1123 : : *
1124 : : * Decode DER encoding of AS-REP and create a ASN.1 structure.
1125 : : *
1126 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1127 : : **/
1128 : : Shishi_asn1
1129 : 3 : shishi_der2asn1_asrep (Shishi * handle, const char *der, size_t derlen)
1130 : : {
1131 : 3 : return der2asn1 (handle, ASN1NAME "AS-REP", "KDC-REP", der, derlen);
1132 : : }
1133 : :
1134 : : /**
1135 : : * shishi_der2asn1_tgsrep:
1136 : : * @handle: shishi handle as allocated by shishi_init().
1137 : : * @der: input character array with DER encoding.
1138 : : * @derlen: length of input character array with DER encoding.
1139 : : *
1140 : : * Decode DER encoding of TGS-REP and create a ASN.1 structure.
1141 : : *
1142 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1143 : : **/
1144 : : Shishi_asn1
1145 : 2 : shishi_der2asn1_tgsrep (Shishi * handle, const char *der, size_t derlen)
1146 : : {
1147 : 2 : return der2asn1 (handle, ASN1NAME "TGS-REP", "KDC-REP", der, derlen);
1148 : : }
1149 : :
1150 : : /**
1151 : : * shishi_der2asn1_kdcrep:
1152 : : * @handle: shishi handle as allocated by shishi_init().
1153 : : * @der: input character array with DER encoding.
1154 : : * @derlen: length of input character array with DER encoding.
1155 : : *
1156 : : * Decode DER encoding of KDC-REP and create a ASN.1 structure.
1157 : : *
1158 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1159 : : **/
1160 : : Shishi_asn1
1161 : 0 : shishi_der2asn1_kdcrep (Shishi * handle, const char *der, size_t derlen)
1162 : : {
1163 : 0 : return der2asn1 (handle, ASN1NAME "KDC-REP", "KDC-REP", der, derlen);
1164 : : }
1165 : :
1166 : : /**
1167 : : * shishi_der2asn1_encasreppart:
1168 : : * @handle: shishi handle as allocated by shishi_init().
1169 : : * @der: input character array with DER encoding.
1170 : : * @derlen: length of input character array with DER encoding.
1171 : : *
1172 : : * Decode DER encoding of EncASRepPart and create a ASN.1 structure.
1173 : : *
1174 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1175 : : **/
1176 : : Shishi_asn1
1177 : 4 : shishi_der2asn1_encasreppart (Shishi * handle, const char *der, size_t derlen)
1178 : : {
1179 : 4 : return der2asn1 (handle, ASN1NAME "EncASRepPart", "EncKDCRepPart",
1180 : : der, derlen);
1181 : : }
1182 : :
1183 : : /**
1184 : : * shishi_der2asn1_enctgsreppart:
1185 : : * @handle: shishi handle as allocated by shishi_init().
1186 : : * @der: input character array with DER encoding.
1187 : : * @derlen: length of input character array with DER encoding.
1188 : : *
1189 : : * Decode DER encoding of EncTGSRepPart and create a ASN.1 structure.
1190 : : *
1191 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1192 : : **/
1193 : : Shishi_asn1
1194 : 2 : shishi_der2asn1_enctgsreppart (Shishi * handle, const char *der,
1195 : : size_t derlen)
1196 : : {
1197 : 2 : return der2asn1 (handle, ASN1NAME "EncTGSRepPart", "EncKDCRepPart",
1198 : : der, derlen);
1199 : : }
1200 : :
1201 : : /**
1202 : : * shishi_der2asn1_enckdcreppart:
1203 : : * @handle: shishi handle as allocated by shishi_init().
1204 : : * @der: input character array with DER encoding.
1205 : : * @derlen: length of input character array with DER encoding.
1206 : : *
1207 : : * Decode DER encoding of EncKDCRepPart and create a ASN.1 structure.
1208 : : *
1209 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1210 : : **/
1211 : : Shishi_asn1
1212 : 0 : shishi_der2asn1_enckdcreppart (Shishi * handle, const char *der,
1213 : : size_t derlen)
1214 : : {
1215 : 0 : return der2asn1 (handle, ASN1NAME "EncKDCRepPart", "EncKDCRepPart",
1216 : : der, derlen);
1217 : : }
1218 : :
1219 : : /**
1220 : : * shishi_der2asn1_authenticator:
1221 : : * @handle: shishi handle as allocated by shishi_init().
1222 : : * @der: input character array with DER encoding.
1223 : : * @derlen: length of input character array with DER encoding.
1224 : : *
1225 : : * Decode DER encoding of Authenticator and create a ASN.1 structure.
1226 : : *
1227 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1228 : : **/
1229 : : Shishi_asn1
1230 : 1 : shishi_der2asn1_authenticator (Shishi * handle, const char *der,
1231 : : size_t derlen)
1232 : : {
1233 : 1 : return der2asn1 (handle, ASN1NAME "Authenticator", "Authenticator",
1234 : : der, derlen);
1235 : : }
1236 : :
1237 : : /**
1238 : : * shishi_der2asn1_krberror:
1239 : : * @handle: shishi handle as allocated by shishi_init().
1240 : : * @der: input character array with DER encoding.
1241 : : * @derlen: length of input character array with DER encoding.
1242 : : *
1243 : : * Decode DER encoding of KRB-ERROR and create a ASN.1 structure.
1244 : : *
1245 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1246 : : **/
1247 : : Shishi_asn1
1248 : 0 : shishi_der2asn1_krberror (Shishi * handle, const char *der, size_t derlen)
1249 : : {
1250 : 0 : return der2asn1 (handle, ASN1NAME "KRB-ERROR", "KRB-ERROR", der, derlen);
1251 : : }
1252 : :
1253 : : /**
1254 : : * shishi_der2asn1_krbsafe:
1255 : : * @handle: shishi handle as allocated by shishi_init().
1256 : : * @der: input character array with DER encoding.
1257 : : * @derlen: length of input character array with DER encoding.
1258 : : *
1259 : : * Decode DER encoding of KRB-SAFE and create a ASN.1 structure.
1260 : : *
1261 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1262 : : **/
1263 : : Shishi_asn1
1264 : 1 : shishi_der2asn1_krbsafe (Shishi * handle, const char *der, size_t derlen)
1265 : : {
1266 : 1 : return der2asn1 (handle, ASN1NAME "KRB-SAFE", "KRB-SAFE", der, derlen);
1267 : : }
1268 : :
1269 : : /**
1270 : : * shishi_der2asn1_priv:
1271 : : * @handle: shishi handle as allocated by shishi_init().
1272 : : * @der: input character array with DER encoding.
1273 : : * @derlen: length of input character array with DER encoding.
1274 : : *
1275 : : * Decode DER encoding of KRB-PRIV and create a ASN.1 structure.
1276 : : *
1277 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1278 : : **/
1279 : : Shishi_asn1
1280 : 1 : shishi_der2asn1_priv (Shishi * handle, const char *der, size_t derlen)
1281 : : {
1282 : 1 : return der2asn1 (handle, ASN1NAME "KRB-PRIV", "KRB-PRIV", der, derlen);
1283 : : }
1284 : :
1285 : : /**
1286 : : * shishi_der2asn1_encprivpart:
1287 : : * @handle: shishi handle as allocated by shishi_init().
1288 : : * @der: input character array with DER encoding.
1289 : : * @derlen: length of input character array with DER encoding.
1290 : : *
1291 : : * Decode DER encoding of EncKrbPrivPart and create a ASN.1 structure.
1292 : : *
1293 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1294 : : **/
1295 : : Shishi_asn1
1296 : 0 : shishi_der2asn1_encprivpart (Shishi * handle, const char *der, size_t derlen)
1297 : : {
1298 : 0 : return der2asn1 (handle, ASN1NAME "EncKrbPrivPart", "EncKrbPrivPart",
1299 : : der, derlen);
1300 : : }
1301 : :
1302 : : /**
1303 : : * shishi_der2asn1_apreq:
1304 : : * @handle: shishi handle as allocated by shishi_init().
1305 : : * @der: input character array with DER encoding.
1306 : : * @derlen: length of input character array with DER encoding.
1307 : : *
1308 : : * Decode DER encoding of AP-REQ and create a ASN.1 structure.
1309 : : *
1310 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1311 : : **/
1312 : : Shishi_asn1
1313 : 0 : shishi_der2asn1_apreq (Shishi * handle, const char *der, size_t derlen)
1314 : : {
1315 : 0 : return der2asn1 (handle, ASN1NAME "AP-REQ", "AP-REQ", der, derlen);
1316 : : }
1317 : :
1318 : : /**
1319 : : * shishi_der2asn1_aprep:
1320 : : * @handle: shishi handle as allocated by shishi_init().
1321 : : * @der: input character array with DER encoding.
1322 : : * @derlen: length of input character array with DER encoding.
1323 : : *
1324 : : * Decode DER encoding of AP-REP and create a ASN.1 structure.
1325 : : *
1326 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1327 : : **/
1328 : : Shishi_asn1
1329 : 0 : shishi_der2asn1_aprep (Shishi * handle, const char *der, size_t derlen)
1330 : : {
1331 : 0 : return der2asn1 (handle, ASN1NAME "AP-REP", "AP-REP", der, derlen);
1332 : : }
1333 : :
1334 : : /**
1335 : : * shishi_der2asn1_encapreppart:
1336 : : * @handle: shishi handle as allocated by shishi_init().
1337 : : * @der: input character array with DER encoding.
1338 : : * @derlen: length of input character array with DER encoding.
1339 : : *
1340 : : * Decode DER encoding of EncAPRepPart and create a ASN.1 structure.
1341 : : *
1342 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1343 : : **/
1344 : : Shishi_asn1
1345 : 0 : shishi_der2asn1_encapreppart (Shishi * handle, const char *der, size_t derlen)
1346 : : {
1347 : 0 : return der2asn1 (handle, ASN1NAME "EncAPRepPart", "EncAPRepPart",
1348 : : der, derlen);
1349 : : }
1350 : :
1351 : : /**
1352 : : * shishi_der2asn1_kdcreq:
1353 : : * @handle: shishi handle as allocated by shishi_init().
1354 : : * @der: input character array with DER encoding.
1355 : : * @derlen: length of input character array with DER encoding.
1356 : : *
1357 : : * Decode DER encoding of AS-REQ, TGS-REQ or KDC-REQ and create a
1358 : : * ASN.1 structure.
1359 : : *
1360 : : * Return value: Returns ASN.1 structure corresponding to DER data.
1361 : : **/
1362 : : Shishi_asn1
1363 : 0 : shishi_der2asn1_kdcreq (Shishi * handle, const char *der, size_t derlen)
1364 : : {
1365 : 0 : Shishi_asn1 structure = NULL;
1366 : :
1367 : 0 : structure = shishi_der2asn1_asreq (handle, der, derlen);
1368 [ # # ]: 0 : if (structure == NULL)
1369 : : {
1370 : 0 : printf ("der2asn1_kdcreq: not asreq\n");
1371 : 0 : shishi_error_printf (handle, "Could not DER decode AS-REQ\n");
1372 : :
1373 : 0 : structure = shishi_der2asn1_tgsreq (handle, der, derlen);
1374 [ # # ]: 0 : if (structure == NULL)
1375 : : {
1376 : 0 : printf ("der2asn1_kdcreq: not tgsreq\n");
1377 : 0 : shishi_error_printf (handle, "Could not DER decode TGS-REQ\n");
1378 : :
1379 : 0 : structure = shishi_der2asn1_kdcreq (handle, der, derlen);
1380 [ # # ]: 0 : if (structure == NULL)
1381 : : {
1382 : 0 : printf ("der2asn1_kdcreq: not kdcreq\n");
1383 : 0 : shishi_error_printf (handle, "Could not DER decode KDC-REQ\n");
1384 : :
1385 : 0 : return NULL;
1386 : : }
1387 : : else
1388 : 0 : printf ("der2asn1_kdcreq: kdcreq!!\n");
1389 : : }
1390 : : }
1391 : :
1392 : 0 : return structure;
1393 : : }
1394 : :
1395 : : /**
1396 : : * shishi_asn1_print:
1397 : : * @handle: shishi handle as allocated by shishi_init().
1398 : : * @node: ASN.1 data that have field to extract.
1399 : : * @fh: file descriptor to print to, e.g. stdout.
1400 : : *
1401 : : * Print ASN.1 structure in human readable form, typically for
1402 : : * debugging purposes.
1403 : : **/
1404 : : void
1405 : 15 : shishi_asn1_print (Shishi * handle, Shishi_asn1 node, FILE * fh)
1406 : : {
1407 : 15 : asn1_print_structure (fh, node, "", ASN1_PRINT_NAME_TYPE_VALUE);
1408 : 15 : }
|