2 * Copyright (c) 2010, 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 2009 by the 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.
56 #include "gssapiP_eap.h"
58 static const gss_OID_desc gssEapNtPrincipalName = {
59 /* 1.3.6.1.4.1.5322.21.2.1 */
60 12, "\x06\x0A\x2B\x06\x01\x04\x01\xA9\x4A\x15\x02\x01"
63 const gss_OID_desc *const GSS_EAP_NT_PRINCIPAL_NAME =
64 &gssEapNtPrincipalName;
67 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName)
72 assert(*pName == GSS_C_NO_NAME);
74 name = (gss_name_t)GSSEAP_CALLOC(1, sizeof(*name));
80 if (GSSEAP_MUTEX_INIT(&name->mutex) != 0) {
82 gssEapReleaseName(&tmpMinor, &name);
88 return GSS_S_COMPLETE;
92 gssEapReleaseName(OM_uint32 *minor, gss_name_t *pName)
95 krb5_context krbContext = NULL;
99 return GSS_S_COMPLETE;
103 if (name == GSS_C_NO_NAME) {
104 return GSS_S_COMPLETE;
107 GSSEAP_KRB_INIT(&krbContext);
108 krb5_free_principal(krbContext, name->krbPrincipal);
110 radiusFreeAVPs(&tmpMinor, name->avps);
111 samlFreeAssertion(&tmpMinor, name->assertion);
113 GSSEAP_MUTEX_DESTROY(&name->mutex);
118 return GSS_S_COMPLETE;
121 OM_uint32 gssEapExportName(OM_uint32 *minor,
122 const gss_name_t name,
123 gss_buffer_t exportedName,
126 OM_uint32 major, tmpMinor;
127 krb5_context krbContext;
128 char *krbName = NULL;
132 exportedName->length = 0;
133 exportedName->value = NULL;
135 GSSEAP_KRB_INIT(&krbContext);
137 if (name == GSS_C_NO_NAME) {
139 return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME;
142 GSSEAP_MUTEX_LOCK(&name->mutex);
145 * Don't export a composite name if we don't have any attributes.
148 (name->flags & (NAME_FLAG_SAML | NAME_FLAG_RADIUS)) == 0) {
152 *minor = krb5_unparse_name(krbContext, name->krbPrincipal, &krbName);
154 major = GSS_S_FAILURE;
157 krbNameLen = strlen(krbName);
159 exportedName->length = 6 + GSS_EAP_MECHANISM->length + krbNameLen;
161 /* TODO: export SAML/AVP, this is pending specification */
162 GSSEAP_NOT_IMPLEMENTED;
165 exportedName->value = GSSEAP_MALLOC(exportedName->value);
166 if (exportedName->value == NULL) {
168 major = GSS_S_FAILURE;
172 p = (unsigned char *)exportedName->value;
179 store_uint16_be(GSS_EAP_MECHANISM->length + 2, p);
182 *p++ = GSS_EAP_MECHANISM->length & 0xff;
183 memcpy(p, GSS_EAP_MECHANISM->elements, GSS_EAP_MECHANISM->length);
184 p += GSS_EAP_MECHANISM->length;
186 store_uint32_be(krbNameLen, p);
188 memcpy(p, krbName, krbNameLen);
192 major = GSS_S_COMPLETE;
195 GSSEAP_MUTEX_UNLOCK(&name->mutex);
196 if (GSS_ERROR(major))
197 gss_release_buffer(&tmpMinor, exportedName);
198 krb5_free_unparsed_name(krbContext, krbName);