Blame SOURCES/0013-Add-tests-for-MS-KKDCP-client-support.patch

4be148
Tweaked context for src/tests/Makefile.in because t_salt.py hadn't yet been
4be148
added as a test in 1.12, and the rdreq and s2p helpers weren't there yet.
4be148
4be148
From 3e2c7cc557048faac3400ae41b0228bd37a82a4c Mon Sep 17 00:00:00 2001
4be148
From: Nalin Dahyabhai <nalin@dahyabhai.net>
4be148
Date: Fri, 7 Feb 2014 18:56:10 -0500
4be148
Subject: [PATCH 13/13] Add tests for MS-KKDCP client support
4be148
4be148
Exercise the MS-KKDCP client support using the test proxy server, for
4be148
AS, TGS, and kpasswd requests while also checking the certificate
4be148
verification and name checks.
4be148
4be148
ticket: 7929
4be148
---
4be148
 src/tests/Makefile.in |   1 +
4be148
 src/tests/t_proxy.py  | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++
4be148
 2 files changed, 220 insertions(+)
4be148
 create mode 100644 src/tests/t_proxy.py
4be148
4be148
diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in
4be148
index 7347ed6..536f5cb 100644
4be148
--- a/src/tests/Makefile.in
4be148
+++ b/src/tests/Makefile.in
4be148
@@ -134,6 +134,7 @@ check-pytests:: t_init_creds t_localauth
4be148
 	$(RUNPYTEST) $(srcdir)/jsonwalker.py -d $(srcdir)/au_dict.json \
4be148
 			-i au.log
4be148
 	$(RUNPYTEST) $(srcdir)/t_bogus_kdc_req.py $(PYTESTFLAGS)
4be148
+	$(RUNPYTEST) $(srcdir)/t_proxy.py $(PYTESTFLAGS)
4be148
 
4be148
 clean::
4be148
 	$(RM) gcred hist hrealm kdbtest plugorder responder
