Ë
    oj,d  ã                   óä  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ d dlmZ d dlm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ 	 d dlm,Z,m-Z-  e(d«      Z/e/rd dl0m1Z1 d dl2m3Z3m4Z4m5Z5 nd dl6m3Z3  G d„ d«      Z1	 d dl7m4Z8 e8Z9d„ Z= e=«       Z> G d„ d«      Z? G d„ de+«      Z@ G d„ d ej‚                  «      ZB G d!„ d"ej†                  «      ZD G d#„ d$ejŠ                  «      ZF G d%„ d&ejŠ                  «      ZG G d'„ d(ej‚                  «      ZHd>d)„ZI G d*„ d+«      ZJ G d,„ d-eJ«      ZK e	e3«       G d.„ d/e1«      «       ZL G d0„ d1«      ZM G d2„ d3eJ«      ZN G d4„ d5«      ZO G d6„ d7eJeOe+«      ZP G d8„ d9eKeOe+«      ZQ G d:„ d;eNeOe+«      ZR G d<„ d=eKe+«      ZSy# e.$ r Y �ŒFw xY w# e.$ rZ:dZ9 e;e:«      Z<[:Y dZ:[:�Œ,dZ:[:ww xY w)?é    N)Úcount)ÚskipIf)Úimplementer)Ú
ConchError)ÚprivateDSA_opensshÚprivateRSA_opensshÚpublicDSA_opensshÚpublicRSA_openssh©ÚConchTestRealm)Úportal)ÚdeferÚprotocolÚreactor)ÚProcessExitedAlready)ÚLoopingCall)ÚgetProcessValue)ÚfilepathÚlogÚruntime)ÚFilePath)Úwhich)ÚrequireModule)ÚSkipTestÚTestCase)ÚConchTestServerFactoryÚconchTestPublicKeyCheckerÚcryptography)Ú	ConchUser)ÚISessionÚ
SSHSessionÚwrapProtocol)r    c                   ó   — e Zd Zy)r   N)Ú__name__Ú
__module__Ú__qualname__© ó    ú?/usr/lib/python3/dist-packages/twisted/conch/test/test_conch.pyr   r   1   s   „ Ør(   r   )r!   c                  ó¾   — d} d}	 t        j                   t         j                  «      } | j                  d«       d}| r| j	                  «        |S # t        $ r Y Œw xY w)z4Returns True if the system can bind an IPv6 address.NF)ú::1r   T)ÚsocketÚAF_INET6ÚbindÚOSErrorÚclose)ÚsockÚhas_ipv6s     r)   Ú	_has_ipv6r3   ?   s[   € à€DØ€HðÜ�}‰}œVŸ_™_Ó-ˆØ�	‰	�*ÔØˆñ Ø�
‰
ŒØ€Oøô ò Ùðús   †6A Á	AÁAc                   ó   — e Zd ZdZdZd„ Zy)Ú	FakeStdiozø
    A fake for testing L{twisted.conch.scripts.conch.SSHSession.eofReceived} and
    L{twisted.conch.scripts.cftp.SSHSession.eofReceived}.

    @ivar writeConnLost: A flag which records whether L{loserWriteConnection}
        has been called.
    Fc                 ó   — d| _         y)z9
        Record the call to loseWriteConnection.
        TN)ÚwriteConnLost©Úselfs    r)   ÚloseWriteConnectionzFakeStdio.loseWriteConnection^   s   € ð "ˆÕr(   N)r$   r%   r&   Ú__doc__r7   r:   r'   r(   r)   r5   r5   S   s   „ ñð €Mó"r(   r5   c                   ó   — e Zd ZdZe€eZd„ Zy)ÚStdioInteractingSessionTestsz>
    Tests for L{twisted.conch.scripts.conch.SSHSession}.
    Nc                 ó�   — t        «       }t        «       }||_        |j                  «        | j	                  |j
                  «       y)z}
        L{twisted.conch.scripts.conch.SSHSession.eofReceived} loses the
        write half of its stdio connection.
        N)r5   ÚStdioInteractingSessionÚstdioÚeofReceivedÚ
assertTruer7   )r9   r@   Úchannels      r)   Útest_eofReceivedz-StdioInteractingSessionTests.test_eofReceivedm   s8   € ô
 “ˆÜ)Ó+ˆØˆŒØ×ÑÔØ�‰˜×+Ñ+Õ,r(   )r$   r%   r&   r;   r?   Ú_reasonÚskiprD   r'   r(   r)   r=   r=   e   s   „ ñð Ð&Øˆó	-r(   r=   c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚEchoc                 ó.   — t        j                  d«       y )NzECHO CONNECTION MADE©r   Úmsgr8   s    r)   ÚconnectionMadezEcho.connectionMadez   ó   € Ü�‰Ð&Õ'r(   c                 ó.   — t        j                  d«       y )NzECHO CONNECTION DONErJ   ©r9   Úreasons     r)   ÚconnectionLostzEcho.connectionLost}   rM   r(   c                 óx   — | j                   j                  |«       d|v r| j                   j                  «        y y )Nó   
)Ú	transportÚwriteÚloseConnection©r9   Údatas     r)   ÚdataReceivedzEcho.dataReceived€   s0   € Ø�‰×Ñ˜TÔ"Ø�D‰=Ø�N‰N×)Ñ)Õ+ð r(   N)r$   r%   r&   rL   rQ   rY   r'   r(   r)   rH   rH   y   s   „ ò(ò(ó,r(   rH   c                   ó   — e Zd ZeZy)ÚEchoFactoryN)r$   r%   r&   rH   r   r'   r(   r)   r[   r[   †   s   „ Ø�Hr(   r[   c                   ó4   — e Zd ZdZdZdZdZd„ Zd„ Zd„ Z	d„ Z
y)ÚConchTestOpenSSHProcessa  
    Test protocol for launching an OpenSSH client process.

    @ivar deferred: Set by whatever uses this object. Accessed using
    L{_getDeferred}, which destroys the value so the Deferred is not
    fired twice. Fires when the process is terminated.
    Nr(   c                 ó.   — | j                   d c}| _         |S ©N©Údeferred©r9   Úds     r)   Ú_getDeferredz$ConchTestOpenSSHProcess._getDeferred—   ó   € ØŸ=™=¨$Ðˆˆ4Œ=Øˆr(   c                 ó.   — | xj                   |z  c_         y r_   )ÚbufrW   s     r)   ÚoutReceivedz#ConchTestOpenSSHProcess.outReceived›   s   € Ø�Š�DÑŽr(   c                 ó.   — | xj                   |z  c_         y r_   )ÚproblemsrW   s     r)   ÚerrReceivedz#ConchTestOpenSSHProcess.errReceivedž   s   € Ø�Š˜ÑŽr(   c           
      óx  — |j                   j                  dk7  rf| j                  «       j                  t	        dj                  |j                   j                  | j                  j                  d«      «      «      «       y| j                  j                  dd«      }| j                  «       j                  |«       y)z~
        Called when the process has ended.

        @param reason: a Failure giving the reason for the process' end.
        r   zexit code was not 0: {} ({})Úcharmaps   
