2 * Copyright (c) 2010, 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 #include "gssapiP_eap.h"
36 eapGssSmAcceptAuthenticate(OM_uint32 *minor,
39 gss_buffer_t inputToken,
40 gss_channel_bindings_t chanBindings,
41 gss_buffer_t outputToken)
43 OM_uint32 major, tmpMinor;
50 static struct eap_gss_acceptor_sm {
51 enum gss_eap_token_type inputTokenType;
52 enum gss_eap_token_type outputTokenType;
53 OM_uint32 (*processToken)(OM_uint32 *,
57 gss_channel_bindings_t,
59 } eapGssAcceptorSm[] = {
60 { TOK_TYPE_EAP_RESP, TOK_TYPE_EAP_REQ, NULL },
64 gss_accept_sec_context(OM_uint32 *minor,
65 gss_ctx_id_t *context_handle,
67 gss_buffer_t input_token,
68 gss_channel_bindings_t input_chan_bindings,
71 gss_buffer_t output_token,
74 gss_cred_id_t *delegated_cred_handle)
76 OM_uint32 major, tmpMinor;
77 gss_ctx_id_t ctx = *context_handle;
78 struct eap_gss_acceptor_sm *sm = NULL;
79 gss_buffer_desc innerInputToken, innerOutputToken;
83 innerOutputToken.length = 0;
84 innerOutputToken.value = NULL;
86 output_token->length = 0;
87 output_token->value = NULL;
89 if (cred != GSS_C_NO_CREDENTIAL && !(cred->flags & CRED_FLAG_ACCEPT)) {
93 if (input_token == GSS_C_NO_BUFFER || input_token->length == 0) {
94 return GSS_S_DEFECTIVE_TOKEN;
97 if (ctx == GSS_C_NO_CONTEXT) {
98 major = gssEapAllocContext(minor, &ctx);
102 *context_handle = ctx;
105 GSSEAP_MUTEX_LOCK(&ctx->mutex);
107 sm = &eapGssAcceptorSm[ctx->state];
109 major = gssEapVerifyToken(minor, ctx, input_token,
110 sm->inputTokenType, &innerInputToken);
111 if (GSS_ERROR(major))
114 major = (sm->processToken)(minor,
120 if (GSS_ERROR(major))
123 if (src_name != NULL && ctx->initiatorName != GSS_C_NO_NAME) {
124 major = gss_duplicate_name(&minor, ctx->initiatorName, src_name);
125 if (GSS_ERROR(major))
128 if (mech_type != NULL) {
129 if (!gssEapInternalizeOid(ctx->mechanismUsed, mech_type))
130 duplicateOid(&tmpMinor, ctx->mechanismUsed, mech_type);
132 if (innerOutputToken.length != 0) {
133 major = gssEapMakeToken(minor, ctx, &innerOutputToken,
134 sm->outputTokenType, output_token);
135 if (GSS_ERROR(major))
138 if (ret_flags != NULL)
139 *ret_flags = ctx->gssFlags;
140 if (time_rec != NULL)
141 gss_context_time(&tmpMinor, ctx, time_rec);
142 if (delegated_cred_handle != NULL)
143 *delegated_cred_handle = GSS_C_NO_CREDENTIAL;
145 assert(ctx->state == EAP_STATE_ESTABLISHED || major == GSS_S_CONTINUE_NEEDED);
148 GSSEAP_MUTEX_UNLOCK(&ctx->mutex);
150 if (GSS_ERROR(major))
151 gssEapReleaseContext(&tmpMinor, context_handle);
153 gss_release_buffer(&tmpMinor, &innerOutputToken);