Ñò
îgcJc           @   s    d  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 l Z l Z l Z d d k l Z d e f d	 „  ƒ  YZ d S(
   s   
L{AuthHandler}
iÿÿÿÿN(   t   *(   t   util(   t   Message(   t   SSHExceptiont   AuthenticationExceptiont   BadAuthenticationTypet   PartialAuthentication(   t   InteractiveQueryt   AuthHandlerc           B   s  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z 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 d „  Z d „  Z d „  Z h e e 6e e 6e e 6e e 6e e 6e e 6e e  6e e! 6Z" RS(   sC   
    Internal class to handle the mechanics of authentication.
    c         C   sp   t  i | ƒ |  _ d  |  _ t |  _ d  |  _ d |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d |  _ d  S(   Nt    i    (   t   weakreft   proxyt	   transportt   Nonet   usernamet   Falset   authenticatedt
   auth_eventt   auth_methodt   passwordt   private_keyt   interactive_handlert
   submethodst   auth_usernamet   auth_fail_count(   t   selfR   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   __init__*   s    									c         C   s   |  i  S(   N(   R   (   R   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   is_authenticated8   s    c         C   s    |  i  i o |  i S|  i Sd  S(   N(   R   t   server_modeR   R   (   R   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   get_username;   s    c         C   sQ   |  i  i i ƒ  z) | |  _ d |  _ | |  _ |  i ƒ  Wd  |  i  i i ƒ  Xd  S(   Nt   none(   R   t   lockt   acquireR   R   R   t   _request_autht   release(   R   R   t   event(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt	   auth_noneA   s    			c         C   sZ   |  i  i i ƒ  z2 | |  _ d |  _ | |  _ | |  _ |  i ƒ  Wd  |  i  i i ƒ  Xd  S(   Nt	   publickey(	   R   R   R    R   R   R   R   R!   R"   (   R   R   t   keyR#   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   auth_publickeyK   s    				c         C   sZ   |  i  i i ƒ  z2 | |  _ d |  _ | |  _ | |  _ |  i ƒ  Wd  |  i  i i ƒ  Xd  S(   NR   (	   R   R   R    R   R   R   R   R!   R"   (   R   R   R   R#   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   auth_passwordV   s    				R	   c         C   sc   |  i  i i ƒ  z; | |  _ d |  _ | |  _ | |  _ | |  _ |  i ƒ  Wd |  i  i i	 ƒ  Xd S(   sK   
        response_list = handler(title, instructions, prompt_list)
        s   keyboard-interactiveN(
   R   R   R    R   R   R   R   R   R!   R"   (   R   R   t   handlerR#   R   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   auth_interactivea   s    					c         C   s%   |  i  d  j	 o |  i  i ƒ  n d  S(   N(   R   R   t   set(   R   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   abortp   s    c         C   s=   t  ƒ  } | i t t ƒ ƒ | i d ƒ |  i i | ƒ d  S(   Ns   ssh-userauth(   R   t   add_bytet   chrt   MSG_SERVICE_REQUESTt
   add_stringR   t   _send_message(   R   t   m(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyR!   x   s    	c         C   sd   t  ƒ  } | i t t ƒ ƒ | i t ƒ | i d ƒ | i d ƒ |  i i | ƒ |  i i	 ƒ  d  S(   Ns   Service not availablet   en(
   R   R-   R.   t   MSG_DISCONNECTt   add_intt    DISCONNECT_SERVICE_NOT_AVAILABLER0   R   R1   t   close(   R   R2   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt!   _disconnect_service_not_available~   s    	c         C   sd   t  ƒ  } | i t t ƒ ƒ | i t ƒ | i d ƒ | i d ƒ |  i i | ƒ |  i i	 ƒ  d  S(   Ns   No more auth methods availableR3   (
   R   R-   R.   R4   R5   t)   DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLER0   R   R1   R7   (   R   R2   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _disconnect_no_more_auth‡   s    	c         C   s“   t  ƒ  } | i |  i i ƒ | i t t ƒ ƒ | i | ƒ | i | ƒ | i d ƒ | i d ƒ | i | i ƒ  ƒ | i t	 | ƒ ƒ t	 | ƒ S(   NR%   i   (
   R   R0   R   t
   session_idR-   R.   t   MSG_USERAUTH_REQUESTt   add_booleant   get_namet   str(   R   R&   t   serviceR   R2   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _get_session_blob   s    	c         C   sé   x„ t  o| | i d ƒ |  i i ƒ  pI |  i i ƒ  } | d  j p t | i t ƒ o t	 d ƒ } n | ‚ n | i
 ƒ  o Pq q W|  i ƒ  pQ |  i i ƒ  } | d  j o t	 d ƒ } n t | i t ƒ o | i S| ‚ n g  S(   Ngš™™™™™¹?s   Authentication failed.(   t   Truet   waitR   t	   is_activet   get_exceptionR   t
   issubclasst	   __class__t   EOFErrorR   t   isSetR   R   t   allowed_types(   R   R#   t   e(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   wait_for_responseœ   s$      


c         C   sr   | i  ƒ  } |  i i oK | d j o> t ƒ  } | i t t ƒ ƒ | i | ƒ |  i i | ƒ d  S|  i	 ƒ  d  S(   Ns   ssh-userauth(
   t
   get_stringR   R   R   R-   R.   t   MSG_SERVICE_ACCEPTR0   R1   R8   (   R   R2   R@   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_service_request±   s    	c         C   sì  | i  ƒ  } | d j o¸|  i i t d ƒ t ƒ  } | i t t ƒ ƒ | i |  i	 ƒ | i d ƒ | i |  i
 ƒ |  i
 d j oJ | i t ƒ |  i } t | t ƒ o | i d ƒ } n | i | ƒ nï |  i
 d j o† | i t ƒ | i |  i i ƒ  ƒ | i t |  i ƒ ƒ |  i |  i d |  i	 ƒ } |  i i |  i i | ƒ } | i t | ƒ ƒ nY |  i
 d j o! | i d ƒ | i |  i ƒ n( |  i
 d	 j o n t d
 |  i
 ƒ ‚ |  i i | ƒ n |  i i t d | ƒ d  S(   Ns   ssh-userauths   userauth is OKs   ssh-connectionR   s   UTF-8R%   s   keyboard-interactiveR	   R   s   Unknown auth method "%s"s!   Service request "%s" accepted (?)(   RM   R   t   _logt   DEBUGR   R-   R.   R<   R0   R   R   R=   R   R   t
   isinstancet   unicodet   encodeRB   R   R>   R?   RA   t   sign_ssh_datat   randpoolR   R   R1   (   R   R2   R@   R   t   blobt   sig(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_service_accept½   s:    		c         C   s  t  ƒ  } | t j o7 |  i i t d | ƒ | i t t ƒ ƒ t |  _	 n |  i i t d | ƒ | i t t
 ƒ ƒ | i |  i i i | ƒ ƒ | t j o | i d ƒ n | i d ƒ |  i d 7_ |  i i | ƒ |  i d j o |  i ƒ  n | t j o |  i i ƒ  n d  S(   Ns   Auth granted (%s).s   Auth rejected (%s).i   i    i
   (   R   t   AUTH_SUCCESSFULR   RP   t   INFOR-   R.   t   MSG_USERAUTH_SUCCESSRB   R   t   MSG_USERAUTH_FAILURER0   t   server_objectt   get_allowed_authst   AUTH_PARTIALLY_SUCCESSFULR=   R   R1   R:   t   _auth_trigger(   R   R   t   methodt   resultR2   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _send_auth_resultÞ   s"    	c         C   s©   t  ƒ  } | i t t ƒ ƒ | i | i ƒ | i | i ƒ | i d ƒ | i t | i	 ƒ ƒ x3 | i	 D]( } | i | d ƒ | i
 | d ƒ qi W|  i i | ƒ d  S(   NR	   i    i   (   R   R-   R.   t   MSG_USERAUTH_INFO_REQUESTR0   t   namet   instructionsR5   t   lent   promptsR=   R   R1   (   R   t   qR2   t   p(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _interactive_queryô   s    	
 c      
   C   s*  |  i  i pK t ƒ  } | i t t ƒ ƒ | i d ƒ | i d ƒ |  i  i | ƒ d  S|  i	 o d  S| i
 ƒ  } | i
 ƒ  } | i
 ƒ  } |  i  i t d | | | f ƒ | d j o |  i ƒ  d  S|  i d  j	 o2 |  i | j o" |  i  i t d ƒ |  i ƒ  d  S| |  _ | d j o |  i  i i | ƒ } nÜ| d j o¹ | i ƒ  } | i
 ƒ  } y | i d ƒ } Wn t j
 o n X| oU |  i  i t d ƒ | i
 ƒ  } y | i d d	 ƒ } Wn t j
 o n Xt } q|  i  i i | | ƒ } n| d
 j o| i ƒ  }	 | i
 ƒ  }
 | i
 ƒ  } y  |  i  i |
 t | ƒ ƒ } WnW t j
 o, } |  i  i t d t | ƒ ƒ d  } n! |  i  i t d ƒ d  } n X| d  j o |  i ƒ  d  S|  i  i i | | ƒ } | t j o­ |	 pK t ƒ  } | i t t ƒ ƒ | i |
 ƒ | i | ƒ |  i  i | ƒ d  St | i
 ƒ  ƒ } |  i | | | ƒ } | i  | | ƒ p |  i  i t d ƒ t } q—qny | d j oV | i
 ƒ  } | i
 ƒ  } |  i  i i! | | ƒ } t" | t# ƒ o |  i$ | ƒ d  Sn |  i  i i | ƒ } |  i% | | | ƒ d  S(   NR   i    s.   Auth request (type=%s) service=%s, username=%ss   ssh-connectionsK   Auth rejected because the client attempted to change username in mid-flightR   s   UTF-8s+   Auth request to change passwords (rejected)t   replaceR%   s   Auth rejected: public key: %ss0   Auth rejected: unsupported or mangled public keys    Auth rejected: invalid signatures   keyboard-interactive(&   R   R   R   R-   R.   R]   R0   R=   R1   R   RM   RP   RQ   R8   R   R   t   WARNINGR:   R^   t   check_auth_nonet   get_booleant   decodet   UnicodeErrort   AUTH_FAILEDt   check_auth_passwordt	   _key_infoR   R[   R?   t   check_auth_publickeyt   MSG_USERAUTH_PK_OKRA   t   verify_ssh_sigt   check_auth_interactiveRR   R   Rl   Rd   (   R   R2   R   R@   Rb   Rc   t	   changereqR   t   newpasswordt   sig_attachedt   keytypet   keyblobR&   RK   RX   RW   t   langR   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_userauth_request  sš    	
 
 
	
 


		c         C   sU   |  i  i t d |  i ƒ t |  _ |  i  i ƒ  |  i d  j o |  i i	 ƒ  n d  S(   Ns   Authentication (%s) successful!(
   R   RP   R[   R   RB   R   Ra   R   R   R+   (   R   R2   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_userauth_success_  s
    	c         C   s  | i  ƒ  } | i ƒ  } | oF |  i i t d ƒ |  i i t d t | ƒ ƒ t | ƒ |  i _ n{ |  i	 | j oP |  i i t d |  i	 ƒ |  i i t d t | ƒ ƒ t
 d | ƒ |  i _ n |  i i t d |  i	 ƒ t |  _ d  |  _ |  i d  j o |  i i ƒ  n d  S(   Ns   Authentication continues...s	   Methods: s'   Authentication type (%s) not permitted.s   Allowed methods: s   Bad authentication types   Authentication (%s) failed.(   t   get_listRp   R   RP   R[   RQ   R?   R   t   saved_exceptionR   R   R   R   R   R   R   R+   (   R   R2   t   authlistt   partial(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_userauth_failuref  s    		c         C   s3   | i  ƒ  } | i  ƒ  } |  i i t d | ƒ d  S(   Ns   Auth banner: (   RM   R   RP   R[   (   R   R2   t   bannerR   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_userauth_bannerx  s    c   	      C   s   |  i  d j o t d ƒ ‚ n | i ƒ  } | i ƒ  } | i ƒ  | i ƒ  } g  } x3 t | ƒ D]% } | i | i ƒ  | i ƒ  f ƒ qa W|  i | | | ƒ } t ƒ  } | i	 t
 t ƒ ƒ | i t | ƒ ƒ x | D] } | i | ƒ qÕ W|  i i | ƒ d  S(   Ns   keyboard-interactives    Illegal info request from server(   R   R   RM   t   get_intt   ranget   appendRp   R   R   R-   R.   t   MSG_USERAUTH_INFO_RESPONSER5   Rh   R0   R   R1   (	   R   R2   t   titleRg   Ri   t   prompt_listt   it   response_listt   r(    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_userauth_info_request~  s$    
 #	 c         C   s°   |  i  i p t d ƒ ‚ n | i ƒ  } g  } x' t | ƒ D] } | i | i ƒ  ƒ q< W|  i  i i | ƒ } t	 t
 | ƒ t ƒ o |  i | ƒ d  S|  i |  i d | ƒ d  S(   Ns!   Illegal info response from servers   keyboard-interactive(   R   R   R   R‰   RŠ   R‹   RM   R^   t   check_auth_interactive_responseRR   t   typeR   Rl   Rd   R   (   R   R2   t   nt	   responsesR   Rc   (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   _parse_userauth_info_response‘  s     (#   t   __name__t
   __module__t   __doc__R   R   R   R$   R'   R(   R*   R,   R!   R8   R:   RA   RL   RO   RY   Rd   Rl   R€   R   R†   Rˆ   R’   R—   R/   RN   R<   R\   R]   t   MSG_USERAUTH_BANNERRe   RŒ   t   _handler_table(    (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyR   %   sB   				
												!			^					(   Rš   t	   threadingR
   t   encodings.utf_8t	   encodingst   paramiko.commont   paramikoR   t   paramiko.messageR   t   paramiko.ssh_exceptionR   R   R   R   t   paramiko.serverR   t   objectR   (    (    (    sT   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\auth_handler.pyt   <module>   s   
"