remove util_alloc.c
[mech_eap.git] / init_sec_context.c
index 96ec805..68c55eb 100644 (file)
@@ -255,8 +255,6 @@ initReady(OM_uint32 *minor, gss_ctx_id_t ctx, OM_uint32 reqFlags)
     OM_uint32 major;
     const unsigned char *key;
     size_t keyLength;
-    krb5_enctype encryptionType;
-    int gotKey = 0;
 
 #if 1
     /* XXX actually check for mutual auth */
@@ -265,41 +263,30 @@ initReady(OM_uint32 *minor, gss_ctx_id_t ctx, OM_uint32 reqFlags)
 #endif
 
     /* Cache encryption type derived from selected mechanism OID */
-    major = gssEapOidToEnctype(minor, ctx->mechanismUsed, &encryptionType);
+    major = gssEapOidToEnctype(minor, ctx->mechanismUsed, &ctx->encryptionType);
     if (GSS_ERROR(major))
         return major;
 
-    if (encryptionType != ENCTYPE_NULL &&
-        eap_key_available(ctx->initiatorCtx.eap)) {
-        key = eap_get_eapKeyData(ctx->initiatorCtx.eap, &keyLength);
-
-        if (keyLength >= EAP_EMSK_LEN) {
-            major = gssEapDeriveRfc3961Key(minor,
-                                           &key[EAP_EMSK_LEN / 2],
-                                           EAP_EMSK_LEN / 2,
-                                           encryptionType,
-                                           &ctx->rfc3961Key);
-               if (GSS_ERROR(major))
-                   return major;
-
-            major = rfc3961ChecksumTypeForKey(minor, &ctx->rfc3961Key,
-                                              &ctx->checksumType);
-            if (GSS_ERROR(major))
-                return major;
-            gotKey++;
-        }
-    }
+    if (!eap_key_available(ctx->initiatorCtx.eap))
+        return GSS_S_UNAVAILABLE;
 
-    if (gotKey) {
-        ctx->encryptionType = encryptionType;
-    } else {
-        /*
-         * draft-howlett-eap-gss says that integrity/confidentialty should
-         * always be advertised as available, but if we have no keying
-         * material it seems confusing to the caller to advertise this.
-         */
-        ctx->gssFlags &= ~(GSS_C_INTEG_FLAG | GSS_C_CONF_FLAG);
-    }
+    key = eap_get_eapKeyData(ctx->initiatorCtx.eap, &keyLength);
+
+    if (keyLength < EAP_EMSK_LEN)
+        return GSS_S_UNAVAILABLE;
+
+    major = gssEapDeriveRfc3961Key(minor,
+                                   &key[EAP_EMSK_LEN / 2],
+                                   EAP_EMSK_LEN / 2,
+                                   ctx->encryptionType,
+                                   &ctx->rfc3961Key);
+       if (GSS_ERROR(major))
+           return major;
+
+    major = rfc3961ChecksumTypeForKey(minor, &ctx->rfc3961Key,
+                                      &ctx->checksumType);
+    if (GSS_ERROR(major))
+        return major;
 
     major = sequenceInit(minor,
                          &ctx->seqState,