ó
    Ö›‘h   ã                   ó:  • S r SSKrSSKJrJr  SSKJrJr  SSKJ	r	J
r
   " S S\R                  5      r " S S	\R                  5      r " S
 S\5      r " S S\5      r " S S\R                  5      rS r " S S\R&                  5      rS r\rS r\rS rS rg)z¯
This module contains the implementation of the TCP forwarding, which allows
clients and servers to forward arbitrary TCP data across the connection.

Maintainer: Paul Swartz
é    N)ÚchannelÚcommon)ÚprotocolÚreactor)ÚHostnameEndpointÚconnectProtocolc                   ó    • \ rS rSrS rS rSrg)ÚSSHListenForwardingFactoryé   c                 ó(   • Xl         X l        X0l        g ©N©ÚconnÚhostportÚklass)ÚselfÚ
connectionr   r   s       Ú`C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/conch/ssh/forwarding.pyÚ__init__Ú#SSHListenForwardingFactory.__init__   s   € ØŒ	Ø ŒØ�
ó    c                 óì   • U R                  U R                  S9n[        U5      nX2l        UR                  UR
                  4n[        U R                  U5      nU R                  R                  X%5        U$ )N)r   )	r   r   ÚSSHForwardingClientÚclientÚhostÚportÚpackOpen_direct_tcpipr   ÚopenChannel)r   Úaddrr   r   Ú	addrTupleÚchannelOpenDatas         r   ÚbuildProtocolÚ(SSHListenForwardingFactory.buildProtocol   s^   € Ø—*‘* $§)¡)�*Ð,ˆÜ$ WÓ-ˆØŒØ—Y‘Y §	¡	Ð*ˆ	Ü/°·±¸yÓIˆØ�	‰	×Ñ˜gÔ7Øˆr   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r"   Ú__static_attributes__© r   r   r
   r
      s   † òõ
r   r
   c                   ó2   • \ rS rSrS rS rS rS rS rSr	g)	ÚSSHListenForwardingChannelé#   c                 ó  • U R                   R                  SU R                  S9  [        U R                  R
                  5      S:”  a*  U R                  R
                  SS  nU R                  U5        SU R                  l        g )Nzopened forwarding channel {id}©Úidé   r   )Ú_logÚinfor/   Úlenr   ÚbufÚwrite)r   ÚspecificDataÚbs      r   ÚchannelOpenÚ&SSHListenForwardingChannel.channelOpen$   sZ   € Ø�	‰	�‰Ð7¸D¿G¹GˆÑDÜˆt�{‰{�‰Ó !Ó#Ø—‘—‘  Ð#ˆAØ�J‰J�qŒMØˆ�‰�r   c                 ó$   • U R                  5         g r   )Úclosed©r   Úreasons     r   Ú
openFailedÚ%SSHListenForwardingChannel.openFailed+   s   € Ø�‰�r   c                 óN   • U R                   R                  R                  U5        g r   )r   Ú	transportr5   ©r   Údatas     r   ÚdataReceivedÚ'SSHListenForwardingChannel.dataReceived.   s   € Ø�‰×Ñ×#Ñ# DÕ)r   c                 óL   • U R                   R                  R                  5         g r   )r   rA   ÚloseConnection©r   s    r   ÚeofReceivedÚ&SSHListenForwardingChannel.eofReceived1   s   € Ø�‰×Ñ×,Ñ,Õ.r   c                 ó¼   • [        U S5      (       aK  U R                  R                  SU R                  S9  U R                  R
                  R                  5         U ?g g )Nr   z%closing local forwarding channel {id}r.   )Úhasattrr1   r2   r/   r   rA   rG   rH   s    r   r;   Ú!SSHListenForwardingChannel.closed4   sH   € Ü�4˜×"Ñ"Ø�I‰I�N‰NÐBÀtÇwÁwˆNÑOØ�K‰K×!Ñ!×0Ñ0Ô2Ø‘ð #r   r)   N)
r$   r%   r&   r'   r8   r>   rD   rI   r;   r(   r)   r   r   r+   r+   #   s   † òòò*ò/õr   r+   c                   ó   • \ rS rSrSrSrg)Ú SSHListenClientForwardingChannelé;   s   direct-tcpipr)   N©r$   r%   r&   r'   Únamer(   r)   r   r   rO   rO   ;   s   † ØƒDr   rO   c                   ó   • \ rS rSrSrSrg)Ú SSHListenServerForwardingChannelé?   s   forwarded-tcpipr)   NrQ   r)   r   r   rT   rT   ?   s   † ØƒDr   rT   c                   ó@   • \ rS rSrSr\rS rS rS r	S r
S rS rS	rg
)ÚSSHConnectForwardingChanneléC   a³  
Channel used for handling server side forwarding request.
It acts as a client for the remote forwarding destination.

@ivar hostport: C{(host, port)} requested by client as forwarding
    destination.
@type hostport: L{tuple} or a C{sequence}

@ivar client: Protocol connected to the forwarding destination.
@type client: L{protocol.Protocol}

@ivar clientBuf: Data received while forwarding channel is not yet
    connected.
@type clientBuf: L{bytes}

@var  _reactor: Reactor used for TCP connections.
@type _reactor: A reactor.

@ivar _channelOpenDeferred: Deferred used in testing to check the
    result of C{channelOpen}.
@type _channelOpenDeferred: L{twisted.internet.defer.Deferred}
c                 ót   • [         R                  R                  " U /UQ70 UD6  Xl        S U l        SU l        g )Nr   )r   Ú
SSHChannelr   r   r   Ú	clientBuf)r   r   ÚargsÚkws       r   r   Ú$SSHConnectForwardingChannel.__init__]   s3   € Ü×Ñ×#Ò# DÐ6¨4Ò6°2Ò6Ø ŒØˆŒØˆ�r   c                 óR  • U R                   R                  SU R                  S   U R                  S   S9  [        U R                  U R                  S   U R                  S   5      n[        U[        U 5      5      nUR                  U R                  U R                  5        X0l
        g)ú
See: L{channel.SSHChannel}
zconnecting to {host}:{port}r   r0   ©r   r   N)r1   r2   r   r   Ú_reactorr   r   ÚaddCallbacksÚ
_setClientÚ_closeÚ_channelOpenDeferred)r   r6   ÚepÚds       r   r8   Ú'SSHConnectForwardingChannel.channelOpenc   s‡   € ð 	�	‰	�‰Ø)°·±¸aÑ0@ÀtÇ}Á}ÐUVÑGWð 	ñ 	
ô ˜dŸm™m¨T¯]©]¸1Ñ-=¸t¿}¹}ÈQÑ?OÓPˆÜ˜BÔ 3°DÓ 9Ó:ˆØ	�‰�t—‘¨¯©Ô4Ø$%Õ!r   c                 ó¶  • Xl         U R                  R                  SU R                  S   U R                  S   S9  U R                  (       a6  U R                   R
                  R                  U R                  5        SU l        U R                   R                  SS (       a(  U R                  U R                   R                  SS 5        SU R                   l        g)z¸
Called when the connection was established to the forwarding
destination.

@param client: Client protocol connected to the forwarding destination.
@type  client: L{protocol.Protocol}
zconnected to {host}:{port}r   r0   ra   Nr   )r   r1   r2   r   r[   rA   r5   r4   )r   r   s     r   rd   Ú&SSHConnectForwardingChannel._setCliento   sœ   € ð ŒØ�	‰	�‰Ø(¨t¯}©}¸QÑ/?ÀdÇmÁmÐTUÑFVð 	ñ 	
ð �>�>Ø�K‰K×!Ñ!×'Ñ'¨¯©Ô7Ø!ˆDŒNØ�;‰;�?‰?˜1˜2ÖØ�J‰J�t—{‘{—‘ q rÐ*Ô+Øˆ�‰�r   c                 ó�   • U R                   R                  SU R                  S   U R                  S   US9  U R                  5         g)z�
Called when failed to connect to the forwarding destination.

@param reason: Reason why connection failed.
@type  reason: L{twisted.python.failure.Failure}
z,failed to connect to {host}:{port}: {reason}r   r0   )r   r   r=   N)r1   Úerrorr   rG   r<   s     r   re   Ú"SSHConnectForwardingChannel._close‚   sE   € ð 	�	‰	�‰Ø:Ø—‘˜qÑ!Ø—‘˜qÑ!Øð	 	ñ 	
ð 	×ÑÕr   c                 óœ   • U R                   (       a&  U R                   R                  R                  U5        gU =R                  U-  sl        g)r`   N)r   rA   r5   r[   rB   s     r   rD   Ú(SSHConnectForwardingChannel.dataReceived‘   s1   € ð �;�;Ø�K‰K×!Ñ!×'Ñ'¨Õ-à�NŠN˜dÑ"ŽNr   c                 ó  • U R                   (       av  U R                  R                  SU R                  S9  U R                   R                  (       a  U R                  5         U R                   R                  R                  5         U ? gg)r`   z%closed remote forwarding channel {id}r.   N)r   r1   r2   r/   r   rG   rA   rH   s    r   r;   Ú"SSHConnectForwardingChannel.closedš   s]   € ð �;�;Ø�I‰I�N‰NÐBÀtÇwÁwˆNÑOØ�{‰{×"×"Ø×#Ñ#Ô%Ø�K‰K×!Ñ!×0Ñ0Ô2Ø‘ð r   )rf   r   r[   r   N)r$   r%   r&   r'   Ú__doc__r   rb   r   r8   rd   re   rD   r;   r(   r)   r   r   rW   rW   C   s,   † ñð. €Hòò
&òò&ò#õ	r   rW   c                 ó4   • [        U5      u  pE[        UU UUS9$ )N)ÚremoteWindowÚremoteMaxPacketÚavatar)ÚunpackOpen_direct_tcpiprW   )ru   rv   rC   rw   ÚremoteHPÚorigHPs         r   ÚopenConnectForwardingClientr{   ¦   s(   € Ü.¨tÓ4Ñ€HÜ&ØØ!Ø'Øñ	ð r   c                   ó&   • \ rS rSrS rS rS rSrg)r   é°   c                 ó   • Xl         SU l        g )Nó    )r   r4   )r   r   s     r   r   ÚSSHForwardingClient.__init__±   s   € ØŒØˆ�r   c                 óˆ   • U R                   (       a  U =R                   U-  sl         g U R                  R                  U5        g r   )r4   r   r5   rB   s     r   rD   Ú SSHForwardingClient.dataReceivedµ   s)   € Ø�8�8Ø�HŠH˜ÑŽHà�L‰L×Ñ˜tÕ$r   c                 ój   • U R                   (       a"  U R                   R                  5         S U l         g g r   )r   rG   r<   s     r   ÚconnectionLostÚ"SSHForwardingClient.connectionLost»   s%   € Ø�<�<Ø�L‰L×'Ñ'Ô)ØˆD�Lð r   )r4   r   N)r$   r%   r&   r'   r   rD   r„   r(   r)   r   r   r   r   °   s   † òò%õ r   r   c                 ój  • U u  p#Uu  pE[        U[        5      (       a  UR                  S5      n[        U[        5      (       a  UR                  S5      n[        R                  " U5      [
        R                  " SU5      -   n[        R                  " U5      [
        R                  " SU5      -   nXg-   $ )zû
Pack the data suitable for sending in a CHANNEL_OPEN packet.

@type destination: L{tuple}
@param destination: A tuple of the (host, port) of the destination host.

@type source: L{tuple}
@param source: A tuple of the (host, port) of the source host.
úutf-8ú>L)Ú
isinstanceÚstrÚencoder   ÚNSÚstructÚpack)ÚdestinationÚsourceÚconnHostÚconnPortÚorigHostÚorigPortr   Úorigs           r   r   r   Á   sŽ   € ð 'Ñ€XØ!Ñ€XÜ�(œC× Ñ Ø—?‘? 7Ó+ˆÜ�(œC× Ñ Ø—?‘? 7Ó+ˆÜ�9Š9�XÓ¤§¢¨T°8Ó!<Ñ<€DÜ�9Š9�XÓ¤§¢¨T°8Ó!<Ñ<€DØ‰;Ðr   c                 ó¤  • [         R                  " U 5      u  p[        U[        5      (       a  UR	                  S5      n[        [        R                  " SUSS 5      S   5      n[         R                  " USS 5      u  pB[        U[        5      (       a  UR	                  S5      n[        [        R                  " SUSS 5      S   5      nX4XE44$ )z#Unpack the data to a usable format.r‡   rˆ   Né   r   ©r   ÚgetNSr‰   ÚbytesÚdecodeÚintr�   Úunpack)rC   r‘   Úrestr’   r“   r”   s         r   rx   rx   Ù   s¯   € ä—\’\ $Ó'�N€HÜ�(œE×"Ñ"Ø—?‘? 7Ó+ˆÜ”6—=’=  t¨B¨Q xÓ0°Ñ3Ó4€HÜ—\’\ $ q r (Ó+�N€HÜ�(œE×"Ñ"Ø—?‘? 7Ó+ˆÜ”6—=’=  t¨B¨Q xÓ0°Ñ3Ó4€HØÐ (Ð!5Ð5Ð5r   c                 óf   • U u  p[         R                  " U5      [        R                  " SU5      -   $ )zf
Pack the data for tcpip forwarding.

@param peer: A tuple of the (host, port) .
@type peer: L{tuple}
rˆ   )r   rŒ   r�   rŽ   )Úpeerr   r   s      r   ÚpackGlobal_tcpip_forwardr¡   é   s)   € ð �L€TÜ�9Š9�T‹?œVŸ[š[¨¨tÓ4Ñ4Ð4r   c                 óÐ   • [         R                  " U 5      u  p[        U[        5      (       a  UR	                  S5      n[        [        R                  " SUS S 5      S   5      nX4$ )Nr‡   rˆ   r—   r   r˜   )rC   r   rž   r   s       r   ÚunpackGlobal_tcpip_forwardr£   ô   sU   € Ü—’˜dÓ#�J€DÜ�$œ×ÑØ�{‰{˜7Ó#ˆÜŒv�}Š}˜T 4¨¨ 8Ó,¨QÑ/Ó0€DØˆ:Ðr   )rs   r�   Útwisted.conch.sshr   r   Útwisted.internetr   r   Útwisted.internet.endpointsr   r   ÚFactoryr
   rZ   r+   rO   rT   rW   r{   ÚProtocolr   r   ÚpackOpen_forwarded_tcpiprx   ÚunpackOpen_forwarded_tcpipr¡   r£   r)   r   r   Ú<module>r«      s«   ðñó ç -ß .ß Hô ×!1Ñ!1ô ô  ×!3Ñ!3ô ô0Ð'Aô ôÐ'Aô ô` '×"4Ñ"4ô `òFô ˜(×+Ñ+ô  ò"ð* 1Ð ò
6ð 5Ð ò5òðr   