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>
77 # define inline __inline
79 #define snprintf _snprintf
87 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
90 #if !defined(WIN32) && !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
91 #define GSSEAP_UNUSED __attribute__ ((__unused__))
98 makeStringBuffer(OM_uint32 *minor,
100 gss_buffer_t buffer);
102 #define makeStringBufferOrCleanup(src, dst) \
104 major = makeStringBuffer((minor), (src), (dst));\
105 if (GSS_ERROR(major)) \
110 bufferToString(OM_uint32 *minor,
111 const gss_buffer_t buffer,
115 duplicateBuffer(OM_uint32 *minor,
116 const gss_buffer_t src,
119 #define duplicateBufferOrCleanup(src, dst) \
121 major = duplicateBuffer((minor), (src), (dst)); \
122 if (GSS_ERROR(major)) \
127 bufferEqual(const gss_buffer_t b1, const gss_buffer_t b2)
129 return (b1->length == b2->length &&
130 memcmp(b1->value, b2->value, b2->length) == 0);
134 bufferEqualString(const gss_buffer_t b1, const char *s)
138 b2.length = strlen(s);
139 b2.value = (char *)s;
141 return bufferEqual(b1, &b2);
146 gssEapSign(krb5_context context,
149 #ifdef HAVE_HEIMDAL_VERSION
154 krb5_keyusage sign_usage,
155 gss_iov_buffer_desc *iov,
159 gssEapVerify(krb5_context context,
162 #ifdef HAVE_HEIMDAL_VERSION
167 krb5_keyusage sign_usage,
168 gss_iov_buffer_desc *iov,
174 gssEapEncodeGssChannelBindings(OM_uint32 *minor,
175 gss_channel_bindings_t chanBindings,
176 gss_buffer_t encodedBindings);
180 #define EAP_EXPORT_CONTEXT_V1 1
182 enum gss_eap_token_type {
183 TOK_TYPE_NONE = 0x0000, /* no token */
184 TOK_TYPE_MIC = 0x0404, /* RFC 4121 MIC token */
185 TOK_TYPE_WRAP = 0x0504, /* RFC 4121 wrap token */
186 TOK_TYPE_EXPORT_NAME = 0x0401, /* RFC 2743 exported name */
187 TOK_TYPE_EXPORT_NAME_COMPOSITE = 0x0402, /* exported composite name */
188 TOK_TYPE_DELETE_CONTEXT = 0x0405, /* RFC 2743 delete context */
189 TOK_TYPE_INITIATOR_CONTEXT = 0x0601, /* initiator-sent context token */
190 TOK_TYPE_ACCEPTOR_CONTEXT = 0x0602, /* acceptor-sent context token */
193 /* inner token types and flags */
194 #define ITOK_TYPE_NONE 0x00000000
195 #define ITOK_TYPE_CONTEXT_ERR 0x00000001 /* critical */
196 #define ITOK_TYPE_ACCEPTOR_NAME_REQ 0x00000002 /* TBD */
197 #define ITOK_TYPE_ACCEPTOR_NAME_RESP 0x00000003 /* TBD */
198 #define ITOK_TYPE_EAP_RESP 0x00000004 /* critical, required, if not reauth */
199 #define ITOK_TYPE_EAP_REQ 0x00000005 /* critical, required, if not reauth */
200 #define ITOK_TYPE_GSS_CHANNEL_BINDINGS 0x00000006 /* critical, required, if not reauth */
201 #define ITOK_TYPE_REAUTH_CREDS 0x00000007 /* optional */
202 #define ITOK_TYPE_REAUTH_REQ 0x00000008 /* optional */
203 #define ITOK_TYPE_REAUTH_RESP 0x00000009 /* optional */
204 #define ITOK_TYPE_VERSION_INFO 0x0000000A /* optional */
205 #define ITOK_TYPE_VENDOR_INFO 0x0000000B /* optional */
206 #define ITOK_TYPE_GSS_FLAGS 0x0000000C /* optional */
207 #define ITOK_TYPE_INITIATOR_MIC 0x0000000D /* critical, required, if not reauth */
208 #define ITOK_TYPE_ACCEPTOR_MIC 0x0000000E /* TBD */
210 #define ITOK_FLAG_CRITICAL 0x80000000 /* critical, wire flag */
211 #define ITOK_FLAG_VERIFIED 0x40000000 /* verified, API flag */
213 #define ITOK_TYPE_MASK (~(ITOK_FLAG_CRITICAL | ITOK_FLAG_VERIFIED))
215 #define GSSEAP_WIRE_FLAGS_MASK ( GSS_C_MUTUAL_FLAG | \
217 GSS_C_IDENTIFY_FLAG | \
218 GSS_C_EXTENDED_ERROR_FLAG )
220 OM_uint32 gssEapAllocContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
221 OM_uint32 gssEapReleaseContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
224 gssEapMakeToken(OM_uint32 *minor,
226 const gss_buffer_t innerToken,
227 enum gss_eap_token_type tokenType,
228 gss_buffer_t outputToken);
231 gssEapVerifyToken(OM_uint32 *minor,
233 const gss_buffer_t inputToken,
234 enum gss_eap_token_type *tokenType,
235 gss_buffer_t innerInputToken);
238 gssEapContextTime(OM_uint32 *minor,
239 gss_ctx_id_t context_handle,
240 OM_uint32 *time_rec);
243 gssEapMakeTokenMIC(OM_uint32 *minor,
245 gss_buffer_t tokenMIC);
248 gssEapVerifyTokenMIC(OM_uint32 *minor,
250 const gss_buffer_t tokenMIC);
253 OM_uint32 gssEapAllocCred(OM_uint32 *minor, gss_cred_id_t *pCred);
254 OM_uint32 gssEapReleaseCred(OM_uint32 *minor, gss_cred_id_t *pCred);
257 gssEapPrimaryMechForCred(gss_cred_id_t cred);
260 gssEapAcquireCred(OM_uint32 *minor,
261 const gss_name_t desiredName,
263 const gss_OID_set desiredMechs,
265 gss_cred_id_t *pCred,
266 gss_OID_set *pActualMechs,
270 gssEapSetCredPassword(OM_uint32 *minor,
272 const gss_buffer_t password);
275 gssEapSetCredService(OM_uint32 *minor,
277 const gss_name_t target);
280 gssEapResolveInitiatorCred(OM_uint32 *minor,
281 const gss_cred_id_t cred,
282 const gss_name_t target,
283 gss_cred_id_t *resolvedCred);
285 int gssEapCredAvailable(gss_cred_id_t cred, gss_OID mech);
288 gssEapInquireCred(OM_uint32 *minor,
291 OM_uint32 *pLifetime,
292 gss_cred_usage_t *cred_usage,
293 gss_OID_set *mechanisms);
297 gssEapEncrypt(krb5_context context, int dce_style, size_t ec,
299 #ifdef HAVE_HEIMDAL_VERSION
305 gss_iov_buffer_desc *iov, int iov_count);
308 gssEapDecrypt(krb5_context context, int dce_style, size_t ec,
310 #ifdef HAVE_HEIMDAL_VERSION
316 gss_iov_buffer_desc *iov, int iov_count);
319 gssEapMapCryptoFlag(OM_uint32 type);
322 gssEapLocateIov(gss_iov_buffer_desc *iov,
327 gssEapIovMessageLength(gss_iov_buffer_desc *iov,
330 size_t *assoc_data_length);
333 gssEapReleaseIov(gss_iov_buffer_desc *iov, int iov_count);
336 gssEapIsIntegrityOnly(gss_iov_buffer_desc *iov, int iov_count);
339 gssEapAllocIov(gss_iov_buffer_t iov, size_t size);
342 gssEapDeriveRfc3961Key(OM_uint32 *minor,
343 const unsigned char *key,
345 krb5_enctype enctype,
346 krb5_keyblock *pKey);
352 * If your Kerberos library uses a different allocator to your
353 * GSS mechanism glue, then you might wish to define these in
354 * config.h or elsewhere. This should eventually go away when
355 * we no longer need to allocate memory that is freed by the
358 #define KRB_CALLOC calloc
359 #define KRB_MALLOC malloc
360 #define KRB_FREE free
361 #define KRB_REALLOC realloc
362 #endif /* KRB_MALLOC */
364 #ifdef HAVE_HEIMDAL_VERSION
366 #define KRB_TIME_FOREVER ((time_t)~0L)
368 #define KRB_KEY_TYPE(key) ((key)->keytype)
369 #define KRB_KEY_DATA(key) ((key)->keyvalue.data)
370 #define KRB_KEY_LENGTH(key) ((key)->keyvalue.length)
372 #define KRB_PRINC_LENGTH(princ) ((princ)->name.name_string.len)
373 #define KRB_PRINC_TYPE(princ) ((princ)->name.name_type)
374 #define KRB_PRINC_NAME(princ) ((princ)->name.name_string.val)
375 #define KRB_PRINC_REALM(princ) ((princ)->realm)
377 #define KRB_KT_ENT_KEYBLOCK(e) (&(e)->keyblock)
378 #define KRB_KT_ENT_FREE(c, e) krb5_kt_free_entry((c), (e))
380 #define KRB_CRYPTO_CONTEXT(ctx) (krbCrypto)
382 #define KRB_DATA_INIT(d) krb5_data_zero((d))
386 #define KRB_TIME_FOREVER KRB5_INT32_MAX
388 #define KRB_KEY_TYPE(key) ((key)->enctype)
389 #define KRB_KEY_DATA(key) ((key)->contents)
390 #define KRB_KEY_LENGTH(key) ((key)->length)
392 #define KRB_PRINC_LENGTH(princ) (krb5_princ_size(NULL, (princ)))
393 #define KRB_PRINC_TYPE(princ) (krb5_princ_type(NULL, (princ)))
394 #define KRB_PRINC_NAME(princ) (krb5_princ_name(NULL, (princ)))
395 #define KRB_PRINC_REALM(princ) (krb5_princ_realm(NULL, (princ)))
397 #define KRB_KT_ENT_KEYBLOCK(e) (&(e)->key)
398 #define KRB_KT_ENT_FREE(c, e) krb5_free_keytab_entry_contents((c), (e))
400 #define KRB_CRYPTO_CONTEXT(ctx) (&(ctx)->rfc3961Key)
402 #define KRB_DATA_INIT(d) do { \
403 (d)->magic = KV5M_DATA; \
408 #endif /* HAVE_HEIMDAL_VERSION */
410 #define KRB_KEY_INIT(key) do { \
411 KRB_KEY_TYPE(key) = ENCTYPE_NULL; \
412 KRB_KEY_DATA(key) = NULL; \
413 KRB_KEY_LENGTH(key) = 0; \
416 #define GSSEAP_KRB_INIT(ctx) do { \
417 OM_uint32 tmpMajor; \
419 tmpMajor = gssEapKerberosInit(minor, ctx); \
420 if (GSS_ERROR(tmpMajor)) { \
426 gssEapKerberosInit(OM_uint32 *minor, krb5_context *context);
429 rfc3961ChecksumTypeForKey(OM_uint32 *minor,
431 krb5_cksumtype *cksumtype);
434 krbCryptoLength(krb5_context krbContext,
435 #ifdef HAVE_HEIMDAL_VERSION
436 krb5_crypto krbCrypto,
444 krbPaddingLength(krb5_context krbContext,
445 #ifdef HAVE_HEIMDAL_VERSION
446 krb5_crypto krbCrypto,
454 krbBlockSize(krb5_context krbContext,
455 #ifdef HAVE_HEIMDAL_VERSION
456 krb5_crypto krbCrypto,
463 krbEnctypeToString(krb5_context krbContext,
464 krb5_enctype enctype,
466 gss_buffer_t string);
469 krbMakeAuthDataKdcIssued(krb5_context context,
470 const krb5_keyblock *key,
471 krb5_const_principal issuer,
472 #ifdef HAVE_HEIMDAL_VERSION
473 const AuthorizationData *authdata,
474 AuthorizationData *adKdcIssued
476 krb5_authdata *const *authdata,
477 krb5_authdata ***adKdcIssued
482 krbMakeCred(krb5_context context,
483 krb5_auth_context authcontext,
489 gssEapExportLucidSecContext(OM_uint32 *minor,
491 const gss_OID desiredObject,
492 gss_buffer_set_t *data_set);
495 extern gss_OID GSS_EAP_MECHANISM;
497 #define OID_FLAG_NULL_VALID 0x00000001
498 #define OID_FLAG_FAMILY_MECH_VALID 0x00000002
499 #define OID_FLAG_MAP_NULL_TO_DEFAULT_MECH 0x00000004
500 #define OID_FLAG_MAP_FAMILY_MECH_TO_NULL 0x00000008
503 gssEapCanonicalizeOid(OM_uint32 *minor,
509 gssEapReleaseOid(OM_uint32 *minor, gss_OID *oid);
512 gssEapDefaultMech(OM_uint32 *minor,
516 gssEapIndicateMechs(OM_uint32 *minor,
520 gssEapEnctypeToOid(OM_uint32 *minor,
521 krb5_enctype enctype,
525 gssEapOidToEnctype(OM_uint32 *minor,
527 krb5_enctype *enctype);
530 gssEapIsMechanismOid(const gss_OID oid);
533 gssEapIsConcreteMechanismOid(const gss_OID oid);
536 gssEapValidateMechs(OM_uint32 *minor,
537 const gss_OID_set mechs);
540 gssEapOidToSaslName(const gss_OID oid);
543 gssEapSaslNameToOid(const gss_buffer_t name);
545 /* util_moonshot.c */
547 libMoonshotResolveDefaultIdentity(OM_uint32 *minor,
548 const gss_cred_id_t cred,
552 libMoonshotResolveInitiatorCred(OM_uint32 *minor,
554 const gss_name_t targetName);
557 #define EXPORT_NAME_FLAG_OID 0x1
558 #define EXPORT_NAME_FLAG_COMPOSITE 0x2
559 #define EXPORT_NAME_FLAG_ALLOW_COMPOSITE 0x4
561 OM_uint32 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName);
562 OM_uint32 gssEapReleaseName(OM_uint32 *minor, gss_name_t *pName);
563 OM_uint32 gssEapExportName(OM_uint32 *minor,
564 const gss_name_t name,
565 gss_buffer_t exportedName);
566 OM_uint32 gssEapExportNameInternal(OM_uint32 *minor,
567 const gss_name_t name,
568 gss_buffer_t exportedName,
570 OM_uint32 gssEapImportName(OM_uint32 *minor,
571 const gss_buffer_t input_name_buffer,
572 const gss_OID input_name_type,
573 const gss_OID input_mech_type,
574 gss_name_t *output_name);
575 OM_uint32 gssEapImportNameInternal(OM_uint32 *minor,
576 const gss_buffer_t input_name_buffer,
577 gss_name_t *output_name,
580 gssEapDuplicateName(OM_uint32 *minor,
581 const gss_name_t input_name,
582 gss_name_t *dest_name);
585 gssEapCanonicalizeName(OM_uint32 *minor,
586 const gss_name_t input_name,
587 const gss_OID mech_type,
588 gss_name_t *dest_name);
591 gssEapDisplayName(OM_uint32 *minor,
593 gss_buffer_t output_name_buffer,
594 gss_OID *output_name_type);
597 gssEapCompareName(OM_uint32 *minor,
604 composeOid(OM_uint32 *minor_status,
611 decomposeOid(OM_uint32 *minor_status,
618 duplicateOid(OM_uint32 *minor_status,
619 const gss_OID_desc * const oid,
623 duplicateOidSet(OM_uint32 *minor,
624 const gss_OID_set src,
628 oidEqual(const gss_OID_desc *o1, const gss_OID_desc *o2)
630 if (o1 == GSS_C_NO_OID)
631 return (o2 == GSS_C_NO_OID);
632 else if (o2 == GSS_C_NO_OID)
633 return (o1 == GSS_C_NO_OID);
635 return (o1->length == o2->length &&
636 memcmp(o1->elements, o2->elements, o1->length) == 0);
639 /* util_ordering.c */
641 sequenceInternalize(OM_uint32 *minor,
647 sequenceExternalize(OM_uint32 *minor,
653 sequenceSize(void *vqueue);
656 sequenceFree(OM_uint32 *minor, void **vqueue);
659 sequenceCheck(OM_uint32 *minor, void **vqueue, uint64_t seqnum);
662 sequenceInit(OM_uint32 *minor, void **vqueue, uint64_t seqnum,
663 int do_replay, int do_sequence, int wide_nums);
667 GSSEAP_STATE_INITIAL = 0x01, /* initial state */
668 GSSEAP_STATE_AUTHENTICATE = 0x02, /* exchange EAP messages */
669 GSSEAP_STATE_INITIATOR_EXTS = 0x04, /* initiator extensions */
670 GSSEAP_STATE_ACCEPTOR_EXTS = 0x08, /* acceptor extensions */
671 #ifdef GSSEAP_ENABLE_REAUTH
672 GSSEAP_STATE_REAUTHENTICATE = 0x10, /* GSS reauthentication messages */
674 GSSEAP_STATE_ESTABLISHED = 0x20, /* context established */
675 GSSEAP_STATE_ALL = 0x3F
678 #define GSSEAP_STATE_NEXT(s) ((s) << 1)
680 #define GSSEAP_SM_STATE(ctx) ((ctx)->state)
683 void gssEapSmTransition(gss_ctx_id_t ctx, enum gss_eap_state state);
684 #define GSSEAP_SM_TRANSITION(ctx, state) gssEapSmTransition((ctx), (state))
686 #define GSSEAP_SM_TRANSITION(ctx, newstate) do { (ctx)->state = (newstate); } while (0)
689 #define GSSEAP_SM_TRANSITION_NEXT(ctx) GSSEAP_SM_TRANSITION((ctx), GSSEAP_STATE_NEXT(GSSEAP_SM_STATE((ctx))))
691 /* state machine entry */
693 OM_uint32 inputTokenType;
694 OM_uint32 outputTokenType;
695 enum gss_eap_state validStates;
697 OM_uint32 (*processToken)(OM_uint32 *,
704 gss_channel_bindings_t,
710 /* state machine flags, set by handler */
711 #define SM_FLAG_FORCE_SEND_TOKEN 0x00000001 /* send token even if no inner tokens */
712 #define SM_FLAG_OUTPUT_TOKEN_CRITICAL 0x00000002 /* output token is critical */
714 /* state machine flags, set by state machine */
715 #define SM_FLAG_INPUT_TOKEN_CRITICAL 0x10000000 /* input token was critical */
717 #define SM_ITOK_FLAG_REQUIRED 0x00000001 /* received tokens must be present */
720 gssEapSmStep(OM_uint32 *minor,
727 gss_channel_bindings_t chanBindings,
728 gss_buffer_t inputToken,
729 gss_buffer_t outputToken,
730 struct gss_eap_sm *sm,
734 gssEapSmTransition(gss_ctx_id_t ctx, enum gss_eap_state state);
737 struct gss_eap_token_buffer_set {
738 gss_buffer_set_desc buffers; /* pointers only */
743 gssEapEncodeInnerTokens(OM_uint32 *minor,
744 struct gss_eap_token_buffer_set *tokens,
745 gss_buffer_t buffer);
747 gssEapDecodeInnerTokens(OM_uint32 *minor,
748 const gss_buffer_t buffer,
749 struct gss_eap_token_buffer_set *tokens);
752 gssEapReleaseInnerTokens(OM_uint32 *minor,
753 struct gss_eap_token_buffer_set *tokens,
757 gssEapAllocInnerTokens(OM_uint32 *minor,
759 struct gss_eap_token_buffer_set *tokens);
762 tokenSize(const gss_OID_desc *mech, size_t body_size);
765 makeTokenHeader(const gss_OID_desc *mech,
768 enum gss_eap_token_type tok_type);
771 verifyTokenHeader(OM_uint32 *minor,
774 unsigned char **buf_in,
776 enum gss_eap_token_type *ret_tok_type);
780 #ifndef GSSEAP_MALLOC
781 #define GSSEAP_CALLOC calloc
782 #define GSSEAP_MALLOC malloc
783 #define GSSEAP_FREE free
784 #define GSSEAP_REALLOC realloc
787 #ifndef GSSAPI_CALLCONV
788 #define GSSAPI_CALLCONV KRB5_CALLCONV
791 #ifndef GSSEAP_ASSERT
793 #define GSSEAP_ASSERT(x) assert((x))
794 #endif /* !GSSEAP_ASSERT */
797 #define GSSEAP_CONSTRUCTOR
798 #define GSSEAP_DESTRUCTOR
800 #define GSSEAP_CONSTRUCTOR __attribute__((constructor))
801 #define GSSEAP_DESTRUCTOR __attribute__((destructor))
804 #define GSSEAP_NOT_IMPLEMENTED do { \
805 GSSEAP_ASSERT(0 && "not implemented"); \
807 return GSS_S_FAILURE; \
814 #define GSSEAP_GET_LAST_ERROR() (GetLastError()) /* XXX FIXME */
816 #define GSSEAP_MUTEX CRITICAL_SECTION
817 #define GSSEAP_MUTEX_INIT(m) (InitializeCriticalSection((m)), 0)
818 #define GSSEAP_MUTEX_DESTROY(m) DeleteCriticalSection((m))
819 #define GSSEAP_MUTEX_LOCK(m) EnterCriticalSection((m))
820 #define GSSEAP_MUTEX_UNLOCK(m) LeaveCriticalSection((m))
821 #define GSSEAP_ONCE_LEAVE do { return TRUE; } while (0)
823 /* Thread-local is handled separately */
825 #define GSSEAP_THREAD_ONCE INIT_ONCE
826 #define GSSEAP_ONCE_CALLBACK(cb) BOOL CALLBACK cb(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
827 #define GSSEAP_ONCE(o, i) InitOnceExecuteOnce((o), (i), NULL, NULL)
828 #define GSSEAP_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT
834 #define GSSEAP_GET_LAST_ERROR() (errno)
836 #define GSSEAP_MUTEX pthread_mutex_t
837 #define GSSEAP_MUTEX_INIT(m) pthread_mutex_init((m), NULL)
838 #define GSSEAP_MUTEX_DESTROY(m) pthread_mutex_destroy((m))
839 #define GSSEAP_MUTEX_LOCK(m) pthread_mutex_lock((m))
840 #define GSSEAP_MUTEX_UNLOCK(m) pthread_mutex_unlock((m))
842 #define GSSEAP_THREAD_KEY pthread_key_t
843 #define GSSEAP_KEY_CREATE(k, d) pthread_key_create((k), (d))
844 #define GSSEAP_GETSPECIFIC(k) pthread_getspecific((k))
845 #define GSSEAP_SETSPECIFIC(k, d) pthread_setspecific((k), (d))
847 #define GSSEAP_THREAD_ONCE pthread_once_t
848 #define GSSEAP_ONCE_CALLBACK(cb) void cb(void)
849 #define GSSEAP_ONCE(o, i) pthread_once((o), (i))
850 #define GSSEAP_ONCE_INITIALIZER PTHREAD_ONCE_INIT
851 #define GSSEAP_ONCE_LEAVE do { } while (0)
855 /* Helper functions */
857 store_uint16_be(uint16_t val, void *vp)
859 unsigned char *p = (unsigned char *)vp;
861 p[0] = (val >> 8) & 0xff;
862 p[1] = (val ) & 0xff;
865 static inline uint16_t
866 load_uint16_be(const void *cvp)
868 const unsigned char *p = (const unsigned char *)cvp;
870 return (p[1] | (p[0] << 8));
874 store_uint32_be(uint32_t val, void *vp)
876 unsigned char *p = (unsigned char *)vp;
878 p[0] = (val >> 24) & 0xff;
879 p[1] = (val >> 16) & 0xff;
880 p[2] = (val >> 8) & 0xff;
881 p[3] = (val ) & 0xff;
884 static inline uint32_t
885 load_uint32_be(const void *cvp)
887 const unsigned char *p = (const unsigned char *)cvp;
889 return (p[3] | (p[2] << 8)
890 | ((uint32_t) p[1] << 16)
891 | ((uint32_t) p[0] << 24));
895 store_uint64_be(uint64_t val, void *vp)
897 unsigned char *p = (unsigned char *)vp;
899 p[0] = (unsigned char)((val >> 56) & 0xff);
900 p[1] = (unsigned char)((val >> 48) & 0xff);
901 p[2] = (unsigned char)((val >> 40) & 0xff);
902 p[3] = (unsigned char)((val >> 32) & 0xff);
903 p[4] = (unsigned char)((val >> 24) & 0xff);
904 p[5] = (unsigned char)((val >> 16) & 0xff);
905 p[6] = (unsigned char)((val >> 8) & 0xff);
906 p[7] = (unsigned char)((val ) & 0xff);
909 static inline uint64_t
910 load_uint64_be(const void *cvp)
912 const unsigned char *p = (const unsigned char *)cvp;
914 return ((uint64_t)load_uint32_be(p) << 32) | load_uint32_be(p + 4);
917 static inline unsigned char *
918 store_buffer(gss_buffer_t buffer, void *vp, int wide_nums)
920 unsigned char *p = (unsigned char *)vp;
923 store_uint64_be(buffer->length, p);
926 store_uint32_be(buffer->length, p);
930 if (buffer->value != NULL) {
931 memcpy(p, buffer->value, buffer->length);
938 static inline unsigned char *
939 load_buffer(const void *cvp, size_t length, gss_buffer_t buffer)
942 buffer->value = GSSEAP_MALLOC(length);
943 if (buffer->value == NULL)
945 buffer->length = length;
946 memcpy(buffer->value, cvp, length);
947 return (unsigned char *)cvp + length;
950 static inline unsigned char *
951 store_oid(gss_OID oid, void *vp)
955 if (oid != GSS_C_NO_OID) {
956 buf.length = oid->length;
957 buf.value = oid->elements;
963 return store_buffer(&buf, vp, FALSE);
967 krbDataToGssBuffer(krb5_data *data, gss_buffer_t buffer)
969 buffer->value = (void *)data->data;
970 buffer->length = data->length;
974 krbPrincComponentToGssBuffer(krb5_principal krbPrinc,
975 int index, gss_buffer_t buffer)
977 #ifdef HAVE_HEIMDAL_VERSION
978 buffer->value = (void *)KRB_PRINC_NAME(krbPrinc)[index];
979 buffer->length = strlen((char *)buffer->value);
981 buffer->value = (void *)krb5_princ_component(NULL, krbPrinc, index)->data;
982 buffer->length = krb5_princ_component(NULL, krbPrinc, index)->length;
983 #endif /* HAVE_HEIMDAL_VERSION */
987 krbPrincRealmToGssBuffer(krb5_principal krbPrinc, gss_buffer_t buffer)
989 #ifdef HAVE_HEIMDAL_VERSION
990 buffer->value = (void *)KRB_PRINC_REALM(krbPrinc);
991 buffer->length = strlen((char *)buffer->value);
993 krbDataToGssBuffer(KRB_PRINC_REALM(krbPrinc), buffer);
998 gssBufferToKrbData(gss_buffer_t buffer, krb5_data *data)
1000 data->data = (char *)buffer->value;
1001 data->length = buffer->length;
1005 struct gss_eap_status_info;
1007 struct gss_eap_thread_local_data {
1008 krb5_context krbContext;
1009 struct gss_eap_status_info *statusInfo;
1012 struct gss_eap_thread_local_data *
1013 gssEapGetThreadLocalData(void);
1016 gssEapDestroyStatusInfo(struct gss_eap_status_info *status);
1019 gssEapDestroyKrbContext(krb5_context context);
1025 #ifdef GSSEAP_ENABLE_ACCEPTOR
1026 #include "util_json.h"
1027 #include "util_attr.h"
1028 #include "util_base64.h"
1029 #endif /* GSSEAP_ENABLE_ACCEPTOR */
1030 #ifdef GSSEAP_ENABLE_REAUTH
1031 #include "util_reauth.h"
1034 #endif /* _UTIL_H_ */