
    Eqg,                     p   d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z G d dej
        j                  Z G d dej
        j                  Z G d dej
        j                  Z G d	 d
ej
        j                  Z G d dej
        j                  Z G d de          Z G d de          Z G d de          Z G d de          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Zej                            d          Z eZ!eded ed!ed"ed#ed$ed%ed!ed"e d&i
Z" G d' d(          Z# G d) d*          Z$ G d+ d,          Z%d5d-Z&d. Z'd6d0Z(	 d7d1Z)d2 Z* G d3 d4          Z+dS )8zDNS TSIG support.    Nc                       e Zd ZdZdS )BadTimez8The current time is not within the TSIG's validity time.N__name__
__module____qualname____doc__     :/var/www/html/env/lib/python3.11/site-packages/dns/tsig.pyr   r      s        BBBBr   r   c                       e Zd ZdZdS )BadSignaturez#The TSIG signature fails to verify.Nr   r
   r   r   r   r   #   s        ----r   r   c                       e Zd ZdZdS )BadKeyz2The TSIG record owner name does not match the key.Nr   r
   r   r   r   r   '   s        <<<<r   r   c                       e Zd ZdZdS )BadAlgorithmz*The TSIG algorithm does not match the key.Nr   r
   r   r   r   r   +           4444r   r   c                       e Zd ZdZdS )	PeerErrorz;Base class for all TSIG errors generated by the remote peerNr   r
   r   r   r   r   /   s        EEEEr   r   c                       e Zd ZdZdS )
PeerBadKeyz$The peer didn't know the key we usedNr   r
   r   r   r   r   3   s        ....r   r   c                       e Zd ZdZdS )PeerBadSignaturez*The peer didn't like the signature we sentNr   r
   r   r   r   r   7   r   r   r   c                       e Zd ZdZdS )PeerBadTimez%The peer didn't like the time we sentNr   r
   r   r   r   r   ;   s        ////r   r   c                       e Zd ZdZdS )PeerBadTruncationz=The peer didn't like amount of truncation in the TSIG we sentNr   r
   r   r   r   r   ?   s        GGG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-tsig             0      @      c                   *    e Zd ZdZd Zd Zd Zd ZdS )GSSTSigaG  
    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                 0    || _         d| _        d| _        d S )Nr   r   )gssapi_contextdataname)selfr*   s     r   __init__zGSSTSig.__init__j   s    ,				r   c                 &    | xj         |z  c_         d S N)r+   r-   r+   s     r   updatezGSSTSig.updateo   s    		T				r   c                 @    | j                             | j                  S r0   )r*   get_signaturer+   )r-   s    r   signzGSSTSig.signr   s    "00;;;r   c                 n    	 | j                             | j        |          S # t          $ r t          w xY wr0   )r*   verify_signaturer+   	Exceptionr   )r-   expecteds     r   verifyzGSSTSig.verifyv   sC    	&77	8LLL 	 	 		s   " 4N)r   r   r   r	   r.   r2   r5   r:   r
   r   r   r(   r(   `   sZ           
  < < <    r   r(   c                   0    e Zd Zd Zd Zed             ZdS )GSSTSigAdapterc                     || _         d S r0   )keyring)r-   r>   s     r   r.   zGSSTSigAdapter.__init__   s    r   c                     || j         v rR| j         |         }t          |t                    r.|j        t          k    r|rt
                              |||           |S d S r0   )r>   
isinstanceKey	algorithmGSS_TSIGr<   parse_tkey_and_step)r-   messagekeynamekeys       r   __call__zGSSTSigAdapter.__call__   se    dl"",w'C#s## N(A(A N"66sGWMMMJ4r   c                     	 |                     |j        |t          j        j        t          j        j                  }|r)|d         j        }|j        }|	                    |          S d S # t          $ r Y d S w xY w)Nr   )
find_rrsetanswerdns
rdataclassANY	rdatatypeTKEYrG   secretstepKeyError)clsrG   rE   rF   rrsettokenr*   s          r   rD   z"GSSTSigAdapter.parse_tkey_and_step   s    		&&);S]=O E  2a!$%**51112 2  	 	 	DD	s   A%A* *
A87A8N)r   r   r   r.   rH   classmethodrD   r
   r   r   r<   r<      sM               [  r   r<   c                       e Zd ZdZeej        eej        e	ej
        eej
        dfeej        eej        dfeej        eej        dfeej        i	Zd Zd Zd Zd Zd	S )
HMACTSigzo
    HMAC TSIG implementation.  This uses the HMAC python module to handle the
    sign/verify operations.
    r&         c                    	 | j         |         }n!# t          $ r t          d| d          w xY wt          |t                    r/t          j        ||d                   | _        |d         | _        n"t          j        ||          | _        d | _        | j        j	        | _	        | j        r| xj	        d| j         z  c_	        d S d S )NzTSIG algorithm z is not supportedr   )	digestmod   -)
_hashesrS   NotImplementedErrorr@   tuplehmacnewhmac_contextsizer,   )r-   rG   rB   hashinfos       r   r.   zHMACTSig.__init__   s    	V|I.HH 	V 	V 	V%&T	&T&T&TUUU	V h&& 	 $ D D DD DII $ A A ADDI%*	9 	)IITY(IIII	) 	)s    .c                 6    | j                             |          S r0   )re   r2   r1   s     r   r2   zHMACTSig.update   s     ''---r   c                 j    | j                                         }| j        r|d | j        dz           }|S )N   )re   digestrf   )r-   rk   s     r   r5   zHMACTSig.sign   s;    "))++9 	0.tyA~./Fr   c                 f    |                                  }t          j        ||          st          d S r0   )r5   rc   compare_digestr   )r-   r9   macs      r   r:   zHMACTSig.verify   s4    iikk"311 		 	r   N)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md5r`   r.   r2   r5   r:   r
   r   r   rY   rY      s          	7<W^W^'.#.W^'.#.W^'.#.'+
G) ) )". . .      r   rY   c                 (   |o| }|r[t          |          }|rJ|                    t          j        dt	          |                               |                    |           |                    t          j        d|j                             |                    | dd                    |r|                    |j                                                   |                    t          j        dt          j	        j
                             |                    t          j        dd                     ||j        }|dz	  dz  }|dz  }	t          j        d	||	|j                  }
