1 /* enckdcreppart.c Key distribution encrypted reply part functions
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
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);
48 shishi_encasreppart (Shishi
* handle
)
53 node
= shishi_asn1_encasreppart (handle
);
57 /* XXX remove these two: */
58 res
= shishi_asn1_write (handle
, node
, "key-expiration", NULL
, 0);
61 res
= shishi_asn1_write (handle
, node
, "caddr", NULL
, 0);
69 * shishi_enckdcreppart_get_key:
70 * @handle: shishi handle as allocated by shishi_init().
71 * @enckdcreppart: input EncKDCRepPart variable.
72 * @key: newly allocated encryption key handle.
74 * Extract the key to use with the ticket sent in the KDC-REP
75 * associated with the EndKDCRepPart input variable.
77 * Return value: Returns SHISHI_OK iff succesful.
80 shishi_enckdcreppart_get_key (Shishi
* handle
,
81 Shishi_asn1 enckdcreppart
, Shishi_key
** key
)
88 res
= shishi_asn1_read_int32 (handle
, enckdcreppart
,
89 "key.keytype", &keytype
);
93 res
= shishi_asn1_read2 (handle
, enckdcreppart
, "key.keyvalue",
98 res
= shishi_key_from_value (handle
, keytype
, buf
, key
);
100 if (res
!= SHISHI_OK
)
107 * shishi_enckdcreppart_key_set:
108 * @handle: shishi handle as allocated by shishi_init().
109 * @enckdcreppart: input EncKDCRepPart variable.
110 * @key: key handle with information to store in enckdcreppart.
112 * Set the EncKDCRepPart.key field to key type and value of supplied
115 * Return value: Returns SHISHI_OK iff succesful.
118 shishi_enckdcreppart_key_set (Shishi
* handle
,
119 Shishi_asn1 enckdcreppart
, Shishi_key
* key
)
123 res
= shishi_asn1_write_integer (handle
, enckdcreppart
, "key.keytype",
124 shishi_key_type (key
));
125 if (res
!= SHISHI_OK
)
126 return SHISHI_ASN1_ERROR
;
128 res
= shishi_asn1_write (handle
, enckdcreppart
, "key.keyvalue",
129 shishi_key_value (key
), shishi_key_length (key
));
130 if (res
!= SHISHI_OK
)
131 return SHISHI_ASN1_ERROR
;
137 * shishi_enckdcreppart_nonce_set:
138 * @handle: shishi handle as allocated by shishi_init().
139 * @enckdcreppart: input EncKDCRepPart variable.
140 * @nonce: nonce to set in EncKDCRepPart.
142 * Set the EncKDCRepPart.nonce field.
144 * Return value: Returns SHISHI_OK iff succesful.
147 shishi_enckdcreppart_nonce_set (Shishi
* handle
,
148 Shishi_asn1 enckdcreppart
, uint32_t nonce
)
152 res
= shishi_asn1_write_integer (handle
, enckdcreppart
, "nonce", nonce
);
153 if (res
!= SHISHI_OK
)
160 * shishi_enckdcreppart_flags_set:
161 * @handle: shishi handle as allocated by shishi_init().
162 * @enckdcreppart: input EncKDCRepPart variable.
163 * @flags: flags to set in EncKDCRepPart.
165 * Set the EncKDCRepPart.flags field.
167 * Return value: Returns SHISHI_OK iff succesful.
170 shishi_enckdcreppart_flags_set (Shishi
* handle
,
171 Shishi_asn1 enckdcreppart
, int flags
)
175 res
= shishi_asn1_write_integer (handle
, enckdcreppart
, "flags", flags
);
176 if (res
!= SHISHI_OK
)
177 return SHISHI_ASN1_ERROR
;
183 * shishi_enckdcreppart_populate_encticketpart:
184 * @handle: shishi handle as allocated by shishi_init().
185 * @enckdcreppart: input EncKDCRepPart variable.
186 * @encticketpart: input EncTicketPart variable.
188 * Set the flags, authtime, starttime, endtime, renew-till and caddr
189 * fields of the EncKDCRepPart to the corresponding values in the
192 * Return value: Returns SHISHI_OK iff succesful.
195 shishi_enckdcreppart_populate_encticketpart (Shishi
* handle
,
196 Shishi_asn1 enckdcreppart
,
197 Shishi_asn1 encticketpart
)
203 res
= shishi_asn1_read2 (handle
, encticketpart
, "flags", &buf
, &buflen
);
204 if (res
!= SHISHI_OK
)
205 return SHISHI_ASN1_ERROR
;
207 res
= shishi_asn1_write (handle
, enckdcreppart
, "flags", buf
, buflen
);
209 if (res
!= SHISHI_OK
)
210 return SHISHI_ASN1_ERROR
;
212 res
= shishi_asn1_read2 (handle
, encticketpart
, "authtime", &buf
, &buflen
);
213 if (res
!= SHISHI_OK
)
214 return SHISHI_ASN1_ERROR
;
216 res
= shishi_asn1_write (handle
, enckdcreppart
, "authtime", buf
, buflen
);
218 if (res
!= SHISHI_OK
)
219 return SHISHI_ASN1_ERROR
;
221 res
= shishi_asn1_read2 (handle
, encticketpart
, "starttime", &buf
, &buflen
);
222 if (res
!= SHISHI_OK
&& res
!= SHISHI_ASN1_NO_ELEMENT
)
223 return SHISHI_ASN1_ERROR
;
225 if (res
== SHISHI_ASN1_NO_ELEMENT
)
226 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime", NULL
, 0);
229 res
= shishi_asn1_write (handle
, enckdcreppart
, "starttime",
233 if (res
!= SHISHI_OK
)
234 return SHISHI_ASN1_ERROR
;
236 res
= shishi_asn1_read2 (handle
, encticketpart
, "endtime", &buf
, &buflen
);
237 if (res
!= SHISHI_OK
)
238 return SHISHI_ASN1_ERROR
;
240 res
= shishi_asn1_write (handle
, enckdcreppart
, "endtime", buf
, buflen
);
242 if (res
!= SHISHI_OK
)
243 return SHISHI_ASN1_ERROR
;
246 shishi_asn1_read2 (handle
, encticketpart
, "renew-till", &buf
, &buflen
);
247 if (res
!= SHISHI_OK
&& res
!= SHISHI_ASN1_NO_ELEMENT
)
248 return SHISHI_ASN1_ERROR
;
250 if (res
== SHISHI_ASN1_NO_ELEMENT
)
251 res
= shishi_asn1_write (handle
, enckdcreppart
, "renew-till", NULL
, 0);
254 res
= shishi_asn1_write (handle
, enckdcreppart
,
255 "renew-till", buf
, buflen
);
258 if (res
!= SHISHI_OK
)
259 return SHISHI_ASN1_ERROR
;
261 /* XXX copy caddr too */
267 * shishi_enckdcreppart_srealm_set:
268 * @handle: shishi handle as allocated by shishi_init().
269 * @enckdcreppart: EncKDCRepPart variable to set realm field in.
270 * @srealm: input array with name of realm.
272 * Set the server realm field in the EncKDCRepPart.
274 * Return value: Returns SHISHI_OK iff successful.
277 shishi_enckdcreppart_srealm_set (Shishi
* handle
,
278 Shishi_asn1 enckdcreppart
,
283 res
= shishi_asn1_write (handle
, enckdcreppart
, "srealm", srealm
, 0);
284 if (res
!= SHISHI_OK
)
292 * shishi_enckdcreppart_sname_set:
293 * @handle: shishi handle as allocated by shishi_init().
294 * @enckdcreppart: EncKDCRepPart variable to set server name field in.
295 * @name_type: type of principial, see Shishi_name_type, usually
297 * @sname: input array with principal name.
299 * Set the server name field in the EncKDCRepPart.
301 * Return value: Returns SHISHI_OK iff successful.
304 shishi_enckdcreppart_sname_set (Shishi
* handle
,
305 Shishi_asn1 enckdcreppart
,
306 Shishi_name_type name_type
, char *sname
[])
312 res
= shishi_asn1_write_integer (handle
, enckdcreppart
,
313 "sname.name-type", name_type
);
314 if (res
!= SHISHI_OK
)
317 res
= shishi_asn1_write (handle
, enckdcreppart
,
318 "sname.name-string", NULL
, 0);
319 if (res
!= SHISHI_OK
)
325 res
= shishi_asn1_write (handle
, enckdcreppart
, "sname.name-string",
327 if (res
!= SHISHI_OK
)
330 asprintf (&buf
, "sname.name-string.?%d", i
);
331 res
= shishi_asn1_write (handle
, enckdcreppart
, buf
, sname
[i
- 1], 0);
333 if (res
!= SHISHI_OK
)
343 shishi_enckdcreppart_server_set (Shishi
* handle
,
344 Shishi_asn1 enckdcreppart
,
353 tmpserver
= xstrdup (server
);
355 serverbuf
= xmalloc (sizeof (*serverbuf
));
357 (serverbuf
[i
] = strtok_r (i
== 0 ? tmpserver
: NULL
, "/", &tokptr
));
360 serverbuf
= xrealloc (serverbuf
, (i
+ 2) * sizeof (*serverbuf
));
362 res
= shishi_enckdcreppart_sname_set (handle
, enckdcreppart
,
363 SHISHI_NT_PRINCIPAL
, serverbuf
);
364 if (res
!= SHISHI_OK
)
366 fprintf (stderr
, _("Could not set sname: %s\n"), shishi_error (handle
));
376 shishi_enckdcreppart_srealmserver_set (Shishi
* handle
,
377 Shishi_asn1 enckdcreppart
,
378 const char *srealm
, const char *server
)
382 res
= shishi_enckdcreppart_srealm_set (handle
, enckdcreppart
, srealm
);
383 if (res
!= SHISHI_OK
)
386 res
= shishi_enckdcreppart_server_set (handle
, enckdcreppart
, server
);
387 if (res
!= SHISHI_OK
)