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",
57 shishi_asn1_done (handle
, node
);
65 * shishi_asn1ticket_get_enc_part_etype:
66 * @handle: shishi handle as allocated by shishi_init().
67 * @kdcrep: Ticket variable to get value from.
68 * @etype: output variable that holds the value.
70 * Extract Ticket.enc-part.etype.
72 * Return value: Returns SHISHI_OK iff successful.
75 shishi_encticketpart_get_enc_part_etype (Shishi
* handle
,
76 Shishi_asn1 encticketpart
,
83 buflen
= sizeof (*etype
);
84 res
= shishi_asn1_field (handle
, encticketpart
, (char *) etype
, &buflen
,
91 * shishi_encticketpart_get_key:
92 * @handle: shishi handle as allocated by shishi_init().
93 * @encticketpart: input EncTicketPart variable.
94 * @keytype: output variable that holds key type.
95 * @keyvalue: output array with key.
96 * @keyvalue_len: on input, maximum size of output array with key,
97 * on output, holds the actual size of output array with key.
99 * Extract the session key in the Ticket.
101 * Return value: Returns SHISHI_OK iff succesful.
104 shishi_encticketpart_get_key (Shishi
* handle
,
105 Shishi_asn1 encticketpart
, Shishi_key
** key
)
112 res
= shishi_asn1_integer_field (handle
, encticketpart
, &keytype
,
114 if (res
!= SHISHI_OK
)
118 res
= shishi_asn1_field (handle
, encticketpart
, buf
, &buflen
,
120 if (res
!= SHISHI_OK
)
123 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
124 if (res
!= SHISHI_OK
)
131 * shishi_encticketpart_key_set:
132 * @handle: shishi handle as allocated by shishi_init().
133 * @encticketpart: input EncTicketPart variable.
134 * @key: key handle with information to store in encticketpart.
136 * Set the EncTicketPart.key field to key type and value of supplied
139 * Return value: Returns SHISHI_OK iff succesful.
142 shishi_encticketpart_key_set (Shishi
* handle
,
143 Shishi_asn1 encticketpart
, Shishi_key
* key
)
149 keytype
= shishi_key_type (key
);
150 sprintf (buf
, "%d", keytype
);
151 res
= shishi_asn1_write (handle
, encticketpart
, "key.keytype",
153 if (res
!= SHISHI_OK
)
156 res
= shishi_asn1_write (handle
, encticketpart
,
158 shishi_key_value (key
), shishi_key_length (key
));
159 if (res
!= SHISHI_OK
)
166 * shishi_encticketpart_flags_set:
167 * @handle: shishi handle as allocated by shishi_init().
168 * @encticketpart: input EncTicketPart variable.
169 * @flags: flags to set in encticketpart.
171 * Set the EncTicketPart.flags to supplied value.
173 * Return value: Returns SHISHI_OK iff succesful.
176 shishi_encticketpart_flags_set (Shishi
* handle
,
177 Shishi_asn1 encticketpart
, int flags
)
182 sprintf (buf
, "%d", flags
);
183 res
= shishi_asn1_write (handle
, encticketpart
, "flags",
185 if (res
!= SHISHI_OK
)
192 * shishi_encticketpart_crealm_set:
193 * @handle: shishi handle as allocated by shishi_init().
194 * @encticketpart: input EncTicketPart variable.
195 * @realm: input array with name of realm.
197 * Set the realm field in the KDC-REQ.
199 * Return value: Returns SHISHI_OK iff successful.
202 shishi_encticketpart_crealm_set (Shishi
* handle
,
203 Shishi_asn1 encticketpart
, const char *realm
)
207 res
= shishi_asn1_write (handle
, encticketpart
, "crealm",
209 if (res
!= SHISHI_OK
)
216 * shishi_encticketpart_cname_set:
217 * @handle: shishi handle as allocated by shishi_init().
218 * @encticketpart: input EncTicketPart variable.
219 * @name_type: type of principial, see Shishi_name_type, usually
221 * @principal: input array with principal name.
223 * Set the client name field in the EncTicketPart.
225 * Return value: Returns SHISHI_OK iff successful.
228 shishi_encticketpart_cname_set (Shishi
* handle
,
229 Shishi_asn1 encticketpart
,
230 Shishi_name_type name_type
,
231 const char *principal
)
236 sprintf (buf
, "%d", name_type
);
238 res
= shishi_asn1_write (handle
, encticketpart
,
239 "cname.name-type", buf
, 0);
240 if (res
!= SHISHI_OK
)
243 res
= shishi_asn1_write (handle
, encticketpart
,
244 "cname.name-string", NULL
, 0);
245 if (res
!= SHISHI_OK
)
248 res
= shishi_asn1_write (handle
, encticketpart
,
249 "cname.name-string", "NEW", 1);
250 if (res
!= SHISHI_OK
)
253 res
= shishi_asn1_write (handle
, encticketpart
,
254 "cname.name-string.?1",
255 principal
, strlen (principal
));
256 if (res
!= SHISHI_OK
)
263 * shishi_encticketpart_transited_set:
264 * @handle: shishi handle as allocated by shishi_init().
265 * @encticketpart: input EncTicketPart variable.
266 * @trtype: transitedencoding type, e.g. SHISHI_TR_DOMAIN_X500_COMPRESS.
267 * @trdata: actual transited realm data.
268 * @trdatalen: length of actual transited realm data.
270 * Set the EncTicketPart.transited field to supplied value.
272 * Return value: Returns SHISHI_OK iff succesful.
275 shishi_encticketpart_transited_set (Shishi
* handle
,
276 Shishi_asn1 encticketpart
,
278 char *trdata
, size_t trdatalen
)
283 sprintf (buf
, "%d", trtype
);
284 res
= shishi_asn1_write (handle
, encticketpart
,
285 "transited.tr-type", buf
, 0);
286 if (res
!= SHISHI_OK
)
289 res
= shishi_asn1_write (handle
, encticketpart
,
290 "transited.contents",
292 if (res
!= SHISHI_OK
)
299 * shishi_encticketpart_authtime_set:
300 * @handle: shishi handle as allocated by shishi_init().
301 * @encticketpart: input EncTicketPart variable.
302 * @authtime: character buffer containing a generalized time string.
304 * Set the EncTicketPart.authtime to supplied value.
306 * Return value: Returns SHISHI_OK iff succesful.
309 shishi_encticketpart_authtime_set (Shishi
* handle
,
310 Shishi_asn1 encticketpart
,
311 const char *authtime
)
315 res
= shishi_asn1_write (handle
, encticketpart
, "authtime",
316 authtime
, GENERALIZEDTIME_TIME_LEN
);
317 if (res
!= SHISHI_OK
)
318 return SHISHI_ASN1_ERROR
;
324 * shishi_encticketpart_endtime_set:
325 * @handle: shishi handle as allocated by shishi_init().
326 * @encticketpart: input EncTicketPart variable.
327 * @endtime: character buffer containing a generalized time string.
329 * Set the EncTicketPart.endtime to supplied value.
331 * Return value: Returns SHISHI_OK iff succesful.
334 shishi_encticketpart_endtime_set (Shishi
* handle
,
335 Shishi_asn1 encticketpart
,
340 res
= shishi_asn1_write (handle
, encticketpart
, "endtime",
341 endtime
, GENERALIZEDTIME_TIME_LEN
);
342 if (res
!= SHISHI_OK
)
349 shishi_encticketpart_authtime (Shishi
* handle
,
350 Shishi_asn1 encticketpart
,
351 char *authtime
, int *authtimelen
)
353 return shishi_asn1_field (handle
, encticketpart
, authtime
, authtimelen
,
358 shishi_encticketpart_authctime (Shishi
* handle
, Shishi_asn1 encticketpart
)
360 char authtime
[GENERALIZEDTIME_TIME_LEN
+ 1];
365 authtimelen
= sizeof (authtime
);
366 res
= shishi_encticketpart_authtime (handle
, encticketpart
,
367 authtime
, &authtimelen
);
368 if (res
!= SHISHI_OK
)
371 authtime
[GENERALIZEDTIME_TIME_LEN
] = '\0';
373 t
= shishi_generalize_ctime (handle
, authtime
);
379 shishi_encticketpart_cname_get (Shishi
* handle
,
380 Shishi_asn1 encticketpart
,
381 char *cname
, int *cnamelen
)
383 return shishi_principal_name_get (handle
, encticketpart
,
384 "cname", cname
, cnamelen
);
388 shishi_encticketpart_cnamerealm_get (Shishi
* handle
,
389 Shishi_asn1 encticketpart
,
390 char *cnamerealm
, int *cnamerealmlen
)
392 return shishi_principal_name_realm_get (handle
, encticketpart
,
396 cnamerealm
, cnamerealmlen
);