Ϫf3NdZddlZddlmZddlmZmZmZddlm Z m Z m Z m Z ddl mZddlmZddlmZdd lmZmZmZdd lmZdd lmZmZdd lmZdd lmZedZ e rddl!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(n GddZ"GddZ)Gdde"jTZ+GddZ,ddlm-Z-e re-j\e,e+e(j^Gddej`Z1GddZ2GddZ3Gd d!Z4Gd"d#Z5e dd$l!m6Z6dd%l$m7Z7m8Z8m9Z9m:Z:m;Z;mejZQGd?d@ejZRy)Az! Tests for L{twisted.conch.ssh}. N)chain)DictListTuple)privateDSA_opensshprivateRSA_opensshpublicDSA_opensshpublicRSA_openssh) LoopbackRelay)portal)UnauthorizedLogin)deferprotocolreactor)ProcessTerminated)failurelog) requireModule)unittest cryptography)avatarerror)_kexcommon forwardingsessionc eZdZGddZy)rc eZdZy)avatar.ConchUserN)__name__ __module__ __qualname__=/usr/lib/python3/dist-packages/twisted/conch/test/test_ssh.py ConchUserr$s r$r&N)r r!r"r&r#r$r%rr#s   r$rc eZdZdZdZdZdZy)ConchTestRealma" A realm which expects a particular avatarId to log in once and creates a L{ConchTestAvatar} for that request. @ivar expectedAvatarID: The only avatarID that this realm will produce an avatar for. @ivar avatar: A reference to the avatar after it is requested. Nc||_yN)expectedAvatarID)selfr+s r%__init__zConchTestRealm.__init__5s 0r$c||jk(rL|j tdt|_|d|j|jjfStd|jd|)z Return a new L{ConchTestAvatar} if the avatarID matches the expected one and this is the first avatar request. zOnly one login allowedrzOnly z may log in, not )r+rr ConchTestAvatarlogout)r,avatarIDmind interfacess r% requestAvatarzConchTestRealm.requestAvatar8sv t,, ,{{&'(@AA)+DKa=$++t{{/A/AA AD)),,=h\ J  r$)r r!r"__doc__rr-r4r#r$r%r(r((sF1  r$r(c@eZdZdZesdZdZdZdZdZ dZ dZ d Z y ) r/z An avatar against which various SSH features can be tested. @ivar loggedOut: A flag indicating whether the avatar logout method has been called. cannot run without cryptographyFctjj|i|_i|_|j j tjtjd|jj dtiy)N)sessions direct-tcpipcrazy) rr&r- listenersglobalRequests channelLookupupdater SSHSessionropenConnectForwardingClientsubsystemLookupCrazySubsystemr,s r%r-zConchTestAvatar.__init__Tsk!!$'  !!#..!+!G!G  ##X~$>?r$c"||jd<y)Nfoor<r,datas r% global_foozConchTestAvatar.global_foo`s%)E"r$c"||jd<y)Nfoo_2)rFdatarGrHs r% global_foo_2zConchTestAvatar.global_foo_2ds'+G$r$c0tj|\}} tj|tj|j ||ftj |}||j||f<y#t$rtjddYywxYw)N) interfacerFz2something went wrong with remote->local forwardingr) runpackGlobal_tcpip_forwardr listenTCPSSHListenForwardingFactoryconn SSHListenServerForwardingChannelr; BaseExceptionrerrr,rIhostportlisteners r%global_tcpip_forwardz$ConchTestAvatar.global_tcpip_forwardhs::4@ d ((55IId|Z-X-X H,4DNND$< (   GGDN O sAA33BBctj|\}}|jj||fd}|sy|j||f=|j y)NrrF)rrQr;get stopListeningrXs r%global_cancel_tcpip_forwardz+ConchTestAvatar.global_cancel_tcpip_forwardysU::4@ d>>%%tTlD9 NND$< ( r$cd|_|jjD]*}tjd|z|j ,y)NTzstopListening %s) loggedOutr;valuesrmsgr_)r,r[s r%r0zConchTestAvatar.logoutsC--/ %H GG&1 2  " " $ %r$N) r r!r"r5rskiprbr-rJrNr\r`r0r#r$r%r/r/Gs5 0I @"%r$r/c4eZdZdZdZdZdZdZdZdZ y) ConchSessionForTestAvatarz2 An ISession adapter for ConchTestAvatar. c||_||j_d|_d|_d|_d|_t j|_y)zq Initialize the session and create a reference to it on the avatar for later inspection. NFr) r _testSessioncmdprotoptyReqeofrDeferredonClose)r,rs r%r-z"ConchSessionForTestAvatar.__init__sA  #'    ~~' r$cXtjd||_||_d|_y)Nzpty reqT)rrd _terminalType _windowSizerl)r,term windowSizeattrss r%getPtyz ConchSessionForTestAvatar.getPtys%  !% r$c`tjd||_t|d|_y)Nz opening shellshell)rrdrk EchoTransportrj)r,rks r% openShellz#ConchSessionForTestAvatar.openShells$   er$cZ||_||_|jd}|dk(r,t|}t j d|j n|dk(r0t|}|j|dd|j n|dk(r0t|}|j|dd|j nJ|dk(r0t|}|j|dd|j ntjdd |jjj_y) Nrfalsesechossechoseechobad execrF)rjrksplitFalseTransportr callLaterloseConnectionrywriteSuperEchoTransportErrEchoTransportr ConchErrorrrT transportexpectedLoseConnection)r,rkrjfts r% execCommandz%ConchSessionForTestAvatar.execCommands IIKN =u%A   a!1!1 2 '\e$A GGCG     (]"5)A GGCG     (] 'A GGCG    "":. .<= ""9r$cd|_yNrF)rmrCs r% eofReceivedz%ConchSessionForTestAvatar.eofReceiveds r$ctjd|jz|jjj |_|jjdy)Nzclosed cmd "%s") rrdrjrkrremoteWindowLeftremoteWindowLeftAtCloserocallbackrCs r%closedz ConchSessionForTestAvatar.closedsB !DHH,-'+zz'9'9'J'J$ d#r$N) r r!r"r5r-rvrzrrrr#r$r%rgrgs% (  >2$r$rg) componentsceZdZdZdZy)rBcyr*r#)r,argskws r%r-zCrazySubsystem.__init__s r$cy)z good ... good Nr#rCs r%connectionMadezCrazySubsystem.connectionMadesr$N)r r!r"r-rr#r$r%rBrBs   r$rBceZdZdZdZdZy)ra False transport should act like a /bin/false execution, i.e. just exit with nonzero status, writing nothing to the terminal. @ivar proto: The protocol associated with this transport. @ivar closed: A flag tracking whether C{loseConnection} has been called yet. cB||_|j|d|_y)zY @type p L{twisted.conch.ssh.session.SSHSessionProcessProtocol} instance rNrkmakeConnectionrr,ps r%r-zFalseTransport.__init__s    r$c :|jryd|_|jj|jj|jj |jj t jtdddy)zI Disconnect the protocol associated with this transport. NrF rrkinConnectionLostoutConnectionLosterrConnectionLost processEndedrFailurerrCs r%rzFalseTransport.loseConnectionsj ;;   ##% $$& $$& 0A#tT0R STr$N)r r!r"r5r-rr#r$r%rrs Ur$rceZdZdZdZdZy)rycB||_|j|d|_yNrrrs r%r-zEchoTransport.__init__   r$ctjt||jj ||jj dd|vr|j yy)N )rrdreprrk outReceivedrrHs r%rzEchoTransport.writesN T  t$ w' d?    ! r$c :|jryd|_|jj|jj|jj |jj t jtdddyNrFrrrCs r%rzEchoTransport.loseConnectionh ;;   ##% $$& $$& 0A!T40P QRr$Nr r!r"r-rrr#r$r%ryrys "Sr$ryceZdZdZdZdZy)rcB||_|j|d|_yrrrs r%r-zErrEchoTransport.__init__rr$cp|jj||jjdyNr)rk errReceivedrHs r%rzErrEchoTransport.writes& t$ w'r$c :|jryd|_|jj|jj|jj |jj t jtdddyrrrCs r%rzErrEchoTransport.loseConnectionrr$Nrr#r$r%rrs (Sr$rceZdZdZdZdZy)rcB||_|j|d|_yrrrs r%r-zSuperEchoTransport.__init__%rr$c|jj||jjd|jj||jjdyr)rkrrrHs r%rzSuperEchoTransport.write*sJ t$ w' t$ w'r$c :|jryd|_|jj|jj|jj |jj t jtdddyrrrCs r%rz!SuperEchoTransport.loseConnection0rr$Nrr#r$r%rr$s ( Sr$r)checkers)channel connectionfactorykeysruserauthc,eZdZejfZdZy)ConchTestPasswordCheckerc|jdk(r.|jdk(rtj|jStjt dS)NtestusertestpasszBad credentials)usernamepasswordrsucceedfail Exception)r, credentialss r%requestAvatarIdz(ConchTestPasswordChecker.requestAvatarIdHsH$$ 3((K7}}[%9%9::::i(9:; ;r$N)r r!r"rIUsernamePasswordcredentialInterfacesrr#r$r%rrEs ( : :< z7ConchTestServerFactory.buildProtocol..as!$446$sr) ConchTestServerlistr from_iterable privateKeysrcsupportedPublicKeysrhasattrrrk)r,addrrks r% buildProtocolz$ConchTestServerFactory.buildProtocol^so#%E(,##$#//668$)E % !EMt56/3/J/J,DJLr$ctjjttjjtdSN)ssh-rsassh-dssrKey fromStringr r rCs r% getPublicKeysz$ConchTestServerFactory.getPublicKeysns2 HH//0AB HH//0AB r$ctjjttjjtdSrrrrrrrCs r%getPrivateKeysz%ConchTestServerFactory.getPrivateKeysts2 HH//0BC HH//0BC r$returnc2dtjdgiS)a% Diffie-Hellman primes that can be used for the diffie-hellman-group-exchange-sha1 key exchange. @return: The primes and generators. @rtype: L{dict} mapping the key size to a C{list} of C{(generator, prime)} tupple. isdiffie-hellman-group14-sha1)rgetDHGeneratorAndPrimerCs r% getPrimesz ConchTestServerFactory.getPrimeszs4667UVWX Xr$cDtjj|||Sr*)r SSHFactory getService)r,transnames r%rz!ConchTestServerFactory.getServices%%00udC Cr$N)r r!r"noisyrSSHUserAuthServerr SSHConnectionservicesrrrrintrrrrr#r$r%rrVs\&77)77        YtCeCHo)>$>? Y Dr$rc"eZdZdZdZdZdZy) ConchTestBasercz|jryt|dstjd|d|d|_y)Nrzunexpectedly lost connection  rF)donerrFailTestr,reasons r%connectionLostzConchTestBase.connectionLostsCyy4!9:''3D6F8DDIr$c d|_|tjk7r'tjt d|d|d||j y)NrFzgot disconnect for z : reason z, desc: )rrDISCONNECT_BY_APPLICATIONrrWrr)r, reasonCodedescs r% receiveErrorzConchTestBase.receiveErrorsH*+D ' Y@@@T3    !r$c2tjd|)Nzgot unimplemented: seqid )rr )r,seqIDs r%receiveUnimplementedz"ConchTestBase.receiveUnimplementeds##&?w$GH Hr$N)r r!r"r rrrr#r$r%rrs  "  Ir$rceZdZdZy)rcptj||tjj||yr*)rrrSSHServerTransportr s r%rzConchTestServer.connectionLost(  ( (v 6  ( ( 7 7f Er$N)r r!r"rr#r$r%rrs Fr$rc(eZdZdZdZdZdZdZy)ConchTestClientz @ivar _channelFactory: A callable which accepts an SSH connection and returns a channel which will be attached to a new channel on that connection. c||_yr*)_channelFactoryr,channelFactorys r%r-zConchTestClient.__init__s #1D r$cptj||tjj||yr*)rrrSSHClientTransportr s r%rzConchTestClient.connectionLostrr$c|tjjtj k(}|dk(}|r|rt j dSt jtdS)Ns/85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:darFzKey or fingerprint mismatch) rrrr blobrrrr)r,rfpkeyMatchfingerprintMatchs r% verifyHostKeyzConchTestClient.verifyHostKeys[dhh112CDIIKKH!%WW ,}}Q''::i(EFG Gr$c`|jtdt|jy)Nr)requestServiceConchTestClientAuthConchTestClientConnectionrrCs r%connectionSecurez ConchTestClient.connectionSecures)   #!:4;O;O!P r$N)r r!r"r5r-rr)r.r#r$r%rrs  2 F H r$rc0eZdZdZdZdZdZdZdZdZ y)r,rc|js!|jrtjdtj j ||y)Nz2got USERAUTH_SUCCESS before password and publickey)canSucceedPasswordcanSucceedPublicKeyrr rSSHUserAuthClientssh_USERAUTH_SUCCESS)r,packets r%r4z(ConchTestClientAuth.ssh_USERAUTH_SUCCESSsA**t/G/G''H  & & ; ;D& Ir$c:d|_tjdS)NrFr)r1rrrCs r% getPasswordzConchTestClientAuth.getPasswords&'D #==- -r$c|d|_tjtjj t Sr)r2rrrrrrrCs r% getPrivateKeyz!ConchTestClientAuth.getPrivateKeys)'(D $==!4!45G!HI Ir$cHtjjtSr*)rrrr rCs r% getPublicKeyz ConchTestClientAuth.getPublicKeys88&&'89 9r$N) r r!r" hasTriedNoner2r1r4r7r9r;r#r$r%r,r,s)  J . J :r$r,c(eZdZdZdZdZdZdZdZy)r-z @ivar _completed: A L{Deferred} which will be fired when the number of results collected reaches C{totalResults}. rrcPtjj|||_yr*)rrr-rr s r%r-z"ConchTestClientConnection.__init__s  $ $ - -d 3#1D r$cF|j|j|y)N)rT) openChannelrrCs r%serviceStartedz(ConchTestClientConnection.serviceStarteds   T11t1< =r$N) r r!r"r5rresults totalResultsr-rBr#r$r%r-r-s" !  2 >r$r-c<eZdZdZdZdZdZdZdZdZ dZ y ) SSHTestChannelc||_||_g|_g|_t j |_tjj|g|i|yr*) r_openedreceived receivedExtrrnror SSHChannelr-)r,ropenedrkwargss r%r-zSSHTestChannel.__init__sKDI!DLDM!D  >>+DL    ' ' >t >v >r$c:|jj|yr*)rHerrbackr s r% openFailedzSSHTestChannel.openFaileds LL  (r$c:|jj|yr*)rHr)r,ignores r% channelOpenzSSHTestChannel.channelOpen LL ! !$ 'r$c:|jj|yr*)rIappendrHs r% dataReceivedzSSHTestChannel.dataReceiveds MM  &r$c|tjk(r|jj|yt j d|y)NzUnrecognized extended data: )rEXTENDED_DATA_STDERRrJrVrrd)r,dataTyperIs r% extReceivedzSSHTestChannel.extReceiveds8::::  ''-6xlCDr$c>tjd|\|_y)Nz>L)structunpackstatus)r,r_s r%request_exit_statusz"SSHTestChannel.request_exit_status s"MM$7MT[r$cd|_y)NT) eofCalledrCs r%rzSSHTestChannel.eofReceiveds !DNr$c:|jjdyr*)rorrCs r%rzSSHTestChannel.closedrTr$N) r r!r"r-rPrSrWr[r`rrr#r$r%rFrFs+ ? ) ( ' E  8 " (r$rFctjdtjj t gi}tj |S)z Produces a SSHPublicKeyChecker with an in-memory key mapping with a single use: 'testuser' @return: L{twisted.conch.checkers.SSHPublicKeyChecker} r)rInMemorySSHKeyDBrrrr SSHPublicKeyChecker)conchTestPublicKeyDBs r%conchTestPublicKeyCheckerrhsD (88 488../@AB C ++,@AAr$cPeZdZdZesdZd dZdZdZdZ dZ dZ d Z d Z d Zy )SSHProtocolTestsz^ Tests for communication between L{SSHServerTransport} and L{SSHClientTransport}. can't run without cryptographyc tjtd|_t j |j}t }|jt|jt|j|t}||_|j|jd|_ t|j|_t!fd|_t|j"|_|jj'|j$|j"j'|jS)z Create a connected SSH client and server protocol pair and return a L{Deferred} which fires with an L{SSHTestChannel} instance connected to a channel on that SSH connection. rNc"tfd|iS)NrT)rF)rTrMrresults r%z:SSHProtocolTests._ourServerOurClientTest..>sfJ4J6Jr$)rrnr(realmr PortalrregisterCheckerrrhr startFactoryrserverr clientTransportrclientserverTransportr)r,rrMrsshpcfacrns `` @r%_ourServerOurClientTestz(SSHProtocolTests._ourServerOurClientTest+s !#K0 MM$** %#% 689 79: % $&  ''- ,T[[9% J   -T[[9 ""4#7#78 ""4#7#78 r$cj}fd}|j|fd}|j|fd}|j|fd}|j||S)z Run the Conch server against the Conch client. Set up several different channels which exercise different behaviors and wait for them to complete. Verify that the channels with errors log them. c |_j|jj|dt j ddt S)N subsystems not-crazyrFr assertFailurerT sendRequestrNSrrr,s r% cbSubsystemzFSSHProtocolTests.test_subsystemsAndGlobalRequests..cbSubsystemOsF"DL%% ((\699\+BA  r$c~j}|jj|dtjddS)Nr}r:rFrrTrrrignoredrr,s r%cbNotCrazyFailedzKSSHProtocolTests.test_subsystemsAndGlobalRequests..cbNotCrazyFailedZs5llG<<++vyy':A r$cZj}|jjddd}|jjddd}|jjdj |jjdddt }tj|||gS)NfoobarrFsfoo-2bar2rM) rrTsendGlobalRequest addCallback assertEqualrrr gatherResults)rrd1d2d3r,s r%cbGlobalRequestszKSSHProtocolTests.test_subsystemsAndGlobalRequests..cbGlobalRequestsbsllG//BB//'1EB NN4++W 5## ..vvqA9B&&B|4 4r$cjjjjdddj}d|j j _|j j|jy)Nrr)rErLT) rrprr<rrTrrserviceStoppedrrs r% disconnectzESSHProtocolTests.test_subsystemsAndGlobalRequests..disconnectqsf    !!00&72S llG<@GLL " " 9 LL ' ' ) "G " " $r$rzr)r,rrrrrs` r% test_subsystemsAndGlobalRequestsz1SSHProtocolTests.test_subsystemsAndGlobalRequestsGsv ..0  K(  ,- 5 ,- % J'r$cj}tjdddfd}|j|fd}|j|fd}|j|fd}|j||S)z L{SSHChannel.sendRequest} can open a shell with a I{pty-req} request, specifying a terminal type and window size. conch-test-termPrrr$cN|_|jj|ddS)Nspty-reqrF)rrTr)rrIr,s r% cbChannelz.SSHProtocolTests.test_shell..cbChannels%"DL<<++GZqI Ir$cjjjjdj}j |jjjj |jdj |jdj|jj}|jj|dddS)Nrrrrxr$rF) rprrTchannelsrassertIsrrqrr assertTruerlrr)rrrr,s r%cbPtyz*SSHProtocolTests.test_shell..cbPtysjj'',,55a8@@G MM'..$***;*; <   W224F G   W00. A OOGNN +llG<<++GXsAF Fr$c>jjdjjjjt j jj jjjj gS)Nstesting the shell!) rrrTsendEOFrrrorprrirr,s r%cbShellz,SSHProtocolTests.test_shell..cbShellsm LL  8 9 LL   % %dll 3&&%%tzz'8'8'E'E'M'MN r$cjjdk7r-tjdjjfzj dj jj djjjjjjjjy)Nrzshell exit status was not 0: %ir$stesting the shell! ) rr_rrdrjoinrIrrbrprrirmrs r%cbExitedz-SSHProtocolTests.test_shell..cbExiteds||""a'9T\\=P=P> ?r$)rzrpackRequest_pty_reqr)r,rrrrrrIs` @r% test_shellzSSHProtocolTests.test_shell~s ..0**+=~sS J I& G E"  G$ @ H%r$cj}fd}|j|fd}|j||S)z If L{SSHChannel.sendRequest} issues an exec which the server responds to with an error, the L{Deferred} it returns fires its errback. c |_j|jj|dt j ddt S)Nexecs jumboliahrFr~rs r%rz3SSHProtocolTests.test_failedExec..cbChannelsB"DL%% (('699\;RTUV r$cjtj}j|djj dy)Nr)rN)flushLoggedErrorsrrrvaluerrerrorsr,s r%cbFailedz2SSHProtocolTests.test_failedExec..cbFaileds:++E,<,<=F   VAY__113E Fr$r)r,rrrs` r%test_failedExecz SSHProtocolTests.test_failedExecsG ..0  I& G H%r$cj}fd}|j|fd}|j|fd}|j||S)z When the process started by a L{SSHChannel.sendRequest} exec request exits, the exit status is reported to the channel. ct|_|jj|dtjddS)Nrr|rFrrs r%rz5SSHProtocolTests.test_falseChannel..cbChannels/"DL<<++GWfii>QSTU Ur$c0jjSr*rrors r%cbExecz2SSHProtocolTests.test_falseChannel..cbExec<<'' 'r$cjjjgjjjdyr)rrrIassertNotEqualr_rs r%cbClosedz4SSHProtocolTests.test_falseChannel..cbCloseds7   T\\22B 7    3 3Q 7r$rr,rrrrs` r%test_falseChannelz"SSHProtocolTests.test_falseChannels^ ..0 V I& ( F# 8 H%r$cjdd}fd}|j|fd}|j|fd}|j||S)z Bytes sent over the extended channel for stderr data are delivered to the channel's C{extReceived} method. r} localWindowlocalMaxPacketct|_|jj|dtjddS)Nrs eecho hellorFrrs r%rz5SSHProtocolTests.test_errorChannel..cbChannel3"DL<<++&))N";Q r$ctjjjjj j jgSr*rrrrorprrirs r%rz2SSHProtocolTests.test_errorChannel..cbExec>&&%%tzz'8'8'E'E'M'MN r$c:jjjgjdjjjdjjj dj jjjjjdjjjjjjjy)Nr$hello rr) rrrIrrJr_rrblocalWindowLeftrprrirrs r%rz4SSHProtocolTests.test_errorChannel..cbCloseds   T\\22B 7   SXXdll&>&>? N   T\\00! 4 OODLL22 3   T\\991 =    ,, !!..FF r$rrs` r%test_errorChannelz"SSHProtocolTests.test_errorChannelsd ..1Q.O  I&  F#  H%r$c~jjdt}fd}|j||S)z When an attempt is made to open an unknown channel type, the L{Deferred} returned by L{SSHChannel.sendRequest} fires its errback. scrazy-unknown-channelcjtj}j|djj djt |dy)Nr)zunknown channelrF)rrrrrrrrs r%rz6SSHProtocolTests.test_unknownChannel..cbFailedsL++E,<,<=F   VAY__113I J   S[! ,r$)rrzrr)r,drs` r%test_unknownChannelz$SSHProtocolTests.test_unknownChannels>     ( ()A BI  - hr$cjdd}fd}|j|fd}|j|fd}|j||S)zc An L{SSHChannel} can be configured with a maximum packet size to receive. rFrct|_|jj|dtjddS)Nrs secho hellorFrrs r%rz2SSHProtocolTests.test_maxPacket..cbChannelrr$c0jjSr*rrs r%rz/SSHProtocolTests.test_maxPacket..cbExec'rr$cjjjdjdjjjdjdjjj djjj djjjy)Nrr$rr) rrr_rrIrJrrrbrs r%rz1SSHProtocolTests.test_maxPacket..cbClosed,s   T\\00! 4   SXXdll&;&;&>? N   T\\992 > OODLL22 3r$rrs` r%test_maxPacketzSSHProtocolTests.test_maxPacketsd..2a.P  I& ( F# 4 H%r$cjdd}fd}|j|fd}|j|fd}|j||S)ze Normal standard out bytes are sent to the channel's C{dataReceived} method. rr}rct|_|jj|dtjddS)Nrs echo hellorFrrs r%rz-SSHProtocolTests.test_echo..cbChannel=s3"DL<<++&))M":A r$ctjjjjj j jgSr*rrs r%cbEchoz*SSHProtocolTests.test_echo..cbEchoErr$cjjjdjdjjjdjjj dj jjjjj jjjjy)Nrr$rr) rrr_rrIrrrbrprrirrs r%rz,SSHProtocolTests.test_echo..cbClosedLs   T\\00! 4   SXXdll&;&;.`svr$cLdtjjtiSNr)rrrr r#r$r%roz0SSHFactoryTests.makeSSHFactory..as ++,=>, r$cLdtjjtiSr)rrrrr#r$r%roz0SSHFactoryTests.makeSSHFactory..ds ++,>?- r$)rrrrrrs)r,r sshFactorys ` r%makeSSHFactoryzSSHFactoryTests.makeSSHFactory^sA'') - $  % ! !r$c|j}|jd}|j|tjy)zc By default, buildProtocol() constructs an instance of SSHServerTransport. N)rrassertIsInstancerr)r,rrs r%test_buildProtocolz"SSHFactoryTests.test_buildProtocoljs: %%'(7((. h (D(DEr$cgfd}|j}||_|jd|jdgy)zc buildProtocol() calls 'self.protocol()' to construct a protocol instance. cNj|tjSr*)rVrr)rcallss r% makeProtocolzHSSHFactoryTests.test_buildProtocolRespectsProtocol..makeProtocolzs LL //1 1r$Nr#)rrrr)r,rrrs @r%"test_buildProtocolRespectsProtocolz2SSHFactoryTests.test_buildProtocolRespectsProtocolssI  2%%''d# "u%r$ctj}d|_d|_|j |j d}|j gd|jy)zq buildProtocol() sets supportedPublicKeys to the list of supported signature algorithms. ctjjttjjtdSrrr#r$r%rozGSSHFactoryTests.test_buildProtocolSignatureAlgorithms..s/++,=>++,=># r$ctjjttjjtdSrrr#r$r%rozGSSHFactoryTests.test_buildProtocolSignatureAlgorithms..s/++,>?++,>?$ r$N)s rsa-sha2-512s rsa-sha2-256rr)rrrrrsrrr)r,rrs r%%test_buildProtocolSignatureAlgorithmsz5SSHFactoryTests.test_buildProtocolSignatureAlgorithmssY        OOD !  F ! ! r$c|jd}|jd}|jd|j|jd|jy)zg Group key exchanges are not supported when we don't have the primes database. Nr"diffie-hellman-group-exchange-sha1$diffie-hellman-group-exchange-sha256)rr assertNotInsupportedKeyExchanges)r,f1p1s r%test_buildProtocolNoPrimesz*SSHFactoryTests.test_buildProtocolNoPrimess[   -   d #  123K3K   3R5M5M r$c|jddi}|jd}|jd|j|jd|jy)zU Group key exchanges are supported when we have the primes database. rF)rrrNrr)rrassertInrr,f2p2s r%test_buildProtocolWithPrimesz,SSHFactoryTests.test_buildProtocolWithPrimessU F 4   d # ;R=U=UV =r?W?WXr$c|j}|jd}|jddj|jy)z_ ECDSA key exchanges are listed with 256 having a higher priority among ECDSA. Ns8ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,)rrrrrrs r%test_buildProtocolKexECDSAz*SSHFactoryTests.test_buildProtocolKexECDSAsE "   d # G IIb.. / r$r*) r r!r"rrerrrrrrr r#r$r%rrZs/ / F&  * Y  r$rc^eZdZdZesdZereejZdZ dZ dZ dZ dZ y) MPTestszs Tests for L{common.getMP}. @cvar getMP: a method providing a MP parser. @type getMP: C{callable} rkcF|j|jddy)z L{common.getMP} should parse the a multiple precision integer from a string: a 4-byte length followed by length bytes of the integer. s)rFr$NrgetMPrCs r% test_getMPzMPTests.test_getMPs $GH(Sr$cF|j|jddy)zv L{common.getMP} should be able to parse a big enough integer (that doesn't fit on one byte). s)ir$NrrCs r%test_getMPBigIntegerzMPTests.test_getMPBigIntegers!  JJ: ;_ r$cH|j|jdddy)zg L{common.getMP} has the ability to parse multiple integer in the same string. sr)rFrr$NrrCs r%test_multipleGetMPzMPTests.test_multipleGetMPs)  JJW    r$cF|j|jddy)zu When more data than needed is sent to L{common.getMP}, it should return the remaining data. s foo)rFrNrrCs r%test_getMPRemainingDatazMPTests.test_getMPRemainingDatas!  JJ= >  r$cZ|jtj|jdy)z When the string passed to L{common.getMP} doesn't even make 5 bytes, it should raise a L{struct.error}. sN) assertRaisesr]rrrCs r%test_notEnoughDatazMPTests.test_notEnoughDatas &,, K@r$N)r r!r"r5rre staticmethodrrrrrrrr#r$r%r r s= /V\\*T    Ar$r ceZdZdZesdZdZy)GMPYInstallDeprecationTestszI Tests for the deprecation of former GMPY accidental public API. r7ctj|j|jg}|j t |d|j |dddy)zD L{twisted.conch.ssh.common.install} is deprecated. rFrmessagezAtwisted.conch.ssh.common.install was deprecated in Twisted 16.5.0N)rinstall flushWarningstest_deprecatedrr)r,warningss r%r!z+GMPYInstallDeprecationTests.test_deprecatedsX %%t';';&<= X*  QK " O r$N)r r!r"r5rrer!r#r$r%rrs 0  r$r)Sr5r] itertoolsrtypingrrrtwisted.conch.test.keydatarrr r twisted.conch.test.loopbackr twisted.credr twisted.cred.errorr twisted.internetrrrtwisted.internet.errorrtwisted.pythonrrtwisted.python.reflectr twisted.trialrr twisted.conchrrtwisted.conch.sshrrrrr(r&r/rgrregisterAdapterISessionProtocolrBrryrrrrrrrrrrSSHProtocolCheckerrrrrrrr#rr3r,rr-rKrFrhTestCaserjrr rr#r$r%r5s $$ 60554'0"^, +CC   >?%f&&?%D=$=$@&J!?G4D4D  X&& UU<SS.SS(SS,& < <h99 4D!3!34DlII>F-)E)EF -)E)E8:h88:.>J$<$<>"(++(B Bux((up f h''f R9Ah9Ax ("3"3 r$