rS   N)ÚvalueÚexitCoderd   Úerrbackr   Úformatrj   Údecoderg   ÚreplaceÚcallback)r9   rP   rg   s      r)   ÚprocessEndedz$ConchTestOpenSSHProcess.processEnded¡   s‘   € ð �<‰<× Ñ  AÒ%Ø×ÑÓ×'Ñ'ÜØ2×9Ñ9ØŸ™×-Ñ-ØŸ™×,Ñ,¨YÓ7óóõð —(‘(×"Ñ" 7¨EÓ2ˆCØ×ÑÓ×(Ñ(¨Õ-r(   )r$   r%   r&   r;   ra   rg   rj   rd   rh   rk   ru   r'   r(   r)   r]   r]   Š   s,   „ ñð €HØ
€CØ€Hòòòó.r(   r]   c                   óD   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zy)ÚConchTestForwardingProcessaæ  
    Manages a third-party process which launches a server.

    Uses L{ConchTestForwardingPort} to connect to the third-party server.
    Once L{ConchTestForwardingPort} has disconnected, kill the process and fire
    a Deferred with the data received by the L{ConchTestForwardingPort}.

    @ivar deferred: Set by whatever uses this object. Accessed using
    L{_getDeferred}, which destroys the value so the Deferred is not
    fired twice. Fires when the process is terminated.
    Nc                 ó.   — || _         d| _        || _        y)aF  
        @type port: L{int}
        @param port: The port on which the third-party server is listening.
        (it is assumed that the server is running on localhost).

        @type data: L{str}
        @param data: This is sent to the third-party server. Must end with '
'
        in order to trigger a disconnect.
        N)ÚportÚbufferrX   )r9   ry   rX   s      r)   Ú__init__z#ConchTestForwardingProcess.__init__Ä   s   € ð ˆŒ	ØˆŒØˆ�	r(   c                 ó.   — | j                   d c}| _         |S r_   r`   rb   s     r)   rd   z'ConchTestForwardingProcess._getDeferredÒ   re   r(   c                 ó$   — | j                  «        y r_   )Ú_connectr8   s    r)   rL   z)ConchTestForwardingProcess.connectionMadeÖ   s   € Ø�‰�r(   c                 óÈ   — t        j                  t        t        | | j                  «      }|j                  d| j                  «      }|j                  | j                  «       |S )a  
        Connect to the server, which is often a third-party process.
        Tries to reconnect if it fails because we have no way of determining
        exactly when the port becomes available for listening -- we can only
        know when the process starts.
        ú	127.0.0.1)	r   ÚClientCreatorr   ÚConchTestForwardingPortrX   Ú
connectTCPry   Ú
addErrbackÚ
_ebConnect)r9   Úccrc   s      r)   r~   z#ConchTestForwardingProcess._connectÙ   sH   € ô ×#Ñ#¤GÔ-DÀdÈDÏIÉIÓVˆØ�M‰M˜+ t§y¡yÓ1ˆØ	�‰�T—_‘_Ô%Øˆr(   c                 óD   — t        j                  d| j                  «       y )Ngš™™™™™¹?)r   Ú	callLaterr~   )r9   Úfs     r)   r…   z%ConchTestForwardingProcess._ebConnectå   s   € Ü×Ñ˜#˜tŸ}™}Õ-r(   c                 ó¼   — || _         | j                  j                  d«       | j                  j                  «        t	        j
                  d| j                  «       y)zÖ
        The network connection has died; save the buffer of output
        from the network and attempt to quit the process gracefully,
        and then (after the reactor has spun) send it a KILL signal.
        ó   r   N)rz   rT   rU   rV   r   rˆ   Ú
