�
�;Xc@sOdZddlmZddlZeje�ZddlmZm Z m
Z
ddlmZddl
mZmZddljjZddgZd Zd
ZdZd!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$iiiiiiiii
iiiii i
icCs|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_ctxta_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��Zd�ZRS(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.pytfrom_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__tsetting_kwdst
checksum_sizeRtHASH64_CHARStchecksum_charst
max_salt_sizet
salt_charstclassmethodR9R<(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyR0�s cBsVeZdZdZed�Zd Zed��Zd�Z ed��Z
d�ZRS(
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.pyRKs1cCs|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(iiii
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.pyt<module>s( � Q |