5Xc@sUdZddlmZddlZddlZejeZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZddljjZdgZd aed Zed eDed eDed eDedeDgZ[dZd Zdej ej!ej"fdYZ#dS(!spasslib.handlers.sun_md5_crypt - Sun's Md5 Crypt, used on Solaris .. warning:: This implementation may not reproduce the original Solaris behavior in some border cases. See documentation for details. i(tmd5N(twarn(t to_unicode(th64(tbyte_elem_valuetirangetut uascii_to_strtunicodet str_to_basciit sun_md5_cryptsTo be, or not to be,--that is the question:-- Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them?--To die,--to sleep,-- No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to,--'tis a consummation Devoutly to be wish'd. To die,--to sleep;-- To sleep! perchance to dream:--ay, there's the rub; For in that sleep of death what dreams may come, When we have shuffled off this mortal coil, Must give us pause: there's the respect That makes calamity of so long life; For who would bear the whips and scorns of time, The oppressor's wrong, the proud man's contumely, The pangs of despis'd love, the law's delay, The insolence of office, and the spurns That patient merit of the unworthy takes, When he himself might his quietus make With a bare bodkin? who would these fardels bear, To grunt and sweat under a weary life, But that the dread of something after death,-- The undiscover'd country, from whose bourn No traveller returns,--puzzles the will, And makes us rather bear those ills we have Than fly to others that we know not of? Thus conscience does make cowards of us all; And thus the native hue of resolution Is sicklied o'er with the pale cast of thought; And enterprises of great pith and moment, With this regard, their currents turn awry, And lose the name of action.--Soft you now! The fair Ophelia!--Nymph, in thy orisons Be all my sins remember'd. iccs"|]}|||dfVqdS(iN((t.0ti((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys Nsccs&|]}||d|dfVqdS(iiN((R R ((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys Osccs*|] }||d|dd@fVqdS(ii iN((R R ((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys Psccs.|]$}||dd@|dd@fVqdS(i ii N((R R ((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys QscCst|tstt|ts*t|dkr?d}nd|}t||j}t|dkswtt\}}}}d} x$| |krg|D]} t| ^qj} d} | | d?d@| d@?d@r|n|} x| D]w\}}}| |}| |}| ||d?d@||d@?d@?}| | |d?d@|d@?d@|>O} qWd}| | d d?d@| d@?d@r|n|}x|D]w\}}}| |}| |}| ||d?d@||d@?d@?}|| |d?d@|d@?d@|>O}qW| | d?| d@?| |d?|d@?Ad@}t|}|r|j t n|j t | j d |j}| d7} qWt j|tS( s:given secret & salt, return encoded sun-md5-crypt checksumiiiiiiiii@tascii(t isinstancetbytestAssertionErrorRtdigesttlent _XY_ROUNDSRt __getitem__tupdatet MAGIC_HAMLETRtencodeRtencode_transposed_bytest _chk_offsets(tsecrettroundstsaltt real_roundstresultt X_ROUNDS_0t X_ROUNDS_1t Y_ROUNDS_0t Y_ROUNDS_1troundtctrvaltxtxroundsR tiatibtatbtvtytyroundstcointh((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pytraw_sun_md5_cryptUsB   ",  (,0  (,2  i iii iiiiii iii ii cBseZdZdZdZejZdZdZ dZ ejZ dZ d Zd Zd Zed ed fZeZedZedZedZedZdZRS(sPThis class implements the Sun-MD5-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, a salt will be autogenerated (this is recommended). If specified, it must be drawn from the regexp range ``[./0-9A-Za-z]``. :type salt_size: int :param salt_size: If no salt is specified, this parameter can be used to specify the size (in characters) of the autogenerated salt. It currently defaults to 8. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to 34000, must be between 0 and 4294963199, inclusive. :type bare_salt: bool :param bare_salt: Optional flag used to enable an alternate salt digest behavior used by some hash strings in this scheme. This flag can be ignored by most users. Defaults to ``False``. (see :ref:`smc-bare-salt` for details). :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 R RRt bare_saltt salt_sizeiiiЄiItlinears$md5$s$md5,cKs#||_tt|j|dS(N(R2tsuperR t__init__(tselfR2tkwds((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyR6s cCstj|}|j|jS(N(tuhtto_unicode_for_identifyt startswitht ident_values(tclsthash((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pytidentifysc Csnt|dd}|jtdr6d}d}n|jtdr%|jtdd}|d krtjj|d n|d|!}yt|}Wn&tk rtjj|d nX|t |krtjj |n|dkrtjj|d n|d }ntjj ||j td|}|d krt||}d}t} n|t|d kr||kr|dtdkrtjj|dn||d !}d}t} no|dkr.||d tdkr.|||d !}||d }t} n!|||!}||d }t} |d|d|d|d| S(NR R>s$md5$iis $md5,rounds=t$i isunexpected end of roundss bad roundssexplicit zero roundsiistoo many '$' separatorsRRtchecksumR2(RR;RtfindR9texctMalformedHashErrortintt ValueErrorRtZeroPaddedRoundsErrortInvalidHashErrortrfindtNonetTrueRtFalse( R=R>Rtsalt_idxtidxtrstrtchk_idxRtchkR2((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyt from_stringsT         "  &  cCs|jrtdn td}|j}|dkrUtd||j|f}ntd|j|f}|r|j}td||f}nt|S(NtR@is$md5,rounds=%d$%s%ss $md5$%s%ss%s$%s(R2RRRRAR(R7t_withchktssRR>RQ((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyt to_stringJs!   cCsUt|tr!|jd}nt|jdt}t||j|jdS(Nsutf-8RTR ( RRRR RVRLR1Rtdecode(R7Rtconfig((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyt_calc_checksum^s(ssaltsroundss bare_saltR3N(t__name__t __module__t__doc__tnamet setting_kwdsR9t HASH64_CHARStchecksum_charst checksum_sizetdefault_salt_sizeRJt max_salt_sizet salt_charstdefault_roundst min_roundst max_roundst rounds_costRR<RLR2R6t classmethodR?RRRKRVRY(((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyR s&)   D (i iii iiiiiii iii ii ($R\thashlibRtretloggingt getLoggerRZtlogtwarningsRt passlib.utilsRtpasslib.utils.binaryRtpasslib.utils.compatRRRRRR tpasslib.utils.handlerstutilsthandlersR9t__all__RtxrttupleRR1Rt HasRoundstHasSalttGenericHandlerR (((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyts2  . &  O