_reallyDie)r9   rz   s     r)   ÚforwardingPortDisconnectedz5ConchTestForwardingProcess.forwardingPortDisconnectedè   sA   € ð ˆŒØ�‰×Ñ˜WÔ%Ø�‰×%Ñ%Ô'Ü×Ñ˜!˜TŸ_™_Õ-r(   c                 óZ   — 	 | j                   j                  d«       y # t        $ r Y y w xY w)NÚKILL)rT   ÚsignalProcessr   r8   s    r)   rŒ   z%ConchTestForwardingProcess._reallyDieó   s+   € ð	Ø�N‰N×(Ñ(¨Õ0øÜ#ò 	Ùð	ús   ‚ ž	*©*c                 óV   — | j                  «       j                  | j                  «       y)zŒ
        Fire the Deferred at self.deferred with the data collected
        from the L{ConchTestForwardingPort} connection, if any.
        N)rd   rt   rz   rO   s     r)   ru   z'ConchTestForwardingProcess.processEndedù   s   € ð
 	×ÑÓ×$Ñ$ T§[¡[Õ1r(   )r$   r%   r&   r;   ra   r{   rd   rL   r~   r…   r�   rŒ   ru   r'   r(   r)   rw   rw   µ   s6   „ ñ
ð €Hòòòò
ò.ò	.òó2r(   rw   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)r‚   zë
    Connects to server launched by a third-party process (managed by
    L{ConchTestForwardingProcess}) sends data, then reports whatever it
    received back to the L{ConchTestForwardingProcess} once the connection
    is ended.
    c                 ó    — || _         || _        y)zè
        @type protocol: L{ConchTestForwardingProcess}
        @param protocol: The L{ProcessProtocol} which made this connection.

        @type data: str
        @param data: The data to be sent to the third-party server.
        N)r   rX   )r9   r   rX   s      r)   r{   z ConchTestForwardingPort.__init__	  s   € ð !ˆŒØˆ�	r(   c                 ó\   — d| _         | j                  j                  | j                  «       y )Nr(   )rz   rT   rU   rX   r8   s    r)   rL   z&ConchTestForwardingPort.connectionMade  s   € ØˆŒØ�‰×Ñ˜TŸY™YÕ'r(   c                 ó.   — | xj                   |z  c_         y r_   )rz   rW   s     r)   rY   z$ConchTestForwardingPort.dataReceived  s   € Ø�Š�tÑŽr(   c                 óN   — | j                   j                  | j                  «       y r_   )r   r�   rz   rO   s     r)   rQ   z&ConchTestForwardingPort.connectionLost  s   € Ø�‰×0Ñ0°·±Õ=r(   N)r$   r%   r&   r;   r{   rL   rY   rQ   r'   r(   r)   r‚   r‚     s   „ ñò	ò(òó>r(   r‚   c                 ó¾   — t         j                  d|z  g}g }|t        | «      z   D ]4  }t        |t        «      r|j                  d«      }|j                  |«       Œ6 |S )Na$  -c
### Twisted Preamble
import sys, os
path = os.path.abspath(sys.argv[0])
while os.path.dirname(path) != path:
    if os.path.basename(path).startswith('Twisted'):
        sys.path.insert(0, path)
        break
    path = os.path.dirname(path)

from twisted.conch.scripts.%s import run
run()úutf-8)ÚsysÚ
executableÚlistÚ
isinstanceÚstrÚencodeÚappend)ÚargsÚmodÚstartÚmadeArgsÚargs        r)   Ú	_makeArgsr¥     si   € ä�‰ð		ð ñ	ð€Eð" €HØ”t˜D“zÑ!ò ˆÜ�cœ3ÔØ—*‘*˜WÓ%ˆCØ�‰˜Õðð €Or(   c                   óB   — e Zd ZesdZed„ «       Zd„ Zd„ Zd„ Z	d„ Z
d„ Zy)	ÚConchServerSetupMixinzcan't run without cryptographyc                  ó   — t        d«      S )Ns   testuserr   r'   r(   r)   ÚrealmFactoryz"ConchServerSetupMixin.realmFactory=  s   € ä˜kÓ*Ð*r(   c                 óš  — dD ]7  }t         j                  j                  |«      sŒ#t        j                  |«       Œ9 t	        dd«      5 }|j                  t        «       d d d «       t	        dd«      5 }|j                  t        «       d d d «       t	        dd«      5 }|j                  t        «       d d d «       t	        dd«      5 }|j                  t        «       d d d «       t        j                  dd«       t        j                  dd«       t        d«      j                  «       }|j                  j                  s|j                  j                  rt!        d«      ‚t	        d	d«      5 }|j                  d
t        z   «       d d d «       y # 1 sw Y   �Œ2xY w# 1 sw Y   �ŒxY w# 1 sw Y   Œ÷xY w# 1 sw Y   ŒÙxY w# 1 sw Y   y xY w)N)Úrsa_testúrsa_test.pubÚdsa_testúdsa_test.pubÚkh_testr«   Úwbr¬   r®   r­   i€  zgprivate key readable by others despite chmod; possible windows permission issue? see https://tm.tl/9767r¯   s
   127.0.0.1 )ÚosÚpathÚexistsÚremoveÚopenrU   r   r
   r	   r   Úchmodr   ÚgetPermissionsÚgroupÚreadÚotherr   )r9   r‰   Úpermissionss      r)   Ú_createFilesz"ConchServerSetupMixin._createFilesA  s~  € ØTò 	ˆAÜ�w‰w�~‰~˜aÕ Ü—	‘	˜!•ð	ô �*˜dÓ#ð 	( qØ�G‰GÔ&Ô'÷	(ä�. $Ó'ð 	'¨1Ø�G‰GÔ%Ô&÷	'ä�. $Ó'ð 	'¨1Ø�G‰GÔ%Ô&÷	'ä�*˜dÓ#ð 	( qØ�G‰GÔ&Ô'÷	(ä
