(krb5_mk_req_ext): figure out the correct `enctype'
[heimdal.git] / lib / krb5 / mk_req_ext.c
blobd4db810806534cdde9249248e620fb167c2c0e80
1 /*
2 * Copyright (c) 1997 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
39 #include <krb5_locl.h>
41 RCSID("$Id$");
43 krb5_error_code
44 krb5_mk_req_extended(krb5_context context,
45 krb5_auth_context *auth_context,
46 const krb5_flags ap_req_options,
47 krb5_data *in_data,
48 krb5_creds *in_creds,
49 krb5_data *outbuf)
51 krb5_error_code ret;
52 krb5_data authenticator;
53 Checksum c;
54 Checksum *c_opt;
55 krb5_cksumtype cksumtype;
56 krb5_auth_context ac;
57 krb5_enctype enctype;
59 if(auth_context) {
60 if(*auth_context == NULL)
61 ret = krb5_auth_con_init(context, auth_context);
62 else
63 ret = 0;
64 ac = *auth_context;
65 } else
66 ret = krb5_auth_con_init(context, &ac);
67 if(ret)
68 return ret;
70 krb5_free_keyblock(context, ac->keyblock);
71 krb5_copy_keyblock(context, &in_creds->session, &ac->keyblock);
73 if (ac->enctype)
74 enctype = ac->enctype;
75 else {
76 ret = krb5_keytype_to_etype(context,
77 ac->keyblock->keytype,
78 &enctype);
79 if (ret)
80 return ret;
83 if (ac->cksumtype)
84 cksumtype = ac->cksumtype;
85 else
86 krb5_keytype_to_cksumtype (context, ac->keyblock->keytype, &cksumtype);
88 if (in_data) {
89 ret = krb5_create_checksum (context,
90 cksumtype,
91 in_data->data,
92 in_data->length,
93 ac->keyblock,
94 &c);
95 c_opt = &c;
96 } else {
97 c_opt = NULL;
100 ret = krb5_build_authenticator (context,
102 enctype,
103 in_creds,
104 c_opt,
105 NULL,
106 &authenticator);
107 if (c_opt)
108 free_Checksum (c_opt);
109 if (ret)
110 return ret;
112 ret = krb5_build_ap_req (context, enctype, in_creds, ap_req_options,
113 authenticator, outbuf);
114 if(auth_context == NULL)
115 krb5_auth_con_free(context, ac);
116 return ret;