xref: /freebsd/crypto/krb5/src/tests/t_u2u.py (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubertfrom k5test import *
2*7f2fe78bSCy Schubert
3*7f2fe78bSCy Schubertrealm = K5Realm(create_host=False)
4*7f2fe78bSCy Schubert
5*7f2fe78bSCy Schubert# Create a second user principal and get tickets for it.
6*7f2fe78bSCy Schubertu2u_ccache = 'FILE:' + os.path.join(realm.testdir, 'ccu2u')
7*7f2fe78bSCy Schubertrealm.addprinc('alice', password('alice'))
8*7f2fe78bSCy Schubertrealm.kinit('alice', password('alice'), ['-c', u2u_ccache])
9*7f2fe78bSCy Schubert
10*7f2fe78bSCy Schubert# Verify that -allow_dup_skey denies u2u requests.
11*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '-allow_dup_skey', 'alice'])
12*7f2fe78bSCy Schubertrealm.run([kvno, '--u2u', u2u_ccache, 'alice'], expected_code=1,
13*7f2fe78bSCy Schubert          expected_msg='KDC policy rejects request')
14*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '+allow_dup_skey', 'alice'])
15*7f2fe78bSCy Schubert
16*7f2fe78bSCy Schubert# Verify that -allow_svr denies regular TGS requests, but allows
17*7f2fe78bSCy Schubert# user-to-user TGS requests.
18*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '-allow_svr', 'alice'])
19*7f2fe78bSCy Schubertrealm.run([kvno, 'alice'], expected_code=1,
20*7f2fe78bSCy Schubert          expected_msg='Server principal valid for user2user only')
21*7f2fe78bSCy Schubertrealm.run([kvno, '--u2u', u2u_ccache, 'alice'], expected_msg='kvno = 0')
22*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '+allow_svr', 'alice'])
23*7f2fe78bSCy Schubert
24*7f2fe78bSCy Schubert# Verify that normal lookups ignore the user-to-user ticket.
25*7f2fe78bSCy Schubertrealm.run([kvno, 'alice'], expected_msg='kvno = 1')
26*7f2fe78bSCy Schubertout = realm.run([klist])
27*7f2fe78bSCy Schubertif out.count('alice@KRBTEST.COM') != 2:
28*7f2fe78bSCy Schubert    fail('expected two alice tickets after regular kvno')
29*7f2fe78bSCy Schubert
30*7f2fe78bSCy Schubert# Try u2u against the client user.
31*7f2fe78bSCy Schubertrealm.run([kvno, '--u2u', realm.ccache, realm.user_princ])
32*7f2fe78bSCy Schubert
33*7f2fe78bSCy Schubertrealm.run([klist])
34*7f2fe78bSCy Schubert
35*7f2fe78bSCy Schubertrealm.stop()
36*7f2fe78bSCy Schubert
37*7f2fe78bSCy Schubert# Load the test KDB module to test aliases
38*7f2fe78bSCy Schuberttestprincs = {'krbtgt/KRBTEST.COM': {'keys': 'aes128-cts'},
39*7f2fe78bSCy Schubert              'user': {'keys': 'aes128-cts', 'flags': '+preauth'},
40*7f2fe78bSCy Schubert              'WIN10': {'keys': 'aes128-cts'}}
41*7f2fe78bSCy Schubertkdcconf = {'realms': {'$realm': {'database_module': 'test'}},
42*7f2fe78bSCy Schubert           'dbmodules': {'test': {'db_library': 'test',
43*7f2fe78bSCy Schubert                                  'princs': testprincs,
44*7f2fe78bSCy Schubert                                  'alias': {'HOST/win10': 'WIN10'}}}}
45*7f2fe78bSCy Schubert
46*7f2fe78bSCy Schubertrealm = K5Realm(kdc_conf=kdcconf, create_kdb=False)
47*7f2fe78bSCy Schubertrealm.start_kdc()
48*7f2fe78bSCy Schubert
49*7f2fe78bSCy Schubert# Create a second user principal and get tickets for it.
50*7f2fe78bSCy Schubertu2u_ccache = 'FILE:' + os.path.join(realm.testdir, 'ccu2u')
51*7f2fe78bSCy Schubertrealm.extract_keytab('WIN10', realm.keytab)
52*7f2fe78bSCy Schubertrealm.kinit('WIN10', None, ['-k', '-c', u2u_ccache])
53*7f2fe78bSCy Schubert
54*7f2fe78bSCy Schubertrealm.extract_keytab(realm.user_princ, realm.keytab)
55*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-k'])
56*7f2fe78bSCy Schubert
57*7f2fe78bSCy Schubertrealm.run([kvno, '--u2u', u2u_ccache, 'HOST/win10'], expected_msg='kvno = 0')
58*7f2fe78bSCy Schubertrealm.run([kvno, '--u2u', u2u_ccache, 'WIN10'], expected_msg='kvno = 0')
59*7f2fe78bSCy Schubert
60*7f2fe78bSCy Schubertsuccess('user-to-user tests')
61