ó
    Ö›‘h½d  ã                  ó  • S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJrJr  S SKJr  S S	KJr  S S
KJrJr  S SKJrJrJr  S SKJr  S SKJr  S SK J!r!  S SK"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)  S SK*J+r+  S SK,J-r-J.r.  S SK/J0r0J1r1   S SKJ2r2J3r3  \+" S5      r5\5(       a  S SK6J7r7  S SK8J9r9J:r:J;r;  OS SK<J9r9   " S S5      r7 S SK=J:r>  \>r? " S S5      rC " S S \15      rD " S! S"\RŠ                  5      rF " S# S$\RŽ                  5      rH " S% S&\R’                  5      rJ " S' S(\R’                  5      rK " S) S*\RŠ                  5      rLS@SAS+ jjrM " S, S-5      rN " S. S/\N5      rO\" \95       " S0 S1\75      5       rP " S2 S35      rQ " S4 S5\N5      rR " S6 S75      rS " S8 S9\N\S\15      rT " S: S;\O\S\15      rU " S< S=\R\S\15      rV " S> S?\O\15      rWg! \4 a     GNEf = f! \4 a  r@Sr?\A" \@5      rBC@ Sr@C@GN'Sr@C@ff = f)Bé    )ÚannotationsN)Úcount)ÚAny)Úimplementer)Ú
ConchError)ÚprivateRSA_opensshÚpublicRSA_openssh©ÚConchTestRealm)Úportal)ÚprotocolÚreactor)ÚDeferredÚgatherResultsÚmaybeDeferred)ÚProcessExitedAlready)ÚIReactorProcess)ÚLoopingCall)ÚfilepathÚlogÚruntime)ÚFilePath)Úwhich)ÚrequireModule)ÚHAS_IPV6ÚskipWithoutIPv6)ÚSkipTestÚTestCase)ÚConchTestServerFactoryÚconchTestPublicKeyCheckerÚcryptography)Ú	ConchUser)ÚISessionÚ
SSHSessionÚwrapProtocol)r#   c                  ó   • \ rS rSrSrg)r"   é/   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r(   ó    ÚaC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/conch/test/test_conch.pyr"   r"   /   s   † Úr.   r"   )r$   c                  ó"   • \ rS rSrSrSrS rSrg)Ú	FakeStdioé=   zä
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                ó   • SU l         g)z)
Record the call to loseWriteConnection.
TN©ÚwriteConnLost©Úselfs    r/   ÚloseWriteConnectionÚFakeStdio.loseWriteConnectionH   s   € ð "ˆÕr.   r4   N)r)   r*   r+   r,   Ú__doc__r5   r8   r-   r(   r.   r/   r1   r1   =   s   † ñð €Mõ"r.   r1   c                  ó(   • \ rS rSrSr\c  \rS rSr	g)ÚStdioInteractingSessionTestséO   z6
Tests for L{twisted.conch.scripts.conch.SSHSession}.
Nc                óŽ   • [        5       n[        5       nXl        UR                  5         U R	                  UR
                  5        g)ze
L{twisted.conch.scripts.conch.SSHSession.eofReceived} loses the
write half of its stdio connection.
N)r1   ÚStdioInteractingSessionÚstdioÚeofReceivedÚ
assertTruer5   )r7   r@   Úchannels      r/   Útest_eofReceivedÚ-StdioInteractingSessionTests.test_eofReceivedW   s6   € ô
 “ˆÜ)Ó+ˆØŒØ×ÑÔØ�‰˜×+Ñ+Õ,r.   r(   )
r)   r*   r+   r,   r:   r?   Ú_reasonÚskiprD   r-   r(   r.   r/   r<   r<   O   s   † ñð Ñ&Øˆõ	-r.   r<   c                  ó&   • \ rS rSrS rS rS rSrg)ÚEchoéc   c                ó0   • [         R                  " S5        g )NzECHO CONNECTION MADE©r   Úmsgr6   s    r/   ÚconnectionMadeÚEcho.connectionMaded   ó   € Ü�ŠÐ&Õ'r.   c                ó0   • [         R                  " S5        g )NzECHO CONNECTION DONErL   ©r7   Úreasons     r/   ÚconnectionLostÚEcho.connectionLostg   rP   r.   c                ó|   • U R                   R                  U5        SU;   a  U R                   R                  5         g g )Nó   
)Ú	transportÚwriteÚloseConnection©r7   Údatas     r/   ÚdataReceivedÚEcho.dataReceivedj   s0   € Ø�‰×Ñ˜TÔ"Ø�D‹=Ø�N‰N×)Ñ)Õ+ð r.   r(   N)r)   r*   r+   r,   rN   rT   r]   r-   r(   r.   r/   rI   rI   c   s   † ò(ò(õ,r.   rI   c                  ó   • \ rS rSr\rSrg)ÚEchoFactoryép   r(   N)r)   r*   r+   r,   rI   r   r-   r(   r.   r/   r`   r`   p   s   † ØƒHr.   r`   c                  óV   • \ rS rSr% SrSrS\S'   SrSrSr	S\S	'   S
 r
