return self._functional_level
- def get_default_enctypes(self):
+ def get_default_enctypes(self, creds):
+ self.assertIsNotNone(creds, 'expected client creds to be passed in')
+
functional_level = self.get_domain_functional_level()
default_enctypes = []
default_enctypes.append(kcrypto.Enctype.AES256)
default_enctypes.append(kcrypto.Enctype.AES128)
- # RC4 should always be supported
- default_enctypes.append(kcrypto.Enctype.RC4)
+ if self.expect_nt_hash or creds.get_workstation():
+ default_enctypes.append(kcrypto.Enctype.RC4)
return default_enctypes
return bind, identifier, attributes
- def get_keys(self, dn, expected_etypes=None):
+ def get_keys(self, creds, expected_etypes=None):
admin_creds = self.get_admin_creds()
samdb = self.get_samdb()
+ dn = creds.get_dn()
+
bind, identifier, attributes = self.get_secrets(
str(dn),
destination_dsa_guid=misc.GUID(samdb.get_ntds_GUID()),
keys[kcrypto.Enctype.RC4] = pwd.hex()
if expected_etypes is None:
- expected_etypes = self.get_default_enctypes()
+ expected_etypes = self.get_default_enctypes(creds)
self.assertCountEqual(expected_etypes, keys)
fast_support=False,
claims_support=False,
compound_id_support=False):
- default_enctypes = self.get_default_enctypes()
+ default_enctypes = self.get_default_enctypes(creds)
supported_enctypes = KerberosCredentials.etypes_to_bits(
default_enctypes)
expected_etypes = None
if force_nt4_hash:
expected_etypes = {kcrypto.Enctype.RC4}
- keys = self.get_keys(dn, expected_etypes=expected_etypes)
+ keys = self.get_keys(creds, expected_etypes=expected_etypes)
self.creds_set_keys(creds, keys)
# Handle secret replication to the RODC.
creds.set_kvno(rodc_kvno)
creds.set_dn(krbtgt_dn)
- keys = self.get_keys(krbtgt_dn)
+ keys = self.get_keys(creds)
self.creds_set_keys(creds, keys)
# The RODC krbtgt account should support the default enctypes,
creds.set_kvno(rodc_kvno)
creds.set_dn(dn)
- keys = self.get_keys(dn)
+ keys = self.get_keys(creds)
self.creds_set_keys(creds, keys)
if self.get_domain_functional_level() >= DS_DOMAIN_FUNCTION_2008:
creds.set_kvno(kvno)
creds.set_dn(dn)
- keys = self.get_keys(dn)
+ keys = self.get_keys(creds)
self.creds_set_keys(creds, keys)
# The krbtgt account should support the default enctypes, although
creds.set_workstation(username[:-1])
creds.set_dn(dn)
- keys = self.get_keys(dn)
+ keys = self.get_keys(creds)
self.creds_set_keys(creds, keys)
if self.get_domain_functional_level() >= DS_DOMAIN_FUNCTION_2008:
creds.set_kvno(kvno)
creds.set_dn(dn)
- keys = self.get_keys(dn)
+ keys = self.get_keys(creds)
self.creds_set_keys(creds, keys)
if self.get_domain_functional_level() >= DS_DOMAIN_FUNCTION_2008:
salt = creds.get_salt()
- etype = self.get_default_enctypes()
+ etype = self.get_default_enctypes(creds)
cname = self.PrincipalName_create(name_type=client_name_type,
names=user_name.split('/'))
if sname is None:
lm_verifier=None)
num, _ = err.exception.args
- if protected:
+ if not self.expect_nt_hash:
+ self.assertEqual(ntstatus.NT_STATUS_NTLM_BLOCKED, num)
+ elif protected:
self.assertEqual(ntstatus.NT_STATUS_ACCOUNT_RESTRICTION, num)
else:
self.assertEqual(ntstatus.NT_STATUS_WRONG_PASSWORD, num)
password3=None)
num, _ = err.exception.args
- if protected:
+ if not self.expect_nt_hash:
+ self.assertEqual(ntstatus.NT_STATUS_NTLM_BLOCKED, num)
+ elif protected:
self.assertEqual(ntstatus.NT_STATUS_ACCOUNT_RESTRICTION, num)
else:
self.assertEqual(ntstatus.NT_STATUS_WRONG_PASSWORD, num)
validation_level,
netr_flags))
except NTSTATUSError as err:
- self.assertTrue(protected, 'got unexpected error')
-
num, _ = err.args
- if num != ntstatus.NT_STATUS_ACCOUNT_RESTRICTION:
- raise
+ if protected:
+ if num != ntstatus.NT_STATUS_ACCOUNT_RESTRICTION:
+ raise
+ else:
+ self.assertFalse(self.expect_nt_hash, 'got unexpected error')
+ if num != ntstatus.NT_STATUS_NTLM_BLOCKED:
+ raise
else:
self.assertFalse(protected, 'expected error')
+ self.assertTrue(self.expect_nt_hash, 'expected error')
self.assertEqual(1, authoritative)
self.assertEqual(0, flags)
forced_rc4 = '0'
cls.forced_rc4 = bool(int(forced_rc4))
+ expect_nt_hash = samba.tests.env_get_var_value('EXPECT_NT_HASH',
+ allow_missing=True)
+ if expect_nt_hash is None:
+ expect_nt_hash = '1'
+ cls.expect_nt_hash = bool(int(expect_nt_hash))
+
def setUp(self):
super().setUp()
self.do_asn1_print = False
return c
# Overridden by KDCBaseTest. At this level we don't know what actual
- # enctypes are supported, so assume they all are. This matches the
- # behaviour that tests expect by default.
- def get_default_enctypes(self):
- return [
+ # enctypes are supported, so the best we can do is go by whether NT hashes
+ # are expected and whether the account is a workstation or not. This
+ # matches the behaviour that tests expect by default.
+ def get_default_enctypes(self, creds):
+ self.assertIsNotNone(creds)
+
+ default_enctypes = [
kcrypto.Enctype.AES256,
kcrypto.Enctype.AES128,
- kcrypto.Enctype.RC4,
]
+ if self.expect_nt_hash or creds.get_workstation():
+ default_enctypes.append(kcrypto.Enctype.RC4)
+
+ return default_enctypes
+
def asn1_dump(self, name, obj, asn1_print=None):
if asn1_print is None:
asn1_print = self.do_asn1_print
return max(filter(lambda e: e in etypes, proposed_etypes),
default=None)
- supported_etypes = self.get_default_enctypes()
+ creds = kdc_exchange_dict['creds']
+ supported_etypes = self.get_default_enctypes(creds)
aes_etypes = set()
if kcrypto.Enctype.AES256 in supported_etypes: