2 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <krb5_locl.h>
36 RCSID("$Id: rd_priv.c,v 1.29 2001/06/18 02:46:15 assar Exp $");
39 krb5_rd_priv(krb5_context context,
40 krb5_auth_context auth_context,
41 const krb5_data *inbuf,
43 /*krb5_replay_data*/ void *outdata)
53 memset(&priv, 0, sizeof(priv));
54 ret = decode_KRB_PRIV (inbuf->data, inbuf->length, &priv, &len);
58 krb5_clear_error_string (context);
59 ret = KRB5KRB_AP_ERR_BADVERSION;
62 if (priv.msg_type != krb_priv) {
63 krb5_clear_error_string (context);
64 ret = KRB5KRB_AP_ERR_MSG_TYPE;
68 if (auth_context->remote_subkey)
69 key = auth_context->remote_subkey;
70 else if (auth_context->local_subkey)
71 key = auth_context->local_subkey;
73 key = auth_context->keyblock;
75 ret = krb5_crypto_init(context, key, 0, &crypto);
78 ret = krb5_decrypt_EncryptedData(context,
83 krb5_crypto_destroy(context, crypto);
87 ret = decode_EncKrbPrivPart (plain.data, plain.length, &part, &len);
88 krb5_data_free (&plain);
92 /* check sender address */
95 && auth_context->remote_address
96 && !krb5_address_compare (context,
97 auth_context->remote_address,
99 krb5_clear_error_string (context);
100 ret = KRB5KRB_AP_ERR_BADADDR;
104 /* check receiver address */
107 && auth_context->local_address
108 && !krb5_address_compare (context,
109 auth_context->local_address,
111 krb5_clear_error_string (context);
112 ret = KRB5KRB_AP_ERR_BADADDR;
116 /* check timestamp */
117 if (auth_context->flags & KRB5_AUTH_CONTEXT_DO_TIME) {
120 krb5_timeofday (context, &sec);
121 if (part.timestamp == NULL ||
123 abs(*part.timestamp - sec) > context->max_skew) {
124 krb5_clear_error_string (context);
125 ret = KRB5KRB_AP_ERR_SKEW;
130 /* XXX - check replay cache */
132 /* check sequence number. since MIT krb5 cannot generate a sequence
133 number of zero but instead generates no sequence number, we accept that
136 if (auth_context->flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE) {
137 if ((part.seq_number == NULL
138 && auth_context->remote_seqnumber != 0)
139 || (part.seq_number != NULL
140 && *part.seq_number != auth_context->remote_seqnumber)) {
141 krb5_clear_error_string (context);
142 ret = KRB5KRB_AP_ERR_BADORDER;
145 auth_context->remote_seqnumber++;
148 ret = krb5_data_copy (outbuf, part.user_data.data, part.user_data.length);
152 free_EncKrbPrivPart (&part);
153 free_KRB_PRIV (&priv);
157 free_EncKrbPrivPart (&part);
160 free_KRB_PRIV (&priv);