#endif
/*
- * Mark a context as ready for cryptographic operations
+ * Mark an acceptor context as ready for cryptographic operations
*/
static OM_uint32
acceptReadyEap(OM_uint32 *minor, gss_ctx_id_t ctx, gss_cred_id_t cred)
return GSS_S_COMPLETE;
}
+/*
+ * Emit a identity EAP request to force the initiator (peer) to identify
+ * itself.
+ */
static OM_uint32
eapGssSmAcceptIdentity(OM_uint32 *minor,
gss_ctx_id_t ctx,
return GSS_S_CONTINUE_NEEDED;
}
+/*
+ * Pass the asserted acceptor identity to the authentication server.
+ */
static OM_uint32
setAcceptorIdentity(OM_uint32 *minor,
gss_ctx_id_t ctx,
return GSS_S_COMPLETE;
}
+/*
+ * Allocate a RadSec handle
+ */
static OM_uint32
createRadiusHandle(OM_uint32 *minor,
gss_cred_id_t cred,
return gssEapRadiusMapError(minor, err);
}
+/*
+ * Process a EAP response from the initiator.
+ */
static OM_uint32
eapGssSmAcceptAuthenticate(OM_uint32 *minor,
gss_ctx_id_t ctx,
if (frresp->code == PW_ACCESS_CHALLENGE) {
major = gssEapRadiusGetAvp(minor, frresp->vps, PW_STATE, 0,
&ctx->acceptorCtx.state, TRUE);
- if (major != GSS_S_UNAVAILABLE && GSS_ERROR(major))
+ if (GSS_ERROR(major) && *minor != GSSEAP_NO_SUCH_ATTR)
goto cleanup;
} else {
ctx->acceptorCtx.vps = frresp->vps;
case GSSEAP_MISSING_EAP_REQUEST:
break;
default:
- /* Don't return system error codes */
if (IS_RADIUS_ERROR(minorStatus))
+ /* Squash RADIUS error codes */
minorStatus = GSSEAP_GENERIC_RADIUS_ERROR;
else
+ /* Don't return system error codes */
return GSS_S_COMPLETE;
}
input_chan_bindings,
&innerOutputToken);
if (GSS_ERROR(major)) {
- /* Generate an error token */
+ /* Possibly generate an error token */
tmpMajor = makeErrorToken(&tmpMinor, major, *minor, &innerOutputToken);
if (GSS_ERROR(tmpMajor)) {
major = tmpMajor;
GSSEAP_KEY_CREATE(&gssEapStatusInfoKey, destroyStatusInfo);
}
+/*
+ * Associate a message with a mechanism (minor) status code. This function
+ * takes ownership of the message regardless of success. The message must
+ * be explicitly cleared, if required, so it is suggested that a specific
+ * minor code is either always or never associated with a message, to avoid
+ * dangling (and potentially confusing) error messages.
+ */
static void
saveStatusInfoNoCopy(OM_uint32 minor, char *message)
{
p = GSSEAP_GETSPECIFIC(gssEapStatusInfoKey);
for (; p != NULL; p = p->next) {
if (p->code == minor) {
- GSSEAP_FREE(p->message);
+ /* Set message in-place */
+ if (p->message != NULL)
+ GSSEAP_FREE(p->message);
p->message = message;
return;
}
p = GSSEAP_CALLOC(1, sizeof(*p));
if (p == NULL) {
- GSSEAP_FREE(message);
+ if (message != NULL)
+ GSSEAP_FREE(message);
return;
}
if (errMsg == NULL) {
GSSEAP_KRB_INIT(&krbContext);
+ /* Try the com_err message */
errMsg = krb5_get_error_message(krbContext, status_value);
}
#include "gssapiP_eap.h"
+/*
+ * Export a partially established acceptor context.
+ */
static OM_uint32
gssEapExportPartialContext(OM_uint32 *minor,
gss_ctx_id_t ctx,
unsigned char *p;
if ((CTX_IS_INITIATOR(ctx) && !CTX_IS_ESTABLISHED(ctx)) ||
- ctx->mechanismUsed == GSS_C_NO_OID)
+ ctx->mechanismUsed == GSS_C_NO_OID) {
+ *minor = GSSEAP_CONTEXT_INCOMPLETE;
return GSS_S_NO_CONTEXT;
+ }
key.length = KRB_KEY_LENGTH(&ctx->rfc3961Key);
key.value = KRB_KEY_DATA(&ctx->rfc3961Key);
error_code GSSEAP_BAD_CONTEXT_TOKEN, "Context token is malformed or corrupt"
error_code GSSEAP_MISSING_IOV, "IOV is missing required buffer"
error_code GSSEAP_BAD_STREAM_IOV, "Stream IOV can only contain a single data buffer"
+error_code GSSEAP_BAD_PADDING_IOV, "Padding IOV is not permitted for RFC 4121 tokens"
error_code GSSEAP_BAD_PRF_KEY, "PRF key usage type is unknown"
error_code GSSEAP_BAD_ERROR_TOKEN, "Error token is malformed or corrupt"
+error_code GSSEAP_BAD_WRAP_TOKEN, "Bad RFC 4121 wrap or MIC token"
end
return GSS_S_COMPLETE;
}
+/*
+ * Mark an initiator context as ready for cryptographic operations
+ */
static OM_uint32
initReady(OM_uint32 *minor, gss_ctx_id_t ctx, OM_uint32 reqFlags)
{
if (sasl_mech_name != GSS_C_NO_BUFFER) {
name = gssEapOidToSaslName(mech);
- if (name == GSS_C_NO_BUFFER)
+ if (name == GSS_C_NO_BUFFER) {
+ *minor = GSSEAP_WRONG_MECH;
major = GSS_S_BAD_MECH;
- else
+ } else {
major = duplicateBuffer(minor, name, sasl_mech_name);
+ }
}
return major;
size_t i;
if (!gssEapIsMechanismOid(mechanism)) {
- *minor = 0;
+ *minor = GSSEAP_WRONG_MECH;
return GSS_S_BAD_MECH;
}
gss_OID *mech_type)
{
*mech_type = gssEapSaslNameToOid(sasl_mech_name);
- if (*mech_type == GSS_C_NO_OID)
+ if (*mech_type == GSS_C_NO_OID) {
+ *minor = GSSEAP_WRONG_MECH;
return GSS_S_BAD_MECH;
+ }
return GSS_S_COMPLETE;
}
*minor = 0;
- if (ctx == NULL)
+ if (ctx == NULL) {
+ *minor = EINVAL;
return GSS_S_NO_CONTEXT;
+ }
GSSEAP_MUTEX_LOCK(&ctx->mutex);
gss_cred_id_t cred = *pCred;
int i;
- if (cred == GSS_C_NO_CREDENTIAL)
+ if (cred == GSS_C_NO_CREDENTIAL) {
+ *minor = EINVAL;
return GSS_S_UNAVAILABLE;
+ }
GSSEAP_MUTEX_LOCK(&cred->mutex);
assert(header != NULL);
padding = gssEapLocateIov(iov, iov_count, GSS_IOV_BUFFER_TYPE_PADDING);
- if (padding != NULL && padding->buffer.length != 0)
+ if (padding != NULL && padding->buffer.length != 0) {
+ *minor = GSSEAP_BAD_PADDING_IOV;
return GSS_S_DEFECTIVE_TOKEN;
+ }
trailer = gssEapLocateIov(iov, iov_count, GSS_IOV_BUFFER_TYPE_TRAILER);
ptr = (unsigned char *)header->buffer.value;
- if (header->buffer.length < 16)
+ if (header->buffer.length < 16) {
+ *minor = GSSEAP_WRONG_SIZE;
return GSS_S_DEFECTIVE_TOKEN;
+ }
- if ((ptr[2] & flags) != flags)
+ if ((ptr[2] & flags) != flags) {
+ *minor = GSSEAP_BAD_DIRECTION;
return GSS_S_BAD_SIG;
+ }
if (toktype == TOK_TYPE_WRAP) {
unsigned int krbTrailerLen;
|| althdr[2] != ptr[2]
|| althdr[3] != ptr[3]
|| memcmp(althdr + 8, ptr + 8, 8) != 0) {
- *minor = 0;
+ *minor = GSSEAP_BAD_WRAP_TOKEN;
return GSS_S_BAD_SIG;
}
} else {
return code;
defective:
- *minor = 0;
+ *minor = GSSEAP_BAD_WRAP_TOKEN;
return GSS_S_DEFECTIVE_TOKEN;
}
{
OM_uint32 major;
- if (ctx->encryptionType == ENCTYPE_NULL)
+ if (ctx->encryptionType == ENCTYPE_NULL) {
+ *minor = GSSEAP_KEY_UNAVAILABLE;
return GSS_S_UNAVAILABLE;
+ }
if (gssEapLocateIov(iov, iov_count, GSS_IOV_BUFFER_TYPE_STREAM) != NULL) {
major = unwrapStream(minor, ctx, conf_state, qop_state,
uint32_t attr = VENDORATTR(vendor, attribute);
*vp = pairfind(vps, attr);
+ if (*vp == NULL) {
+ *minor = GSSEAP_NO_SUCH_ATTR;
+ return GSS_S_UNAVAILABLE;
+ }
- return (*vp == NULL) ? GSS_S_UNAVAILABLE : GSS_S_COMPLETE;
+ return GSS_S_COMPLETE;
}
OM_uint32
buffer->value = NULL;
vp = pairfind(vps, attr);
- if (vp == NULL)
+ if (vp == NULL) {
+ *minor = GSSEAP_NO_SUCH_ATTR;
return GSS_S_UNAVAILABLE;
+ }
do {
buffer->length += vp->length;
size_t dataLen, assocDataLen;
krb5_context krbContext;
- if (ctx->encryptionType == ENCTYPE_NULL)
+ if (ctx->encryptionType == ENCTYPE_NULL) {
+ *minor = GSSEAP_KEY_UNAVAILABLE;
return GSS_S_UNAVAILABLE;
+ }
GSSEAP_KRB_INIT(&krbContext);