o 5@gR:@s~dZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZddlmZddlmZmZmZdd lmZmZmZdd lmZdd lmZm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddZ2Gddde3Z4GdddZ5ddZ6Gddde*j7Z8Gddde8Z9Gddde8Z:Gdd d Z;Gd!d"d"Zd%\Z?Z@d&ZAd'ZBd(ZCd)ZDd*ZEd+ZFd,ZGd-ZHd.ZId/ZJd0ZKd/ZLd1ZMd0ZNd2ZOd3ZPd&ZQd'ZRd(ZSd)ZTd*ZUd+ZVd,ZWd4ZXd5ZYd6ZZd7Z[d8Z\d9Z]d:Z^d;Z_iZ`eaebcD]\ZdZeedfd<r-edfd=s-ede`ee<qd>e`vs9d?e`vr=egd@dS)Az The lowest level SSH protocol. This handles the key negotiation, the encryption and the compression. The transport layer is described in RFC 4253. Maintainer: Paul Swartz N)md5sha1sha256sha384sha512)Dict)UnsupportedAlgorithm)default_backend) serialization)dhecx25519)Cipher algorithmsmodes) __version__)_kexaddresskeys)MPNSffsgetMPgetNS)deferprotocol)Logger) randbytes) iterbytes networkStringcCstt|dS)a*Make an SSH multiple-precision integer from big-endian L{bytes}. Used in ECDH key exchange. @type data: L{bytes} @param data: The input data, interpreted as a big-endian octet string. @rtype: L{bytes} @return: The given data encoded as an SSH multiple-precision integer. big)rint from_bytes)datar$=/usr/lib/python3/dist-packages/twisted/conch/ssh/transport.py _mpFromBytes's r&c@seZdZdZdS) _MACParamsaP L{_MACParams} represents the parameters necessary to compute SSH MAC (Message Authenticate Codes). L{_MACParams} is a L{tuple} subclass to maintain compatibility with older versions of the code. The elements of a L{_MACParams} are:: 0. The digest object used for the MAC 1. The inner pad ("ipad") string 2. The outer pad ("opad") string 3. The size of the digest produced by the digest object L{_MACParams} is also an object lesson in why tuples are a bad type for public APIs. @ivar key: The HMAC key which will be used. N)__name__ __module__ __qualname____doc__r$r$r$r%r'5sr'c@seZdZdZejdejfejdejfej dejfej dejfej dejfej dejfej dej fej dej fej dej fejdej fejdej fej dej fddejfd Z e eeeeddZd d Zd d Zd dZddZddZddZddZddZdS) SSHCiphersa SSHCiphers represents all the encryption operations that need to occur to encrypt and authenticate the SSH connection. @cvar cipherMap: A dictionary mapping SSH encryption names to 3-tuples of (, , ) @cvar macMap: A dictionary mapping SSH MAC names to hash modules. @ivar outCipType: the string type of the outgoing cipher. @ivar inCipType: the string type of the incoming cipher. @ivar outMACType: the string type of the incoming MAC. @ivar inMACType: the string type of the incoming MAC. @ivar encBlockSize: the block size of the outgoing cipher. @ivar decBlockSize: the block size of the incoming cipher. @ivar verifyDigestSize: the size of the incoming MAC. @ivar outMAC: a tuple of (, , , ) representing the outgoing MAC. @ivar inMAc: see outMAC, but for the incoming MAC.  Nr) 3des-cbc blowfish-cbc aes256-cbc aes192-cbc aes128-cbc cast128-cbc aes128-ctr aes192-ctr aes256-ctr3des-ctr blowfish-ctr cast128-ctrnone) hmac-sha2-512 hmac-sha2-384 hmac-sha2-256 hmac-sha1hmac-md5r<cCs:||_||_||_||_d|_d|_d|_d|_d|_dS)NrNrCr) outCipType inCipType outMACType inMACType encBlockSize decBlockSizeverifyDigestSizeoutMACinMAC)selfoutCipinCipoutMacinMacr$r$r%__init__ws zSSHCiphers.__init__cCs||j||}||_|jjd|_||j||}||_|jjd|_| |j ||_ | |j ||_ |j rC|j d|_dSdS)a Set up the ciphers and hashes using the given keys, @param outIV: the outgoing initialization vector @param outKey: the outgoing encryption key @param inIV: the incoming initialization vector @param inKey: the incoming encryption key @param outInteg: the outgoing integrity key @param inInteg: the incoming integrity key. N) _getCipherrD encryptor algorithm block_sizerHrE decryptorrI_getMACrFrKrGrLrJ)rMoutIVoutKeyinIVinKeyoutInteginIntegor$r$r%setKeyss  zSSHCiphers.setKeyscCsL|j|\}}}|durtSt||d|||d|jdtdS)z Creates an initialized cipher object. @param cip: the name of the cipher, maps into cipherMap @param iv: the initialzation vector @param key: the encryption key @return: the cipher object. NrSbackend) cipherMap _DummyCipherrrXr )rMcipivkeyalgorithmClasskeySize modeClassr$r$r%rUs zSSHCiphers._getCipherc Csn|j|}|s dS|}|j}|j}|d|d||}|tj}|tj}t||||f} || _| S)am Gets a 4-tuple representing the message authentication code. (, , , ) @type mac: L{bytes} @param mac: a key mapping into macMap @type key: L{bytes} @param key: the MAC key. @rtype: L{bytes} @return: The MAC components. rBN) macMap digest_sizerX translatehmactrans_36trans_5Cr'ri) rMmacrimod hashObject digestSize blockSizeiraresultr$r$r%rZs   zSSHCiphers._getMACcC |j|S)z Encrypt some data. @type blocks: L{bytes} @param blocks: The data to encrypt. @rtype: L{bytes} @return: The encrypted data. )rVupdaterMblocksr$r$r%encrypt zSSHCiphers.encryptcCr{)z Decrypt some data. @type blocks: L{bytes} @param blocks: The data to decrypt. @rtype: L{bytes} @return: The decrypted data. )rYr|r}r$r$r%decryptrzSSHCiphers.decryptcCs:|jdsdStd||}t|jj||jdS)aa Create a message authentication code (MAC) for the given packet using the outgoing MAC values. @type seqid: L{int} @param seqid: The sequence ID of the outgoing packet. @type data: L{bytes} @param data: The data to create a MAC for. @rtype: L{str} @return: The serialized MAC. rrC>L)rKstructpackrqHMACridigest)rMseqidr#r$r$r%makeMACs zSSHCiphers.makeMACcCsJ|jds |dkStd||}t|jj||jd}t||S)a Verify an incoming MAC using the incoming MAC values. @type seqid: L{int} @param seqid: The sequence ID of the incoming packet. @type data: L{bytes} @param data: The packet data to verify. @type mac: L{bytes} @param mac: The MAC sent with the packet. @rtype: L{bool} @return: C{True} if the MAC is valid. rrCr)rLrrrqrrircompare_digest)rMrr#rtouterr$r$r%verifys  zSSHCiphers.verify)r(r)r*r+r TripleDESrCBCBlowfishAESCAST5CTRrerrrrrrnrRrbrUrZrrrrr$r$r$r%r,Is>               "  r,c Csvg}gd}|D]0}tj|\}}}zt|d||d|jdtdWn ty2Yqw||q|S)z Build a list of ciphers that are supported by the backend in use. @return: a list of supported ciphers. @rtype: L{list} of L{str} ) r8r2r7r3r6r4r;r5r:r1r9r0 rSrc)r,rerrXr rVrappend)supportedCipherscscipherrjrkrlr$r$r%_getSupportedCipherss     rc@s^eZdZUdZeZdZdedZ dZ dede de  Z e Zgd ZeZgZeD]Zed d krDeed d g7Zq2ed dg7ZerUedddgZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(e&Z)dZ*dZ+dZ,dZ-iZ.e/e0e0fe1d<ddZ2dd Z3d!d"Z4d#d$Z5d%d&Z6d'd(Z7d)d*Z8d+d,Z9d-d.Z:d/d0Z;d1d2Ze>j?d5d4Z>d6d7Z@d8d9ZAd:d;ZBdd?ZDd@dAZEdBdCZFdkdDdEZGdFdGZHdHdIZIdJdKZJdLdMZKdNdOZLdPdQZMdRdSZNdTdUZOdVdWZPdldYdZZQdld[d\ZRd]d^ZSd_d`ZTdadbZUdcddZVdedfZWdgdhZXdidjZYdS)mSSHTransportBasea Protocol supporting basic SSH functionality: sending/receiving packets and message dispatch. To connect to or run a server, you must use SSHClientTransport or SSHServerTransport. @ivar protocolVersion: A string representing the version of the SSH protocol we support. Currently defaults to '2.0'. @ivar version: A string representing the version of the server or client. Currently defaults to 'Twisted'. @ivar comment: An optional string giving more information about the server or client. @ivar supportedCiphers: A list of strings representing the encryption algorithms supported, in order from most-preferred to least. @ivar supportedMACs: A list of strings representing the message authentication codes (hashes) supported, in order from most-preferred to least. Both this and supportedCiphers can include 'none' to use no encryption or authentication, but that must be done manually, @ivar supportedKeyExchanges: A list of strings representing the key exchanges supported, in order from most-preferred to least. @ivar supportedPublicKeys: A list of strings representing the public key types supported, in order from most-preferred to least. @ivar supportedCompressions: A list of strings representing compression types supported, from most-preferred to least. @ivar supportedLanguages: A list of strings representing languages supported, from most-preferred to least. @ivar supportedVersions: A container of strings representing supported ssh protocol version numbers. @ivar isClient: A boolean indicating whether this is a client or server. @ivar gotVersion: A boolean indicating whether we have received the version string from the other side. @ivar buf: Data we've received but hasn't been parsed into a packet. @ivar outgoingPacketSequence: the sequence number of the next packet we will send. @ivar incomingPacketSequence: the sequence number of the next packet we are expecting from the other side. @ivar outgoingCompression: an object supporting the .compress(str) and .flush() methods, or None if there is no outgoing compression. Used to compress outgoing data. @ivar outgoingCompressionType: A string representing the outgoing compression type. @ivar incomingCompression: an object supporting the .decompress(str) method, or None if there is no incoming compression. Used to decompress incoming data. @ivar incomingCompressionType: A string representing the incoming compression type. @ivar ourVersionString: the version string that we sent to the other side. Used in the key exchange. @ivar otherVersionString: the version string sent by the other side. Used in the key exchange. @ivar ourKexInitPayload: the MSG_KEXINIT payload we sent. Used in the key exchange. @ivar otherKexInitPayload: the MSG_KEXINIT payload we received. Used in the key exchange @ivar sessionID: a string that is unique to this SSH session. Created as part of the key exchange, sessionID is used to generate the various encryption and authentication keys. @ivar service: an SSHService instance, or None. If it's set to an object, it's the currently running service. @ivar kexAlg: the agreed-upon key exchange algorithm. @ivar keyAlg: the agreed-upon public key type for the key exchange. @ivar currentEncryptions: an SSHCiphers instance. It represents the current encryption and authentication options for the transport. @ivar nextEncryptions: an SSHCiphers instance. Held here until the MSG_NEWKEYS messages are exchanged, when nextEncryptions is transitioned to currentEncryptions. @ivar first: the first bytes of the next packet. In order to avoid decrypting data twice, the first bytes are decrypted and stored until the whole packet is available. @ivar _keyExchangeState: The current protocol state with respect to key exchange. This is either C{_KEY_EXCHANGE_NONE} if no key exchange is in progress (and returns to this value after any key exchange completqes), C{_KEY_EXCHANGE_REQUESTED} if this side of the connection initiated a key exchange, and C{_KEY_EXCHANGE_PROGRESSING} if the other side of the connection initiated a key exchange. C{_KEY_EXCHANGE_NONE} is the initial value (however SSH connections begin with key exchange, so it will quickly change to another state). @ivar _blockedByKeyExchange: Whenever C{_keyExchangeState} is not C{_KEY_EXCHANGE_NONE}, this is a C{list} of pending messages which were passed to L{sendPacket} but could not be sent because it is not legal to send them while a key exchange is in progress. When the key exchange completes, another attempt is made to send these messages. @ivar _peerSupportsExtensions: a boolean indicating whether the other side of the connection supports RFC 8308 extension negotiation. @ivar peerExtensions: a dict of extensions supported by the other side of the connection. 2.0sTwisted_asciirCSSH--r)r=r>r?r@rAsecdhecdsasssh-rsasssh-dsss ssh-ed25519r<zlibr$)s1.99rFrN_KEY_EXCHANGE_NONE_KEY_EXCHANGE_REQUESTED_KEY_EXCHANGE_PROGRESSINGs ext-info-cs ext-info-speerExtensionscCs2|jr|jt|dr||jddS)a When the underlying connection is closed, stop the running service (if any), and log out the avatar (if any). @type reason: L{twisted.python.failure.Failure} @param reason: The cause of the connection being closed. avatarzconnection lostN)serviceserviceStoppedhasattrlogoutFunction_loginfo)rMreasonr$r$r%connectionLosts   zSSHTransportBase.connectionLostcCsD|j|jdtdddd|_|jdddddd|dS)z Called when the connection is made to the other side. We sent our version and the MSG_KEXINIT packet. s r<rCN) transportwriteourVersionStringr,currentEncryptionsrb sendKexInitrMr$r$r%connectionMades zSSHTransportBase.connectionMadecCs|j|jkrtd|jft|j}||jr|jn|jd t t ft dtd |td |jtd |jtd |jtd |jtd |jtd |jtd |jtd |jtd |jdg |_|t |jdd|j|_g|_dS)a7 Send a I{KEXINIT} message to initiate key exchange or to respond to a key exchange initiated by the peer. @raise RuntimeError: If a key exchange has already been started and it is not appropriate to send a I{KEXINIT} message at this time. @return: L{None} z2Cannot send KEXINIT while key exchange state is %rrCr.,sN)_keyExchangeStater RuntimeErrorlistsupportedKeyExchangesrisClient _EXT_INFO_C _EXT_INFO_Sjoinbytes MSG_KEXINITr secureRandomrsupportedPublicKeysr supportedMACssupportedCompressionssupportedLanguagesourKexInitPayload sendPacketr_blockedByKeyExchange)rMrr$r$r%rs:     zSSHTransportBase.sendKexInitcCs`d|kr dkrnn|tttfvSd|krdkr$nn|tfvSd|ko-dkSS)a Determine if the given message type may be sent while key exchange is in progress. @param messageType: The type of message @type messageType: L{int} @return: C{True} if the given type of message may be sent while key exchange is in progress, C{False} if it may not. @rtype: L{bool} @see: U{http://tools.ietf.org/html/rfc4253#section-7.1} r1)MSG_SERVICE_REQUESTMSG_SERVICE_ACCEPT MSG_EXT_INFOr)rM messageTyper$r$r%_allowedKeyExchangeMessageTypeDs z/SSHTransportBase._allowedKeyExchangeMessageTypecCs|j|jkr||s|j||fdSt|f|}|jr+|j||jd}|j j }dt |}|||}|dkrC||}t d||d||t|}|j ||j |j|}|j||jd7_dS)a Sends a packet. If it's been set up, compress the data, encrypt it, and authenticate it before sending. If key exchange is in progress and the message is not part of key exchange, queue it to be sent later. @param messageType: The type of the packet; generally one of the MSG_* values. @type messageType: L{int} @param payload: The payload for the message. @type payload: L{str} N!LBr)rrrrrroutgoingCompressioncompressflushrrHlenrrrrrroutgoingPacketSequencerr)rMrpayloadbs totalSizelenPadpacket encPacketr$r$r%r^s:     zSSHTransportBase.sendPacketc Cs|jj}|jj}t|j|krdSt|ds"|j|jd|}n|j}|`t d|dd\}}|dkrD| t t d|dSt|j|d|krT||_dS|d|dkrq| t t d |d||d|fdS|jdd||jd|d}|_||j||d}t|d|kr| t d dS|r|jd||j|d}|_|j |j||s| td dS|d| } |jrz|j| } Wnty|jd | td YdSw|jd7_| S)z Try to return a decrypted, authenticated, and decompressed packet out of the buffer. If there is not enough data, return None. @rtype: L{str} or L{None} @return: The decoded packet, if any. Nfirstrrizbad packet length rrzbad packet mod (%i%%%i == %i)sbad decryptionsbad MACzError decompressing payloadscompression errorr)rrIrJrbufrrrrunpacksendDisconnectDISCONNECT_PROTOCOL_ERRORrrincomingPacketSequenceDISCONNECT_MAC_ERRORincomingCompression decompress ExceptionrfailureDISCONNECT_COMPRESSION_ERROR) rMrmsr packetLen paddingLenencDatarmacDatarr$r$r% getPacketsf  (      zSSHTransportBase.getPacketcCs|td|dS)z Called when an unsupported version of the ssh protocol is received from the remote endpoint. @param remoteVersion: remote ssh protocol version which is unsupported by us. @type remoteVersion: L{str} s bad version N)r)DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED)rM remoteVersionr$r$r%_unsupportedVersionReceiveds z,SSHTransportBase._unsupportedVersionReceivedcCs|j||_|jset|jdkr|tddS|jd|jddkr'dS|jd}|D]5}|drdd|_|d|_ |d d }||j vrS| |dS| |}d ||d d|_q/|}|rt|d d }|||d d|}|skdSdS) a First, check for the version string (SSH-2.0-*). After that has been received, this method adds data to the buffer, and pulls out any packets. @type data: L{bytes} @param data: The data that was received. isKPeer version string longer than 4KB. Preventing a denial of service attack.N rrT rrr)r gotVersionrrDISCONNECT_CONNECTION_LOSTfindsplit startswithrstripotherVersionStringsupportedVersionsrindexrrorddispatchMessage)rMr#linesprryr messageNumr$r$r% dataReceiveds8        zSSHTransportBase.dataReceivedcCs|dkr2|tvr2t|dd}t|d|d}|dur#||dS|jjd||d|dS|jr>|j||dS|jjd||d|dS) z Send a received message to the appropriate method. @type messageNum: L{int} @param messageNum: The message number. @type payload: L{bytes} @param payload: The message payload. 2rNssh_z*couldn't handle {messageType}: {payload!r})rrz)couldn't handle {messageNum}: {payload!r})rr)messagesgetattrrdebugsendUnimplementedrpacketReceived)rMrrrfr$r$r%rs&    z SSHTransportBase.dispatchMessagecCt|jS)z Returns an L{SSHTransportAddress} corresponding to the other (peer) side of this transport. @return: L{SSHTransportAddress} for the peer @rtype: L{SSHTransportAddress} @since: 12.1 )rSSHTransportAddressrgetPeerrr$r$r%r zSSHTransportBase.getPeercCr)z Returns an L{SSHTransportAddress} corresponding to the this side of transport. @return: L{SSHTransportAddress} for the peer @rtype: L{SSHTransportAddress} @since: 12.1 )rrrgetHostrr$r$r%r)rzSSHTransportBase.getHostcCs|jS)zS The key exchange algorithm name agreed between client and server. _kexAlgrr$r$r%kexAlg4zSSHTransportBase.kexAlgcCs ||_dS)z6 Set the key exchange algorithm name. Nr)rMvaluer$r$r%r;s c Csdttf||_t|ddd}|dd|d}}dd|D\ }}}}} } } } } }|| | g}|| | g}|jr?||}}|j|j|j|j|j|j|j |j f}|||d|d|d|d|d |d f}|jro||}}t |d|d|_ t |d|d|_ t t |d |d t |d |d t |d |d t |d |d |_t |d |d |_t |d|d|_d|j |j |j|jfvs|j |j|jfvr|tddSd|jjvr|tddS|jr|jn|j|v|_|jjd|j |j d|jjd|jj|jj|jd|jjd|jj|jj|jd|j|jkr)|j |_n|!|||fS)a Called when we receive a MSG_KEXINIT message. Payload:: bytes[16] cookie string keyExchangeAlgorithms string keyAlgorithms string incomingEncryptions string outgoingEncryptions string incomingAuthentications string outgoingAuthentications string incomingCompressions string outgoingCompressions string incomingLanguages string outgoingLanguages bool firstPacketFollows unit32 0 (reserved) Starts setting up the key exchange, keys, encryptions, and authentications. Extended by ssh_KEXINIT in SSHServerTransport and SSHClientTransport. @type packet: L{bytes} @param packet: The message data. @return: A L{tuple} of negotiated key exchange algorithms, key algorithms, and unhandled data, or L{None} if something went wrong. r.N rcss|]}|dVqdS)rN)r).0sr$r$r% {sz/SSHTransportBase.ssh_KEXINIT..rrrrTrrscouldn't match all kex partsz%kex alg={kexAlg!r} key alg={keyAlg!r})rkeyAlgz)outgoing: {cip!r} {mac!r} {compression!r})rgrt compressionz)incoming: {cip!r} {mac!r} {compression!r})"rrotherKexInitPayloadrrrrrrrrrrr,nextEncryptionsoutgoingCompressionTypeincomingCompressionTyperrrDISCONNECT_KEY_EXCHANGE_FAILED__dict__values_peerSupportsExtensionsrr rDrFrErGrrrr)rMrkstringsrestkexAlgskeyAlgsencCSencSCmacCSmacSCcompCScompSClangCSlangSCoutsinsserverclientr$r$r% ssh_KEXINITPs    ,     zSSHTransportBase.ssh_KEXINITcCsFtd|ddd}t|dd\}}||||jdS)a< Called when we receive a MSG_DISCONNECT message. Payload:: long code string description This means that the other side has disconnected. Pass the message up and disconnect ourselves. @type packet: L{bytes} @param packet: The message data. rNrr)rrr receiveErrorrloseConnection)rMr reasonCode descriptionfoor$r$r%ssh_DISCONNECTs  zSSHTransportBase.ssh_DISCONNECTcCsdS)z Called when we receive a MSG_IGNORE message. No payload. This means nothing; we simply return. @type packet: L{bytes} @param packet: The message data. Nr$rMrr$r$r% ssh_IGNOREszSSHTransportBase.ssh_IGNOREcCstd|\}||dS)z Called when we receive a MSG_UNIMPLEMENTED message. Payload:: long packet This means that the other side did not implement one of our packets. @type packet: L{bytes} @param packet: The message data. rN)rrreceiveUnimplemented)rMrseqnumr$r$r%ssh_UNIMPLEMENTEDs z"SSHTransportBase.ssh_UNIMPLEMENTEDcCs>tt|dd}t|ddd\}}}||||dS)a0 Called when we receive a MSG_DEBUG message. Payload:: bool alwaysDisplay string message string language This means the other side has passed along some debugging info. @type packet: L{bytes} @param packet: The message data. rrNr)boolrr receiveDebug)rMr alwaysDisplaymessagelangr?r$r$r% ssh_DEBUGs zSSHTransportBase.ssh_DEBUGcCsVtd|dd\}|dd}i}t|D]}t|d\}}}|||<q||_dS)aD Called when we get a MSG_EXT_INFO message. Payload:: uint32 nr-extensions repeat the following 2 fields "nr-extensions" times: string extension-name string extension-value (binary) @type packet: L{bytes} @param packet: The message data. rNrr)rrrangerr)rMr numExtensions extensions_extNameextValuer$r$r% ssh_EXT_INFOs    zSSHTransportBase.ssh_EXT_INFOcCs<|jjd|jd|jr|j||_||_|jdS)z Set our service to service and start it running. If we were running a service previously, stop it first. @type service: C{SSHService} @param service: The service to attach. zstarting service {service!r})rN)rr namerrrserviceStarted)rMrr$r$r% setServices  zSSHTransportBase.setServicecCs(|t|rdndt|t|dS)a Send a debug message to the other side. @param message: the message to send. @type message: L{str} @param alwaysDisplay: if True, tell the other side to always display this message. @type alwaysDisplay: L{bool} @param language: optionally, the language the message is in. @type language: L{str} rmN)r MSG_DEBUGr)rMrIrHlanguager$r$r% sendDebug#s zSSHTransportBase.sendDebugcCs|tt|dS)a Send a message that will be ignored by the other side. This is useful to fool attacks based on guessing packet sizes in the encrypted stream. @param message: data to send with the message @type message: L{str} N)r MSG_IGNOREr)rMrIr$r$r% sendIgnore3s zSSHTransportBase.sendIgnorecCs|j}|ttd|dS)zc Send a message to the other side that the last packet was not understood. z!LN)rrMSG_UNIMPLEMENTEDrrrMrDr$r$r%r >sz"SSHTransportBase.sendUnimplementedcCsD|ttd|t|td|jjd||d|jdS)aJ Send a disconnect message to the other side and then disconnect. @param reason: the reason for the disconnect. Should be one of the DISCONNECT_* values. @type reason: L{int} @param desc: a descrption of the reason for the disconnection. @type desc: L{str} rrCz;Disconnecting with error, code {code} reason: {description}coder>N) rMSG_DISCONNECTrrrrrrr<)rMrdescr$r$r%rFs$ zSSHTransportBase.sendDisconnectcCs@|jrdtdt|gdd|D}|t|dSdS)a Send an RFC 8308 extension advertisement to the remote peer. Nothing is sent if the peer doesn't support negotiations. @type extensions: L{list} of (L{bytes}, L{bytes}) @param extensions: a list of (extension-name, extension-value) pairs. rCrcSs g|] \}}t|t|qSr$)r)rrSrr$r$r% cs z0SSHTransportBase.sendExtInfo..N)r(rrrrrr)rMrNrr$r$r% sendExtInfoXs zSSHTransportBase.sendExtInfocCsDt|j|j}|t}||_|j j }t ||_ dS)z Prepares for a Diffie-Hellman key agreement exchange. Creates an ephemeral keypair in the group defined by (self.g, self.p) and stores it. N) r DHParameterNumbersrg parametersr generate_private_key dhSecretKey public_keypublic_numbersyrdhSecretKeyPublicMP)rMnumbersrfrkr$r$r%_startEphemeralDHgs   z"SSHTransportBase._startEphemeralDHcCst|t|j|jt}|j|}|`| d}t |dd}|d@r9t dt |dd}||St dt |}||S)a  Completes the Diffie-Hellman key agreement started by _startEphemeralDH, and forgets the ephemeral secret key. @type remoteDHpublicKey: L{int} @rtype: L{bytes} @return: The new shared secret, in SSH C{mpint} format. rmrrr)r DHPublicNumbersrdrrerir rhexchangelstriprrrr)rMremoteDHpublicKey remoteKeysecretchprefixr$r$r%_finishEphemeralDHus   z#SSHTransportBase._finishEphemeralDHc Cst|j}|||||j}|}||||}|||||}||||||}||||S)a Get one of the keys for authentication/encryption. @type c: L{bytes} @param c: The letter identifying which key this is. @type sharedSecret: L{bytes} @param sharedSecret: The shared secret K. @type exchangeHash: L{bytes} @param exchangeHash: The hash H from key exchange. @rtype: L{bytes} @return: The derived key. )rgetHashProcessorr sessionIDr) rMc sharedSecret exchangeHash hashProcessork1k2k3k4r$r$r%_getKeys zSSHTransportBase._getKeyc Cs|js||_|d||}|d||}|d||}|d||}|d||}|d||}|||g} |||g} |jrB| | } } |j| d| d| d| d| d | d |td d S) a Set up the keys for the connection and sends MSG_NEWKEYS when finished, @param sharedSecret: a secret string agreed upon using a Diffie- Hellman exchange, so it is only shared between the server and the client. @type sharedSecret: L{str} @param exchangeHash: A hash of various data known by both sides. @type exchangeHash: L{str} ABCDEFrrrrCN)rzrrr"rbr MSG_NEWKEYS) rMr|r}initIVCSinitIVSCencKeyCSencKeySC integKeyCS integKeySCr6r7r$r$r% _keySetups    .zSSHTransportBase._keySetupcCsp|jd|j|_|jdkrtd|_|jdkrt |_ |j |_ |j }d|_ |D] \}}|||q+dS)a* Called back by a subclass once a I{MSG_NEWKEYS} message has been received. This indicates key exchange has completed and new encryption and compression parameters should be adopted. Any messages which were queued during key exchange will also be flushed. zNEW KEYSrrN)rr r"rr#zlib compressobjrr$ decompressobjrrrrr)rMr rrr$r$r%_newKeyss      zSSHTransportBase._newKeysoutcCL|dkr |jjdkS|dkr|jjdkS|dkr"|do!|dStd)z Check if the connection is encrypted in the given direction. @type direction: L{str} @param direction: The direction: one of 'out', 'in', or 'both'. @rtype: L{bool} @return: C{True} if it is encrypted. rr<inboth(direction must be "out", "in", or "both")rrDrE isEncrypted TypeErrorrM directionr$r$r%r  zSSHTransportBase.isEncryptedcCr)a  Check if the connection is verified/authentication in the given direction. @type direction: L{str} @param direction: The direction: one of 'out', 'in', or 'both'. @rtype: L{bool} @return: C{True} if it is verified. rr<rrr)rrFrG isVerifiedrrr$r$r%rrzSSHTransportBase.isVerifiedcCs|tddS)zn Lose the connection to the other side, sending a DISCONNECT_CONNECTION_LOST message. suser closed connectionN)rrrr$r$r%r<szSSHTransportBase.loseConnectioncCs|jjd||ddS)a Called when we receive a disconnect error message from the other side. @param reasonCode: the reason for the disconnect, one of the DISCONNECT_ values. @type reasonCode: L{int} @param description: a human-readable description of the disconnection. @type description: L{str} z3Got remote error, code {code} reason: {description}r^N)rerror)rMr=r>r$r$r%r; s   zSSHTransportBase.receiveErrorcCs|jjd|ddS)z Called when we receive an unimplemented packet message from the other side. @param seqnum: the sequence number that was not understood. @type seqnum: L{int} z)other side unimplemented packet #{seqnum})rDN)rwarnr]r$r$r%rCsz%SSHTransportBase.receiveUnimplementedcCs|r |jjd|ddSdS)a Called when we receive a debug message from the other side. @param alwaysDisplay: if True, this message should always be displayed. @type alwaysDisplay: L{bool} @param message: the debug message @type message: L{str} @param lang: optionally the language the message is in. @type lang: L{str} zRemote Debug Message: {message})rIN)rr )rMrHrIrJr$r$r%rG%s zSSHTransportBase.receiveDebugcCsr|jdr'ztjd|jdd}Wn tytdwt|tS|jdvr1t j Std |j)a> Generate an private key for ECDH key exchange. @rtype: The appropriate private key type matching C{self.kexAlg}: L{ec.EllipticCurvePrivateKey} for C{ecdh-sha2-nistp*}, or L{x25519.X25519PrivateKey} for C{curve25519-sha256}. @return: The generated private key. ecdh-sha2-nistprrN unused-keyscurve25519-sha256scurve25519-sha256@libssh.orgz3Cannot generate elliptic curve private key for {!r}) rrr _curveTableKeyErrorrr rgr r X25519PrivateKeygenerateformat)rMcurver$r$r%_generateECPrivateKey4s    z&SSHTransportBase._generateECPrivateKeycCsN|jdr|tjjtjjS|jdvr|tjjtjjSt d|j)a Encode an elliptic curve public key to bytes. @type ecPub: The appropriate public key type matching C{self.kexAlg}: L{ec.EllipticCurvePublicKey} for C{ecdh-sha2-nistp*}, or L{x25519.X25519PublicKey} for C{curve25519-sha256}. @param ecPub: The public key to encode. @rtype: L{bytes} @return: The encoded public key. rrz,Cannot encode elliptic curve public key for ) rr public_bytesr EncodingX962 PublicFormatUncompressedPointRawr)rMecPubr$r$r%_encodeECPublicKeyMs    z#SSHTransportBase._encodeECPublicKeycCs|jdr3ztjd|jdd}Wn tytdwtj||}| t |}t|S|jdvrGt j |}| |}t|Std|j)a Generate a shared secret for ECDH key exchange. @type ecPriv: The appropriate private key type matching C{self.kexAlg}: L{ec.EllipticCurvePrivateKey} for C{ecdh-sha2-nistp*}, or L{x25519.X25519PrivateKey} for C{curve25519-sha256}. @param ecPriv: Our private key. @rtype: L{bytes} @return: The generated shared secret, as an SSH multiple-precision integer. rrrNrrz5Cannot generate elliptic curve shared secret for {!r})rrrrrrr EllipticCurvePublicKeyfrom_encoded_pointrqECDHr X25519PublicKeyfrom_public_bytesrr&)rMecPrivtheirECPubBytesr theirECPubr|r$r$r%_generateECSharedSecreths(    z(SSHTransportBase._generateECSharedSecret)FrC)r)Zr(r)r*r+rrprotocolVersiontwisted_versionencodeversioncommentstriprrrrrgetSupportedKeyExchangesrreckeyrreplacer ed25519_supportedrrrrrrrrrrrrzrrrrrrrrr(rrr__annotations__rrrrrrrrrrrpropertyrsetterr:r@rBrErKrRrUrYr[r rrcrnrxrrrrrr<r;rCrGrrrr$r$r$r%r5s x     2'> .    z         rc@s`eZdZdZdZdZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZdS)SSHServerTransporta/ SSHServerTransport implements the server side of the SSH protocol. @ivar isClient: since we are never the client, this is always False. @ivar ignoreNextPacket: if True, ignore the next key exchange packet. This is set when the client sends a guessed key exchange packet but with an incorrect guess. @ivar dhGexRequest: the KEX_DH_GEX_REQUEST(_OLD) that the client sent. The key generation needs this to be stored. @ivar g: the Diffie-Hellman group generator. @ivar p: the Diffie-Hellman group prime. FrcCsdt||}|s dS|\}}}t|ddr.|d|jdks)|d|jdkr0d|_dSdSdS)aM Called when we receive a MSG_KEXINIT message. For a description of the packet, see SSHTransportBase.ssh_KEXINIT(). Additionally, this method checks if a guessed key exchange packet was sent. If it was sent, and it guessed incorrectly, the next key exchange packet MUST be ignored. NrrT)rr:rrrignoreNextPacket)rMrretvalr,r-r+r$r$r%r:s   zSSHServerTransport.ssh_KEXINITc Cst|\}}|jj|j}|jj|j}|}||_||j}| ||}t |j }| t|j| t|j| t|j| t|j| t|| t|| t|| ||} |tt|t|t|| ||| dS)a Called from L{ssh_KEX_DH_GEX_REQUEST_OLD} to handle elliptic curve key exchanges. Payload:: string client Elliptic Curve Diffie-Hellman public key Just like L{_ssh_KEXDH_INIT} this message type is also not dispatched directly. Extra check to determine if this is really KEX_ECDH_INIT is required. First we load the host's public/private keys. Then we generate the ECDH public/private keypair for the given curve. With that we generate the shared secret key. Then we compute the hash to sign and send back to the client Along with the server's public key and the ECDH public key. @type packet: L{bytes} @param packet: The message data. @return: None. N)rfactory publicKeysr privateKeysrrirrrrryrr|rrrr!rblobrrMSG_KEXDH_REPLYsignr) rMrpktPub pubHostKey privHostKeyrencPubr|hr}r$r$r%_ssh_KEX_ECDH_INITs,      z%SSHServerTransport._ssh_KEX_ECDH_INITcCst|\}}t|j\|_|_|||}t|j}| t |j | t |j | t |j | t |j| t |jj|j| t|| |j| ||}|tt |jj|j|jt |jj|j||||dS)aW Called to handle the beginning of a non-group key exchange. Unlike other message types, this is not dispatched automatically. It is called from C{ssh_KEX_DH_GEX_REQUEST_OLD} because an extra check is required to determine if this is really a KEXDH_INIT message or if it is a KEX_DH_GEX_REQUEST_OLD message. The KEXDH_INIT payload:: integer e (the client's Diffie-Hellman public key) We send the KEXDH_REPLY with our host key and signature. @type packet: L{bytes} @param packet: The message data. N)rrgetDHGeneratorAndPrimerrerrnrxryr|rrrr!rrrrrrrlrrrrrrrMrclientDHpublicKeyr?r|rr}r$r$r%_ssh_KEXDH_INITs.    z"SSHServerTransport._ssh_KEXDH_INITcCs|jrd|_dSt|jr||St|jr||S||_t d|d}|j |\|_ |_ ||tt|j t|j dS)a This represents different key exchange methods that share the same integer value. If the message is determined to be a KEXDH_INIT, L{_ssh_KEXDH_INIT} is called to handle it. If it is a KEX_ECDH_INIT, L{_ssh_KEX_ECDH_INIT} is called. Otherwise, for KEX_DH_GEX_REQUEST_OLD payload:: integer ideal (ideal size for the Diffie-Hellman prime) We send the KEX_DH_GEX_GROUP message with the group that is closest in size to ideal. If we were told to ignore the next key exchange packet by ssh_KEXINIT, drop it on the floor and return. @type packet: L{bytes} @param packet: The message data. rNr)rr isFixedGrouprrisEllipticCurver dhGexRequestrrr getDHPrimererrnrMSG_KEX_DH_GEX_GROUPr)rMridealr$r$r%ssh_KEX_DH_GEX_REQUEST_OLDs     z-SSHServerTransport.ssh_KEX_DH_GEX_REQUEST_OLDcCsd|jrd|_dS||_td|\}}}|j|\|_|_|| t t |jt |jdS)a# Called when we receive a MSG_KEX_DH_GEX_REQUEST message. Payload:: integer minimum integer ideal integer maximum The client is asking for a Diffie-Hellman group between minimum and maximum size, and close to ideal if possible. We reply with a MSG_KEX_DH_GEX_GROUP message. If we were told to ignore the next key exchange packet by ssh_KEXINIT, drop it on the floor and return. @type packet: L{bytes} @param packet: The message data. rNz>3L) rrrrrrrerrnrrr)rMrminrmaxr$r$r%ssh_KEX_DH_GEX_REQUEST>s z)SSHServerTransport.ssh_KEX_DH_GEX_REQUESTcCs$t|\}}||}t|j}|t|j|t|j|t|j |t|j |t|j j |j ||j|t|j|t|j|t|||j|||}|tt|j j |j |jt|j j|j ||||dS)a Called when we get a MSG_KEX_DH_GEX_INIT message. Payload:: integer e (client DH public key) We send the MSG_KEX_DH_GEX_REPLY message with our host key and signature. @type packet: L{bytes} @param packet: The message data. N)rrxrryrr|rrrr!rrrrrrrrrerlrrMSG_KEX_DH_GEX_REPLYrrrrr$r$r%ssh_KEX_DH_GEX_INITXs0    z&SSHServerTransport.ssh_KEX_DH_GEX_INITcCs<|jdu}t||||r|dd|jfgdSdS)3 See SSHTransportBase._keySetup(). Nsserver-sig-algsr)rzrrrcrr)rMr|r}firstKeyr$r$r%rs zSSHServerTransport._keySetupcCs$|dkr |tddS|dS)a Called when we get a MSG_NEWKEYS message. No payload. When we get this, the keys have been set on both sides, and we start using them to encrypt and authenticate the connection. @type packet: L{bytes} @param packet: The message data. rCNEWKEYS takes no dataN)rrrrAr$r$r% ssh_NEWKEYSs  zSSHServerTransport.ssh_NEWKEYScCsRt|\}}|j||}|s|td|dS|tt|||dS)aX Called when we get a MSG_SERVICE_REQUEST message. Payload:: string serviceName The client has requested a service. If we can start the service, start it; otherwise, disconnect with DISCONNECT_SERVICE_NOT_AVAILABLE. @type packet: L{bytes} @param packet: The message data. sdon't have service N) rr getServicer DISCONNECT_SERVICE_NOT_AVAILABLErrrrU)rMrrr+clsr$r$r%ssh_SERVICE_REQUESTs z&SSHServerTransport.ssh_SERVICE_REQUESTN)r(r)r*r+rrr:rrrrrrrrr$r$r$r%rs;(%) rc@seZdZdZdZdZdZdZddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZd d!Zd"S)#SSHClientTransporta) SSHClientTransport implements the client side of the SSH protocol. @ivar isClient: since we are always the client, this is always True. @ivar _gotNewKeys: if we receive a MSG_NEWKEYS message before we are ready to transition to the new keys, this is set to True so we can transition when the keys are ready locally. @ivar x: our Diffie-Hellman private key. @ivar e: our Diffie-Hellman public key. @ivar g: the Diffie-Hellman group generator. @ivar p: the Diffie-Hellman group prime @ivar instance: the SSHService object we are requesting. @ivar _dhMinimalGroupSize: Minimal acceptable group size advertised by the client in MSG_KEX_DH_GEX_REQUEST. @type _dhMinimalGroupSize: int @ivar _dhMaximalGroupSize: Maximal acceptable group size advertised by the client in MSG_KEX_DH_GEX_REQUEST. @type _dhMaximalGroupSize: int @ivar _dhPreferredGroupSize: Preferred group size advertised by the client in MSG_KEX_DH_GEX_REQUEST. @type _dhPreferredGroupSize: int Tii icCst|d|_dS)z{ Called when the connection is started with the server. Just sets up a private instance variable. rN)rr _gotNewKeysrr$r$r%rs  z!SSHClientTransport.connectionMadec Cst||dur dSt|jr)||_|j|_| t t | |jdSt |jrFt|j\|_|_|| t|jdS| ttd|j|j|jdS)a> Called when we receive a MSG_KEXINIT message. For a description of the packet, see SSHTransportBase.ssh_KEXINIT(). Additionally, this method sends the first key exchange packet. If the agreed-upon exchange is ECDH, generate a key pair for the corresponding curve and send the public key. If the agreed-upon exchange has a fixed prime/generator group, generate a public key and send it in a MSG_KEXDH_INIT message. Otherwise, ask for a 2048 bit group with a MSG_KEX_DH_GEX_REQUEST message. N!LLL)rr:rrrrrrirrMSG_KEX_DH_GEX_REQUEST_OLDrrrrrerrnMSG_KEXDH_INITrlMSG_KEX_DH_GEX_REQUESTrr_dhMinimalGroupSize_dhPreferredGroupSize_dhMaximalGroupSizerAr$r$r%r:s*    zSSHClientTransport.ssh_KEXINITcspfdd}t|d\}}}}dddtt|D}||}||||||fdd|S) a Called to handle a reply to a ECDH exchange message(KEX_ECDH_INIT). Like the handler for I{KEXDH_INIT}, this message type has an overlapping value. This method is called from C{ssh_KEX_DH_GEX_GROUP} if that method detects a non-group key exchange is in progress. Payload:: string serverHostKey string server Elliptic Curve Diffie-Hellman public key string signature We verify the host key and continue if it passes verificiation. Otherwise raise an exception and return. @type packet: L{bytes} @param packet: The message data. @return: A deferred firing when key exchange is complete. cs|}j|}tj}|tj|tj|tj |tj |t||t j |t|||| }tj|||sdtddS||dS)N bad signature)rrrryrr|rrrrr!rrrrKey fromStringrrr%r)ignoredhostKeypubKey signature theirECHostr|rr}rr$r%_continue_KEX_ECDH_REPLY0s zHSSHClientTransport._ssh_KEX_ECDH_REPLY.._continue_KEX_ECDH_REPLYrT:cSg|]}t|qSr$binasciihexlifyrrvr$r$r%rbPz:SSHClientTransport._ssh_KEX_ECDH_REPLY..c tdSNs bad host keyr"DISCONNECT_HOST_KEY_NOT_VERIFIABLEunusedrr$r%Uz8SSHClientTransport._ssh_KEX_ECDH_REPLY..)rrrrr verifyHostKey addCallback addErrback)rMrrrrr fingerprintdr$rr%_ssh_KEX_ECDH_REPLYs   z&SSHClientTransport._ssh_KEX_ECDH_REPLYcxt|\}}t|\}}t|\}}dddtt|D}||}|j|||| fdd|S)a Called to handle a reply to a non-group key exchange message (KEXDH_INIT). Like the handler for I{KEXDH_INIT}, this message type has an overlapping value. This method is called from C{ssh_KEX_DH_GEX_GROUP} if that method detects a non-group key exchange is in progress. Payload:: string serverHostKey integer f (server Diffie-Hellman public key) string signature We verify the host key by calling verifyHostKey, then continue in _continueKEXDH_REPLY. @type packet: L{bytes} @param packet: The message data. @return: A deferred firing when key exchange is complete. rcSrr$rr r$r$r%rbvr z7SSHClientTransport._ssh_KEXDH_REPLY..cr r r rrr$r%r{rz5SSHClientTransport._ssh_KEXDH_REPLY..) rrrrrrrr_continueKEXDH_REPLYrrMrrrrrrr$rr%_ssh_KEXDH_REPLY[s     z#SSHClientTransport._ssh_KEXDH_REPLYcCsbt|jr ||St|jr||St|\|_}t|\|_}| | t |j dS)a This handles different messages which share an integer value. If the key exchange does not have a fixed prime/generator group, we generate a Diffie-Hellman public key and send it in a MSG_KEX_DH_GEX_INIT message. Payload:: string g (group generator) string p (group prime) @type packet: L{bytes} @param packet: The message data. N) rrrrrrrrrernrMSG_KEX_DH_GEX_INITrl)rMrr+r$r$r%ssh_KEX_DH_GEX_GROUPs    z'SSHClientTransport.ssh_KEX_DH_GEX_GROUPc Cstj|}||}t|j}|t|j |t|j |t|j |t|j |t|||j |t||||}|||s]|tddS|||dS) The host key has been verified, so we generate the keys. @param ignored: Ignored. @param pubKey: the public key blob for the server's public key. @type pubKey: L{str} @param f: the server's Diffie-Hellman public key. @type f: L{int} @param signature: the server's signature, verifying that it has the correct private key. @type signature: L{str} rN)rrrrxrryrr|rrrrr!rlrrrrr%r rMrrrr serverKeyr|rr}r$r$r%rs      z'SSHClientTransport._continueKEXDH_REPLYcr)a Called when we receive a MSG_KEX_DH_GEX_REPLY message. Payload:: string server host key integer f (server DH public key) We verify the host key by calling verifyHostKey, then continue in _continueGEX_REPLY. @type packet: L{bytes} @param packet: The message data. @return: A deferred firing once key exchange is complete. rcSrr$r)rr{r$r$r%rbr z;SSHClientTransport.ssh_KEX_DH_GEX_REPLY..cr r r rrr$r%rrz9SSHClientTransport.ssh_KEX_DH_GEX_REPLY..) rrrrrrrr_continueGEX_REPLYrrr$rr%ssh_KEX_DH_GEX_REPLYs     z'SSHClientTransport.ssh_KEX_DH_GEX_REPLYc Cstj|}||}t|j}|t|j |t|j |t|j |t|j |t||t d|j|j|j|t|j|t|j||j|t||||}|||s{|tddS|||dS)rrrN)rrrrxrryrr|rrrrr!rrrrrrrrerlrrrr%rr r$r$r%r"s4      z%SSHClientTransport._continueGEX_REPLYcCs&t||||jr|ddSdS)rrCN)rrrr)rMr|r}r$r$r%rszSSHClientTransport._keySetupcCs>|dkr |tddS|jjsd|_dS||dS)a Called when we receive a MSG_NEWKEYS message. No payload. If we've finished setting up our own keys, start using them. Otherwise, remember that we've received this message. @type packet: L{bytes} @param packet: The message data. rCrNr)rrr"rHrrconnectionSecurerAr$r$r%rs  zSSHClientTransport.ssh_NEWKEYScCsJ|dkr |jdnt|d}||jjkr|td||jdS)z Called when we receive a MSG_SERVICE_ACCEPT message. Payload:: string service name Start the service we requested. @type packet: L{bytes} @param packet: The message data. rCz"got SERVICE_ACCEPT without payloadrs.received accept for service we did not requestN)rrrinstancerSrrrU)rMrrSr$r$r%ssh_SERVICE_ACCEPTs   z%SSHClientTransport.ssh_SERVICE_ACCEPTcCs|tt|j||_dS)z Request that a service be run over this transport. @type instance: subclass of L{twisted.conch.ssh.service.SSHService} @param instance: The service to run. N)rrrrSr%)rMr%r$r$r%requestService.s z!SSHClientTransport.requestServicecCs ttS)aa Returns a Deferred that gets a callback if it is a valid key, or an errback if not. @type hostKey: L{bytes} @param hostKey: The host key to verify. @type fingerprint: L{bytes} @param fingerprint: The fingerprint of the key. @return: A deferred firing with C{True} if the key is valid. )rfailNotImplementedError)rMrrr$r$r%r:s z SSHClientTransport.verifyHostKeycCst)z Called when the encryption has been set up. Generally, requestService() is called to run another service over the transport. )r)rr$r$r%r$Irz#SSHClientTransport.connectionSecureN)r(r)r*r+rrrrrr:rrrrr#r"rrr&r'rr$r$r$r$r%rs( /B&) rc@seZdZdZddZdS)_NullEncryptionContextzH An encryption context that does not actually encrypt anything. cCs|S)z 'Encrypt' new data by doing nothing. @type data: L{bytes} @param data: The data to 'encrypt'. @rtype: L{bytes} @return: The 'encrypted' data. r$)rMr#r$r$r%r|Vs z_NullEncryptionContext.updateN)r(r)r*r+r|r$r$r$r%r*Qs r*c@seZdZdZdZdS)_DummyAlgorithmzJ An encryption algorithm that does not actually encrypt anything. @N)r(r)r*r+rXr$r$r$r%r+csr+c@s&eZdZdZeZddZddZdS)rfz A cipher for the none encryption method. @ivar block_size: the block size of the encryption. In the case of the none cipher, this is 8 bytes. cCtS)zN Construct a noop encryptor. @return: The encryptor. r*rr$r$r%rVuz_DummyCipher.encryptorcCr-)zN Construct a noop decryptor. @return: The decryptor. r.rr$r$r%rY}r/z_DummyCipher.decryptorN)r(r)r*r+r+rWrVrYr$r$r$r%rfks  rfsdiffie-hellman-group14-sha1rrrTrrrrrr"r/!rS r MSG_ MSG_KEXDH_rrz7legacy SSH mnemonics should not end up in messages dict)hr+rrqrrhashlibrrrrrtypingrcryptography.exceptionsrcryptography.hazmat.backendsr cryptography.hazmat.primitivesr )cryptography.hazmat.primitives.asymmetricr r r &cryptography.hazmat.primitives.ciphersrrrtwistedrrtwisted.conch.sshrrrtwisted.conch.ssh.commonrrrrrtwisted.internetrrtwisted.loggerrtwisted.pythonrtwisted.python.compatrrr&tupler'r,rProtocolrrrr*r+rfr DH_GENERATORDH_PRIMEr`rZr\rWrrrrrrrrrrrr&DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECTrr%DISCONNECT_RESERVEDrrrrrrDISCONNECT_BY_APPLICATIONDISCONNECT_TOO_MANY_CONNECTIONS!DISCONNECT_AUTH_CANCELLED_BY_USER)DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLEDISCONNECT_ILLEGAL_USER_NAMEr rglobalsitemsrSrrrr$r$r$r%s        H%`,