xref: /freebsd/crypto/krb5/src/tests/t_y2038.py (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubertfrom k5test import *
2*7f2fe78bSCy Schubert
3*7f2fe78bSCy Schubert# These tests will become much less important after the y2038 boundary
4*7f2fe78bSCy Schubert# has elapsed, and may start exhibiting problems around the year 2075.
5*7f2fe78bSCy Schubert
6*7f2fe78bSCy Schubertif runenv.sizeof_time_t <= 4:
7*7f2fe78bSCy Schubert    skip_rest('y2038 timestamp tests', 'platform has 32-bit time_t')
8*7f2fe78bSCy Schubert
9*7f2fe78bSCy Schubert# Start a KDC running roughly 21 years in the future, after the y2038
10*7f2fe78bSCy Schubert# boundary.  Set long maximum lifetimes for later tests.
11*7f2fe78bSCy Schubertconf = {'realms': {'$realm': {'max_life': '9000d',
12*7f2fe78bSCy Schubert                              'max_renewable_life': '9000d'}}}
13*7f2fe78bSCy Schubertrealm = K5Realm(start_kdc=False, kdc_conf=conf)
14*7f2fe78bSCy Schubertrealm.start_kdc(['-T', '662256000'])
15*7f2fe78bSCy Schubert
16*7f2fe78bSCy Schubert# kinit without preauth should succeed with clock skew correction, but
17*7f2fe78bSCy Schubert# will result in an expired ticket, because we sent an absolute end
18*7f2fe78bSCy Schubert# time and didn't get a chance to correct it..
19*7f2fe78bSCy Schubertmark('kinit, no preauth')
20*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'))
21*7f2fe78bSCy Schubertrealm.run([kvno, realm.host_princ], expected_code=1,
22*7f2fe78bSCy Schubert          expected_msg='Ticket expired')
23*7f2fe78bSCy Schubert
24*7f2fe78bSCy Schubert# kinit with preauth should succeed and result in a valid ticket, as
25*7f2fe78bSCy Schubert# we get a chance to correct the end time based on the KDC time.  Try
26*7f2fe78bSCy Schubert# with encrypted timestamp and encrypted challenge.
27*7f2fe78bSCy Schubertmark('kinit, with preauth')
28*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '+requires_preauth', 'user'])
29*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'))
30*7f2fe78bSCy Schubertrealm.run([kvno, realm.host_princ])
31*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'), flags=['-T', realm.ccache])
32*7f2fe78bSCy Schubertrealm.run([kvno, realm.host_princ])
33*7f2fe78bSCy Schubert
34*7f2fe78bSCy Schubert# Test that expiration warning works after y2038, by setting a
35*7f2fe78bSCy Schubert# password expiration time ten minutes after the KDC time.
36*7f2fe78bSCy Schubertmark('expiration warning')
37*7f2fe78bSCy Schubertrealm.run([kadminl, 'modprinc', '-pwexpire', '662256600 seconds', 'user'])
38*7f2fe78bSCy Schubertout = realm.kinit(realm.user_princ, password('user'))
39*7f2fe78bSCy Schubertif 'will expire in less than one hour' not in out:
40*7f2fe78bSCy Schubert    fail('password expiration message')
41*7f2fe78bSCy Schubertyear = int(out.split()[-1])
42*7f2fe78bSCy Schubertif year < 2038 or year > 9999:
43*7f2fe78bSCy Schubert    fail('password expiration year')
44*7f2fe78bSCy Schubert
45*7f2fe78bSCy Schubertrealm.stop_kdc()
46*7f2fe78bSCy Schubertrealm.start_kdc()
47*7f2fe78bSCy Schubertrealm.start_kadmind()
48*7f2fe78bSCy Schubertrealm.prep_kadmin()
49*7f2fe78bSCy Schubert
50*7f2fe78bSCy Schubert# Test getdate parsing of absolute timestamps after 2038 and
51*7f2fe78bSCy Schubert# marshalling over the kadmin protocol.  The local time zone will
52*7f2fe78bSCy Schubert# affect the display time by a little bit, so just look for the year.
53*7f2fe78bSCy Schubertmark('kadmin marshalling')
54*7f2fe78bSCy Schubertrealm.run_kadmin(['modprinc', '-pwexpire', '2040-02-03', realm.host_princ])
55*7f2fe78bSCy Schubertrealm.run_kadmin(['getprinc', realm.host_princ], expected_msg=' 2040\n')
56*7f2fe78bSCy Schubert
57*7f2fe78bSCy Schubert# Get a ticket whose lifetime crosses the y2038 boundary and
58*7f2fe78bSCy Schubert# range-check the expiration year as reported by klist.
59*7f2fe78bSCy Schubertmark('ticket lifetime across y2038')
60*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, password('user'),
61*7f2fe78bSCy Schubert            flags=['-l', '8000d', '-r', '8500d'])
62*7f2fe78bSCy Schubertrealm.run([kvno, realm.host_princ])
63*7f2fe78bSCy Schubertout = realm.run([klist])
64*7f2fe78bSCy Schubertif int(out.split('\n')[4].split()[2].split('/')[2]) < 39:
65*7f2fe78bSCy Schubert    fail('unexpected tgt expiration year')
66*7f2fe78bSCy Schubertif int(out.split('\n')[5].split()[2].split('/')[2]) < 40:
67*7f2fe78bSCy Schubert    fail('unexpected tgt rtill year')
68*7f2fe78bSCy Schubertif int(out.split('\n')[6].split()[2].split('/')[2]) < 39:
69*7f2fe78bSCy Schubert    fail('unexpected service ticket expiration year')
70*7f2fe78bSCy Schubertif int(out.split('\n')[7].split()[2].split('/')[2]) < 40:
71*7f2fe78bSCy Schubert    fail('unexpected service ticket rtill year')
72*7f2fe78bSCy Schubertrealm.kinit(realm.user_princ, None, ['-R'])
73*7f2fe78bSCy Schubertout = realm.run([klist])
74*7f2fe78bSCy Schubertif int(out.split('\n')[4].split()[2].split('/')[2]) < 39:
75*7f2fe78bSCy Schubert    fail('unexpected renewed tgt expiration year')
76*7f2fe78bSCy Schubertif int(out.split('\n')[5].split()[2].split('/')[2]) < 40:
77*7f2fe78bSCy Schubert    fail('unexpected renewed tgt rtill year')
78*7f2fe78bSCy Schubert
79*7f2fe78bSCy Schubertsuccess('y2038 tests')
80