1 /* encticketpart.c --- Encrypted ticket part handling.
2 * Copyright (C) 2002, 2003, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
);
60 res
= shishi_encticketpart_flags_set (handle
, node
, 0);
63 shishi_asn1_done (handle
, node
);
71 * shishi_encticketpart_get_key:
72 * @handle: shishi handle as allocated by shishi_init().
73 * @encticketpart: input EncTicketPart variable.
74 * @key: newly allocated key.
76 * Extract the session key in the Ticket.
78 * Return value: Returns SHISHI_OK iff succesful.
81 shishi_encticketpart_get_key (Shishi
* handle
,
82 Shishi_asn1 encticketpart
, Shishi_key
** key
)
89 res
= shishi_asn1_read_int32 (handle
, encticketpart
,
90 "key.keytype", &keytype
);
94 res
= shishi_asn1_read (handle
, encticketpart
, "key.keyvalue",
99 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
101 if (res
!= SHISHI_OK
)
108 * shishi_encticketpart_key_set:
109 * @handle: shishi handle as allocated by shishi_init().
110 * @encticketpart: input EncTicketPart variable.
111 * @key: key handle with information to store in encticketpart.
113 * Set the EncTicketPart.key field to key type and value of supplied
116 * Return value: Returns SHISHI_OK iff succesful.
119 shishi_encticketpart_key_set (Shishi
* handle
,
120 Shishi_asn1 encticketpart
, Shishi_key
* key
)
125 keytype
= shishi_key_type (key
);
126 res
= shishi_asn1_write_uint32 (handle
, encticketpart
,
127 "key.keytype", keytype
);
128 if (res
!= SHISHI_OK
)
131 res
= shishi_asn1_write (handle
, encticketpart
, "key.keyvalue",
132 shishi_key_value (key
), shishi_key_length (key
));
133 if (res
!= SHISHI_OK
)
140 * shishi_encticketpart_flags_set:
141 * @handle: shishi handle as allocated by shishi_init().
142 * @encticketpart: input EncTicketPart variable.
143 * @flags: flags to set in encticketpart.
145 * Set the EncTicketPart.flags to supplied value.
147 * Return value: Returns SHISHI_OK iff succesful.
150 shishi_encticketpart_flags_set (Shishi
* handle
,
151 Shishi_asn1 encticketpart
, int flags
)
155 res
= shishi_asn1_write_bitstring (handle
, encticketpart
, "flags", flags
);
156 if (res
!= SHISHI_OK
)
163 shishi_encticketpart_crealm (Shishi
* handle
,
164 Shishi_asn1 encticketpart
,
165 char **crealm
, size_t * crealmlen
)
167 return shishi_asn1_read (handle
, encticketpart
, "crealm",
172 * shishi_encticketpart_crealm_set:
173 * @handle: shishi handle as allocated by shishi_init().
174 * @encticketpart: input EncTicketPart variable.
175 * @realm: input array with name of realm.
177 * Set the realm field in the KDC-REQ.
179 * Return value: Returns SHISHI_OK iff successful.
182 shishi_encticketpart_crealm_set (Shishi
* handle
,
183 Shishi_asn1 encticketpart
, const char *realm
)
187 res
= shishi_asn1_write (handle
, encticketpart
, "crealm", realm
, 0);
188 if (res
!= SHISHI_OK
)
195 * shishi_encticketpart_cname_set:
196 * @handle: shishi handle as allocated by shishi_init().
197 * @encticketpart: input EncTicketPart variable.
198 * @name_type: type of principial, see Shishi_name_type, usually
200 * @principal: input array with principal name.
202 * Set the client name field in the EncTicketPart.
204 * Return value: Returns SHISHI_OK iff successful.
207 shishi_encticketpart_cname_set (Shishi
* handle
,
208 Shishi_asn1 encticketpart
,
209 Shishi_name_type name_type
,
210 const char *principal
)
214 res
= shishi_asn1_write_uint32 (handle
, encticketpart
,
215 "cname.name-type", name_type
);
216 if (res
!= SHISHI_OK
)
219 res
= shishi_asn1_write (handle
, encticketpart
,
220 "cname.name-string", NULL
, 0);
221 if (res
!= SHISHI_OK
)
224 res
= shishi_asn1_write (handle
, encticketpart
,
225 "cname.name-string", "NEW", 1);
226 if (res
!= SHISHI_OK
)
229 res
= shishi_asn1_write (handle
, encticketpart
,
230 "cname.name-string.?1",
231 principal
, strlen (principal
));
232 if (res
!= SHISHI_OK
)
239 * shishi_encticketpart_transited_set:
240 * @handle: shishi handle as allocated by shishi_init().
241 * @encticketpart: input EncTicketPart variable.
242 * @trtype: transitedencoding type, e.g. SHISHI_TR_DOMAIN_X500_COMPRESS.
243 * @trdata: actual transited realm data.
244 * @trdatalen: length of actual transited realm data.
246 * Set the EncTicketPart.transited field to supplied value.
248 * Return value: Returns SHISHI_OK iff succesful.
251 shishi_encticketpart_transited_set (Shishi
* handle
,
252 Shishi_asn1 encticketpart
,
254 const char *trdata
, size_t trdatalen
)
258 res
= shishi_asn1_write_int32 (handle
, encticketpart
,
259 "transited.tr-type", trtype
);
260 if (res
!= SHISHI_OK
)
263 res
= shishi_asn1_write (handle
, encticketpart
,
264 "transited.contents", trdata
, trdatalen
);
265 if (res
!= SHISHI_OK
)
272 * shishi_encticketpart_authtime_set:
273 * @handle: shishi handle as allocated by shishi_init().
274 * @encticketpart: input EncTicketPart variable.
275 * @authtime: character buffer containing a generalized time string.
277 * Set the EncTicketPart.authtime to supplied value.
279 * Return value: Returns SHISHI_OK iff succesful.
282 shishi_encticketpart_authtime_set (Shishi
* handle
,
283 Shishi_asn1 encticketpart
,
284 const char *authtime
)
288 res
= shishi_asn1_write (handle
, encticketpart
, "authtime",
289 authtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
290 if (res
!= SHISHI_OK
)
291 return SHISHI_ASN1_ERROR
;
297 * shishi_encticketpart_endtime_set:
298 * @handle: shishi handle as allocated by shishi_init().
299 * @encticketpart: input EncTicketPart variable.
300 * @endtime: character buffer containing a generalized time string.
302 * Set the EncTicketPart.endtime to supplied value.
304 * Return value: Returns SHISHI_OK iff succesful.
307 shishi_encticketpart_endtime_set (Shishi
* handle
,
308 Shishi_asn1 encticketpart
,
313 res
= shishi_asn1_write (handle
, encticketpart
, "endtime",
314 endtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
315 if (res
!= SHISHI_OK
)
322 shishi_encticketpart_authtime (Shishi
* handle
,
323 Shishi_asn1 encticketpart
,
324 char *authtime
, size_t * authtimelen
)
326 return shishi_asn1_read_inline (handle
, encticketpart
, "authtime",
327 authtime
, authtimelen
);
331 shishi_encticketpart_authctime (Shishi
* handle
, Shishi_asn1 encticketpart
)
333 char authtime
[SHISHI_GENERALIZEDTIME_LENGTH
+ 1];
338 authtimelen
= sizeof (authtime
);
339 res
= shishi_encticketpart_authtime (handle
, encticketpart
,
340 authtime
, &authtimelen
);
341 if (res
!= SHISHI_OK
)
344 authtime
[SHISHI_GENERALIZEDTIME_LENGTH
] = '\0';
346 t
= shishi_generalize_ctime (handle
, authtime
);
352 * shishi_encticketpart_client:
353 * @handle: Shishi library handle create by shishi_init().
354 * @encticketpart: EncTicketPart variable to get client name from.
355 * @client: pointer to newly allocated zero terminated string containing
356 * principal name. May be %NULL (to only populate @clientlen).
357 * @clientlen: pointer to length of @client on output, excluding terminating
358 * zero. May be %NULL (to only populate @client).
360 * Represent client principal name in EncTicketPart as zero-terminated
361 * string. The string is allocate by this function, and it is the
362 * responsibility of the caller to deallocate it. Note that the
363 * output length @clientlen does not include the terminating zero.
365 * Return value: Returns SHISHI_OK iff successful.
368 shishi_encticketpart_client (Shishi
* handle
,
369 Shishi_asn1 encticketpart
,
370 char **client
, size_t * clientlen
)
372 return shishi_principal_name (handle
, encticketpart
, "cname",
377 * shishi_encticketpart_clientrealm:
378 * @handle: Shishi library handle create by shishi_init().
379 * @encticketpart: EncTicketPart variable to get client name and realm from.
380 * @client: pointer to newly allocated zero terminated string containing
381 * principal name and realm. May be %NULL (to only populate @clientlen).
382 * @clientlen: pointer to length of @client on output, excluding terminating
383 * zero. May be %NULL (to only populate @client).
385 * Convert cname and realm fields from EncTicketPart to printable
386 * principal name format. The string is allocate by this function,
387 * and it is the responsibility of the caller to deallocate it. Note
388 * that the output length @clientlen does not include the terminating
391 * Return value: Returns SHISHI_OK iff successful.
394 shishi_encticketpart_clientrealm (Shishi
* handle
,
395 Shishi_asn1 encticketpart
,
396 char **client
, size_t * clientlen
)
398 return shishi_principal_name_realm (handle
,
399 encticketpart
, "cname",
400 encticketpart
, "crealm",