509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
¢báW&  ã               @   s~  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m	Z	m
Z
mZ G dd„ dejjƒZG dd„ dejjƒZG d	d
„ d
ejjƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZejjdƒZejjdƒZejjdƒZejjdƒZejjdƒZejjdƒZedededededediZeZdZd Z d!Z!d"Z"dd#d$efd%d&„Z#dd#d$efd'd(„Z$d/d)d*„Z%d+d,„ Z&d-d.„ Z'dS )0zDNS TSIG support.é    Né   )ÚlongÚstring_typesÚ	text_typec               @   s   e Zd ZdZdS )ÚBadTimez8The current time is not within the TSIG's validity time.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú/usr/lib/python3.6/tsig.pyr      s   r   c               @   s   e Zd ZdZdS )ÚBadSignaturez#The TSIG signature fails to verify.N)r   r   r	   r
   r   r   r   r   r       s   r   c               @   s   e Zd ZdZdS )Ú	PeerErrorz;Base class for all TSIG errors generated by the remote peerN)r   r   r	   r
   r   r   r   r   r   %   s   r   c               @   s   e Zd ZdZdS )Ú
PeerBadKeyz$The peer didn't know the key we usedN)r   r   r	   r
   r   r   r   r   r   *   s   r   c               @   s   e Zd ZdZdS )ÚPeerBadSignaturez*The peer didn't like the signature we sentN)r   r   r	   r
   r   r   r   r   r   /   s   r   c               @   s   e Zd ZdZdS )ÚPeerBadTimez%The peer didn't like the time we sentN)r   r   r	   r
   r   r   r   r   r   4   s   r   c               @   s   e Zd ZdZdS )ÚPeerBadTruncationz=The peer didn't like amount of truncation in the TSIG we sentN)r   r   r	   r
   r   r   r   r   r   9   s   r   zHMAC-MD5.SIG-ALG.REG.INTz	hmac-sha1zhmac-sha224zhmac-sha256zhmac-sha384zhmac-sha512ZSHA224ZSHA256ZSHA384ZSHA512ZSHA1ZMD5é   é   é   é   FTc             C   sÄ  t |tƒr|jƒ }t|ƒ\}}|r\tj||d�}	t|ƒ}|dkr\|	jtj	d|ƒƒ |	j|ƒ tj	d|ƒ}|	j|ƒ |	j| dd… ƒ |r¾|	j|j
ƒ ƒ |	jtj	dtjjƒƒ |	jtj	ddƒƒ |tdƒ }|d? tdƒ@ }|td	ƒ@ }tj	d
|||ƒ}|| }t|ƒ}|dk�rtdƒ‚tj	d||ƒ| }|�rF|	j|ƒ |	j|ƒ n
|	j|ƒ |	jƒ }tj	dt|ƒƒ}|| | | | }|
�r¶tj||d�}	t|ƒ}|	jtj	d|ƒƒ |	j|ƒ nd}	|||	fS )aj  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   z!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ÚdnsZ
rdataclassÚANYr   Ú
ValueErrorZdigest)ÚwireÚkeynameÚsecretÚtimeÚfudgeÚoriginal_idÚerrorÚ
other_dataÚrequest_macÚctxÚmultiÚfirstÚ	algorithmZalgorithm_namer   ZmlÚidZ	long_timeÚ
upper_timeÚ
lower_timeZtime_macZpre_macZolZpost_macÚmacZmpackÚ
tsig_rdatar   r   r   ÚsignW   sN    





r9   c             C   s    t | |||||||||	|
||ƒS )N)r9   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r   r   r   Úhmac_md5�   s    r:   c             C   sÖ  t jd| dd… ƒ\}|dkr&tjj‚|d8 }| dd… t jd|ƒ | d|…  }|}tjj| |ƒ\}}|| }t jd| ||d … ƒ\}}}}|tdƒ d> |tdƒ  }|d7 }| ||| … }||7 }t jd| ||d	 … ƒ\}}}|d	7 }| ||| … }||7 }||| k�r tjj‚|dk�rv|t	k�r:t
‚n<|tk�rJt‚n,|tk�rZt‚n|tk�rjt‚ntd
| ƒ‚|| }|| }||k �sš||k�ržt‚t|||||||||||	|
|ƒ\}}}||k�rÒt‚|S )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 objectz!Hé
   é   r   r   z!HIHHr   z!HHHé   zunknown TSIG error code %d)r!   Úunpackr$   Ú	exceptionÚ	FormErrorr"   ÚnameÚ	from_wirer   ÚBADSIGr   ÚBADKEYr   ÚBADTIMEr   ÚBADTRUNCr   r   r   r9   r   )r'   r(   r)   Znowr/   Z
tsig_startr8   Ú
tsig_rdlenr0   r1   r2   ZadcountZnew_wireÚcurrentÚanameÚusedr5   r6   r+   Úmac_sizer*   r7   r,   r-   Z
other_sizer.   Ztime_lowZ	time_highZjunkZour_macr   r   r   Úvalidate”   sN    
$ 





rL   c             C   s\   t | tƒrtjj| ƒ} y| jƒ tjjt|   fS  t	k
rV   t
dt| ƒ d ƒ‚Y nX dS )zÊReturns 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 supportedN)r   r   r$   rA   Ú	from_textr#   ÚhashZhashesÚ_hashesÚKeyErrorÚNotImplementedErrorÚstr)r3   r   r   r   r   Ê   s    
r   c             C   sz   |}t jj| |ƒ\}}|| }tjd| ||d … ƒ\}}}}	|d7 }| |||	 … }
||	7 }||| krrt jj‚||
fS )zlReturn the tsig algorithm for the specified tsig_rdata
    @raises FormError: The TSIG is badly formed.
    z!HIHHr;   )r$   rA   rB   r!   r>   r?   r@   )r'   r8   rG   rH   rI   rJ   r5   r6   r+   rK   r7   r   r   r   Úget_algorithm_and_macÜ   s     rS   )NFT)(r
   r   r!   Zdns.exceptionr$   Zdns.hashZdns.rdataclassZdns.nameZ_compatr   r   r   r?   ZDNSExceptionr   r   r   r   r   r   r   rA   rM   ZHMAC_MD5Z	HMAC_SHA1ZHMAC_SHA224ZHMAC_SHA256ZHMAC_SHA384ZHMAC_SHA512rO   Zdefault_algorithmrC   rD   rE   rF   r9   r:   rL   r   rS   r   r   r   r   Ú<module>   sL   5
5