4 * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
7 * For copying and distribution information, please see the file
11 #include "mit-copyright.h"
18 #ifdef KRB_CRYPT_DEBUG
23 * This routine takes a ticket and pointers to the variables that
24 * should be filled in based on the information in the ticket. It
26 * decrypts the ticket using the given key, and
28 * fills in values for its arguments.
30 * Note: if the client realm field in the ticket is the null string,
31 * then the "prealm" variable is filled in with the local realm (as
32 * defined by KRB_REALM).
34 * If the ticket byte order is different than the host's byte order
35 * (as indicated by the byte order bit of the "flags" field), then
36 * the KDC timestamp "time_sec" is byte-swapped. The other fields
37 * potentially affected by byte order, "paddress" and "session" are
40 * The routine returns KFAILURE if any of the "pname", "pinstance",
41 * or "prealm" fields is too big, otherwise it returns KSUCCESS.
43 * The corresponding routine to generate tickets is create_ticket.
44 * When changes are made to this routine, the corresponding changes
45 * should also be made to that file.
47 * See create_ticket.c for the format of the ticket packet.
51 decomp_ticket(tkt, flags, pname, pinstance, prealm, paddress, session,
52 life, time_sec, sname, sinstance, key, key_s)
53 KTEXT tkt; /* The ticket to be decoded */
54 unsigned char *flags; /* Kerberos ticket flags */
55 char *pname; /* Authentication name */
56 char *pinstance; /* Principal's instance */
57 char *prealm; /* Principal's authentication domain */
58 unsigned KRB4_32 *paddress; /* Net address of entity
59 * requesting ticket */
60 C_Block session; /* Session key inserted in ticket */
61 int *life; /* Lifetime of the ticket */
62 unsigned KRB4_32 *time_sec; /* Issue time and date */
63 char *sname; /* Service name */
64 char *sinstance; /* Service instance */
65 C_Block key; /* Service's secret key
66 * (to decrypt the ticket) */
67 Key_schedule key_s; /* The precomputed key schedule */
70 dcmp_tkt_int(tkt, flags, pname, pinstance, prealm,
71 paddress, session, life, time_sec, sname, sinstance,
76 decomp_tkt_krb5(tkt, flags, pname, pinstance, prealm, paddress, session,
77 life, time_sec, sname, sinstance, k5key)
78 KTEXT tkt; /* The ticket to be decoded */
79 unsigned char *flags; /* Kerberos ticket flags */
80 char *pname; /* Authentication name */
81 char *pinstance; /* Principal's instance */
82 char *prealm; /* Principal's authentication domain */
83 unsigned KRB4_32 *paddress; /* Net address of entity
84 * requesting ticket */
85 C_Block session; /* Session key inserted in ticket */
86 int *life; /* Lifetime of the ticket */
87 unsigned KRB4_32 *time_sec; /* Issue time and date */
88 char *sname; /* Service name */
89 char *sinstance; /* Service instance */
90 krb5_keyblock *k5key; /* krb5 keyblock of service */
92 C_Block key; /* placeholder; doesn't get used */
93 Key_schedule key_s; /* placeholder; doesn't get used */
96 dcmp_tkt_int(tkt, flags, pname, pinstance, prealm, paddress, session,
97 life, time_sec, sname, sinstance, key, key_s, k5key);
101 dcmp_tkt_int(tkt, flags, pname, pinstance, prealm, paddress, session,
102 life, time_sec, sname, sinstance, key, key_s, k5key)
103 KTEXT tkt; /* The ticket to be decoded */
104 unsigned char *flags; /* Kerberos ticket flags */
105 char *pname; /* Authentication name */
106 char *pinstance; /* Principal's instance */
107 char *prealm; /* Principal's authentication domain */
108 unsigned KRB4_32 *paddress; /* Net address of entity
109 * requesting ticket */
110 C_Block session; /* Session key inserted in ticket */
111 int *life; /* Lifetime of the ticket */
112 unsigned KRB4_32 *time_sec; /* Issue time and date */
113 char *sname; /* Service name */
114 char *sinstance; /* Service instance */
115 C_Block key; /* Service's secret key
116 * (to decrypt the ticket) */
117 Key_schedule key_s; /* The precomputed key schedule */
118 krb5_keyblock *k5key; /* krb5 keyblock of service */
120 static int tkt_swap_bytes;
122 char *ptr = (char *)tkt->dat;
125 /* Do the decryption */
126 #ifdef KRB_CRYPT_DEBUG
129 char *keybuf[BUFSIZ]; /* Avoid secret stuff in stdio buffers */
131 fp = fopen("/kerberos/tkt.des", "wb");
133 fwrite(tkt->dat, 1, tkt->length, fp);
135 memset(keybuf, 0, sizeof(keybuf)); /* Clear the buffer */
144 in.enctype = k5key->enctype;
146 in.ciphertext.length = tkt->length;
147 in.ciphertext.data = tkt->dat;
148 out.length = tkt->length;
149 out.data = malloc(tkt->length);
150 if (out.data == NULL)
151 return KFAILURE; /* XXX maybe ENOMEM? */
153 /* XXX note the following assumes that context arg isn't used */
155 krb5_c_decrypt(NULL, k5key,
156 KRB5_KEYUSAGE_KDC_REP_TICKET, NULL, &in, &out);
161 memcpy(tkt->dat, out.data, out.length);
162 memset(out.data, 0, out.length);
166 pcbc_encrypt((C_Block *)tkt->dat,(C_Block *)tkt->dat,
167 (long) tkt->length,key_s,(C_Block *) key,0);
169 #endif /* ! NOENCRYPTION */
170 #ifdef KRB_CRYPT_DEBUG
173 char *keybuf[BUFSIZ]; /* Avoid secret stuff in stdio buffers */
175 fp = fopen("/kerberos/tkt.clear", "wb");
177 fwrite(tkt->dat, 1, tkt->length, fp);
179 memset(keybuf, 0, sizeof(keybuf)); /* Clear the buffer */
183 *flags = *ptr; /* get flags byte */
184 ptr += sizeof(*flags);
186 if (HOST_BYTE_ORDER != ((*flags >> K_FLAG_ORDER)& 1))
189 if (strlen(ptr) > ANAME_SZ)
191 (void) strcpy(pname,ptr); /* pname */
192 ptr += strlen(pname) + 1;
194 if (strlen(ptr) > INST_SZ)
196 (void) strcpy(pinstance,ptr); /* instance */
197 ptr += strlen(pinstance) + 1;
199 if (strlen(ptr) > REALM_SZ)
201 (void) strcpy(prealm,ptr); /* realm */
202 ptr += strlen(prealm) + 1;
203 /* temporary hack until realms are dealt with properly */
205 (void) strcpy(prealm,KRB_REALM);
207 memcpy((char *)paddress, ptr, 4); /* net address */
210 memcpy((char *)session, ptr, 8); /* session key */
212 #ifdef notdef /* DONT SWAP SESSION KEY spm 10/22/86 */
214 swap_C_Block(session);
217 /* get lifetime, being certain we don't get negative lifetimes */
218 uptr = (unsigned char *) ptr++;
221 memcpy((char *) time_sec, ptr, 4); /* issue time */
224 *time_sec = krb4_swab32(*time_sec);
226 (void) strcpy(sname,ptr); /* service name */
227 ptr += 1 + strlen(sname);
229 (void) strcpy(sinstance,ptr); /* instance */
230 ptr += 1 + strlen(sinstance);
232 #ifdef KRB_CRYPT_DEBUG
234 krb_log("service=%s.%s len(sname)=%d, len(sinstance)=%d",
235 sname, sinstance, strlen(sname), strlen(sinstance));
236 krb_log("ptr - tkt->dat=%d",(char *)ptr - (char *)tkt->dat);