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 GSS_C_IDENTIFY_FLAG | \
216 GSS_C_EXTENDED_ERROR_FLAG )
218 OM_uint32 gssEapAllocContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
219 OM_uint32 gssEapReleaseContext(OM_uint32 *minor, gss_ctx_id_t *pCtx);
222 gssEapMakeToken(OM_uint32 *minor,
224 const gss_buffer_t innerToken,
225 enum gss_eap_token_type tokenType,
226 gss_buffer_t outputToken);
229 gssEapVerifyToken(OM_uint32 *minor,
231 const gss_buffer_t inputToken,
232 enum gss_eap_token_type *tokenType,
233 gss_buffer_t innerInputToken);
236 gssEapContextTime(OM_uint32 *minor,
237 gss_ctx_id_t context_handle,
238 OM_uint32 *time_rec);
241 gssEapMakeTokenMIC(OM_uint32 *minor,
243 gss_buffer_t tokenMIC);
246 gssEapVerifyTokenMIC(OM_uint32 *minor,
248 const gss_buffer_t tokenMIC);
251 OM_uint32 gssEapAllocCred(OM_uint32 *minor, gss_cred_id_t *pCred);
252 OM_uint32 gssEapReleaseCred(OM_uint32 *minor, gss_cred_id_t *pCred);
255 gssEapPrimaryMechForCred(gss_cred_id_t cred);
258 gssEapAcquireCred(OM_uint32 *minor,
259 const gss_name_t desiredName,
261 const gss_OID_set desiredMechs,
263 gss_cred_id_t *pCred,
264 gss_OID_set *pActualMechs,
268 gssEapSetCredPassword(OM_uint32 *minor,
270 const gss_buffer_t password);
273 gssEapSetCredClientCertificate(OM_uint32 *minor,
275 const gss_buffer_t clientCert,
276 const gss_buffer_t privateKey);
279 gssEapSetCredService(OM_uint32 *minor,
281 const gss_name_t target);
284 gssEapResolveInitiatorCred(OM_uint32 *minor,
285 const gss_cred_id_t cred,
286 const gss_name_t target,
287 gss_cred_id_t *resolvedCred);
289 int gssEapCredAvailable(gss_cred_id_t cred, gss_OID mech);
292 gssEapInquireCred(OM_uint32 *minor,
295 OM_uint32 *pLifetime,
296 gss_cred_usage_t *cred_usage,
297 gss_OID_set *mechanisms);
301 gssEapEncrypt(krb5_context context, int dce_style, size_t ec,
303 #ifdef HAVE_HEIMDAL_VERSION
309 gss_iov_buffer_desc *iov, int iov_count);
312 gssEapDecrypt(krb5_context context, int dce_style, size_t ec,
314 #ifdef HAVE_HEIMDAL_VERSION
320 gss_iov_buffer_desc *iov, int iov_count);
323 gssEapMapCryptoFlag(OM_uint32 type);
326 gssEapLocateIov(gss_iov_buffer_desc *iov,
331 gssEapIovMessageLength(gss_iov_buffer_desc *iov,
334 size_t *assoc_data_length);
337 gssEapReleaseIov(gss_iov_buffer_desc *iov, int iov_count);
340 gssEapIsIntegrityOnly(gss_iov_buffer_desc *iov, int iov_count);
343 gssEapAllocIov(gss_iov_buffer_t iov, size_t size);
346 gssEapDeriveRfc3961Key(OM_uint32 *minor,
347 const unsigned char *key,
349 krb5_enctype enctype,
350 krb5_keyblock *pKey);
356 * If your Kerberos library uses a different allocator to your
357 * GSS mechanism glue, then you might wish to define these in
358 * config.h or elsewhere. This should eventually go away when
359 * we no longer need to allocate memory that is freed by the
362 #define KRB_CALLOC calloc
363 #define KRB_MALLOC malloc
364 #define KRB_FREE free
365 #define KRB_REALLOC realloc
366 #endif /* KRB_MALLOC */
368 #ifdef HAVE_HEIMDAL_VERSION
370 #define KRB_TIME_FOREVER ((time_t)~0L)
372 #define KRB_KEY_TYPE(key) ((key)->keytype)
373 #define KRB_KEY_DATA(key) ((key)->keyvalue.data)
374 #define KRB_KEY_LENGTH(key) ((key)->keyvalue.length)
376 #define KRB_PRINC_LENGTH(princ) ((princ)->name.name_string.len)
377 #define KRB_PRINC_TYPE(princ) ((princ)->name.name_type)
378 #define KRB_PRINC_NAME(princ) ((princ)->name.name_string.val)
379 #define KRB_PRINC_REALM(princ) ((princ)->realm)
381 #define KRB_KT_ENT_KEYBLOCK(e) (&(e)->keyblock)
382 #define KRB_KT_ENT_FREE(c, e) krb5_kt_free_entry((c), (e))
384 #define KRB_CRYPTO_CONTEXT(ctx) (krbCrypto)
386 #define KRB_DATA_INIT(d) krb5_data_zero((d))
390 #define KRB_TIME_FOREVER KRB5_INT32_MAX
392 #define KRB_KEY_TYPE(key) ((key)->enctype)
393 #define KRB_KEY_DATA(key) ((key)->contents)
394 #define KRB_KEY_LENGTH(key) ((key)->length)
396 #define KRB_PRINC_LENGTH(princ) (krb5_princ_size(NULL, (princ)))
397 #define KRB_PRINC_TYPE(princ) (krb5_princ_type(NULL, (princ)))
398 #define KRB_PRINC_NAME(princ) (krb5_princ_name(NULL, (princ)))
399 #define KRB_PRINC_REALM(princ) (krb5_princ_realm(NULL, (princ)))
401 #define KRB_KT_ENT_KEYBLOCK(e) (&(e)->key)
402 #define KRB_KT_ENT_FREE(c, e) krb5_free_keytab_entry_contents((c), (e))
404 #define KRB_CRYPTO_CONTEXT(ctx) (&(ctx)->rfc3961Key)
406 #define KRB_DATA_INIT(d) do { \
407 (d)->magic = KV5M_DATA; \
412 #endif /* HAVE_HEIMDAL_VERSION */
414 #define KRB_KEY_INIT(key) do { \
415 KRB_KEY_TYPE(key) = ENCTYPE_NULL; \
416 KRB_KEY_DATA(key) = NULL; \
417 KRB_KEY_LENGTH(key) = 0; \
420 #define GSSEAP_KRB_INIT(ctx) do { \
421 OM_uint32 tmpMajor; \
423 tmpMajor = gssEapKerberosInit(minor, ctx); \
424 if (GSS_ERROR(tmpMajor)) { \
430 gssEapKerberosInit(OM_uint32 *minor, krb5_context *context);
433 rfc3961ChecksumTypeForKey(OM_uint32 *minor,
435 krb5_cksumtype *cksumtype);
438 krbCryptoLength(krb5_context krbContext,
439 #ifdef HAVE_HEIMDAL_VERSION
440 krb5_crypto krbCrypto,
448 krbPaddingLength(krb5_context krbContext,
449 #ifdef HAVE_HEIMDAL_VERSION
450 krb5_crypto krbCrypto,
458 krbBlockSize(krb5_context krbContext,
459 #ifdef HAVE_HEIMDAL_VERSION
460 krb5_crypto krbCrypto,
467 krbEnctypeToString(krb5_context krbContext,
468 krb5_enctype enctype,
470 gss_buffer_t string);
473 krbMakeAuthDataKdcIssued(krb5_context context,
474 const krb5_keyblock *key,
475 krb5_const_principal issuer,
476 #ifdef HAVE_HEIMDAL_VERSION
477 const AuthorizationData *authdata,
478 AuthorizationData *adKdcIssued
480 krb5_authdata *const *authdata,
481 krb5_authdata ***adKdcIssued
486 krbMakeCred(krb5_context context,
487 krb5_auth_context authcontext,
493 gssEapExportLucidSecContext(OM_uint32 *minor,
495 const gss_OID desiredObject,
496 gss_buffer_set_t *data_set);
499 extern gss_OID GSS_EAP_MECHANISM;
501 #define OID_FLAG_NULL_VALID 0x00000001
502 #define OID_FLAG_FAMILY_MECH_VALID 0x00000002
503 #define OID_FLAG_MAP_NULL_TO_DEFAULT_MECH 0x00000004
504 #define OID_FLAG_MAP_FAMILY_MECH_TO_NULL 0x00000008
507 gssEapCanonicalizeOid(OM_uint32 *minor,
513 gssEapReleaseOid(OM_uint32 *minor, gss_OID *oid);
516 gssEapDefaultMech(OM_uint32 *minor,
520 gssEapIndicateMechs(OM_uint32 *minor,
524 gssEapEnctypeToOid(OM_uint32 *minor,
525 krb5_enctype enctype,
529 gssEapOidToEnctype(OM_uint32 *minor,
531 krb5_enctype *enctype);
534 gssEapIsMechanismOid(const gss_OID oid);
537 gssEapIsConcreteMechanismOid(const gss_OID oid);
540 gssEapValidateMechs(OM_uint32 *minor,
541 const gss_OID_set mechs);
544 gssEapOidToSaslName(const gss_OID oid);
547 gssEapSaslNameToOid(const gss_buffer_t name);
549 /* util_moonshot.c */
551 libMoonshotResolveDefaultIdentity(OM_uint32 *minor,
552 const gss_cred_id_t cred,
556 libMoonshotResolveInitiatorCred(OM_uint32 *minor,
558 const gss_name_t targetName);
561 #define EXPORT_NAME_FLAG_OID 0x1
562 #define EXPORT_NAME_FLAG_COMPOSITE 0x2
563 #define EXPORT_NAME_FLAG_ALLOW_COMPOSITE 0x4
565 OM_uint32 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName);
566 OM_uint32 gssEapReleaseName(OM_uint32 *minor, gss_name_t *pName);
567 OM_uint32 gssEapExportName(OM_uint32 *minor,
568 const gss_name_t name,
569 gss_buffer_t exportedName);
570 OM_uint32 gssEapExportNameInternal(OM_uint32 *minor,
571 const gss_name_t name,
572 gss_buffer_t exportedName,
574 OM_uint32 gssEapImportName(OM_uint32 *minor,
575 const gss_buffer_t input_name_buffer,
576 const gss_OID input_name_type,
577 const gss_OID input_mech_type,
578 gss_name_t *output_name);
579 OM_uint32 gssEapImportNameInternal(OM_uint32 *minor,
580 const gss_buffer_t input_name_buffer,
581 gss_name_t *output_name,
584 gssEapDuplicateName(OM_uint32 *minor,
585 const gss_name_t input_name,
586 gss_name_t *dest_name);
589 gssEapCanonicalizeName(OM_uint32 *minor,
590 const gss_name_t input_name,
591 const gss_OID mech_type,
592 gss_name_t *dest_name);
595 gssEapDisplayName(OM_uint32 *minor,
597 gss_buffer_t output_name_buffer,
598 gss_OID *output_name_type);
601 gssEapCompareName(OM_uint32 *minor,
608 composeOid(OM_uint32 *minor_status,
615 decomposeOid(OM_uint32 *minor_status,
622 duplicateOid(OM_uint32 *minor_status,
623 const gss_OID_desc * const oid,
627 duplicateOidSet(OM_uint32 *minor,
628 const gss_OID_set src,
632 oidEqual(const gss_OID_desc *o1, const gss_OID_desc *o2)
634 if (o1 == GSS_C_NO_OID)
635 return (o2 == GSS_C_NO_OID);
636 else if (o2 == GSS_C_NO_OID)
637 return (o1 == GSS_C_NO_OID);
639 return (o1->length == o2->length &&
640 memcmp(o1->elements, o2->elements, o1->length) == 0);
643 /* util_ordering.c */
645 sequenceInternalize(OM_uint32 *minor,
651 sequenceExternalize(OM_uint32 *minor,
657 sequenceSize(void *vqueue);
660 sequenceFree(OM_uint32 *minor, void **vqueue);
663 sequenceCheck(OM_uint32 *minor, void **vqueue, uint64_t seqnum);
666 sequenceInit(OM_uint32 *minor, void **vqueue, uint64_t seqnum,
667 int do_replay, int do_sequence, int wide_nums);
671 GSSEAP_STATE_INITIAL = 0x01, /* initial state */
672 GSSEAP_STATE_AUTHENTICATE = 0x02, /* exchange EAP messages */
673 GSSEAP_STATE_INITIATOR_EXTS = 0x04, /* initiator extensions */
674 GSSEAP_STATE_ACCEPTOR_EXTS = 0x08, /* acceptor extensions */
675 #ifdef GSSEAP_ENABLE_REAUTH
676 GSSEAP_STATE_REAUTHENTICATE = 0x10, /* GSS reauthentication messages */
678 GSSEAP_STATE_ESTABLISHED = 0x20, /* context established */
679 GSSEAP_STATE_ALL = 0x3F
682 #define GSSEAP_STATE_NEXT(s) ((s) << 1)
684 #define GSSEAP_SM_STATE(ctx) ((ctx)->state)
687 void gssEapSmTransition(gss_ctx_id_t ctx, enum gss_eap_state state);
688 #define GSSEAP_SM_TRANSITION(ctx, state) gssEapSmTransition((ctx), (state))
690 #define GSSEAP_SM_TRANSITION(ctx, newstate) do { (ctx)->state = (newstate); } while (0)
693 #define GSSEAP_SM_TRANSITION_NEXT(ctx) GSSEAP_SM_TRANSITION((ctx), GSSEAP_STATE_NEXT(GSSEAP_SM_STATE((ctx))))
695 /* state machine entry */
697 OM_uint32 inputTokenType;
698 OM_uint32 outputTokenType;
699 enum gss_eap_state validStates;
701 OM_uint32 (*processToken)(OM_uint32 *,
708 gss_channel_bindings_t,
714 /* state machine flags, set by handler */
715 #define SM_FLAG_FORCE_SEND_TOKEN 0x00000001 /* send token even if no inner tokens */
716 #define SM_FLAG_OUTPUT_TOKEN_CRITICAL 0x00000002 /* output token is critical */
718 /* state machine flags, set by state machine */
719 #define SM_FLAG_INPUT_TOKEN_CRITICAL 0x10000000 /* input token was critical */
721 #define SM_ITOK_FLAG_REQUIRED 0x00000001 /* received tokens must be present */
724 gssEapSmStep(OM_uint32 *minor,
731 gss_channel_bindings_t chanBindings,
732 gss_buffer_t inputToken,
733 gss_buffer_t outputToken,
734 struct gss_eap_sm *sm,
738 gssEapSmTransition(gss_ctx_id_t ctx, enum gss_eap_state state);
741 struct gss_eap_token_buffer_set {
742 gss_buffer_set_desc buffers; /* pointers only */
747 gssEapEncodeInnerTokens(OM_uint32 *minor,
748 struct gss_eap_token_buffer_set *tokens,
749 gss_buffer_t buffer);
751 gssEapDecodeInnerTokens(OM_uint32 *minor,
752 const gss_buffer_t buffer,
753 struct gss_eap_token_buffer_set *tokens);
756 gssEapReleaseInnerTokens(OM_uint32 *minor,
757 struct gss_eap_token_buffer_set *tokens,
761 gssEapAllocInnerTokens(OM_uint32 *minor,
763 struct gss_eap_token_buffer_set *tokens);
766 tokenSize(const gss_OID_desc *mech, size_t body_size);
769 makeTokenHeader(const gss_OID_desc *mech,
772 enum gss_eap_token_type tok_type);
775 verifyTokenHeader(OM_uint32 *minor,
778 unsigned char **buf_in,
780 enum gss_eap_token_type *ret_tok_type);
784 #ifndef GSSEAP_MALLOC
785 #define GSSEAP_CALLOC calloc
786 #define GSSEAP_MALLOC malloc
787 #define GSSEAP_FREE free
788 #define GSSEAP_REALLOC realloc
791 #ifndef GSSAPI_CALLCONV
792 #define GSSAPI_CALLCONV KRB5_CALLCONV
795 #ifndef GSSEAP_ASSERT
797 #define GSSEAP_ASSERT(x) assert((x))
798 #endif /* !GSSEAP_ASSERT */
801 #define GSSEAP_CONSTRUCTOR
802 #define GSSEAP_DESTRUCTOR
804 #define GSSEAP_CONSTRUCTOR __attribute__((constructor))
805 #define GSSEAP_DESTRUCTOR __attribute__((destructor))
808 #define GSSEAP_NOT_IMPLEMENTED do { \
809 GSSEAP_ASSERT(0 && "not implemented"); \
811 return GSS_S_FAILURE; \
818 #define GSSEAP_GET_LAST_ERROR() (GetLastError()) /* XXX FIXME */
820 #define GSSEAP_MUTEX CRITICAL_SECTION
821 #define GSSEAP_MUTEX_INIT(m) (InitializeCriticalSection((m)), 0)
822 #define GSSEAP_MUTEX_DESTROY(m) DeleteCriticalSection((m))
823 #define GSSEAP_MUTEX_LOCK(m) EnterCriticalSection((m))
824 #define GSSEAP_MUTEX_UNLOCK(m) LeaveCriticalSection((m))
825 #define GSSEAP_ONCE_LEAVE do { return TRUE; } while (0)
827 /* Thread-local is handled separately */
829 #define GSSEAP_THREAD_ONCE INIT_ONCE
830 #define GSSEAP_ONCE_CALLBACK(cb) BOOL CALLBACK cb(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
831 #define GSSEAP_ONCE(o, i) InitOnceExecuteOnce((o), (i), NULL, NULL)
832 #define GSSEAP_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT
838 #define GSSEAP_GET_LAST_ERROR() (errno)
840 #define GSSEAP_MUTEX pthread_mutex_t
841 #define GSSEAP_MUTEX_INIT(m) pthread_mutex_init((m), NULL)
842 #define GSSEAP_MUTEX_DESTROY(m) pthread_mutex_destroy((m))
843 #define GSSEAP_MUTEX_LOCK(m) pthread_mutex_lock((m))
844 #define GSSEAP_MUTEX_UNLOCK(m) pthread_mutex_unlock((m))
846 #define GSSEAP_THREAD_KEY pthread_key_t
847 #define GSSEAP_KEY_CREATE(k, d) pthread_key_create((k), (d))
848 #define GSSEAP_GETSPECIFIC(k) pthread_getspecific((k))
849 #define GSSEAP_SETSPECIFIC(k, d) pthread_setspecific((k), (d))
851 #define GSSEAP_THREAD_ONCE pthread_once_t
852 #define GSSEAP_ONCE_CALLBACK(cb) void cb(void)
853 #define GSSEAP_ONCE(o, i) pthread_once((o), (i))
854 #define GSSEAP_ONCE_INITIALIZER PTHREAD_ONCE_INIT
855 #define GSSEAP_ONCE_LEAVE do { } while (0)
859 /* Helper functions */
861 store_uint16_be(uint16_t val, void *vp)
863 unsigned char *p = (unsigned char *)vp;
865 p[0] = (val >> 8) & 0xff;
866 p[1] = (val ) & 0xff;
869 static inline uint16_t
870 load_uint16_be(const void *cvp)
872 const unsigned char *p = (const unsigned char *)cvp;
874 return (p[1] | (p[0] << 8));
878 store_uint32_be(uint32_t val, void *vp)
880 unsigned char *p = (unsigned char *)vp;
882 p[0] = (val >> 24) & 0xff;
883 p[1] = (val >> 16) & 0xff;
884 p[2] = (val >> 8) & 0xff;
885 p[3] = (val ) & 0xff;
888 static inline uint32_t
889 load_uint32_be(const void *cvp)
891 const unsigned char *p = (const unsigned char *)cvp;
893 return (p[3] | (p[2] << 8)
894 | ((uint32_t) p[1] << 16)
895 | ((uint32_t) p[0] << 24));
899 store_uint64_be(uint64_t val, void *vp)
901 unsigned char *p = (unsigned char *)vp;
903 p[0] = (unsigned char)((val >> 56) & 0xff);
904 p[1] = (unsigned char)((val >> 48) & 0xff);
905 p[2] = (unsigned char)((val >> 40) & 0xff);
906 p[3] = (unsigned char)((val >> 32) & 0xff);
907 p[4] = (unsigned char)((val >> 24) & 0xff);
908 p[5] = (unsigned char)((val >> 16) & 0xff);
909 p[6] = (unsigned char)((val >> 8) & 0xff);
910 p[7] = (unsigned char)((val ) & 0xff);
913 static inline uint64_t
914 load_uint64_be(const void *cvp)
916 const unsigned char *p = (const unsigned char *)cvp;
918 return ((uint64_t)load_uint32_be(p) << 32) | load_uint32_be(p + 4);
921 static inline unsigned char *
922 store_buffer(gss_buffer_t buffer, void *vp, int wide_nums)
924 unsigned char *p = (unsigned char *)vp;
927 store_uint64_be(buffer->length, p);
930 store_uint32_be(buffer->length, p);
934 if (buffer->value != NULL) {
935 memcpy(p, buffer->value, buffer->length);
942 static inline unsigned char *
943 load_buffer(const void *cvp, size_t length, gss_buffer_t buffer)
946 buffer->value = GSSEAP_MALLOC(length);
947 if (buffer->value == NULL)
949 buffer->length = length;
950 memcpy(buffer->value, cvp, length);
951 return (unsigned char *)cvp + length;
954 static inline unsigned char *
955 store_oid(gss_OID oid, void *vp)
959 if (oid != GSS_C_NO_OID) {
960 buf.length = oid->length;
961 buf.value = oid->elements;
967 return store_buffer(&buf, vp, FALSE);
971 krbDataToGssBuffer(krb5_data *data, gss_buffer_t buffer)
973 buffer->value = (void *)data->data;
974 buffer->length = data->length;
978 krbPrincComponentToGssBuffer(krb5_principal krbPrinc,
979 int index, gss_buffer_t buffer)
981 #ifdef HAVE_HEIMDAL_VERSION
982 buffer->value = (void *)KRB_PRINC_NAME(krbPrinc)[index];
983 buffer->length = strlen((char *)buffer->value);
985 buffer->value = (void *)krb5_princ_component(NULL, krbPrinc, index)->data;
986 buffer->length = krb5_princ_component(NULL, krbPrinc, index)->length;
987 #endif /* HAVE_HEIMDAL_VERSION */
991 krbPrincRealmToGssBuffer(krb5_principal krbPrinc, gss_buffer_t buffer)
993 #ifdef HAVE_HEIMDAL_VERSION
994 buffer->value = (void *)KRB_PRINC_REALM(krbPrinc);
995 buffer->length = strlen((char *)buffer->value);
997 krbDataToGssBuffer(KRB_PRINC_REALM(krbPrinc), buffer);
1002 gssBufferToKrbData(gss_buffer_t buffer, krb5_data *data)
1004 data->data = (char *)buffer->value;
1005 data->length = buffer->length;
1009 struct gss_eap_status_info;
1011 struct gss_eap_thread_local_data {
1012 krb5_context krbContext;
1013 struct gss_eap_status_info *statusInfo;
1016 struct gss_eap_thread_local_data *
1017 gssEapGetThreadLocalData(void);
1020 gssEapDestroyStatusInfo(struct gss_eap_status_info *status);
1023 gssEapDestroyKrbContext(krb5_context context);
1029 #ifdef GSSEAP_ENABLE_ACCEPTOR
1030 #include "util_json.h"
1031 #include "util_attr.h"
1032 #include "util_base64.h"
1033 #endif /* GSSEAP_ENABLE_ACCEPTOR */
1034 #ifdef GSSEAP_ENABLE_REAUTH
1035 #include "util_reauth.h"
1038 #endif /* _UTIL_H_ */