S rS rS rSrg)ÚConchTestOpenSSHProcessét   ap  
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.

@ivar expectedExitCode: If the process exit code is not C{expectedExitCode}
the set C{deferred} will by triggerd with a failure.
NzDeferred[None] | NoneÚdeferredr.   r   ÚintÚexpectedExitCodec                ó,   • U R                   S sol         U$ ©N©re   ©r7   Úds     r/   Ú_getDeferredÚ$ConchTestOpenSSHProcess._getDeferred…   ó   € ØŸ=™=¨$ÐˆŒ=Øˆr.   c                ó.   • U =R                   U-  sl         g ri   )Úbufr[   s     r/   ÚoutReceivedÚ#ConchTestOpenSSHProcess.outReceived‰   s   € Ø�Š�DÑŽr.   c                ó.   • U =R                   U-  sl         g ri   )Úproblemsr[   s     r/   ÚerrReceivedÚ#ConchTestOpenSSHProcess.errReceivedŒ   s   € Ø�Š˜ÑŽr.   c                ó¤  • UR                   R                  U R                  :w  aq  U R                  5       R	                  [        SR                  U R                  UR                   R                  U R                  R                  S5      5      5      5        gU R                  R                  SS5      nU R                  5       R                  U5        g)zf
Called when the process has ended.

@param reason: a Failure giving the reason for the process' end.
zexit code was not {}: {} ({})Úcharmaps   
rW   N)ÚvalueÚexitCoderg   rm   Úerrbackr   Úformatru   Údecoderq   ÚreplaceÚcallback)r7   rS   rq   s      r/   ÚprocessEndedÚ$ConchTestOpenSSHProcess.processEnded�   s    € ð �<‰<× Ñ  D×$9Ñ$9Ó9Ø×ÑÓ×'Ñ'ÜØ3×:Ñ:Ø×-Ñ-ØŸ™×-Ñ-ØŸ™×,Ñ,¨YÓ7óóõð —(‘(×"Ñ" 7¨EÓ2ˆCØ×ÑÓ×(Ñ(¨Õ-r.   rj   )r)   r*   r+   r,   r:   re   Ú__annotations__rq   ru   rg   rm   rr   rv   r�   r-   r(   r.   r/   rc   rc   t   s=   ‡ ñ	ð '+€HÐ#Ó*Ø
€CØ€HØÐ�cÓòòòõ.r.   rc   c                  óL   • \ rS rSrSrSrS rS rS rS r	S r
S	 rS
 rS rSrg)ÚConchTestForwardingProcessé¤   aÆ  
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                ó*   • Xl         SU l        X l        g)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Úbufferr\   )r7   rˆ   r\   s      r/   Ú__init__Ú#ConchTestForwardingProcess.__init__³   s   € ð Œ	ØˆŒØ�	r.   c                ó,   • U R                   S sol         U$ ri   rj   rk   s     r/   rm   Ú'ConchTestForwardingProcess._getDeferredÁ   ro   r.   c                ó$   • U R                  5         g ri   )Ú_connectr6   s    r/   rN   Ú)ConchTestForwardingProcess.connectionMadeÅ   s   € Ø�‰�r.   c                óÈ   • [         R                  " [        [        X R                  5      nUR                  SU R                  5      nUR                  U R                  5        U$ )zæ
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   ÚConchTestForwardingPortr\   Ú
connectTCPrˆ   Ú
addErrbackÚ
_ebConnect)r7   Úccrl   s      r/   r�   Ú#ConchTestForwardingProcess._connectÈ   sF   € ô ×#Ò#¤GÔ-DÀdÏIÉIÓVˆØ�M‰M˜+ t§y¡yÓ1ˆØ	�‰�T—_‘_Ô%Øˆr.   c                óF   • [         R                  " SU R                  5        g )Ngš™™™™™¹?)r   Ú	callLaterr�   )r7   Úfs     r/   r—   Ú%ConchTestForwardingProcess._ebConnectÔ   s   € Ü×Ò˜#˜tŸ}™}Õ-r.   c                ó¼   • Xl         U R                  R                  S5        U R                  R                  5         [        R
                  " SU R                  5        g)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)r‰   rX   rY   rZ   r   r›   Ú
