Some work on SAML
[mech_eap.orig] / util.h
diff --git a/util.h b/util.h
index 86fa6f7..bc88681 100644 (file)
--- a/util.h
+++ b/util.h
 #ifndef _UTIL_H_
 #define _UTIL_H_ 1
 
+#include <string.h>
+#include <errno.h>
+
 #include <krb5.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "util_saml.h"
 #include "util_radius.h"
 
-#define KRB_KEYTYPE(key)        ((key)->enctype)
+#define KRB_KEY_TYPE(key)       ((key)->enctype)
+#define KRB_KEY_DATA(key)       ((key)->contents)
+#define KRB_KEY_LENGTH(key)     ((key)->length)
+#define KRB_KEY_INIT(key)       do {        \
+        KRB_KEY_TYPE(key) = ENCTYPE_NULL;   \
+        KRB_KEY_DATA(key) = NULL;           \
+        KRB_KEY_LENGTH(key) = 0;            \
+    } while (0)
 
 enum gss_eap_token_type {
     TOK_TYPE_NONE                    = 0x0000,  /* no token */
@@ -76,6 +90,8 @@ enum gss_eap_token_type {
     TOK_TYPE_GSS_CB                  = 0x0603,  /* draft-howlett-eap-gss */
 };
 
+#define EAP_EXPORT_CONTEXT_V1           1
+
 /* util_buffer.c */
 OM_uint32
 makeStringBuffer(OM_uint32 *minor,
@@ -112,10 +128,12 @@ gssEapVerify(krb5_context context,
              int iov_count,
              int *valid);
 
+#if 0
 OM_uint32
 gssEapEncodeGssChannelBindings(OM_uint32 *minor,
                                gss_channel_bindings_t chanBindings,
                                gss_buffer_t encodedBindings);
+#endif
 
 /* util_context.c */
 OM_uint32 gssEapAllocContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
@@ -187,7 +205,7 @@ int
 gssEapAllocIov(gss_iov_buffer_t iov, size_t size);
 
 OM_uint32
-gssEapDeriveRFC3961Key(OM_uint32 *minor,
+gssEapDeriveRfc3961Key(OM_uint32 *minor,
                        const unsigned char *key,
                        size_t keyLength,
                        krb5_enctype enctype,
@@ -197,6 +215,11 @@ gssEapDeriveRFC3961Key(OM_uint32 *minor,
 OM_uint32
 gssEapKerberosInit(OM_uint32 *minor, krb5_context *context);
 
+OM_uint32
+rfc3961ChecksumTypeForKey(OM_uint32 *minor,
+                          krb5_keyblock *key,
+                          krb5_cksumtype *cksumtype);
+
 #define GSSEAP_KRB_INIT(ctx) do {                   \
         OM_uint32 tmpMajor;                         \
         tmpMajor  = gssEapKerberosInit(minor, ctx); \
@@ -316,8 +339,8 @@ sequenceInternalize(void **vqueue, unsigned char **buf, size_t *lenremain);
 int
 sequenceExternalize(void *vqueue, unsigned char **buf, size_t *lenremain);
 
-int
-sequenceSize(void *vqueue, size_t *sizep);
+size_t
+sequenceSize(void *vqueue);
 
 void
 sequenceFree(void **vqueue);
@@ -440,17 +463,57 @@ load_uint64_be(const void *cvp)
     return ((uint64_t)load_uint32_be(p) << 32) | load_uint32_be(p + 4);
 }
 
-static inline void
+static inline unsigned char *
 store_buffer(gss_buffer_t buffer, void *vp, int wide_nums)
 {
     unsigned char *p = (unsigned char *)vp;
 
-    if (wide_nums)
+    if (wide_nums) {
         store_uint64_be(buffer->length, p);
-    else
+        p += 8;
+    } else {
         store_uint32_be(buffer->length, p);
-    if (buffer->value != NULL)
-        memcpy(p + 4, buffer->value, buffer->length);
+        p += 4;
+    }
+
+    if (buffer->value != NULL) {
+        memcpy(p, buffer->value, buffer->length);
+        p += buffer->length;
+    }
+
+    return p;
+}
+
+static inline unsigned char *
+load_buffer(const void *cvp, size_t length, gss_buffer_t buffer)
+{
+    buffer->length = 0;
+    buffer->value = GSSEAP_MALLOC(length);
+    if (buffer->value == NULL)
+        return NULL;
+    buffer->length = length;
+    memcpy(buffer->value, cvp, length);
+    return (unsigned char *)cvp + length;
+}
+
+static inline unsigned char *
+store_oid(gss_OID oid, void *vp)
+{
+    gss_buffer_desc buf;
+
+    if (oid != GSS_C_NO_OID) {
+        buf.length = oid->length;
+        buf.value = oid->elements;
+    } else {
+        buf.length = 0;
+        buf.value = NULL;
+    }
+
+    return store_buffer(&buf, vp, FALSE);
+}
+
+#ifdef __cplusplus
 }
+#endif
 
 #endif /* _UTIL_H_ */