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

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