_reallyDie)r7   r‰   s     r/   ÚforwardingPortDisconnectedÚ5ConchTestForwardingProcess.forwardingPortDisconnected×   s?   € ð ŒØ�‰×Ñ˜WÔ%Ø�‰×%Ñ%Ô'Ü×Ò˜!˜TŸ_™_Õ-r.   c                ó\   •  U R                   R                  S5        g ! [         a     g f = f)NÚKILL)rX   ÚsignalProcessr   r6   s    r/   r    Ú%ConchTestForwardingProcess._reallyDieâ   s+   € ð	Ø�N‰N×(Ñ(¨Õ0øÜ#ó 	Ùð	ús   ‚ ž
+ª+c                óV   • U R                  5       R                  U R                  5        g)zt
Fire the Deferred at self.deferred with the data collected
from the L{ConchTestForwardingPort} connection, if any.
N)rm   r€   r‰   rR   s     r/   r�   Ú'ConchTestForwardingProcess.processEndedè   s   € ð
 	×ÑÓ×$Ñ$ T§[¡[Õ1r.   )r‰   r\   re   rˆ   )r)   r*   r+   r,   r:   re   rŠ   rm   rN   r�   r—   r¡   r    r�   r-   r(   r.   r/   r…   r…   ¤   s6   † ñ
ð €Hòòòò
ò.ò	.òõ2r.   r…   c                  ó0   • \ rS rSrSrS rS rS rS rSr	g)	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                ó   • Xl         X l        g)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   r\   )r7   r   r\   s      r/   rŠ   Ú ConchTestForwardingPort.__init__ø   s   € ð !ŒØ�	r.   c                ó\   • SU l         U R                  R                  U R                  5        g )Nr.   )r‰   rX   rY   r\   r6   s    r/   rN   Ú&ConchTestForwardingPort.connectionMade  s   € ØˆŒØ�‰×Ñ˜TŸY™YÕ'r.   c                ó.   • U =R                   U-  sl         g ri   )r‰   r[   s     r/   r]   Ú$ConchTestForwardingPort.dataReceived  s   € Ø�Š�tÑŽr.   c                óN   • U R                   R                  U R                  5        g ri   )r   r¡   r‰   rR   s     r/   rT   Ú&ConchTestForwardingPort.connectionLost
  s   € Ø�‰×0Ñ0°·±Õ=r.   )r‰   r\   r   N)
