ó
øÐLac        @   @   s  d  Z  d d l Z d d l Z e j e ƒ Z d d l m Z m Z m	 Z	 m
 Z
 d d l m Z d d l m Z m Z m Z m Z d d l j j Z d d g Z d Z dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ d` da db dc dd de f Z df Z dg Z e dI „ Z e dJ ƒ Z e dK ƒ Z e dL ƒ Z dM e j  e j! e j" e j# f dN „  ƒ  YZ$ d e$ f dO „  ƒ  YZ% d e$ f dP „  ƒ  YZ& d S(h   s9   passlib.handlers.sha2_crypt - SHA256-Crypt / SHA512-CryptiÿÿÿÿN(   t
   safe_cryptt
   test_cryptt   repeat_stringt
   to_unicode(   t   h64(   t   byte_elem_valuet   ut   uascii_to_strt   unicodet   sha512_cryptt   sha256_crypts    i    i   i   i   i   i   i   i
   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i	   i   i   i*   i+   i,   i-   i.   i/   i0   i1   i2   i3   i4   i    i5   i6   i!   i7   i"   i#   i8   i9   i$   i:   i%   i&   i;   i<   i'   i=   i(   i)   i>   i?   c         C   sâ  t  |  t ƒ r! |  j d ƒ }  n  t  |  t ƒ s6 t ‚ t |  k rc t j j | rW t	 n t
 ƒ ‚ n  t |  ƒ } d | k o† d k n s— t d ƒ ‚ t  | t ƒ s² t d ƒ ‚ | j d ƒ } t | ƒ } | d k  så t d ƒ ‚ | rý t j } t } n t j } t } | |  | |  ƒ j ƒ  } | |  | ƒ }	 |	 j }
 |
 t | | ƒ ƒ | } x. | rˆ|
 | d	 @rt| n |  ƒ | d	 L} q[W|	 j ƒ  } | d
 k  rÃt | |  | ƒ j ƒ  | ƒ } nU | |  ƒ } | j } | d	 } x | r| |  ƒ | d	 8} qåWt | j ƒ  | ƒ } t | ƒ | k s0t ‚ | | d t | d ƒ ƒ j ƒ  |  } t | ƒ | k svt d ƒ ‚ | | } | | } | | | | | | | | | g } g  t D]  \ } } | | | | f ^ qµ} | } t | d ƒ \ } } xQ | rIx: | D]2 \ } } | | | | | ƒ j ƒ  ƒ j ƒ  } qW| d	 8} qùW| rÉ| d	 ?} x> | |  D]2 \ } } | | | | | ƒ j ƒ  ƒ j ƒ  } qeW| d	 @rÉ| | | | d ƒ j ƒ  } qÉn  t j | | ƒ j d ƒ S(   sß  perform raw sha256-crypt / sha512-crypt

    this function provides a pure-python implementation of the internals
    for the SHA256-Crypt and SHA512-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 rounds: linear rounds cost
    :arg use_512: use sha512-crypt instead of sha256-crypt mode

    :returns:
        encoded checksum chars
    s   utf-8iè  iÿÉš;s   invalid roundss   salt not unicodet   asciii   s   salt too largei   i`   i   i    s   salt_len somehow > hash_len!i*   (   t
   isinstanceR   t   encodet   bytest   AssertionErrort   _BNULLt   uht   exct   NullPasswordErrorR	   R
   t   lent   hashlibt   sha512t   _512_transpose_mapt   sha256t   _256_transpose_mapt   digestt   updateR   R   t   _c_digest_offsetst   divmodR   t   encode_transposed_bytest   decode(   t   pwdt   saltt   roundst   use_512t   pwd_lent   salt_lent
   hash_constt   transpose_mapt   dbt   a_ctxt   a_ctx_updatet   it   dat   dpt   tmp_ctxt   tmp_ctx_updatet   dst   dp_dpt   dp_dst   permst   event   oddt   datat   dct   blockst   tailt   pairs(    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   _raw_sha2_crypt8   sl    !!(					"	
	
(.

$-	*
*
$s   rounds=t   $t   0t   _SHA2_Commonc           B   sÂ   e  Z d  Z d Z e j Z d Z e j Z d Z	 d Z
 d Z e Z d Z e Z d d	 „ Z d
 „  Z d „  Z e d „  ƒ Z d „  Z d Z d Z e d „  ƒ Z d „  Z e d „  ƒ Z d „  Z RS(   sB   class containing common code shared by sha256_crypt & sha512_cryptR!   R"   t   implicit_roundst	   salt_sizei   iè  iÿÉš;t   linearc         K   sJ   t  t |  ƒ j |   | d  k r= |  j o7 |  j d k } n  | |  _ d  S(   Niˆ  (   t   superR>   t   __init__t   Nonet   use_defaultsR"   R?   (   t   selfR?   t   kwds(    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyRC     s    c         C   s   |  j  | d |  j d  k ƒS(   Nt   relaxed(   t
   _norm_saltt   checksumRD   (   RF   R!   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   _parse_salt  s    c         C   s   |  j  | d |  j d  k ƒS(   NRH   (   t   _norm_roundsRJ   RD   (   RF   R"   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   _parse_rounds#  s    c      	   C   sv  t  | d d ƒ } |  j } | j | ƒ s? t j j |  ƒ ‚ n  t | ƒ d k sW t ‚ | d j t	 ƒ } | d j t
 ƒ rí t t
 ƒ d k s• t ‚ | j d ƒ d } | j t ƒ rØ | t k rØ t j j |  ƒ ‚ n  t | ƒ } t } n d } t } t | ƒ d k r| \ } } n7 t | ƒ d k r?| d } d  } n t j j |  ƒ ‚ |  d	 | d
 | d | pld  d | ƒ S(   NR   t   hashi   i    i   iˆ  i   i   R"   R!   RJ   R?   (   R   t   identt
   startswithR   R   t   InvalidHashErrorR   R   t   splitt   _UDOLLARt   _UROUNDSt   popt   _UZEROt   ZeroPaddedRoundsErrort   intt   Falset   TrueRD   t   MalformedHashError(   t   clsRN   RO   t   partsR"   R?   R!   t   chk(    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   from_string'  s4    			
	c         C   s‡   |  j  d k rI |  j rI t d ƒ |  j |  j |  j p? t d ƒ f } n4 t d ƒ |  j |  j  |  j |  j pv t d ƒ f } t | ƒ S(   Niˆ  s   %s%s$%st    s   %srounds=%d$%s$%s(   R"   R?   R   RO   R!   RJ   R   (   RF   RN   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt	   to_stringT  s    t   os_cryptt   builtinc         C   s+   t  |  j Œ  r# |  j |  j ƒ t St Sd  S(   N(   R   t
   _test_hasht   _set_calc_checksum_backendt   _calc_checksum_os_cryptRZ   RY   (   R\   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   _load_backend_os_crypti  s    c         C   s‰   |  j  ƒ  } t | | ƒ } | d  k r4 |  j | ƒ S|  j } | j |  j ƒ se | | d t k r€ t j	 j
 |  | | ƒ ‚ n  | | S(   Ni   (   Ra   R    RD   t   _calc_checksum_builtint   checksum_sizeRP   RO   RS   R   R   t   CryptBackendError(   RF   t   secrett   configRN   t   cs(    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyRf   q  s    	(c         C   s   |  j  |  j ƒ t S(   N(   Re   Rh   RZ   (   R\   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   _load_backend_builtin‚  s    c         C   s   t  | |  j |  j |  j ƒ S(   N(   R;   R!   R"   t   _cdb_use_512(   RF   Rk   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyRh   ‡  s    (   R!   R"   R?   R@   N(   Rb   Rc   (   t   __name__t
   __module__t   __doc__t   setting_kwdsR   t   HASH64_CHARSt   checksum_charst   max_salt_sizet
   salt_charst
   min_roundst
   max_roundst   rounds_costRY   Ro   RD   t   _rounds_prefixR?   RC   RK   RM   t   classmethodR_   Ra   t   backendsRd   Rg   Rf   Rn   Rh   (    (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyR>   ý   s,   				-		c           B   s2   e  Z d  Z d Z e d ƒ Z d Z d Z d Z RS(   sK  This class implements the SHA256-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-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 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 535000, must be between 1000 and 999999999, inclusive.

        .. note::
            per the official specification, when the rounds parameter is set to 5000,
            it may be omitted from the hash string.

    :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

    ..
        commented out, currently only supported by :meth:`hash`, and not via :meth:`using`:

        :type implicit_rounds: bool
        :param implicit_rounds:
            this is an internal option which generally doesn't need to be touched.

            this flag determines whether the hash should omit the rounds parameter
            when encoding it to a string; this is only permitted by the spec for rounds=5000,
            and the flag is ignored otherwise. the spec requires the two different
            encodings be preserved as they are, instead of normalizing them.
    R
   s   $5$i+   iØ) t   tests?   $5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/(   R~   s?   $5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/(	   Rp   Rq   Rr   t   nameR   RO   Ri   t   default_roundsRd   (    (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyR
     s   +c           B   s8   e  Z d  Z d Z e d ƒ Z d Z e Z d Z	 d Z
 RS(   sK  This class implements the SHA512-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-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 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 656000, must be between 1000 and 999999999, inclusive.

        .. note::
            per the official specification, when the rounds parameter is set to 5000,
            it may be omitted from the hash string.

    :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

    ..
        commented out, currently only supported by :meth:`hash`, and not via :meth:`using`:

        :type implicit_rounds: bool
        :param implicit_rounds:
            this is an internal option which generally doesn't need to be touched.

            this flag determines whether the hash should omit the rounds parameter
            when encoding it to a string; this is only permitted by the spec for rounds=5000,
            and the flag is ignored otherwise. the spec requires the two different
            encodings be preserved as they are, instead of normalizing them.
    R	   s   $6$iV   i€
 R~   sj   $6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0(   R~   sj   $6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0(   Rp   Rq   Rr   R   R   RO   Ri   RZ   Ro   R€   Rd   (    (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyR	   Ñ  s   +(   i    i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i    (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (    i   i
   i    i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i	   i   i   (@   i*   i   i    i   i+   i   i   i   i,   i-   i   i   i   i.   i   i   i   i/   i0   i   i   i   i1   i   i   i   i2   i3   i   i	   i
   i4   i   i    i   i5   i6   i!   i   i   i7   i"   i#   i   i8   i9   i$   i   i   i:   i%   i&   i   i;   i<   i'   i   i   i=   i(   i)   i   i>   i?   ('   Rr   R   t   loggingt	   getLoggerRp   t   logt   passlib.utilsR    R   R   R   t   passlib.utils.binaryR   t   passlib.utils.compatR   R   R   R   t   passlib.utils.handlerst   utilst   handlersR   t   __all__R   R   R   R   RY   R;   RT   RS   RV   t   HasManyBackendst	   HasRoundst   HasSaltt   GenericHandlerR>   R
   R	   (    (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha2_crypt.pyt   <module>   s6    ""	    Á‘B