4be148
diff --git a/src/tests/t_proxy.py b/src/tests/t_proxy.py
4be148
new file mode 100644
4be148
index 0000000..e4e3d48
4be148
--- /dev/null
4be148
+++ b/src/tests/t_proxy.py
4be148
@@ -0,0 +1,219 @@
4be148
+#!/usr/bin/python
4be148
+from k5test import *
4be148
+
4be148
+# Skip this test if we're missing proxy functionality or parts of the proxy.
4be148
+if runenv.proxy_tls_impl == 'no':
4be148
+    success('Warning: not testing proxy support because feature ' +
4be148
+            'was not enabled')
4be148
+    exit(0)
4be148
+try:
4be148
+    from paste import httpserver
4be148
+except:
4be148
+    success('Warning: not testing proxy support because python ' +
4be148
+            'paste.httpserver module not found')
4be148
+    exit(0)
4be148
+try:
4be148
+    import kdcproxy
4be148
+except:
4be148
+    success('Warning: not testing proxy support because python ' +
4be148
+            'kdcproxy module not found')
4be148
+    exit(0)
4be148
+
4be148
+# Construct a krb5.conf fragment configuring the client to use a local proxy
4be148
+# server.
4be148
+proxysubjectpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
4be148
+                               'proxy-subject.pem')
4be148
+proxysanpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
4be148
+                           'proxy-san.pem')
4be148
+proxyidealpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
4be148
+                             'proxy-ideal.pem')
4be148
+proxywrongpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
4be148
+                             'proxy-no-match.pem')
4be148
+proxybadpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
4be148
+                           'proxy-badsig.pem')
4be148
+proxyca = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs', 'ca.pem')
4be148
+proxyurl = 'https://localhost:$port5/KdcProxy'
4be148
+proxyurlupcase = 'https://LocalHost:$port5/KdcProxy'
4be148
+proxyurl4 = 'https://127.0.0.1:$port5/KdcProxy'
4be148
+proxyurl6 = 'https://[::1]:$port5/KdcProxy'
4be148
+
4be148
+unanchored_krb5_conf = {'realms': {'$realm': {
4be148
+                        'kdc': proxyurl,
4be148
+                        'kpasswd_server': proxyurl}}}
4be148
+anchored_name_krb5_conf = {'realms': {'$realm': {
4be148
+                           'kdc': proxyurl,
4be148
+                           'kpasswd_server': proxyurl,
4be148
+                           'http_anchors': 'FILE:%s' % proxyca}}}
4be148
+anchored_upcasename_krb5_conf = {'realms': {'$realm': {
4be148
+                                 'kdc': proxyurlupcase,
4be148
+                                 'kpasswd_server': proxyurlupcase,
4be148
+                                 'http_anchors': 'FILE:%s' % proxyca}}}
4be148
+anchored_kadmin_krb5_conf = {'realms': {'$realm': {
4be148
+                             'kdc': proxyurl,
4be148
+                             'admin_server': proxyurl,
4be148
+                             'http_anchors': 'FILE:%s' % proxyca}}}
4be148
+anchored_ipv4_krb5_conf = {'realms': {'$realm': {
4be148
+                           'kdc': proxyurl4,
4be148
+                           'kpasswd_server': proxyurl4,
4be148
+                           'http_anchors': 'FILE:%s' % proxyca}}}
4be148
+kpasswd_input = (password('user') + '\n' + password('user') + '\n' +
4be148
+                 password('user') + '\n')
4be148
+
4be148
+def start_proxy(realm, keycertpem):
4be148
+    proxy_conf_path = os.path.join(realm.testdir, 'kdcproxy.conf')
4be148
+    proxy_exec_path = os.path.join(srctop, 'util', 'paste-kdcproxy.py')
4be148
+    conf = open(proxy_conf_path, 'w')
4be148
+    conf.write('[%s]\n' % realm.realm)
4be148
+    conf.write('kerberos = kerberos://localhost:%d\n' % realm.portbase)
4be148
+    conf.write('kpasswd = kpasswd://localhost:%d\n' % (realm.portbase + 2))
4be148
+    conf.close()
4be148
+    realm.env['KDCPROXY_CONFIG'] = proxy_conf_path
4be148
+    cmd = [proxy_exec_path, str(realm.server_port()), keycertpem]
4be148
+    return realm.start_server(cmd, sentinel='proxy server ready')
4be148
+
4be148
+# Fail: untrusted issuer and hostname doesn't match.
4be148
+output("running pass 1: issuer not trusted and hostname doesn't match\n")
4be148
+realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxywrongpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: untrusted issuer, host name matches subject.
4be148
+output("running pass 2: subject matches, issuer not trusted\n")
4be148
+realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxysubjectpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: untrusted issuer, host name matches subjectAltName.
4be148
+output("running pass 3: subjectAltName matches, issuer not trusted\n")
4be148
+realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxysanpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: untrusted issuer, certificate signature is bad.
4be148
+output("running pass 4: subject matches, issuer not trusted\n")
4be148
+realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxybadpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: trusted issuer but hostname doesn't match.
4be148
+output("running pass 5: issuer trusted but hostname doesn't match\n")
4be148
+realm = K5Realm(krb5_conf=anchored_name_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxywrongpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Succeed: trusted issuer and host name matches subject.
4be148
+output("running pass 6: issuer trusted, subject matches\n")
4be148
+realm = K5Realm(krb5_conf=anchored_name_krb5_conf, start_kadmind=True,
4be148
+                get_creds=False)
4be148
+proxy = start_proxy(realm, proxysubjectpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'))
4be148
+realm.run([kvno, realm.host_princ])
4be148
+realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Succeed: trusted issuer and host name matches subjectAltName.
4be148
+output("running pass 7: issuer trusted, subjectAltName matches\n")
4be148
+realm = K5Realm(krb5_conf=anchored_name_krb5_conf, start_kadmind=True,
4be148
+                get_creds=False)
4be148
+proxy = start_proxy(realm, proxysanpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'))
4be148
+realm.run([kvno, realm.host_princ])
4be148
+realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: certificate signature is bad.
4be148
+output("running pass 8: issuer trusted and subjectAltName matches, sig bad\n")
4be148
+realm = K5Realm(krb5_conf=anchored_name_krb5_conf,
4be148
+                get_creds=False,
4be148
+		                create_host=False)
4be148
+proxy = start_proxy(realm, proxybadpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: trusted issuer but IP doesn't match.
4be148
+output("running pass 9: issuer trusted but no name matches IP\n")
4be148
+realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxywrongpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: trusted issuer, but subject does not match.
4be148
+output("running pass 10: issuer trusted, but subject does not match IP\n")
4be148
+realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxysubjectpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Succeed: trusted issuer and host name matches subjectAltName.
4be148
+output("running pass 11: issuer trusted, subjectAltName matches IP\n")
4be148
+realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, start_kadmind=True,
4be148
+                get_creds=False)
4be148
+proxy = start_proxy(realm, proxysanpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'))
4be148
+realm.run([kvno, realm.host_princ])
4be148
+realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Fail: certificate signature is bad.
4be148
+output("running pass 12: issuer trusted, names don't match, signature bad\n")
4be148
+realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,
4be148
+                create_host=False)
4be148
+proxy = start_proxy(realm, proxybadpem)
4be148
+realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Succeed: trusted issuer and host name matches subject, using kadmin
4be148
+# configuration to find kpasswdd.
4be148
+output("running pass 13: issuer trusted, subject matches\n")
4be148
+realm = K5Realm(krb5_conf=anchored_kadmin_krb5_conf, start_kadmind=True,
4be148
+                get_creds=False, create_host=False)
4be148
+proxy = start_proxy(realm, proxysubjectpem)
4be148
+realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Succeed: trusted issuer and host name matches subjectAltName, using
4be148
+# kadmin configuration to find kpasswdd.
4be148
+output("running pass 14: issuer trusted, subjectAltName matches\n")
4be148
+realm = K5Realm(krb5_conf=anchored_kadmin_krb5_conf, start_kadmind=True,
4be148
+                get_creds=False, create_host=False)
4be148
+proxy = start_proxy(realm, proxysanpem)
4be148
+realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+# Succeed: trusted issuer and host name matches subjectAltName (give or take
4be148
+# case).
4be148
+output("running pass 15: issuer trusted, subjectAltName case-insensitive\n")
4be148
+realm = K5Realm(krb5_conf=anchored_upcasename_krb5_conf, start_kadmind=True,
4be148
+                get_creds=False, create_host=False)
4be148
+proxy = start_proxy(realm, proxysanpem)
4be148
+realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
4be148
+stop_daemon(proxy)
4be148
+realm.stop()
4be148
+
4be148
+success('MS-KKDCP proxy')
4be148
-- 
4be148
2.1.0
4be148