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