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 #include "gssapiP_eap.h"
36 * 1.3.6.1.4.1.5322(padl)
39 * eap-aes128-cts-hmac-sha1-96(17)
40 * eap-aes256-cts-hmac-sha1-96(18)
43 * inquireSecContextByOid(1)
45 * setSecContextOption(3)
51 * Note: the enctype-less OID is used as the mechanism OID in exported
52 * names. There is no public symbol for it. This is consistent with
53 * the krb5 mechanism which, whilst known by many OIDs, always uses a
54 * canonical OID for exported names. (This OID is also returned by
57 static gss_OID_desc gssEapMechOids[] = {
58 /* 1.3.6.1.4.1.5322.22.1 */
59 { 9, "\x2B\x06\x01\x04\x01\xA9\x4A\x16\x01" },
60 /* 1.3.6.1.4.1.5322.22.1.17 */
61 { 10, "\x2B\x06\x01\x04\x01\xA9\x4A\x16\x01\x11" },
62 /* 1.3.6.1.4.1.5322.22.1.18 */
63 { 10, "\x2B\x06\x01\x04\x01\xA9\x4A\x16\x01\x12" }
66 gss_OID GSS_EAP_MECHANISM = &gssEapMechOids[0];
67 gss_OID GSS_EAP_AES128_CTS_HMAC_SHA1_96_MECHANISM = &gssEapMechOids[1];
68 gss_OID GSS_EAP_AES256_CTS_HMAC_SHA1_96_MECHANISM = &gssEapMechOids[2];
71 * Returns TRUE is the OID is a concrete mechanism OID, that is, one
72 * with a Kerberos enctype as the last element.
75 gssEapIsConcreteMechanismOid(const gss_OID oid)
77 return oid->length > GSS_EAP_MECHANISM->length &&
78 memcmp(oid->elements, GSS_EAP_MECHANISM->elements,
79 GSS_EAP_MECHANISM->length) == 0;
83 gssEapIsMechanismOid(const gss_OID oid)
85 return oid == GSS_C_NO_OID ||
86 oidEqual(oid, GSS_EAP_MECHANISM) ||
87 gssEapIsConcreteMechanismOid(oid);
91 * Validate that all elements are concrete mechanism OIDs.
94 gssEapValidateMechs(OM_uint32 *minor,
95 const gss_OID_set mechs)
101 if (mechs == GSS_C_NO_OID_SET) {
102 return GSS_S_COMPLETE;
105 for (i = 0; i < mechs->count; i++) {
106 gss_OID oid = &mechs->elements[i];
108 if (!gssEapIsConcreteMechanismOid(oid)) {
109 *minor = GSSEAP_WRONG_MECH;
110 return GSS_S_BAD_MECH;
114 return GSS_S_COMPLETE;
118 gssEapOidToEnctype(OM_uint32 *minor,
120 krb5_enctype *enctype)
125 major = decomposeOid(minor,
126 GSS_EAP_MECHANISM->elements,
127 GSS_EAP_MECHANISM->length,
130 if (major == GSS_S_COMPLETE)
137 gssEapEnctypeToOid(OM_uint32 *minor,
138 krb5_enctype enctype,
146 oid = (gss_OID)GSSEAP_MALLOC(sizeof(*oid));
149 return GSS_S_FAILURE;
152 oid->length = GSS_EAP_MECHANISM->length + 1;
153 oid->elements = GSSEAP_MALLOC(oid->length);
154 if (oid->elements == NULL) {
157 return GSS_S_FAILURE;
160 major = composeOid(minor,
161 GSS_EAP_MECHANISM->elements,
162 GSS_EAP_MECHANISM->length,
165 if (major == GSS_S_COMPLETE) {
166 gssEapInternalizeOid(oid, pOid);
169 GSSEAP_FREE(oid->elements);
177 gssEapIndicateMechs(OM_uint32 *minor,
180 krb5_context krbContext;
181 OM_uint32 major, tmpMinor;
182 krb5_enctype *etypes;
185 GSSEAP_KRB_INIT(&krbContext);
187 *minor = krb5_get_permitted_enctypes(krbContext, &etypes);
189 return GSS_S_FAILURE;
192 major = gss_create_empty_oid_set(minor, mechs);
193 if (GSS_ERROR(major)) {
194 GSSEAP_FREE(etypes); /* XXX */
198 for (i = 0; etypes[i] != ENCTYPE_NULL; i++) {
201 /* XXX currently we aren't equipped to encode these enctypes */
202 if (etypes[i] < 0 || etypes[i] > 127)
205 major = gssEapEnctypeToOid(minor, etypes[i], &mechOid);
206 if (GSS_ERROR(major))
209 major = gss_add_oid_set_member(minor, mechOid, mechs);
210 if (GSS_ERROR(major))
213 gss_release_oid(&tmpMinor, &mechOid);
216 GSSEAP_FREE(etypes); /* XXX */
223 gssEapDefaultMech(OM_uint32 *minor,
227 OM_uint32 major, tmpMinor;
229 major = gssEapIndicateMechs(minor, &mechs);
230 if (GSS_ERROR(major)) {
234 if (mechs->count == 0) {
235 gss_release_oid_set(&tmpMinor, &mechs);
236 return GSS_S_BAD_MECH;
239 if (!gssEapInternalizeOid(&mechs->elements[0], oid)) {
240 /* don't double-free if we didn't internalize it */
241 mechs->elements[0].length = 0;
242 mechs->elements[0].elements = NULL;
245 gss_release_oid_set(&tmpMinor, &mechs);
248 return GSS_S_COMPLETE;
252 gssEapInternalizeOid(const gss_OID oid,
253 gss_OID *const pInternalizedOid)
257 *pInternalizedOid = GSS_C_NO_OID;
260 i < sizeof(gssEapMechOids) / sizeof(gssEapMechOids[0]);
262 if (oidEqual(oid, &gssEapMechOids[i])) {
263 *pInternalizedOid = (const gss_OID)&gssEapMechOids[i];
268 if (*pInternalizedOid == GSS_C_NO_OID) {
269 if (oidEqual(oid, GSS_EAP_NT_PRINCIPAL_NAME))
270 *pInternalizedOid = (const gss_OID)GSS_EAP_NT_PRINCIPAL_NAME;
273 if (*pInternalizedOid == GSS_C_NO_OID) {
274 *pInternalizedOid = oid;
281 static gss_buffer_desc gssEapSaslMechs[] = {
282 { sizeof("EAP") - 1, "EAP", }, /* not used */
283 { sizeof("EAP-AES128") - 1, "EAP-AES128" },
284 { sizeof("EAP-AES256") - 1, "EAP-AES256" },
288 gssEapOidToSaslName(const gss_OID oid)
292 for (i = 1; i < sizeof(gssEapMechOids)/sizeof(gssEapMechOids[0]); i++) {
293 if (oidEqual(&gssEapMechOids[i], oid))
294 return &gssEapSaslMechs[i];
297 return GSS_C_NO_BUFFER;
301 gssEapSaslNameToOid(const gss_buffer_t name)
305 for (i = 1; i < sizeof(gssEapSaslMechs)/sizeof(gssEapSaslMechs[0]); i++) {
306 if (bufferEqual(&gssEapSaslMechs[i], name))
307 return &gssEapMechOids[i];