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 * Prefix for GSS EAP mechanisms. A Kerberos encryption type is
52 * concatenated with this to form a concrete mechanism OID.
54 static const gss_OID_desc gssEapMechPrefix = {
55 /* 1.3.6.1.4.1.5322.21.1 */
56 11, "\x06\x09\x2B\x06\x01\x04\x01\xA9\x4A\x15\x01"
59 const gss_OID_desc *const gss_mech_eap = &gssEapMechPrefix;
61 static const gss_OID_desc gssEapConcreteMechs[] = {
62 /* 1.3.6.1.4.1.5322.21.1.17 */
63 { 12, "\x06\x0A\x2B\x06\x01\x04\x01\xA9\x4A\x15\x01\x11" },
64 /* 1.3.6.1.4.1.5322.21.1.18 */
65 { 12, "\x06\x0A\x2B\x06\x01\x04\x01\xA9\x4A\x15\x01\x12" }
68 const gss_OID_desc *const gss_mech_eap_aes128_cts_hmac_sha1_96 =
69 &gssEapConcreteMechs[0];
70 const gss_OID_desc *const gss_mech_eap_aes256_cts_hmac_sha1_96 =
71 &gssEapConcreteMechs[1];
74 gssEapOidToEnctype(OM_uint32 *minor,
76 krb5_enctype *enctype)
81 major = decomposeOid(minor,
82 gssEapMechPrefix.elements,
83 gssEapMechPrefix.length,
86 if (major == GSS_S_COMPLETE)
93 gssEapEnctypeToOid(OM_uint32 *minor,
102 oid = (gss_OID)GSSEAP_MALLOC(sizeof(*oid));
105 return GSS_S_FAILURE;
108 oid->elements = GSSEAP_MALLOC(gssEapMechPrefix.length + 2);
109 if (oid->elements == NULL) {
112 return GSS_S_FAILURE;
115 major = composeOid(minor,
116 gssEapMechPrefix.elements,
117 gssEapMechPrefix.length,
120 if (major == GSS_S_COMPLETE) {
121 gssEapInternalizeOid(oid, pOid);
132 gssEapIndicateMechs(OM_uint32 *minor,
135 krb5_context context;
136 OM_uint32 major, tmpMinor;
137 krb5_enctype *etypes;
140 *minor = krb5_init_context(&context);
142 return GSS_S_FAILURE;
145 *minor = krb5_get_permitted_enctypes(context, &etypes);
147 krb5_free_context(context);
148 return GSS_S_FAILURE;
151 major = gss_create_empty_oid_set(minor, mechs);
152 if (GSS_ERROR(major)) {
153 krb5_free_context(context);
154 GSSEAP_FREE(etypes); /* XXX */
158 for (i = 0; etypes[i] != ENCTYPE_NULL; i++) {
161 major = gssEapEnctypeToOid(minor, etypes[i], &mechOid);
162 if (GSS_ERROR(major))
165 major = gss_add_oid_set_member(minor, mechOid, mechs);
166 if (GSS_ERROR(major))
169 gss_release_oid(&tmpMinor, &mechOid);
172 GSSEAP_FREE(etypes); /* XXX */
173 krb5_free_context(context);
179 gssEapDefaultMech(OM_uint32 *minor,
183 OM_uint32 major, tmpMinor;
185 major = gssEapIndicateMechs(minor, &mechs);
186 if (GSS_ERROR(major)) {
190 if (mechs->count == 0) {
191 gss_release_oid_set(&tmpMinor, &mechs);
192 return GSS_S_BAD_MECH;
195 gssEapInternalizeOid(&mechs->elements[0], oid);
196 if (*oid == &mechs->elements[0]) {
197 /* don't double-free if we didn't internalize it */
198 mechs->elements[0].length = 0;
199 mechs->elements[0].elements = NULL;
202 gss_release_oid_set(&tmpMinor, &mechs);
205 return GSS_S_COMPLETE;
209 gssEapInternalizeOid(const gss_OID oid,
210 gss_OID *const pInternalizedOid)
214 *pInternalizedOid = GSS_C_NO_OID;
216 if (oidEqual(oid, &gssEapMechPrefix)) {
217 *pInternalizedOid = (const gss_OID)&gssEapMechPrefix;
220 i < sizeof(gssEapConcreteMechs) / sizeof(gssEapConcreteMechs[0]);
222 if (oidEqual(oid, &gssEapConcreteMechs[i])) {
223 *pInternalizedOid = (const gss_OID)&gssEapConcreteMechs[i];
229 if (*pInternalizedOid == GSS_C_NO_OID) {
230 *pInternalizedOid = oid;