Blame src/tests/t_salt.py

Packit Service 99d1c0
from k5test import *
Packit Service 99d1c0
import re
Packit Service 99d1c0
Packit Service 99d1c0
realm = K5Realm(create_user=False)
Packit Service 99d1c0
Packit Service 99d1c0
# Check that a non-default salt type applies only to the key it is
Packit Service 99d1c0
# matched with and not to subsequent keys.  e1 and e2 are enctypes,
Packit Service 99d1c0
# and salt is a non-default salt type.
Packit Service 99d1c0
def test_salt(realm, e1, salt, e2):
Packit Service 99d1c0
    keysalts = e1 + ':' + salt + ',' + e2
Packit Service 99d1c0
    realm.run([kadminl, 'ank', '-e', keysalts, '-pw', 'password', 'user'])
Packit Service 99d1c0
    out = realm.run([kadminl, 'getprinc', 'user'])
Packit Service 99d1c0
    if len(re.findall(':' + salt, out)) != 1:
Packit Service 99d1c0
        fail(salt + ' present in second enctype or not present')
Packit Service 99d1c0
    realm.run([kadminl, 'delprinc', 'user'])
Packit Service 99d1c0
Packit Service 99d1c0
# Enctype/salt pairs chosen with non-default salt types.
Packit Service 99d1c0
# The enctypes are mostly arbitrary.
rpm-build 84505a
salts = [('aes128-cts-hmac-sha1-96', 'norealm'),
Packit Service 99d1c0
         ('arcfour-hmac', 'onlyrealm'),
Packit Service 99d1c0
         ('aes128-cts-hmac-sha1-96', 'special')]
Packit Service 99d1c0
# These enctypes are chosen to cover the different string-to-key routines.
Packit Service 99d1c0
# Omit ":normal" from aes256 to check that salttype defaulting works.
rpm-build 84505a
second_kstypes = ['aes256-cts-hmac-sha1-96', 'arcfour-hmac:normal']
Packit Service 99d1c0
Packit Service 99d1c0
# Test using different salt types in a principal's key list.
Packit Service 99d1c0
# Parameters from one key in the list must not leak over to later ones.
Packit Service 99d1c0
for e1, string in salts:
Packit Service 99d1c0
    for e2 in second_kstypes:
Packit Service 99d1c0
        test_salt(realm, e1, string, e2)
Packit Service 99d1c0
Packit Service 99d1c0
def test_dup(realm, ks):
Packit Service 99d1c0
    realm.run([kadminl, 'ank', '-e', ks, '-pw', 'password', 'ks_princ'])
Packit Service 99d1c0
    out = realm.run([kadminl, 'getprinc', 'ks_princ'])
Packit Service 99d1c0
    lines = out.split('\n')
Packit Service 99d1c0
    keys = [l for l in lines if 'Key: ' in l]
Packit Service 99d1c0
    uniq = set(keys)
Packit Service 99d1c0
    # 'Key:' matches 'MKey:' as well so len(keys) has one extra
Packit Service 99d1c0
    if (len(uniq) != len(keys)) or len(keys) > len(ks.split(',')):
Packit Service 99d1c0
        fail('Duplicate keysalt detection failed for keysalt ' + ks)
Packit Service 99d1c0
    realm.run([kadminl, 'delprinc', 'ks_princ'])
Packit Service 99d1c0
Packit Service 99d1c0
# All in-tree callers request duplicate suppression from
Packit Service 99d1c0
# krb5_string_to_keysalts(); we should check that it works, respects
Packit Service 99d1c0
# aliases, and doesn't result in an infinite loop.
Packit Service 99d1c0
dup_kstypes = ['arcfour-hmac-md5:normal,rc4-hmac:normal',
Packit Service 99d1c0
               'aes256-cts-hmac-sha1-96:normal,aes128-cts,aes256-cts',
Packit Service 99d1c0
               'aes256-cts-hmac-sha1-96:normal,aes256-cts:special,' +
Packit Service 99d1c0
               'aes256-cts-hmac-sha1-96:normal']
Packit Service 99d1c0
Packit Service 99d1c0
for ks in dup_kstypes:
Packit Service 99d1c0
    test_dup(realm, ks)
Packit Service 99d1c0
Packit Service 99d1c0
success("Salt types")