2 * Copyright (c) 2011, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Portions Copyright 2003-2010 Massachusetts Institute of Technology.
34 * All Rights Reserved.
36 * Export of this software from the United States of America may
37 * require a specific license from the United States Government.
38 * It is the responsibility of any person or organization contemplating
39 * export to obtain such a license before exporting.
41 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
42 * distribute this software and its documentation for any purpose and
43 * without fee is hereby granted, provided that the above copyright
44 * notice appear in all copies and that both that copyright notice and
45 * this permission notice appear in supporting documentation, and that
46 * the name of M.I.T. not be used in advertising or publicity pertaining
47 * to distribution of the software without specific, written prior
48 * permission. Furthermore if you modify this software you must label
49 * your software as modified software and not distribute it in such a
50 * fashion that it might be confused with the original M.I.T. software.
51 * M.I.T. makes no representations about the suitability of
52 * this software for any purpose. It is provided "as is" without express
53 * or implied warranty.
64 #ifdef HAVE_SYS_PARAM_H
65 #include <sys/param.h>
76 #define inline __inline
77 #define snprintf _snprintf
85 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
88 #if !defined(WIN32) && (!(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)))
89 #define GSSEAP_UNUSED __attribute__ ((__unused__))
96 makeStringBuffer(OM_uint32 *minor,
100 #define makeStringBufferOrCleanup(src, dst) \
102 major = makeStringBuffer((minor), (src), (dst));\
103 if (GSS_ERROR(major)) \
108 bufferToString(OM_uint32 *minor,
109 const gss_buffer_t buffer,
113 duplicateBuffer(OM_uint32 *minor,
114 const gss_buffer_t src,
117 #define duplicateBufferOrCleanup(src, dst) \
119 major = duplicateBuffer((minor), (src), (dst)); \
120 if (GSS_ERROR(major)) \
125 bufferEqual(const gss_buffer_t b1, const gss_buffer_t b2)
127 return (b1->length == b2->length &&
128 memcmp(b1->value, b2->value, b2->length) == 0);
132 bufferEqualString(const gss_buffer_t b1, const char *s)
136 b2.length = strlen(s);
137 b2.value = (char *)s;
139 return bufferEqual(b1, &b2);
144 gssEapSign(krb5_context context,
147 #ifdef HAVE_HEIMDAL_VERSION
152 krb5_keyusage sign_usage,
153 gss_iov_buffer_desc *iov,
157 gssEapVerify(krb5_context context,
160 #ifdef HAVE_HEIMDAL_VERSION
165 krb5_keyusage sign_usage,
166 gss_iov_buffer_desc *iov,
172 gssEapEncodeGssChannelBindings(OM_uint32 *minor,
173 gss_channel_bindings_t chanBindings,
174 gss_buffer_t encodedBindings);
178 #define EAP_EXPORT_CONTEXT_V1 1
180 enum gss_eap_token_type {
181 TOK_TYPE_NONE = 0x0000, /* no token */
182 TOK_TYPE_MIC = 0x0404, /* RFC 4121 MIC token */
183 TOK_TYPE_WRAP = 0x0504, /* RFC 4121 wrap token */
184 TOK_TYPE_EXPORT_NAME = 0x0401, /* RFC 2743 exported name */
185 TOK_TYPE_EXPORT_NAME_COMPOSITE = 0x0402, /* exported composite name */
186 TOK_TYPE_DELETE_CONTEXT = 0x0405, /* RFC 2743 delete context */
187 TOK_TYPE_INITIATOR_CONTEXT = 0x0601, /* initiator-sent context token */
188 TOK_TYPE_ACCEPTOR_CONTEXT = 0x0602, /* acceptor-sent context token */
191 /* inner token types and flags */
192 #define ITOK_TYPE_NONE 0x00000000
193 #define ITOK_TYPE_CONTEXT_ERR 0x00000001 /* critical */
194 #define ITOK_TYPE_ACCEPTOR_NAME_REQ 0x00000002 /* TBD */
195 #define ITOK_TYPE_ACCEPTOR_NAME_RESP 0x00000003 /* TBD */
196 #define ITOK_TYPE_EAP_RESP 0x00000004 /* critical, required, if not reauth */
197 #define ITOK_TYPE_EAP_REQ 0x00000005 /* critical, required, if not reauth */
198 #define ITOK_TYPE_GSS_CHANNEL_BINDINGS 0x00000006 /* critical, required, if not reauth */
199 #define ITOK_TYPE_REAUTH_CREDS 0x00000007 /* optional */
200 #define ITOK_TYPE_REAUTH_REQ 0x00000008 /* optional */
201 #define ITOK_TYPE_REAUTH_RESP 0x00000009 /* optional */
202 #define ITOK_TYPE_VERSION_INFO 0x0000000A /* optional */
203 #define ITOK_TYPE_VENDOR_INFO 0x0000000B /* optional */
204 #define ITOK_TYPE_GSS_FLAGS 0x0000000C /* optional */
205 #define ITOK_TYPE_INITIATOR_MIC 0x0000000D /* critical, required, if not reauth */
206 #define ITOK_TYPE_ACCEPTOR_MIC 0x0000000E /* TBD */
208 #define ITOK_FLAG_CRITICAL 0x80000000 /* critical, wire flag */
209 #define ITOK_FLAG_VERIFIED 0x40000000 /* verified, API flag */
211 #define ITOK_TYPE_MASK (~(ITOK_FLAG_CRITICAL | ITOK_FLAG_VERIFIED))
213 #define GSSEAP_WIRE_FLAGS_MASK GSS_C_MUTUAL_FLAG
215 OM_uint32 gssEapAllocContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
216 OM_uint32 gssEapReleaseContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
219 gssEapMakeToken(OM_uint32 *minor,
221 const gss_buffer_t innerToken,
222 enum gss_eap_token_type tokenType,
223 gss_buffer_t outputToken);
226 gssEapVerifyToken(OM_uint32 *minor,
228 const gss_buffer_t inputToken,
229 enum gss_eap_token_type *tokenType,
230 gss_buffer_t innerInputToken);
233 gssEapContextTime(OM_uint32 *minor,
234 gss_ctx_id_t context_handle,
235 OM_uint32 *time_rec);
238 gssEapMakeTokenMIC(OM_uint32 *minor,
240 gss_buffer_t tokenMIC);
243 gssEapVerifyTokenMIC(OM_uint32 *minor,
245 const gss_buffer_t tokenMIC);
248 OM_uint32 gssEapAllocCred(OM_uint32 *minor, gss_cred_id_t *pCred);
249 OM_uint32 gssEapReleaseCred(OM_uint32 *minor, gss_cred_id_t *pCred);
252 gssEapPrimaryMechForCred(gss_cred_id_t cred);
255 gssEapAcquireCred(OM_uint32 *minor,
256 const gss_name_t desiredName,
258 const gss_OID_set desiredMechs,
260 gss_cred_id_t *pCred,
261 gss_OID_set *pActualMechs,
265 gssEapSetCredPassword(OM_uint32 *minor,
267 const gss_buffer_t password);
270 gssEapSetCredService(OM_uint32 *minor,
272 const gss_name_t target);
275 gssEapResolveInitiatorCred(OM_uint32 *minor,
276 const gss_cred_id_t cred,
277 const gss_name_t target,
278 gss_cred_id_t *resolvedCred);
280 int gssEapCredAvailable(gss_cred_id_t cred, gss_OID mech);
283 gssEapInquireCred(OM_uint32 *minor,
286 OM_uint32 *pLifetime,
287 gss_cred_usage_t *cred_usage,
288 gss_OID_set *mechanisms);
292 gssEapEncrypt(krb5_context context, int dce_style, size_t ec,
294 #ifdef HAVE_HEIMDAL_VERSION
300 gss_iov_buffer_desc *iov, int iov_count);
303 gssEapDecrypt(krb5_context context, int dce_style, size_t ec,
305 #ifdef HAVE_HEIMDAL_VERSION
311 gss_iov_buffer_desc *iov, int iov_count);
314 gssEapMapCryptoFlag(OM_uint32 type);
317 gssEapLocateIov(gss_iov_buffer_desc *iov,
322 gssEapIovMessageLength(gss_iov_buffer_desc *iov,
325 size_t *assoc_data_length);
328 gssEapReleaseIov(gss_iov_buffer_desc *iov, int iov_count);
331 gssEapIsIntegrityOnly(gss_iov_buffer_desc *iov, int iov_count);
334 gssEapAllocIov(gss_iov_buffer_t iov, size_t size);
337 gssEapDeriveRfc3961Key(OM_uint32 *minor,
338 const unsigned char *key,
340 krb5_enctype enctype,
341 krb5_keyblock *pKey);
344 #ifdef HAVE_HEIMDAL_VERSION
346 #define KRB_TIME_FOREVER ((time_t)~0L)
348 #define KRB_KEY_TYPE(key) ((key)->keytype)
349 #define KRB_KEY_DATA(key) ((key)->keyvalue.data)
350 #define KRB_KEY_LENGTH(key) ((key)->keyvalue.length)
352 #define KRB_PRINC_LENGTH(princ) ((princ)->name.name_string.len)
353 #define KRB_PRINC_TYPE(princ) ((princ)->name.name_type)
354 #define KRB_PRINC_NAME(princ) ((princ)->name.name_string.val)
355 #define KRB_PRINC_REALM(princ) ((princ)->realm)
357 #define KRB_KT_ENT_KEYBLOCK(e) (&(e)->keyblock)
358 #define KRB_KT_ENT_FREE(c, e) krb5_kt_free_entry((c), (e))
360 #define KRB_CRYPTO_CONTEXT(ctx) (krbCrypto)
364 #define KRB_TIME_FOREVER KRB5_INT32_MAX
366 #define KRB_KEY_TYPE(key) ((key)->enctype)
367 #define KRB_KEY_DATA(key) ((key)->contents)
368 #define KRB_KEY_LENGTH(key) ((key)->length)
370 #define KRB_PRINC_LENGTH(princ) (krb5_princ_size(NULL, (princ)))
371 #define KRB_PRINC_TYPE(princ) (krb5_princ_type(NULL, (princ)))
372 #define KRB_PRINC_NAME(princ) (krb5_princ_name(NULL, (princ)))
373 #define KRB_PRINC_REALM(princ) (krb5_princ_realm(NULL, (princ)))
375 #define KRB_KT_ENT_KEYBLOCK(e) (&(e)->key)
376 #define KRB_KT_ENT_FREE(c, e) krb5_free_keytab_entry_contents((c), (e))
378 #define KRB_CRYPTO_CONTEXT(ctx) (&(ctx)->rfc3961Key)
380 #endif /* HAVE_HEIMDAL_VERSION */
382 #define KRB_KEY_INIT(key) do { \
383 KRB_KEY_TYPE(key) = ENCTYPE_NULL; \
384 KRB_KEY_DATA(key) = NULL; \
385 KRB_KEY_LENGTH(key) = 0; \
388 #define GSSEAP_KRB_INIT(ctx) do { \
389 OM_uint32 tmpMajor; \
391 tmpMajor = gssEapKerberosInit(minor, ctx); \
392 if (GSS_ERROR(tmpMajor)) { \
398 gssEapKerberosInit(OM_uint32 *minor, krb5_context *context);
401 rfc3961ChecksumTypeForKey(OM_uint32 *minor,
403 krb5_cksumtype *cksumtype);
406 krbCryptoLength(krb5_context krbContext,
407 #ifdef HAVE_HEIMDAL_VERSION
408 krb5_crypto krbCrypto,
416 krbPaddingLength(krb5_context krbContext,
417 #ifdef HAVE_HEIMDAL_VERSION
418 krb5_crypto krbCrypto,
426 krbBlockSize(krb5_context krbContext,
427 #ifdef HAVE_HEIMDAL_VERSION
428 krb5_crypto krbCrypto,
435 krbEnctypeToString(krb5_context krbContext,
436 krb5_enctype enctype,
438 gss_buffer_t string);
441 krbMakeAuthDataKdcIssued(krb5_context context,
442 const krb5_keyblock *key,
443 krb5_const_principal issuer,
444 #ifdef HAVE_HEIMDAL_VERSION
445 const AuthorizationData *authdata,
446 AuthorizationData *adKdcIssued
448 krb5_authdata *const *authdata,
449 krb5_authdata ***adKdcIssued
454 krbMakeCred(krb5_context context,
455 krb5_auth_context authcontext,
461 gssEapExportLucidSecContext(OM_uint32 *minor,
463 const gss_OID desiredObject,
464 gss_buffer_set_t *data_set);
467 extern gss_OID GSS_EAP_MECHANISM;
469 #define OID_FLAG_NULL_VALID 0x00000001
470 #define OID_FLAG_FAMILY_MECH_VALID 0x00000002
471 #define OID_FLAG_MAP_NULL_TO_DEFAULT_MECH 0x00000004
472 #define OID_FLAG_MAP_FAMILY_MECH_TO_NULL 0x00000008
475 gssEapCanonicalizeOid(OM_uint32 *minor,
481 gssEapReleaseOid(OM_uint32 *minor, gss_OID *oid);
484 gssEapDefaultMech(OM_uint32 *minor,
488 gssEapIndicateMechs(OM_uint32 *minor,
492 gssEapEnctypeToOid(OM_uint32 *minor,
493 krb5_enctype enctype,
497 gssEapOidToEnctype(OM_uint32 *minor,
499 krb5_enctype *enctype);
502 gssEapIsMechanismOid(const gss_OID oid);
505 gssEapIsConcreteMechanismOid(const gss_OID oid);
508 gssEapValidateMechs(OM_uint32 *minor,
509 const gss_OID_set mechs);
512 gssEapOidToSaslName(const gss_OID oid);
515 gssEapSaslNameToOid(const gss_buffer_t name);
517 /* util_moonshot.c */
519 libMoonshotResolveDefaultIdentity(OM_uint32 *minor,
520 const gss_cred_id_t cred,
524 libMoonshotResolveInitiatorCred(OM_uint32 *minor,
526 const gss_name_t targetName);
529 #define EXPORT_NAME_FLAG_OID 0x1
530 #define EXPORT_NAME_FLAG_COMPOSITE 0x2
531 #define EXPORT_NAME_FLAG_ALLOW_COMPOSITE 0x4
533 OM_uint32 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName);
534 OM_uint32 gssEapReleaseName(OM_uint32 *minor, gss_name_t *pName);
535 OM_uint32 gssEapExportName(OM_uint32 *minor,
536 const gss_name_t name,
537 gss_buffer_t exportedName);
538 OM_uint32 gssEapExportNameInternal(OM_uint32 *minor,
539 const gss_name_t name,
540 gss_buffer_t exportedName,
542 OM_uint32 gssEapImportName(OM_uint32 *minor,
543 const gss_buffer_t input_name_buffer,
544 const gss_OID input_name_type,
545 const gss_OID input_mech_type,
546 gss_name_t *output_name);
547 OM_uint32 gssEapImportNameInternal(OM_uint32 *minor,
548 const gss_buffer_t input_name_buffer,
549 gss_name_t *output_name,
552 gssEapDuplicateName(OM_uint32 *minor,
553 const gss_name_t input_name,
554 gss_name_t *dest_name);
557 gssEapCanonicalizeName(OM_uint32 *minor,
558 const gss_name_t input_name,
559 const gss_OID mech_type,
560 gss_name_t *dest_name);
563 gssEapDisplayName(OM_uint32 *minor,
565 gss_buffer_t output_name_buffer,
566 gss_OID *output_name_type);
569 gssEapCompareName(OM_uint32 *minor,
576 composeOid(OM_uint32 *minor_status,
583 decomposeOid(OM_uint32 *minor_status,
590 duplicateOid(OM_uint32 *minor_status,
591 const gss_OID_desc * const oid,
595 duplicateOidSet(OM_uint32 *minor,
596 const gss_OID_set src,
600 oidEqual(const gss_OID_desc *o1, const gss_OID_desc *o2)
602 if (o1 == GSS_C_NO_OID)
603 return (o2 == GSS_C_NO_OID);
604 else if (o2 == GSS_C_NO_OID)
605 return (o1 == GSS_C_NO_OID);
607 return (o1->length == o2->length &&
608 memcmp(o1->elements, o2->elements, o1->length) == 0);
611 /* util_ordering.c */
613 sequenceInternalize(OM_uint32 *minor,
619 sequenceExternalize(OM_uint32 *minor,
625 sequenceSize(void *vqueue);
628 sequenceFree(OM_uint32 *minor, void **vqueue);
631 sequenceCheck(OM_uint32 *minor, void **vqueue, uint64_t seqnum);
634 sequenceInit(OM_uint32 *minor, void **vqueue, uint64_t seqnum,
635 int do_replay, int do_sequence, int wide_nums);
639 GSSEAP_STATE_INITIAL = 0x01, /* initial state */
640 GSSEAP_STATE_AUTHENTICATE = 0x02, /* exchange EAP messages */
641 GSSEAP_STATE_INITIATOR_EXTS = 0x04, /* initiator extensions */
642 GSSEAP_STATE_ACCEPTOR_EXTS = 0x08, /* acceptor extensions */
643 #ifdef GSSEAP_ENABLE_REAUTH
644 GSSEAP_STATE_REAUTHENTICATE = 0x10, /* GSS reauthentication messages */
646 GSSEAP_STATE_ESTABLISHED = 0x20, /* context established */
647 GSSEAP_STATE_ALL = 0x3F
650 #define GSSEAP_STATE_NEXT(s) ((s) << 1)
652 #define GSSEAP_SM_STATE(ctx) ((ctx)->state)
655 void gssEapSmTransition(gss_ctx_id_t ctx, enum gss_eap_state state);
656 #define GSSEAP_SM_TRANSITION(ctx, state) gssEapSmTransition((ctx), (state))
658 #define GSSEAP_SM_TRANSITION(ctx, newstate) do { (ctx)->state = (newstate); } while (0)
661 #define GSSEAP_SM_TRANSITION_NEXT(ctx) GSSEAP_SM_TRANSITION((ctx), GSSEAP_STATE_NEXT(GSSEAP_SM_STATE((ctx))))
663 /* state machine entry */
665 OM_uint32 inputTokenType;
666 OM_uint32 outputTokenType;
667 enum gss_eap_state validStates;
669 OM_uint32 (*processToken)(OM_uint32 *,
676 gss_channel_bindings_t,
682 /* state machine flags, set by handler */
683 #define SM_FLAG_FORCE_SEND_TOKEN 0x00000001 /* send token even if no inner tokens */
684 #define SM_FLAG_OUTPUT_TOKEN_CRITICAL 0x00000002 /* output token is critical */
686 /* state machine flags, set by state machine */
687 #define SM_FLAG_INPUT_TOKEN_CRITICAL 0x10000000 /* input token was critical */
689 #define SM_ITOK_FLAG_REQUIRED 0x00000001 /* received tokens must be present */
692 gssEapSmStep(OM_uint32 *minor,
699 gss_channel_bindings_t chanBindings,
700 gss_buffer_t inputToken,
701 gss_buffer_t outputToken,
702 struct gss_eap_sm *sm,
706 gssEapSmTransition(gss_ctx_id_t ctx, enum gss_eap_state state);
709 struct gss_eap_token_buffer_set {
710 gss_buffer_set_desc buffers; /* pointers only */
715 gssEapEncodeInnerTokens(OM_uint32 *minor,
716 struct gss_eap_token_buffer_set *tokens,
717 gss_buffer_t buffer);
719 gssEapDecodeInnerTokens(OM_uint32 *minor,
720 const gss_buffer_t buffer,
721 struct gss_eap_token_buffer_set *tokens);
724 gssEapReleaseInnerTokens(OM_uint32 *minor,
725 struct gss_eap_token_buffer_set *tokens,
729 gssEapAllocInnerTokens(OM_uint32 *minor,
731 struct gss_eap_token_buffer_set *tokens);
734 tokenSize(const gss_OID_desc *mech, size_t body_size);
737 makeTokenHeader(const gss_OID_desc *mech,
740 enum gss_eap_token_type tok_type);
743 verifyTokenHeader(OM_uint32 *minor,
746 unsigned char **buf_in,
748 enum gss_eap_token_type *ret_tok_type);
752 #define GSSEAP_CALLOC calloc
753 #define GSSEAP_MALLOC malloc
754 #define GSSEAP_FREE free
755 #define GSSEAP_REALLOC realloc
757 #ifndef GSSAPI_CALLCONV
758 #define GSSAPI_CALLCONV KRB5_CALLCONV
762 #define GSSEAP_CONSTRUCTOR
763 #define GSSEAP_DESTRUCTOR
765 #define GSSEAP_CONSTRUCTOR __attribute__((constructor))
766 #define GSSEAP_DESTRUCTOR __attribute__((destructor))
769 #define GSSEAP_NOT_IMPLEMENTED do { \
770 assert(0 && "not implemented"); \
772 return GSS_S_FAILURE; \
779 #define GSSEAP_GET_LAST_ERROR() (GetLastError())
781 #define GSSEAP_MUTEX CRITICAL_SECTION
783 #define GSSEAP_MUTEX_INIT(m) (InitializeCriticalSection((m)), 0)
784 #define GSSEAP_MUTEX_DESTROY(m) DeleteCriticalSection((m))
785 #define GSSEAP_MUTEX_LOCK(m) EnterCriticalSection((m))
786 #define GSSEAP_MUTEX_UNLOCK(m) LeaveCriticalSection((m))
788 /* XXX yet to implement thread-local wrappers */
790 #define GSSEAP_THREAD_ONCE INIT_ONCE
791 #define GSSEAP_ONCE(o, i) InitOnceExecuteOnce((o), (i))
792 #define GSSEAP_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT
798 #define GSSEAP_GET_LAST_ERROR() (errno)
800 #define GSSEAP_MUTEX pthread_mutex_t
802 #define GSSEAP_MUTEX_INIT(m) pthread_mutex_init((m), NULL)
803 #define GSSEAP_MUTEX_DESTROY(m) pthread_mutex_destroy((m))
804 #define GSSEAP_MUTEX_LOCK(m) pthread_mutex_lock((m))
805 #define GSSEAP_MUTEX_UNLOCK(m) pthread_mutex_unlock((m))
807 #define GSSEAP_THREAD_KEY pthread_key_t
808 #define GSSEAP_KEY_CREATE(k, d) pthread_key_create((k), (d))
809 #define GSSEAP_GETSPECIFIC(k) pthread_getspecific((k))
810 #define GSSEAP_SETSPECIFIC(k, d) pthread_setspecific((k), (d))
812 #define GSSEAP_THREAD_ONCE pthread_once_t
813 #define GSSEAP_ONCE(o, i) pthread_once((o), (i))
814 #define GSSEAP_ONCE_INITIALIZER PTHREAD_ONCE_INIT
818 /* Helper functions */
820 store_uint16_be(uint16_t val, void *vp)
822 unsigned char *p = (unsigned char *)vp;
824 p[0] = (val >> 8) & 0xff;
825 p[1] = (val ) & 0xff;
828 static inline uint16_t
829 load_uint16_be(const void *cvp)
831 const unsigned char *p = (const unsigned char *)cvp;
833 return (p[1] | (p[0] << 8));
837 store_uint32_be(uint32_t val, void *vp)
839 unsigned char *p = (unsigned char *)vp;
841 p[0] = (val >> 24) & 0xff;
842 p[1] = (val >> 16) & 0xff;
843 p[2] = (val >> 8) & 0xff;
844 p[3] = (val ) & 0xff;
847 static inline uint32_t
848 load_uint32_be(const void *cvp)
850 const unsigned char *p = (const unsigned char *)cvp;
852 return (p[3] | (p[2] << 8)
853 | ((uint32_t) p[1] << 16)
854 | ((uint32_t) p[0] << 24));
858 store_uint64_be(uint64_t val, void *vp)
860 unsigned char *p = (unsigned char *)vp;
862 p[0] = (unsigned char)((val >> 56) & 0xff);
863 p[1] = (unsigned char)((val >> 48) & 0xff);
864 p[2] = (unsigned char)((val >> 40) & 0xff);
865 p[3] = (unsigned char)((val >> 32) & 0xff);
866 p[4] = (unsigned char)((val >> 24) & 0xff);
867 p[5] = (unsigned char)((val >> 16) & 0xff);
868 p[6] = (unsigned char)((val >> 8) & 0xff);
869 p[7] = (unsigned char)((val ) & 0xff);
872 static inline uint64_t
873 load_uint64_be(const void *cvp)
875 const unsigned char *p = (const unsigned char *)cvp;
877 return ((uint64_t)load_uint32_be(p) << 32) | load_uint32_be(p + 4);
880 static inline unsigned char *
881 store_buffer(gss_buffer_t buffer, void *vp, int wide_nums)
883 unsigned char *p = (unsigned char *)vp;
886 store_uint64_be(buffer->length, p);
889 store_uint32_be(buffer->length, p);
893 if (buffer->value != NULL) {
894 memcpy(p, buffer->value, buffer->length);
901 static inline unsigned char *
902 load_buffer(const void *cvp, size_t length, gss_buffer_t buffer)
905 buffer->value = GSSEAP_MALLOC(length);
906 if (buffer->value == NULL)
908 buffer->length = length;
909 memcpy(buffer->value, cvp, length);
910 return (unsigned char *)cvp + length;
913 static inline unsigned char *
914 store_oid(gss_OID oid, void *vp)
918 if (oid != GSS_C_NO_OID) {
919 buf.length = oid->length;
920 buf.value = oid->elements;
926 return store_buffer(&buf, vp, FALSE);
930 krbDataToGssBuffer(krb5_data *data, gss_buffer_t buffer)
932 buffer->value = (void *)data->data;
933 buffer->length = data->length;
937 krbPrincComponentToGssBuffer(krb5_principal krbPrinc,
938 int index, gss_buffer_t buffer)
940 #ifdef HAVE_HEIMDAL_VERSION
941 buffer->value = (void *)KRB_PRINC_NAME(krbPrinc)[index];
942 buffer->length = strlen((char *)buffer->value);
944 buffer->value = (void *)krb5_princ_component(NULL, krbPrinc, index)->data;
945 buffer->length = krb5_princ_component(NULL, krbPrinc, index)->length;
946 #endif /* HAVE_HEIMDAL_VERSION */
950 krbPrincRealmToGssBuffer(krb5_principal krbPrinc, gss_buffer_t buffer)
952 #ifdef HAVE_HEIMDAL_VERSION
953 buffer->value = (void *)KRB_PRINC_REALM(krbPrinc);
954 buffer->length = strlen((char *)buffer->value);
956 krbDataToGssBuffer(KRB_PRINC_REALM(krbPrinc), buffer);
961 gssBufferToKrbData(gss_buffer_t buffer, krb5_data *data)
963 data->data = (char *)buffer->value;
964 data->length = buffer->length;
968 struct gss_eap_status_info;
970 struct gss_eap_thread_local_data {
971 krb5_context krbContext;
972 struct gss_eap_status_info *statusInfo;
975 struct gss_eap_thread_local_data *
976 gssEapGetThreadLocalData(void);
979 gssEapDestroyStatusInfo(struct gss_eap_status_info *status);
982 gssEapDestroyKrbContext(krb5_context context);
988 #ifdef GSSEAP_ENABLE_ACCEPTOR
989 #include "util_json.h"
990 #include "util_attr.h"
991 #include "util_base64.h"
993 #ifdef GSSEAP_ENABLE_REAUTH
994 #include "util_reauth.h"
997 #endif /* _UTIL_H_ */