Imported Upstream version 1.15.1
[platform/upstream/krb5.git] / src / tests / t_skew.py
1 #!/usr/bin/python
2 from k5test import *
3
4 # Create a realm with the KDC one hour in the past.
5 realm = K5Realm(start_kdc=False)
6 realm.start_kdc(['-T', '-3600'])
7
8 # kinit (no preauth) should work, and should set a clock skew allowing
9 # kvno to work, with or without FAST.
10 realm.kinit(realm.user_princ, password('user'))
11 realm.run([kvno, realm.host_princ])
12 realm.kinit(realm.user_princ, password('user'), flags=['-T', realm.ccache])
13 realm.run([kvno, realm.host_princ])
14 realm.run([kdestroy])
15
16 # kinit (with preauth) should work, with or without FAST.
17 realm.run([kadminl, 'modprinc', '+requires_preauth', 'user'])
18 realm.kinit(realm.user_princ, password('user'))
19 realm.run([kvno, realm.host_princ])
20 realm.kinit(realm.user_princ, password('user'), flags=['-T', realm.ccache])
21 realm.run([kvno, realm.host_princ])
22 realm.run([kdestroy])
23
24 realm.stop()
25
26 # Repeat the above tests with kdc_timesync disabled.
27 conf = {'libdefaults': {'kdc_timesync': '0'}}
28 realm = K5Realm(start_kdc=False, krb5_conf=conf)
29 realm.start_kdc(['-T', '-3600'])
30
31 # Get tickets to use for FAST kinit tests.  The start time offset is
32 # ignored by the KDC since we aren't getting postdatable tickets, but
33 # serves to suppress the client clock skew check on the KDC reply.
34 fast_cache = realm.ccache + '.fast'
35 realm.kinit(realm.user_princ, password('user'),
36             flags=['-s', '-3600s', '-c', fast_cache])
37
38 # kinit should detect too much skew in the KDC response.  kinit with
39 # FAST should fail from the KDC since the armor AP-REQ won't be valid.
40 out = realm.kinit(realm.user_princ, password('user'), expected_code=1)
41 if 'Clock skew too great in KDC reply' not in out:
42     fail('Expected error message not seen in kinit skew case')
43 out = realm.kinit(realm.user_princ, None, flags=['-T', fast_cache],
44                   expected_code=1)
45 if 'Clock skew too great while' not in out:
46     fail('Expected error message not seen in kinit FAST skew case')
47
48 # kinit (with preauth) should fail from the KDC, with or without FAST.
49 realm.run([kadminl, 'modprinc', '+requires_preauth', 'user'])
50 out = realm.kinit(realm.user_princ, password('user'), expected_code=1)
51 if 'Clock skew too great while' not in out:
52     fail('Expected error message not seen in kinit skew case (preauth)')
53 out = realm.kinit(realm.user_princ, None, flags=['-T', fast_cache],
54                   expected_code=1)
55 if 'Clock skew too great while' not in out:
56     fail('Expected error message not seen in kinit FAST skew case (preauth)')
57
58 success('Clock skew tests')