def krb5_asn1(principal, password, krb5_context=None): # type: (str, str, Optional[heimdal.context]) -> List[bytes] """ Generate Kerberos password hashes. :param principal: Kerberos principal name. :param password: password string. :param krb5_context: optional Kerberos context. :returns: list of ASN1 encoded Kerberos hashes. """ list = [] if isinstance(principal, unicode): principal = principal.encode('utf-8') if isinstance(password, unicode): password = password.encode('utf-8') if not krb5_context: krb5_context = heimdal.context() for krb5_etype in krb5_context.get_permitted_enctypes(): if str(krb5_etype) == 'des3-cbc-md5' and configRegistry.is_false('password/krb5/enctype/des3-cbc-md5', True): continue krb5_principal = heimdal.principal(krb5_context, principal) krb5_keyblock = heimdal.keyblock(krb5_context, krb5_etype, password, krb5_principal) krb5_salt = heimdal.salt(krb5_context, krb5_principal) list.append(heimdal.asn1_encode_key(krb5_keyblock, krb5_salt, 0)) return list
def test_creds(self): principal = heimdal.principal(self.context, USER) tkt_service = "" creds = heimdal.creds(self.context, principal, PASSWORD, tkt_service) (enctype, kvno, name, principal) = creds.parse() creds.change_password(PASSWORD)
def test_type(self): with self.assertRaises(TypeError): heimdal.principal(None, USER) with self.assertRaises(TypeError): heimdal.principal("", USER) with self.assertRaises(TypeError): heimdal.principal(object(), USER)
def test_principal(self): context = heimdal.context() before = middle = after = 0 before = sys.gettotalrefcount() principal = heimdal.principal(context, USER) middle = sys.gettotalrefcount() del principal after = sys.gettotalrefcount() self.assertGreater(middle, before) self.assertLess(after, middle) self.assertEqual(before, after)
def test_creds(self): context = heimdal.context() principal = heimdal.principal(context, USER) tkt_service = "" before = middle = after = 0 before = sys.gettotalrefcount() creds = heimdal.creds(context, principal, PASSWORD, tkt_service) middle = sys.gettotalrefcount() del creds after = sys.gettotalrefcount() self.assertGreater(middle, before) self.assertLess(after, middle) self.assertEqual(before, after)
def krb5_asn1(principal, password, krb5_context=None): list=[] if type(principal) == types.UnicodeType: principal = str( principal ) if type(password) == types.UnicodeType: password = str( password ) if not krb5_context: krb5_context = heimdal.context() for krb5_etype in krb5_context.get_permitted_enctypes(): if str(krb5_etype) == 'des3-cbc-md5' and configRegistry.is_false('password/krb5/enctype/des3-cbc-md5', True): continue krb5_principal = heimdal.principal(krb5_context, principal) krb5_keyblock = heimdal.keyblock(krb5_context, krb5_etype, password, krb5_principal) krb5_salt = heimdal.salt(krb5_context, krb5_principal) list.append(heimdal.asn1_encode_key(krb5_keyblock, krb5_salt, 0)) return list
def krb5_asn1(principal, password, krb5_context=None): list = [] if isinstance(principal, types.UnicodeType): principal = str(principal) if isinstance(password, types.UnicodeType): password = str(password) if not krb5_context: krb5_context = heimdal.context() for krb5_etype in krb5_context.get_permitted_enctypes(): if str(krb5_etype) == 'des3-cbc-md5' and configRegistry.is_false('password/krb5/enctype/des3-cbc-md5', True): continue krb5_principal = heimdal.principal(krb5_context, principal) krb5_keyblock = heimdal.keyblock(krb5_context, krb5_etype, password, krb5_principal) krb5_salt = heimdal.salt(krb5_context, krb5_principal) list.append(heimdal.asn1_encode_key(krb5_keyblock, krb5_salt, 0)) return list
def setUp(self): self.context = heimdal.context() self.principal = heimdal.principal(self.context, USER) self.ccache = heimdal.ccache(self.context)
def setUp(self): self.context = heimdal.context() self.enctype = heimdal.enctype(self.context, ENCSTR) self.principal = heimdal.principal(self.context, USER)
def test_salt(self): principal = heimdal.principal(self.context, USER) salt = heimdal.salt(self.context, principal) self.assertEqual(self.VALUE, salt.saltvalue())
def setUp(self): context = heimdal.context() principal = heimdal.principal(context, USER) tkt_service = "" self.creds = heimdal.creds(self.context, principal, PASSWORD, tkt_service)
def setUp(self): context = heimdal.context() self.principal = heimdal.principal(context, USER)