Path: blob/main/crypto/krb5/src/tests/t_certauth.py
34878 views
from k5test import *12# Skip this test if pkinit wasn't built.3if not pkinit_enabled:4skip_rest('certauth tests', 'PKINIT module not built')56modpath = os.path.join(buildtop, 'plugins', 'certauth', 'test',7'certauth_test.so')8krb5_conf = {'plugins': {'certauth': {9'module': ['test1:' + modpath, 'test2:' + modpath, 'test3:' + modpath],10'enable_only': ['test1', 'test2', 'test3']}}}11kdc_conf = {'realms': {'$realm': {12'default_principal_flags': '+preauth',13'pkinit_indicator': ['indpkinit1', 'indpkinit2']}}}1415realm = K5Realm(krb5_conf=krb5_conf, kdc_conf=kdc_conf, get_creds=False,16pkinit=True)17realm.addprinc('nocert')1819def check_indicators(inds):20msg = '+97: [%s]' % inds21realm.run(['./adata', realm.host_princ], expected_msg=msg)2223# Test that authentication fails if no module accepts.24realm.pkinit('nocert', expected_code=1, expected_msg='Client name mismatch')2526# Let the test2 module match user to CN=user, with indicators.27realm.pkinit(realm.user_princ)28realm.klist(realm.user_princ)29check_indicators('test1, test2, user, indpkinit1, indpkinit2')3031# Let the test2 module mismatch with user2 to CN=user.32realm.addprinc('[email protected]')33realm.pkinit('user2', expected_code=1, expected_msg='Certificate mismatch')3435# Test the KRB5_CERTAUTH_HWAUTH return code.36mark('hw-authent flag tests')37# First test +requires_hwauth without causing the hw-authent ticket38# flag to be set. This currently results in a preauth loop.39realm.run([kadminl, 'modprinc', '+requires_hwauth', realm.user_princ])40realm.pkinit(realm.user_princ, expected_code=1,41expected_msg='Looping detected')42# Cause the test3 module to return KRB5_CERTAUTH_HWAUTH and try again.43# Authentication should succeed whether or not another module accepts,44# but not if another module rejects.45realm.run([kadminl, 'setstr', realm.user_princ, 'hwauth', 'ok'])46realm.run([kadminl, 'setstr', 'user2', 'hwauth', 'ok'])47realm.run([kadminl, 'setstr', 'nocert', 'hwauth', 'ok'])48realm.pkinit(realm.user_princ)49check_indicators('test1, test2, user, hwauth:ok, indpkinit1, indpkinit2')50realm.pkinit('user2', expected_code=1, expected_msg='Certificate mismatch')51realm.pkinit('nocert')52check_indicators('test1, hwauth:ok, indpkinit1, indpkinit2')5354# Cause the test3 module to return KRB5_CERTAUTH_HWAUTH_PASS and try55# again. Authentication should succeed only if another module accepts.56realm.run([kadminl, 'setstr', realm.user_princ, 'hwauth', 'pass'])57realm.run([kadminl, 'setstr', 'user2', 'hwauth', 'pass'])58realm.run([kadminl, 'setstr', 'nocert', 'hwauth', 'pass'])59realm.pkinit(realm.user_princ)60check_indicators('test1, test2, user, hwauth:pass, indpkinit1, indpkinit2')61realm.pkinit('user2', expected_code=1, expected_msg='Certificate mismatch')62realm.pkinit('nocert', expected_code=1, expected_msg='Client name mismatch')6364success("certauth tests")656667