1*ebfedea0SLionel Sambuc /* $NetBSD: mk_req_ext.c,v 1.1.1.1 2011/04/13 18:15:36 elric Exp $ */
2*ebfedea0SLionel Sambuc
3*ebfedea0SLionel Sambuc /*
4*ebfedea0SLionel Sambuc * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
5*ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden).
6*ebfedea0SLionel Sambuc * All rights reserved.
7*ebfedea0SLionel Sambuc *
8*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
9*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
10*ebfedea0SLionel Sambuc * are met:
11*ebfedea0SLionel Sambuc *
12*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
13*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
14*ebfedea0SLionel Sambuc *
15*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
17*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
18*ebfedea0SLionel Sambuc *
19*ebfedea0SLionel Sambuc * 3. Neither the name of the Institute nor the names of its contributors
20*ebfedea0SLionel Sambuc * may be used to endorse or promote products derived from this software
21*ebfedea0SLionel Sambuc * without specific prior written permission.
22*ebfedea0SLionel Sambuc *
23*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24*ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26*ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27*ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28*ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29*ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30*ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31*ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32*ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*ebfedea0SLionel Sambuc * SUCH DAMAGE.
34*ebfedea0SLionel Sambuc */
35*ebfedea0SLionel Sambuc
36*ebfedea0SLionel Sambuc #include "krb5_locl.h"
37*ebfedea0SLionel Sambuc
38*ebfedea0SLionel Sambuc krb5_error_code
_krb5_mk_req_internal(krb5_context context,krb5_auth_context * auth_context,const krb5_flags ap_req_options,krb5_data * in_data,krb5_creds * in_creds,krb5_data * outbuf,krb5_key_usage checksum_usage,krb5_key_usage encrypt_usage)39*ebfedea0SLionel Sambuc _krb5_mk_req_internal(krb5_context context,
40*ebfedea0SLionel Sambuc krb5_auth_context *auth_context,
41*ebfedea0SLionel Sambuc const krb5_flags ap_req_options,
42*ebfedea0SLionel Sambuc krb5_data *in_data,
43*ebfedea0SLionel Sambuc krb5_creds *in_creds,
44*ebfedea0SLionel Sambuc krb5_data *outbuf,
45*ebfedea0SLionel Sambuc krb5_key_usage checksum_usage,
46*ebfedea0SLionel Sambuc krb5_key_usage encrypt_usage)
47*ebfedea0SLionel Sambuc {
48*ebfedea0SLionel Sambuc krb5_error_code ret;
49*ebfedea0SLionel Sambuc krb5_data authenticator;
50*ebfedea0SLionel Sambuc Checksum c;
51*ebfedea0SLionel Sambuc Checksum *c_opt;
52*ebfedea0SLionel Sambuc krb5_auth_context ac;
53*ebfedea0SLionel Sambuc
54*ebfedea0SLionel Sambuc if(auth_context) {
55*ebfedea0SLionel Sambuc if(*auth_context == NULL)
56*ebfedea0SLionel Sambuc ret = krb5_auth_con_init(context, auth_context);
57*ebfedea0SLionel Sambuc else
58*ebfedea0SLionel Sambuc ret = 0;
59*ebfedea0SLionel Sambuc ac = *auth_context;
60*ebfedea0SLionel Sambuc } else
61*ebfedea0SLionel Sambuc ret = krb5_auth_con_init(context, &ac);
62*ebfedea0SLionel Sambuc if(ret)
63*ebfedea0SLionel Sambuc return ret;
64*ebfedea0SLionel Sambuc
65*ebfedea0SLionel Sambuc if(ac->local_subkey == NULL && (ap_req_options & AP_OPTS_USE_SUBKEY)) {
66*ebfedea0SLionel Sambuc ret = krb5_auth_con_generatelocalsubkey(context,
67*ebfedea0SLionel Sambuc ac,
68*ebfedea0SLionel Sambuc &in_creds->session);
69*ebfedea0SLionel Sambuc if(ret)
70*ebfedea0SLionel Sambuc goto out;
71*ebfedea0SLionel Sambuc }
72*ebfedea0SLionel Sambuc
73*ebfedea0SLionel Sambuc krb5_free_keyblock(context, ac->keyblock);
74*ebfedea0SLionel Sambuc ret = krb5_copy_keyblock(context, &in_creds->session, &ac->keyblock);
75*ebfedea0SLionel Sambuc if (ret)
76*ebfedea0SLionel Sambuc goto out;
77*ebfedea0SLionel Sambuc
78*ebfedea0SLionel Sambuc /* it's unclear what type of checksum we can use. try the best one, except:
79*ebfedea0SLionel Sambuc * a) if it's configured differently for the current realm, or
80*ebfedea0SLionel Sambuc * b) if the session key is des-cbc-crc
81*ebfedea0SLionel Sambuc */
82*ebfedea0SLionel Sambuc
83*ebfedea0SLionel Sambuc if (in_data) {
84*ebfedea0SLionel Sambuc if(ac->keyblock->keytype == ETYPE_DES_CBC_CRC) {
85*ebfedea0SLionel Sambuc /* this is to make DCE secd (and older MIT kdcs?) happy */
86*ebfedea0SLionel Sambuc ret = krb5_create_checksum(context,
87*ebfedea0SLionel Sambuc NULL,
88*ebfedea0SLionel Sambuc 0,
89*ebfedea0SLionel Sambuc CKSUMTYPE_RSA_MD4,
90*ebfedea0SLionel Sambuc in_data->data,
91*ebfedea0SLionel Sambuc in_data->length,
92*ebfedea0SLionel Sambuc &c);
93*ebfedea0SLionel Sambuc } else if(ac->keyblock->keytype == ETYPE_ARCFOUR_HMAC_MD5 ||
94*ebfedea0SLionel Sambuc ac->keyblock->keytype == ETYPE_ARCFOUR_HMAC_MD5_56 ||
95*ebfedea0SLionel Sambuc ac->keyblock->keytype == ETYPE_DES_CBC_MD4 ||
96*ebfedea0SLionel Sambuc ac->keyblock->keytype == ETYPE_DES_CBC_MD5) {
97*ebfedea0SLionel Sambuc /* this is to make MS kdc happy */
98*ebfedea0SLionel Sambuc ret = krb5_create_checksum(context,
99*ebfedea0SLionel Sambuc NULL,
100*ebfedea0SLionel Sambuc 0,
101*ebfedea0SLionel Sambuc CKSUMTYPE_RSA_MD5,
102*ebfedea0SLionel Sambuc in_data->data,
103*ebfedea0SLionel Sambuc in_data->length,
104*ebfedea0SLionel Sambuc &c);
105*ebfedea0SLionel Sambuc } else {
106*ebfedea0SLionel Sambuc krb5_crypto crypto;
107*ebfedea0SLionel Sambuc
108*ebfedea0SLionel Sambuc ret = krb5_crypto_init(context, ac->keyblock, 0, &crypto);
109*ebfedea0SLionel Sambuc if (ret)
110*ebfedea0SLionel Sambuc goto out;
111*ebfedea0SLionel Sambuc ret = krb5_create_checksum(context,
112*ebfedea0SLionel Sambuc crypto,
113*ebfedea0SLionel Sambuc checksum_usage,
114*ebfedea0SLionel Sambuc 0,
115*ebfedea0SLionel Sambuc in_data->data,
116*ebfedea0SLionel Sambuc in_data->length,
117*ebfedea0SLionel Sambuc &c);
118*ebfedea0SLionel Sambuc krb5_crypto_destroy(context, crypto);
119*ebfedea0SLionel Sambuc }
120*ebfedea0SLionel Sambuc c_opt = &c;
121*ebfedea0SLionel Sambuc } else {
122*ebfedea0SLionel Sambuc c_opt = NULL;
123*ebfedea0SLionel Sambuc }
124*ebfedea0SLionel Sambuc
125*ebfedea0SLionel Sambuc if (ret)
126*ebfedea0SLionel Sambuc goto out;
127*ebfedea0SLionel Sambuc
128*ebfedea0SLionel Sambuc ret = _krb5_build_authenticator(context,
129*ebfedea0SLionel Sambuc ac,
130*ebfedea0SLionel Sambuc ac->keyblock->keytype,
131*ebfedea0SLionel Sambuc in_creds,
132*ebfedea0SLionel Sambuc c_opt,
133*ebfedea0SLionel Sambuc &authenticator,
134*ebfedea0SLionel Sambuc encrypt_usage);
135*ebfedea0SLionel Sambuc if (c_opt)
136*ebfedea0SLionel Sambuc free_Checksum (c_opt);
137*ebfedea0SLionel Sambuc if (ret)
138*ebfedea0SLionel Sambuc goto out;
139*ebfedea0SLionel Sambuc
140*ebfedea0SLionel Sambuc ret = krb5_build_ap_req (context, ac->keyblock->keytype,
141*ebfedea0SLionel Sambuc in_creds, ap_req_options, authenticator, outbuf);
142*ebfedea0SLionel Sambuc out:
143*ebfedea0SLionel Sambuc if(auth_context == NULL)
144*ebfedea0SLionel Sambuc krb5_auth_con_free(context, ac);
145*ebfedea0SLionel Sambuc return ret;
146*ebfedea0SLionel Sambuc }
147*ebfedea0SLionel Sambuc
148*ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_mk_req_extended(krb5_context context,krb5_auth_context * auth_context,const krb5_flags ap_req_options,krb5_data * in_data,krb5_creds * in_creds,krb5_data * outbuf)149*ebfedea0SLionel Sambuc krb5_mk_req_extended(krb5_context context,
150*ebfedea0SLionel Sambuc krb5_auth_context *auth_context,
151*ebfedea0SLionel Sambuc const krb5_flags ap_req_options,
152*ebfedea0SLionel Sambuc krb5_data *in_data,
153*ebfedea0SLionel Sambuc krb5_creds *in_creds,
154*ebfedea0SLionel Sambuc krb5_data *outbuf)
155*ebfedea0SLionel Sambuc {
156*ebfedea0SLionel Sambuc return _krb5_mk_req_internal (context,
157*ebfedea0SLionel Sambuc auth_context,
158*ebfedea0SLionel Sambuc ap_req_options,
159*ebfedea0SLionel Sambuc in_data,
160*ebfedea0SLionel Sambuc in_creds,
161*ebfedea0SLionel Sambuc outbuf,
162*ebfedea0SLionel Sambuc KRB5_KU_AP_REQ_AUTH_CKSUM,
163*ebfedea0SLionel Sambuc KRB5_KU_AP_REQ_AUTH);
164*ebfedea0SLionel Sambuc }
165