1 /* enckdcreppart.c --- Key distribution encrypted reply part functions
2 * Copyright (C) 2002, 2003, 2004, 2006, 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
27 shishi_enckdcreppart (Shishi
* handle
)
32 node
= shishi_asn1_enckdcreppart (handle
);
36 /* XXX remove these two: */
37 res
= shishi_asn1_write (handle
, node
, "key-expiration", NULL
, 0);
41 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
45 res
= shishi_enckdcreppart_flags_set (handle
, node
, 0);
53 shishi_encasreppart (Shishi
* handle
)
58 node
= shishi_asn1_encasreppart (handle
);
62 /* XXX remove these two: */
63 res
= shishi_asn1_write (handle
, node
, "key-expiration", NULL
, 0);
66 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
74 * shishi_enckdcreppart_get_key:
75 * @handle: shishi handle as allocated by shishi_init().
76 * @enckdcreppart: input EncKDCRepPart variable.
77 * @key: newly allocated encryption key handle.
79 * Extract the key to use with the ticket sent in the KDC-REP
80 * associated with the EncKDCRepPart input variable.
82 * Return value: Returns SHISHI_OK iff succesful.
85 shishi_enckdcreppart_get_key (Shishi
* handle
,
86 Shishi_asn1 enckdcreppart
, Shishi_key
** key
)
93 res
= shishi_asn1_read_int32 (handle
, enckdcreppart
,
94 "key.keytype", &keytype
);
98 res
= shishi_asn1_read (handle
, enckdcreppart
, "key.keyvalue",
100 if (res
!= SHISHI_OK
)
103 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
105 if (res
!= SHISHI_OK
)
112 * shishi_enckdcreppart_key_set:
113 * @handle: shishi handle as allocated by shishi_init().
114 * @enckdcreppart: input EncKDCRepPart variable.
115 * @key: key handle with information to store in enckdcreppart.
117 * Set the EncKDCRepPart.key field to key type and value of supplied
120 * Return value: Returns SHISHI_OK iff succesful.
123 shishi_enckdcreppart_key_set (Shishi
* handle
,
124 Shishi_asn1 enckdcreppart
, Shishi_key
* key
)
128 res
= shishi_asn1_write_integer (handle
, enckdcreppart
, "key.keytype",
129 shishi_key_type (key
));
130 if (res
!= SHISHI_OK
)
131 return SHISHI_ASN1_ERROR
;
133 res
= shishi_asn1_write (handle
, enckdcreppart
, "key.keyvalue",
134 shishi_key_value (key
), shishi_key_length (key
));
135 if (res
!= SHISHI_OK
)
136 return SHISHI_ASN1_ERROR
;
142 * shishi_enckdcreppart_nonce_set:
143 * @handle: shishi handle as allocated by shishi_init().
144 * @enckdcreppart: input EncKDCRepPart variable.
145 * @nonce: nonce to set in EncKDCRepPart.
147 * Set the EncKDCRepPart.nonce field.
149 * Return value: Returns SHISHI_OK iff succesful.
152 shishi_enckdcreppart_nonce_set (Shishi
* handle
,
153 Shishi_asn1 enckdcreppart
, uint32_t nonce
)
157 res
= shishi_asn1_write_uint32 (handle
, enckdcreppart
, "nonce", nonce
);
158 if (res
!= SHISHI_OK
)
165 * shishi_enckdcreppart_flags_set:
166 * @handle: shishi handle as allocated by shishi_init().
167 * @enckdcreppart: input EncKDCRepPart variable.
168 * @flags: flags to set in EncKDCRepPart.
170 * Set the EncKDCRepPart.flags field.
172 * Return value: Returns SHISHI_OK iff succesful.
175 shishi_enckdcreppart_flags_set (Shishi
* handle
,
176 Shishi_asn1 enckdcreppart
, int flags
)
180 res
= shishi_asn1_write_bitstring (handle
, enckdcreppart
, "flags", flags
);
181 if (res
!= SHISHI_OK
)
188 * shishi_enckdcreppart_authtime_set:
189 * @handle: shishi handle as allocated by shishi_init().
190 * @enckdcreppart: input EncKDCRepPart variable.
191 * @authtime: character buffer containing a generalized time string.
193 * Set the EncTicketPart.authtime to supplied value.
195 * Return value: Returns SHISHI_OK iff succesful.
198 shishi_enckdcreppart_authtime_set (Shishi
* handle
,
199 Shishi_asn1 enckdcreppart
,
200 const char *authtime
)
204 res
= shishi_asn1_write (handle
, enckdcreppart
, "authtime",
205 authtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
206 if (res
!= SHISHI_OK
)
213 * shishi_enckdcreppart_starttime_set:
214 * @handle: shishi handle as allocated by shishi_init().
215 * @enckdcreppart: input EncKDCRepPart variable.
216 * @starttime: character buffer containing a generalized time string.
218 * Set the EncTicketPart.starttime to supplied value. Use a NULL
219 * value for @starttime to remove the field.
221 * Return value: Returns SHISHI_OK iff succesful.
224 shishi_enckdcreppart_starttime_set (Shishi
* handle
,
225 Shishi_asn1 enckdcreppart
,
226 const char *starttime
)
231 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime", NULL
, 0);
233 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime",
234 starttime
, SHISHI_GENERALIZEDTIME_LENGTH
);
235 if (res
!= SHISHI_OK
)
242 * shishi_enckdcreppart_endtime_set:
243 * @handle: shishi handle as allocated by shishi_init().
244 * @enckdcreppart: input EncKDCRepPart variable.
245 * @endtime: character buffer containing a generalized time string.
247 * Set the EncTicketPart.endtime to supplied value.
249 * Return value: Returns SHISHI_OK iff succesful.
252 shishi_enckdcreppart_endtime_set (Shishi
* handle
,
253 Shishi_asn1 enckdcreppart
,
258 res
= shishi_asn1_write (handle
, enckdcreppart
, "endtime",
259 endtime
, SHISHI_GENERALIZEDTIME_LENGTH
);
260 if (res
!= SHISHI_OK
)
267 * shishi_enckdcreppart_renew_till_set:
268 * @handle: shishi handle as allocated by shishi_init().
269 * @enckdcreppart: input EncKDCRepPart variable.
270 * @renew_till: character buffer containing a generalized time string.
272 * Set the EncTicketPart.renew-till to supplied value. Use a NULL
273 * value for @renew_till to remove the field.
275 * Return value: Returns SHISHI_OK iff succesful.
278 shishi_enckdcreppart_renew_till_set (Shishi
* handle
,
279 Shishi_asn1 enckdcreppart
,
280 const char *renew_till
)
285 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till", NULL
, 0);
287 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till",
288 renew_till
, SHISHI_GENERALIZEDTIME_LENGTH
);
289 if (res
!= SHISHI_OK
)
296 * shishi_enckdcreppart_srealm_set:
297 * @handle: shishi handle as allocated by shishi_init().
298 * @enckdcreppart: EncKDCRepPart variable to set realm field in.
299 * @srealm: input array with name of realm.
301 * Set the server realm field in the EncKDCRepPart.
303 * Return value: Returns SHISHI_OK iff successful.
306 shishi_enckdcreppart_srealm_set (Shishi
* handle
,
307 Shishi_asn1 enckdcreppart
,
312 res
= shishi_asn1_write (handle
, enckdcreppart
, "srealm", srealm
, 0);
313 if (res
!= SHISHI_OK
)
321 * shishi_enckdcreppart_sname_set:
322 * @handle: shishi handle as allocated by shishi_init().
323 * @enckdcreppart: EncKDCRepPart variable to set server name field in.
324 * @name_type: type of principial, see Shishi_name_type, usually
326 * @sname: input array with principal name.
328 * Set the server name field in the EncKDCRepPart.
330 * Return value: Returns SHISHI_OK iff successful.
333 shishi_enckdcreppart_sname_set (Shishi
* handle
,
334 Shishi_asn1 enckdcreppart
,
335 Shishi_name_type name_type
, char *sname
[])
341 res
= shishi_asn1_write_integer (handle
, enckdcreppart
,
342 "sname.name-type", name_type
);
343 if (res
!= SHISHI_OK
)
346 res
= shishi_asn1_write (handle
, enckdcreppart
,
347 "sname.name-string", NULL
, 0);
348 if (res
!= SHISHI_OK
)
354 res
= shishi_asn1_write (handle
, enckdcreppart
, "sname.name-string",
356 if (res
!= SHISHI_OK
)
359 asprintf (&buf
, "sname.name-string.?%d", i
);
360 res
= shishi_asn1_write (handle
, enckdcreppart
, buf
, sname
[i
- 1], 0);
362 if (res
!= SHISHI_OK
)
372 shishi_enckdcreppart_server_set (Shishi
* handle
,
373 Shishi_asn1 enckdcreppart
,
382 tmpserver
= xstrdup (server
);
384 serverbuf
= xmalloc (sizeof (*serverbuf
));
386 (serverbuf
[i
] = strtok_r (i
== 0 ? tmpserver
: NULL
, "/", &tokptr
));
389 serverbuf
= xrealloc (serverbuf
, (i
+ 2) * sizeof (*serverbuf
));
392 res
= shishi_enckdcreppart_sname_set (handle
, enckdcreppart
,
393 SHISHI_NT_PRINCIPAL
, serverbuf
);
394 if (res
!= SHISHI_OK
)
404 shishi_enckdcreppart_srealmserver_set (Shishi
* handle
,
405 Shishi_asn1 enckdcreppart
,
406 const char *srealm
, const char *server
)
410 res
= shishi_enckdcreppart_srealm_set (handle
, enckdcreppart
, srealm
);
411 if (res
!= SHISHI_OK
)
414 res
= shishi_enckdcreppart_server_set (handle
, enckdcreppart
, server
);
415 if (res
!= SHISHI_OK
)
422 * shishi_enckdcreppart_populate_encticketpart:
423 * @handle: shishi handle as allocated by shishi_init().
424 * @enckdcreppart: input EncKDCRepPart variable.
425 * @encticketpart: input EncTicketPart variable.
427 * Set the flags, authtime, starttime, endtime, renew-till and caddr
428 * fields of the EncKDCRepPart to the corresponding values in the
431 * Return value: Returns SHISHI_OK iff succesful.
434 shishi_enckdcreppart_populate_encticketpart (Shishi
* handle
,
435 Shishi_asn1 enckdcreppart
,
436 Shishi_asn1 encticketpart
)
442 res
= shishi_asn1_read (handle
, encticketpart
, "flags", &buf
, &buflen
);
443 if (res
!= SHISHI_OK
)
444 return SHISHI_ASN1_ERROR
;
446 res
= shishi_asn1_write (handle
, enckdcreppart
, "flags", buf
, buflen
);
448 if (res
!= SHISHI_OK
)
449 return SHISHI_ASN1_ERROR
;
451 res
= shishi_asn1_read (handle
, encticketpart
, "authtime", &buf
, &buflen
);
452 if (res
!= SHISHI_OK
)
453 return SHISHI_ASN1_ERROR
;
455 res
= shishi_asn1_write (handle
, enckdcreppart
, "authtime", buf
, buflen
);
457 if (res
!= SHISHI_OK
)
458 return SHISHI_ASN1_ERROR
;
460 res
= shishi_asn1_read (handle
, encticketpart
, "starttime", &buf
, &buflen
);
461 if (res
!= SHISHI_OK
&& res
!= SHISHI_ASN1_NO_ELEMENT
)
462 return SHISHI_ASN1_ERROR
;
464 if (res
== SHISHI_ASN1_NO_ELEMENT
)
465 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime", NULL
, 0);
468 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime",
472 if (res
!= SHISHI_OK
)
473 return SHISHI_ASN1_ERROR
;
475 res
= shishi_asn1_read (handle
, encticketpart
, "endtime", &buf
, &buflen
);
476 if (res
!= SHISHI_OK
)
477 return SHISHI_ASN1_ERROR
;
479 res
= shishi_asn1_write (handle
, enckdcreppart
, "endtime", buf
, buflen
);
481 if (res
!= SHISHI_OK
)
482 return SHISHI_ASN1_ERROR
;
484 res
= shishi_asn1_read (handle
, encticketpart
, "renew-till", &buf
, &buflen
);
485 if (res
!= SHISHI_OK
&& res
!= SHISHI_ASN1_NO_ELEMENT
)
486 return SHISHI_ASN1_ERROR
;
488 if (res
== SHISHI_ASN1_NO_ELEMENT
)
489 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till", NULL
, 0);
492 res
= shishi_asn1_write (handle
, enckdcreppart
,
493 "renew-till", buf
, buflen
);
496 if (res
!= SHISHI_OK
)
497 return SHISHI_ASN1_ERROR
;
499 /* XXX copy caddr too */