xref: /freebsd/crypto/krb5/src/tests/asn.1/trval.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright (C) 1992,1993 Trusted Information Systems, Inc.
4  *
5  * Permission to include this software in the Kerberos V5 distribution
6  * was graciously provided by Trusted Information Systems.
7  *
8  * Trusted Information Systems makes no representation about the
9  * suitability of this software for any purpose.  It is provided
10  * "as is" without express or implied warranty.
11  */
12 /*
13  * Copyright (C) 1994 Massachusetts Institute of Technology
14  *
15  * Export of this software from the United States of America may
16  *   require a specific license from the United States Government.
17  *   It is the responsibility of any person or organization contemplating
18  *   export to obtain such a license before exporting.
19  *
20  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
21  * distribute this software and its documentation for any purpose and
22  * without fee is hereby granted, provided that the above copyright
23  * notice appear in all copies and that both that copyright notice and
24  * this permission notice appear in supporting documentation, and that
25  * the name of M.I.T. not be used in advertising or publicity pertaining
26  * to distribution of the software without specific, written prior
27  * permission.  Furthermore if you modify this software you must label
28  * your software as modified software and not distribute it in such a
29  * fashion that it might be confused with the original M.I.T. software.
30  * M.I.T. makes no representations about the suitability of
31  * this software for any purpose.  It is provided "as is" without express
32  * or implied warranty.
33  */
34 
35 /*****************************************************************************
36  * trval.c.c
37  *****************************************************************************/
38 
39 #include <unistd.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <ctype.h>
43 #include <string.h>
44 
45 #define OK 0
46 #define NOTOK (-1)
47 
48 /* IDENTIFIER OCTET = TAG CLASS | FORM OF ENCODING | TAG NUMBER */
49 
50 /* TAG CLASSES */
51 #define ID_CLASS   0xc0         /* bits 8 and 7 */
52 #define CLASS_UNIV 0x00         /* 0 = universal */
53 #define CLASS_APPL 0x40         /* 1 = application */
54 #define CLASS_CONT 0x80         /* 2 = context-specific */
55 #define CLASS_PRIV 0xc0         /* 3 = private */
56 
57 /* FORM OF ENCODING */
58 #define ID_FORM   0x20          /* bit 6 */
59 #define FORM_PRIM 0x00          /* 0 = primitive */
60 #define FORM_CONS 0x20          /* 1 = constructed */
61 
62 /* TAG NUMBERS */
63 #define ID_TAG    0x1f          /* bits 5-1 */
64 #define PRIM_BOOL 0x01          /* Boolean */
65 #define PRIM_INT  0x02          /* Integer */
66 #define PRIM_BITS 0x03          /* Bit String */
67 #define PRIM_OCTS 0x04          /* Octet String */
68 #define PRIM_NULL 0x05          /* Null */
69 #define PRIM_OID  0x06          /* Object Identifier */
70 #define PRIM_ODE  0x07          /* Object Descriptor */
71 #define CONS_EXTN 0x08          /* External */
72 #define PRIM_REAL 0x09          /* Real */
73 #define PRIM_ENUM 0x0a          /* Enumerated type */
74 #define PRIM_ENCR 0x0b          /* Encrypted */
75 #define CONS_SEQ  0x10          /* SEQUENCE/SEQUENCE OF */
76 #define CONS_SET  0x11          /* SET/SET OF */
77 #define DEFN_NUMS 0x12          /* Numeric String */
78 #define DEFN_PRTS 0x13          /* Printable String */
79 #define DEFN_T61S 0x14          /* T.61 String */
80 #define DEFN_VTXS 0x15          /* Videotex String */
81 #define DEFN_IA5S 0x16          /* IA5 String */
82 #define DEFN_UTCT 0x17          /* UTCTime */
83 #define DEFN_GENT 0x18          /* Generalized Time */
84 #define DEFN_GFXS 0x19          /* Graphics string (ISO2375) */
85 #define DEFN_VISS 0x1a          /* Visible string */
86 #define DEFN_GENS 0x1b          /* General string */
87 #define DEFN_CHRS 0x1c          /* Character string */
88 
89 #define LEN_XTND        0x80    /* long or indefinite form */
90 #define LEN_SMAX        127     /* largest short form */
91 #define LEN_MASK        0x7f    /* mask to get number of bytes in length */
92 #define LEN_INDF        (-1)    /* indefinite length */
93 
94 #define KRB5    /* Do krb5 application types */
95 
96 int print_types = 0;
97 int print_id_and_len = 1;
98 int print_constructed_length = 1;
99 int print_primitive_length = 1;
100 int print_skip_context = 0;
101 int print_skip_tagnum = 1;
102 int print_context_shortcut = 0;
103 int do_hex = 0;
104 #ifdef KRB5
105 int print_krb5_types = 0;
106 #endif
107 
108 int current_appl_type = -1;
109 
110 int decode_len (FILE *, unsigned char *, int);
111 int do_prim (FILE *, int, unsigned char *, int, int);
112 int do_cons (FILE *, unsigned char *, int, int, int *);
113 int do_prim_bitstring (FILE *, int, unsigned char *, int, int);
114 int do_prim_int (FILE *, int, unsigned char *, int, int);
115 int do_prim_string (FILE *, int, unsigned char *, int, int);
116 void print_tag_type (FILE *, int, int);
117 int trval (FILE *, FILE *);
118 int trval2 (FILE *, unsigned char *, int, int, int *);
119 
120 
121 /****************************************************************************/
122 
convert_nibble(int ch)123 static int convert_nibble(int ch)
124 {
125     if (isdigit(ch))
126         return (ch - '0');
127     if (ch >= 'a' && ch <= 'f')
128         return (ch - 'a' + 10);
129     if (ch >= 'A' && ch <= 'F')
130         return (ch - 'A' + 10);
131     return -1;
132 }
133 
trval(fin,fout)134 int trval(fin, fout)
135     FILE        *fin;
136     FILE        *fout;
137 {
138     unsigned char *p;
139     unsigned int maxlen;
140     int len;
141     int cc, cc2, n1, n2;
142     int r;
143     int rlen;
144 
145     maxlen = BUFSIZ;
146     p = (unsigned char *)malloc(maxlen);
147     len = 0;
148     while ((cc = fgetc(fin)) != EOF) {
149         if ((unsigned int) len == maxlen) {
150             maxlen += BUFSIZ;
151             p = (unsigned char *)realloc(p, maxlen);
152         }
153         if (do_hex) {
154             if (cc == ' ' || cc == '\n' || cc == '\t')
155                 continue;
156             cc2 = fgetc(fin);
157             if (cc2 == EOF)
158                 break;
159             n1 = convert_nibble(cc);
160             n2 = convert_nibble(cc2);
161             cc = (n1 << 4) + n2;
162         }
163         p[len++] = cc;
164     }
165     fprintf(fout, "<%d>", len);
166     r = trval2(fout, p, len, 0, &rlen);
167     fprintf(fout, "\n");
168     (void) free(p);
169     return(r);
170 }
171 
trval2(fp,enc,len,lev,rlen)172 int trval2(fp, enc, len, lev, rlen)
173     FILE *fp;
174     unsigned char *enc;
175     int len;
176     int lev;
177     int *rlen;
178 {
179     int l, eid, elen, xlen, r, rlen2 = 0;
180     int rlen_ext = 0;
181 
182     r = OK;
183     *rlen = -1;
184 
185     if (len < 2) {
186         fprintf(fp, "missing id and length octets (%d)\n", len);
187         return(NOTOK);
188     }
189 
190     fprintf(fp, "\n");
191     for (l=0; l<lev; l++) fprintf(fp, ".  ");
192 
193 context_restart:
194     eid = enc[0];
195     elen = enc[1];
196 
197     if (print_id_and_len) {
198         fprintf(fp, "%02x ", eid);
199         fprintf(fp, "%02x ", elen);
200     }
201 
202     if (elen == LEN_XTND) {
203         fprintf(fp,
204                 "indefinite length encoding not implemented (0x%02x)\n", elen);
205         return(NOTOK);
206     }
207 
208     xlen = 0;
209     if (elen & LEN_XTND) {
210         xlen = elen & LEN_MASK;
211         if (xlen > len - 2) {
212             fprintf(fp, "extended length too long (%d > %d - 2)\n", xlen, len);
213             return(NOTOK);
214         }
215         elen = decode_len(fp, enc+2, xlen);
216     }
217 
218     if (elen > len - 2 - xlen) {
219         fprintf(fp, "length too long (%d > %d - 2 - %d)\n", elen, len, xlen);
220         return(NOTOK);
221     }
222 
223     print_tag_type(fp, eid, lev);
224 
225     if (print_context_shortcut && (eid & ID_CLASS) == CLASS_CONT &&
226         (eid & ID_FORM) == FORM_CONS && lev > 0) {
227         rlen_ext += 2 + xlen;
228         enc += 2 + xlen;
229         fprintf(fp, " ");
230         goto context_restart;
231     }
232 
233     switch(eid & ID_FORM) {
234     case FORM_PRIM:
235         r = do_prim(fp, eid & ID_TAG, enc+2+xlen, elen, lev+1);
236         *rlen = 2 + xlen + elen + rlen_ext;
237         break;
238     case FORM_CONS:
239         if (print_constructed_length) {
240             fprintf(fp, " constr");
241             fprintf(fp, " <%d>", elen);
242         }
243         r = do_cons(fp, enc+2+xlen, elen, lev+1, &rlen2);
244         *rlen = 2 + xlen + rlen2 + rlen_ext;
245         break;
246     }
247 
248     return(r);
249 }
250 
decode_len(fp,enc,len)251 int decode_len(fp, enc, len)
252     FILE *fp;
253     unsigned char *enc;
254     int len;
255 {
256     int rlen;
257     int i;
258 
259     if (print_id_and_len)
260         fprintf(fp, "%02x ", enc[0]);
261     rlen = enc[0];
262     for (i=1; i<len; i++) {
263         if (print_id_and_len)
264             fprintf(fp, "%02x ", enc[i]);
265         rlen = (rlen * 0x100) + enc[i];
266     }
267     return(rlen);
268 }
269 
270 /*
271  * This is the printing function for bit strings
272  */
do_prim_bitstring(fp,tag,enc,len,lev)273 int do_prim_bitstring(fp, tag, enc, len, lev)
274     FILE *fp;
275     int tag;
276     unsigned char *enc;
277     int len;
278     int lev;
279 {
280     int i;
281     long        num = 0;
282 
283     if (tag != PRIM_BITS || len > 5)
284         return 0;
285 
286     for (i=1; i < len; i++) {
287         num = num << 8;
288         num += enc[i];
289     }
290 
291     fprintf(fp, " 0x%lx", num);
292     if (enc[0])
293         fprintf(fp, " (%d unused bits)", enc[0]);
294     return 1;
295 }
296 
297 /*
298  * This is the printing function for integers
299  */
do_prim_int(fp,tag,enc,len,lev)300 int do_prim_int(fp, tag, enc, len, lev)
301     FILE *fp;
302     int tag;
303     unsigned char *enc;
304     int len;
305     int lev;
306 {
307     int i;
308     long        num = 0;
309 
310     if (tag != PRIM_INT || len > 4)
311         return 0;
312 
313     if (enc[0] & 0x80)
314         num = -1;
315 
316     for (i=0; i < len; i++) {
317         num = num << 8;
318         num += enc[i];
319     }
320 
321     fprintf(fp, " %ld", num);
322     return 1;
323 }
324 
325 
326 /*
327  * This is the printing function which we use if it's a string or
328  * other other type which is best printed as a string
329  */
do_prim_string(fp,tag,enc,len,lev)330 int do_prim_string(fp, tag, enc, len, lev)
331     FILE *fp;
332     int tag;
333     unsigned char *enc;
334     int len;
335     int lev;
336 {
337     int i;
338 
339     /*
340      * Only try this printing function with "reasonable" types
341      */
342     if ((tag < DEFN_NUMS) && (tag != PRIM_OCTS))
343         return 0;
344 
345     for (i=0; i < len; i++)
346         if (!isprint(enc[i]))
347             return 0;
348     fprintf(fp, " \"%.*s\"", len, enc);
349     return 1;
350 }
351 
do_prim(fp,tag,enc,len,lev)352 int do_prim(fp, tag, enc, len, lev)
353     FILE *fp;
354     int tag;
355     unsigned char *enc;
356     int len;
357     int lev;
358 {
359     int n;
360     int i;
361     int j;
362     int width;
363 
364     if (do_prim_string(fp, tag, enc, len, lev))
365         return OK;
366     if (do_prim_int(fp, tag, enc, len, lev))
367         return OK;
368     if (do_prim_bitstring(fp, tag, enc, len, lev))
369         return OK;
370 
371     if (print_primitive_length)
372         fprintf(fp, " <%d>", len);
373 
374     width = (80 - (lev * 3) - 8) / 4;
375 
376     for (n = 0; n < len; n++) {
377         if ((n % width) == 0) {
378             fprintf(fp, "\n");
379             for (i=0; i<lev; i++) fprintf(fp, "   ");
380         }
381         fprintf(fp, "%02x ", enc[n]);
382         if ((n % width) == (width-1)) {
383             fprintf(fp, "    ");
384             for (i=n-(width-1); i<=n; i++)
385                 if (isprint(enc[i])) fprintf(fp, "%c", enc[i]);
386                 else fprintf(fp, ".");
387         }
388     }
389     if ((j = (n % width)) != 0) {
390         fprintf(fp, "    ");
391         for (i=0; i<width-j; i++) fprintf(fp, "   ");
392         for (i=n-j; i<n; i++)
393             if (isprint(enc[i])) fprintf(fp, "%c", enc[i]);
394             else fprintf(fp, ".");
395     }
396     return(OK);
397 }
398 
do_cons(fp,enc,len,lev,rlen)399 int do_cons(fp, enc, len, lev, rlen)
400     FILE *fp;
401     unsigned char *enc;
402     int len;
403     int lev;
404     int *rlen;
405 {
406     int n;
407     int r = 0;
408     int rlen2;
409     int rlent;
410     int save_appl;
411 
412     save_appl = current_appl_type;
413     for (n = 0, rlent = 0; n < len; n+=rlen2, rlent+=rlen2) {
414         r = trval2(fp, enc+n, len-n, lev, &rlen2);
415         current_appl_type = save_appl;
416         if (r != OK) return(r);
417     }
418     if (rlent != len) {
419         fprintf(fp, "inconsistent constructed lengths (%d != %d)\n",
420                 rlent, len);
421         return(NOTOK);
422     }
423     *rlen = rlent;
424     return(r);
425 }
426 
427 struct typestring_table {
428     int k1, k2;
429     char        *str;
430     int new_appl;
431 };
432 
lookup_typestring(table,key1,key2)433 static char *lookup_typestring(table, key1, key2)
434     struct typestring_table *table;
435     int key1, key2;
436 {
437     struct typestring_table *ent;
438 
439     for (ent = table; ent->k1 > 0; ent++) {
440         if ((ent->k1 == key1) &&
441             (ent->k2 == key2)) {
442             if (ent->new_appl)
443                 current_appl_type = ent->new_appl;
444             return ent->str;
445         }
446     }
447     return 0;
448 }
449 
450 
451 struct typestring_table univ_types[] = {
452     { PRIM_BOOL, -1, "Boolean"},
453     { PRIM_INT, -1, "Integer"},
454     { PRIM_BITS, -1, "Bit String"},
455     { PRIM_OCTS, -1, "Octet String"},
456     { PRIM_NULL, -1, "Null"},
457     { PRIM_OID, -1, "Object Identifier"},
458     { PRIM_ODE, -1, "Object Descriptor"},
459     { CONS_EXTN, -1, "External"},
460     { PRIM_REAL, -1, "Real"},
461     { PRIM_ENUM, -1, "Enumerated type"},
462     { PRIM_ENCR, -1, "Encrypted"},
463     { CONS_SEQ, -1, "Sequence/Sequence Of"},
464     { CONS_SET, -1, "Set/Set Of"},
465     { DEFN_NUMS, -1, "Numeric String"},
466     { DEFN_PRTS, -1, "Printable String"},
467     { DEFN_T61S, -1, "T.61 String"},
468     { DEFN_VTXS, -1, "Videotex String"},
469     { DEFN_IA5S, -1, "IA5 String"},
470     { DEFN_UTCT, -1, "UTCTime"},
471     { DEFN_GENT, -1, "Generalized Time"},
472     { DEFN_GFXS, -1, "Graphics string (ISO2375)"},
473     { DEFN_VISS, -1, "Visible string"},
474     { DEFN_GENS, -1, "General string"},
475     { DEFN_CHRS, -1, "Character string"},
476     { -1, -1, 0}
477 };
478 
479 #ifdef KRB5
480 struct typestring_table krb5_types[] = {
481     { 1, -1, "Krb5 Ticket"},
482     { 2, -1, "Krb5 Authenticator"},
483     { 3, -1, "Krb5 Encrypted ticket part"},
484     { 10, -1, "Krb5 AS-REQ packet"},
485     { 11, -1, "Krb5 AS-REP packet"},
486     { 12, -1, "Krb5 TGS-REQ packet"},
487     { 13, -1, "Krb5 TGS-REP packet"},
488     { 14, -1, "Krb5 AP-REQ packet"},
489     { 15, -1, "Krb5 AP-REP packet"},
490     { 20, -1, "Krb5 SAFE packet"},
491     { 21, -1, "Krb5 PRIV packet"},
492     { 22, -1, "Krb5 CRED packet"},
493     { 30, -1, "Krb5 ERROR packet"},
494     { 25, -1, "Krb5 Encrypted AS-REP part"},
495     { 26, -1, "Krb5 Encrypted TGS-REP part"},
496     { 27, -1, "Krb5 Encrypted AP-REP part"},
497     { 28, -1, "Krb5 Encrypted PRIV part"},
498     { 29, -1, "Krb5 Encrypted CRED part"},
499     { -1, -1, 0}
500 };
501 
502 struct typestring_table krb5_fields[] = {
503     { 1000, 0, "name-type"}, /* PrincipalName */
504     { 1000, 1, "name-string"},
505 
506     { 1001, 0, "etype"},        /* Encrypted data */
507     { 1001, 1, "kvno"},
508     { 1001, 2, "cipher"},
509 
510     { 1002, 0, "addr-type"},    /* HostAddress */
511     { 1002, 1, "address"},
512 
513     { 1003, 0, "addr-type"},    /* HostAddresses */
514     { 1003, 1, "address"},
515 
516     { 1004, 0, "ad-type"},      /* AuthorizationData */
517     { 1004, 1, "ad-data"},
518 
519     { 1005, 0, "keytype"},      /* EncryptionKey */
520     { 1005, 1, "keyvalue"},
521 
522     { 1006, 0, "cksumtype"},    /* Checksum */
523     { 1006, 1, "checksum"},
524 
525     { 1007, 0, "kdc-options"},  /* KDC-REQ-BODY */
526     { 1007, 1, "cname", 1000},
527     { 1007, 2, "realm"},
528     { 1007, 3, "sname", 1000},
529     { 1007, 4, "from"},
530     { 1007, 5, "till"},
531     { 1007, 6, "rtime"},
532     { 1007, 7, "nonce"},
533     { 1007, 8, "etype"},
534     { 1007, 9, "addresses", 1003},
535     { 1007, 10, "enc-authorization-data", 1001},
536     { 1007, 11, "additional-tickets"},
537 
538     { 1008, 1, "padata-type"},  /* PA-DATA */
539     { 1008, 2, "pa-data"},
540 
541     { 1009, 0, "user-data"},    /* KRB-SAFE-BODY */
542     { 1009, 1, "timestamp"},
543     { 1009, 2, "usec"},
544     { 1009, 3, "seq-number"},
545     { 1009, 4, "s-address", 1002},
546     { 1009, 5, "r-address", 1002},
547 
548     { 1010, 0, "lr-type"},      /* LastReq */
549     { 1010, 1, "lr-value"},
550 
551     { 1011, 0, "key", 1005},    /* KRB-CRED-INFO */
552     { 1011, 1, "prealm"},
553     { 1011, 2, "pname", 1000},
554     { 1011, 3, "flags"},
555     { 1011, 4, "authtime"},
556     { 1011, 5, "startime"},
557     { 1011, 6, "endtime"},
558     { 1011, 7, "renew-till"},
559     { 1011, 8, "srealm"},
560     { 1011, 9, "sname", 1000},
561     { 1011, 10, "caddr", 1002},
562 
563     { 1, 0, "tkt-vno"}, /* Ticket */
564     { 1, 1, "realm"},
565     { 1, 2, "sname", 1000},
566     { 1, 3, "tkt-enc-part", 1001},
567 
568     { 2, 0, "authenticator-vno"}, /* Authenticator */
569     { 2, 1, "crealm"},
570     { 2, 2, "cname", 1000},
571     { 2, 3, "cksum", 1006},
572     { 2, 4, "cusec"},
573     { 2, 5, "ctime"},
574     { 2, 6, "subkey", 1005},
575     { 2, 7, "seq-number"},
576     { 2, 8, "authorization-data", 1004},
577 
578     { 3, 0, "flags"}, /* EncTicketPart */
579     { 3, 1, "key", 1005},
580     { 3, 2, "crealm"},
581     { 3, 3, "cname", 1000},
582     { 3, 4, "transited"},
583     { 3, 5, "authtime"},
584     { 3, 6, "starttime"},
585     { 3, 7, "endtime"},
586     { 3, 8, "renew-till"},
587     { 3, 9, "caddr", 1003},
588     { 3, 10, "authorization-data", 1004},
589 
590     { 10, 1, "pvno"},   /* AS-REQ */
591     { 10, 2, "msg-type"},
592     { 10, 3, "padata", 1008},
593     { 10, 4, "req-body", 1007},
594 
595     { 11, 0, "pvno"},   /* AS-REP */
596     { 11, 1, "msg-type"},
597     { 11, 2, "padata", 1008},
598     { 11, 3, "crealm"},
599     { 11, 4, "cname", 1000},
600     { 11, 5, "ticket"},
601     { 11, 6, "enc-part", 1001},
602 
603     { 12, 1, "pvno"},   /* TGS-REQ */
604     { 12, 2, "msg-type"},
605     { 12, 3, "padata", 1008},
606     { 12, 4, "req-body", 1007},
607 
608     { 13, 0, "pvno"},   /* TGS-REP */
609     { 13, 1, "msg-type"},
610     { 13, 2, "padata", 1008},
611     { 13, 3, "crealm"},
612     { 13, 4, "cname", 1000},
613     { 13, 5, "ticket"},
614     { 13, 6, "enc-part", 1001},
615 
616     { 14, 0, "pvno"},   /* AP-REQ */
617     { 14, 1, "msg-type"},
618     { 14, 2, "ap-options"},
619     { 14, 3, "ticket"},
620     { 14, 4, "authenticator", 1001},
621 
622     { 15, 0, "pvno"},   /* AP-REP */
623     { 15, 1, "msg-type"},
624     { 15, 2, "enc-part", 1001},
625 
626     { 20, 0, "pvno"},   /* KRB-SAFE */
627     { 20, 1, "msg-type"},
628     { 20, 2, "safe-body", 1009},
629     { 20, 3, "cksum", 1006},
630 
631     { 21, 0, "pvno"},   /* KRB-PRIV */
632     { 21, 1, "msg-type"},
633     { 21, 2, "enc-part", 1001},
634 
635     { 22, 0, "pvno"},   /* KRB-CRED */
636     { 22, 1, "msg-type"},
637     { 22, 2, "tickets"},
638     { 22, 3, "enc-part", 1001},
639 
640     { 25, 0, "key", 1005},      /* EncASRepPart */
641     { 25, 1, "last-req", 1010},
642     { 25, 2, "nonce"},
643     { 25, 3, "key-expiration"},
644     { 25, 4, "flags"},
645     { 25, 5, "authtime"},
646     { 25, 6, "starttime"},
647     { 25, 7, "enddtime"},
648     { 25, 8, "renew-till"},
649     { 25, 9, "srealm"},
650     { 25, 10, "sname", 1000},
651     { 25, 11, "caddr", 1003},
652 
653     { 26, 0, "key", 1005},      /* EncTGSRepPart */
654     { 26, 1, "last-req", 1010},
655     { 26, 2, "nonce"},
656     { 26, 3, "key-expiration"},
657     { 26, 4, "flags"},
658     { 26, 5, "authtime"},
659     { 26, 6, "starttime"},
660     { 26, 7, "enddtime"},
661     { 26, 8, "renew-till"},
662     { 26, 9, "srealm"},
663     { 26, 10, "sname", 1000},
664     { 26, 11, "caddr", 1003},
665 
666     { 27, 0, "ctime"},  /* EncApRepPart */
667     { 27, 1, "cusec"},
668     { 27, 2, "subkey", 1005},
669     { 27, 3, "seq-number"},
670 
671     { 28, 0, "user-data"},      /* EncKrbPrivPart */
672     { 28, 1, "timestamp"},
673     { 28, 2, "usec"},
674     { 28, 3, "seq-number"},
675     { 28, 4, "s-address", 1002},
676     { 28, 5, "r-address", 1002},
677 
678     { 29, 0, "ticket-info", 1011},      /* EncKrbCredPart */
679     { 29, 1, "nonce"},
680     { 29, 2, "timestamp"},
681     { 29, 3, "usec"},
682     { 29, 4, "s-address", 1002},
683     { 29, 5, "r-address", 1002},
684 
685     { 30, 0, "pvno"},   /* KRB-ERROR */
686     { 30, 1, "msg-type"},
687     { 30, 2, "ctime"},
688     { 30, 3, "cusec"},
689     { 30, 4, "stime"},
690     { 30, 5, "susec"},
691     { 30, 6, "error-code"},
692     { 30, 7, "crealm"},
693     { 30, 8, "cname", 1000},
694     { 30, 9, "realm"},
695     { 30, 10, "sname", 1000},
696     { 30, 11, "e-text"},
697     { 30, 12, "e-data"},
698 
699     { -1, -1, 0}
700 };
701 #endif
702 
print_tag_type(fp,eid,lev)703 void print_tag_type(fp, eid, lev)
704     FILE *fp;
705     int     eid;
706     int     lev;
707 {
708     int tag = eid & ID_TAG;
709     int do_space = 1;
710     char        *str;
711 
712     fprintf(fp, "[");
713 
714     switch(eid & ID_CLASS) {
715     case CLASS_UNIV:
716         if (print_types && print_skip_tagnum)
717             do_space = 0;
718         else
719             fprintf(fp, "UNIV %d", tag);
720         break;
721     case CLASS_APPL:
722         current_appl_type = tag;
723 #ifdef KRB5
724         if (print_krb5_types) {
725             str = lookup_typestring(krb5_types, tag, -1);
726             if (str) {
727                 fputs(str, fp);
728                 break;
729             }
730         }
731 #endif
732         fprintf(fp, "APPL %d", tag);
733         break;
734     case CLASS_CONT:
735 #ifdef KRB5
736         if (print_krb5_types && current_appl_type) {
737             str = lookup_typestring(krb5_fields,
738                                     current_appl_type, tag);
739             if (str) {
740                 fputs(str, fp);
741                 break;
742             }
743         }
744 #endif
745         if (print_skip_context && lev)
746             fprintf(fp, "%d", tag);
747         else
748             fprintf(fp, "CONT %d", tag);
749         break;
750     case CLASS_PRIV:
751         fprintf(fp, "PRIV %d", tag);
752         break;
753     }
754 
755     if (print_types && ((eid & ID_CLASS) == CLASS_UNIV)) {
756         if (do_space)
757             fputs(" ", fp);
758         str = lookup_typestring(univ_types, eid & ID_TAG, -1);
759         if (str)
760             fputs(str, fp);
761         else
762             fprintf(fp, "UNIV %d???", eid & ID_TAG);
763     }
764 
765     fprintf(fp, "]");
766 
767 }
768 
769 /*****************************************************************************/
770