From f80789910cbf6a8b68496783a9203bff3f6a63bd Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Wed, 8 Sep 2010 16:27:08 +0200 Subject: [PATCH] Add mech name OID, gss_display_name implementation --- Makefile.am | 1 + display_name.c | 33 ++++++++++++++++++++++++-- display_status.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gssapi_eap.h | 10 ++++---- util.h | 19 +++++++++++++++ util_mech.c | 13 ++++++---- util_name.c | 8 +++++++ 7 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 display_status.c diff --git a/Makefile.am b/Makefile.am index b24dd6b..7910012 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ libmech_eap_la_SOURCES = \ delete_sec_context.c \ display_name.c \ display_name_ext.c \ + display_status.c \ duplicate_name.c \ eap_mech.c \ export_name.c \ diff --git a/display_name.c b/display_name.c index 0886263..4022efd 100644 --- a/display_name.c +++ b/display_name.c @@ -34,9 +34,38 @@ OM_uint32 gss_display_name(OM_uint32 *minor, - gss_name_t input_name, + gss_name_t name, gss_buffer_t output_name_buffer, gss_OID *output_name_type) { - GSSEAP_NOT_IMPLEMENTED; + OM_uint32 major, tmpMinor; + krb5_context krbContext; + char *krbName; + + GSSEAP_KRB_INIT(&krbContext); + + output_name_buffer->length = 0; + output_name_buffer->value = NULL; + + if (name == GSS_C_NO_NAME) { + *minor = EINVAL; + return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME; + } + + *minor = krb5_unparse_name(krbContext, name->krbPrincipal, &krbName); + if (*minor != 0) { + return GSS_S_FAILURE; + } + + major = makeStringBuffer(minor, krbName, output_name_buffer); + if (GSS_ERROR(major)) { + krb5_free_unparsed_name(krbContext, krbName); + return major; + } + + krb5_free_unparsed_name(krbContext, krbName); + + *output_name_type = (gss_OID)GSS_EAP_NT_PRINCIPAL_NAME; + + return GSS_S_COMPLETE; } diff --git a/display_status.c b/display_status.c new file mode 100644 index 0000000..4e259bb --- /dev/null +++ b/display_status.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010, JANET(UK) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JANET(UK) nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "gssapiP_eap.h" + +OM_uint32 +gss_display_status(OM_uint32 *minor, + OM_uint32 status_value, + int status_type, + gss_OID mech_type, + OM_uint32 *message_context, + gss_buffer_t status_string) +{ + OM_uint32 major, tmpMinor; + krb5_context krbContext; + const char *errMsg; + + status_string->length = 0; + status_string->value = NULL; + + if (mech_type != GSS_C_NO_OID && + !gssEapIsMechanismOid(mech_type)) { + return GSS_S_BAD_MECH; + } + + if (status_type != GSS_C_MECH_CODE) { + /* we rely on the mechglue for GSS_C_GSS_CODE */ + return GSS_S_BAD_STATUS; + } + + /* XXX we need to support RADIUS codes too? */ + GSSEAP_KRB_INIT(&krbContext); + + errMsg = krb5_get_error_message(krbContext, status_value); + if (errMsg != NULL) { + major = makeStringBuffer(minor, errMsg, status_string); + krb5_free_error_message(krbContext, errMsg); + } else { + major = GSS_S_COMPLETE; + } + + return GSS_S_COMPLETE; +} diff --git a/gssapi_eap.h b/gssapi_eap.h index 20533d6..0e5bb96 100644 --- a/gssapi_eap.h +++ b/gssapi_eap.h @@ -39,12 +39,12 @@ extern "C" { #endif /* __cplusplus */ -/* preferred mechanism */ -extern const gss_OID_desc *const gss_mech_eap; +extern const gss_OID_desc *const GSS_EAP_MECHANISM; +extern const gss_OID_desc *const GSS_EAP_AES128_CTS_HMAC_SHA1_96_MECHANISM; +extern const gss_OID_desc *const GSS_EAP_AES256_CTS_HMAC_SHA1_96_MECHANISM; -/* concrete mechanisms */ -extern const gss_OID_desc *const gss_mech_eap_aes128_cts_hmac_sha1_96; -extern const gss_OID_desc *const gss_mech_eap_aes256_cts_hmac_sha1_96; +/* name type */ +extern const gss_OID_desc *const GSS_EAP_NT_PRINCIPAL_NAME; #ifdef __cplusplus } diff --git a/util.h b/util.h index 5a276f4..7299a8b 100644 --- a/util.h +++ b/util.h @@ -332,4 +332,23 @@ load_uint64_be(const void *cvp) return ((uint64_t)load_uint32_be(p) << 32) | load_uint32_be(p + 4); } +static OM_uint32 +makeStringBuffer(OM_uint32 *minor, + const char *string, + gss_buffer_t buffer) +{ + size_t len = strlen(string); + + buffer->value = GSSEAP_MALLOC(len + 1); + if (buffer->value == NULL) { + *minor = ENOMEM; + return GSS_S_FAILURE; + } + memcpy(buffer->value, string, len + 1); + buffer->length = len; + + *minor = 0; + return GSS_S_COMPLETE; +} + #endif /* _UTIL_H_ */ diff --git a/util_mech.c b/util_mech.c index 6e8676d..f4513e8 100644 --- a/util_mech.c +++ b/util_mech.c @@ -61,17 +61,17 @@ static const gss_OID_desc gssEapConcreteMechs[] = { { 12, "\x06\x0A\x2B\x06\x01\x04\x01\xA9\x4A\x15\x01\x12" } }; -const gss_OID_desc *const gss_mech_eap = +const gss_OID_desc *const GSS_EAP_MECHANISM = &gssEapConcreteMechs[0]; -const gss_OID_desc *const gss_mech_eap_aes128_cts_hmac_sha1_96 = +const gss_OID_desc *const GSS_EAP_AES128_CTS_HMAC_SHA1_96_MECHANISM = &gssEapConcreteMechs[1]; -const gss_OID_desc *const gss_mech_eap_aes256_cts_hmac_sha1_96 = +const gss_OID_desc *const GSS_EAP_AES256_CTS_HMAC_SHA1_96_MECHANISM = &gssEapConcreteMechs[2]; int gssEapIsMechanismOid(const gss_OID oid) { - if (oidEqual(oid, gss_mech_eap)) { + if (oidEqual(oid, GSS_EAP_MECHANISM)) { return TRUE; } else if (oid->length > gssEapMechPrefix.length && memcmp(oid->elements, gssEapMechPrefix.elements, @@ -239,6 +239,11 @@ gssEapInternalizeOid(const gss_OID oid, } if (*pInternalizedOid == GSS_C_NO_OID) { + if (oidEqual(oid, GSS_EAP_NT_PRINCIPAL_NAME)) + *pInternalizedOid = (const gss_OID)GSS_EAP_NT_PRINCIPAL_NAME; + } + + if (*pInternalizedOid == GSS_C_NO_OID) { *pInternalizedOid = oid; } } diff --git a/util_name.c b/util_name.c index 0d9b198..0f40a17 100644 --- a/util_name.c +++ b/util_name.c @@ -32,6 +32,14 @@ #include "gssapiP_eap.h" +static const gss_OID_desc gssEapNtPrincipalName = { + /* 1.3.6.1.4.1.5322.21.2.1 */ + 12, "\x06\x0A\x2B\x06\x01\x04\x01\xA9\x4A\x15\x02\x01" +}; + +const gss_OID_desc *const GSS_EAP_NT_PRINCIPAL_NAME = + &gssEapNtPrincipalName; + OM_uint32 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName) { -- 2.1.4