r)   r*   r+   r,   r:   rŠ   rN   r]   rT   r-   r(   r.   r/   r”   r”   ð   s   † ñò	ò(òõ>r.   r”   c                ó€   • [         R                  SU-  /n/ UQU Q Vs/ s H  o3R                  S5      PM     sn$ s  snf )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Úencode)ÚargsÚmodÚstartÚeachs       r/   Ú	_makeArgsr¼     sH   € ä�‰ð		ð ñ	ð€Eð" .=¨u¨_°t©_Ó=ª_ T�K‰K˜Ö ©_Ñ=Ð=ùÒ=s   ž;c                  óX   • \ rS rSr\(       d  Sr\S 5       rS rS r	S r
S rSS jrS	rg
)ÚConchServerSetupMixini#  zcan't run without cryptographyc                 ó   • [        S5      $ )Ns   testuserr
   r(   r.   r/   ÚrealmFactoryÚ"ConchServerSetupMixin.realmFactory'  s   € ä˜kÓ*Ð*r.   c                óØ  • S H?  n[         R                  R                  U5      (       d  M)  [         R                  " U5        MA     [	        SS5       nUR                  [        5        S S S 5        [	        SS5       nUR                  [        5        S S S 5        [         R                  " SS5        [        S5      R                  5       nUR                  R                  (       d  UR                  R                  (       a  [        S5      e[	        SS5       nUR                  S[        -   5        S S S 5        g ! , (       d  f       N×= f! , (       d  f       N¾= f! , (       d  f       g = f)	N)Úrsa_testúrsa_test.pubÚkh_testrÃ   ÚwbrÄ   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ÚopenrY   r   r	   Úchmodr   ÚgetPermissionsÚgroupÚreadÚotherr   )r7   rœ   Úpermissionss      r/   Ú_createFilesÚ"ConchServerSetupMixin._createFiles+  sù   € Û8ˆAÜ�w‰w�~‰~˜a× Ó Ü—	’	˜!–ñ 9ô �*˜dÔ# qØ�G‰GÔ&Ô'÷ $ä�. $Ô'¨1Ø�G‰GÔ%Ô&÷ (ä
�Š�˜UÔ#Ü˜zÓ*×9Ñ9Ó;ˆØ×Ñ×!×! [×%6Ñ%6×%;×%;Üð*óð ô
 �)˜TÔ" aØ�G‰G�MÔ$5Ñ5Ô6÷ #Ð"÷ $Õ#úç'Õ'ú÷ #Õ"ús$   ÁD9Á<E
ÄEÄ9
EÅ

EÅ
E)c                ó˜   • [         R                   " 5       nUR                  S5        UR                  5       S   nUR                  5         U$ )N)Ú r   é   )ÚsocketÚbindÚgetsocknameÚclose)r7   Úsrˆ   s      r/   Ú_getFreePortÚ"ConchServerSetupMixin._getFreePort>  s6   € Ü�MŠM‹OˆØ	�‰ˆwŒØ�}‰}‹˜qÑ!ˆØ	�‰Œ	Øˆr.   c                ó¤   • U R                  5       n[        R                  " U5      nUR                  [	        5       5        [        5       nX#l        U$ )zv
Make a L{ConchTestServerFactory}, which allows us to start a
L{ConchTestServer} -- i.e. an actually listening conch.
)rÀ   r   ÚPortalÚregisterCheckerr    r   )r7   ÚrealmÚpÚfactorys       r/   Ú_makeConchFactoryÚ'ConchServerSetupMixin._makeConchFactoryE  sD   € ð
 ×!Ñ!Ó#ˆÜ�MŠM˜%Ó ˆØ	×ÑÔ3Ó5Ô6Ü(Ó*ˆØŒØˆr.   c                ó  • U R                  5         U R                  5       U l        SU R                  l        [        R
                  " SU R                  SS9U l        [        R
                  " S[        5       5      U l        U R                  R                  5       R                  U l        [        (       aM  [        R
                  " S[        5       SS9U l        U R                  R                  5       R                  U l        g g )NrÖ   r   r’   )Ú	interfacez::1)rÒ   rä   ÚconchFactoryÚexpectedLoseConnectionr   Ú	listenTCPÚconchServerr`   Ú
echoServerÚgetHostrˆ   ÚechoPortr   ÚechoServerV6Ú
echoPortV6r6   s    r/   ÚsetUpÚConchServerSetupMixin.setUpQ  s¾   € Ø×ÑÔØ ×2Ñ2Ó4ˆÔØ34ˆ×ÑÔ0Ü"×,Ò,Øˆt× Ñ ¨Kñ
ˆÔô "×+Ò+¨A¬{«}Ó=ˆŒØŸ™×/Ñ/Ó1×6Ñ6ˆŒßŠ8Ü '× 1Ò 1°!´[³]ÈeÑ TˆDÔØ"×/Ñ/×7Ñ7Ó9×>Ñ>ˆD�Oð r.   c                óº  •  SU R                   R                  l        U R                   R                  R                  R	                  5         [        U R                  R                  5      [        U R                  R                  5      /n[        (       a.  UR                  [        U R                  R                  5      5        [        U5      $ ! [
         a     NŽf = f)NrÖ   )rè   ÚprotoÚdonerX   rZ   ÚAttributeErrorr   rë   ÚstopListeningrì   r   Úappendrï   r   )r7   Ú	deferredss     r/   ÚtearDownÚConchServerSetupMixin.tearDown^  s­   € ð	?Ø+,ˆD×Ñ×#Ñ#Ô(ð ×Ñ×#Ñ#×-Ñ-×<Ñ<Ô>ä˜$×*Ñ*×8Ñ8Ó9Ü˜$Ÿ/™/×7Ñ7Ó8ð
ˆ	÷ Š8Ø×Ñœ]¨4×+<Ñ+<×+JÑ+JÓKÔLÜ˜YÓ'Ð'øô ó 	Ùð	ús   ‚C Ã
CÃC)rè   rë   rî   rð   rì   rï   N)Úreturnr   )r)   r*   r+   r,   r!   rG   ÚstaticmethodrÀ   rÒ   rÜ   rä   rñ   rú   r-   r(   r.   r/   r¾   r¾   #  s5   † ÞØ/ˆàñ+ó ð+ò7ò&ò
ò?÷(r.   r¾   c                  ó*   • \ rS rSrSrS rS rS rSrg)ÚForwardingMixinio  a«  
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   • U R                  S[        5       5      nUR                  U R                  S5      $ )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
©Úexecuterc   ÚaddCallbackÚassertEqualrk   s     r/   Ú	test_execÚForwardingMixin.test_exec}  s/   € ð �L‰L˜Ô)@Ó)BÓCˆØ�}‰}˜T×-Ñ-¨|Ó<Ð<r.   c                ó´   • U R                  5       n[        US5      nU R                  SUSXR                  4-  S9nUR	                  U R
                  S5        U$ )za
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Ü   r…   r  rî   r  r  ©r7   Ú	localPortÚprocessrl   s       r/   Útest_localToRemoteForwardingÚ,ForwardingMixin.test_localToRemoteForwarding†  s`   € ð
 ×%Ñ%Ó'ˆ	Ü,¨Y¸	ÓBˆØ�L‰LØ�Ð!7¸9ÇmÁmÐ:TÑ!Tð ð 
ˆð 	
�‰�d×&Ñ&¨	Ô2Øˆr.   c                ó´   • U R                  5       n[        US5      nU R                  SUSXR                  4-  S9nUR	                  U R
                  S5        U$ )z[
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_remoteToLocalForwardingÚ,ForwardingMixin.test_remoteToLocalForwarding“  s`   € ð
 ×%Ñ%Ó'ˆ	Ü,¨Y¸	ÓBˆØ�L‰LØ�Ð!8¸IÇ}Á}Ð;UÑ!Uð ð 
