ó Ÿ;Xc@sOdZddlmZddlZejeƒZddlmZm Z m Z ddl m Z ddl mZmZddljjZddgZd Zd Zd Zd!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5fZd6Zed„Zdejejfd„ƒYZdejefd„ƒYZ defd „ƒYZ!dS(7s0passlib.handlers.md5_crypt - md5-crypt algorithmiÿÿÿÿ(tmd5N(t safe_cryptt test_cryptt repeat_string(th64(tunicodetut md5_cryptt apr_md5_cryptts$1$s$apr1$iiiiiii ii iiiii i i cCs|t|tƒr!|jdƒ}nt|tƒs<tdƒ‚t|kr]tjjt ƒ‚nt |ƒ}t|tƒs„tdƒ‚|jdƒ}t |ƒdks±tdƒ‚|rÀt }nt }t |||ƒjƒ}t |||ƒ}|j}|t||ƒƒ|}|d } x.|rP||d@r<tn| ƒ|dL}q#W|jƒ} ||} ||} || | | ||||| g} gtD] \}}| || |f^qœ}| }d}xQ|r!x:|D]2\}}t |t ||ƒjƒƒjƒ}qÞW|d8}qÑWx>|d D]2\}}t |t ||ƒjƒƒjƒ}q-Wtj|tƒjdƒS( s†perform 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 sutf-8spwd not unicode or bytesssalt not unicodetasciii ssalt too largeiii(t isinstanceRtencodetbytestAssertionErrort_BNULLtuhtexctNullPasswordErrorRtlent _APR_MAGICt _MD5_MAGICRtdigesttupdateRt_c_digest_offsetsRtencode_transposed_bytest_transpose_maptdecode(tpwdtsalttuse_aprtpwd_lentmagictdbta_ctxt a_ctx_updatetitevenchartdatpwd_pwdtpwd_salttpermsteventoddtdatatdctblocks((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_raw_md5_crypt,sF       .  $- **t _MD5_CommoncBsJeZdZdZdZejZdZejZ e d„ƒZ d„Z RS(s+common code for md5_crypt and apr_md5_cryptRt salt_sizeiicCs4tj||jd|ƒ\}}|d|d|ƒS(NthandlerRtchecksum(Rt parse_mc2tident(tclsthashRtchk((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt from_stringÒs!cCstj|j|j|jƒS(N(Rt render_mc2R5RR3(tself((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt to_string×s(ssaltR1( t__name__t __module__t__doc__t setting_kwdst checksum_sizeRt HASH64_CHARStchecksum_charst max_salt_sizet salt_charst classmethodR9R<(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyR0Às  cBsVeZdZdZedƒZd Zed„ƒZd„Z ed„ƒZ d„Z RS( s•This 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 Rs$1$tos_crypttbuiltincCs+tddƒr#|j|jƒtStSdS(Nttests$1$test$pi/xDtU5WFVRqYS6BMU8X/(Rt_set_calc_checksum_backendt_calc_checksum_os_crypttTruetFalse(R6((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_load_backend_os_cryptscCso|j|j}t||ƒ}|r^|j|ƒrPt|ƒt|ƒdksVt‚|dS|j|ƒSdS(Niiêÿÿÿ(R5RRt startswithRRt_calc_checksum_builtin(R;tsecrettconfigR7((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyRKs 1cCs|j|jƒtS(N(RJRPRL(R6((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_load_backend_builtin%scCst||jƒS(N(R/R(R;RQ((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyRP*s(RGRH( R=R>R?tnameRR5tbackendsRFRNRKRSRP(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyRàs  cBs)eZdZdZedƒZd„ZRS(spThis 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 Rs$apr1$cCst||jdtƒS(NR(R/RRL(R;RQ((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_calc_checksumQs(R=R>R?RTRR5RV(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyR1s (ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(i iii iiiiiii iii ii ("R?thashlibRtloggingt getLoggerR=tlogt passlib.utilsRRRtpasslib.utils.binaryRtpasslib.utils.compatRRtpasslib.utils.handlerstutilsthandlersRt__all__RRRRRRMR/tHasSalttGenericHandlerR0tHasManyBackendsRR(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyts(    ” Q