return GSS_S_COMPLETE;
}
-static OM_uint32
-recordTokens(OM_uint32 *minor,
- gss_ctx_id_t ctx,
- gss_buffer_t tokens,
- size_t tokensCount)
+OM_uint32
+gssEapContextTime(OM_uint32 *minor,
+ gss_ctx_id_t context_handle,
+ OM_uint32 *time_rec)
{
- unsigned char *buf;
- size_t i, size, offset;
-
- size = ctx->conversation.length;
-
- for (i = 0; i < tokensCount; i++)
- size += tokens[i].length;
-
- buf = GSSEAP_REALLOC(ctx->conversation.value, size);
- if (buf == NULL) {
- *minor = ENOMEM;
- return GSS_S_FAILURE;
- }
-
- offset = ctx->conversation.length;
+ *minor = 0;
- ctx->conversation.length = size;
- ctx->conversation.value = buf;
+ if (context_handle->expiryTime == 0) {
+ *time_rec = GSS_C_INDEFINITE;
+ } else {
+ time_t now, lifetime;
- for (i = 0; i < tokensCount; i++) {
- memcpy(buf + offset, tokens[i].value, tokens[i].length);
- offset += tokens[i].length;
+ time(&now);
+ lifetime = context_handle->expiryTime - now;
+ if (lifetime <= 0) {
+ *time_rec = 0;
+ return GSS_S_CONTEXT_EXPIRED;
+ }
+ *time_rec = lifetime;
}
- *minor = 0;
return GSS_S_COMPLETE;
}
OM_uint32
-gssEapRecordContextTokenHeader(OM_uint32 *minor,
- gss_ctx_id_t ctx,
- enum gss_eap_token_type tokType)
+gssEapGetConversationMIC(OM_uint32 *minor,
+ gss_ctx_id_t ctx,
+ gss_buffer_t convMIC)
{
- unsigned char wireOidHeader[2], wireTokType[2];
- gss_buffer_desc buffers[3];
+ OM_uint32 major;
+ gss_iov_buffer_desc iov[2];
+
+ iov[0].type = GSS_IOV_BUFFER_TYPE_DATA;
+ iov[0].buffer = ctx->conversation;
- assert(ctx->mechanismUsed != GSS_C_NO_OID);
+ iov[1].type = GSS_IOV_BUFFER_TYPE_HEADER | GSS_IOV_BUFFER_FLAG_ALLOCATE;
+ iov[1].buffer.length = 0;
+ iov[1].buffer.value = NULL;
- wireOidHeader[0] = 0x06;
- wireOidHeader[1] = ctx->mechanismUsed->length;
- buffers[0].length = sizeof(wireOidHeader);
- buffers[0].value = wireOidHeader;
+ major = gssEapWrapOrGetMIC(minor, ctx, FALSE, NULL, iov, 2, TOK_TYPE_MIC);
+ if (GSS_ERROR(major))
+ return major;
- buffers[1].length = ctx->mechanismUsed->length;
- buffers[1].value = ctx->mechanismUsed->elements;
+ *convMIC = iov[1].buffer;
- store_uint16_be(tokType, wireTokType);
- buffers[2].length = sizeof(wireTokType);
- buffers[2].value = wireTokType;
-
- return recordTokens(minor, ctx, buffers, sizeof(buffers)/sizeof(buffers[0]));
+ *minor = 0;
+ return GSS_S_COMPLETE;
}
OM_uint32
-gssEapRecordInnerContextToken(OM_uint32 *minor,
- gss_ctx_id_t ctx,
- gss_buffer_t innerToken,
- OM_uint32 itokType)
+gssEapVerifyConversationMIC(OM_uint32 *minor,
+ gss_ctx_id_t ctx,
+ const gss_buffer_t convMIC)
{
- gss_buffer_desc buffers[3];
- unsigned char wireItokType[4], wireLength[4];
+ OM_uint32 major;
+ gss_iov_buffer_desc iov[3];
+ int confState;
+ size_t tokenHeaderLength;
+
+ if (convMIC == GSS_C_NO_BUFFER || convMIC->length < 16) {
+ *minor = GSSEAP_TOK_TRUNC;
+ return GSS_S_BAD_SIG;
+ }
+
+ iov[0].type = GSS_IOV_BUFFER_TYPE_DATA;
+ iov[0].buffer = ctx->conversation;
+
+ /*
+ * The conversation state already includes the MIC and its
+ * TLV header, as well as a header for emiting a subsequent
+ * token. These should not be included as input to verifyMIC.
+ */
+ tokenHeaderLength = ITOK_HEADER_LENGTH + convMIC->length
+ + 2 + ctx->mechanismUsed->length + 2;
+ assert(ctx->conversation.length >= tokenHeaderLength);
+ iov[0].buffer.length -= tokenHeaderLength;
- assert(innerToken != GSS_C_NO_BUFFER);
+ iov[1].type = GSS_IOV_BUFFER_TYPE_HEADER;
+ iov[1].buffer.length = 16;
+ iov[1].buffer.value = convMIC->value;
- store_uint32_be(itokType, wireItokType);
- buffers[0].length = sizeof(wireItokType);
- buffers[0].value = wireItokType;
+ iov[2].type = GSS_IOV_BUFFER_TYPE_TRAILER;
+ iov[2].buffer.length = convMIC->length - 16;
+ iov[2].buffer.value = (unsigned char *)convMIC->value + 16;
- store_uint32_be(innerToken->length, wireLength);
- buffers[1].length = sizeof(wireLength);
- buffers[1].value = wireLength;
+ major = gssEapUnwrapOrVerifyMIC(minor, ctx, &confState, NULL,
+ iov, 3, TOK_TYPE_MIC);
- buffers[2] = *innerToken;
- return recordTokens(minor, ctx, buffers, sizeof(buffers)/sizeof(buffers[0]));
+ return major;
}
OM_uint32
-gssEapVerifyContextToken(OM_uint32 *minor,
- gss_ctx_id_t ctx,
- const gss_buffer_t inputToken,
- enum gss_eap_token_type tokType,
- gss_buffer_t innerInputToken)
+gssEapMakeTokenChannelBindings(OM_uint32 *minor,
+ gss_ctx_id_t ctx,
+ gss_channel_bindings_t userChanBindings,
+ gss_buffer_t inputToken,
+ gss_channel_bindings_t wireChanBindings)
{
- OM_uint32 major;
- size_t bodySize;
- unsigned char *p = (unsigned char *)inputToken->value;
- gss_OID_desc oidBuf;
- gss_OID oid;
- enum gss_eap_token_type actualTokType;
- gss_buffer_desc tokenBuf;
-
- if (ctx->mechanismUsed != GSS_C_NO_OID) {
- oid = ctx->mechanismUsed;
- } else {
- oidBuf.elements = NULL;
- oidBuf.length = 0;
- oid = &oidBuf;
- }
+ gss_buffer_t wireData = &wireChanBindings->application_data;
+ unsigned char *p;
+ size_t tokenHeaderLength = 0;
- major = verifyTokenHeader(minor, oid, &bodySize, &p,
- inputToken->length, &actualTokType);
- if (GSS_ERROR(major))
- return major;
+ memset(wireChanBindings, 0, sizeof(*wireChanBindings));
- if (actualTokType != tokType) {
- *minor = GSSEAP_WRONG_TOK_ID;
- return GSS_S_DEFECTIVE_TOKEN;
- }
-
- if (ctx->mechanismUsed == GSS_C_NO_OID) {
- if (!gssEapIsConcreteMechanismOid(oid)) {
- *minor = GSSEAP_WRONG_MECH;
- return GSS_S_BAD_MECH;
- }
+ if (!CTX_IS_INITIATOR(ctx)) {
+ assert(inputToken != GSS_C_NO_BUFFER);
- if (!gssEapInternalizeOid(oid, &ctx->mechanismUsed)) {
- major = duplicateOid(minor, oid, &ctx->mechanismUsed);
- if (GSS_ERROR(major))
- return major;
- }
+ tokenHeaderLength = ITOK_HEADER_LENGTH + inputToken->length +
+ 2 + ctx->mechanismUsed->length + 2;
+ assert(ctx->conversation.length >= tokenHeaderLength);
}
- innerInputToken->length = bodySize;
- innerInputToken->value = p;
+ wireData->length = ctx->conversation.length - tokenHeaderLength;
- /*
- * Add OID, tokenType, body to conversation; variable length
- * header omitted. A better API to verifyTokenHeader would
- * avoid this ugly pointer arithmetic. XXX FIXME
- */
- tokenBuf.value = p - (2 + oid->length + 2);
- tokenBuf.length = 2 + oid->length + 2 + bodySize;
+ if (userChanBindings != GSS_C_NO_CHANNEL_BINDINGS)
+ wireData->length += userChanBindings->application_data.length;
- major = recordTokens(minor, ctx, &tokenBuf, 1);
- if (GSS_ERROR(major))
- return major;
+ wireData->value = GSSEAP_MALLOC(wireData->length);
+ if (wireData->value == NULL) {
+ *minor = ENOMEM;
+ return GSS_S_FAILURE;
+ }
- *minor = 0;
- return GSS_S_COMPLETE;
-}
+ p = (unsigned char *)wireData->value;
-OM_uint32
-gssEapContextTime(OM_uint32 *minor,
- gss_ctx_id_t context_handle,
- OM_uint32 *time_rec)
-{
- if (context_handle->expiryTime == 0) {
- *time_rec = GSS_C_INDEFINITE;
- } else {
- time_t now, lifetime;
+ memcpy(p, ctx->conversation.value, ctx->conversation.length - tokenHeaderLength);
+ p += ctx->conversation.length - tokenHeaderLength;
- time(&now);
- lifetime = context_handle->expiryTime - now;
- if (lifetime <= 0) {
- *time_rec = 0;
- return GSS_S_CONTEXT_EXPIRED;
- }
- *time_rec = lifetime;
+ if (userChanBindings != GSS_C_NO_CHANNEL_BINDINGS) {
+ memcpy(p, userChanBindings->application_data.value,
+ userChanBindings->application_data.length);
+ p += userChanBindings->application_data.length;
}
+ *minor = 0;
return GSS_S_COMPLETE;
}