Current File : //usr/lib/python2.7/site-packages/passlib/handlers/windows.pyc
�
�
5Xc	@sQdZddlmZddlZeje�ZddlmZddl	m
Z
mZddlm
Z
ddlmZed�jZddljjZd	d
ddd
gZd	ejejejfd��YZd
ejfd��YZejdedddddd�Zdejejfd��YZd
ejejfd��YZ dS(s;passlib.handlers.nthash - Microsoft Windows -related hashesi����(thexlifyN(twarn(t
to_unicodetright_pad_string(tunicode(tlookup_hashtmd4tlmhashtnthasht
bsd_nthashtmsdcctmsdcc2cBseeZdZdZd
ZejZdZdZ	dZ
ed��Zd�Z
dZedd	��ZRS(s�This class implements the Lan Manager Password hash, and follows the :ref:`password-hash-api`.

    It has no salt and a single fixed round.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts a single
    optional keyword:

    :param bool truncate_error:
        By default, this will silently truncate passwords larger than 14 bytes.
        Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
        to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.

        .. versionadded:: 1.7

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.verify` methods accept a single
    optional keyword:

    :type encoding: str
    :param encoding:

        This specifies what character encoding LMHASH should use when
        calculating digest. It defaults to ``cp437``, the most
        common encoding encountered.

    Note that while this class outputs digests in lower-case hexadecimal,
    it will accept upper-case as well.
    Rttruncate_errori itcp437cCs
|j�S(N(tlower(tclsthash((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyt
_norm_hashUscCs;|jr|j|�nt|j||j��jd�S(Ntascii(tuse_defaultst_check_truncate_policyRtrawtencodingtdecode(tselftsecret((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyt_calc_checksumYs	sKGS!@#$%cCs�|s|j}nddlm}|j}t|t�rR|j�j|�}n*t|t�rp|j�}nt	d��t
|d�}||dd!|�||dd!|�S(s�encode password using LANMAN hash algorithm.

        :type secret: unicode or utf-8 encoded bytes
        :arg secret: secret to hash
        :type encoding: str
        :arg encoding:
            optional encoding to use for unicode inputs.
            this defaults to ``cp437``, which is the
            common case for most situations.

        :returns: returns string of raw bytes
        i����(tdes_encrypt_blockssecret must be unicode or bytesiii(tdefault_encodingtpasslib.crypto.desRt_magict
isinstanceRtuppertencodetbytest	TypeErrorR(RRRRtMAGIC((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyRcs	(RN(t__name__t
__module__t__doc__tnametsetting_kwdstuht	HEX_CHARStchecksum_charst
checksum_sizet
truncate_sizeRtclassmethodRRRtNoneR(((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyRs		cBs\eZdZdZejZdZed��Z	d�Z
ed��Zeed��Z
RS(s�This class implements the NT Password hash, and follows the :ref:`password-hash-api`.

    It has no salt and a single fixed round.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.

    Note that while this class outputs lower-case hexadecimal digests,
    it will accept upper-case digests as well.
    Ri cCs
|j�S(N(R(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR�scCst|j|��jd�S(NR(RRR(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR�scCs.t|ddd�}t|jd��j�S(s�encode password using MD4-based NTHASH algorithm

        :arg secret: secret as unicode or utf-8 encoded bytes

        :returns: returns string of raw bytes
        sutf-8tparamRs	utf-16-le(RRR!tdigest(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR�scCs9tdt�tj|�}|r5t|�jd�S|S(Nsfnthash.raw_nthash() is deprecated, and will be removed in Passlib 1.8, please use nthash.raw() insteadR(RtDeprecationWarningRRRR(RRthextret((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyt
raw_nthash�s(R%R&R'R(R*R+R,R-R/RRRtFalseR6(((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR�s			tprefixs$3$$tidenttdocsZThe class support FreeBSD's representation of NTHASH
    (which is compatible with the :ref:`modular-crypt-format`),
    and follows the :ref:`password-hash-api`.

    It has no salt and a single fixed round.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.
    cBsJeZdZdZejZdZed��Z	d�Z
ed��ZRS(sKThis class implements Microsoft's Domain Cached Credentials password hash,
    and follows the :ref:`password-hash-api`.

    It has a fixed number of rounds, and uses the associated
    username as the salt.

    The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods
    have the following optional keywords:

    :type user: str
    :param user:
        String containing name of user account this password is associated with.
        This is required to properly calculate the hash.

        This keyword is case-insensitive, and should contain just the username
        (e.g. ``Administrator``, not ``SOMEDOMAIN\Administrator``).

    Note that while this class outputs lower-case hexadecimal digests,
    it will accept upper-case digests as well.
    R
i cCs
|j�S(N(R(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyRscCs"t|j||j��jd�S(NR(RRtuserR(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR
scCsbt|ddd�jd�}t|ddd�j�jd�}tt|�j�|�j�S(s�encode password using mscash v1 algorithm

        :arg secret: secret as unicode or utf-8 encoded bytes
        :arg user: username to use as salt

        :returns: returns string of raw bytes
        sutf-8R1Rs	utf-16-leR;(RR!RRR2(RRR;((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR
s	$(R%R&R'R(R*R+R,R-R/RRR(((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR
�s		cBsJeZdZdZejZdZed��Z	d�Z
ed��ZRS(s�This class implements version 2 of Microsoft's Domain Cached Credentials
    password hash, and follows the :ref:`password-hash-api`.

    It has a fixed number of rounds, and uses the associated
    username as the salt.

    The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods
    have the following extra keyword:

    :type user: str
    :param user:
        String containing name of user account this password is associated with.
        This is required to properly calculate the hash.

        This keyword is case-insensitive, and should contain just the username
        (e.g. ``Administrator``, not ``SOMEDOMAIN\Administrator``).
    Ri cCs
|j�S(N(R(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR3scCs"t|j||j��jd�S(NR(RRR;R(RR((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR7scCs�ddlm}t|ddd�jd�}t|ddd�j�jd�}tt|�j�|�j�}|d||d	d
�S(s�encode password using msdcc v2 algorithm

        :type secret: unicode or utf-8 bytes
        :arg secret: secret

        :type user: str
        :arg user: username to use as salt

        :returns: returns string of raw bytes
        i����(tpbkdf2_hmacsutf-8R1Rs	utf-16-leR;tsha1i(i(tpasslib.crypto.digestR<RR!RRR2(RRR;R<ttmp((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyR:s
$"(R%R&R'R(R*R+R,R-R/RRR(((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyRs		(!R'tbinasciiRtloggingt	getLoggerR%tlogtwarningsRt
passlib.utilsRRtpasslib.utils.compatRR>RtconstRtpasslib.utils.handlerstutilsthandlersR*t__all__t
TruncateMixintHasEncodingContextt
StaticHandlerRRt
PrefixWrapperR	tHasUserContextR
R(((s</usr/lib/python2.7/site-packages/passlib/handlers/windows.pyt<module>s(	%t3	"0