ÿØÿà JFIF      ÿÛ „ 	 ( %!1!%)+//.383,7(-.+



-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ               ÿÄ J  	     ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ              ÿÄ *        !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍÑ¶¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     ÿØÿà JFIF      ÿÛ „ 	 ( %!1!%)+//.383,7(-.+



-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ               ÿÄ J  	     ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ              ÿÄ *        !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍÑ¶¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     3
bW&                 @   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|}|| | | | }|
rt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rtt|||||||||||	|
|\}}}||krt|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 )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 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