�‰�˜UÔ#Ü
�‰�˜UÔ#Ü˜zÓ*×9Ñ9Ó;ˆØ×Ñ×!Ò! [×%6Ñ%6×%;Ò%;Üð*óð ô
 �)˜TÓ"ð 	7 aØ�G‰G�MÔ$5Ñ5Ô6÷	7ð 	7÷#	(ñ 	(ú÷	'ñ 	'ú÷	'ð 	'ú÷	(ð 	(ú÷	7ð 	7ús<   Á	FÁ3FÂF)ÃF5Å-GÆFÆF&Æ)F2Æ5F>ÇG
c                 ó–   — t        j                   «       }|j                  d«       |j                  «       d   }|j                  «        |S )N)Ú r   é   )r,   r.   Úgetsocknamer0   )r9   Úsry   s      r)   Ú_getFreePortz"ConchServerSetupMixin._getFreePortY  s6   € Ü�M‰M‹OˆØ	�‰ˆwŒØ�}‰}‹˜qÑ!ˆØ	�‰Œ	Øˆr(   c                 ó¤   — | j                  «       }t        j                  |«      }|j                  t	        «       «       t        «       }||_        |S )zŽ
        Make a L{ConchTestServerFactory}, which allows us to start a
        L{ConchTestServer} -- i.e. an actually listening conch.
        )r©   r   ÚPortalÚregisterCheckerr   r   )r9   ÚrealmÚpÚfactorys       r)   Ú_makeConchFactoryz'ConchServerSetupMixin._makeConchFactory`  sF   € ð
 ×!Ñ!Ó#ˆÜ�M‰M˜%Ó ˆØ	×ÑÔ3Ó5Ô6Ü(Ó*ˆØˆŒØˆr(   c                 ó   — | j                  «        | j                  «       | _        d| j                  _        t	        j
                  d| j                  d¬«      | _        t	        j
                  dt        «       «      | _        | j                  j                  «       j                  | _        t        rOt	        j
                  dt        «       d¬«      | _        | j                  j                  «       j                  | _        y y )Nr¿   r   r€   )Ú	interfacer+   )r¼   rÉ   ÚconchFactoryÚexpectedLoseConnectionr   Ú	listenTCPÚconchServerr[   Ú
echoServerÚgetHostry   ÚechoPortÚHAS_IPV6ÚechoServerV6Ú
echoPortV6r8   s    r)   ÚsetUpzConchServerSetupMixin.setUpl  s¼   € Ø×ÑÔØ ×2Ñ2Ó4ˆÔØ34ˆ×ÑÔ0Ü"×,Ñ,Øˆt× Ñ ¨Kô
ˆÔô "×+Ñ+¨A¬{«}Ó=ˆŒØŸ™×/Ñ/Ó1×6Ñ6ˆŒÝÜ '× 1Ñ 1°!´[³]ÈeÔ TˆDÔØ"×/Ñ/×7Ñ7Ó9×>Ñ>ˆD�Oð r(   c                 óþ  — 	 d| j                   j                  _        | j                   j                  j                  j	                  «        t        j                  | j                  j                  «      t        j                  | j                  j                  «      g}t        r8|j                  t        j                  | j                  j                  «      «       t        j                  |«      S # t
        $ r Y Œ°w xY w)Nr¿   )rÌ   ÚprotoÚdonerT   rV   ÚAttributeErrorr   ÚmaybeDeferredrÏ   ÚstopListeningrÐ   rÓ   rŸ   rÔ   ÚgatherResults)r9   Ú	deferredss     r)   ÚtearDownzConchServerSetupMixin.tearDowny  sÃ   € ð	?Ø+,ˆD×Ñ×#Ñ#Ô(ð ×Ñ×#Ñ#×-Ñ-×<Ñ<Ô>ä×Ñ × 0Ñ 0× >Ñ >Ó?Ü×Ñ §¡× =Ñ =Ó>ð
ˆ	õ Ø×ÑœU×0Ñ0°×1BÑ1B×1PÑ1PÓQÔRÜ×"Ñ" 9Ó-Ð-øô ò 	Ùð	ús   ‚C0 Ã0	C<Ã;C<N)r$   r%   r&   r   rF   Ústaticmethodr©   r¼   rÂ   rÉ   rÖ   rß   r'   r(   r)   r§   r§   9  s5   „ ÙØ/ˆàñ+ó ð+ò7ò0ò
ò?ó.r(   r§   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚForwardingMixinaÏ  
    Template class for tests of the Conch server's ability to forward arbitrary
    protocols over SSH.

    These tests are integration tests, not unit tests. They launch a Conch
    server, a custom TCP server (just an L{EchoProtocol}) and then call
    L{execute}.

    L{execute} is implemented by subclasses of L{ForwardingMixin}. It should
    cause an SSH client to connect to the Conch server, asking it to forward
    data to the custom TCP server.
    c                 ón   — | j                  dt        «       «      }|j                  | j                  d«      S )z³
        Test that we can use whatever client to send the command "echo goodbye"
        to the Conch server. Make sure we receive "goodbye" back from the
        server.
        úecho goodbyeó   goodbye
©Úexecuter]   ÚaddCallbackÚassertEqualrb   s     r)   Ú	test_execzForwardingMixin.test_exec—  s/   € ð �L‰L˜Ô)@Ó)BÓCˆØ�}‰}˜T×-Ñ-¨|Ó<Ð<r(   c                 ó¼   — | j                  «       }t        |d«      }| j                  d|d|| j                  fz  ¬«      }|j	                  | j
                  d«       |S )zy
        Test that we can use whatever client to forward a local port to a
        specified port on the server.
        ó   test
