xref: /freebsd/crypto/krb5/src/tests/t_authdata.py (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubertfrom k5test import *
2*7f2fe78bSCy Schubert
3*7f2fe78bSCy Schubert# Load the sample KDC authdata module.  Allow renewable tickets.
4*7f2fe78bSCy Schubertgreet_path = os.path.join(buildtop, 'plugins', 'authdata', 'greet_server',
5*7f2fe78bSCy Schubert                          'greet_server.so')
6*7f2fe78bSCy Schubertconf = {'realms': {'$realm': {'max_life': '20h', 'max_renewable_life': '20h'}},
7*7f2fe78bSCy Schubert        'plugins': {'kdcauthdata': {'module': 'greet:' + greet_path}}}
8*7f2fe78bSCy Schubertrealm = K5Realm(krb5_conf=conf)
9*7f2fe78bSCy Schubert
10*7f2fe78bSCy Schubert# With no requested authdata, we expect to see PAC (128) in an
11*7f2fe78bSCy Schubert# if-relevant container and the greet authdata in a kdc-issued
12*7f2fe78bSCy Schubert# container.
13*7f2fe78bSCy Schubertmark('baseline authdata')
14*7f2fe78bSCy Schubertout = realm.run(['./adata', realm.host_princ])
15*7f2fe78bSCy Schubertif '?128: [6, 7, 10, 16, 19]' not in out or '^-42: Hello' not in out:
16*7f2fe78bSCy Schubert    fail('expected authdata not seen for basic request')
17*7f2fe78bSCy Schubert
18*7f2fe78bSCy Schubert# Requested authdata is copied into the ticket, with KDC-only types
19*7f2fe78bSCy Schubert# filtered out.  (128 is win2k-pac, which should be filtered.)
20*7f2fe78bSCy Schubertmark('request authdata')
21*7f2fe78bSCy Schubertout = realm.run(['./adata', realm.host_princ, '-5', 'test1', '?-6', 'test2',
22*7f2fe78bSCy Schubert                 '128', 'fakepac', '?128', 'ifrelfakepac',
23*7f2fe78bSCy Schubert                 '^-8', 'fakekdcissued', '?^-8', 'ifrelfakekdcissued'])
24*7f2fe78bSCy Schubertif ' -5: test1' not in out or '?-6: test2' not in out:
25*7f2fe78bSCy Schubert    fail('expected authdata not seen for request with authdata')
26*7f2fe78bSCy Schubertif 'fake' in out:
27*7f2fe78bSCy Schubert    fail('KDC-only authdata not filtered for request with authdata')
28*7f2fe78bSCy Schubert
29*7f2fe78bSCy Schubertmark('AD-MANDATORY-FOR-KDC')
30*7f2fe78bSCy Schubertrealm.run(['./adata', realm.host_princ, '!-1', 'mandatoryforkdc'],
31*7f2fe78bSCy Schubert          expected_code=1, expected_msg='KDC policy rejects request')
32*7f2fe78bSCy Schubert
33*7f2fe78bSCy Schubert# The no_auth_data_required server flag should suppress the PAC, but
34*7f2fe78bSCy Schubert# not module or request authdata.
35*7f2fe78bSCy Schubertmark('no_auth_data_required server flag')
36*7f2fe78bSCy Schubertrealm.run([kadminl, 'ank', '-randkey', '+no_auth_data_required', 'noauth'])
37*7f2fe78bSCy Schubertrealm.extract_keytab('noauth', realm.keytab)
38*7f2fe78bSCy Schubertout = realm.run(['./adata', 'noauth', '-2', 'test'])
39*7f2fe78bSCy Schubertif '^-42: Hello' not in out or ' -2: test' not in out:
40*7f2fe78bSCy Schubert    fail('expected authdata not seen for no_auth_data_required request')
41*7f2fe78bSCy Schubertif '128: ' in out:
42*7f2fe78bSCy Schubert    fail('PAC authdata seen for no_auth_data_required request')
43*7f2fe78bSCy Schubert
44*7f2fe78bSCy Schubert# Cross-realm TGT requests should not suppress PAC or request
45*7f2fe78bSCy Schubert# authdata.
46*7f2fe78bSCy Schubertmark('cross-realm')
47*7f2fe78bSCy Schubertrealm.addprinc('krbtgt/XREALM')
48*7f2fe78bSCy Schubertrealm.extract_keytab('krbtgt/XREALM', realm.keytab)
49*7f2fe78bSCy Schubertout = realm.run(['./adata', 'krbtgt/XREALM', '-3', 'test'])
50*7f2fe78bSCy Schubertif '128:' not in out or  '^-42: Hello' not in out or ' -3: test' not in out:
51*7f2fe78bSCy Schubert    fail('expected authdata not seen for cross-realm TGT request')
52*7f2fe78bSCy Schubert
53*7f2fe78bSCy Schubertmark('pac_privsvr_enctype')
54*7f2fe78bSCy Schubert# Change the privsvr enctype and make sure we can still verify the PAC
55*7f2fe78bSCy Schubert# on a service ticket in a TGS request.
56*7f2fe78bSCy Schubertrealm.run([kadminl, 'setstr', realm.host_princ,
57*7f2fe78bSCy Schubert           'pac_privsvr_enctype', 'aes128-sha1'])
58*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'),
59*7f2fe78bSCy Schubert            ['-S', realm.host_princ, '-r', '1h'])
60*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-S', realm.host_princ, '-R'])
61*7f2fe78bSCy Schubert# Remove the attribute and make sure the previously-issued service
62*7f2fe78bSCy Schubert# ticket PAC no longer verifies.
63*7f2fe78bSCy Schubertrealm.run([kadminl, 'delstr', realm.host_princ, 'pac_privsvr_enctype'])
64*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-S', realm.host_princ, '-R'],
65*7f2fe78bSCy Schubert            expected_code=1, expected_msg='Message stream modified')
66*7f2fe78bSCy Schubert
67*7f2fe78bSCy Schubertrealm.stop()
68*7f2fe78bSCy Schubert
69*7f2fe78bSCy Schubertif not pkinit_enabled:
70*7f2fe78bSCy Schubert    skipped('anonymous ticket authdata tests', 'PKINIT not built')
71*7f2fe78bSCy Schubertelse:
72*7f2fe78bSCy Schubert    # Set up a realm with PKINIT support and get anonymous tickets.
73*7f2fe78bSCy Schubert    realm = K5Realm(krb5_conf=conf, get_creds=False, pkinit=True)
74*7f2fe78bSCy Schubert    realm.addprinc('WELLKNOWN/ANONYMOUS')
75*7f2fe78bSCy Schubert    realm.kinit('@%s' % realm.realm, flags=['-n'])
76*7f2fe78bSCy Schubert
77*7f2fe78bSCy Schubert    # PAC and module authdata should be suppressed for anonymous
78*7f2fe78bSCy Schubert    # tickets, but not request authdata.
79*7f2fe78bSCy Schubert    mark('anonymous')
80*7f2fe78bSCy Schubert    out = realm.run(['./adata', realm.host_princ, '-4', 'test'])
81*7f2fe78bSCy Schubert    if ' -4: test' not in out:
82*7f2fe78bSCy Schubert        fail('expected authdata not seen for anonymous request')
83*7f2fe78bSCy Schubert    if '128: ' in out or '-42: ' in out:
84*7f2fe78bSCy Schubert        fail('PAC or greet authdata seen for anonymous request')
85*7f2fe78bSCy Schubert
86*7f2fe78bSCy Schubertrealm.stop()
87*7f2fe78bSCy Schubert
88*7f2fe78bSCy Schubert# Test authentication indicators.  Load the test preauth module so we
89*7f2fe78bSCy Schubert# can control the indicators asserted.
90*7f2fe78bSCy Schuberttestpreauth = os.path.join(buildtop, 'plugins', 'preauth', 'test', 'test.so')
91*7f2fe78bSCy Schubertkrb5conf = {'plugins': {'kdcpreauth': {'module': 'test:' + testpreauth},
92*7f2fe78bSCy Schubert                        'clpreauth': {'module': 'test:' + testpreauth}}}
93*7f2fe78bSCy Schubertrealm, realm2 = cross_realms(2, args=({'realm': 'LOCAL'},
94*7f2fe78bSCy Schubert                                      {'realm': 'FOREIGN'}),
95*7f2fe78bSCy Schubert                             krb5_conf=krb5conf, get_creds=False)
96*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '+requires_preauth', '-maxrenewlife', '2 days',
97*7f2fe78bSCy Schubert           realm.user_princ])
98*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '-maxrenewlife', '2 days', realm.host_princ])
99*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '-maxrenewlife', '2 days', realm.krbtgt_princ])
100*7f2fe78bSCy Schubertrealm.extract_keytab(realm.krbtgt_princ, realm.keytab)
101*7f2fe78bSCy Schubertrealm.extract_keytab(realm.host_princ, realm.keytab)
102*7f2fe78bSCy Schubertrealm.extract_keytab('krbtgt/FOREIGN', realm.keytab)
103*7f2fe78bSCy Schubertrealm2.extract_keytab(realm2.krbtgt_princ, realm.keytab)
104*7f2fe78bSCy Schubertrealm2.extract_keytab(realm2.host_princ, realm.keytab)
105*7f2fe78bSCy Schubertrealm2.extract_keytab('krbtgt/LOCAL', realm.keytab)
106*7f2fe78bSCy Schubert
107*7f2fe78bSCy Schubert# AS request to local-realm service
108*7f2fe78bSCy Schubertmark('AS-REQ to local service auth indicator')
109*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'),
110*7f2fe78bSCy Schubert            ['-X', 'indicators=indcl', '-r', '2d', '-S', realm.host_princ])
111*7f2fe78bSCy Schubertrealm.run(['./adata', realm.host_princ], expected_msg='+97: [indcl]')
112*7f2fe78bSCy Schubert
113*7f2fe78bSCy Schubert# Ticket modification request
114*7f2fe78bSCy Schubertmark('ticket modification auth indicator')
115*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-R', '-S', realm.host_princ])
116*7f2fe78bSCy Schubertrealm.run(['./adata', realm.host_princ], expected_msg='+97: [indcl]')
117*7f2fe78bSCy Schubert
118*7f2fe78bSCy Schubert# AS request to cross TGT
119*7f2fe78bSCy Schubertmark('AS-REQ to cross TGT auth indicator')
120*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'),
121*7f2fe78bSCy Schubert            ['-X', 'indicators=indcl', '-S', 'krbtgt/FOREIGN'])
122*7f2fe78bSCy Schubertrealm.run(['./adata', 'krbtgt/FOREIGN'], expected_msg='+97: [indcl]')
123*7f2fe78bSCy Schubert
124*7f2fe78bSCy Schubert# Multiple indicators
125*7f2fe78bSCy Schubertmark('AS multiple indicators')
126*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'),
127*7f2fe78bSCy Schubert            ['-X', 'indicators=indcl indcl2 indcl3'])
128*7f2fe78bSCy Schubertrealm.run(['./adata', realm.krbtgt_princ],
129*7f2fe78bSCy Schubert          expected_msg='+97: [indcl, indcl2, indcl3]')
130*7f2fe78bSCy Schubert
131*7f2fe78bSCy Schubert# AS request to local TGT (resulting creds are used for TGS tests)
132*7f2fe78bSCy Schubertmark('AS-REQ to local TGT auth indicator')
133*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'), ['-X', 'indicators=indcl'])
134*7f2fe78bSCy Schubertrealm.run(['./adata', realm.krbtgt_princ], expected_msg='+97: [indcl]')
135*7f2fe78bSCy Schubert
136*7f2fe78bSCy Schubert# Local TGS request for local realm service
137*7f2fe78bSCy Schubertmark('TGS-REQ to local service auth indicator')
138*7f2fe78bSCy Schubertrealm.run(['./adata', realm.host_princ], expected_msg='+97: [indcl]')
139*7f2fe78bSCy Schubert
140*7f2fe78bSCy Schubert# Local TGS request for cross TGT service
141*7f2fe78bSCy Schubertmark('TGS-REQ to cross TGT auth indicator')
142*7f2fe78bSCy Schubertrealm.run(['./adata', 'krbtgt/FOREIGN'], expected_msg='+97: [indcl]')
143*7f2fe78bSCy Schubert
144*7f2fe78bSCy Schubert# We don't yet have support for passing auth indicators across realms,
145*7f2fe78bSCy Schubert# so just verify that indicators don't survive cross-realm requests.
146*7f2fe78bSCy Schubertmark('TGS-REQ to foreign service auth indicator')
147*7f2fe78bSCy Schubertout = realm.run(['./adata', realm2.krbtgt_princ])
148*7f2fe78bSCy Schubertif '97:' in out:
149*7f2fe78bSCy Schubert    fail('auth-indicator seen in cross TGT request to local TGT')
150*7f2fe78bSCy Schubertout = realm.run(['./adata', 'krbtgt/LOCAL@FOREIGN'])
151*7f2fe78bSCy Schubertif '97:' in out:
152*7f2fe78bSCy Schubert    fail('auth-indicator seen in cross TGT request to cross TGT')
153*7f2fe78bSCy Schubertout = realm.run(['./adata', realm2.host_princ])
154*7f2fe78bSCy Schubertif '97:' in out:
155*7f2fe78bSCy Schubert    fail('auth-indicator seen in cross TGT request to service')
156*7f2fe78bSCy Schubert
157*7f2fe78bSCy Schubert# Test that the CAMMAC signature still works during a krbtgt rollover.
158*7f2fe78bSCy Schubertmark('CAMMAC signature across krbtgt rollover')
159*7f2fe78bSCy Schubertrealm.run([kadminl, 'cpw', '-randkey', '-keepold', realm.krbtgt_princ])
160*7f2fe78bSCy Schubertrealm.run(['./adata', realm.host_princ], expected_msg='+97: [indcl]')
161*7f2fe78bSCy Schubert
162*7f2fe78bSCy Schubert# Test indicator enforcement.
163*7f2fe78bSCy Schubertmark('auth indicator enforcement')
164*7f2fe78bSCy Schubertrealm.addprinc('restricted')
165*7f2fe78bSCy Schubertrealm.run([kadminl, 'setstr', 'restricted', 'require_auth', 'superstrong'])
166*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'), ['-S', 'restricted'],
167*7f2fe78bSCy Schubert            expected_code=1, expected_msg='KDC policy rejects request')
168*7f2fe78bSCy Schubertrealm.run([kvno, 'restricted'], expected_code=1,
169*7f2fe78bSCy Schubert          expected_msg='KDC policy rejects request')
170*7f2fe78bSCy Schubertrealm.run([kadminl, 'setstr', 'restricted', 'require_auth', 'indcl'])
171*7f2fe78bSCy Schubertrealm.run([kvno, 'restricted'])
172*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'), ['-X', 'indicators=ind1 ind2'])
173*7f2fe78bSCy Schubertrealm.run([kvno, 'restricted'], expected_code=1)
174*7f2fe78bSCy Schubertrealm.run([kadminl, 'setstr', 'restricted', 'require_auth', 'a b c ind2'])
175*7f2fe78bSCy Schubertrealm.run([kvno, 'restricted'])
176*7f2fe78bSCy Schubert
177*7f2fe78bSCy Schubert# Regression test for one manifestation of #8139: ensure that
178*7f2fe78bSCy Schubert# forwarded TGTs obtained across a TGT re-key still work when the
179*7f2fe78bSCy Schubert# preferred krbtgt enctype changes.
180*7f2fe78bSCy Schubertmark('#8139 regression test')
181*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'), ['-f'])
182*7f2fe78bSCy Schubertrealm.run([kadminl, 'cpw', '-randkey', '-keepold', '-e', 'des3-cbc-sha1',
183*7f2fe78bSCy Schubert           realm.krbtgt_princ])
184*7f2fe78bSCy Schubertrealm.run(['./forward'])
185*7f2fe78bSCy Schubertrealm.run([kvno, realm.host_princ])
186*7f2fe78bSCy Schubert
187*7f2fe78bSCy Schubert# Repeat the above test using a renewed TGT.
188*7f2fe78bSCy Schubertmark('#8139 regression test (renewed TGT)')
189*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'), ['-r', '2d'])
190*7f2fe78bSCy Schubertrealm.run([kadminl, 'cpw', '-randkey', '-keepold', '-e', 'aes128-cts',
191*7f2fe78bSCy Schubert           realm.krbtgt_princ])
192*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-R'])
193*7f2fe78bSCy Schubertrealm.run([kvno, realm.host_princ])
194*7f2fe78bSCy Schubert
195*7f2fe78bSCy Schubertrealm.stop()
196*7f2fe78bSCy Schubertrealm2.stop()
197*7f2fe78bSCy Schubert
198*7f2fe78bSCy Schubert# Load the test KDB module to allow successful S4U2Proxy
199*7f2fe78bSCy Schubert# auth-indicator requests and to detect whether replaced_reply_key is
200*7f2fe78bSCy Schubert# set.
201*7f2fe78bSCy Schuberttestprincs = {'krbtgt/KRBTEST.COM': {'keys': 'aes128-cts'},
202*7f2fe78bSCy Schubert              'krbtgt/FOREIGN': {'keys': 'aes128-cts'},
203*7f2fe78bSCy Schubert              'user': {'keys': 'aes128-cts', 'flags': '+preauth'},
204*7f2fe78bSCy Schubert              'user2': {'keys': 'aes128-cts', 'flags': '+preauth'},
205*7f2fe78bSCy Schubert              'rservice': {'keys': 'aes128-cts',
206*7f2fe78bSCy Schubert                           'strings': 'require_auth:strong'},
207*7f2fe78bSCy Schubert              'service/1': {'keys': 'aes128-cts',
208*7f2fe78bSCy Schubert                            'flags': '+ok_to_auth_as_delegate'},
209*7f2fe78bSCy Schubert              'service/2': {'keys': 'aes128-cts'},
210*7f2fe78bSCy Schubert              'noauthdata': {'keys': 'aes128-cts',
211*7f2fe78bSCy Schubert                             'flags': '+no_auth_data_required'}}
212*7f2fe78bSCy Schubertkdcconf = {'realms': {'$realm': {'database_module': 'test'}},
213*7f2fe78bSCy Schubert           'dbmodules': {'test': {'db_library': 'test',
214*7f2fe78bSCy Schubert                                  'princs': testprincs,
215*7f2fe78bSCy Schubert                                  'delegation': {'service/1': 'service/2'}}}}
216*7f2fe78bSCy Schubertrealm = K5Realm(krb5_conf=krb5conf, kdc_conf=kdcconf, create_kdb=False,
217*7f2fe78bSCy Schubert                pkinit=True)
218*7f2fe78bSCy Schubertusercache = 'FILE:' + os.path.join(realm.testdir, 'usercache')
219*7f2fe78bSCy Schubertrealm.extract_keytab(realm.krbtgt_princ, realm.keytab)
220*7f2fe78bSCy Schubertrealm.extract_keytab('krbtgt/FOREIGN', realm.keytab)
221*7f2fe78bSCy Schubertrealm.extract_keytab(realm.user_princ, realm.keytab)
222*7f2fe78bSCy Schubertrealm.extract_keytab('ruser', realm.keytab)
223*7f2fe78bSCy Schubertrealm.extract_keytab('service/1', realm.keytab)
224*7f2fe78bSCy Schubertrealm.extract_keytab('service/2', realm.keytab)
225*7f2fe78bSCy Schubertrealm.extract_keytab('noauthdata', realm.keytab)
226*7f2fe78bSCy Schubertrealm.start_kdc()
227*7f2fe78bSCy Schubert
228*7f2fe78bSCy Schubertif not pkinit_enabled:
229*7f2fe78bSCy Schubert    skipped('replaced_reply_key test', 'PKINIT not built')
230*7f2fe78bSCy Schubertelse:
231*7f2fe78bSCy Schubert    # Check that replaced_reply_key is set in issue_pac() when PKINIT
232*7f2fe78bSCy Schubert    # is used.  The test KDB module will indicate this by including a
233*7f2fe78bSCy Schubert    # fake PAC_CREDENTIAL_INFO(2) buffer in the PAC.
234*7f2fe78bSCy Schubert    mark('PKINIT (replaced_reply_key set)')
235*7f2fe78bSCy Schubert    realm.pkinit(realm.user_princ)
236*7f2fe78bSCy Schubert    realm.run(['./adata', realm.krbtgt_princ],
237*7f2fe78bSCy Schubert              expected_msg='?128: [1, 2, 6, 7, 10]')
238*7f2fe78bSCy Schubert
239*7f2fe78bSCy Schubert# S4U2Self (should have no indicators since client did not authenticate)
240*7f2fe78bSCy Schubertmark('S4U2Self (no auth indicators expected)')
241*7f2fe78bSCy Schubertrealm.kinit('service/1', None, ['-k', '-f', '-X', 'indicators=inds1'])
242*7f2fe78bSCy Schubertrealm.run([kvno, '-U', 'user', 'service/1'])
243*7f2fe78bSCy Schubertout = realm.run(['./adata', '-p', realm.user_princ, 'service/1'])
244*7f2fe78bSCy Schubertif '97:' in out:
245*7f2fe78bSCy Schubert    fail('auth-indicator present in S4U2Self response')
246*7f2fe78bSCy Schubert
247*7f2fe78bSCy Schubert# Get another S4U2Self ticket with requested authdata.
248*7f2fe78bSCy Schubertrealm.run(['./s4u2self', 'user', 'service/1', '-', '-2', 'self_ad'])
249*7f2fe78bSCy Schubertrealm.run(['./adata', '-p', realm.user_princ, 'service/1', '-2', 'self_ad'],
250*7f2fe78bSCy Schubert          expected_msg=' -2: self_ad')
251*7f2fe78bSCy Schubert
252*7f2fe78bSCy Schubert# S4U2Proxy (indicators should come from evidence ticket, not TGT)
253*7f2fe78bSCy Schubertmark('S4U2Proxy (auth indicators from evidence ticket expected)')
254*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-k', '-f', '-X', 'indicators=indcl',
255*7f2fe78bSCy Schubert                                     '-S', 'service/1', '-c', usercache])
256*7f2fe78bSCy Schubertrealm.run(['./s4u2proxy', usercache, 'service/2'])
257*7f2fe78bSCy Schubertout = realm.run(['./adata', '-p', realm.user_princ, 'service/2'])
258*7f2fe78bSCy Schubertif '+97: [indcl]' not in out or '[inds1]' in out:
259*7f2fe78bSCy Schubert    fail('correct auth-indicator not seen for S4U2Proxy req')
260*7f2fe78bSCy Schubert# Make sure a PAC with an S4U_DELEGATION_INFO(11) buffer is included.
261*7f2fe78bSCy Schubertif '?128: [1, 6, 7, 10, 11, 16, 19]' not in out:
262*7f2fe78bSCy Schubert    fail('PAC with delegation info not seen for S4U2Proxy req')
263*7f2fe78bSCy Schubert
264*7f2fe78bSCy Schubert# Get another S4U2Proxy ticket including request-authdata.
265*7f2fe78bSCy Schubertrealm.run(['./s4u2proxy', usercache, 'service/2', '-2', 'proxy_ad'])
266*7f2fe78bSCy Schubertrealm.run(['./adata', '-p', realm.user_princ, 'service/2', '-2', 'proxy_ad'],
267*7f2fe78bSCy Schubert          expected_msg=' -2: proxy_ad')
268*7f2fe78bSCy Schubert
269*7f2fe78bSCy Schubert# Get an S4U2Proxy ticket using an evidence ticket obtained by S4U2Self,
270*7f2fe78bSCy Schubert# with request authdata in both steps.
271*7f2fe78bSCy Schubertrealm.run(['./s4u2self', 'user2', 'service/1', usercache, '-2', 'self_ad'])
272*7f2fe78bSCy Schubertrealm.run(['./s4u2proxy', usercache, 'service/2', '-2', 'proxy_ad'])
273*7f2fe78bSCy Schubertout = realm.run(['./adata', '-p', 'user2', 'service/2', '-2', 'proxy_ad'])
274*7f2fe78bSCy Schubertif ' -2: self_ad' not in out or ' -2: proxy_ad' not in out:
275*7f2fe78bSCy Schubert    fail('expected authdata not seen in S4U2Proxy ticket')
276*7f2fe78bSCy Schubert
277*7f2fe78bSCy Schubert# Test alteration of auth indicators by KDB module (AS and TGS).
278*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-k', '-X', 'indicators=dummy dbincr1'])
279*7f2fe78bSCy Schubertrealm.run(['./adata', realm.krbtgt_princ], expected_msg='+97: [dbincr2]')
280*7f2fe78bSCy Schubertrealm.run(['./adata', 'service/1'], expected_msg='+97: [dbincr3]')
281*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None,
282*7f2fe78bSCy Schubert            ['-k', '-X', 'indicators=strong', '-S', 'rservice'])
283*7f2fe78bSCy Schubert# Test enforcement of altered indicators during AS request.
284*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None,
285*7f2fe78bSCy Schubert            ['-k', '-X', 'indicators=strong dbincr1', '-S', 'rservice'],
286*7f2fe78bSCy Schubert            expected_code=1)
287*7f2fe78bSCy Schubert
288*7f2fe78bSCy Schubert# Test that the PAC is suppressed in an AS request by a negative PAC
289*7f2fe78bSCy Schubert# request.
290*7f2fe78bSCy Schubertmark('AS-REQ PAC client supression')
291*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-k', '--no-request-pac'])
292*7f2fe78bSCy Schubertout = realm.run(['./adata', realm.krbtgt_princ])
293*7f2fe78bSCy Schubertif '128:' in out:
294*7f2fe78bSCy Schubert    fail('PAC not suppressed by --no-request-pac')
295*7f2fe78bSCy Schubert
296*7f2fe78bSCy Schubertmark('S4U2Proxy with a foreign client')
297*7f2fe78bSCy Schubert
298*7f2fe78bSCy Schuberta_princs = {'krbtgt/A': {'keys': 'aes128-cts'},
299*7f2fe78bSCy Schubert            'krbtgt/B': {'keys': 'aes128-cts'},
300*7f2fe78bSCy Schubert            'impersonator': {'keys': 'aes128-cts'},
301*7f2fe78bSCy Schubert            'impersonator2': {'keys': 'aes128-cts'},
302*7f2fe78bSCy Schubert            'resource': {'keys': 'aes128-cts'}}
303*7f2fe78bSCy Schuberta_kconf = {'realms': {'$realm': {'database_module': 'test'}},
304*7f2fe78bSCy Schubert           'dbmodules': {'test': {'db_library': 'test',
305*7f2fe78bSCy Schubert                                  'delegation': {'impersonator' : 'resource'},
306*7f2fe78bSCy Schubert                                  'princs': a_princs,
307*7f2fe78bSCy Schubert                                  'alias': {'service/rb.b': '@B'}}}}
308*7f2fe78bSCy Schubert
309*7f2fe78bSCy Schubertb_princs = {'krbtgt/B': {'keys': 'aes128-cts'},
310*7f2fe78bSCy Schubert            'krbtgt/A': {'keys': 'aes128-cts'},
311*7f2fe78bSCy Schubert            'user': {'keys': 'aes128-cts', 'flags': '+preauth'},
312*7f2fe78bSCy Schubert            'rb': {'keys': 'aes128-cts'}}
313*7f2fe78bSCy Schubertb_kconf = {'realms': {'$realm': {'database_module': 'test'}},
314*7f2fe78bSCy Schubert           'dbmodules': {'test': {'db_library': 'test',
315*7f2fe78bSCy Schubert                                  'princs': b_princs,
316*7f2fe78bSCy Schubert                                  'rbcd': {'rb@B': 'impersonator2@A'},
317*7f2fe78bSCy Schubert                                  'alias': {'service/rb.b': 'rb',
318*7f2fe78bSCy Schubert                                            'impersonator2@A': '@A'}}}}
319*7f2fe78bSCy Schubert
320*7f2fe78bSCy Schubertra, rb = cross_realms(2, xtgts=(),
321*7f2fe78bSCy Schubert                          args=({'realm': 'A', 'kdc_conf': a_kconf},
322*7f2fe78bSCy Schubert                                {'realm': 'B', 'kdc_conf': b_kconf}),
323*7f2fe78bSCy Schubert                          create_kdb=False)
324*7f2fe78bSCy Schubert
325*7f2fe78bSCy Schubertra.start_kdc()
326*7f2fe78bSCy Schubertrb.start_kdc()
327*7f2fe78bSCy Schubert
328*7f2fe78bSCy Schubertra.extract_keytab('impersonator@A', ra.keytab)
329*7f2fe78bSCy Schubertra.extract_keytab('impersonator2@A', ra.keytab)
330*7f2fe78bSCy Schubertrb.extract_keytab('user@B', rb.keytab)
331*7f2fe78bSCy Schubert
332*7f2fe78bSCy Schubertusercache = 'FILE:' + os.path.join(rb.testdir, 'usercache')
333*7f2fe78bSCy Schubertrb.kinit(rb.user_princ, None, ['-k', '-f', '-c', usercache])
334*7f2fe78bSCy Schubertrb.run([kvno, '-C', 'impersonator@A', '-c', usercache])
335*7f2fe78bSCy Schubert
336*7f2fe78bSCy Schubertra.kinit('impersonator@A', None, ['-f', '-k', '-t', ra.keytab])
337*7f2fe78bSCy Schubertra.run(['./s4u2proxy', usercache, 'resource@A'])
338*7f2fe78bSCy Schubert
339*7f2fe78bSCy Schubertmark('Cross realm S4U authdata tests')
340*7f2fe78bSCy Schubert
341*7f2fe78bSCy Schubertra.kinit('impersonator2@A', None, ['-f', '-k', '-t', ra.keytab])
342*7f2fe78bSCy Schubertra.run(['./s4u2self', rb.user_princ, 'impersonator2@A', usercache, '-2',
343*7f2fe78bSCy Schubert        'cross_s4u_self_ad'])
344*7f2fe78bSCy Schubertout = ra.run(['./adata', '-c', usercache, '-p', rb.user_princ,
345*7f2fe78bSCy Schubert              'impersonator2@A', '-2', 'cross_s4u_self_ad'])
346*7f2fe78bSCy Schubertif out.count(' -2: cross_s4u_self_ad') != 1:
347*7f2fe78bSCy Schubert    fail('expected one cross_s4u_self_ad, got: %s' % count)
348*7f2fe78bSCy Schubert
349*7f2fe78bSCy Schubertra.run(['./s4u2proxy', usercache, 'service/rb.b', '-2',
350*7f2fe78bSCy Schubert        'cross_s4u_proxy_ad'])
351*7f2fe78bSCy Schubertrb.extract_keytab('service/rb.b', ra.keytab)
352*7f2fe78bSCy Schubertout = ra.run(['./adata', '-p', rb.user_princ, 'service/rb.b', '-2',
353*7f2fe78bSCy Schubert              'cross_s4u_proxy_ad'])
354*7f2fe78bSCy Schubertif out.count(' -2: cross_s4u_self_ad') != 1:
355*7f2fe78bSCy Schubert    fail('expected one cross_s4u_self_ad, got: %s' % count)
356*7f2fe78bSCy Schubertif out.count(' -2: cross_s4u_proxy_ad') != 1:
357*7f2fe78bSCy Schubert    fail('expected one cross_s4u_proxy_ad, got: %s' % count)
358*7f2fe78bSCy Schubert
359*7f2fe78bSCy Schubertra.stop()
360*7f2fe78bSCy Schubertrb.stop()
361*7f2fe78bSCy Schubert
362*7f2fe78bSCy Schubertsuccess('Authorization data tests')
363