
                            S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	J
r
Jr   " S S\R                  R                  5      r " S S\R                  R                  5      r " S	 S
\R                  R                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\R*                  R-                  S5      r\R*                  R-                  S5      r\R*                  R-                  S5      r\R*                  R-                  S5      r\R*                  R-                  S5      r\R*                  R-                  S5      r\\R:                  \\R<                  \\R>                  \\R@                  \\RB                  \\RD                  0r#\r$Sr%Sr&Sr'Sr(SSS\$4S jr)SSS\$4S  jr* S$S! jr+S" r,S# r-g)%zDNS TSIG support.    N   )longstring_types	text_typec                       \ rS rSrSrSrg)BadTime   z8The current time is not within the TSIG's validity time. N__name__
__module____qualname____firstlineno____doc____static_attributes__r
       lib/third_party/dns/tsig.pyr   r      s    Br   r   c                       \ rS rSrSrSrg)BadSignature"   z#The TSIG signature fails to verify.r
   Nr   r
   r   r   r   r   "   s    -r   r   c                       \ rS rSrSrSrg)	PeerError'   z;Base class for all TSIG errors generated by the remote peerr
   Nr   r
   r   r   r   r   '   s    Er   r   c                       \ rS rSrSrSrg)
PeerBadKey,   z$The peer didn't know the key we usedr
   Nr   r
   r   r   r   r   ,   s    .r   r   c                       \ rS rSrSrSrg)PeerBadSignature1   z*The peer didn't like the signature we sentr
   Nr   r
   r   r   r   r   1   s    4r   r   c                       \ rS rSrSrSrg)PeerBadTime6   z%The peer didn't like the time we sentr
   Nr   r
   r   r   r!   r!   6   s    /r   r!   c                       \ rS rSrSrSrg)PeerBadTruncation;   z=The peer didn't like amount of truncation in the TSIG we sentr
   Nr   r
   r   r   r$   r$   ;   s    Gr   r$   zHMAC-MD5.SIG-ALG.REG.INTz	hmac-sha1zhmac-sha224zhmac-sha256zhmac-sha384zhmac-sha512            FTc                 x   [        U[        5      (       a  UR                  5       n[        U5      u  pU(       a\  [        R
                  " X.S9n	[        U5      nUS:  a7  U	R                  [        R                  " SU5      5        U	R                  U5        [        R                  " SU5      nU	R                  U5        U	R                  U SS 5        U(       a  U	R                  UR                  5       5        U	R                  [        R                  " S[        R                  R                  5      5        U	R                  [        R                  " SS5      5        U[        S5      -   nUS-	  [        S5      -  nU[        S	5      -  n[        R                  " S
UUU5      nUU-   n[        U5      nUS:  a  [        S5      e[        R                  " SUU5      U-   nU(       a#  U	R                  U5        U	R                  U5        OU	R                  U5        U	R!                  5       n[        R                  " S[        U5      5      nUU-   U-   U-   U-   nU
(       aW  [        R
                  " X.S9n	[        U5      nU	R                  [        R                  " SU5      5        U	R                  U5        OSn	UUU	4$ )aR  Return a (tsig_rdata, mac, ctx) tuple containing the HMAC TSIG rdata
for the input parameters, the HMAC MAC calculated by applying the
TSIG signature algorithm, and the TSIG digest context.
@rtype: (string, string, hmac.HMAC object)
@raises ValueError: I{other_data} is too long
@raises NotImplementedError: I{algorithm} is not supported
)	digestmodr   !H   Nz!I    i  l    z!HIHz TSIG Other Data is > 65535 bytesz!HH)
isinstancer   encodeget_algorithmhmacnewlenupdatestructpackto_digestabledns
rdataclassANYr   
ValueErrordigest)wirekeynamesecrettimefudgeoriginal_iderror
other_datarequest_macctxmultifirst	algorithmalgorithm_namer+   mlid	long_time
upper_time
lower_timetime_macpre_macolpost_macmacmpack
tsig_rdatas                              r   signrX   Y   s    *i((&&(
"/	":^hhv36JJv{{4,-JJ{#	T;	'BJJrNJJtABx

7((*+

6;;tS^^%7%789

6;;tQ'(tAwIr/T&\1JT*--J{{6:z5AHx'G	ZB	Ez;<<{{5%,z9H

7

8

8
**,CKKc#h'E53&+h6Jhhv3X

6;;tR()

3S!!r   c                 $    [        XX#XEUXxXX5      $ )N)rX   )r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   s                r   hmac_md5rZ      s"     vUUG Gr   c                    [         R                  " SU SS 5      u  nUS:X  a  [        R                  R                  eUS-  nU SS [         R
                  " SU5      -   U SU -   nUn[        R                  R                  X5      u  pX-   n[         R                  " SXUS-    5      u  nnnnU[        S5      -   S-  U[        S5      -   -   nUS-  nXUU-    nUU-  n[         R                  " SXUS	-    5      u  nnnUS	-  nXUU-    nUU-  nXU-   :w  a  [        R                  R                  eUS:w  aN  U[        :X  a  [        eU[        :X  a  [        eU[        :X  a  [        eU[        :X  a  [         e[#        S
U-  5      eUU-
  nUU-   nUU:  d  UU:  a  [$        e['        XUUUUUUXHXU5      u  nnnUU:w  a  [(        eU$ )a  Validate the specified TSIG rdata against the other input parameters.

@raises FormError: The TSIG is badly formed.
@raises BadTime: There is too much time skew between the client and the
server.
@raises BadSignature: The TSIG signature did not validate
@rtype: hmac.HMAC objectr,   
      r   r   !HIHHr.   z!HHH   zunknown TSIG error code %d)r6   unpackr9   	exception	FormErrorr7   name	from_wirer   BADSIGr   BADKEYr   BADTIMEr!   BADTRUNCr$   r   r   rX   r   )r>   r?   r@   nowrF   
tsig_startrW   
tsig_rdlenrG   rH   rI   adcountnew_wirecurrentanameusedrO   rP   rB   mac_sizerA   rU   rC   rD   
other_sizerE   time_low	time_highjunkour_macs                                 r   validaterw      s    tT"R[1JW!|mm%%%qLGAbzFKKg66b9LLHGHH&&t5MUnGgtGbL9: .ZUH$q'!b(Z$q'-ABDrMG
w)
*CxGfd7Q;78 %[%qLGg
23JzGz))mm%%%zF?""f_gh##85@AAe|HuI
X~y64 +UJ +%GT7C #~Jr   c                     [        U [        5      (       a  [        R                  R	                  U 5      n  U R                  5       [        U    4$ ! [         a    [        S[        U 5      -   S-   5      ef = f)zReturns the wire format string and the hash module to use for the
specified TSIG algorithm

@rtype: (string, hash constructor)
@raises NotImplementedError: I{algorithm} is not supported
zTSIG algorithm z is not supported)
r/   r   r9   rc   	from_textr8   _hashesKeyErrorNotImplementedErrorstr)rJ   s    r   r1   r1      ss     )\**HH&&y1	7'')79+=>> 7!"3c)n"D"5#6 7 	77s   A %A4c                     Un[         R                  R                  X5      u  pEX5-   n[        R                  " SXUS-    5      u  pgpUS-  nXX9-    n
X9-  nX1U-   :  a  [         R
                  R                  eXJ4$ )zdReturn the tsig algorithm for the specified tsig_rdata
@raises FormError: The TSIG is badly formed.
r^   r\   )r9   rc   rd   r6   r`   ra   rb   )r>   rW   rk   rn   ro   rp   rO   rP   rB   rq   rU   s              r   get_algorithm_and_macr      s     GHH&&t5MUnGgtGbL9: .ZUrMG
w)
*CGj((mm%%%<r   )NFT).r   hashlibr2   r6   dns.exceptionr9   dns.rdataclassdns.name_compatr   r   r   ra   DNSExceptionr   r   r   r   r   r!   r$   rc   ry   HMAC_MD5	HMAC_SHA1HMAC_SHA224HMAC_SHA256HMAC_SHA384HMAC_SHA512sha224sha256sha384sha512sha1md5rz   default_algorithmre   rf   rg   rh   rX   rZ   rw   r1   r   r
   r   r   <module>r      s  $        2 2Ccmm(( C
.3==-- .
F** F
/ /
5y 5
0) 0
H	 H 8889HH{+	hh  /hh  /hh  /hh  / w||gkk  		
 '+%t$3"n +/e4(G 7;3l7$r   