Blame src/tests/t_etype_info.py

Packit fd8b60
from k5test import *
Packit fd8b60
rpm-build 1cb403
supported_enctypes = 'aes128-cts rc4-hmac'
Packit fd8b60
conf = {'libdefaults': {'allow_weak_crypto': 'true'},
Packit fd8b60
        'realms': {'$realm': {'supported_enctypes': supported_enctypes}}}
Packit fd8b60
realm = K5Realm(create_host=False, get_creds=False, krb5_conf=conf)
Packit fd8b60
Packit fd8b60
realm.run([kadminl, 'addprinc', '-pw', 'pw', '+requires_preauth',
Packit fd8b60
           'preauthuser'])
Packit fd8b60
realm.run([kadminl, 'addprinc', '-pw', 'pw', '-e', 'rc4-hmac',
Packit fd8b60
           '+requires_preauth', 'rc4user'])
Packit fd8b60
realm.run([kadminl, 'addprinc', '-nokey', '+requires_preauth', 'nokeyuser'])
Packit fd8b60
Packit fd8b60
Packit fd8b60
# Run the test harness for the given principal and request enctype
Packit fd8b60
# list.  Compare the output to the expected lines, ignoring order.
Packit fd8b60
def test_etinfo(princ, enctypes, expected_lines):
Packit fd8b60
    mark('etinfo test: %s %s' % (princ.partition('@')[0], enctypes))
Packit fd8b60
    lines = realm.run(['./etinfo', princ, enctypes]).splitlines()
Packit fd8b60
    if sorted(lines) != sorted(expected_lines):
Packit fd8b60
        fail('Unexpected output for princ %s, etypes %s' % (princ, enctypes))
Packit fd8b60
Packit fd8b60
Packit fd8b60
# With no newer enctypes in the request, PA-ETYPE-INFO2,
Packit fd8b60
# PA-ETYPE-INFO, and PA-PW-SALT appear in the AS-REP, each listing one
Packit fd8b60
# key for the most preferred matching enctype.
rpm-build 1cb403
test_etinfo('user', 'rc4-hmac-exp rc4',
rpm-build 1cb403
            ['asrep etype_info2 rc4-hmac KRBTEST.COMuser',
rpm-build 1cb403
             'asrep etype_info rc4-hmac KRBTEST.COMuser',
Packit fd8b60
             'asrep pw_salt KRBTEST.COMuser'])
Packit fd8b60
Packit fd8b60
# With a newer enctype in the request (even if it is not the most
Packit fd8b60
# preferred enctype and doesn't match any keys), only PA-ETYPE-INFO2
Packit fd8b60
# appears.
Packit fd8b60
test_etinfo('user', 'rc4 aes256-cts',
Packit fd8b60
            ['asrep etype_info2 rc4-hmac KRBTEST.COMuser'])
Packit fd8b60
Packit fd8b60
# In preauth-required errors, PA-PW-SALT does not appear, but the same
Packit fd8b60
# etype-info2 values are expected.
rpm-build 1cb403
test_etinfo('preauthuser', 'rc4-hmac-exp rc4',
rpm-build 1cb403
            ['error etype_info2 rc4-hmac KRBTEST.COMpreauthuser',
rpm-build 1cb403
             'error etype_info rc4-hmac KRBTEST.COMpreauthuser'])
Packit fd8b60
test_etinfo('preauthuser', 'rc4 aes256-cts',
Packit fd8b60
            ['error etype_info2 rc4-hmac KRBTEST.COMpreauthuser'])
Packit fd8b60
Packit fd8b60
# If no keys are found matching the request enctypes, a
Packit fd8b60
# preauth-required error can be generated with no etype-info at all
Packit fd8b60
# (to allow for preauth mechs which don't depend on long-term keys).
Packit fd8b60
# An AS-REP cannot be generated without preauth as there is no reply
Packit fd8b60
# key.
rpm-build 1cb403
test_etinfo('rc4user', 'aes128-cts', [])
rpm-build 1cb403
test_etinfo('nokeyuser', 'aes128-cts', [])
Packit fd8b60
Packit fd8b60
# Verify that etype-info2 is included in a MORE_PREAUTH_DATA_REQUIRED
Packit fd8b60
# error if the client does optimistic preauth.
Packit fd8b60
mark('MORE_PREAUTH_DATA_REQUIRED test')
Packit fd8b60
realm.stop()
Packit fd8b60
testpreauth = os.path.join(buildtop, 'plugins', 'preauth', 'test', 'test.so')
Packit fd8b60
conf = {'plugins': {'kdcpreauth': {'module': 'test:' + testpreauth},
Packit fd8b60
                    'clpreauth': {'module': 'test:' + testpreauth}}}
Packit fd8b60
realm = K5Realm(create_host=False, get_creds=False, krb5_conf=conf)
Packit fd8b60
realm.run([kadminl, 'setstr', realm.user_princ, '2rt', '2rtval'])
Packit fd8b60
out = realm.run(['./etinfo', realm.user_princ, 'aes128-cts', '-123'])
Packit fd8b60
if out != 'more etype_info2 aes128-cts KRBTEST.COMuser\n':
Packit fd8b60
    fail('Unexpected output for MORE_PREAUTH_DATA_REQUIRED test')
Packit fd8b60
Packit fd8b60
success('KDC etype-info tests')