Add mech name OID, gss_display_name implementation
authorLuke Howard <lukeh@padl.com>
Wed, 8 Sep 2010 14:27:08 +0000 (16:27 +0200)
committerLuke Howard <lukeh@padl.com>
Wed, 8 Sep 2010 14:27:08 +0000 (16:27 +0200)
Makefile.am
display_name.c
display_status.c [new file with mode: 0644]
gssapi_eap.h
util.h
util_mech.c
util_name.c

index b24dd6b..7910012 100644 (file)
@@ -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                           \
index 0886263..4022efd 100644 (file)
 
 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 (file)
index 0000000..4e259bb
--- /dev/null
@@ -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;
+}
index 20533d6..0e5bb96 100644 (file)
 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 (file)
--- 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_ */
index 6e8676d..f4513e8 100644 (file)
@@ -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;
     }
 }
index 0d9b198..0f40a17 100644 (file)
 
 #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)
 {