Fix autoconf 2.70 compatibility
[platform/upstream/krb5.git] / src / tests / t_salt.py
1 from k5test import *
2 import re
3
4 realm = K5Realm(create_user=False)
5
6 # Check that a non-default salt type applies only to the key it is
7 # matched with and not to subsequent keys.  e1 and e2 are enctypes,
8 # and salt is a non-default salt type.
9 def test_salt(realm, e1, salt, e2):
10     keysalts = e1 + ':' + salt + ',' + e2
11     realm.run([kadminl, 'ank', '-e', keysalts, '-pw', 'password', 'user'])
12     out = realm.run([kadminl, 'getprinc', 'user'])
13     if len(re.findall(':' + salt, out)) != 1:
14         fail(salt + ' present in second enctype or not present')
15     realm.run([kadminl, 'delprinc', 'user'])
16
17 # Enctype/salt pairs chosen with non-default salt types.
18 # The enctypes are mostly arbitrary, though afs3 must only be used with des.
19 # We do not enforce that v4 salts must only be used with des, but it seems
20 # like a good idea.
21 salts = [('des-cbc-crc', 'afs3'),
22          ('des3-cbc-sha1', 'norealm'),
23          ('arcfour-hmac', 'onlyrealm'),
24          ('des-cbc-crc', 'v4'),
25          ('aes128-cts-hmac-sha1-96', 'special')]
26 # These enctypes are chosen to cover the different string-to-key routines.
27 # Omit ":normal" from aes256 to check that salttype defaulting works.
28 second_kstypes = ['aes256-cts-hmac-sha1-96', 'arcfour-hmac:normal',
29                   'des3-cbc-sha1:normal', 'des-cbc-crc:normal']
30
31 # Test using different salt types in a principal's key list.
32 # Parameters from one key in the list must not leak over to later ones.
33 for e1, string in salts:
34     for e2 in second_kstypes:
35         test_salt(realm, e1, string, e2)
36
37 def test_dup(realm, ks):
38     realm.run([kadminl, 'ank', '-e', ks, '-pw', 'password', 'ks_princ'])
39     out = realm.run([kadminl, 'getprinc', 'ks_princ'])
40     lines = out.split('\n')
41     keys = [l for l in lines if 'Key: ' in l]
42     uniq = set(keys)
43     # 'Key:' matches 'MKey:' as well so len(keys) has one extra
44     if (len(uniq) != len(keys)) or len(keys) > len(ks.split(',')):
45         fail('Duplicate keysalt detection failed for keysalt ' + ks)
46     realm.run([kadminl, 'delprinc', 'ks_princ'])
47
48 # All in-tree callers request duplicate suppression from
49 # krb5_string_to_keysalts(); we should check that it works, respects
50 # aliases, and doesn't result in an infinite loop.
51 dup_kstypes = ['arcfour-hmac-md5:normal,rc4-hmac:normal',
52                'aes256-cts-hmac-sha1-96:normal,aes128-cts,aes256-cts',
53                'aes256-cts-hmac-sha1-96:normal,aes256-cts:special,' +
54                'aes256-cts-hmac-sha1-96:normal']
55
56 for ks in dup_kstypes:
57     test_dup(realm, ks)
58
59 # Attempt to create a principal with a non-des enctype and the afs3 salt,
60 # verifying that the expected error is received and the principal creation
61 # fails.
62 def test_reject_afs3(realm, etype):
63     query = 'ank -e ' + etype + ':afs3 -pw password princ1'
64     realm.run([kadminl, 'ank', '-e', etype + ':afs3', '-pw', 'password',
65                'princ1'], expected_code=1,
66               expected_msg='Invalid key generation parameters from KDC')
67     realm.run([kadminl, 'getprinc', 'princ1'], expected_code=1,
68               expected_msg='Principal does not exist')
69
70 # Verify that the afs3 salt is rejected for arcfour and pbkdf2 enctypes.
71 # We do not currently do any verification on the key-generation parameters
72 # for the triple-DES enctypes, so that test is commented out.
73 test_reject_afs3(realm, 'arcfour-hmac')
74 test_reject_afs3(realm, 'aes256-cts-hmac-sha1-96')
75 #test_reject_afs3(realm, 'des3-cbc-sha1')
76
77 success("Salt types")