ˆð 	
�‰�d×&Ñ&¨	Ô2Øˆr.   r(   N)	r)   r*   r+   r,   r:   r  r  r  r-   r(   r.   r/   rÿ   rÿ   o  s   † ñò=òõr.   rÿ   c                  óB   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)ÚRekeyAvatari¥  a  
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                óV   • [         R                  " U 5        [        U R                  S'   g )Ns   session)r"   rŠ   r$   ÚchannelLookupr6   s    r/   rŠ   ÚRekeyAvatar.__init__¯  s    € Ü×Ò˜4Ô Ü)3ˆ×Ñ˜:Ò&r.   c                óà   ^^• [         R                  " 5       nUR                  T5        TR                  [        U5      5        UU4S jn[	        U[        5       5      mTR                  S5        g)z5
Write 60 lines of data to the transport, then exit.
c                ó  >• [        U 5      nUS:X  aR  TR                  5         TR                  R                  R	                  TR                  SS5        TR                  5         g SU4-  nUR                  S5      nTR                  U5        g )Né<   s   exit-statuss       zline #%02d
r´   )ÚnextÚstopÚsessionÚconnÚsendRequestrZ   r·   rY   )ÚcounterÚiÚlineÚcallrX   s      €€r/   rY   Ú$RekeyAvatar.openShell.<locals>.write½  sx   ø€ Ü�W“ˆAØ�B‹wØ—	‘	”Ø×!Ñ!×&Ñ&×2Ñ2Ø×%Ñ% ~Ð7Jôð ×(Ñ(Õ*à%¨¨Ñ,�Ø—{‘{ 7Ó+�Ø—‘ Õ%r.   g{®Gáz„?N)r   ÚProtocolÚmakeConnectionr%   r   r   rº   )r7   rX   rô   rY   r&  s    `  @r/   Ú	openShellÚRekeyAvatar.openShell³  sU   ù€ ô ×!Ò!Ó#ˆØ×Ñ˜YÔ'Ø× Ñ ¤¨eÓ!4Ô5ö	&ô( ˜5¤%£'Ó*ˆØ�
‰
�4Õr.   c                ó   • g)z"
Ignore the close of the session.
Nr(   r6   s    r/   ÚclosedÚRekeyAvatar.closedÔ  s   � r.   c                ó   • g ri   r(   r6   s    r/   rA   ÚRekeyAvatar.eofReceivedÙ  ó   € àr.   c                ó   • g ri   r(   )r7   rô   Úcommands      r/   ÚexecCommandÚRekeyAvatar.execCommandÝ  r1  r.   c                ó   • g ri   r(   )r7   ÚtermÚ
windowSizeÚmodess       r/   ÚgetPtyÚRekeyAvatar.getPtyá  r1  r.   c                ó   • g ri   r(   )r7   ÚnewWindowSizes     r/   ÚwindowChangedÚRekeyAvatar.windowChangedå  r1  r.   r(   N)r)   r*   r+   r,   r:   rŠ   r*  r-  rA   r4  r:  r>  r-   r(   r.   r/   r  r  ¥  s+   † ñò4òòBò
òòõr.   r  c                  ó   • \ rS rSrSrS rSrg)Ú
RekeyRealmiê  zK
This realm gives out new L{RekeyAvatar} instances for any avatar request.
c                ó$   • US   [        5       S 4$ )Nr   c                 ó   • g ri   r(   r(   r.   r/   Ú<lambda>Ú*RekeyRealm.requestAvatar.<locals>.<lambda>ð  s   € °Tr.   )r  )r7   ÚavatarIDÚmindÚ
interfacess       r/   ÚrequestAvatarÚRekeyRealm.requestAvatarï  s   € Ø˜!‰}œk›m©\Ð9Ð9r.   r(   N)r)   r*   r+   r,   r:   rI  r-   r(   r.   r/   rA  rA  ê  s   † ñõ:r.   rA  c                  ó"   • \ rS rSrSr\rS rSrg)ÚRekeyTestsMixinió  zd
TestCase mixin which defines tests exercising L{SSHTransportBase}'s handling
of rekeying messages.
c                óp   ^ • [        5       nT R                  SUS5      nU 4S jnUR                  U5        U$ )zo
After a client-initiated rekey is completed, application data continues
to be passed over the SSH connection.
rÕ   z-o RekeyLimit=2Kc                ó¸   >• SR                  [        S5       Vs/ s H	  nSU4-  PM     sn5      S-   nUR                  S5      nTR                  X5        g s  snf )NÚ
r  z
line #%02dr´   )ÚjoinÚranger·   r  )Úresultr$  ÚexpectedResultr7   s      €r/   ÚfinishedÚ2RekeyTestsMixin.test_clientRekey.<locals>.finished  sU   ø€ Ø!ŸY™YÄUÈ2ÄYÓ'OÂYÀ¨¸°tÔ(;ÁYÑ'OÓPÐSWÑWˆNØ+×2Ñ2°7Ó;ˆNØ×Ñ˜VÕ4ùò (Ps   šA)rc   r  r  )r7   r  rl   rT  s   `   r/   Útest_clientRekeyÚ RekeyTestsMixin.test_clientRekeyû  s8   ø€ ô
 *Ó+ˆØ�L‰L˜˜WÐ&8Ó9ˆõ	5ð
 	
�‰�hÔØˆr.   r(   N)	r)   r*   r+   r,   r:   rA  rÀ   rV  r-   r(   r.   r/   rL  rL  ó  s   † ñð
 €Lõr.   rL  c                  óP   • \ rS rSr\" S5      (       d  Sr S       SS jjrSrg)	ÚOpenSSHClientMixini  Ússhz$no ssh command-line client availablec                óV  • [        5       =oBl        SU-   S-   U-   nU R                  R                  5       R                  nXV-  R                  5       n/ nU H#  n	UR                  U	R                  S5      5        M%     [        [        5      R                  U[        S5      S   U5        U$ )ah  
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}
zŸssh -2 -l testuser -p %i -F /dev/null -oIdentitiesOnly=yes -oUserKnownHostsFile=kh_test -oPasswordAuthentication=no -oHostKeyAlgorithms=ssh-rsa -a -i rsa_test z 127.0.0.1 r´   rZ  r   )r   re   rë   rí   rˆ   Úsplitrø   r·   r   r   ÚspawnProcessr   )
r7   ÚremoteCommandr  r  rR  Úcmdlinerˆ   ÚcmdsÚencodedCmdsÚcmds
             r/   r  ÚOpenSSHClientMixin.execute  s¯   € ô& %-£JÐ.ˆÔ!ðð ñð ñð ñð 	ð  ×$Ñ$×,Ñ,Ó.×3Ñ3ˆØ‘×%Ñ%Ó'ˆØˆÛˆCØ×Ñ˜sŸz™z¨'Ó2Ö3ñ äœÓ ×-Ñ-¨g´u¸U³|ÀA±ÈÔTØˆr.   r(   N)rÕ   )r^  Ústrr  rc   r  rd  rü   úDeferred[None])r)   r*   r+   r,   r   rG   r  r-   r(   r.   r/   rY  rY    sA   † Ù��<‰<Ø5ˆð TVð-Ø ð-Ø+Bð-ØMPð-à	÷-ð -r.   rY  c                  óH   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)ÚOpenSSHKeyExchangeTestsi@  zP
