�
�
5Xc@s�dZddlZddlZeje�ZddlmZddlm Z m
Z
mZddlm
Z
mZddlmZmZmZmZmZddlmZddljjZdd d
dgZdZd
�Zd�Zd�Zd�Z dej!ej"ej#ej$fd��YZ%d ej"ej&ej#ej$fd��YZ'd
ej#ej$fd��YZ(dej!ej#ej$fd��YZ)dS(sFpasslib.handlers.des_crypt - traditional unix (DES) crypt and variantsi����N(twarn(t
safe_cryptt
test_cryptt
to_unicode(th64th64big(tbyte_elem_valuetut
uascii_to_strtunicodetsuppress_cause(tdes_encrypt_int_blockt des_cryptt
bsdi_crypttbigcrypttcrypt16tcCstd�t|d �D��S(s�convert secret to 64-bit DES key.
this only uses the first 8 bytes of the secret,
and discards the high 8th bit of each byte at that.
a null parity bit is inserted after every 7th bit of the output.
css1|]'\}}t|�d@d|d>VqdS(ii9iN(R(t.0titc((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pys <genexpr>(si(tsumt enumerate(tsecret((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_crypt_secret_to_keys cCstj|�}t|t�r0|jd�}nt|krQtjjt ��nt
|�}t|d|d�}tj
|�S(s pure-python backed for des_cryptsutf-8ii(Rtdecode_int12t
isinstanceR tencodet_BNULLtuhtexctNullPasswordErrorRRRRtencode_int64(Rtsaltt
salt_valuet key_valuetresult((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_raw_des_crypt+s
cCskt|�}d}t|�}xF||krf|d}t|||!�}t||�|A}|}q!W|S(s,convert secret to DES key used by bsdi_crypti(RtlenR(RR"tidxtendtnextt tmp_value((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_bsdi_secret_to_keyIs
cCstj|�}t|t�r0|jd�}nt|krQtjjt ��nt
|�}t|d||�}tj
|�S(s"pure-python backend for bsdi_cryptsutf-8i(Rtdecode_int24RR RRRRRR
R*RRR(RtroundsR R!R"R#((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_raw_bsdi_cryptUscBs�eZdZdZdZejZdZdZ Z
ejZdZe
jed�e
je
jB�Zed��Zd �Zd
�ZdZed
��Zd�Zed��Zd�ZRS(s�This class implements the des-crypt password hash, and follows the :ref:`password-hash-api`.
It supports a fixed-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 2 characters, drawn from the regexp range ``[./0-9A-Za-z]``.
:param bool truncate_error:
By default, des_crypt will silently truncate passwords larger than 8 bytes.
Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.
.. versionadded:: 1.7
: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
RR ttruncate_erroriiisU
^
(?P<salt>[./a-z0-9]{2})
(?P<chk>[./a-z0-9]{11})?
$cCs@t|dd�}|d |d}}|d|d|p<d�S(NtasciithashiR tchecksum(RtNone(tclsR0R tchk((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pytfrom_string�scCs&td�|j|jf}t|�S(Ns%s%s(RR R1R(tselfR0((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt to_string�scCs&|jr|j|�n|j|�S(N(tuse_defaultst_check_truncate_policyt_calc_checksum_backend(R6R((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_calc_checksum�s tos_crypttbuiltincCs+tdd�r#|j|j�tStSdS(Nttestt
abgOeLfPimXQo(Rt_set_calc_checksum_backendt_calc_checksum_os_crypttTruetFalse(R3((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_load_backend_os_crypt�scCs1t||j�}|r |dS|j|�SdS(Ni(RR t_calc_checksum_builtin(R6RR0((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRA�scCs|j|j�tS(N(R@RERB(R3((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt_load_backend_builtin�scCs"t||jjd��jd�S(NR/(R$R Rtdecode(R6R((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRE�s(ssaltR.(R<R=(t__name__t
__module__t__doc__tnametsetting_kwdsRtHASH64_CHARStchecksum_charst
checksum_sizet
min_salt_sizet
max_salt_sizet
salt_charst
truncate_sizetretcompileRtXtIt_hash_regextclassmethodR5R7R;tbackendsRDRARFRE(((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRps$
cBs�eZdZdZdZdZejZdZ Z
ejZdZdZ
dZd Zejed
�ejejB�Zed��Zd�ZeZed
��Zed��Zd�ZdZed��Zd�Z ed��Z!d�Z"RS(s
This class implements the BSDi-Crypt password hash, and follows the :ref:`password-hash-api`.
It supports a fixed-length salt, and a variable number of rounds.
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 4 characters, drawn from the regexp range ``[./0-9A-Za-z]``.
:type rounds: int
:param rounds:
Optional number of rounds to use.
Defaults to 5001, must be between 1 and 16777215, inclusive.
: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 ``rounds``
that are too small or too large, and ``salt`` strings that are too long.
.. versionadded:: 1.6
.. versionchanged:: 1.6
:meth:`hash` will now issue a warning if an even number of rounds is used
(see :ref:`bsdi-crypt-security-issues` regarding weak DES keys).
R
R R,iii�ii���tlinears�
^
_
(?P<rounds>[./a-z0-9]{4})
(?P<salt>[./a-z0-9]{4})
(?P<chk>[./a-z0-9]{11})?
$cCs�t|dd�}|jj|�}|s?tjj|��n|jddd�\}}}|dtj|j d��d|d|�S(NR/R0R,R R4R1(
RRXtmatchRRtInvalidHashErrortgroupRR+R(R3R0tmR,R R4((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR54scCs>td�tj|j�jd�|j|jf}t|�S(Ns_%s%s%sR/(RRtencode_int24R,RGR R1R(R6R0((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR7As!cKs?tt|�j|�}|jd@s;tdtjj�n|S(NisHbsdi_crypt rounds should be odd, as even rounds may reveal weak DES keys(tsuperR
tusingtdefault_roundsRRRtPasslibSecurityWarning(R3tkwdstsubcls((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRbNs
cCstt|�j�}|dBS(Ni(RaR
t_generate_rounds(R3R,((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRgWscKs'|jd@stStt|�j|�S(Ni(R,RBRaR
t_calc_needs_update(R6Re((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRhes
R<R=cCs+tdd�r#|j|j�tStSdS(NR>s_/...lLDAxARksGCHin.(RR@RARBRC(R3((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRDtscCs:|j�}t||�}|r)|dS|j|�SdS(Ni����(R7RRE(R6RtconfigR0((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRA|s
cCs|j|j�tS(N(R@RERB(R3((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRF�scCs(t||j|jjd��jd�S(NR/(R-R,R RRG(R6R((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRE�s(ssaltsrounds(sos_cryptsbuiltin(#RHRIRJRKRLRORRMRNRPRQRRRct
min_roundst
max_roundstrounds_costRTRURRVRWRXRYR5R7RBt_avoid_even_roundsRbRgRhRZRDRARFRE(((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR
�s0
cBs�eZdZdZd ZejZdZZ ejZ
eje
d�ejejB�Zed��Zd�Zed�Zd�ZRS(
sgThis class implements the BigCrypt password hash, and follows the :ref:`password-hash-api`.
It supports a fixed-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 22 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
RR isX
^
(?P<salt>[./a-z0-9]{2})
(?P<chk>([./a-z0-9]{11})+)?
$cCsjt|dd�}|jj|�}|s?tjj|��n|jdd�\}}|d|d|�S(NR/R0R R4R1(RRXR\RRR]R^(R3R0R_R R4((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR5�scCs&td�|j|jf}t|�S(Ns%s%s(RR R1R(R6R0((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR7�scCsGtt|�j|d|�}t|�drCtjj|��n|S(Ntrelaxedi(RaRt_norm_checksumR%RRR](R6R1Rn((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyRo�scCs�t|t�r!|jd�}nt||jjd��}d}t|�}xA||kr�|d}|t|||!|dd!�7}|}qQW|jd�S(Nsutf-8R/ii����i����(RR RR$R R%RG(R6RR4R&R'R(((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR;�s
!
(ssalt(RHRIRJRKRLRRMRNRPRQRRRTRURRVRWRXRYR5R7RCRoR;(((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR�s
cBs�eZdZdZdZdZejZdZ Z
ejZdZe
jed�e
je
jB�Zed��Zd �Zd
�ZRS(s�This class implements the crypt16 password hash, and follows the :ref:`password-hash-api`.
It supports a fixed-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 2 characters, drawn from the regexp range ``[./0-9A-Za-z]``.
:param bool truncate_error:
By default, crypt16 will silently truncate passwords larger than 16 bytes.
Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.
.. versionadded:: 1.7
: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
RR R.iiisU
^
(?P<salt>[./a-z0-9]{2})
(?P<chk>[./a-z0-9]{22})?
$cCsjt|dd�}|jj|�}|s?tjj|��n|jdd�\}}|d|d|�S(NR/R0R R4R1(RRXR\RRR]R^(R3R0R_R R4((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR5+scCs&td�|j|jf}t|�S(Ns%s%s(RR R1R(R6R0((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR74scCs�t|t�r!|jd�}n|jr:|j|�nytj|jjd��}Wn#tk
r~t td���nXt
|�}t|d|d�}t
|dd!�}t|d|d�}tj
|�tj
|�}|jd�S( Nsutf-8R/sinvalid chars in saltiiiii(RR RR8R9RRR t
ValueErrorR
RRRRRG(R6RR!tkey1tresult1tkey2tresult2R4((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR;;s
(ssaltstruncate_error(RHRIRJRKRLRORRMRNRPRQRRRSRTRURRVRWRXRYR5R7R;(((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyR�s
(*RJRTtloggingt getLoggerRHtlogtwarningsRt
passlib.utilsRRRtpasslib.utils.binaryRRtpasslib.utils.compatRRRR R
tpasslib.crypto.desRtpasslib.utils.handlerstutilsthandlersRt__all__RRR$R*R-t
TruncateMixintHasManyBackendstHasSalttGenericHandlerRt HasRoundsR
RR(((s>/usr/lib/python2.7/site-packages/passlib/handlers/des_crypt.pyt<module>s,( +�+�S |