1 /* $NetBSD: rd_rep.c,v 1.1.1.2 2014/04/24 12:45:51 pettai Exp $ */
4 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "krb5_locl.h"
38 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
39 krb5_rd_rep(krb5_context context
,
40 krb5_auth_context auth_context
,
41 const krb5_data
*inbuf
,
42 krb5_ap_rep_enc_part
**repl
)
50 krb5_data_zero (&data
);
52 ret
= decode_AP_REP(inbuf
->data
, inbuf
->length
, &ap_rep
, &len
);
55 if (ap_rep
.pvno
!= 5) {
56 ret
= KRB5KRB_AP_ERR_BADVERSION
;
57 krb5_clear_error_message (context
);
60 if (ap_rep
.msg_type
!= krb_ap_rep
) {
61 ret
= KRB5KRB_AP_ERR_MSG_TYPE
;
62 krb5_clear_error_message (context
);
66 ret
= krb5_crypto_init(context
, auth_context
->keyblock
, 0, &crypto
);
69 ret
= krb5_decrypt_EncryptedData (context
,
71 KRB5_KU_AP_REQ_ENC_PART
,
74 krb5_crypto_destroy(context
, crypto
);
78 *repl
= malloc(sizeof(**repl
));
81 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
84 ret
= decode_EncAPRepPart(data
.data
, data
.length
, *repl
, &len
);
86 krb5_set_error_message(context
, ret
, N_("Failed to decode EncAPRepPart", ""));
90 if (auth_context
->flags
& KRB5_AUTH_CONTEXT_DO_TIME
) {
91 if ((*repl
)->ctime
!= auth_context
->authenticator
->ctime
||
92 (*repl
)->cusec
!= auth_context
->authenticator
->cusec
)
94 krb5_free_ap_rep_enc_part(context
, *repl
);
96 ret
= KRB5KRB_AP_ERR_MUT_FAIL
;
97 krb5_clear_error_message (context
);
101 if ((*repl
)->seq_number
)
102 krb5_auth_con_setremoteseqnumber(context
, auth_context
,
103 *((*repl
)->seq_number
));
105 krb5_auth_con_setremotesubkey(context
, auth_context
, (*repl
)->subkey
);
108 krb5_data_free (&data
);
109 free_AP_REP (&ap_rep
);
113 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
114 krb5_free_ap_rep_enc_part (krb5_context context
,
115 krb5_ap_rep_enc_part
*val
)
118 free_EncAPRepPart (val
);