r¾   z-N -L%i:127.0.0.1:%i©ÚsshArgs©rÂ   rw   rç   rÒ   rè   ré   ©r9   Ú	localPortÚprocessrc   s       r)   Útest_localToRemoteForwardingz,ForwardingMixin.test_localToRemoteForwarding   sb   € ð
 ×%Ñ%Ó'ˆ	Ü,¨Y¸	ÓBˆØ�L‰LØ�Ð!7¸9ÀdÇmÁmÐ:TÑ!Tð ó 
ˆð 	
�‰�d×&Ñ&¨	Ô2Øˆr(   c                 ó¼   — | j                  «       }t        |d«      }| j                  d|d|| j                  fz  ¬«      }|j	                  | j
                  d«       |S )zs
        Test that we can use whatever client to forward a port from the server
        to a port locally.
        rì   r¾   z-N -R %i:127.0.0.1:%irí   rï   rð   s       r)   Útest_remoteToLocalForwardingz,ForwardingMixin.test_remoteToLocalForwarding­  sb   € ð
 ×%Ñ%Ó'ˆ	Ü,¨Y¸	ÓBˆØ�L‰LØ�Ð!8¸IÀtÇ}Á}Ð;UÑ!Uð ó 
ˆð 	
�‰�d×&Ñ&¨	Ô2Øˆr(   N)r$   r%   r&   r;   rê   ró   rõ   r'   r(   r)   râ   râ   ‰  s   „ ñò=òór(   râ   c                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
ÚRekeyAvatara#  
    This avatar implements a shell which sends 60 numbered lines to whatever
    connects to it, then closes the session with a 0 exit status.

    60 lines is selected as being enough to send more than 2kB of traffic, the
    amount the client is configured to initiate a rekey after.
    c                 óT   — t        j                  | «       t        | j                  d<   y )Ns   session)r   r{   r!   ÚchannelLookupr8   s    r)   r{   zRekeyAvatar.__init__É  s    € Ü×Ñ˜4Ô Ü)3ˆ×Ñ˜:Ò&r(   c                 óÜ   ‡‡— t        j                  «       }|j                  ‰«       ‰j                  t        |«      «       ˆˆfd„}t	        |t        «       «      Š‰j                  d«       y)zE
        Write 60 lines of data to the transport, then exit.
        c                 ó  •— t        | «      }|dk(  rR‰j                  «        ‰j                  j                  j	                  ‰j                  dd«       ‰j                  «        y d|fz  }|j                  d«      }‰j                  |«       y )Né<   s   exit-statuss       zline #%02d
r˜   )ÚnextÚstopÚsessionÚconnÚsendRequestrV   rž   rU   )ÚcounterÚiÚlineÚcallrT   s      €€r)   rU   z$RekeyAvatar.openShell.<locals>.write×  sx   ø€ Ü�W“ˆAØ�BŠwØ—	‘	”Ø×!Ñ!×&Ñ&×2Ñ2Ø×%Ñ% ~Ð7Jôð ×(Ñ(Õ*à%¨¨Ñ,�Ø—{‘{ 7Ó+�Ø—‘ Õ%r(   g{®Gáz„?N)r   ÚProtocolÚmakeConnectionr"   r   r   r¢   )r9   rT   rØ   rU   r  s    `  @r)   Ú	openShellzRekeyAvatar.openShellÍ  sU   ù€ ô ×!Ñ!Ó#ˆØ×Ñ˜YÔ'Ø× Ñ ¤¨eÓ!4Ô5õ	&ô( ˜5¤%£'Ó*ˆØ�
‰
�4Õr(   c                  ó   — y)z2
        Ignore the close of the session.
        Nr'   r8   s    r)   ÚclosedzRekeyAvatar.closedî  ó   � r(   c                  ó   — y r_   r'   r8   s    r)   rA   zRekeyAvatar.eofReceivedó  ó   € àr(   c                  ó   — y r_   r'   )r9   rØ   Úcommands      r)   ÚexecCommandzRekeyAvatar.execCommand÷  r  r(   c                  ó   — y r_   r'   )r9   ÚtermÚ
windowSizeÚmodess       r)   ÚgetPtyzRekeyAvatar.getPtyû  r  r(   c                  ó   — y r_   r'   )r9   ÚnewWindowSizes     r)   ÚwindowChangedzRekeyAvatar.windowChangedÿ  r  r(   N)r$   r%   r&   r;   r{   r  r
  rA   r  r  r  r'   r(   r)   r÷   r÷   ¿  s+   „ ñò4òòBò
òòór(   r÷   c                   ó   — e Zd ZdZd„ Zy)Ú
RekeyRealmzS
    This realm gives out new L{RekeyAvatar} instances for any avatar request.
    c                 ó$   — |d   t        «       d„ fS )Nr   c                   ó   — y r_   r'   r'   r(   r)   ú<lambda>z*RekeyRealm.requestAvatar.<locals>.<lambda>
  r  r(   )r÷   )r9   ÚavatarIDÚmindÚ
interfacess       r)   ÚrequestAvatarzRekeyRealm.requestAvatar	  s   € Ø˜!‰}œk›m©\Ð9Ð9r(   N)r$   r%   r&   r;   r!  r'   r(   r)   r  r    s   „ ñó:r(   r  c                   ó   — e Zd ZdZeZd„ Zy)ÚRekeyTestsMixinzp
    TestCase mixin which defines tests exercising L{SSHTransportBase}'s handling
    of rekeying messages.
    c                 ón   ‡ — t        «       }‰ j                  d|d«      }ˆ fd„}|j                  |«       |S )z‡
        After a client-initiated rekey is completed, application data continues
        to be passed over the SSH connection.
        r¾   z-o RekeyLimit=2Kc                 ó´   •— dj                  t        d«      D �cg c]  }d|fz  ‘Œ
 c}«      dz   }|j                  d«      }‰j                  | |«       y c c}w )Nú
