o
    b                     @   s\   d dl mZ d dlmZ d dlmZmZmZ G dd dejZ	G dd dej
Z
dd	 Zd
S )    )error)	transport)deferprotocolreactorc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
SSHClientFactoryc                 C   s   || _ || _|| _|| _d S N)doptionsverifyHostKeyuserAuthObject)selfr	   r
   r   r    r   =/usr/lib/python3/dist-packages/twisted/conch/client/direct.py__init__   s   
zSSHClientFactory.__init__c                 C   s   | j d r|  d S d S )N	reconnect)r
   connect)r   	connectorreasonr   r   r   clientConnectionLost   s   
z%SSHClientFactory.clientConnectionLostc                 C   s*   | j d u rd S | j d }| _ || d S r   )r	   errback)r   r   r   r	   r   r   r   clientConnectionFailed   s   
z'SSHClientFactory.clientConnectionFailedc                 C   sh   t | }| jd r| jd |_| jd r| jd |_| jd r'dg|jdd< | jd r2| jd |_|S )Nciphersmacscompresszlibr      zhost-key-algorithms)SSHClientTransportr
   supportedCipherssupportedMACssupportedCompressionssupportedPublicKeys)r   addrtransr   r   r   buildProtocol   s   



zSSHClientFactory.buildProtocolN)__name__
__module____qualname__r   r   r   r$   r   r   r   r   r   
   s
    r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )r   c                 C   s   || _ d | _d S r   )factory
unixServer)r   r(   r   r   r   r   )   s   
zSSHClientTransport.__init__c                    s:   j rj  }d _ ntd }| fdd d S )Nc                    s   t j S r   )r   r   connectionLost)xr   r   r   r   <lambda>4   s    z3SSHClientTransport.connectionLost.<locals>.<lambda>)r)   stopListeningr   succeedaddCallback)r   r   r	   r   r,   r   r*   -   s   

z!SSHClientTransport.connectionLostc                 C   s8   | j jd u rd S | j jd }| j _|t|| d S r   )r(   r	   r   r   
ConchError)r   codedescr	   r   r   r   receiveError7   s   zSSHClientTransport.receiveErrorc                 C   sH   | j jd u rd S | j jd }| j _tj| || |t|| d S r   )r(   r	   r   r   sendDisconnectr   r   r1   )r   r2   r   r	   r   r   r   r5   =   s
   z!SSHClientTransport.sendDisconnectc                 C   s(   | j jd|||d |rt| d S d S )Nz!Received Debug Message: {message})messagealwaysDisplaylang)_logdebugprint)r   r7   r6   r8   r   r   r   receiveDebugD   s   zSSHClientTransport.receiveDebugc                 C   s   | j | | j j||S r   )r(   r   r   getPeerhost)r   pubKeyfingerprintr   r   r   r   N   s   z SSHClientTransport.verifyHostKeyc                 C   s\   | j jd|d tj| | |jdkr*| jjd ur,| jjd }| j_|d  d S d S d S )Nz"setting client server to {service})servicezssh-userauth)	r9   infor   r   
setServicenamer(   r	   callback)r   rA   r	   r   r   r   rC   S   s   zSSHClientTransport.setServicec                 C   s   |  | jj d S r   )requestServicer(   r   )r   r   r   r   connectionSecureZ   s   z#SSHClientTransport.connectionSecureN)r%   r&   r'   r   r*   r4   r5   r<   r   rC   rG   r   r   r   r   r   (   s    

r   c                 C   s(   t  }t||||}t| || |S r   )r   Deferredr   r   
connectTCP)r>   portr
   r   r   r	   r(   r   r   r   r   ^   s   r   N)twisted.conchr   twisted.conch.sshr   twisted.internetr   r   r   ClientFactoryr   r   r   r   r   r   r   <module>   s   6