X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=mech_eap%2Faccept_sec_context.c;h=16e60fbd1a1f814227aade4ebc98fd8b87efea1f;hb=806475d7e7d185314fcba8417660369d01ca47f7;hp=6d6564757de1fd85c81a9f381a964b69e1313c87;hpb=315f3c6eea9abad1e3e45bf7b89e63aed1d0419b;p=moonshot.git diff --git a/mech_eap/accept_sec_context.c b/mech_eap/accept_sec_context.c index 6d65647..16e60fb 100644 --- a/mech_eap/accept_sec_context.c +++ b/mech_eap/accept_sec_context.c @@ -42,13 +42,14 @@ static OM_uint32 eapGssSmAcceptGssReauth(OM_uint32 *minor, gss_cred_id_t cred, gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), - gss_OID mech __attribute__((__unused__)), - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), + gss_name_t target, + gss_OID mech, + OM_uint32 reqFlags, + OM_uint32 timeReq, gss_channel_bindings_t chanBindings, gss_buffer_t inputToken, - gss_buffer_t outputToken); + gss_buffer_t outputToken, + OM_uint32 *smFlags); #endif /* @@ -71,7 +72,7 @@ acceptReadyEap(OM_uint32 *minor, gss_ctx_id_t ctx, gss_cred_id_t cred) major = gssEapRadiusGetRawAvp(minor, ctx->acceptorCtx.vps, PW_USER_NAME, 0, &vp); - if (major == GSS_S_COMPLETE) { + if (major == GSS_S_COMPLETE && vp->length) { nameBuf.length = vp->length; nameBuf.value = vp->vp_strvalue; } else { @@ -81,6 +82,7 @@ acceptReadyEap(OM_uint32 *minor, gss_ctx_id_t ctx, gss_cred_id_t cred) major = gssEapImportName(minor, &nameBuf, (ctx->gssFlags & GSS_C_ANON_FLAG) ? GSS_C_NT_ANONYMOUS : GSS_C_NT_USER_NAME, + ctx->mechanismUsed, &ctx->initiatorName); if (GSS_ERROR(major)) return major; @@ -119,10 +121,109 @@ acceptReadyEap(OM_uint32 *minor, gss_ctx_id_t ctx, gss_cred_id_t cred) if (GSS_ERROR(major)) return major; + if (ctx->expiryTime < time(NULL)) { + *minor = GSSEAP_CRED_EXPIRED; + return GSS_S_CREDENTIALS_EXPIRED; + } + *minor = 0; return GSS_S_COMPLETE; } +static OM_uint32 +gssEapSupportedInitiatorExts[] = { +}; + +static struct gss_eap_itok_map +gssEapAcceptorExtsFlagMap[] = { + { ITOK_TYPE_REAUTH_CREDS, CTX_FLAG_KRB_REAUTH_SUPPORTED }, +}; + +static OM_uint32 +eapGssSmAcceptExts(OM_uint32 *minor, + gss_cred_id_t cred GSSEAP_UNUSED, + gss_ctx_id_t ctx GSSEAP_UNUSED, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken, + gss_buffer_t outputToken, + OM_uint32 *smFlags GSSEAP_UNUSED) +{ + OM_uint32 major; + + major = gssEapProcessSupportedExts(minor, inputToken, + gssEapAcceptorExtsFlagMap, + sizeof(gssEapAcceptorExtsFlagMap) / + sizeof(gssEapAcceptorExtsFlagMap[0]), + &ctx->flags); + if (GSS_ERROR(major)) + return major; + + major = gssEapEncodeSupportedExts(minor, + gssEapSupportedInitiatorExts, + sizeof(gssEapSupportedInitiatorExts) / + sizeof(gssEapSupportedInitiatorExts[0]), + outputToken); + if (GSS_ERROR(major)) + return major; + + return GSS_S_CONTINUE_NEEDED; +} + +static OM_uint32 +eapGssSmAcceptAcceptorName(OM_uint32 *minor, + gss_cred_id_t cred GSSEAP_UNUSED, + gss_ctx_id_t ctx, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken GSSEAP_UNUSED, + gss_buffer_t outputToken, + OM_uint32 *smFlags GSSEAP_UNUSED) +{ + OM_uint32 major; + + /* XXX TODO import and validate name from inputToken */ + + if (ctx->acceptorName != GSS_C_NO_NAME) { + /* Send desired target name to acceptor */ + major = gssEapDisplayName(minor, ctx->acceptorName, + outputToken, NULL); + if (GSS_ERROR(major)) + return major; + } + + return GSS_S_CONTINUE_NEEDED; +} + +#ifdef GSSEAP_DEBUG +static OM_uint32 +eapGssSmAcceptVendorInfo(OM_uint32 *minor, + gss_cred_id_t cred GSSEAP_UNUSED, + gss_ctx_id_t ctx GSSEAP_UNUSED, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken, + gss_buffer_t outputToken GSSEAP_UNUSED, + OM_uint32 *smFlags GSSEAP_UNUSED) +{ + fprintf(stderr, "GSS-EAP: vendor: %.*s\n", + (int)inputToken->length, (char *)inputToken->value); + + *minor = 0; + return GSS_S_CONTINUE_NEEDED; +} +#endif + + /* * Emit a identity EAP request to force the initiator (peer) to identify * itself. @@ -131,13 +232,14 @@ static OM_uint32 eapGssSmAcceptIdentity(OM_uint32 *minor, gss_cred_id_t cred, gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), - gss_OID mech __attribute__((__unused__)), - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), - gss_channel_bindings_t chanBindings __attribute__((__unused__)), + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, gss_buffer_t inputToken, - gss_buffer_t outputToken) + gss_buffer_t outputToken, + OM_uint32 *smFlags) { OM_uint32 major; struct wpabuf *reqData; @@ -153,14 +255,6 @@ eapGssSmAcceptIdentity(OM_uint32 *minor, return GSS_S_DEFECTIVE_TOKEN; } - assert(ctx->acceptorName == GSS_C_NO_NAME); - - if (cred->name != GSS_C_NO_NAME) { - major = gssEapDuplicateName(minor, cred->name, &ctx->acceptorName); - if (GSS_ERROR(major)) - return major; - } - reqData = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, 0, EAP_CODE_REQUEST, 0); if (reqData == NULL) { @@ -177,8 +271,12 @@ eapGssSmAcceptIdentity(OM_uint32 *minor, wpabuf_free(reqData); + GSSEAP_SM_TRANSITION_NEXT(ctx); + *minor = 0; - return GSS_S_COMPLETE; /* advance state */ + *smFlags |= SM_FLAG_SEND_TOKEN | SM_FLAG_OUTPUT_TOKEN_CRITICAL; + + return GSS_S_CONTINUE_NEEDED; } /* @@ -223,7 +321,7 @@ importInitiatorIdentity(OM_uint32 *minor, gssEapReleaseName(&tmpMinor, &ctx->initiatorName); return gssEapImportName(minor, &nameBuf, GSS_C_NT_USER_NAME, - &ctx->initiatorName); + ctx->mechanismUsed, &ctx->initiatorName); } /* @@ -371,7 +469,7 @@ createRadiusHandle(OM_uint32 *minor, assert(actx->radContext == NULL); assert(actx->radConn == NULL); - if (rs_context_create(&actx->radContext, RS_DICT_FILE) != 0) { + if (rs_context_create(&actx->radContext) != 0) { *minor = GSSEAP_RADSEC_CONTEXT_FAILURE; return GSS_S_FAILURE; } @@ -393,6 +491,11 @@ createRadiusHandle(OM_uint32 *minor, goto fail; } + if (rs_context_init_freeradius_dict(actx->radContext, NULL) != 0) { + err = rs_err_ctx_pop(actx->radContext); + goto fail; + } + if (rs_conn_create(actx->radContext, &actx->radConn, configStanza) != 0) { err = rs_err_conn_pop(actx->radConn); goto fail; @@ -419,13 +522,14 @@ static OM_uint32 eapGssSmAcceptAuthenticate(OM_uint32 *minor, gss_cred_id_t cred, gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), - gss_OID mech __attribute__((__unused__)), - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), - gss_channel_bindings_t chanBindings, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, gss_buffer_t inputToken, - gss_buffer_t outputToken) + gss_buffer_t outputToken, + OM_uint32 *smFlags) { OM_uint32 major, tmpMinor; struct rs_connection *rconn; @@ -493,8 +597,8 @@ eapGssSmAcceptAuthenticate(OM_uint32 *minor, frresp = rs_packet_frpkt(resp); switch (frresp->code) { - case PW_AUTHENTICATION_ACK: case PW_ACCESS_CHALLENGE: + case PW_AUTHENTICATION_ACK: break; case PW_AUTHENTICATION_REJECT: *minor = GSSEAP_RADIUS_AUTH_FAILURE; @@ -522,46 +626,90 @@ eapGssSmAcceptAuthenticate(OM_uint32 *minor, &ctx->acceptorCtx.state, TRUE); if (GSS_ERROR(major) && *minor != GSSEAP_NO_SUCH_ATTR) goto cleanup; - - major = GSS_S_CONTINUE_NEEDED; } else { ctx->acceptorCtx.vps = frresp->vps; frresp->vps = NULL; - rs_conn_destroy(ctx->acceptorCtx.radConn); - ctx->acceptorCtx.radConn = NULL; - major = acceptReadyEap(minor, ctx, cred); if (GSS_ERROR(major)) goto cleanup; - major = GSS_S_COMPLETE; /* advance state */ + GSSEAP_SM_TRANSITION_NEXT(ctx); } + major = GSS_S_CONTINUE_NEEDED; + *minor = 0; + *smFlags |= SM_FLAG_SEND_TOKEN | SM_FLAG_OUTPUT_TOKEN_CRITICAL; + cleanup: if (request != NULL) rs_request_destroy(request); if (req != NULL) rs_packet_destroy(req); + if (resp != NULL) + rs_packet_destroy(resp); + if (GSSEAP_SM_STATE(ctx) == GSSEAP_STATE_INITIATOR_EXTS) { + assert(major == GSS_S_CONTINUE_NEEDED); + + rs_conn_destroy(ctx->acceptorCtx.radConn); + ctx->acceptorCtx.radConn = NULL; + } return major; } static OM_uint32 +eapGssSmAcceptGssFlags(OM_uint32 *minor, + gss_cred_id_t cred GSSEAP_UNUSED, + gss_ctx_id_t ctx, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken, + gss_buffer_t outputToken GSSEAP_UNUSED, + OM_uint32 *smFlags GSSEAP_UNUSED) +{ + unsigned char *p; + OM_uint32 initiatorGssFlags; + + assert((ctx->flags & CTX_FLAG_KRB_REAUTH) == 0); + + if (inputToken->length < 4) { + *minor = GSSEAP_TOK_TRUNC; + return GSS_S_DEFECTIVE_TOKEN; + } + + /* allow flags to grow for future expansion */ + p = (unsigned char *)inputToken->value + inputToken->length - 4; + + initiatorGssFlags = load_uint32_be(p); + initiatorGssFlags &= GSSEAP_WIRE_FLAGS_MASK; + + ctx->gssFlags |= initiatorGssFlags; + + return GSS_S_CONTINUE_NEEDED; +} + +static OM_uint32 eapGssSmAcceptGssChannelBindings(OM_uint32 *minor, - gss_cred_id_t cred, + gss_cred_id_t cred GSSEAP_UNUSED, gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), - gss_OID mech __attribute__((__unused__)), - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, gss_channel_bindings_t chanBindings, gss_buffer_t inputToken, - gss_buffer_t outputToken) + gss_buffer_t outputToken GSSEAP_UNUSED, + OM_uint32 *smFlags GSSEAP_UNUSED) { OM_uint32 major, tmpMinor; gss_iov_buffer_desc iov[2]; + assert((ctx->flags & CTX_FLAG_KRB_REAUTH) == 0); + iov[0].type = GSS_IOV_BUFFER_TYPE_DATA | GSS_IOV_BUFFER_FLAG_ALLOCATE; iov[0].buffer.length = 0; iov[0].buffer.value = NULL; @@ -572,14 +720,14 @@ eapGssSmAcceptGssChannelBindings(OM_uint32 *minor, major = gssEapUnwrapOrVerifyMIC(minor, ctx, NULL, NULL, iov, 2, TOK_TYPE_WRAP); if (GSS_ERROR(major)) - return GSS_S_BAD_BINDINGS; + return major; if (chanBindings != GSS_C_NO_CHANNEL_BINDINGS && !bufferEqual(&iov[0].buffer, &chanBindings->application_data)) { major = GSS_S_BAD_BINDINGS; *minor = GSSEAP_BINDINGS_MISMATCH; } else { - major = GSS_S_CONTINUE_NEEDED; /* process additional extensions */ + major = GSS_S_CONTINUE_NEEDED; *minor = 0; } @@ -593,13 +741,14 @@ static OM_uint32 eapGssSmAcceptReauthCreds(OM_uint32 *minor, gss_cred_id_t cred, gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), - gss_OID mech __attribute__((__unused__)), - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), - gss_channel_bindings_t chanBindings __attribute__((__unused__)), - gss_buffer_t inputToken, - gss_buffer_t outputToken) + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken GSSEAP_UNUSED, + gss_buffer_t outputToken, + OM_uint32 *smFlags GSSEAP_UNUSED) { OM_uint32 major; @@ -607,81 +756,159 @@ eapGssSmAcceptReauthCreds(OM_uint32 *minor, * If we're built with fast reauthentication enabled, then * fabricate a ticket from the initiator to ourselves. */ - major = gssEapMakeReauthCreds(minor, ctx, cred, outputToken); + if (ctx->flags & CTX_FLAG_KRB_REAUTH_SUPPORTED) + major = gssEapMakeReauthCreds(minor, ctx, cred, outputToken); + else + major = GSS_S_UNAVAILABLE; + + if (major == GSS_S_UNAVAILABLE) + major = GSS_S_COMPLETE; + + return GSS_ERROR(major) ? major : GSS_S_CONTINUE_NEEDED; +} +#endif + +static OM_uint32 +eapGssSmAcceptInitiatorMIC(OM_uint32 *minor, + gss_cred_id_t cred GSSEAP_UNUSED, + gss_ctx_id_t ctx, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken, + gss_buffer_t outputToken GSSEAP_UNUSED, + OM_uint32 *smFlags GSSEAP_UNUSED) +{ + OM_uint32 major; + + assert((ctx->flags & CTX_FLAG_KRB_REAUTH) == 0); + + major = gssEapVerifyConversationMIC(minor, ctx, inputToken); if (GSS_ERROR(major)) return major; + GSSEAP_SM_TRANSITION_NEXT(ctx); + *minor = 0; - return GSS_S_CONTINUE_NEEDED; /* process additional extensions */ + + return GSS_S_CONTINUE_NEEDED; } -#endif static OM_uint32 -eapGssSmAcceptNegoExtFinished(OM_uint32 *minor, - gss_cred_id_t cred, - gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), - gss_OID mech __attribute__((__unused__)), - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), - gss_channel_bindings_t chanBindings __attribute__((__unused__)), - gss_buffer_t inputToken, - gss_buffer_t outputToken) +eapGssSmAcceptAcceptorMIC(OM_uint32 *minor, + gss_cred_id_t cred GSSEAP_UNUSED, + gss_ctx_id_t ctx, + gss_name_t target GSSEAP_UNUSED, + gss_OID mech GSSEAP_UNUSED, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t chanBindings GSSEAP_UNUSED, + gss_buffer_t inputToken GSSEAP_UNUSED, + gss_buffer_t outputToken, + OM_uint32 *smFlags) { + OM_uint32 major; + + major = gssEapGetConversationMIC(minor, ctx, outputToken); + if (GSS_ERROR(major)) + return major; + + GSSEAP_SM_TRANSITION(ctx, GSSEAP_STATE_ESTABLISHED); + *minor = 0; - return GSS_S_COMPLETE; /* advance state */ + *smFlags |= SM_FLAG_SEND_TOKEN | SM_FLAG_OUTPUT_TOKEN_CRITICAL; + + return GSS_S_COMPLETE; } +/* + * Acceptor state machine. + */ static struct gss_eap_sm eapGssAcceptorSm[] = { #ifdef GSSEAP_ENABLE_REAUTH { ITOK_TYPE_REAUTH_REQ, ITOK_TYPE_REAUTH_RESP, - GSSEAP_STATE_INITIAL, - 0, /* critical */ - 0, /* required */ + GSSEAP_STATE_INITIAL | GSSEAP_STATE_REAUTHENTICATE, + 0, eapGssSmAcceptGssReauth, }, #endif { + ITOK_TYPE_ACCEPTOR_NAME_REQ, + ITOK_TYPE_ACCEPTOR_NAME_RESP, + GSSEAP_STATE_INITIAL, + 0, + eapGssSmAcceptAcceptorName + }, + { + ITOK_TYPE_SUPPORTED_ACCEPTOR_EXTS, + ITOK_TYPE_SUPPORTED_INITIATOR_EXTS, + GSSEAP_STATE_INITIAL, + 0, + eapGssSmAcceptExts, + }, +#ifdef GSSEAP_DEBUG + { + ITOK_TYPE_VENDOR_INFO, + ITOK_TYPE_NONE, + GSSEAP_STATE_INITIAL, + 0, + eapGssSmAcceptVendorInfo, + }, +#endif + { ITOK_TYPE_NONE, ITOK_TYPE_EAP_REQ, GSSEAP_STATE_INITIAL, - 1, /* critical */ - 1, /* required */ + SM_ITOK_FLAG_REQUIRED, eapGssSmAcceptIdentity, }, { ITOK_TYPE_EAP_RESP, ITOK_TYPE_EAP_REQ, GSSEAP_STATE_AUTHENTICATE, - 1, /* critical */ - 1, /* required */ + SM_ITOK_FLAG_REQUIRED, eapGssSmAcceptAuthenticate }, { + ITOK_TYPE_GSS_FLAGS, + ITOK_TYPE_NONE, + GSSEAP_STATE_INITIATOR_EXTS, + 0, + eapGssSmAcceptGssFlags + }, + { ITOK_TYPE_GSS_CHANNEL_BINDINGS, ITOK_TYPE_NONE, - GSSEAP_STATE_NEGO_EXT, - 1, /* critical */ - 1, /* required */ + GSSEAP_STATE_INITIATOR_EXTS, + 0, eapGssSmAcceptGssChannelBindings, }, { + ITOK_TYPE_INITIATOR_MIC, + ITOK_TYPE_NONE, + GSSEAP_STATE_INITIATOR_EXTS, + SM_ITOK_FLAG_REQUIRED, + eapGssSmAcceptInitiatorMIC, + }, +#ifdef GSSEAP_ENABLE_REAUTH + { ITOK_TYPE_NONE, ITOK_TYPE_REAUTH_CREDS, - GSSEAP_STATE_NEGO_EXT, - 0, /* critical */ - 0, /* required */ + GSSEAP_STATE_ACCEPTOR_EXTS, + 0, eapGssSmAcceptReauthCreds, }, +#endif { ITOK_TYPE_NONE, - ITOK_TYPE_NONE, - GSSEAP_STATE_NEGO_EXT, - 1, /* critical */ - 1, /* required */ - eapGssSmAcceptNegoExtFinished + ITOK_TYPE_ACCEPTOR_MIC, + GSSEAP_STATE_ACCEPTOR_EXTS, + 0, + eapGssSmAcceptAcceptorMIC }, }; @@ -744,6 +971,12 @@ gss_accept_sec_context(OM_uint32 *minor, GSSEAP_MUTEX_LOCK(&cred->mutex); + if (cred->name != GSS_C_NO_NAME) { + major = gssEapDuplicateName(minor, cred->name, &ctx->acceptorName); + if (GSS_ERROR(major)) + goto cleanup; + } + major = gssEapSmStep(minor, cred, ctx, @@ -760,8 +993,14 @@ gss_accept_sec_context(OM_uint32 *minor, goto cleanup; if (mech_type != NULL) { - if (!gssEapInternalizeOid(ctx->mechanismUsed, mech_type)) - duplicateOid(&tmpMinor, ctx->mechanismUsed, mech_type); + OM_uint32 tmpMajor; + + tmpMajor = gssEapCanonicalizeOid(&tmpMinor, ctx->mechanismUsed, 0, mech_type); + if (GSS_ERROR(tmpMajor)) { + major = tmpMajor; + *minor = tmpMinor; + goto cleanup; + } } if (ret_flags != NULL) *ret_flags = ctx->gssFlags; @@ -781,7 +1020,7 @@ gss_accept_sec_context(OM_uint32 *minor, } } - assert(ctx->state == GSSEAP_STATE_ESTABLISHED || major == GSS_S_CONTINUE_NEEDED); + assert(CTX_IS_ESTABLISHED(ctx) || major == GSS_S_CONTINUE_NEEDED); cleanup: if (cred != GSS_C_NO_CREDENTIAL) @@ -809,37 +1048,31 @@ acceptReadyKrb(OM_uint32 *minor, if (GSS_ERROR(major)) return major; - if (cred->name != GSS_C_NO_NAME) { - major = gssEapDuplicateName(minor, cred->name, &ctx->acceptorName); - if (GSS_ERROR(major)) - return major; - } - major = gssEapReauthComplete(minor, ctx, cred, mech, timeRec); if (GSS_ERROR(major)) return major; - ctx->state = GSSEAP_STATE_NEGO_EXT; /* skip */ - *minor = 0; - return GSS_S_COMPLETE; /* advance state */ + return GSS_S_COMPLETE; } static OM_uint32 eapGssSmAcceptGssReauth(OM_uint32 *minor, gss_cred_id_t cred, gss_ctx_id_t ctx, - gss_name_t target __attribute__((__unused__)), + gss_name_t target GSSEAP_UNUSED, gss_OID mech, - OM_uint32 reqFlags __attribute__((__unused__)), - OM_uint32 timeReq __attribute__((__unused__)), - gss_channel_bindings_t chanBindings, + OM_uint32 reqFlags GSSEAP_UNUSED, + OM_uint32 timeReq GSSEAP_UNUSED, + gss_channel_bindings_t userChanBindings, gss_buffer_t inputToken, - gss_buffer_t outputToken) + gss_buffer_t outputToken, + OM_uint32 *smFlags) { OM_uint32 major, tmpMinor; gss_name_t krbInitiator = GSS_C_NO_NAME; OM_uint32 gssFlags, timeRec = GSS_C_INDEFINITE; + struct gss_channel_bindings_struct wireChanBindings = { 0 }; /* * If we're built with fast reauthentication support, it's valid @@ -850,11 +1083,25 @@ eapGssSmAcceptGssReauth(OM_uint32 *minor, ctx->flags |= CTX_FLAG_KRB_REAUTH; + /* + * To avoid an additional round trip, we use GSS channel bindings + * to integrity protect the rest of the initiator exchange. This + * does have the disadvantage of making it impossible for the + * acceptor to ignore application channel bindings, behaviour + * which differs from normal Kerberos and GSS-EAP itself. + */ + major = gssEapMakeTokenChannelBindings(minor, ctx, + userChanBindings, + inputToken, + &wireChanBindings); + if (GSS_ERROR(major)) + return major; + major = gssAcceptSecContext(minor, &ctx->kerberosCtx, cred->krbCred, inputToken, - chanBindings, + &wireChanBindings, &krbInitiator, &mech, outputToken, @@ -864,11 +1111,25 @@ eapGssSmAcceptGssReauth(OM_uint32 *minor, if (major == GSS_S_COMPLETE) { major = acceptReadyKrb(minor, ctx, cred, krbInitiator, mech, timeRec); + if (major == GSS_S_COMPLETE) { + /* Generate acceptor MIC */ + GSSEAP_SM_TRANSITION(ctx, GSSEAP_STATE_ACCEPTOR_EXTS); + } + ctx->gssFlags = gssFlags; + } else if (GSS_ERROR(major) && + (*smFlags & SM_FLAG_INPUT_TOKEN_CRITICAL) == 0) { + /* Fall back to EAP */ + gssDeleteSecContext(&tmpMinor, &ctx->kerberosCtx, GSS_C_NO_BUFFER); + ctx->flags &= ~(CTX_FLAG_KRB_REAUTH); + GSSEAP_SM_TRANSITION(ctx, GSSEAP_STATE_INITIAL); + } else { + GSSEAP_SM_TRANSITION(ctx, GSSEAP_STATE_REAUTHENTICATE); } - ctx->gssFlags = gssFlags; + major = GSS_S_CONTINUE_NEEDED; gssReleaseName(&tmpMinor, &krbInitiator); + gss_release_buffer(&tmpMinor, &wireChanBindings.application_data); return major; }