1 /* encticketpart.c encrypted ticket part handling
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 shishi_encticketpart (Shishi
* handle
)
30 node
= shishi_asn1_encticketpart (handle
);
32 res
= shishi_asn1_write (handle
, node
, "starttime", NULL
, 0);
35 shishi_asn1_done (handle
, node
);
39 res
= shishi_asn1_write (handle
, node
, "renew-till", NULL
, 0);
42 shishi_asn1_done (handle
, node
);
46 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
49 shishi_asn1_done (handle
, node
);
53 res
= shishi_asn1_write (handle
, node
, "authorization-data", NULL
, 0);
56 shishi_asn1_done (handle
, node
);
64 * shishi_asn1ticket_get_enc_part_etype:
65 * @handle: shishi handle as allocated by shishi_init().
66 * @kdcrep: Ticket variable to get value from.
67 * @etype: output variable that holds the value.
69 * Extract Ticket.enc-part.etype.
71 * Return value: Returns SHISHI_OK iff successful.
74 shishi_encticketpart_get_enc_part_etype (Shishi
* handle
,
75 Shishi_asn1 encticketpart
,
80 res
= shishi_asn1_read_int32 (handle
, encticketpart
,
81 "enc-part.etype", etype
);
87 * shishi_encticketpart_get_key:
88 * @handle: shishi handle as allocated by shishi_init().
89 * @encticketpart: input EncTicketPart variable.
90 * @keytype: output variable that holds key type.
91 * @keyvalue: output array with key.
92 * @keyvalue_len: on input, maximum size of output array with key,
93 * on output, holds the actual size of output array with key.
95 * Extract the session key in the Ticket.
97 * Return value: Returns SHISHI_OK iff succesful.
100 shishi_encticketpart_get_key (Shishi
* handle
,
101 Shishi_asn1 encticketpart
, Shishi_key
** key
)
108 res
= shishi_asn1_read_int32 (handle
, encticketpart
,
109 "key.keytype", &keytype
);
110 if (res
!= SHISHI_OK
)
114 res
= shishi_asn1_field (handle
, encticketpart
, buf
, &buflen
,
116 if (res
!= SHISHI_OK
)
119 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
120 if (res
!= SHISHI_OK
)
127 * shishi_encticketpart_key_set:
128 * @handle: shishi handle as allocated by shishi_init().
129 * @encticketpart: input EncTicketPart variable.
130 * @key: key handle with information to store in encticketpart.
132 * Set the EncTicketPart.key field to key type and value of supplied
135 * Return value: Returns SHISHI_OK iff succesful.
138 shishi_encticketpart_key_set (Shishi
* handle
,
139 Shishi_asn1 encticketpart
, Shishi_key
* key
)
145 keytype
= shishi_key_type (key
);
146 sprintf (buf
, "%d", keytype
);
147 res
= shishi_asn1_write (handle
, encticketpart
, "key.keytype", buf
, 0);
148 if (res
!= SHISHI_OK
)
151 res
= shishi_asn1_write (handle
, encticketpart
,
153 shishi_key_value (key
), shishi_key_length (key
));
154 if (res
!= SHISHI_OK
)
161 * shishi_encticketpart_flags_set:
162 * @handle: shishi handle as allocated by shishi_init().
163 * @encticketpart: input EncTicketPart variable.
164 * @flags: flags to set in encticketpart.
166 * Set the EncTicketPart.flags to supplied value.
168 * Return value: Returns SHISHI_OK iff succesful.
171 shishi_encticketpart_flags_set (Shishi
* handle
,
172 Shishi_asn1 encticketpart
, int flags
)
177 sprintf (buf
, "%d", flags
);
178 res
= shishi_asn1_write (handle
, encticketpart
, "flags", buf
, 0);
179 if (res
!= SHISHI_OK
)
186 * shishi_encticketpart_crealm_set:
187 * @handle: shishi handle as allocated by shishi_init().
188 * @encticketpart: input EncTicketPart variable.
189 * @realm: input array with name of realm.
191 * Set the realm field in the KDC-REQ.
193 * Return value: Returns SHISHI_OK iff successful.
196 shishi_encticketpart_crealm_set (Shishi
* handle
,
197 Shishi_asn1 encticketpart
, const char *realm
)
201 res
= shishi_asn1_write (handle
, encticketpart
, "crealm", realm
, 0);
202 if (res
!= SHISHI_OK
)
209 * shishi_encticketpart_cname_set:
210 * @handle: shishi handle as allocated by shishi_init().
211 * @encticketpart: input EncTicketPart variable.
212 * @name_type: type of principial, see Shishi_name_type, usually
214 * @principal: input array with principal name.
216 * Set the client name field in the EncTicketPart.
218 * Return value: Returns SHISHI_OK iff successful.
221 shishi_encticketpart_cname_set (Shishi
* handle
,
222 Shishi_asn1 encticketpart
,
223 Shishi_name_type name_type
,
224 const char *principal
)
229 sprintf (buf
, "%d", name_type
);
231 res
= shishi_asn1_write (handle
, encticketpart
, "cname.name-type", buf
, 0);
232 if (res
!= SHISHI_OK
)
235 res
= shishi_asn1_write (handle
, encticketpart
,
236 "cname.name-string", NULL
, 0);
237 if (res
!= SHISHI_OK
)
240 res
= shishi_asn1_write (handle
, encticketpart
,
241 "cname.name-string", "NEW", 1);
242 if (res
!= SHISHI_OK
)
245 res
= shishi_asn1_write (handle
, encticketpart
,
246 "cname.name-string.?1",
247 principal
, strlen (principal
));
248 if (res
!= SHISHI_OK
)
255 * shishi_encticketpart_transited_set:
256 * @handle: shishi handle as allocated by shishi_init().
257 * @encticketpart: input EncTicketPart variable.
258 * @trtype: transitedencoding type, e.g. SHISHI_TR_DOMAIN_X500_COMPRESS.
259 * @trdata: actual transited realm data.
260 * @trdatalen: length of actual transited realm data.
262 * Set the EncTicketPart.transited field to supplied value.
264 * Return value: Returns SHISHI_OK iff succesful.
267 shishi_encticketpart_transited_set (Shishi
* handle
,
268 Shishi_asn1 encticketpart
,
270 char *trdata
, size_t trdatalen
)
275 sprintf (buf
, "%d", trtype
);
276 res
= shishi_asn1_write (handle
, encticketpart
,
277 "transited.tr-type", buf
, 0);
278 if (res
!= SHISHI_OK
)
281 res
= shishi_asn1_write (handle
, encticketpart
,
282 "transited.contents", trdata
, trdatalen
);
283 if (res
!= SHISHI_OK
)
290 * shishi_encticketpart_authtime_set:
291 * @handle: shishi handle as allocated by shishi_init().
292 * @encticketpart: input EncTicketPart variable.
293 * @authtime: character buffer containing a generalized time string.
295 * Set the EncTicketPart.authtime to supplied value.
297 * Return value: Returns SHISHI_OK iff succesful.
300 shishi_encticketpart_authtime_set (Shishi
* handle
,
301 Shishi_asn1 encticketpart
,
302 const char *authtime
)
306 res
= shishi_asn1_write (handle
, encticketpart
, "authtime",
307 authtime
, GENERALIZEDTIME_TIME_LEN
);
308 if (res
!= SHISHI_OK
)
309 return SHISHI_ASN1_ERROR
;
315 * shishi_encticketpart_endtime_set:
316 * @handle: shishi handle as allocated by shishi_init().
317 * @encticketpart: input EncTicketPart variable.
318 * @endtime: character buffer containing a generalized time string.
320 * Set the EncTicketPart.endtime to supplied value.
322 * Return value: Returns SHISHI_OK iff succesful.
325 shishi_encticketpart_endtime_set (Shishi
* handle
,
326 Shishi_asn1 encticketpart
,
331 res
= shishi_asn1_write (handle
, encticketpart
, "endtime",
332 endtime
, GENERALIZEDTIME_TIME_LEN
);
333 if (res
!= SHISHI_OK
)
340 shishi_encticketpart_authtime (Shishi
* handle
,
341 Shishi_asn1 encticketpart
,
342 char *authtime
, int *authtimelen
)
344 return shishi_asn1_field (handle
, encticketpart
, authtime
, authtimelen
,
349 shishi_encticketpart_authctime (Shishi
* handle
, Shishi_asn1 encticketpart
)
351 char authtime
[GENERALIZEDTIME_TIME_LEN
+ 1];
356 authtimelen
= sizeof (authtime
);
357 res
= shishi_encticketpart_authtime (handle
, encticketpart
,
358 authtime
, &authtimelen
);
359 if (res
!= SHISHI_OK
)
362 authtime
[GENERALIZEDTIME_TIME_LEN
] = '\0';
364 t
= shishi_generalize_ctime (handle
, authtime
);
370 shishi_encticketpart_cname_get (Shishi
* handle
,
371 Shishi_asn1 encticketpart
,
372 char *cname
, int *cnamelen
)
374 return shishi_principal_name_get (handle
, encticketpart
,
375 "cname", cname
, cnamelen
);
379 shishi_encticketpart_cnamerealm_get (Shishi
* handle
,
380 Shishi_asn1 encticketpart
,
381 char *cnamerealm
, int *cnamerealmlen
)
383 return shishi_principal_name_realm_get (handle
, encticketpart
,
387 cnamerealm
, cnamerealmlen
);