rü   z
line #%02dr˜   )ÚjoinÚrangerž   ré   )Úresultr  ÚexpectedResultr9   s      €r)   Úfinishedz2RekeyTestsMixin.test_clientRekey.<locals>.finished  sS   ø€ Ø!ŸY™YÄUÈ2ÃYÖ'OÀ¨¸°tÓ(;Ò'OÓPÐSWÑWˆNØ+×2Ñ2°7Ó;ˆNØ×Ñ˜V ^Õ4ùò (Ps   šA)r]   rç   rè   )r9   rò   rc   r+  s   `   r)   Útest_clientRekeyz RekeyTestsMixin.test_clientRekey  s8   ø€ ô
 *Ó+ˆØ�L‰L˜˜WÐ&8Ó9ˆô	5ð
 	
�‰�hÔØˆr(   N)r$   r%   r&   r;   r  r©   r,  r'   r(   r)   r#  r#    s   „ ñð
 €Lór(   r#  c                   ó(   — e Zd Z ed«      sdZdd„Zy)ÚOpenSSHClientMixinÚsshz$no ssh command-line client availablec                 ól   ‡ ‡‡‡— t        t        d«      d   d«      }ˆˆˆ ˆfd„}|j                  |«      S )a¸  
        Connects to the SSH server started in L{ConchServerSetupMixin.setUp} by
        running the 'ssh' command line tool.

        @type remoteCommand: str
        @param remoteCommand: The command (with arguments) to run on the
        remote end.

        @type process: L{ConchTestOpenSSHProcess}

        @type sshArgs: str
        @param sshArgs: Arguments to pass to the 'ssh' process.

        @return: L{defer.Deferred}
        r/  r   )z-ozPubkeyAcceptedKeyTypes=ssh-dssz-Vc                 ó¨  •— | dk(  rd}nd}t        j                  «       ‰_        d|z   ‰
z   dz   ‰z   }‰	j                  j	                  «       j
                  }||z  j                  «       }g }|D ]4  }t        |t        «      r|j                  d«      }|j                  |«       Œ6 t        j                  ‰t        d«      d   |«       ‰j                  S )Nr   z!-oPubkeyAcceptedKeyTypes=ssh-dss r¾   zŠssh -2 -l testuser -p %i -F /dev/null -oUserKnownHostsFile=kh_test -oPasswordAuthentication=no -oHostKeyAlgorithms=ssh-rsa -a -i dsa_test ú 127.0.0.1 r˜   r/  )r   ÚDeferredra   rÏ   rÑ   ry   Úsplitrœ   r�   rž   rŸ   r   ÚspawnProcessr   )ÚstatusÚoptsÚcmdlinery   ÚcmdsÚencodedCmdsÚcmdrò   ÚremoteCommandr9   rî   s          €€€€r)   ÚhasPAKTz+OpenSSHClientMixin.execute.<locals>.hasPAKTB  så   ø€ Ø˜Š{Ø:‘à�ä$Ÿ~™~Ó/ˆGÔð#ð ñ
ð ñð  ñ ð  ñ ð ð  ×#Ñ#×+Ñ+Ó-×2Ñ2ˆDØ˜d‘N×)Ñ)Ó+ˆDØˆKØò (�Ü˜c¤3Ô'ØŸ*™* WÓ-�CØ×"Ñ" 3Õ'ð(ô × Ñ  ¬%°«,°q©/¸;ÔGØ×#Ñ#Ð#r(   )r   r   rè   )r9   r<  rò   rî   rc   r=  s   ````  r)   rç   zOpenSSHClientMixin.execute*  s4   û€ ô( Ü�%‹L˜‰OÐKó
ˆ÷"	$ðH �}‰}˜WÓ%Ð%r(   N)r¾   )r$   r%   r&   r   rF   rç   r'   r(   r)   r.  r.  &  s   „ Ù�Œ<Ø5ˆô<&r(   r.  c                   ó@   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zy
)ÚOpenSSHKeyExchangeTestsz\
    Tests L{SSHTransportBase}'s key exchange algorithm compatibility with
    OpenSSH.
    c                 óˆ  — g }	 t        j                  t        d«      d   ddgt         j                  ¬«      }t	        |t
        «      s|j                  d«      }|j                  «       }||vrt        |› d�«      ‚| j                  dt        «       d	|z   «      }|j                  | j                  d
«      S # t        $ r Y ŒWw xY w)aI  
        Call execute() method of L{OpenSSHClientMixin} with an ssh option that
        forces the exclusive use of the key exchange algorithm specified by
        keyExchangeAlgo

        @type keyExchangeAlgo: L{str}
        @param keyExchangeAlgo: The key exchange algorithm to use

        @return: L{defer.Deferred}
        r/  r   z-QÚkex)Ústderrr˜   z not supported by ssh clientz