t	          |j                  }|dk    rt          d
          |rf|                    |j                                        |
z              |                    t          j        d|j        |          |j        z              n|                    |
           |S )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   r!   i  l    z!HIHz TSIG Other Data is > 65535 bytesz!HH)get_contextr2   structpacklenoriginal_idr,   to_digestablerL   rM   rN   time_signedfudgeother
ValueErrorrB   error)wirerG   rdatatimerequest_macctxmultifirst
upper_time
lower_timetime_encoded	other_lens               r   _digestr      s    E $# 	$JJv{4[)9)9::;;;JJ{###JJv{4!233444JJtABBx )

38))++,,,

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

6;tQ''(((| "*&J
"J;vz:u{KKLEK  I5;<<< !

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

6;uek9==KLLLL

<   Jr   c                     |r[t          |           }|                    t          j        dt	          |                               |                    |           |S dS )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   r2   r   r   r   )rG   rn   r   r   s       r   _maybe_start_digestr      sV    
  #

6;tSXX..///

3
tr   Fc           	          t          | ||||||          }|                                }|                    ||          }|t          |||          fS )a~  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   rn   )r   r5   replacer   )	r   rG   r   r   r   r   r   rn   tsigs	            r   r5   r5     sW     $UD+sE
B
BC
((**C==Ts=33D%c36677r   c	           	      D   t          j        d| dd                   \  }	|	dk    rt          j        j        |	dz  }	| dd         t          j        d|	          z   | d|         z   }
|j        dk    r|j        t          j        j        k    rt          |j        t          j        j
        k    rt          |j        t          j        j        k    rt          |j        t          j        j        k    rt          t!          d|j        z            t#          |j        |z
            |j        k    rt(          |j        |k    rt,          |j        |j        k    rt0          t3          |
||d|||          }|                    |j                   t9          ||j        |          S )aF  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   r^   zunknown TSIG error code %dN)r   unpackrL   	exception	FormErrorr   r   rcodeBADSIGr   BADKEYr   BADTIMEr   BADTRUNCr   r   absr   r   r   r,   r   rB   r   r   r:   rn   r   )r   rG   ownerr   nowr   
tsig_startr   r   adcountnew_wires              r   validater     su    tT"R%[11JW!||m%%qLGAbDzFKg666bm9LLH{a;#)***""[CI,,,[CI---[CI...##85;FGGG
5s"##ek11
x5
}''
(Ck3
F
FCJJuysEIu555r   c                 ~    | j         t          k    rt          | j                  S t	          | j        | j                   S )zReturns an HMAC context for the specified key.

    @rtype: HMAC context
    @raises NotImplementedError: I{algorithm} is not supported
    )rB   rC   r(   rQ   rY   )rG   s    r   r   r   :  s5     }  sz"""
CM222r   c                   $    e Zd ZefdZd Zd ZdS )rA   c                 v   t          |t                    rt          j                            |          }|| _        t          |t                    r&t          j        |                                          }|| _        t          |t                    rt          j                            |          }|| _	        d S r0   )
r@   strrL   r,   	from_textbase64decodebytesencoderQ   rB   )r-   r,   rQ   rB   s       r   r.   zKey.__init__H  s    dC   	,8%%d++D	fc"" 	9'88Fi%% 	6**955I"r   c                     t          |t                    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S r0   )r@   rA   r,   rQ   rB   )r-   r   s     r   __eq__z
Key.__eq__S  sI    uc"" 2	UZ'2u|+2 %/1		
r   c                     d| j          dd| j         dz   }| j        t          k    r2|dt          j        | j                                                   dz  }|dz  }|S )Nz<DNS key name='z', zalgorithm=''z
, secret='>)r,   rB   rC   r   	b64encoderQ   decode)r-   rs     r   __repr__zKey.__repr__[  sq    ,di,,,/NT^/N/N/NN>X%%Gf.t{;;BBDDGGGGA	Sr   N)r   r   r   default_algorithmr.   r   r   r
   r   r   rA   rA   G  sI        /@ 	# 	# 	# 	#
 
 
    r   rA   )NNNN)NNNF)NF),r	   r   rp   rc   r   dns.exceptionrL   dns.name	dns.rcodedns.rdataclassr   DNSExceptionr   r   r   r   r   r   r   r   r   r,   r   r}   ro   rr   rt   rv   rw   ry   rz   r|   rC   r   	mac_sizesr(   r<   rY   r   r   r5   r   r   rA   r
   r   r   <module>r      s1  $                   C C C C Ccm( C C C. . . . .3=- . . .= = = = =S]' = = =5 5 5 5 53=- 5 5 5F F F F F* F F F/ / / / / / / /5 5 5 5 5y 5 5 50 0 0 0 0) 0 0 0H H H H H	 H H H 8899H{++	h  //h  //($$%677h  //($$%677h  //($$%6778j))  rRRRbc	       >       @1 1 1 1 1 1 1 1h       F  8 8 8 8" LQ#6 #6 #6 #6L
3 
3 
3         r   