Ñò
ðgcJc           @   só   d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Td d k l	 Z	 d d k
 l Z d d k l Z e Z y d d k Z e Z Wn e j
 o n Xd „  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   s   
Packetizer.
iÿÿÿÿN(   t   *(   t   util(   t   SSHException(   t   Messagec         C   sJ   t  o t i |  | | ƒ i ƒ  Sd d k l } | i |  | | ƒ i ƒ  S(   Niÿÿÿÿ(   t   HMAC(   t
   got_r_hmact   r_hmacR   t   digestt   Crypto.Hash(   t   keyt   messaget   digest_classR   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   compute_hmac*   s    t   NeedRekeyExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyR   1   s   t
   Packetizerc           B   s  e  Z d  Z e d d ƒ Z e d d ƒ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s9   
    Implementation of the base SSH packet protocol.
    i   i   c         C   s  | |  _  d  |  _ t |  _ t |  _ t |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d  |  _ d  |  _ d  |  _ d  |  _ d |  _ d |  _ d  |  _ d  |  _ d |  _ d |  _ t i ƒ  |  _ d |  _ t  i  ƒ  |  _! d  |  _" d  S(   Ni    t    i   l    (#   t   _Packetizer__sockett   Nonet   _Packetizer__loggert   Falset   _Packetizer__closedt   _Packetizer__dump_packetst   _Packetizer__need_rekeyt   _Packetizer__init_countt   _Packetizer__remaindert   _Packetizer__sent_bytest   _Packetizer__sent_packetst   _Packetizer__received_bytest   _Packetizer__received_packetst&   _Packetizer__received_packets_overflowt   _Packetizer__block_size_outt   _Packetizer__block_size_int   _Packetizer__mac_size_outt   _Packetizer__mac_size_int   _Packetizer__block_engine_outt   _Packetizer__block_engine_int   _Packetizer__mac_engine_outt   _Packetizer__mac_engine_int   _Packetizer__mac_key_outt   _Packetizer__mac_key_int    _Packetizer__compress_engine_outt   _Packetizer__compress_engine_int    _Packetizer__sequence_number_outt   _Packetizer__sequence_number_int	   threadingt   RLockt   _Packetizer__write_lockt   _Packetizer__keepalive_intervalt   timet   _Packetizer__keepalive_lastt   _Packetizer__keepalive_callback(   t   selft   socket(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   __init__?   s<    																											c         C   s   | |  _  d S(   s?   
        Set the python log object to use for logging.
        N(   R   (   R5   t   log(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_logg   s    c         C   sx   | |  _  | |  _ | |  _ | |  _ | |  _ d |  _ d |  _ |  i d O_ |  i d j o d |  _ t |  _	 n d S(   s.   
        Switch outbound data cipher.
        i    i   i   N(
   R$   R    R&   R"   R(   R   R   R   R   R   (   R5   t   block_enginet
   block_sizet
   mac_enginet   mac_sizet   mac_key(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_outbound_cipherm   s    								c         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ d |  _ d |  _ d |  _ |  i d O_ |  i d j o d |  _ t	 |  _
 n d S(   s-   
        Switch inbound data cipher.
        i    i   i   N(   R%   R!   R'   R#   R)   R   R   R   R   R   R   (   R5   R:   R;   R<   R=   R>   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_inbound_cipher~   s    									c         C   s   | |  _  d  S(   N(   R*   (   R5   t
   compressor(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_outbound_compressor   s    c         C   s   | |  _  d  S(   N(   R+   (   R5   RA   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_inbound_compressor“   s    c         C   s   t  |  _ |  i i ƒ  d  S(   N(   t   TrueR   R   t   close(   R5   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyRE   –   s    	c         C   s   | |  _  d  S(   N(   R   (   R5   t   hexdump(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_hexdumpš   s    c         C   s   |  i  S(   N(   R   (   R5   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   get_hexdump   s    c         C   s   |  i  S(   N(   R#   (   R5   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   get_mac_size_in    s    c         C   s   |  i  S(   N(   R"   (   R5   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   get_mac_size_out£   s    c         C   s   |  i  S(   s3  
        Returns C{True} if a new set of keys needs to be negotiated.  This
        will be triggered during a packet read or write, so it should be
        checked after every read or write, or at least after every few.
        
        @return: C{True} if a new set of keys needs to be negotiated
        (   R   (   R5   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt
   need_rekey¦   s    c         C   s%   | |  _  | |  _ t i ƒ  |  _ d S(   sÎ   
        Turn on/off the callback keepalive.  If C{interval} seconds pass with
        no data read from or written to the socket, the callback will be
        executed and the timer will be reset.
        N(   R1   R4   R2   R3   (   R5   t   intervalt   callback(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   set_keepalive°   s    		c         C   s  d } t  |  i ƒ d j o1 |  i |  } |  i | |  _ | t  | ƒ 8} n t o |  i | | ƒ Sx©| d j o›t } yP |  i i | ƒ } t  | ƒ d j o t ƒ  ‚ n | | 7} | t  | ƒ 8} Wná t i	 j
 o t
 } nÇ t i j
 o· } t | i ƒ t j o7 t  | i ƒ d j o! | i d t i j o
 t
 } q¯t | i ƒ t j o1 t  | i ƒ d j o | i d t i j o q¯|  i o t ƒ  ‚ q¯‚  n X| oV |  i o t ƒ  ‚ n | o* t  | ƒ d j o |  i o t ƒ  ‚ n |  i ƒ  qh qh W| S(   s2  
        Read as close to N bytes as possible, blocking as long as necessary.
        
        @param n: number of bytes to read
        @type n: int
        @return: the data read
        @rtype: str
        @raise EOFError: if the socket was closed before all the bytes could
            be read
        R   i    (   t   lenR   t   PY22t   _py22_read_allR   R   t   recvt   EOFErrorR6   t   timeoutRD   t   errort   typet   argst   tuplet   errnot   EAGAINt   EINTRR   R   R   t   _check_keepalive(   R5   t   nt   check_rekeyt   outt   got_timeoutt   xt   e(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   read_allº   sB     

C
C

$c         C   s“  t  i  ƒ  |  _ x}t | ƒ d j oit } y |  i i | ƒ } Wnå t i j
 o t } nË t i	 j
 o£ } t
 | i ƒ t j o7 t | i ƒ d j o! | i d t i j o
 t } q)t
 | i ƒ t j o1 t | i ƒ d j o | i d t i j o q)d } n t j
 o d } n X| o d } |  i o
 d } qNn | d j  o t ƒ  ‚ n | t | ƒ j o Pn | | } q Wd  S(   Ni    iÿÿÿÿ(   R2   R3   RO   R   R   t   sendR6   RT   RD   RU   RV   RW   RX   RY   RZ   R[   t	   ExceptionR   RS   (   R5   R_   R`   R]   Rb   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt	   write_allì   s4     
C
C

c         C   s‘   |  i  } x% d | j o | |  i | ƒ 7} q W| i d ƒ } | | d |  _  | |  } t | ƒ d j o | d d j o | d  } n | S(   s‰   
        Read a line from the socket.  We assume no data is pending after the
        line, so it's okay to attempt large reads.
        s   
i   i    iÿÿÿÿs   (   R   t   _read_timeoutt   indexRO   (   R5   RT   t   bufR]   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   readline
  s    	 
$c      	   C   s4  t  | ƒ } t | d ƒ } | t j o t | } n d | } t | ƒ } |  i i ƒ  zÅ|  i d
 j	 o |  i | ƒ } n |  i | ƒ } |  i	 o: |  i
 t d | | f ƒ |  i
 t t i | d ƒ ƒ n |  i d
 j o |  i i | ƒ } n | } |  i d
 j o@ t i d |  i ƒ | } | t |  i | |  i ƒ |  i  7} n |  i d d @|  _ |  i | ƒ |  i t | ƒ 7_ |  i d 7_ |  i d d j o t i ƒ  n |  i |  i j p |  i |  i j oB |  i o7 |  i
 t d	 |  i |  i f ƒ d |  _ |  i  ƒ  n Wd
 |  i i! ƒ  Xd
 S(   sR   
        Write a block of data using the current cipher, as an SSH block.
        i    s   $%xs   Write packet <%s>, length %ds   OUT: s   >Ii   l   ÿÿ id   s(   Rekeying (hit %d packets, %d bytes sent)N("   t   strt   ordt	   MSG_NAMESRO   R0   t   acquireR*   R   t   _build_packetR   t   _logt   DEBUGR   t   format_binaryR$   t   encryptt   structt   packR,   R   R(   R&   R"   Rf   R   R   t   randpoolt   stirt   REKEY_PACKETSt   REKEY_BYTESR   R   t   _trigger_rekeyt   release(   R5   t   datat   cmdt   cmd_namet   orig_lent   packetR_   t   payload(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   send_message  sB    

 '&	c         C   s«  |  i  |  i d t ƒ} |  i d j o |  i i | ƒ } n |  i o  |  i t t	 i
 | d ƒ ƒ n t i d | d  ƒ d } | d } | t | ƒ |  i d j o t d ƒ ‚ n |  i  | |  i t | ƒ ƒ } | | t | ƒ  } | | t | ƒ } |  i d j o |  i i | ƒ } n |  i o  |  i t t	 i
 | d ƒ ƒ n | | } |  i d j oi | |  i  } t i d |  i | ƒ | } t |  i | |  i ƒ |  i  }	 |	 | j o t d ƒ ‚ qÕn t | d ƒ }
 | d	 | |
 !} t i ƒ  |  i o |  i t d
 | |
 f ƒ n |  i d j	 o |  i | ƒ } n t | d	 ƒ } |  i | _ |  i d	 d @|  _ |  i | |  i d 7_ |  i d	 7_ |  i o3 |  i d	 7_ |  i d j o t d ƒ ‚ q>n^ |  i |  i j p |  i |  i  j o7 |  i t d |  i |  i f ƒ d |  _ |  i! ƒ  n t | d ƒ } | t" j o t" | } n d | } |  i o$ |  i t d | t | ƒ f ƒ n | | f S(   så   
        Only one thread should ever be in this function (no other locking is
        done).
        
        @raise SSHException: if the packet is mangled
        @raise NeedRekeyException: if the transport should rekey
        R^   s   IN: s   >Ii   i    s   Invalid packet blockings   >IIs   Mismatched MACi   s"   Got payload (%d bytes, %d padding)l   ÿÿ i   s+   Remote transport is ignoring rekey requestss,   Rekeying (hit %d packets, %d bytes received)s   $%xs   Read packet <%s>, length %dN(#   Rc   R!   RD   R%   R   t   decryptR   Rp   Rq   R   Rr   Rt   t   unpackRO   R   R#   Ru   R-   R   R)   R'   Rl   Rv   t	   add_eventR+   R   t   seqnoR   R   R   R   Rx   Ry   Rz   Rm   (   R5   t   headert   packet_sizet   leftoverRi   R€   t   post_packett   mact   mac_payloadt   my_mact   paddingR   t   msgR}   R~   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   read_messageG  sh    
 
 
 



	

$c         C   sj   |  i  d  j o d  St t | ƒ t ƒ o( x8 | D] } |  i  i | | ƒ q2 Wn |  i  i | | ƒ d  S(   N(   R   R   t
   issubclassRV   t   listR8   (   R5   t   levelR   t   m(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyRp   “  s     c         C   sc   |  i  p |  i p
 |  i o d  St i ƒ  } | |  i |  i  j o |  i ƒ  | |  _ n d  S(   N(   R1   R$   R   R2   R3   R4   (   R5   t   now(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyR\   œ  s    

c         C   sÁ   xº | d j o¬ t  i  |  i g g  g  d ƒ \ } } } |  i | j o% |  i o t ƒ  ‚ n |  i ƒ  q |  i i | ƒ } t | ƒ d j o t ƒ  ‚ n | | 7} | t | ƒ 8} q W| S(   Ni    gš™™™™™¹?(   t   selectR   R   RS   R\   RR   RO   (   R5   R]   R_   t   rt   wRb   Ra   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyRQ   ¦  s     '

c         C   sÑ   t  i  ƒ  } x¾ t o¶ t i |  i g g  g  d ƒ \ } } } |  i | j o7 |  i i d ƒ } t | ƒ d j o t ƒ  ‚ n Pn |  i o t ƒ  ‚ n t  i  ƒ  } | | | j o t i	 ƒ  ‚ q q W| S(   Ngš™™™™™¹?i   i    (
   R2   RD   R–   R   RR   RO   RS   R   R6   RT   (   R5   RT   t   startR—   R˜   Rb   Ra   R•   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   _py22_read_timeoutµ  s     '
c         C   sÈ   t  o |  i | ƒ St i ƒ  } x  t o˜ y7 |  i i d ƒ } t | ƒ d j o t ƒ  ‚ n PWn t i	 j
 o n X|  i
 o t ƒ  ‚ n t i ƒ  } | | | j o t i	 ƒ  ‚ q$ q$ W| S(   Ni€   i    (   RP   Rš   R2   RD   R   RR   RO   RS   R6   RT   R   (   R5   RT   R™   Ra   R•   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyRg   Å  s$     
c         C   s‘   |  i  } d | t | ƒ d | } t i d t | ƒ | d | ƒ } | | 7} |  i d  j	 o | t i | ƒ 7} n | t d ƒ | 7} | S(   Ni   i   s   >IBi   i    (	   R    RO   Rt   Ru   R$   R   Rv   t	   get_bytest   chr(   R5   R   t   bsizeRŽ   R€   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyRo   Ø  s    	#
c         C   s   t  |  _ d  S(   N(   RD   R   (   R5   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyRz   æ  s    (    R   R   t   __doc__t   powRx   Ry   R7   R9   R?   R@   RB   RC   RE   RG   RH   RI   RJ   RK   RN   R   Rc   Rf   Rj   R‚   R   Rp   R\   RQ   Rš   Rg   Ro   Rz   (    (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyR   5   s8   	(											
	
2			.	L			
				(   Rž   RY   R–   R6   Rt   R.   R2   t   paramiko.commont   paramikoR   t   paramiko.ssh_exceptionR   t   paramiko.messageR   R   R   R   RD   t   ImportErrorR   Re   R   t   objectR   (    (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\packet.pyt   <module>   s&   

	