grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a q©jL!ã@s¼ddlZddlZddlZddlZddlmZmZmZmZddl m Z ddl m Z m Z mZmZddlmZmZddlmZmZe e¡ZGdd „d e jƒZGd d „d eƒZGd d „d eƒZdS)éN)ÚDictÚListÚOptionalÚTuple)Úfernyé)Ú JsonObjectÚ JsonValueÚget_strÚget_str_or_none)ÚPeerÚ PeerError)ÚRouterÚ RoutingRulec@s”eZdZUe d¡Zeeed<e e eeeeefed<eeed<e ed<eedœdd„Z eeeeee d œd d „Zeeeeed œd d„ZdS)ÚPasswordResponderz!Enter passphrase for key '(.*)': ÚpasswordÚ hostkeys_seenÚ error_messageÚpassword_attempts©rcCs||_g|_d|_d|_dS)Nr)rrrr)Úselfr©rú2/usr/lib/python3.9/site-packages/cockpit/remote.pyÚ__init__szPasswordResponder.__init__)ÚreasonÚhostÚ algorithmÚkeyÚ fingerprintÚreturncÃs|j |||||f¡dS)NF)rÚappend)rrrrrrrrrÚ do_hostkey%szPasswordResponder.do_hostkey)ÚmessagesÚpromptÚhintrcÃs\t d||¡tj |¡}|durH| d¡}t d|¡d|›�|_dS|jd7_|jS)NzGot askpass(%s): %srzCThis is a passphrase request for %s, but we don't do those. Abort.zlocked identity: ) ÚloggerÚdebugrÚ PASSPHRASE_REÚ fullmatchÚgrouprrr)rr"r#r$ÚmatchÚpathrrrÚ do_askpass)s    zPasswordResponder.do_askpassN)Ú__name__Ú __module__Ú __qualname__ÚreÚcompiler'rÚstrÚ__annotations__rrÚintrÚboolr!r,rrrrrs    rcs°eZdZUdZeejed<eed<eeed<eeed<e ed<ddœdd „Z d d e dd œ‡fd d „ Z e ddœdd„Z ddœdd„Zeeeee e ddœ‡fdd„ Z‡ZS)ÚSshPeerNÚsessionrÚuserrÚprivate©rc Ãs¬t d|j|j|j¡|j d¡\}}}|rB| ¡rB|}t|ƒ}n |j}d}t|j ƒ}ddi}|j durv|j dd�n|j ddd�z(|j j ||j||j||d �IdHW�nÚt tjfyú}z0t d ||¡td d t|ƒd �|‚WYd}~�n–d}~0tj�y²}zž|j�rD|jd \} }} } } |›d| ›d| ›�| dœ} ni} t|tjƒ�r\d}n|j�rjd}nd}t dt|ƒ||j|j|| ¡t|| |id�|‚WYd}~nÞd}~0tj�y@}ztt d||¡t |jd¡}d|v�r|j du�r|jd k�r d|d<nd|d<td|j�p"d|d�|‚WYd}~nPd}~0tj�y†}z,t d||¡tdt|ƒd�|‚WYd}~n d}~00|j  dg¡}|  |g¡IdHdS)Nz1Starting ssh session user=%s, host=%s, private=%sú:ZStrictHostKeyCheckingZyesÚ1)ZNumberOfPasswordPromptsÚno)ZPasswordAuthenticationZKbdInteractiveAuthentication)Z login_nameÚportZhandle_host_keyÚoptionsZinteraction_responderz connecting to host %s failed: %szno-host)ÚerrorÚmessagerú )zhost-keyzhost-fingerprintzinvalid-hostkeyzunknown-hostkeyz unknown-hostzPSshPeer got a %s %s; private %s, seen hostkeys %r; raising %s with extra args %r)r@Zauth_method_resultsz$authentication to host %s failed: %sz not-providedrz not-triedZdeniedzauthentication-failedz)unknown failure connecting to host %s: %szinternal-error)rAzcockpit-bridge)!r%r&r8rr9Ú rpartitionÚisdigitr4rrÚupdater7ZconnectÚOSErrorÚsocketZgaierrorr r2rZSshHostKeyErrorrÚ isinstanceZSshChangedHostKeyErrorÚtypeZSshAuthenticationErrorÚdictÚfromkeysÚmethodsrrZSshErrorZwrap_subprocess_argsZspawn)rÚbasenameÚcolonZportstrrr>Z responderr?ÚexcZ_reasonrrrZ error_argsr@ÚresultsÚargsrrrÚdo_connect_transportCsh    þ*ÿ&   þþ(zSshPeer.do_connect_transportz str | None)rr)rArcs0||jkr| ¡n|dur,tƒ |||¡dS©N)rÚcloseÚsuperÚdo_kill)rrr)rA©Ú __class__rrrVŠs  zSshPeer.do_kill)rArcCs:t|dƒ d¡r6t|dƒ}|jd||jp*dd�d|_dS)NZ challengezplain1:ÚcookieZ authorizeÚ)ZcommandrYZresponse)r Ú startswithZ write_controlr)rrArYrrrÚ do_authorize�s zSshPeer.do_authorizecCs d|_dSrSr)rrrrÚdo_superuser_init_done–szSshPeer.do_superuser_init_done)Úrouterrr8r?r9rcsjtƒ |¡||_||_t|ddƒ|_||_t ¡|_ t |ddƒ}|dvrPd}nd|i}|j ||d�dS)Nrzinit-superuser)NZnoneFÚid)Ú init_hostÚ superuser) rUrrr8r rr9rÚSessionr7r Zstart_in_background)rr^rr8r?r9Zinit_superuserrarWrrr™s   zSshPeer.__init__)r-r.r/r7rrrbr3r2r5rRrrVr\r]rrÚ __classcell__rrrWrr6<s   Gr6csbeZdZUeeeeeeefefed<‡fdd„Z e eedœdd„Z ddœd d „Z ‡Z S) ÚHostRoutingRuleÚremotescstƒ |¡i|_dSrS)rUrre)rr^rWrrr¯s zHostRoutingRule.__init__)r?rcsôt|dˆjjƒ}|ˆjjkr dSt|ddƒ}|t ¡krÖóz,HostRoutingRule.apply_rule..) r r^r`ÚgetpassZgetuserrCr%r&rer6Zadd_done_callback)rr?rr8Zuser_from_hostÚ_ZnonceÚpeerrrhrÚ apply_rule³s*         zHostRoutingRule.apply_ruleNr:cCs t|j ¡ƒD] }| ¡qdSrS)ÚsetreÚvaluesrT)rrmrrrÚshutdownÛszHostRoutingRule.shutdown)r-r.r/rrr2rr r3rrrnrqrcrrrWrrd¬s " (rd)rkZloggingr0rGÚtypingrrrrZcockpit._vendorrZjsonutilrr r r rmr r r^rrZ getLoggerr-r%ZAskpassHandlerrr6rdrrrrÚs  'p