
    uiP-                     x   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rSSK	r " S S\R                  R                  5      r " S S\R                  R                  5      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-                  S5      r\R*                  R-                  S5      r\R*                  R-                  S5      r\R*                  R-                  S5      r \r! " S S 5      r" " S! S"5      r# " S# S$5      r$  S,S% jr%S& r&S-S' jr'  S.S( jr(S) r) " S* S+5      r*g)/zDNS TSIG support.    Nc                       \ 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       ?/home/kodi/.kodi/addons/script.module.dnspython/lib/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)BadKey(   z2The TSIG record owner name does not match the key.r   Nr   r   r   r   r   r   (   s    <r   r   c                       \ rS rSrSrSrg)BadAlgorithm-   z*The TSIG algorithm does not match the key.r   Nr   r   r   r   r   r   -       4r   r   c                       \ rS rSrSrSrg)	PeerError2   z;Base class for all TSIG errors generated by the remote peerr   Nr   r   r   r   r   r   2   s    Er   r   c                       \ rS rSrSrSrg)
PeerBadKey7   z$The peer didn't know the key we usedr   Nr   r   r   r   r   r   7   s    .r   r   c                       \ rS rSrSrSrg)PeerBadSignature<   z*The peer didn't like the signature we sentr   Nr   r   r   r   r!   r!   <   r   r   r!   c                       \ rS rSrSrSrg)PeerBadTimeA   z%The peer didn't like the time we sentr   Nr   r   r   r   r$   r$   A   s    /r   r$   c                       \ rS rSrSrSrg)PeerBadTruncationF   z=The peer didn't like amount of truncation in the TSIG we sentr   Nr   r   r   r   r'   r'   F   s    Gr   r'   zHMAC-MD5.SIG-ALG.REG.INTz	hmac-sha1zhmac-sha224zhmac-sha256zhmac-sha256-128zhmac-sha384zhmac-sha384-192zhmac-sha512zhmac-sha512-256gss-tsigc                   0    \ rS rSrSrS rS rS rS rSr	g)	GSSTSig[   a/  
GSS-TSIG TSIG implementation.  This uses the GSS-API context established
in the TKEY message handshake to sign messages using GSS-API message
integrity codes, per the RFC.

