Blame SOURCES/Add-PKINIT-UPN-tests-to-t_pkinit.py.patch

d738b9
From aaa3ceb3c9fa8ff206edcd6d66659c5e69e4811d Mon Sep 17 00:00:00 2001
d738b9
From: Matt Rogers <mrogers@redhat.com>
d738b9
Date: Fri, 9 Dec 2016 11:43:27 -0500
d738b9
Subject: [PATCH] Add PKINIT UPN tests to t_pkinit.py
d738b9
d738b9
[ghudson@mit.edu: simplify and explain tests; add test for
d738b9
id-pkinit-san match against canonicalized client principal]
d738b9
d738b9
ticket: 8528
d738b9
(cherry picked from commit d520fd3f032121b61b22681838af96ee505fe44d)
d738b9
---
d738b9
 src/tests/t_pkinit.py | 57 +++++++++++++++++++++++++++++++++++++++++++
d738b9
 1 file changed, 57 insertions(+)
d738b9
d738b9
diff --git a/src/tests/t_pkinit.py b/src/tests/t_pkinit.py
d738b9
index 526473b42..ac4d326b6 100755
d738b9
--- a/src/tests/t_pkinit.py
d738b9
+++ b/src/tests/t_pkinit.py
d738b9
@@ -23,6 +23,9 @@ privkey_pem = os.path.join(certs, 'privkey.pem')
d738b9
 privkey_enc_pem = os.path.join(certs, 'privkey-enc.pem')
d738b9
 user_p12 = os.path.join(certs, 'user.p12')
d738b9
 user_enc_p12 = os.path.join(certs, 'user-enc.p12')
d738b9
+user_upn_p12 = os.path.join(certs, 'user-upn.p12')
d738b9
+user_upn2_p12 = os.path.join(certs, 'user-upn2.p12')
d738b9
+user_upn3_p12 = os.path.join(certs, 'user-upn3.p12')
d738b9
 path = os.path.join(os.getcwd(), 'testdir', 'tmp-pkinit-certs')
d738b9
 path_enc = os.path.join(os.getcwd(), 'testdir', 'tmp-pkinit-certs-enc')
d738b9
 
d738b9
@@ -36,6 +39,20 @@ pkinit_kdc_conf = {'realms': {'$realm': {
d738b9
 restrictive_kdc_conf = {'realms': {'$realm': {
d738b9
             'restrict_anonymous_to_tgt': 'true' }}}
d738b9
 
d738b9
+testprincs = {'krbtgt/KRBTEST.COM': {'keys': 'aes128-cts'},
d738b9
+              'user': {'keys': 'aes128-cts', 'flags': '+preauth'},
d738b9
+              'user2': {'keys': 'aes128-cts', 'flags': '+preauth'}}
d738b9
+alias_kdc_conf = {'realms': {'$realm': {
d738b9
+            'default_principal_flags': '+preauth',
d738b9
+            'pkinit_eku_checking': 'none',
d738b9
+            'pkinit_allow_upn': 'true',
d738b9
+            'pkinit_identity': 'FILE:%s,%s' % (kdc_pem, privkey_pem),
d738b9
+            'database_module': 'test'}},
d738b9
+                  'dbmodules': {'test': {
d738b9
+                      'db_library': 'test',
d738b9
+                      'alias': {'user@krbtest.com': 'user'},
d738b9
+                      'princs': testprincs}}}
d738b9
+
d738b9
 file_identity = 'FILE:%s,%s' % (user_pem, privkey_pem)
d738b9
 file_enc_identity = 'FILE:%s,%s' % (user_pem, privkey_enc_pem)
d738b9
 dir_identity = 'DIR:%s' % path
d738b9
@@ -45,11 +62,51 @@ dir_file_identity = 'FILE:%s,%s' % (os.path.join(path, 'user.crt'),
d738b9
 dir_file_enc_identity = 'FILE:%s,%s' % (os.path.join(path_enc, 'user.crt'),
d738b9
                                         os.path.join(path_enc, 'user.key'))
d738b9
 p12_identity = 'PKCS12:%s' % user_p12
d738b9
+p12_upn_identity = 'PKCS12:%s' % user_upn_p12
d738b9
+p12_upn2_identity = 'PKCS12:%s' % user_upn2_p12
d738b9
+p12_upn3_identity = 'PKCS12:%s' % user_upn3_p12
d738b9
 p12_enc_identity = 'PKCS12:%s' % user_enc_p12
d738b9
 p11_identity = 'PKCS11:soft-pkcs11.so'
d738b9
 p11_token_identity = ('PKCS11:module_name=soft-pkcs11.so:'
d738b9
                       'slotid=1:token=SoftToken (token)')
d738b9
 
d738b9
+# Start a realm with the test kdb module for the following UPN SAN tests.
d738b9
+realm = K5Realm(krb5_conf=pkinit_krb5_conf, kdc_conf=alias_kdc_conf,
d738b9
+                create_kdb=False)
d738b9
+realm.start_kdc()
d738b9
+
d738b9
+# Compatibility check: cert contains UPN "user", which matches the
d738b9
+# request principal user@KRBTEST.COM if parsed as a normal principal.
d738b9
+realm.kinit(realm.user_princ,
d738b9
+            flags=['-X', 'X509_user_identity=%s' % p12_upn2_identity])
d738b9
+
d738b9
+# Compatibility check: cert contains UPN "user@KRBTEST.COM", which matches
d738b9
+# the request principal user@KRBTEST.COM if parsed as a normal principal.
d738b9
+realm.kinit(realm.user_princ,
d738b9
+            flags=['-X', 'X509_user_identity=%s' % p12_upn3_identity])
d738b9
+
d738b9
+# Cert contains UPN "user@krbtest.com" which is aliased to the request
d738b9
+# principal.
d738b9
+realm.kinit(realm.user_princ,
d738b9
+            flags=['-X', 'X509_user_identity=%s' % p12_upn_identity])
d738b9
+
d738b9
+# Test an id-pkinit-san match to a post-canonical principal.
d738b9
+realm.kinit('user@krbtest.com',
d738b9
+            flags=['-E', '-X', 'X509_user_identity=%s' % p12_identity])
d738b9
+
d738b9
+# Test a UPN match to a post-canonical principal.  (This only works
d738b9
+# for the cert with the UPN containing just "user", as we don't allow
d738b9
+# UPN reparsing when comparing to the canonicalized client principal.)
d738b9
+realm.kinit('user@krbtest.com',
d738b9
+            flags=['-E', '-X', 'X509_user_identity=%s' % p12_upn2_identity])
d738b9
+
d738b9
+# Test a mismatch.
d738b9
+out = realm.run([kinit, '-X', 'X509_user_identity=%s' % p12_upn2_identity,
d738b9
+                 'user2'], expected_code=1)
d738b9
+if 'kinit: Client name mismatch while getting initial credentials' not in out:
d738b9
+    fail('Wrong error for UPN SAN mismatch')
d738b9
+realm.stop()
d738b9
+
d738b9
 realm = K5Realm(krb5_conf=pkinit_krb5_conf, kdc_conf=pkinit_kdc_conf,
d738b9
                 get_creds=False)
d738b9