X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=unwrap.c;h=ae35bf9f9222d84ac51c5f3610cf669c0f262ca1;hb=refs%2Fheads%2Fjson-name;hp=3e0654bfc89622e45b276dd4605e2a0311459de1;hpb=31cef49681566dc99790812f31de834dfce02c74;p=mech_eap.orig diff --git a/unwrap.c b/unwrap.c index 3e0654b..ae35bf9 100644 --- a/unwrap.c +++ b/unwrap.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, JANET(UK) + * Copyright (c) 2011, JANET(UK) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,5 +30,56 @@ * SUCH DAMAGE. */ +/* + * Message protection services: unwrap. + */ + #include "gssapiP_eap.h" +OM_uint32 +gss_unwrap(OM_uint32 *minor, + gss_ctx_id_t ctx, + gss_buffer_t input_message_buffer, + gss_buffer_t output_message_buffer, + int *conf_state, + gss_qop_t *qop_state) +{ + OM_uint32 major, tmpMinor; + gss_iov_buffer_desc iov[2]; + + if (ctx == GSS_C_NO_CONTEXT) { + *minor = EINVAL; + return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT; + } + + *minor = 0; + + GSSEAP_MUTEX_LOCK(&ctx->mutex); + + if (!CTX_IS_ESTABLISHED(ctx)) { + major = GSS_S_NO_CONTEXT; + *minor = GSSEAP_CONTEXT_INCOMPLETE; + goto cleanup; + } + + iov[0].type = GSS_IOV_BUFFER_TYPE_STREAM; + iov[0].buffer = *input_message_buffer; + + iov[1].type = GSS_IOV_BUFFER_TYPE_DATA | GSS_IOV_BUFFER_FLAG_ALLOCATE; + iov[1].buffer.value = NULL; + iov[1].buffer.length = 0; + + major = gssEapUnwrapOrVerifyMIC(minor, ctx, conf_state, qop_state, + iov, 2, TOK_TYPE_WRAP); + if (major == GSS_S_COMPLETE) { + *output_message_buffer = iov[1].buffer; + } else { + if (iov[1].type & GSS_IOV_BUFFER_FLAG_ALLOCATED) + gss_release_buffer(&tmpMinor, &iov[1].buffer); + } + +cleanup: + GSSEAP_MUTEX_UNLOCK(&ctx->mutex); + + return major; +}