In order to avoid a direct GSSAPI dependency, the keyring holds a ref
to the GSSAPI object required, rather than the key itself.
c                 ,    Xl         SU l        SU l        g )Nr   r)   )gssapi_contextdataname)selfr.   s     r   __init__GSSTSig.__init__d   s    ,		r   c                 .    U =R                   U-  sl         g N)r/   r1   r/   s     r   updateGSSTSig.updatei   s    		T	r   c                 L    U R                   R                  U R                  5      $ r5   )r.   get_signaturer/   )r1   s    r   signGSSTSig.signl   s    ""00;;r   c                 x     U R                   R                  U R                  U5      $ ! [         a    [        ef = fr5   )r.   verify_signaturer/   	Exceptionr   )r1   expecteds     r   verifyGSSTSig.verifyp   s9    	&&77		8LL 		s   %( 9)r/   r.   r0   N)
r   r	   r
   r   r   r2   r7   r;   rA   r   r   r   r   r+   r+   [   s    
<r   r+   c                   0    \ rS rSrS rS r\S 5       rSrg)GSSTSigAdaptery   c                     Xl         g r5   keyring)r1   rH   s     r   r2   GSSTSigAdapter.__init__z   s    r   c                     X R                   ;   aW  U R                   U   n[        U[        5      (       a1  UR                  [        :X  a  U(       a  [
        R                  X1U5        U$ g r5   )rH   
isinstanceKey	algorithmGSS_TSIGrD   parse_tkey_and_step)r1   messagekeynamekeys       r   __call__GSSTSigAdapter.__call__}   sM    ll",,w'C#s##(A"66sWMJr   c                 (    UR                  UR                  U[        R                  R                  [        R
                  R                  5      nU(       a,  US   R                  nUR                  nUR                  U5      $ g ! [         a     g f = f)Nr   )
find_rrsetanswerdns
rdataclassANY	rdatatypeTKEYrR   secretstepKeyError)clsrR   rP   rQ   rrsettokenr.   s          r   rO   "GSSTSigAdapter.parse_tkey_and_step   s~    		&&w~~w'*~~'9'9'*}}'9'9;E a!$%**511   		s   B B 
BBrG   N)	r   r	   r
   r   r2   rS   classmethodrO   r   r   r   r   rD   rD   y   s       r   rD   c                      \ rS rSrSr\\R                  \\R                  \
\R                  \\R                  S4\\R                  \\R                  S4\\R"                  \\R"                  S4\\R(                  0	rS rS rS rS	 rS
rg)HMACTSig   zc
HMAC TSIG implementation.  This uses the HMAC python module to handle the
sign/verify operations.
         c                     U R                   U   n[        U[        5      (       a'  [
        R                  " XS   S9U l        US   U l        O [
        R                  " XS9U l        S U l        U R                  R                  U l	        U R                  (       a#  U =R                  SU R                   3-  sl	        g g ! [         a    [        SU S3S-   5      ef = f)NzTSIG algorithm  zis not supportedr   )	digestmod   -)
_hashesr_   NotImplementedErrorrK   tuplehmacnewhmac_contextsizer0   )r1   rR   rM   hashinfos       r   r2   HMACTSig.__init__   s    	:||I.H h&& $ DD DI $ ADDI%%**	99II1TYYK(I   	:%	{!&D&8'9 : :	:s   B= =Cc                 8    U R                   R                  U5      $ r5   )ru   r7   r6   s     r   r7   HMACTSig.update   s      ''--r   c                     U R                   R                  5       nU R                  (       a  US U R                  S-   nU$ )N   )ru   digestrv   )r1   r}   s     r   r;   HMACTSig.sign   s7    ""))+99.tyyA~/Fr   c                 f    U R                  5       n[        R                  " X!5      (       d  [        eg r5   )r;   rs   compare_digestr   )r1   r@   macs      r   rA   HMACTSig.verify   s)    iik""311 2r   )ru   r0   rv   N)r   r	   r
   r   r   	HMAC_SHA1hashlibsha1HMAC_SHA224sha224HMAC_SHA256sha256HMAC_SHA256_128HMAC_SHA384sha384HMAC_SHA384_192HMAC_SHA512sha512HMAC_SHA512_256HMAC_MD5md5rp   r2   r7   r;   rA   r   r   r   r   rf   rf      s     	7<<W^^W^^'..#.W^^'..#.W^^'..#.'++
G)$.r   rf   c                 X   U=(       a    U(       + nU(       aR  [        U5      nU(       a@  UR                  [        R                  " S[	        U5      5      5        UR                  U5        UR                  [        R                  " SUR
                  5      5        UR                  U SS 5        U(       a  UR                  UR                  R                  5       5        UR                  [        R                  " S[        R                  R                  5      5        UR                  [        R                  " SS5      5        Uc  UR                  nUS-	  S-  nUS-  n	[        R                  " S	XUR                  5      n
[	        UR                  5      nUS:  a  [        S
5      eU(       al  UR                  UR                  R                  5       U
-   5        UR                  [        R                  " SUR                   U5      UR                  -   5        U$ UR                  U
5        U$ )zReturn a context containing the TSIG rdata for the input parameters
@rtype: dns.tsig.HMACTSig or dns.tsig.GSSTSig object
@raises ValueError: I{other_data} is too long
@raises NotImplementedError: I{algorithm} is not supported
!H   Nz!Ir       i  l    z!HIHz TSIG Other Data is > 65535 bytesz!HH)get_contextr7   structpacklenoriginal_idr0   to_digestablerX   rY   rZ   time_signedfudgeother
ValueErrorrM   error)wirerR   rdatatimerequest_macctxmultifirst
upper_time
lower_timetime_encoded	other_lens               r   _digestr      s    E#JJv{{4[)9:;JJ{#JJv{{4!2!234JJtABx

388))+,

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

6;;tQ'(|  "*&J
"J;;vzu{{KLEKK I5;<<

3==..0<?@

6;;uekk9=KL J 	

< Jr   c                     U(       aM  [        U 5      nUR                  [        R                  " S[	        U5      5      5        UR                  U5        U$ g)zIf this is the first message in a multi-message sequence,
start a new context.
@rtype: dns.tsig.HMACTSig or dns.tsig.GSSTSig object
r   N)r   r7   r   r   r   )rR   r   r   r   s       r   _maybe_start_digestr      s?    
 #

6;;tSX./

3
r   c           	      x    [        XX#XEU5      nUR                  5       nUR                  X7S9nU[        XU5      4$ )af  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, dns.tsig.HMACTSig or dns.tsig.GSSTSig object)
@raises ValueError: I{other_data} is too long
@raises NotImplementedError: I{algorithm} is not supported
)r   r   )r   r;   replacer   )	r   rR   r   r   r   r   r   r   tsigs	            r   r;   r;      sB     $U+E
BC
((*C==T=3D%c677r   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R                  S:w  a  UR                  [        R                  R                  :X  a  [        eUR                  [        R                  R                  :X  a  [        eUR                  [        R                  R                  :X  a  [        eUR                  [        R                  R                  :X  a  [        e[!        SUR                  -  5      e[#        UR$                  U-
  5      UR&                  :  a  [(        eUR*                  U:w  a  [,        eUR.                  UR.                  :w  a  [0        e[3        XUSXWU5      nUR5                  UR6                  5        [9        XR6                  U5      $ )a2  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: dns.tsig.HMACTSig or dns.tsig.GSSTSig objectr   
      r   rn   zunknown TSIG error code %dN)r   unpackrX   	exception	FormErrorr   r   rcodeBADSIGr!   BADKEYr   BADTIMEr$   BADTRUNCr'   r   absr   r   r   r0   r   rM   r   r   rA   r   r   )r   rR   ownerr   nowr   
tsig_startr   r   adcountnew_wires              r   validater     so    tT"R[1JW!|mm%%%qLGAbzFKKg66b9LLH{{a;;#))***""[[CII,,,[[CII---[[CII...##85;;FGG
5s"#ekk1
xx5
}}'
(k
FCJJuyysIIu55r   c                     U R                   [        :X  a  [        U R                  5      $ [	        U R                  U R                   5      $ )zReturns an HMAC context for the specified key.

@rtype: HMAC context
@raises NotImplementedError: I{algorithm} is not supported
)rM   rN   r+   r]   rf   )rR   s    r   r   r   5  s4     }} szz""

CMM22r   c                   ,    \ rS rSr\4S jrS rS rSrg)rL   iB  c                 j   [        U[        5      (       a  [        R                  R	                  U5      nXl        [        U[        5      (       a$  [
        R                  " UR                  5       5      nX l        [        U[        5      (       a  [        R                  R	                  U5      nX0l	        g r5   )
rK   strrX   r0   	from_textbase64decodebytesencoder]   rM   )r1   r0   r]   rM   s       r   r2   Key.__init__C  sv    dC  88%%d+D	fc""''8Fi%%**95I"r   c                     [        U[        5      =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r5   )rK   rL   r0   r]   rM   )r1   r   s     r   __eq__
Key.__eq__N  sR    5#& 2		UZZ'2u||+2 %//1	3r   c                     SU R                    S3SU R                   S3-   nU R                  [        :w  a5  US[        R                  " U R
                  5      R                  5        S3-  nUS-  nU$ )Nz<DNS key name='z', zalgorithm=''z
, secret='>)r0   rM   rN   r   	b64encoder]   decode)r1   rs     r   __repr__Key.__repr__T  sp    dii[,$..)+,>>X%:f..t{{;BBDEQGGA	Sr   )rM   r0   r]   N)	r   r	   r
   r   default_algorithmr2   r   r   r   r   r   r   rL   rL   B  s    /@ 	#3r   rL   )NNNN)NNNF)NF)+r   r   r   rs   r   dns.exceptionrX   dns.rdataclassdns.name	dns.rcoder   DNSExceptionr   r   r   r   r   r   r!   r$   r'   r0   r   r   r   r   r   r   r   r   r   r   rN   r   r+   rD   rf   r   r   r;   r   r   rL   r   r   r   <module>r      s  $         Ccmm(( C
.3==-- .
=S]]'' =
53==-- 5
F** F
/ /
5y 5
0) 0
H	 H 8889HH{+	hh  /hh  /(($$%67hh  /(($$%67hh  /(($$%6788j)  < @2 2j @D!H8  IM"6J
3 r   