echo helloz-oKexAlgorithms=s   hello
)Ú
subprocessÚcheck_outputr   ÚSTDOUTrœ   r�   rr   r4  ÚBaseExceptionr   rç   r]   rè   ré   )r9   ÚkeyExchangeAlgoÚkexAlgorithmsÚoutputrc   s        r)   ÚassertExecuteWithKexAlgorithmz5OpenSSHKeyExchangeTests.assertExecuteWithKexAlgorithmo  sÇ   € ð ˆð	Ü×,Ñ,Ü�u“˜a‘ $¨Ð.´z×7HÑ7HôˆFô ˜f¤cÔ*ØŸ™ wÓ/�Ø"ŸL™L›NˆMð  -Ñ/Ü˜oÐ.Ð.JÐKÓLÐLà�L‰LØÜ#Ó%Ø Ñ0ó
ˆð
 �}‰}˜T×-Ñ-¨zÓ:Ð:øô ò 	Ùð	ús   „A%B5 Â5	CÃ Cc                 ó$   — | j                  d«      S )zb
        The ecdh-sha2-nistp256 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp256©rJ  r8   s    r)   Útest_ECDHSHA256z'OpenSSHKeyExchangeTests.test_ECDHSHA256�  ó   € ð
 ×1Ñ1Ð2FÓGÐGr(   c                 ó$   — | j                  d«      S )zb
        The ecdh-sha2-nistp384 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp384rL  r8   s    r)   Útest_ECDHSHA384z'OpenSSHKeyExchangeTests.test_ECDHSHA384–  rN  r(   c                 ó$   — | j                  d«      S )zb
        The ecdh-sha2-nistp521 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp521rL  r8   s    r)   Útest_ECDHSHA521z'OpenSSHKeyExchangeTests.test_ECDHSHA521�  rN  r(   c                 ó$   — | j                  d«      S )zl
        The diffie-hellman-group14-sha1 key exchange algorithm is compatible
        with OpenSSH.
        zdiffie-hellman-group14-sha1rL  r8   s    r)   Útest_DH_GROUP14z'OpenSSHKeyExchangeTests.test_DH_GROUP14¤  s   € ð
 ×1Ñ1Ð2OÓPÐPr(   c                 ó$   — | j                  d«      S )zs
        The diffie-hellman-group-exchange-sha1 key exchange algorithm is
        compatible with OpenSSH.
        z"diffie-hellman-group-exchange-sha1rL  r8   s    r)   Útest_DH_GROUP_EXCHANGE_SHA1z3OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA1«  s   € ð
 ×1Ñ1Ð2VÓWÐWr(   c                 ó$   — | j                  d«      S )zu
        The diffie-hellman-group-exchange-sha256 key exchange algorithm is
        compatible with OpenSSH.
        z$diffie-hellman-group-exchange-sha256rL  r8   s    r)   Útest_DH_GROUP_EXCHANGE_SHA256z5OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA256²  s   € ð
 ×1Ñ1Ø2ó
ð 	
r(   c                 óF   — | j                  t        | j                  d«       y)zy
        The list of key exchange algorithms supported
        by OpenSSH client is obtained with C{ssh -Q kex}.
        zunsupported-algorithmN)ÚassertRaisesr   rJ  r8   s    r)   Útest_unsupported_algorithmz2OpenSSHKeyExchangeTests.test_unsupported_algorithm»  s    € ð
 	×ÑÜ�d×8Ñ8Ð:Qõ	
r(   N)r$   r%   r&   r;   rJ  rM  rP  rR  rT  rV  rX  r[  r'   r(   r)   r?  r?  i  s5   „ ñò
;ò@HòHòHòQòXò
ó
r(   r?  c                   ó0   — e Zd ZdZ ee d«      d„ «       Zy)ÚOpenSSHClientForwardingTestszR
    Connection forwarding tests run against the OpenSSL command line client.
    zRequires IPv6 supportc                 ó¼   — | j                  «       }t        |d«      }| j                  d|d|| j                  fz  ¬«      }|j	                  | j
                  d«       |S )zG
        Forwarding of arbitrary IPv6 TCP connections via SSH.
        rì   r¾   z-N -L%i:[::1]:%irí   )rÂ   rw   rç   rÕ   rè   ré   rð   s       r)   Útest_localToRemoteForwardingV6z;OpenSSHClientForwardingTests.test_localToRemoteForwardingV6Ê  sb   € ð
 ×%Ñ%Ó'ˆ	Ü,¨Y¸	ÓBˆØ�L‰LØ�Ð!3°yÀ$Ç/Á/Ð6RÑ!Rð ó 
ˆð 	
�‰�d×&Ñ&¨	Ô2Øˆr(   N)r$   r%   r&   r;   r   rÓ   r_  r'   r(   r)   r]  r]  Å  s%   „ ññ �ˆLÐ1Ó2ñ
ó 3ñ
r(   r]  c                   ó   — e Zd ZdZy)ÚOpenSSHClientRekeyTestszE
    Rekeying tests run against the OpenSSL command line client.
    N)r$   r%   r&   r;   r'   r(   r)   ra  ra  Ø  s   „ òr(   ra  c                   óF   — e Zd ZdZej
                  dk(  rdZdd„Zd„ Zd„ Z	y)	ÚCmdLineClientTestszP
    Connection forwarding tests run against the Conch command line client.
    Úwin32z!can't run cmdline client on win32Nc                 ó  — |€g }t        j                  «       |_        | j                  j	                  «       j
                  }dj                  |«      |z   dz   |z   }t        ||j                  «       z   «      }t        j                  j                  «       }t        j                  j                  t        j                  «      |d<   g }	i }
