1 /* enckdcreppart.c --- Key distribution encrypted reply part functions
2 * Copyright (C) 2002, 2003, 2004, 2006 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
26 shishi_enckdcreppart (Shishi
* handle
)
31 node
= shishi_asn1_enckdcreppart (handle
);
35 /* XXX remove these two: */
36 res
= shishi_asn1_write (handle
, node
, "key-expiration", NULL
, 0);
40 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
44 res
= shishi_enckdcreppart_flags_set (handle
, node
, 0);
52 shishi_encasreppart (Shishi
* handle
)
57 node
= shishi_asn1_encasreppart (handle
);
61 /* XXX remove these two: */
62 res
= shishi_asn1_write (handle
, node
, "key-expiration", NULL
, 0);
65 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
73 * shishi_enckdcreppart_get_key:
74 * @handle: shishi handle as allocated by shishi_init().
75 * @enckdcreppart: input EncKDCRepPart variable.
76 * @key: newly allocated encryption key handle.
78 * Extract the key to use with the ticket sent in the KDC-REP
79 * associated with the EncKDCRepPart input variable.
81 * Return value: Returns SHISHI_OK iff succesful.
84 shishi_enckdcreppart_get_key (Shishi
* handle
,
85 Shishi_asn1 enckdcreppart
, Shishi_key
** key
)
92 res
= shishi_asn1_read_int32 (handle
, enckdcreppart
,
93 "key.keytype", &keytype
);
97 res
= shishi_asn1_read (handle
, enckdcreppart
, "key.keyvalue",
102 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
104 if (res
!= SHISHI_OK
)
111 * shishi_enckdcreppart_key_set:
112 * @handle: shishi handle as allocated by shishi_init().
113 * @enckdcreppart: input EncKDCRepPart variable.
114 * @key: key handle with information to store in enckdcreppart.
116 * Set the EncKDCRepPart.key field to key type and value of supplied
119 * Return value: Returns SHISHI_OK iff succesful.
122 shishi_enckdcreppart_key_set (Shishi
* handle
,
123 Shishi_asn1 enckdcreppart
, Shishi_key
* key
)
127 res
= shishi_asn1_write_integer (handle
, enckdcreppart
, "key.keytype",
128 shishi_key_type (key
));
129 if (res
!= SHISHI_OK
)
130 return SHISHI_ASN1_ERROR
;
132 res
= shishi_asn1_write (handle
, enckdcreppart
, "key.keyvalue",
133 shishi_key_value (key
), shishi_key_length (key
));
134 if (res
!= SHISHI_OK
)
135 return SHISHI_ASN1_ERROR
;
141 * shishi_enckdcreppart_nonce_set:
142 * @handle: shishi handle as allocated by shishi_init().
143 * @enckdcreppart: input EncKDCRepPart variable.
144 * @nonce: nonce to set in EncKDCRepPart.
146 * Set the EncKDCRepPart.nonce field.
148 * Return value: Returns SHISHI_OK iff succesful.
151 shishi_enckdcreppart_nonce_set (Shishi
* handle
,
152 Shishi_asn1 enckdcreppart
, uint32_t nonce
)
156 res
= shishi_asn1_write_uint32 (handle
, enckdcreppart
, "nonce", nonce
);
157 if (res
!= SHISHI_OK
)
164 * shishi_enckdcreppart_flags_set:
165 * @handle: shishi handle as allocated by shishi_init().
166 * @enckdcreppart: input EncKDCRepPart variable.
167 * @flags: flags to set in EncKDCRepPart.
169 * Set the EncKDCRepPart.flags field.
171 * Return value: Returns SHISHI_OK iff succesful.
174 shishi_enckdcreppart_flags_set (Shishi
* handle
,
175 Shishi_asn1 enckdcreppart
, int flags
)
179 res
= shishi_asn1_write_bitstring (handle
, enckdcreppart
, "flags", flags
);
180 if (res
!= SHISHI_OK
)
187 * shishi_enckdcreppart_authtime_set:
188 * @handle: shishi handle as allocated by shishi_init().
189 * @enckdcreppart: input EncKDCRepPart variable.
190 * @authtime: character buffer containing a generalized time string.
192 * Set the EncTicketPart.authtime to supplied value.
194 * Return value: Returns SHISHI_OK iff succesful.
197 shishi_enckdcreppart_authtime_set (Shishi
* handle
,
198 Shishi_asn1 enckdcreppart
,
199 const char *authtime
)
203 res
= shishi_asn1_write (handle
, enckdcreppart
, "authtime",
204 authtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
205 if (res
!= SHISHI_OK
)
212 * shishi_enckdcreppart_starttime_set:
213 * @handle: shishi handle as allocated by shishi_init().
214 * @enckdcreppart: input EncKDCRepPart variable.
215 * @starttime: character buffer containing a generalized time string.
217 * Set the EncTicketPart.starttime to supplied value. Use a NULL
218 * value for @starttime to remove the field.
220 * Return value: Returns SHISHI_OK iff succesful.
223 shishi_enckdcreppart_starttime_set (Shishi
* handle
,
224 Shishi_asn1 enckdcreppart
,
225 const char *starttime
)
230 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime", NULL
, 0);
232 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime",
233 starttime
, SHISHI_GENERALIZEDTIME_LENGTH
);
234 if (res
!= SHISHI_OK
)
241 * shishi_enckdcreppart_endtime_set:
242 * @handle: shishi handle as allocated by shishi_init().
243 * @enckdcreppart: input EncKDCRepPart variable.
244 * @endtime: character buffer containing a generalized time string.
246 * Set the EncTicketPart.endtime to supplied value.
248 * Return value: Returns SHISHI_OK iff succesful.
251 shishi_enckdcreppart_endtime_set (Shishi
* handle
,
252 Shishi_asn1 enckdcreppart
,
257 res
= shishi_asn1_write (handle
, enckdcreppart
, "endtime",
258 endtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
259 if (res
!= SHISHI_OK
)
266 * shishi_enckdcreppart_renew_till_set:
267 * @handle: shishi handle as allocated by shishi_init().
268 * @enckdcreppart: input EncKDCRepPart variable.
269 * @renew_till: character buffer containing a generalized time string.
271 * Set the EncTicketPart.renew-till to supplied value. Use a NULL
272 * value for @renew_till to remove the field.
274 * Return value: Returns SHISHI_OK iff succesful.
277 shishi_enckdcreppart_renew_till_set (Shishi
* handle
,
278 Shishi_asn1 enckdcreppart
,
279 const char *renew_till
)
284 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till", NULL
, 0);
286 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till",
287 renew_till
, SHISHI_GENERALIZEDTIME_LENGTH
);
288 if (res
!= SHISHI_OK
)
295 * shishi_enckdcreppart_srealm_set:
296 * @handle: shishi handle as allocated by shishi_init().
297 * @enckdcreppart: EncKDCRepPart variable to set realm field in.
298 * @srealm: input array with name of realm.
300 * Set the server realm field in the EncKDCRepPart.
302 * Return value: Returns SHISHI_OK iff successful.
305 shishi_enckdcreppart_srealm_set (Shishi
* handle
,
306 Shishi_asn1 enckdcreppart
,
311 res
= shishi_asn1_write (handle
, enckdcreppart
, "srealm", srealm
, 0);
312 if (res
!= SHISHI_OK
)
320 * shishi_enckdcreppart_sname_set:
321 * @handle: shishi handle as allocated by shishi_init().
322 * @enckdcreppart: EncKDCRepPart variable to set server name field in.
323 * @name_type: type of principial, see Shishi_name_type, usually
325 * @sname: input array with principal name.
327 * Set the server name field in the EncKDCRepPart.
329 * Return value: Returns SHISHI_OK iff successful.
332 shishi_enckdcreppart_sname_set (Shishi
* handle
,
333 Shishi_asn1 enckdcreppart
,
334 Shishi_name_type name_type
, char *sname
[])
340 res
= shishi_asn1_write_integer (handle
, enckdcreppart
,
341 "sname.name-type", name_type
);
342 if (res
!= SHISHI_OK
)
345 res
= shishi_asn1_write (handle
, enckdcreppart
,
346 "sname.name-string", NULL
, 0);
347 if (res
!= SHISHI_OK
)
353 res
= shishi_asn1_write (handle
, enckdcreppart
, "sname.name-string",
355 if (res
!= SHISHI_OK
)
358 asprintf (&buf
, "sname.name-string.?%d", i
);
359 res
= shishi_asn1_write (handle
, enckdcreppart
, buf
, sname
[i
- 1], 0);
361 if (res
!= SHISHI_OK
)
371 shishi_enckdcreppart_server_set (Shishi
* handle
,
372 Shishi_asn1 enckdcreppart
,
381 tmpserver
= xstrdup (server
);
383 serverbuf
= xmalloc (sizeof (*serverbuf
));
385 (serverbuf
[i
] = strtok_r (i
== 0 ? tmpserver
: NULL
, "/", &tokptr
));
388 serverbuf
= xrealloc (serverbuf
, (i
+ 2) * sizeof (*serverbuf
));
391 res
= shishi_enckdcreppart_sname_set (handle
, enckdcreppart
,
392 SHISHI_NT_PRINCIPAL
, serverbuf
);
393 if (res
!= SHISHI_OK
)
403 shishi_enckdcreppart_srealmserver_set (Shishi
* handle
,
404 Shishi_asn1 enckdcreppart
,
405 const char *srealm
, const char *server
)
409 res
= shishi_enckdcreppart_srealm_set (handle
, enckdcreppart
, srealm
);
410 if (res
!= SHISHI_OK
)
413 res
= shishi_enckdcreppart_server_set (handle
, enckdcreppart
, server
);
414 if (res
!= SHISHI_OK
)
421 * shishi_enckdcreppart_populate_encticketpart:
422 * @handle: shishi handle as allocated by shishi_init().
423 * @enckdcreppart: input EncKDCRepPart variable.
424 * @encticketpart: input EncTicketPart variable.
426 * Set the flags, authtime, starttime, endtime, renew-till and caddr
427 * fields of the EncKDCRepPart to the corresponding values in the
430 * Return value: Returns SHISHI_OK iff succesful.
433 shishi_enckdcreppart_populate_encticketpart (Shishi
* handle
,
434 Shishi_asn1 enckdcreppart
,
435 Shishi_asn1 encticketpart
)
441 res
= shishi_asn1_read (handle
, encticketpart
, "flags", &buf
, &buflen
);
442 if (res
!= SHISHI_OK
)
443 return SHISHI_ASN1_ERROR
;
445 res
= shishi_asn1_write (handle
, enckdcreppart
, "flags", buf
, buflen
);
447 if (res
!= SHISHI_OK
)
448 return SHISHI_ASN1_ERROR
;
450 res
= shishi_asn1_read (handle
, encticketpart
, "authtime", &buf
, &buflen
);
451 if (res
!= SHISHI_OK
)
452 return SHISHI_ASN1_ERROR
;
454 res
= shishi_asn1_write (handle
, enckdcreppart
, "authtime", buf
, buflen
);
456 if (res
!= SHISHI_OK
)
457 return SHISHI_ASN1_ERROR
;
459 res
= shishi_asn1_read (handle
, encticketpart
, "starttime", &buf
, &buflen
);
460 if (res
!= SHISHI_OK
&& res
!= SHISHI_ASN1_NO_ELEMENT
)
461 return SHISHI_ASN1_ERROR
;
463 if (res
== SHISHI_ASN1_NO_ELEMENT
)
464 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime", NULL
, 0);
467 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime",
471 if (res
!= SHISHI_OK
)
472 return SHISHI_ASN1_ERROR
;
474 res
= shishi_asn1_read (handle
, encticketpart
, "endtime", &buf
, &buflen
);
475 if (res
!= SHISHI_OK
)
476 return SHISHI_ASN1_ERROR
;
478 res
= shishi_asn1_write (handle
, enckdcreppart
, "endtime", buf
, buflen
);
480 if (res
!= SHISHI_OK
)
481 return SHISHI_ASN1_ERROR
;
483 res
= shishi_asn1_read (handle
, encticketpart
, "renew-till", &buf
, &buflen
);
484 if (res
!= SHISHI_OK
&& res
!= SHISHI_ASN1_NO_ELEMENT
)
485 return SHISHI_ASN1_ERROR
;
487 if (res
== SHISHI_ASN1_NO_ELEMENT
)
488 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till", NULL
, 0);
491 res
= shishi_asn1_write (handle
, enckdcreppart
,
492 "renew-till", buf
, buflen
);
495 if (res
!= SHISHI_OK
)
496 return SHISHI_ASN1_ERROR
;
498 /* XXX copy caddr too */