Tests L{SSHTransportBase}'s key exchange algorithm compatibility with
OpenSSH.
c                ó’  • / n [         R                  " [        S5      S   SS/[         R                  S9n[	        U[
        5      (       d  UR                  S5      nUR                  5       nX;  a  [        U S35      eU R                  S[        5       S	U-   5      nUR                  U R                  S
5      $ ! [         a     NYf = f)a  
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}
rZ  r   z-QÚkex)Ústderrr´   z not supported by ssh clientz
echo helloz-oKexAlgorithms=s   hello
)Ú
subprocessÚcheck_outputr   ÚSTDOUTÚ
isinstancerd  r~   r\  ÚBaseExceptionr   r  rc   r  r  )r7   ÚkeyExchangeAlgoÚkexAlgorithmsÚoutputrl   s        r/   ÚassertExecuteWithKexAlgorithmÚ5OpenSSHKeyExchangeTests.assertExecuteWithKexAlgorithmF  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(B9 Â9
CÃCc                ó$   • U R                  S5      $ )zJ
The ecdh-sha2-nistp256 key exchange algorithm is compatible with
OpenSSH
zecdh-sha2-nistp256©rs  r6   s    r/   Útest_ECDHSHA256Ú'OpenSSHKeyExchangeTests.test_ECDHSHA256f  ó   € ð
 ×1Ñ1Ð2FÓGÐGr.   c                ó$   • U R                  S5      $ )zJ
The ecdh-sha2-nistp384 key exchange algorithm is compatible with
OpenSSH
zecdh-sha2-nistp384rv  r6   s    r/   Útest_ECDHSHA384Ú'OpenSSHKeyExchangeTests.test_ECDHSHA384m  ry  r.   c                ó$   • U R                  S5      $ )zJ
The ecdh-sha2-nistp521 key exchange algorithm is compatible with
OpenSSH
zecdh-sha2-nistp521rv  r6   s    r/   Útest_ECDHSHA521Ú'OpenSSHKeyExchangeTests.test_ECDHSHA521t  ry  r.   c                ó$   • U R                  S5      $ )zT
The diffie-hellman-group14-sha1 key exchange algorithm is compatible
with OpenSSH.
zdiffie-hellman-group14-sha1rv  r6   s    r/   Útest_DH_GROUP14Ú'OpenSSHKeyExchangeTests.test_DH_GROUP14{  s   € ð
 ×1Ñ1Ð2OÓPÐPr.   c                ó$   • U R                  S5      $ )z[
The diffie-hellman-group-exchange-sha1 key exchange algorithm is
compatible with OpenSSH.
z"diffie-hellman-group-exchange-sha1rv  r6   s    r/   Útest_DH_GROUP_EXCHANGE_SHA1Ú3OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA1‚  s   € ð
 ×1Ñ1Ð2VÓWÐWr.   c                ó$   • U R                  S5      $ )z]
The diffie-hellman-group-exchange-sha256 key exchange algorithm is
compatible with OpenSSH.
z$diffie-hellman-group-exchange-sha256rv  r6   s    r/   Útest_DH_GROUP_EXCHANGE_SHA256Ú5OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA256‰  s   € ð
 ×1Ñ1Ø2ó
