diff options
| author | Greg Hudson <ghudson@mit.edu> | 2011-02-07 18:40:00 +0000 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2011-02-07 18:40:00 +0000 |
| commit | 66587fcd6380eac2c53674df4f64a827d337aee5 (patch) | |
| tree | e3e98004479a87b3f1e1171056464f3a6be65d95 /src/tests/gssapi | |
| parent | 1b46b254240d95534b7a3ee1f45ac85f6c38db1b (diff) | |
| download | krb5-66587fcd6380eac2c53674df4f64a827d337aee5.tar.gz krb5-66587fcd6380eac2c53674df4f64a827d337aee5.tar.xz krb5-66587fcd6380eac2c53674df4f64a827d337aee5.zip | |
Improve acceptor name flexibility
Be more flexible about the principal names we will accept for a given
GSS acceptor name. Also add support for a new libdefaults profile
variable ignore_acceptor_hostname, which causes the hostnames of
host-based service principals to be ignored when passed by server
applications as acceptor names.
Note that we still always invoke krb5_sname_to_principal() when
importing a gss-krb5 mechanism name, even though we won't always use
the result. This is an unfortunate waste of getaddrinfo/getnameinfo
queries in some situations, but the code surgery necessary to defer
it appears too risky at this time.
The project proposal for this change is at:
http://k5wiki.kerberos.org/wiki/Projects/Acceptor_Names
ticket: 6855
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24616 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/tests/gssapi')
| -rw-r--r-- | src/tests/gssapi/Makefile.in | 12 | ||||
| -rw-r--r-- | src/tests/gssapi/t_accname.c | 172 | ||||
| -rw-r--r-- | src/tests/gssapi/t_gssapi.py | 81 |
3 files changed, 260 insertions, 5 deletions
diff --git a/src/tests/gssapi/Makefile.in b/src/tests/gssapi/Makefile.in index a0e2e47d4e..36b541732b 100644 --- a/src/tests/gssapi/Makefile.in +++ b/src/tests/gssapi/Makefile.in @@ -4,15 +4,19 @@ DEFINES = -DUSE_AUTOCONF_H PROG_LIBPATH=-L$(TOPLIBD) PROG_RPATH=$(KRB5_LIBDIR) -SRCS= $(srcdir)/t_imp_name.c $(srcdir)/t_s4u.c $(srcdir)/t_namingexts.c $(srcdir)/t_gssexts.c $(srcdir)/t_saslname.c +SRCS= $(srcdir)/t_accname.c $(srcdir)/t_imp_name.c $(srcdir)/t_s4u.c \ + $(srcdir)/t_namingexts.c $(srcdir)/t_gssexts.c $(srcdir)/t_saslname.c -OBJS= t_imp_name.o t_s4u.o t_namingexts.o t_gssexts.o t_spnego.o t_saslname.o +OBJS= t_accname.o t_imp_name.o t_s4u.o t_namingexts.o t_gssexts.o \ + t_spnego.o t_saslname.o -all:: t_imp_name t_s4u t_namingexts t_gssexts t_spnego t_saslname +all:: t_accname t_imp_name t_s4u t_namingexts t_gssexts t_spnego t_saslname -check-pytests:: t_spnego +check-pytests:: t_accname t_spnego $(RUNPYTEST) $(srcdir)/t_gssapi.py $(PYTESTFLAGS) +t_accname: t_accname.o $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS) + $(CC_LINK) -o t_accname t_accname.o $(GSS_LIBS) $(KRB5_BASE_LIBS) t_imp_name: t_imp_name.o $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o t_imp_name t_imp_name.o $(GSS_LIBS) $(KRB5_BASE_LIBS) t_s4u: t_s4u.o $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS) diff --git a/src/tests/gssapi/t_accname.c b/src/tests/gssapi/t_accname.c new file mode 100644 index 0000000000..ab6bc83bd5 --- /dev/null +++ b/src/tests/gssapi/t_accname.c @@ -0,0 +1,172 @@ +/* -*- mode: c; indent-tabs-mode: nil -*- */ +/* + * Copyright 2011 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <gssapi/gssapi_krb5.h> + +/* + * Test program for acceptor names, intended to be run from a Python test + * script. Performs a one-token gss_init_sec_context/gss_accept_sec_context + * exchange with the default initiator name, a specified principal name as + * target name, and a specified host-based name as acceptor name (or + * GSS_C_NO_NAME if no acceptor name is given). If the exchange is successful, + * queries the context for the acceptor name and prints it. If any call is + * unsuccessful, displays an error message. Exits with status 0 if all + * operations are successful, or 1 if not. + * + * Usage: ./t_accname targetname [acceptorname] + */ + +static void +display_status_1(const char *m, OM_uint32 code, int type) +{ + OM_uint32 maj_stat, min_stat; + gss_buffer_desc msg; + OM_uint32 msg_ctx; + + msg_ctx = 0; + while (1) { + maj_stat = gss_display_status(&min_stat, code, + type, GSS_C_NULL_OID, + &msg_ctx, &msg); + fprintf(stderr, "%s: %s\n", m, (char *)msg.value); + (void) gss_release_buffer(&min_stat, &msg); + + if (!msg_ctx) + break; + } +} + +static void +display_status(const char *msg, OM_uint32 maj_stat, OM_uint32 min_stat) +{ + display_status_1(msg, maj_stat, GSS_C_GSS_CODE); + display_status_1(msg, min_stat, GSS_C_MECH_CODE); +} + +int +main(int argc, char *argv[]) +{ + OM_uint32 minor, major; + gss_cred_id_t acceptor_cred; + gss_buffer_desc buf; + gss_name_t target_name, acceptor_name = GSS_C_NO_NAME, real_acceptor_name; + gss_buffer_desc token, tmp, namebuf; + gss_ctx_id_t initiator_context = GSS_C_NO_CONTEXT; + gss_ctx_id_t acceptor_context = GSS_C_NO_CONTEXT; + + if (argc < 2 || argc > 3) { + fprintf(stderr, "Usage: %s targetname [acceptorname]\n", argv[0]); + return 1; + } + + /* Import the target name as a krb5 principal name. */ + buf.value = argv[1]; + buf.length = strlen((char *)buf.value); + major = gss_import_name(&minor, &buf, (gss_OID)GSS_KRB5_NT_PRINCIPAL_NAME, + &target_name); + if (GSS_ERROR(major)) { + display_status("gss_import_name(target_name)", major, minor); + return 1; + } + + /* Import the acceptor name as a host-based name. */ + if (argc >= 3) { + buf.value = argv[2]; + buf.length = strlen((char *)buf.value); + major = gss_import_name(&minor, &buf, + (gss_OID)GSS_C_NT_HOSTBASED_SERVICE, + &acceptor_name); + if (GSS_ERROR(major)) { + display_status("gss_import_name(acceptor_name)", major, minor); + return 1; + } + } + + /* Get acceptor cred. */ + major = gss_acquire_cred(&minor, acceptor_name, GSS_C_INDEFINITE, + GSS_C_NO_OID_SET, GSS_C_ACCEPT, + &acceptor_cred, NULL, NULL); + if (GSS_ERROR(major)) { + display_status("gss_acquire_cred", major, minor); + return 1; + } + + /* Create krb5 initiator context and get the first token. */ + token.value = NULL; + token.length = 0; + major = gss_init_sec_context(&minor, GSS_C_NO_CREDENTIAL, + &initiator_context, target_name, + (gss_OID)gss_mech_krb5, + GSS_C_REPLAY_FLAG | GSS_C_SEQUENCE_FLAG, + GSS_C_INDEFINITE, GSS_C_NO_CHANNEL_BINDINGS, + GSS_C_NO_BUFFER, NULL, &token, NULL, NULL); + if (GSS_ERROR(major)) { + display_status("gss_init_sec_context", major, minor); + return 1; + } + + /* Pass the token to gss_accept_sec_context. */ + tmp.value = NULL; + tmp.length = 0; + major = gss_accept_sec_context(&minor, &acceptor_context, acceptor_cred, + &token, GSS_C_NO_CHANNEL_BINDINGS, + NULL, NULL, &tmp, NULL, NULL, NULL); + if (major != GSS_S_COMPLETE) { + display_status("gss_accept_sec_context", major, minor); + return 1; + } + + major = gss_inquire_context(&minor, acceptor_context, NULL, + &real_acceptor_name, NULL, NULL, NULL, NULL, + NULL); + if (GSS_ERROR(major)) { + display_status("gss_inquire_context", major, minor); + return 1; + } + + namebuf.value = NULL; + namebuf.length = 0; + major = gss_display_name(&minor, real_acceptor_name, &namebuf, NULL); + if (GSS_ERROR(major)) { + display_status("gss_display_name", major, minor); + return 1; + } + + printf("%.*s\n", (int)namebuf.length, (char *)namebuf.value); + + (void)gss_release_name(&minor, &target_name); + (void)gss_release_name(&minor, &acceptor_name); + (void)gss_release_cred(&minor, &acceptor_cred); + (void)gss_delete_sec_context(&minor, &initiator_context, NULL); + (void)gss_delete_sec_context(&minor, &acceptor_context, NULL); + (void)gss_release_buffer(&minor, &token); + (void)gss_release_buffer(&minor, &tmp); + return 0; +} diff --git a/src/tests/gssapi/t_gssapi.py b/src/tests/gssapi/t_gssapi.py index d88f7949b8..f4dd9e3cb8 100644 --- a/src/tests/gssapi/t_gssapi.py +++ b/src/tests/gssapi/t_gssapi.py @@ -1,7 +1,86 @@ #!/usr/bin/python from k5test import * +# Test krb5 negotiation under SPNEGO for all enctype configurations. for realm in multipass_realms(): realm.run_as_client(['./t_spnego', realm.host_princ, realm.keytab]) -success('GSSAPI test programs (SPNEGO only).') +### Test acceptor name behavior. + +realm = K5Realm(start_kadmind=False) + +# Create some host-based principals and put most of them into the +# keytab. Rename one principal so that the keytab name matches the +# key but not the client name. +realm.run_kadminl('addprinc -randkey service1/abraham') +realm.run_kadminl('addprinc -randkey service1/barack') +realm.run_kadminl('addprinc -randkey service2/calvin') +realm.run_kadminl('addprinc -randkey service2/dwight') +realm.run_kadminl('addprinc -randkey host/-nomatch-') +realm.run_kadminl('xst service1/abraham') +realm.run_kadminl('xst service1/barack') +realm.run_kadminl('xst service2/calvin') +realm.run_kadminl('renprinc -force service1/abraham service1/andrew') + +# Test with no acceptor name, including client/keytab principal +# mismatch (non-fatal) and missing keytab entry (fatal). +output = realm.run_as_client(['./t_accname', 'service1/andrew']) +if 'service1/abraham' not in output: + fail('Expected service1/abraham in t_accname output') +output = realm.run_as_client(['./t_accname', 'service1/barack']) +if 'service1/barack' not in output: + fail('Expected service1/barack in t_accname output') +output = realm.run_as_client(['./t_accname', 'service2/calvin']) +if 'service2/calvin' not in output: + fail('Expected service1/barack in t_accname output') +output = realm.run_as_client(['./t_accname', 'service2/dwight'], + expected_code=1) +if 'Wrong principal in request' not in output: + fail('Expected error message not seen in t_accname output') + +# Test with acceptor name containing service only, including +# client/keytab hostname mismatch (non-fatal) and service name +# mismatch (fatal). +output = realm.run_as_client(['./t_accname', 'service1/andrew', 'service1']) +if 'service1/abraham' not in output: + fail('Expected service1/abraham in t_accname output') +output = realm.run_as_client(['./t_accname', 'service1/andrew', 'service2'], + expected_code=1) +if 'Wrong principal in request' not in output: + fail('Expected error message not seen in t_accname output') +output = realm.run_as_client(['./t_accname', 'service2/calvin', 'service2']) +if 'service2/calvin' not in output: + fail('Expected service2/calvin in t_accname output') +output = realm.run_as_client(['./t_accname', 'service2/calvin', 'service1'], + expected_code=1) +if 'Wrong principal in request' not in output: + fail('Expected error message not seen in t_accname output') + +# Test with acceptor name containing service and host. Use the +# client's un-canonicalized hostname as acceptor input to mirror what +# many servers do. +output = realm.run_as_client(['./t_accname', realm.host_princ, + 'host@%s' % socket.gethostname()]) +if realm.host_princ not in output: + fail('Expected %s in t_accname output' % realm.host_princ) +output = realm.run_as_client(['./t_accname', 'host/-nomatch-', + 'host@%s' % socket.gethostname()], + expected_code=1) +if 'Wrong principal in request' not in output: + fail('Expected error message not seen in t_accname output') + +realm.stop() + +# Re-run that last test with ignore_acceptor_hostname set and the +# principal for the mismatching hostname in the keytab. +ignore_conf = { 'all' : { 'libdefaults' : { + 'ignore_acceptor_hostname' : 'true' } } } +realm = K5Realm(krb5_conf=ignore_conf, start_kadmind=False) +realm.run_kadminl('addprinc -randkey host/-nomatch-') +realm.run_kadminl('xst host/-nomatch-') +output = realm.run_as_client(['./t_accname', 'host/-nomatch-', + 'host@%s' % socket.gethostname()]) +if 'host/-nomatch-' not in output: + fail('Expected error message not seen in t_accname output') + +success('GSSAPI tests.') |
