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 return GSS_S_BAD_MECH;
112 return GSS_S_COMPLETE;
116 gssEapOidToEnctype(OM_uint32 *minor,
118 krb5_enctype *enctype)
123 major = decomposeOid(minor,
124 GSS_EAP_MECHANISM->elements,
125 GSS_EAP_MECHANISM->length,
128 if (major == GSS_S_COMPLETE)
135 gssEapEnctypeToOid(OM_uint32 *minor,
136 krb5_enctype enctype,
144 oid = (gss_OID)GSSEAP_MALLOC(sizeof(*oid));
147 return GSS_S_FAILURE;
150 oid->length = GSS_EAP_MECHANISM->length + 1;
151 oid->elements = GSSEAP_MALLOC(oid->length);
152 if (oid->elements == NULL) {
155 return GSS_S_FAILURE;
158 major = composeOid(minor,
159 GSS_EAP_MECHANISM->elements,
160 GSS_EAP_MECHANISM->length,
163 if (major == GSS_S_COMPLETE) {
164 gssEapInternalizeOid(oid, pOid);
167 GSSEAP_FREE(oid->elements);
175 gssEapIndicateMechs(OM_uint32 *minor,
178 krb5_context krbContext;
179 OM_uint32 major, tmpMinor;
180 krb5_enctype *etypes;
183 GSSEAP_KRB_INIT(&krbContext);
185 *minor = krb5_get_permitted_enctypes(krbContext, &etypes);
187 return GSS_S_FAILURE;
190 major = gss_create_empty_oid_set(minor, mechs);
191 if (GSS_ERROR(major)) {
192 GSSEAP_FREE(etypes); /* XXX */
196 for (i = 0; etypes[i] != ENCTYPE_NULL; i++) {
199 /* XXX currently we aren't equipped to encode these enctypes */
200 if (etypes[i] < 0 || etypes[i] > 127)
203 major = gssEapEnctypeToOid(minor, etypes[i], &mechOid);
204 if (GSS_ERROR(major))
207 major = gss_add_oid_set_member(minor, mechOid, mechs);
208 if (GSS_ERROR(major))
211 gss_release_oid(&tmpMinor, &mechOid);
214 GSSEAP_FREE(etypes); /* XXX */
221 gssEapDefaultMech(OM_uint32 *minor,
225 OM_uint32 major, tmpMinor;
227 major = gssEapIndicateMechs(minor, &mechs);
228 if (GSS_ERROR(major)) {
232 if (mechs->count == 0) {
233 gss_release_oid_set(&tmpMinor, &mechs);
234 return GSS_S_BAD_MECH;
237 if (!gssEapInternalizeOid(&mechs->elements[0], oid)) {
238 /* don't double-free if we didn't internalize it */
239 mechs->elements[0].length = 0;
240 mechs->elements[0].elements = NULL;
243 gss_release_oid_set(&tmpMinor, &mechs);
246 return GSS_S_COMPLETE;
250 gssEapInternalizeOid(const gss_OID oid,
251 gss_OID *const pInternalizedOid)
255 *pInternalizedOid = GSS_C_NO_OID;
258 i < sizeof(gssEapMechOids) / sizeof(gssEapMechOids[0]);
260 if (oidEqual(oid, &gssEapMechOids[i])) {
261 *pInternalizedOid = (const gss_OID)&gssEapMechOids[i];
266 if (*pInternalizedOid == GSS_C_NO_OID) {
267 if (oidEqual(oid, GSS_EAP_NT_PRINCIPAL_NAME))
268 *pInternalizedOid = (const gss_OID)GSS_EAP_NT_PRINCIPAL_NAME;
271 if (*pInternalizedOid == GSS_C_NO_OID) {
272 *pInternalizedOid = oid;
279 static gss_buffer_desc gssEapSaslMechs[] = {
280 { sizeof("EAP") - 1, "EAP", }, /* not used */
281 { sizeof("EAP-AES128") - 1, "EAP-AES128" },
282 { sizeof("EAP-AES256") - 1, "EAP-AES256" },
286 gssEapOidToSaslName(const gss_OID oid)
290 for (i = 1; i < sizeof(gssEapMechOids)/sizeof(gssEapMechOids[0]); i++) {
291 if (oidEqual(&gssEapMechOids[i], oid))
292 return &gssEapSaslMechs[i];
295 return GSS_C_NO_BUFFER;
299 gssEapSaslNameToOid(const gss_buffer_t name)
303 for (i = 1; i < sizeof(gssEapSaslMechs)/sizeof(gssEapSaslMechs[0]); i++) {
304 if (bufferEqual(&gssEapSaslMechs[i], name))
305 return &gssEapMechOids[i];