ð 	
r.   c                óF   • U R                  [        U R                  S5        g)za
The list of key exchange algorithms supported
by OpenSSH client is obtained with C{ssh -Q kex}.
zunsupported-algorithmN)ÚassertRaisesr   rs  r6   s    r/   Útest_unsupported_algorithmÚ2OpenSSHKeyExchangeTests.test_unsupported_algorithm’  s    € ð
 	×ÑÜ�d×8Ñ8Ð:Qõ	
r.   r(   N)r)   r*   r+   r,   r:   rs  rw  r{  r~  r�  r„  r‡  r‹  r-   r(   r.   r/   rg  rg  @  s5   † ñò
;ò@HòHòHòQòXò
õ
r.   rg  c                  ó(   • \ rS rSrSr\S 5       rSrg)ÚOpenSSHClientForwardingTestsiœ  zJ
Connection forwarding tests run against the OpenSSL command line client.
c                ó´   • U R                  5       n[        US5      nU R                  SUSXR                  4-  S9nUR	                  U R
                  S5        U$ )z7
Forwarding of arbitrary IPv6 TCP connections via SSH.
r
  rÕ   z-N -L%i:[::1]:%ir  )rÜ   r…   r  rð   r  r  r  s       r/   Útest_localToRemoteForwardingV6Ú;OpenSSHClientForwardingTests.test_localToRemoteForwardingV6¡  s`   € ð
 ×%Ñ%Ó'ˆ	Ü,¨Y¸	ÓBˆØ�L‰LØ�Ð!3°yÇ/Á/Ð6RÑ!Rð ð 
ˆð 	
�‰�d×&Ñ&¨	Ô2Øˆr.   r(   N)r)   r*   r+   r,   r:   r   r�  r-   r(   r.   r/   rŽ  rŽ  œ  s   † ñð ñ
ó ó
r.   rŽ  c                  ó   • \ rS rSrSrSrg)ÚOpenSSHClientRekeyTestsi¯  z=
Rekeying tests run against the OpenSSL command line client.
r(   N)r)   r*   r+   r,   r:   r-   r(   r.   r/   r“  r“  ¯  s   † ôr.   r“  c                  ó�   • \ rS rSrSr\R                  S:X  a  Sr   S           SS jjrS r	S r
SS	 jrSS
 jrSS jrSrg)ÚCmdLineClientTestsiµ  zH
Connection forwarding tests run against the Conch command line client.
Úwin32z!can't run cmdline client on win32Nc                ó  • Uc  / n[        5       Ul        U R                  R                  5       R                  nSR                  U5      U-   SU S3-   U-   n[        UR                  5       5      n[        R                  R                  5       n	[        R                  R                  [        R                  5      U	S'   [        [         5      R#                  U[        R$                  ['        XH-   5      U	S9  UR                  $ )zc
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 rsa_test -v Ú Ú
PYTHONPATH)Úenv)r   re   rë   rí   rˆ   r}   Úlistr\  rÇ   ÚenvironÚcopyÚpathseprP  rµ   rÈ   r   r   r]  r¶   r¼   )
r7   r^  r  r  Ú	conchArgsÚ
remoteHostrˆ   Úcmdtemplater\  rš  s
             r/   r  ÚCmdLineClientTests.execute½  sê   € ð ÑØˆIä#›:ˆÔØ×Ñ×'Ñ'Ó)×.Ñ.ˆð÷
 ‘&˜“, ñ)ð
 ./¨z¨l¸!Ð+<ñ=ð
 @MñMð 	ô �[×&Ñ&Ó(Ó)ˆÜ�j‰j�o‰oÓˆÜŸJ™JŸO™O¬C¯H©HÓ5ˆˆLÑÜœÓ ×-Ñ-Ø”S—^‘^¤Y¨yÑ/@Ó%AÀsð 	.ñ 	
ð ×ÑÐr.   c           	     ó
  ^ ^• UU 4S jn[         R                  " T R                  5       5      mT R                  S[	        5       SSTR
                  SS/S9nUR                  T R                  S5        UR                  U5        U$ )	z$
It can store logs to a local file.
c                óJ   >• TR                  5       nTR                  SU5        g )Ns   Log opened.)Ú
getContentÚassertIn)rR  Ú
logContentÚlogPathr7   s     €€r/   Úcb_check_logÚ<CmdLineClientTests.test_runWithLogFile.<locals>.cb_check_logã  s   ø€ Ø ×+Ñ+Ó-ˆJØ�M‰M˜.¨*Õ5r.   r  z--logz	--logfilez--host-key-algorithmszssh-rsa©r^  r  rŸ  r  )r   r   Úmktempr  rc   rÈ   r  r  )r7   r©  rl   r¨  s   `  @r/   Útest_runWithLogFileÚ&CmdLineClientTests.test_runWithLogFileÞ  s{   ù€ ö
	6ô ×#Ò# D§K¡K£MÓ2ˆà�L‰LØ(Ü+Ó-àØØ—‘Ø'Øðð ð 

ˆð 	
�‰�d×&Ñ&¨Ô5Ø	�‰�lÔ#Øˆr.   c                ón   • U R                  S[        5       S9nUR                  U R                  S5        U$ )z8
Do not use --host-key-algorithms flag on command line.
r  )r^  r  r  r  rk   s     r/   Ú%test_runWithNoHostAlgorithmsSpecifiedÚ8CmdLineClientTests.test_runWithNoHostAlgorithmsSpecifiedù  s;   € ð �L‰LØ(Ô2IÓ2Kð ð 
ˆð 	
�‰�d×&Ñ&¨Ô5Øˆr.   c                ój   • U R                  S[        5       S/S9R                  U R                  S5      $ )zC
Simple smoke test for '--compress' flag to ensure we can connect.
zecho compressedz
--compressr«  s   compressed
r  r6   s    r/   Ú test_runWithCompressionSpecifiedÚ3CmdLineClientTests.test_runWithCompressionSpecified  s<   € ð �|‰|Ø+Ü+Ó-Ø#�nð ð 
÷ ‰+�d×&Ñ&¨Ó
8ð		9r.   c                óF   • [        5       nSUl        U R                  SUSS9$ )z,
Connecting to an invalid host should fail.
rÖ   zecho nonfunctionalúnowhere.invalid©r^  r  r   )rc   rg   r  ©r7   ÚexpectErrors     r/   Útest_connectToInvalidHostÚ,CmdLineClientTests.test_connectToInvalidHost  s3   € ô .Ó/ˆØ'(ˆÔ$Ø�|‰|Ø.ØØ(ð ð 
ð 	
r.   c                ó`   • [        5       nU R                  U R                  SUSS9[        5      $ )zU
L{ConchTestOpenSSHProcess} fails with a L{ConchError} if an expectation
is not met.
zecho checkfailurer¶  r·  )rc   ÚassertFailurer  r   r¸  s     r/   Útest_testFailureÚ#CmdLineClientTests.test_testFailure  s>   € ô
 .Ó/ˆØ×!Ñ!Ø�L‰LØ1Ø#Ø,ð ð ô
 ó
ð 	
r.   r(   )rÕ   Nr’   )r^  rd  r  rc   r  rd  rŸ  zlist[str] | Noner   rd  rü   re  )rü   re  )r)   r*   r+   r,   r:   r   ÚplatformTyperG   r  r­  r°  r³  rº  r¾  r-   r(   r.   r/   r•  r•  µ  s€   † ñð ×Ñ˜wÓ&Ø2ˆð Ø&*Ø%ð àð ð )ð ð ð	 ð
 $ð ð ð ð 
õ òBò6	ô9ô

÷
r.   r•  )Úconch)r¸   z	list[str]r¹   rd  rü   zlist[bytes])XÚ
__future__r   rÇ   r×   rk  rµ   Ú	itertoolsr   Útypingr   Úzope.interfacer   Útwisted.conch.errorr   Útwisted.conch.test.keydatar   r	   Útwisted.conch.test.test_sshr   Útwisted.credr   Útwisted.internetr   r   Útwisted.internet.deferr   r   r   Útwisted.internet.errorr   Útwisted.internet.interfacesr   Útwisted.internet.taskr   Útwisted.pythonr   r   r   Útwisted.python.filepathr   Útwisted.python.procutilsr   Útwisted.python.reflectr   Útwisted.test.testutilsr   r   Útwisted.trial.unittestr   r   r   r    ÚImportErrorr!   Útwisted.conch.avatarr"   Útwisted.conch.ssh.sessionr#   r$   r%   Útwisted.conch.interfacesÚtwisted.conch.scripts.conchÚ_StdioInteractingSessionr?   Úerd  rF   r1   r<   r(  rI   ÚFactoryr`   ÚProcessProtocolrc   r…   r”   r¼   r¾   rÿ   r  rA  rL  rY  rg  rŽ  r“  r•  r(   r.   r/   Ú<module>rÞ     sê  ðõ #ã 	Û Û Û 
Ý Ý å &å *ß LÝ 6Ý ß .ß IÑ IÝ 7Ý 7Ý -ß 1Ñ 1Ý ,Ý *Ý 0ß <ß 5ð	÷ñ ˜^Ó,€æÝ.ßLÒLå1÷ñ ð7ÝRð 7Ð÷"ñ "ô$- 8ô -ô(
,ˆ8×Ñô 
,ô�(×"Ñ"ô ô-.˜h×6Ñ6ô -.ô`I2 ×!9Ñ!9ô I2ôX>˜h×/Ñ/ô >ö<>÷*I(ñ I(ôX/Ð+ô /ñl ˆXÓôA�)ó Aó ðA÷H:ñ :ôÐ+ô ÷21ñ 1ôhY
Ð3Ð5GÈô Y
ôx ?Ð4FÈô ô&˜oÐ/AÀ8ô ôr
˜¨(õ r
øðc ó 	Úð	ûð" ó 
Ø"ÐÙ�!‹f€GÞ	ûð
ús*   ÂG ÃG% ÇG"Ç!G"Ç%HÇ+G<Ç<H