a fWcMOO@sdZddlZddlZeeZddlmZddlm Z ddl m Z m Z ddl mZddlmZmZmZddlmZdd lmZgd ZGd d d eZeZeZejZe d dddddddddddddddddddddddddddddddddddddddddddddddddddd dddddddddddddddddd d!d"d"d#ddd$MZ!e"d%Z#e$gd&Z%d'd(Z&d)d*Z'dCd,d-Z(efd.d/Z)dDd0d1Z*dEd2d3Z+dFd5d6Z,dGd8d9Z-d:Z.d;Z/dZ1ed?d@Z2dAdBZ3dS)Hz6passlib.registry - registry for password hash handlersN)warn)exc)ExpectedTypeErrorPasslibWarning) PasswordHash)is_crypt_handler has_cryptunix_crypt_schemes)unicode_or_str)memoize_single_value)register_crypt_handler_pathregister_crypt_handlerget_crypt_handlerlist_crypt_handlersc@s8eZdZdZdZdZddZddZdd Zd d ZdS) _PasslibRegistryProxyzproxy module passlib.hash this module is in fact an object which lazy-loads the requested password hash algorithm from wherever it has been stored. it acts as a thin wrapper around :func:`passlib.registry.get_crypt_handler`. z passlib.hashNcCs<|drtd|ft|d}|r*|Std|fdS)N_zmissing attribute: %rzunknown password hash: %r) startswithAttributeErrorr)selfattrhandlerr4/usr/lib/python3.9/site-packages/passlib/registry.py __getattr__(s   z!_PasslibRegistryProxy.__getattr__cCs*|drt|||n t||ddS)Nr_attr)robject __setattr__r )rrvaluerrrr1s z!_PasslibRegistryProxy.__setattr__cCsdS)Nzr)rrrr__repr__;sz_PasslibRegistryProxy.__repr__cCs,tt|j}||j|tt|SN)setdir __class__update__dict__ _locationssorted)rattrsrrr__dir__>s  z_PasslibRegistryProxy.__dir__) __name__ __module__ __qualname____doc__ __package__rrrr)rrrrrs  rzpasslib.handlers.md5_cryptzpasslib.handlers.argon2zpasslib.handlers.pbkdf2zpasslib.handlers.bcryptzpasslib.handlers.des_cryptzpasslib.handlers.windowszpasslib.handlers.ciscozpasslib.handlers.djangozpasslib.handlers.fshpzpasslib.handlers.digestszpasslib.handlers.ldap_digestszpasslib.handlers.roundupzpasslib.handlers.mssqlzpasslib.handlers.mysqlzpasslib.handlers.oraclezpasslib.handlers.phpasszpasslib.handlers.misczpasslib.handlers.postgreszpasslib.handlers.scramzpasslib.handlers.scryptzpasslib.handlers.sha1_cryptzpasslib.handlers.sha2_cryptzpasslib.handlers.sun_md5_crypt)MZ apr_md5_cryptZargon2Zatlassian_pbkdf2_sha1ZbcryptZ bcrypt_sha256ZbigcryptZ bsd_nthashZ bsdi_cryptZ cisco_pixZ cisco_asaZ cisco_type7Zcta_pbkdf2_sha1Zcrypt16Z des_cryptZ django_argon2Z django_bcryptZdjango_bcrypt_sha256Zdjango_pbkdf2_sha256Zdjango_pbkdf2_sha1Zdjango_salted_sha1Zdjango_salted_md5Zdjango_des_cryptZdjango_disabledZdlitz_pbkdf2_sha1ZfshpZgrub_pbkdf2_sha512Zhex_md4Zhex_md5Zhex_sha1Z hex_sha256Z hex_sha512ZhtdigestZldap_plaintextZldap_md5Z ldap_sha1Z ldap_hex_md5Z ldap_hex_sha1Zldap_salted_md5Zldap_salted_sha1Zldap_salted_sha256Zldap_salted_sha512Zldap_des_cryptZldap_bsdi_cryptZldap_md5_cryptZ ldap_bcryptZldap_sha1_cryptZldap_sha256_cryptZldap_sha512_cryptZldap_pbkdf2_sha1Zldap_pbkdf2_sha256Zldap_pbkdf2_sha512ZlmhashZ md5_cryptZmsdccZmsdcc2Z mssql2000Z mssql2005Zmysql323Zmysql41ZnthashZoracle10Zoracle11Z pbkdf2_sha1Z pbkdf2_sha256Z pbkdf2_sha512ZphpassZ plaintextZ postgres_md5Zroundup_plaintextZscramscryptZ sha1_cryptZ sha256_cryptZ sha512_cryptZ sun_md5_cryptZ unix_disabledZ unix_fallbackz^[a-z][a-z0-9_]+[a-z0-9]$)ZonloadZpolicycontextalldefaultZnoneautocCst|std|f||kr,td|ft|sDtd|fd|vrZtd|f|tvrptd|fdS)zhelper to validate handler name :raises ValueError: * if empty name * if name not lower case * if name contains double underscores * if name is reserved (e.g. ``context``, ``all``). z handler name cannot be empty: %rzname must be lower-case: %rz`invalid name (must be 3+ characters, begin with a-z, and contain only underscore, a-z, 0-9): %r__z+name may not contain double-underscores: %rzthat name is not allowed: %rT) ValueErrorlower_name_rematch_forbidden_names)namerrr_validate_handler_names   r;cCspt||drtdd|vrV|ddkr8td|d|ddkrVtd|t|<td||d S) avregister location to lazy-load handler when requested. custom hashes may be registered via :func:`register_crypt_handler`, or they may be registered by this function, which will delay actually importing and loading the handler until a call to :func:`get_crypt_handler` is made for the specified name. :arg name: name of handler :arg path: module import path the specified module path should contain a password hash handler called :samp:`{name}`, or the path may contain a colon, specifying the module and module attribute to use. for example, the following would cause ``get_handler("myhash")`` to look for a class named ``myhash`` within the ``myapp.helpers`` module:: >>> from passlib.registry import registry_crypt_handler_path >>> registry_crypt_handler_path("myhash", "myapp.helpers") ...while this form would cause ``get_handler("myhash")`` to look for a class name ``MyHash`` within the ``myapp.helpers`` module:: >>> from passlib.registry import registry_crypt_handler_path >>> registry_crypt_handler_path("myhash", "myapp.helpers:MyHash") .zpath cannot start with '.':z"path cannot have more than one ':'z$path cannot have '.' to right of ':'z!registered path to %r handler: %rN) r;rr5countfindindexr&logdebug)r:pathrrrr s r FcCst|st|dd|s td|j}t||rJ||krJtd||ft|}|r||urrt d||dS|rt d||nt d||f|t|<t d ||dS) a@register password hash handler. this method immediately registers a handler with the internal passlib registry, so that it will be returned by :func:`get_crypt_handler` when requested. :arg handler: the password hash handler to register :param force: force override of existing handler (defaults to False) :param _attr: [internal kwd] if specified, ensures ``handler.name`` matches this value, or raises :exc:`ValueError`. :raises TypeError: if the specified object does not appear to be a valid handler. :raises ValueError: if the specified object's name (or other required attributes) contain invalid values. :raises KeyError: if a (different) handler was already registered with the same name, and ``force=True`` was not specified. zpassword hash handlerrz``bool(handler)`` must be Truez %r) stacklevelr=r)fromlistlevelrz(no crypt handler found for algorithm: %rN)r_UNSETrIrGreplacer6rrr&rHsplit __import__getattrr )r:r2ZaltrEmodnameZmodattrmodrrrrr*sH           rcCs(tt}|s|ttdd|DS)zreturn sorted list of all known crypt handler names. :param loaded_only: if ``True``, only returns names of handlers which have actually been loaded. :returns: list of names of all known handlers css|]}|ds|VqdS)rN)r.0r:rrr z&list_crypt_handlers..)r!rGr$r&r') loaded_onlynamesrrrrus rcCs|tvp| o|tvS)aAcheck if handler name is known. this is only useful for two cases: * quickly checking if handler has already been loaded * checking if handler exists, without actually loading it :arg name: name of handler :param loaded_only: if ``True``, returns False if handler exists but hasn't been loaded rGr&)r:r\rrr_has_crypt_handlers r_TcCs$|tvrt|=|r |tvr t|=dS)aunloads a handler from the registry. .. warning:: this is an internal function, used only by the unittests. if loaded handler is found with specified name, it's removed. if path to lazy load handler is found, it's removed. missing names are a noop. :arg name: name of handler to unload :param locations: if False, won't purge registered handler locations (default True) Nr^)r:Z locationsrrr_unload_handler_names r`rcCs0t|r |St|trt|St|t|dS)z> internal helper to resolve argument to hasher object N)r isinstancer rrr)hasherZparamrrr_resolves  rcanyZbuiltinZos_cryptcCst|}|tkrDt|dsdSz|WdStjyBYdS0t|drj|r`||jvr`dS||S|tkrvdS|r~dSt ||dS)a Test if specified backend is available for hasher. :param hasher: Hasher name or object. :param backend: Name of backend, or ``"any"`` if any backend will do. For hashers without multiple backends, will pretend they have a single backend named ``"builtin"``. :param safe: By default, throws error if backend is unknown. If ``safe=True``, will just return false value. :raises ValueError: * if hasher name is unknown. * if backend is unknown to hasher, and safe=False. :return: True if backend available, False if not available, and None if unknown + safe=True. get_backendTF has_backendN) rcANYhasattrrerZMissingBackendErrorZbackendsrfBUILTINZUnknownBackendError)rbZbackendsaferrrrfs$   rfcCsFtsdStddtD}|sBddl}td||ftj|S)zN return tuple of schemes which :func:`crypt.crypt` natively supports. rcss |]}t|tr|VqdSr )rrfOS_CRYPTrXrrrrZsz1get_supported_os_crypt_schemes..rNzkcrypt.crypt() function is present, but doesn't support any formats known to passlib! (system=%r release=%r)) os_crypt_presenttupleos_crypt_schemesplatformrsystemreleaserZPasslibRuntimeWarning)cacherorrrget_supported_os_crypt_schemessrscCstot|tddS)a check if hash is supported by native :func:`crypt.crypt` function. if :func:`crypt.crypt` is not present, will always return False. :param hasher: name or hasher object. :returns bool: True if hash format is supported by OS, else False. T)rj)rlrfrk)rbrrrhas_os_crypt_supports rt)FN)F)F)T)r)4r-reZloggingZ getLoggerr*rCwarningsrZpasslibrZ passlib.excrrZ passlib.ifcrZ passlib.utilsrrrlr rnZpasslib.utils.compatr Zpasslib.utils.decorr __all__rr_proxyrQr%rGdictr&compiler7 frozensetr9r;r r rrr_r`rcrgrirkrfrsrtrrrrs      )S  * 5 K   >