Hacked By AnonymousFox

Current Path : /lib/python3.6/site-packages/dns/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/dns/__pycache__/tsig.cpython-36.pyc

3

�b�W&�@s~dZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZGdd�dejj
�ZGdd�dejj
�ZGd	d
�d
ejj
�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�Zejjd�Zejjd�Zejjd�Zejjd�Zejjd�Zejjd�ZedededededediZeZdZd Z d!Z!d"Z"dd#d$efd%d&�Z#dd#d$efd'd(�Z$d/d)d*�Z%d+d,�Z&d-d.�Z'dS)0zDNS TSIG support.�N�)�long�string_types�	text_typec@seZdZdZdS)�BadTimez8The current time is not within the TSIG's validity time.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/tsig.pyrsrc@seZdZdZdS)�BadSignaturez#The TSIG signature fails to verify.N)rrr	r
rrrrr
 sr
c@seZdZdZdS)�	PeerErrorz;Base class for all TSIG errors generated by the remote peerN)rrr	r
rrrrr%src@seZdZdZdS)�
PeerBadKeyz$The peer didn't know the key we usedN)rrr	r
rrrrr*src@seZdZdZdS)�PeerBadSignaturez*The peer didn't like the signature we sentN)rrr	r
rrrrr/src@seZdZdZdS)�PeerBadTimez%The peer didn't like the time we sentN)rrr	r
rrrrr4src@seZdZdZdS)�PeerBadTruncationz=The peer didn't like amount of truncation in the TSIG we sentN)rrr	r
rrrrr9srzHMAC-MD5.SIG-ALG.REG.INTz	hmac-sha1zhmac-sha224zhmac-sha256zhmac-sha384zhmac-sha512ZSHA224ZSHA256ZSHA384ZSHA512ZSHA1ZMD5����FTc
Cs�t|t�r|j�}t|�\}
}|r\tj||d�}	t|�}|dkr\|	jtj	d|��|	j|�tj	d|�}|	j|�|	j|dd��|r�|	j|j
��|	jtj	dtjj
��|	jtj	dd��|td�}|d?td�@}|td	�@}tj	d
|||�}|
|}t|�}|dk�rtd��tj	d||�|}|�rF|	j|�|	j|�n
|	j|�|	j�}tj	dt|��}|||||}|
�r�tj||d�}	t|�}|	jtj	d|��|	j|�nd}	|||	fS)
ajReturn 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
    )�	digestmodrz!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�
ValueErrorZdigest)�wire�keyname�secret�time�fudge�original_id�error�
other_data�request_mac�ctx�multi�first�	algorithmZalgorithm_namerZml�idZ	long_time�
upper_time�
lower_timeZtime_macZpre_macZolZpost_mac�macZmpack�
tsig_rdatarrr�signWsN





r9c

Cs t||||||||||	|
||�
S)N)r9)
r'r(r)r*r+r,r-r.r/r0r1r2r3rrr�hmac_md5�sr:cCs�tjd|dd��\}|dkr&tjj�|d8}|dd�tjd|�|d|�}|}
tjj||
�\}}|
|}
tjd||
|
d��\}}}}|td�d>|td�}|
d7}
||
|
|�}|
|7}
tjd||
|
d	��\}}}|
d	7}
||
|
|�}|
|7}
|
||k�r tjj�|dk�rv|t	k�r:t
�n<|tk�rJt�n,|t
k�rZt�n|tk�rjt�ntd
|��||}||}||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�
�rrz!HIHHrz!HHH�zunknown TSIG error code %d)r!�unpackr$�	exception�	FormErrorr"�name�	from_wirer�BADSIGr�BADKEYr�BADTIMEr�BADTRUNCrrrr9r
)r'r(r)Znowr/Z
tsig_startr8�
tsig_rdlenr0r1r2ZadcountZnew_wire�current�aname�usedr5r6r+�mac_sizer*r7r,r-Z
other_sizer.Ztime_lowZ	time_highZjunkZour_macrrr�validate�sN
$ 





rLcCs\t|t�rtjj|�}y|j�tjjt|fSt	k
rVt
dt|�d��YnXdS)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
    zTSIG algorithm z is not supportedN)rrr$rA�	from_textr#�hashZhashes�_hashes�KeyError�NotImplementedError�str)r3rrrr�s
rcCsz|}tjj||�\}}||}tjd|||d��\}}}}	|d7}||||	�}
||	7}|||krrtjj�||
fS)zlReturn the tsig algorithm for the specified tsig_rdata
    @raises FormError: The TSIG is badly formed.
    z!HIHHr;)r$rArBr!r>r?r@)r'r8rGrHrIrJr5r6r+rKr7rrr�get_algorithm_and_mac�s rS)NFT)(r
rr!Z
dns.exceptionr$Zdns.hashZdns.rdataclassZdns.nameZ_compatrrrr?ZDNSExceptionrr
rrrrrrArMZHMAC_MD5Z	HMAC_SHA1ZHMAC_SHA224ZHMAC_SHA256ZHMAC_SHA384ZHMAC_SHA512rOZdefault_algorithmrCrDrErFr9r:rLrrSrrrr�<module>sL5
5

Hacked By AnonymousFox1.0, Coded By AnonymousFox