|D ]4  }t!        |t"        «      r|j%                  d«      }|	j'                  |«       Œ6 |D ]N  }||   }t!        |t"        «      r|j%                  d«      }t!        |t"        «      r|j%                  d«      }||
|<   ŒP t)        j*                  |t        j,                  |	|
¬«       |j                  S )z{
        As for L{OpenSSHClientTestCase.execute}, except it runs the 'conch'
        command line tool, not 'ssh'.
        z[-p {} -l testuser --known-hosts kh_test --user-authentications publickey -a -i dsa_test -v r2  Ú
PYTHONPATHr˜   )Úenv)r   r3  ra   rÏ   rÑ   ry   rq   r¥   r4  r±   ÚenvironÚcopyÚpathsepr'  r™   r²   rœ   r�   rž   rŸ   r   r5  rš   )r9   r<  rò   rî   Ú	conchArgsry   r;  r9  rg  r:  Ú
encodedEnvÚvarÚvals                r)   rç   zCmdLineClientTests.executeæ  sd  € ð
 ÐØˆIä Ÿ>™>Ó+ˆÔØ×Ñ×'Ñ'Ó)×.Ñ.ˆð÷
 ‘&˜“, ñ)ð
 ,9ñ9ð
 <IñIð 	ô ˜ S§Y¡Y£[Ñ0Ó1ˆÜ�j‰j�o‰oÓˆÜŸJ™JŸO™O¬C¯H©HÓ5ˆˆLÑØˆØˆ
Øò 	$ˆCÜ˜#œsÔ#Ø—j‘j Ó)�Ø×Ñ˜sÕ#ð	$ð ò 	"ˆCØ�c‘(ˆCÜ˜#œsÔ#Ø—j‘j Ó)�Ü˜#œsÔ#Ø—j‘j Ó)�Ø!ˆJ�sŠOð	"ô 	×Ñ˜W¤c§n¡n°kÀzÕRØ×ÑÐr(   c           	      ó  ‡ ‡— ˆˆ fd„}t        j                  ‰ j                  «       «      Š‰ j                  dt	        «       dd‰j
                  ddg¬«      }|j                  ‰ j                  d«       |j                  |«       |S )	z4
        It can store logs to a local file.
        c                 óJ   •— ‰j                  «       }‰j                  d|«       y )Ns   Log opened.)Ú
getContentÚassertIn)r)  Ú
logContentÚlogPathr9   s     €€r)   Úcb_check_logz<CmdLineClientTests.test_runWithLogFile.<locals>.cb_check_log  s   ø€ Ø ×+Ñ+Ó-ˆJØ�M‰M˜.¨*Õ5r(   rä   z--logz	--logfilez--host-key-algorithmszssh-rsa)r<  rò   rk  rå   )r   r   Úmktemprç   r]   r²   rè   ré   )r9   ru  rc   rt  s   `  @r)   Útest_runWithLogFilez&CmdLineClientTests.test_runWithLogFile  s{   ù€ õ
	6ô ×#Ñ# D§K¡K£MÓ2ˆà�L‰LØ(Ü+Ó-àØØ—‘Ø'Øðð ó 

ˆð 	
�‰�d×&Ñ&¨Ô5Ø	�‰�lÔ#Øˆr(   c                 ót   — | j                  dt        «       ¬«      }|j                  | j                  d«       |S )zH
        Do not use --host-key-algorithms flag on command line.
        rä   )r<  rò   rå   ræ   rb   s     r)   Ú%test_runWithNoHostAlgorithmsSpecifiedz8CmdLineClientTests.test_runWithNoHostAlgorithmsSpecified&  s;   € ð �L‰LØ(Ô2IÓ2Kð ó 
ˆð 	
�‰�d×&Ñ&¨Ô5Øˆr(   )r¾   N)
r$   r%   r&   r;   r   ÚplatformTyperF   rç   rw  ry  r'   r(   r)   rc  rc  Þ  s,   „ ñð ×Ñ˜wÒ&Ø2ˆó# òJó6	r(   rc  )Úconch)Tr±   r,   rC  r™   Ú	itertoolsr   Úunittestr   Úzope.interfacer   Útwisted.conch.errorr   Útwisted.conch.test.keydatar   r   r	   r
   Útwisted.conch.test.test_sshr   Útwisted.credr   Útwisted.internetr   r   r   Útwisted.internet.errorr   Útwisted.internet.taskr   Útwisted.internet.utilsr   Útwisted.pythonr   r   r   Útwisted.python.filepathr   Útwisted.python.procutilsr   Útwisted.python.reflectr   Útwisted.trial.unittestr   r   r   r   ÚImportErrorr   Útwisted.conch.avatarr   Útwisted.conch.ssh.sessionr    r!   r"   Útwisted.conch.interfacesÚtwisted.conch.scripts.conchÚ_StdioInteractingSessionr?   Úer�   rE   r3   rÓ   r5   r=   r  rH   ÚFactoryr[   ÚProcessProtocolr]   rw   r‚   r¥   r§   râ   r÷   r  r#  r.  r?  r]  ra  rc  r'   r(   r)   ú<module>r•     sú  ðó
 
Û Û Û 
Ý Ý å &å *÷ó õ 7Ý ß 5Ñ 5Ý 7Ý -Ý 2ß 1Ñ 1Ý ,Ý *Ý 0ß 5ð	÷ñ ˜^Ó,€áÝ.ßLÒLå1÷ñ ð7ÝRð 7Ðòñ" ‹;€÷"ñ "ô$- 8ô -ô(
,ˆ8×Ñô 
,ô�(×"Ñ"ô ô(.˜h×6Ñ6ô (.ôVI2 ×!9Ñ!9ô I2ôX>˜h×/Ñ/ô >ó<÷4M.ñ M.ô`/Ð+ô /ñl ˆXÓôA�)ó Aó ðA÷H:ñ :ôÐ+ô ÷2@&ñ @&ôFY
Ð3Ð5GÈô Y
ôx ?Ð4FÈô ô&˜oÐ/AÀ8ô ôQ˜¨(õ Qøðq ò 	Úð	ûð" ò 
Ø"ÐÙ�!‹f€GÞ	ûð
ús*   ÂG Â6G ÇGÇGÇG/ÇG*Ç*G/