1 /* encticketpart.c --- Encrypted ticket part handling.
2 * Copyright (C) 2002, 2003, 2004, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful, but
12 * 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, see http://www.gnu.org/licenses or write
18 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 * Floor, Boston, MA 02110-1301, USA
26 shishi_encticketpart (Shishi
* handle
)
31 node
= shishi_asn1_encticketpart (handle
);
33 res
= shishi_asn1_write (handle
, node
, "starttime", NULL
, 0);
36 shishi_asn1_done (handle
, node
);
40 res
= shishi_asn1_write (handle
, node
, "renew-till", NULL
, 0);
43 shishi_asn1_done (handle
, node
);
47 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
50 shishi_asn1_done (handle
, node
);
54 res
= shishi_asn1_write (handle
, node
, "authorization-data", NULL
, 0);
57 shishi_asn1_done (handle
, node
);
61 res
= shishi_encticketpart_flags_set (handle
, node
, 0);
64 shishi_asn1_done (handle
, node
);
72 * shishi_encticketpart_get_key:
73 * @handle: shishi handle as allocated by shishi_init().
74 * @encticketpart: input EncTicketPart variable.
75 * @key: newly allocated key.
77 * Extract the session key in the Ticket.
79 * Return value: Returns SHISHI_OK iff succesful.
82 shishi_encticketpart_get_key (Shishi
* handle
,
83 Shishi_asn1 encticketpart
, Shishi_key
** key
)
90 res
= shishi_asn1_read_int32 (handle
, encticketpart
,
91 "key.keytype", &keytype
);
95 res
= shishi_asn1_read (handle
, encticketpart
, "key.keyvalue",
100 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
102 if (res
!= SHISHI_OK
)
109 * shishi_encticketpart_key_set:
110 * @handle: shishi handle as allocated by shishi_init().
111 * @encticketpart: input EncTicketPart variable.
112 * @key: key handle with information to store in encticketpart.
114 * Set the EncTicketPart.key field to key type and value of supplied
117 * Return value: Returns SHISHI_OK iff succesful.
120 shishi_encticketpart_key_set (Shishi
* handle
,
121 Shishi_asn1 encticketpart
, Shishi_key
* key
)
126 keytype
= shishi_key_type (key
);
127 res
= shishi_asn1_write_uint32 (handle
, encticketpart
,
128 "key.keytype", keytype
);
129 if (res
!= SHISHI_OK
)
132 res
= shishi_asn1_write (handle
, encticketpart
, "key.keyvalue",
133 shishi_key_value (key
), shishi_key_length (key
));
134 if (res
!= SHISHI_OK
)
141 * shishi_encticketpart_flags_set:
142 * @handle: shishi handle as allocated by shishi_init().
143 * @encticketpart: input EncTicketPart variable.
144 * @flags: flags to set in encticketpart.
146 * Set the EncTicketPart.flags to supplied value.
148 * Return value: Returns SHISHI_OK iff succesful.
151 shishi_encticketpart_flags_set (Shishi
* handle
,
152 Shishi_asn1 encticketpart
, int flags
)
156 res
= shishi_asn1_write_bitstring (handle
, encticketpart
, "flags", flags
);
157 if (res
!= SHISHI_OK
)
164 shishi_encticketpart_crealm (Shishi
* handle
,
165 Shishi_asn1 encticketpart
,
166 char **crealm
, size_t * crealmlen
)
168 return shishi_asn1_read (handle
, encticketpart
, "crealm",
173 * shishi_encticketpart_crealm_set:
174 * @handle: shishi handle as allocated by shishi_init().
175 * @encticketpart: input EncTicketPart variable.
176 * @realm: input array with name of realm.
178 * Set the realm field in the KDC-REQ.
180 * Return value: Returns SHISHI_OK iff successful.
183 shishi_encticketpart_crealm_set (Shishi
* handle
,
184 Shishi_asn1 encticketpart
, const char *realm
)
188 res
= shishi_asn1_write (handle
, encticketpart
, "crealm", realm
, 0);
189 if (res
!= SHISHI_OK
)
196 * shishi_encticketpart_cname_set:
197 * @handle: shishi handle as allocated by shishi_init().
198 * @encticketpart: input EncTicketPart variable.
199 * @name_type: type of principial, see Shishi_name_type, usually
201 * @principal: input array with principal name.
203 * Set the client name field in the EncTicketPart.
205 * Return value: Returns SHISHI_OK iff successful.
208 shishi_encticketpart_cname_set (Shishi
* handle
,
209 Shishi_asn1 encticketpart
,
210 Shishi_name_type name_type
,
211 const char *principal
)
215 res
= shishi_asn1_write_uint32 (handle
, encticketpart
,
216 "cname.name-type", name_type
);
217 if (res
!= SHISHI_OK
)
220 res
= shishi_asn1_write (handle
, encticketpart
,
221 "cname.name-string", NULL
, 0);
222 if (res
!= SHISHI_OK
)
225 res
= shishi_asn1_write (handle
, encticketpart
,
226 "cname.name-string", "NEW", 1);
227 if (res
!= SHISHI_OK
)
230 res
= shishi_asn1_write (handle
, encticketpart
,
231 "cname.name-string.?1",
232 principal
, strlen (principal
));
233 if (res
!= SHISHI_OK
)
240 * shishi_encticketpart_transited_set:
241 * @handle: shishi handle as allocated by shishi_init().
242 * @encticketpart: input EncTicketPart variable.
243 * @trtype: transitedencoding type, e.g. SHISHI_TR_DOMAIN_X500_COMPRESS.
244 * @trdata: actual transited realm data.
245 * @trdatalen: length of actual transited realm data.
247 * Set the EncTicketPart.transited field to supplied value.
249 * Return value: Returns SHISHI_OK iff succesful.
252 shishi_encticketpart_transited_set (Shishi
* handle
,
253 Shishi_asn1 encticketpart
,
255 const char *trdata
, size_t trdatalen
)
259 res
= shishi_asn1_write_int32 (handle
, encticketpart
,
260 "transited.tr-type", trtype
);
261 if (res
!= SHISHI_OK
)
264 res
= shishi_asn1_write (handle
, encticketpart
,
265 "transited.contents", trdata
, trdatalen
);
266 if (res
!= SHISHI_OK
)
273 * shishi_encticketpart_authtime_set:
274 * @handle: shishi handle as allocated by shishi_init().
275 * @encticketpart: input EncTicketPart variable.
276 * @authtime: character buffer containing a generalized time string.
278 * Set the EncTicketPart.authtime to supplied value.
280 * Return value: Returns SHISHI_OK iff succesful.
283 shishi_encticketpart_authtime_set (Shishi
* handle
,
284 Shishi_asn1 encticketpart
,
285 const char *authtime
)
289 res
= shishi_asn1_write (handle
, encticketpart
, "authtime",
290 authtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
291 if (res
!= SHISHI_OK
)
292 return SHISHI_ASN1_ERROR
;
298 * shishi_encticketpart_endtime_set:
299 * @handle: shishi handle as allocated by shishi_init().
300 * @encticketpart: input EncTicketPart variable.
301 * @endtime: character buffer containing a generalized time string.
303 * Set the EncTicketPart.endtime to supplied value.
305 * Return value: Returns SHISHI_OK iff succesful.
308 shishi_encticketpart_endtime_set (Shishi
* handle
,
309 Shishi_asn1 encticketpart
,
314 res
= shishi_asn1_write (handle
, encticketpart
, "endtime",
315 endtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
316 if (res
!= SHISHI_OK
)
323 shishi_encticketpart_authtime (Shishi
* handle
,
324 Shishi_asn1 encticketpart
,
325 char *authtime
, size_t * authtimelen
)
327 return shishi_asn1_read_inline (handle
, encticketpart
, "authtime",
328 authtime
, authtimelen
);
332 shishi_encticketpart_authctime (Shishi
* handle
, Shishi_asn1 encticketpart
)
334 char authtime
[SHISHI_GENERALIZEDTIME_LENGTH
+ 1];
339 authtimelen
= sizeof (authtime
);
340 res
= shishi_encticketpart_authtime (handle
, encticketpart
,
341 authtime
, &authtimelen
);
342 if (res
!= SHISHI_OK
)
345 authtime
[SHISHI_GENERALIZEDTIME_LENGTH
] = '\0';
347 t
= shishi_generalize_ctime (handle
, authtime
);
353 * shishi_encticketpart_client:
354 * @handle: Shishi library handle create by shishi_init().
355 * @encticketpart: EncTicketPart variable to get client name from.
356 * @client: pointer to newly allocated zero terminated string containing
357 * principal name. May be %NULL (to only populate @clientlen).
358 * @clientlen: pointer to length of @client on output, excluding terminating
359 * zero. May be %NULL (to only populate @client).
361 * Represent client principal name in EncTicketPart as zero-terminated
362 * string. The string is allocate by this function, and it is the
363 * responsibility of the caller to deallocate it. Note that the
364 * output length @clientlen does not include the terminating zero.
366 * Return value: Returns SHISHI_OK iff successful.
369 shishi_encticketpart_client (Shishi
* handle
,
370 Shishi_asn1 encticketpart
,
371 char **client
, size_t * clientlen
)
373 return shishi_principal_name (handle
, encticketpart
, "cname",
378 * shishi_encticketpart_clientrealm:
379 * @handle: Shishi library handle create by shishi_init().
380 * @encticketpart: EncTicketPart variable to get client name and realm from.
381 * @client: pointer to newly allocated zero terminated string containing
382 * principal name and realm. May be %NULL (to only populate @clientlen).
383 * @clientlen: pointer to length of @client on output, excluding terminating
384 * zero. May be %NULL (to only populate @client).
386 * Convert cname and realm fields from EncTicketPart to printable
387 * principal name format. The string is allocate by this function,
388 * and it is the responsibility of the caller to deallocate it. Note
389 * that the output length @clientlen does not include the terminating
392 * Return value: Returns SHISHI_OK iff successful.
395 shishi_encticketpart_clientrealm (Shishi
* handle
,
396 Shishi_asn1 encticketpart
,
397 char **client
, size_t * clientlen
)
399 return shishi_principal_name_realm (handle
,
400 encticketpart
, "cname",
401 encticketpart
, "crealm",