|
|
665228 |
From 996c0089cf2e3240e1b331555897e5bf83b023e7 Mon Sep 17 00:00:00 2001
|
|
|
665228 |
From: Greg Hudson <ghudson@mit.edu>
|
|
|
665228 |
Date: Wed, 4 Jan 2017 18:31:15 -0500
|
|
|
665228 |
Subject: [PATCH] Add tests for per-request preauth data scoping
|
|
|
665228 |
|
|
|
665228 |
Add a test harness which interleaves calls for multiple initial creds
|
|
|
665228 |
contexts using the same library context. Add a test case to
|
|
|
665228 |
t_preauth.py using the new harness and the test preauth module to
|
|
|
665228 |
verify that modreq pointers are correctly tracked.
|
|
|
665228 |
|
|
|
665228 |
ticket: 7877
|
|
|
665228 |
(cherry picked from commit c0b25fe282355d4f329418956b9c6295780af633)
|
|
|
665228 |
[rharwood@redhat.com: drop .gitignore]
|
|
|
665228 |
---
|
|
|
665228 |
src/tests/Makefile.in | 23 +++++---
|
|
|
665228 |
src/tests/icinterleave.c | 124 +++++++++++++++++++++++++++++++++++++++
|
|
|
665228 |
src/tests/t_preauth.py | 13 ++++
|
|
|
665228 |
3 files changed, 151 insertions(+), 9 deletions(-)
|
|
|
665228 |
create mode 100644 src/tests/icinterleave.c
|
|
|
665228 |
|
|
|
665228 |
diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in
|
|
|
665228 |
index a2093108b..bd1b21346 100644
|
|
|
665228 |
--- a/src/tests/Makefile.in
|
|
|
665228 |
+++ b/src/tests/Makefile.in
|
|
|
665228 |
@@ -6,12 +6,12 @@ SUBDIRS = resolve asn.1 create hammer verify gssapi dejagnu shlib \
|
|
|
665228 |
RUN_DB_TEST = $(RUN_SETUP) KRB5_KDC_PROFILE=kdc.conf KRB5_CONFIG=krb5.conf \
|
|
|
665228 |
LC_ALL=C $(VALGRIND)
|
|
|
665228 |
|
|
|
665228 |
-OBJS= adata.o etinfo.o forward.o gcred.o hist.o hooks.o hrealm.o icred.o \
|
|
|
665228 |
- kdbtest.o localauth.o plugorder.o rdreq.o responder.o s2p.o \
|
|
|
665228 |
- s4u2proxy.o unlockiter.o
|
|
|
665228 |
+OBJS= adata.o etinfo.o forward.o gcred.o hist.o hooks.o hrealm.o \
|
|
|
665228 |
+ icinterleave.o icred.o kdbtest.o localauth.o plugorder.o rdreq.o \
|
|
|
665228 |
+ responder.o s2p.o s4u2proxy.o unlockiter.o
|
|
|
665228 |
EXTRADEPSRCS= adata.c etinfo.c forward.c gcred.c hist.c hooks.c hrealm.c \
|
|
|
665228 |
- icred.c kdbtest.c localauth.c plugorder.c rdreq.o responder.c s2p.c \
|
|
|
665228 |
- s4u2proxy.c unlockiter.c
|
|
|
665228 |
+ icinterleave.c icred.c kdbtest.c localauth.c plugorder.c rdreq.o \
|
|
|
665228 |
+ responder.c s2p.c s4u2proxy.c unlockiter.c
|
|
|
665228 |
|
|
|
665228 |
TEST_DB = ./testdb
|
|
|
665228 |
TEST_REALM = FOO.TEST.REALM
|
|
|
665228 |
@@ -44,6 +44,9 @@ hooks: hooks.o $(KRB5_BASE_DEPLIBS)
|
|
|
665228 |
hrealm: hrealm.o $(KRB5_BASE_DEPLIBS)
|
|
|
665228 |
$(CC_LINK) -o $@ hrealm.o $(KRB5_BASE_LIBS)
|
|
|
665228 |
|
|
|
665228 |
+icinterleave: icinterleave.o $(KRB5_BASE_DEPLIBS)
|
|
|
665228 |
+ $(CC_LINK) -o $@ icinterleave.o $(KRB5_BASE_LIBS)
|
|
|
665228 |
+
|
|
|
665228 |
icred: icred.o $(KRB5_BASE_DEPLIBS)
|
|
|
665228 |
$(CC_LINK) -o $@ icred.o $(KRB5_BASE_LIBS)
|
|
|
665228 |
|
|
|
665228 |
@@ -115,8 +118,9 @@ kdb_check: kdc.conf krb5.conf
|
|
|
665228 |
$(RUN_DB_TEST) ../kadmin/dbutil/kdb5_util $(KADMIN_OPTS) destroy -f
|
|
|
665228 |
$(RM) $(TEST_DB)* stash_file
|
|
|
665228 |
|
|
|
665228 |
-check-pytests: adata etinfo forward gcred hist hooks hrealm icred kdbtest
|
|
|
665228 |
-check-pytests: localauth plugorder rdreq responder s2p s4u2proxy unlockiter
|
|
|
665228 |
+check-pytests: adata etinfo forward gcred hist hooks hrealm icinterleave icred
|
|
|
665228 |
+check-pytests: kdbtest localauth plugorder rdreq responder s2p s4u2proxy
|
|
|
665228 |
+check-pytests: unlockiter
|
|
|
665228 |
$(RUNPYTEST) $(srcdir)/t_general.py $(PYTESTFLAGS)
|
|
|
665228 |
$(RUNPYTEST) $(srcdir)/t_hooks.py $(PYTESTFLAGS)
|
|
|
665228 |
$(RUNPYTEST) $(srcdir)/t_dump.py $(PYTESTFLAGS)
|
|
|
665228 |
@@ -172,8 +176,9 @@ check-pytests: localauth plugorder rdreq responder s2p s4u2proxy unlockiter
|
|
|
665228 |
$(RUNPYTEST) $(srcdir)/t_kdcpolicy.py $(PYTESTFLAGS)
|
|
|
665228 |
|
|
|
665228 |
clean:
|
|
|
665228 |
- $(RM) adata etinfo forward gcred hist hooks hrealm icred kdbtest
|
|
|
665228 |
- $(RM) localauth plugorder rdreq responder s2p s4u2proxy unlockiter
|
|
|
665228 |
+ $(RM) adata etinfo forward gcred hist hooks hrealm icinterleave icred
|
|
|
665228 |
+ $(RM) kdbtest localauth plugorder rdreq responder s2p s4u2proxy
|
|
|
665228 |
+ $(RM) unlockiter
|
|
|
665228 |
$(RM) krb5.conf kdc.conf
|
|
|
665228 |
$(RM) -rf kdc_realm/sandbox ldap
|
|
|
665228 |
$(RM) au.log
|
|
|
665228 |
diff --git a/src/tests/icinterleave.c b/src/tests/icinterleave.c
|
|
|
665228 |
new file mode 100644
|
|
|
665228 |
index 000000000..d76ecf361
|
|
|
665228 |
--- /dev/null
|
|
|
665228 |
+++ b/src/tests/icinterleave.c
|
|
|
665228 |
@@ -0,0 +1,124 @@
|
|
|
665228 |
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
665228 |
+/* tests/icinterleave.c - interleaved init_creds_step test harness */
|
|
|
665228 |
+/*
|
|
|
665228 |
+ * Copyright (C) 2017 by the Massachusetts Institute of Technology.
|
|
|
665228 |
+ * All rights reserved.
|
|
|
665228 |
+ *
|
|
|
665228 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
665228 |
+ * modification, are permitted provided that the following conditions
|
|
|
665228 |
+ * are met:
|
|
|
665228 |
+ *
|
|
|
665228 |
+ * * Redistributions of source code must retain the above copyright
|
|
|
665228 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
665228 |
+ *
|
|
|
665228 |
+ * * Redistributions in binary form must reproduce the above copyright
|
|
|
665228 |
+ * notice, this list of conditions and the following disclaimer in
|
|
|
665228 |
+ * the documentation and/or other materials provided with the
|
|
|
665228 |
+ * distribution.
|
|
|
665228 |
+ *
|
|
|
665228 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
665228 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
665228 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
665228 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
665228 |
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
665228 |
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
665228 |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
665228 |
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
665228 |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
665228 |
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
665228 |
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
665228 |
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
665228 |
+ */
|
|
|
665228 |
+
|
|
|
665228 |
+/*
|
|
|
665228 |
+ * This test harness performs multiple initial creds operations using
|
|
|
665228 |
+ * krb5_init_creds_step(), interleaving the operations to test the scoping of
|
|
|
665228 |
+ * the preauth state. All principals must have the same password (or not
|
|
|
665228 |
+ * require a password).
|
|
|
665228 |
+ */
|
|
|
665228 |
+
|
|
|
665228 |
+#include "k5-int.h"
|
|
|
665228 |
+
|
|
|
665228 |
+static krb5_context ctx;
|
|
|
665228 |
+
|
|
|
665228 |
+static void
|
|
|
665228 |
+check(krb5_error_code code)
|
|
|
665228 |
+{
|
|
|
665228 |
+ const char *errmsg;
|
|
|
665228 |
+
|
|
|
665228 |
+ if (code) {
|
|
|
665228 |
+ errmsg = krb5_get_error_message(ctx, code);
|
|
|
665228 |
+ fprintf(stderr, "%s\n", errmsg);
|
|
|
665228 |
+ krb5_free_error_message(ctx, errmsg);
|
|
|
665228 |
+ exit(1);
|
|
|
665228 |
+ }
|
|
|
665228 |
+}
|
|
|
665228 |
+
|
|
|
665228 |
+int
|
|
|
665228 |
+main(int argc, char **argv)
|
|
|
665228 |
+{
|
|
|
665228 |
+ const char *password;
|
|
|
665228 |
+ char **princstrs;
|
|
|
665228 |
+ krb5_principal client;
|
|
|
665228 |
+ krb5_init_creds_context *iccs;
|
|
|
665228 |
+ krb5_data req, *reps, realm;
|
|
|
665228 |
+ krb5_boolean any_left;
|
|
|
665228 |
+ int i, nclients, master;
|
|
|
665228 |
+ unsigned int flags;
|
|
|
665228 |
+
|
|
|
665228 |
+ if (argc < 3) {
|
|
|
665228 |
+ fprintf(stderr, "Usage: icinterleave password princ1 princ2 ...\n");
|
|
|
665228 |
+ exit(1);
|
|
|
665228 |
+ }
|
|
|
665228 |
+ password = argv[1];
|
|
|
665228 |
+ princstrs = argv + 2;
|
|
|
665228 |
+ nclients = argc - 2;
|
|
|
665228 |
+
|
|
|
665228 |
+ check(krb5_init_context(&ctx));
|
|
|
665228 |
+
|
|
|
665228 |
+ /* Create an initial creds context for each client principal. */
|
|
|
665228 |
+ iccs = calloc(nclients, sizeof(*iccs));
|
|
|
665228 |
+ assert(iccs != NULL);
|
|
|
665228 |
+ for (i = 0; i < nclients; i++) {
|
|
|
665228 |
+ check(krb5_parse_name(ctx, princstrs[i], &client));
|
|
|
665228 |
+ check(krb5_init_creds_init(ctx, client, NULL, NULL, 0, NULL,
|
|
|
665228 |
+ &iccs[i]));
|
|
|
665228 |
+ check(krb5_init_creds_set_password(ctx, iccs[i], password));
|
|
|
665228 |
+ krb5_free_principal(ctx, client);
|
|
|
665228 |
+ }
|
|
|
665228 |
+
|
|
|
665228 |
+ reps = calloc(nclients, sizeof(*reps));
|
|
|
665228 |
+ assert(reps != NULL);
|
|
|
665228 |
+
|
|
|
665228 |
+ any_left = TRUE;
|
|
|
665228 |
+ while (any_left) {
|
|
|
665228 |
+ any_left = FALSE;
|
|
|
665228 |
+ for (i = 0; i < nclients; i++) {
|
|
|
665228 |
+ if (iccs[i] == NULL)
|
|
|
665228 |
+ continue;
|
|
|
665228 |
+ any_left = TRUE;
|
|
|
665228 |
+
|
|
|
665228 |
+ printf("step %d\n", i + 1);
|
|
|
665228 |
+
|
|
|
665228 |
+ req = empty_data();
|
|
|
665228 |
+ realm = empty_data();
|
|
|
665228 |
+ check(krb5_init_creds_step(ctx, iccs[i], &reps[i], &req, &realm,
|
|
|
665228 |
+ &flags));
|
|
|
665228 |
+ if (!(flags & KRB5_INIT_CREDS_STEP_FLAG_CONTINUE)) {
|
|
|
665228 |
+ printf("finish %d\n", i + 1);
|
|
|
665228 |
+ krb5_init_creds_free(ctx, iccs[i]);
|
|
|
665228 |
+ iccs[i] = NULL;
|
|
|
665228 |
+ continue;
|
|
|
665228 |
+ }
|
|
|
665228 |
+
|
|
|
665228 |
+ master = 0;
|
|
|
665228 |
+ krb5_free_data_contents(ctx, &reps[i]);
|
|
|
665228 |
+ check(krb5_sendto_kdc(ctx, &req, &realm, &reps[i], &master, 0));
|
|
|
665228 |
+ krb5_free_data_contents(ctx, &req;;
|
|
|
665228 |
+ krb5_free_data_contents(ctx, &realm;;
|
|
|
665228 |
+ }
|
|
|
665228 |
+ }
|
|
|
665228 |
+
|
|
|
665228 |
+ krb5_free_context(ctx);
|
|
|
665228 |
+ return 0;
|
|
|
665228 |
+}
|
|
|
665228 |
diff --git a/src/tests/t_preauth.py b/src/tests/t_preauth.py
|
|
|
665228 |
index 0ef8bbca4..9b6da5a96 100644
|
|
|
665228 |
--- a/src/tests/t_preauth.py
|
|
|
665228 |
+++ b/src/tests/t_preauth.py
|
|
|
665228 |
@@ -24,4 +24,17 @@ out = realm.run([kinit, realm.user_princ], input=password('user')+'\n')
|
|
|
665228 |
if '2rt: secondtrip' not in out:
|
|
|
665228 |
fail('multi round-trip cookie test')
|
|
|
665228 |
|
|
|
665228 |
+# Test that multiple stepwise initial creds operations can be
|
|
|
665228 |
+# performed with the same krb5_context, with proper tracking of
|
|
|
665228 |
+# clpreauth module request handles.
|
|
|
665228 |
+realm.run([kadminl, 'addprinc', '-pw', 'pw', 'u1'])
|
|
|
665228 |
+realm.run([kadminl, 'addprinc', '+requires_preauth', '-pw', 'pw', 'u2'])
|
|
|
665228 |
+realm.run([kadminl, 'addprinc', '+requires_preauth', '-pw', 'pw', 'u3'])
|
|
|
665228 |
+realm.run([kadminl, 'setstr', 'u2', '2rt', 'extra'])
|
|
|
665228 |
+out = realm.run(['./icinterleave', 'pw', 'u1', 'u2', 'u3'])
|
|
|
665228 |
+if out != ('step 1\nstep 2\nstep 3\nstep 1\nfinish 1\nstep 2\nno attr\n'
|
|
|
665228 |
+ 'step 3\nno attr\nstep 2\n2rt: extra\nstep 3\nfinish 3\nstep 2\n'
|
|
|
665228 |
+ 'finish 2\n'):
|
|
|
665228 |
+ fail('unexpected output from icinterleave')
|
|
|
665228 |
+
|
|
|
665228 |
success('Pre-authentication framework tests')
|