a fWc5@sdZddlmZddlZeeZddlmZm Z m Z ddl m Z ddl mZmZddlmmZddgZd Zd Zd Zd Zd ZdddZGdddejejZGdddejeZGdddeZ dS)z0passlib.handlers.md5_crypt - md5-crypt algorithm)md5N) safe_crypt test_crypt repeat_string)h64)unicodeu md5_crypt apr_md5_crypts$1$s$apr1$))rrr )rr rrr )rrr)rrrrr )rr rr )rrrr r) r rr r r r Fcst|tr|d}t|vr(tjtt|}|d}|rDt }nt }t ||| }t |||}|j }|t|||}|dd} |r||d@rtn| |dL}q| } ||} ||} || | | ||||| gfddtD} | }d}|r>| D]&\}}t |t ||  }q |d8}q| ddD]&\}}t |t ||  }qJt|tdS) aperform raw md5-crypt calculation this function provides a pure-python implementation of the internals for the MD5-Crypt algorithms; it doesn't handle any of the parsing/validation of the hash strings themselves. :arg pwd: password chars/bytes to hash :arg salt: salt chars to use :arg use_apr: use apache variant :returns: encoded checksum chars zutf-8asciiNrcs g|]\}}||fqSr).0evenoddZpermsr>/usr/lib/python3.9/site-packages/passlib/handlers/md5_crypt.py z"_raw_md5_crypt..) isinstancerencode_BNULLuhexcZNullPasswordErrorr len _APR_MAGIC _MD5_MAGICrdigestupdater_c_digest_offsetsrZencode_transposed_bytes_transpose_mapdecode)pwdsaltuse_aprZpwd_lenmagicZdbZa_ctxZ a_ctx_updateiZevenchardaZpwd_pwdZpwd_saltdataZdcZblocksr!r"rr#r$_raw_md5_crypt,s@      .    r=c@s<eZdZdZdZdZejZdZ ejZ e ddZ ddZ d S) _MD5_Commonz+common code for md5_crypt and apr_md5_crypt)r7Z salt_sizercCs"tj||j|d\}}|||dS)N)Zhandler)r7checksum)r,Z parse_mc2ident)clshashr7Zchkrrr$ from_stringsz_MD5_Common.from_stringcCst|j|j|jSN)r,Z render_mc2rAr7r@)selfrrr$ to_stringsz_MD5_Common.to_stringN)__name__ __module__ __qualname____doc__Z setting_kwdsZ checksum_sizer,Z HASH64_CHARSZchecksum_charsZ max_salt_sizeZ salt_chars classmethodrDrGrrrr$r>s r>c@sHeZdZdZdZedZdZeddZ ddZ edd Z d d Z d S) r aThis class implements the MD5-Crypt password hash, and follows the :ref:`password-hash-api`. It supports a variable-length salt. The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords: :type salt: str :param salt: Optional salt string. If not specified, one will be autogenerated (this is recommended). If specified, it must be 0-8 characters, drawn from the regexp range ``[./0-9A-Za-z]``. :type salt_size: int :param salt_size: Optional number of characters to use when autogenerating new salts. Defaults to 8, but can be any value between 0 and 8. (This is mainly needed when generating Cisco-compatible hashes, which require ``salt_size=4``). :type relaxed: bool :param relaxed: By default, providing an invalid value for one of the other keywords will result in a :exc:`ValueError`. If ``relaxed=True``, and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning` will be issued instead. Correctable errors include ``salt`` strings that are too long. .. versionadded:: 1.6 z$1$)Zos_cryptZbuiltincCs"tddr||jdSdSdS)Ntestz$1$test$pi/xDtU5WFVRqYS6BMU8X/TF)r_set_calc_checksum_backend_calc_checksum_os_cryptrBrrr$_load_backend_os_crypts  z md5_crypt._load_backend_os_cryptcCsb|j|j}t||}|dur(||S||rFt|t|dkrVtj||||ddS)Nr'i) rAr7r_calc_checksum_builtin startswithr.r,r-ZCryptBackendError)rFsecretZconfigrCrrr$rOs   z!md5_crypt._calc_checksum_os_cryptcCs||jdS)NT)rNrRrPrrr$_load_backend_builtin%s zmd5_crypt._load_backend_builtincCs t||jSrEr=r7rFrTrrr$rR*sz md5_crypt._calc_checksum_builtinN) rHrIrJrKnamerrAZbackendsrLrQrOrUrRrrrr$r s   c@s$eZdZdZdZedZddZdS)r apThis class implements the Apr-MD5-Crypt password hash, and follows the :ref:`password-hash-api`. It supports a variable-length salt. The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords: :type salt: str :param salt: Optional salt string. If not specified, one will be autogenerated (this is recommended). If specified, it must be 0-8 characters, drawn from the regexp range ``[./0-9A-Za-z]``. :type relaxed: bool :param relaxed: By default, providing an invalid value for one of the other keywords will result in a :exc:`ValueError`. If ``relaxed=True``, and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning` will be issued instead. Correctable errors include ``salt`` strings that are too long. .. versionadded:: 1.6 z$apr1$cCst||jddS)NT)r8rVrWrrr$_calc_checksumQszapr_md5_crypt._calc_checksumN)rHrIrJrKrXrrArYrrrr$r 1s)F)!rKZhashlibrZloggingZ getLoggerrHlogZ passlib.utilsrrrZpasslib.utils.binaryrZpasslib.utils.compatrrZpasslib.utils.handlersZutilshandlersr,__all__r+r0r/r3r4r=ZHasSaltZGenericHandlerr>ZHasManyBackendsr r rrrr$s&     Q