2 * Copyright (c) 2011, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright 1993 by OpenVision Technologies, Inc.
35 * Permission to use, copy, modify, distribute, and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appears in all copies and
38 * that both that copyright notice and this permission notice appear in
39 * supporting documentation, and that the name of OpenVision not be used
40 * in advertising or publicity pertaining to distribution of the software
41 * without specific, written prior permission. OpenVision makes no
42 * representations about the suitability of this software for any
43 * purpose. It is provided "as is" without express or implied warranty.
45 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
46 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
47 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
48 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
49 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
50 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
51 * PERFORMANCE OF THIS SOFTWARE.
55 * Message protection services: checksum helpers.
58 #include "gssapiP_eap.h"
61 gssEapChecksum(krb5_context context,
64 #ifdef HAVE_HEIMDAL_VERSION
67 krb5_keyblock *crypto,
69 krb5_keyusage sign_usage,
70 gss_iov_buffer_desc *iov,
76 gss_iov_buffer_desc *header;
77 gss_iov_buffer_desc *trailer;
78 krb5_crypto_iov *kiov;
81 size_t k5_checksumlen;
86 code = krbCryptoLength(context, crypto, KRB5_CRYPTO_TYPE_CHECKSUM, &k5_checksumlen);
90 header = gssEapLocateIov(iov, iov_count, GSS_IOV_BUFFER_TYPE_HEADER);
91 GSSEAP_ASSERT(header != NULL);
93 trailer = gssEapLocateIov(iov, iov_count, GSS_IOV_BUFFER_TYPE_TRAILER);
94 GSSEAP_ASSERT(rrc != 0 || trailer != NULL);
96 if (trailer == NULL) {
97 if (rrc != k5_checksumlen)
98 return KRB5_BAD_MSIZE;
99 if (header->buffer.length != 16 + k5_checksumlen)
100 return KRB5_BAD_MSIZE;
101 } else if (trailer->buffer.length != k5_checksumlen)
102 return KRB5_BAD_MSIZE;
104 kiov_count = 2 + iov_count;
105 kiov = (krb5_crypto_iov *)GSSEAP_MALLOC(kiov_count * sizeof(krb5_crypto_iov));
109 /* Checksum over ( Data | Header ) */
112 for (j = 0; j < iov_count; j++) {
113 kiov[i].flags = gssEapMapCryptoFlag(iov[j].type);
114 kiov[i].data.length = iov[j].buffer.length;
115 kiov[i].data.data = (char *)iov[j].buffer.value;
120 kiov[i].flags = KRB5_CRYPTO_TYPE_SIGN_ONLY;
121 kiov[i].data.length = 16;
122 kiov[i].data.data = (char *)header->buffer.value;
126 kiov[i].flags = KRB5_CRYPTO_TYPE_CHECKSUM;
127 if (trailer == NULL) {
128 kiov[i].data.length = header->buffer.length - 16;
129 kiov[i].data.data = (char *)header->buffer.value + 16;
131 kiov[i].data.length = trailer->buffer.length;
132 kiov[i].data.data = (char *)trailer->buffer.value;
136 #ifdef HAVE_HEIMDAL_VERSION
138 code = krb5_verify_checksum_iov(context, crypto, sign_usage,
139 kiov, kiov_count, &type);
140 *valid = (code == 0);
142 code = krb5_create_checksum_iov(context, crypto, sign_usage,
143 kiov, kiov_count, &type);
147 krb5_boolean kvalid = FALSE;
149 code = krb5_c_verify_checksum_iov(context, type, crypto,
150 sign_usage, kiov, kiov_count, &kvalid);
154 code = krb5_c_make_checksum_iov(context, type, crypto,
155 sign_usage, kiov, kiov_count);
157 #endif /* HAVE_HEIMDAL_VERSION */
165 gssEapSign(krb5_context context,
168 #ifdef HAVE_HEIMDAL_VERSION
171 krb5_keyblock *crypto,
173 krb5_keyusage sign_usage,
174 gss_iov_buffer_desc *iov,
177 return gssEapChecksum(context, type, rrc, crypto,
178 sign_usage, iov, iov_count, 0, NULL);
182 gssEapVerify(krb5_context context,
185 #ifdef HAVE_HEIMDAL_VERSION
188 krb5_keyblock *crypto,
190 krb5_keyusage sign_usage,
191 gss_iov_buffer_desc *iov,
195 return gssEapChecksum(context, type, rrc, crypto,
196 sign_usage, iov, iov_count, 1, valid);
201 gssEapEncodeGssChannelBindings(OM_uint32 *minor,
202 gss_channel_bindings_t chanBindings,
203 gss_buffer_t encodedBindings)
205 OM_uint32 major, tmpMinor;
209 if (chanBindings != GSS_C_NO_CHANNEL_BINDINGS) {
211 length += chanBindings->initiator_address.length;
212 length += chanBindings->acceptor_address.length;
213 length += chanBindings->application_data.length;
215 encodedBindings->value = GSSEAP_MALLOC(length);
216 if (encodedBindings->value == NULL) {
218 return GSS_S_FAILURE;
221 encodedBindings->length = length;
222 p = (unsigned char *)encodedBindings->value;
224 store_uint32_be(chanBindings->initiator_addrtype, p);
225 store_buffer(&chanBindings->initiator_address, p + 4, 0);
226 p += 4 + chanBindings->initiator_address.length;
228 store_uint32_be(chanBindings->acceptor_addrtype, p);
229 store_buffer(&chanBindings->acceptor_address, p + 4, 0);
230 p += 4 + chanBindings->acceptor_address.length;
232 store_buffer(&chanBindings->application_data, p, 1);
233 p += chanBindings->application_data.length;
235 encodedBindings->length = 0;
236 encodedBindings->value = NULL;
240 return GSS_S_COMPLETE;