
    ho                       S r SSKJr  SSKrSSKJrJrJr  SSKJ	r	J
r
  SSKJrJrJr  SSK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Jr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$  \\\
RJ                     \
RJ                  \/ S4   4   r& " S S\RN                  5      r( " S S\RN                  5      r)Sr*Sr+Sr,Sr-Sr.Sr/0 r0\1" \2" 5       Rg                  5       5       H  u  r4r5\4SS S:X  d  M  \4\0\5'   M     \0\(l6        \0\)l6        C0C5Sr7Sr8g)z
Implementation of the ssh-userauth service.
Currently implemented authentication types are public-key and password.

Maintainer: Paul Swartz
    )annotationsN)CallableTupleType)error
interfaces)keysservice	transport)NSgetNS)Key)credentials)UnauthorizedLogin)deferreactor)Deferred)IReactorTime)Logger)failure)nativeStringc                      \ rS rSr% SrSrSrSrSr\	" \
5      rS\S'   \R                  S	\R                  S
0r\" 5       rS rS rS r        SS jrSS jrSS jrS rS rSS jrSS jrS rS rSrg)SSHUserAuthServer"   a  
A service implementing the server side of the 'ssh-userauth' service.  It
is used to authenticate the user on the other side as being able to access
this server.

@ivar name: the name of this service: 'ssh-userauth'
@type name: L{bytes}
@ivar authenticatedWith: a list of authentication methods that have
    already been used.
@type authenticatedWith: L{list}
@ivar loginTimeout: the number of seconds we wait before disconnecting
    the user for taking too long to authenticate
@type loginTimeout: L{int}
@ivar attemptsBeforeDisconnect: the number of failed login attempts we
    allow before disconnecting.
@type attemptsBeforeDisconnect: L{int}
@ivar loginAttempts: the number of login attempts that have been made
@type loginAttempts: L{int}
@ivar passwordDelay: the number of seconds to delay when the user gives
    an incorrect password
@type passwordDelay: L{int}
@ivar interfaceToMethod: a L{dict} mapping credential interfaces to
    authentication methods.  The server checks to see which of the
    cred interfaces have checkers and tells the client that those methods
    are valid for authentication.
@type interfaceToMethod: L{dict}
@ivar supportedAuthentications: A list of the supported authentication
    methods.
@type supportedAuthentications: L{list} of L{bytes}
@ivar user: the last username the client tried to authenticate with
@type user: L{bytes}
@ivar method: the current authentication method
@type method: L{bytes}
@ivar nextService: the service the user wants started after authentication
    has been completed.
@type nextService: L{bytes}
@ivar portal: the L{twisted.cred.portal.Portal} we are using for
    authentication
@type portal: L{twisted.cred.portal.Portal}
@ivar clock: an object with a callLater method.  Stubbed out for testing.
   ssh-userauthi        r   clock	   publickey   passwordc                H   / U l         SU l        SU l        SU l        U R                  R
                  R                  U l        / U l        U R                  R                  5        H<  nXR                  ;   d  M  U R                  R                  U R                  U   5        M>     U R                  R                  S5      (       d+  SU R                  ;   a  U R                  R                  S5        U R                  R                  U R                  U R                   5      U l        g)z
Called when the userauth service is started.  Set up instance
variables, check if we should allow password authentication (only
allow if the outgoing connection is encrypted) and set up a login
timeout.
r   Ninr    )authenticatedWithloginAttemptsusernextServicer   factoryportalsupportedAuthenticationslistCredentialsInterfacesinterfaceToMethodappendisEncryptedremover   	callLaterloginTimeouttimeoutAuthentication_cancelLoginTimeout)selfis     a/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/ssh/userauth.pyserviceStarted SSHUserAuthServer.serviceStartedZ   s     "$	nn,,33(*%668A***--44T5K5KA5NO 9 ~~))$//d;;;--44[A#'::#7#7t99$
     c                j    U R                   (       a"  U R                   R                  5         SU l         gg)z]
Called when the userauth service is stopped.  Cancel the login timeout
if it's still going.
N)r2   cancelr3   s    r5   serviceStopped SSHUserAuthServer.serviceStoppedt   s,    
 ##$$++-'+D$ $r8   c                f    SU l         U R                  R                  [        R                  S5        g)z}
Called when the user has timed out on authentication.  Disconnect
with a DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE message.
Ns   you took too long)r2   r   sendDisconnect)DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLEr;   s    r5   r1   'SSHUserAuthServer.timeoutAuthentication}   s*    
 $( %%??AU	
r8   c                   U R                   R                  SX!S9  XR                  ;  a*  [        R                  " [
        R                  " S5      5      $ UR                  SS5      R                  S5      n[        U SU 3S5      nUb:  U" U5      nUc-  [        R                  " [
        R                  " U S	35      5      $ U$ [        R                  " [
        R                  " S
U 35      5      $ )a\  
Try to authenticate the user with the given method.  Dispatches to a
auth_* method.

@param kind: the authentication method to try.

@param user: the username the client is authenticating with.

@param data: authentication specific data sent by the client.

@return: A Deferred called back if the method succeeded, or erred back
    if it failed.
z{user!r} trying auth {kind!r})r%   kindz#unsupported authentication, failing   -   _asciiauth_Nz" return None instead of a Deferredzbad auth type: )
_logdebugr)   r   failr   
ConchErrorreplacedecodegetattr)r3   rC   r%   datastrkindfrets          r5   tryAuthSSHUserAuthServer.tryAuth   s      			7dN444::e../TUVV,,tT*11':JQE'#TK
 =D'C{zz$$y0R%ST  
zz%**_WI+FGHHr8   c                   [        US5      u  p#pEX R                  :w  d  X0R                  :w  a  / U l        X l        X0l        X@l        U R                  XBU5      nU(       d:  U R                  [        R                  " [        R                  " S5      5      5        gUR                  U R                  5      R                  U R                  5      R                  U R                  5      $ )z
The client has requested authentication.  Payload::
    string user
    string next service
    string method
    <authentication specific data>

@type packet: L{bytes}
   zauth returned noneN)r   r%   r&   r#   methodrS   
_ebBadAuthr   Failurer   rK   addCallback_cbFinishedAuth
addErrback_ebMaybeBadAuth)r3   packetr%   r&   rW   restds          r5   ssh_USERAUTH_REQUEST&SSHUserAuthServer.ssh_USERAUTH_REQUEST   s     +0*:'699/?/? ?%'D"	&LLt,OOGOOE,<,<=Q,RSTMM$../Z,,-Z(	
r8   c                   Uu  p#nU R                   c   eX0R                   l        X@R                   l        U R                   R                  R	                  U R                   U R
                  5      nU(       d#  [        R                  " SU R
                   35      eU R                  R                  SU R                  U R                  S9  U R                   R                  [        S5        U R                   R                  U" 5       5        g)z
The callback when user has successfully been authenticated.  For a
description of the arguments, see L{twisted.cred.portal.Portal.login}.
We start the service requested by the user.
Nzcould not get next service: z&{user!r} authenticated with {method!r}r%   rW   r8   )r   avatarlogoutFunctionr'   
getServicer&   r   rK   rH   rI   r%   rW   
sendPacketMSG_USERAUTH_SUCCESS
setService)r3   result	interfacere   logoutr
   s         r5   r[   !SSHUserAuthServer._cbFinishedAuth   s     '-#F~~))) &(.%..((33DNNDDTDTU""%A$BRBRAS#TUU		4499T[[ 	 	
 	!!"6<!!'),r8   c                    UR                  [        R                  5        U R                  R	                  [
        [        SR                  U R                  5      5      S-   5        g)z
An intermediate errback.  If the reason is
error.NotEnoughAuthentication, we send a MSG_USERAUTH_FAILURE, but
with the partial success indicator set.

@type reason: L{twisted.python.failure.Failure}
   ,   N)	trapr   NotEnoughAuthenticationr   rh   MSG_USERAUTH_FAILUREr   joinr)   r3   reasons     r5   r]   !SSHUserAuthServer._ebMaybeBadAuth   sG     	E112!! "TYYt/L/L%M"NQX"X	
r8   c                v   UR                  [        R                  5      (       a  gU R                  S:w  Ga>  U R                  R                  SU R                  U R                  S9  UR                  [        5      (       a)  U R                  R                  SUR                  5       S9  OrUR                  [        R                  5      (       a)  U R                  R                  SUR                  5       S9  O%U R                  R                  S	UU R                  S
9  U =R                  S-  sl        U R                  U R                  :  a+  U R                  R                  [        R                  S5        gU R                  R!                  ["        [%        SR'                  U R(                  5      5      S-   5        g)aC  
The final errback in the authentication chain.  If the reason is
error.IgnoreAuthentication, we simply return; the authentication
method has sent its own response.  Otherwise, send a failure message
and (if the method is not 'none') increment the number of login
attempts.

@type reason: L{twisted.python.failure.Failure}
N   nonez{user!r} failed auth {method!r}rd   zunauthorized login: {message})messagezreason: {reason})rw   z#Error checking auth for user {user})r   r%   r   s   too many bad authsrp       )checkr   IgnoreAuthenticationrW   rH   rI   r%   r   getErrorMessagerK   r   r$   attemptsBeforeDisconnectr   r?   r@   rh   rt   r   ru   r)   rv   s     r5   rX   SSHUserAuthServer._ebBadAuth   sU    <<2233;;'!IIOO1		$++   ||-..		3V=S=S=U    e..//		 26;Q;Q;ST		!!9" " 
 !#!!D$A$AA--GG) !! "TYYt/L/L%M"NQX"X	
r8   c                   [        USS 5      n[        USS S5      u  p4n [        R                  R	                  U5        U=(       a    [        U5      S   =(       d    SnU(       Ga  U R                  c   S5       eU R                  R                  c   S5       e[        U R                  R                  5      [!        ["        45      -   [        U R$                  5      -   [        U R&                  5      -   [        S	5      -   [!        U45      -   [        U5      -   [        U5      -   n[(        R*                  " U R$                  X4X5      n	U R,                  R/                  U	S[0        R2                  5      n
U
$ [(        R*                  " U R$                  X4SS5      n	U R,                  R/                  U	S[0        R2                  5      R5                  U R6                  USS 5      n
U
$ ! [        R
                   a]    SR                  UR                  S5      5      nU R                  R                  U5        [        R                  " [        U5      5      s $ f = f)
z
Public key authentication.  Payload::
    byte has signature
    string algorithm name
    string key blob
    [string signature] (if has signature is True)

Create a SSHPublicKey credential and verify it using our portal.
r   r   N   z"Unsupported key type {} or bad keyrF   zmust have transport for authzmust have session for authr   )ordr   r	   r   
fromStringBadKeyErrorformatrM   rH   r   r   rJ   r   r   	sessionIDr   bytesMSG_USERAUTH_REQUESTr%   r&   r   SSHPrivateKeyr(   loginr   
IConchUserr\   _ebCheckKey)r3   r^   hasSigalgNameblobr_   r   	signaturebcrk   s              r5   auth_publickey SSHUserAuthServer.auth_publickey	  s
    VAa[!#F12J2t	8HH% -uT{1~5	>>-M/MM->>++7U9UU74>>++,-/01TYY-  T%%&' \"	#
 	"# W+ T(  ))$))WAQA[[&&q$
0E0EFF 	 ))$))WD$OA[[&&q$
0E0EFQQ  &*F 5  	88??w@WXEIIOOE"::/677	8s   G$ $A.IIc                    U R                   c   eUR                  [        R                  5        U R                   R	                  [
        U5        [        R                  " [        R                  " 5       5      $ )z
Called back if the user did not sent a signature.  If reason is
error.ValidPublicKey then this key is valid for the user to
authenticate with.  Send MSG_USERAUTH_PK_OK.
)	r   rr   r   ValidPublicKeyrh   MSG_USERAUTH_PK_OKr   rY   r~   )r3   rw   r^   s      r5   r   SSHUserAuthServer._ebCheckKey5  sS     ~~)))E(()!!"4f=u99;<<r8   c                    [        USS 5      S   n[        R                  " U R                  U5      nU R                  R                  US[        R                  5      R                  U R                  5      $ )z|
Password authentication.  Payload::
    string password

Make a UsernamePassword credential and verify it with our portal.
r   Nr   )
r   r   UsernamePasswordr%   r(   r   r   r   r\   _ebPassword)r3   r^   passwordr   s       r5   auth_passwordSSHUserAuthServer.auth_passwordA  sd     $Q'((H={{  D**?*?@KK
 	
r8   c                    [         R                  " 5       nU R                  R                  U R                  UR
                  U5        U$ )zn
If the password is invalid, wait before sending the failure in order
to delay brute-force password guessing.
)r   r   r   r/   passwordDelaycallback)r3   rQ   r`   s      r5   r   SSHUserAuthServer._ebPasswordN  s5    
 NN

T//Q?r8   )r2   r#   r$   rW   r&   r(   r)   r%   N)rC   r   r%   r   rO   r   returnDeferred[_ConchPortalTuple])r^   r   r   z"Deferred[_ConchPortalTuple] | None)rk   _ConchPortalTupler   None)r^   r   r   r   )rw   failure.Failurer^   r   r   r   ) __name__
__module____qualname____firstlineno____doc__namer0   r   r   r   r   r   __annotations__r   ISSHPrivateKeyIUsernamePasswordr+   r   rH   r6   r<   r1   rS   ra   r[   r]   rX   r   r   r   r   __static_attributes__ r8   r5   r   r   "   s    (T DL!M&w/E</""L%%{ 8D
4,
II!&I.3I	$IB
4-&
%
N*X
=
r8   r   c                     \ rS rSr% SrSrS\S'   / SQrS\S'   S&S	 jrS'S
 jr	S(S jr
S)S j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*S jrS+S jrS,S jrS,S jrS-S jrS.S jrS/S jrS0S  jrS1S! jr S2S# jr!S$ r"S%r#g")3SSHUserAuthClientiX  a  
A service implementing the client side of 'ssh-userauth'.

This service will try all authentication methods provided by the server,
making callbacks for more information when necessary.

@ivar name: the name of this service: 'ssh-userauth'

@ivar preferredOrder: a list of authentication methods that should be used
    first, in order of preference, if supported by the server

@ivar user: the name of the user to authenticate as

@ivar instance: the service to start after authentication has finished

@ivar authenticatedWith: a list of strings of authentication methods we've
    tried

@ivar triedPublicKeys: a list of public key objects that we've tried to
    authenticate with

@ivar lastPublicKey: the last public key object we've tried to authenticate
    with
r   r   r   )r   r       keyboard-interactivezlist[bytes]preferredOrderc                    Xl         X l        g N)r%   instance)r3   r%   r   s      r5   __init__SSHUserAuthClient.__init__y  s    	 r8   c                R    / U l         / U l        S U l        U R                  SS5        g )Nrz   r8   )r#   triedPublicKeyslastPublicKey
askForAuthr;   s    r5   r6    SSHUserAuthClient.serviceStarted}  s(    .0*,)-%r8   c                    U R                   c   eXl        U R                   R                  [        [	        U R
                  5      [	        U R                  R                  5      -   [	        U5      -   U-   5        g)z
Send a C{MSG_USERAUTH_REQUEST}.

@param kind: the authentication method to try.

@param extraData: method-specific data to go in the packet
N)r   lastAuthrh   r   r   r%   r   r   )r3   rC   	extraDatas      r5   r   SSHUserAuthClient.askForAuth  s[     ~~)))!! tyyMBt}}1122RX=	I	
r8   c                    UR                  SS5      R                  S5      nU R                  R                  SUS9  [	        U SU-   S5      nUb  U" 5       $ S$ )zd
Dispatch to an authentication method.

@param kind: the authentication method
@type kind: L{bytes}
rD   rE   rF   ztrying to auth with {kind})rC   rG   N)rL   rM   rH   rI   rN   )r3   rC   rP   rQ   s       r5   rS   SSHUserAuthClient.tryAuth  sY     ,,tT*11':		44@18w?PRV1Wmqs--r8   c                (    U R                  SS5        g)z
Generic callback for a failed authentication attempt.  Respond by
asking for the list of accepted methods (the 'none' method)
rz   r8   N)r   )r3   ignoredargss      r5   _ebAuthSSHUserAuthClient._ebAuth  s    
 	%r8   c                N    U R                   R                  U R                  5        g)zm
We received a MSG_USERAUTH_SUCCESS.  The server has accepted our
authentication, so start the next service.
N)r   rj   r   )r3   r^   s     r5   ssh_USERAUTH_SUCCESS&SSHUserAuthClient.ssh_USERAUTH_SUCCESS  s    
 	!!$--0r8   c                H  ^  [        U5      u  p#[        U5      nU(       a%  T R                  R                  T R                  5        U 4S jn[        U 4S jUR                  S5       5       US9nT R                  R                  SUS9  T R                  S[        U5      5      $ )a  
We received a MSG_USERAUTH_FAILURE.  Payload::
    string methods
    byte partial success

If partial success is C{True}, then the previous method succeeded but is
not sufficient for authentication. C{methods} is a comma-separated list
of accepted authentication methods.

We sort the list of methods by their position in C{self.preferredOrder},
removing methods that have already succeeded. We then call
C{self.tryAuth} with the most preferred method.

@param packet: the C{MSG_USERAUTH_FAILURE} payload.
@type packet: L{bytes}

@return: a L{defer.Deferred} that will be callbacked with L{None} as
    soon as all authentication methods have been tried, or L{None} if no
    more authentication methods are available.
@rtype: C{defer.Deferred} or L{None}
c                   > U TR                   ;   a  TR                   R                  U 5      $ [        TR                   5      $ )z
Invoked once per authentication method in order to extract a
comparison key which is then used for sorting.

@param meth: the authentication method.
@type meth: L{bytes}

@return: the comparison key for C{meth}.
@rtype: L{int}
)r   indexlen)methr3   s    r5   orderByPreferenceASSHUserAuthClient.ssh_USERAUTH_FAILURE.<locals>.orderByPreference  s=     t*****0066 4..//r8   c              3  L   >#    U  H  nUTR                   ;  d  M  Uv   M     g 7fr   )r#   ).0r   r3   s     r5   	<genexpr>9SSHUserAuthClient.ssh_USERAUTH_FAILURE.<locals>.<genexpr>  s(      3Dt555 3s   $	$rp   )keyzcan continue with: {methods})methodsN)r   r   r#   r,   r   sortedsplitrH   rI   _cbUserauthFailureiter)r3   r^   canContinuepartialr   s   `    r5   ssh_USERAUTH_FAILURE&SSHUserAuthClient.ssh_USERAUTH_FAILURE  s    ,  %V}g,""))$--8	0" '--d3
 "
 			6L&&tT+->??r8   c                   U(       a  g  [        U5      n[        R                  " U R                  U5      nUR	                  U R
                  U5        U$ ! [         a-    U R                  R                  [        R                  S5         g f = f)Ns(   no more authentication methods available)
nextr   maybeDeferredrS   rZ   r   StopIterationr   r?   r@   )r3   rk   iteratorrW   r`   s        r5   r   $SSHUserAuthClient._cbUserauthFailure  sv    
	(^F ##DLL&9AMM$118<H  	NN))CC;	s   A 4B
Bc           
         [        U S[        U R                  R                  SS5      5      -  S5      nUb  U" U5      $ U R	                  SS5        g)z
This message (number 60) can mean several different messages depending
on the current authentication type.  We dispatch to individual methods
in order to handle this request.
zssh_USERAUTH_PK_OK_%srD   rE   Nrz   r8   )rN   r   r   rL   r   )r3   r^   funcs      r5   ssh_USERAUTH_PK_OK$SSHUserAuthClient.ssh_USERAUTH_PK_OK  sR     #l4==3H3Ht3T&UU

 <OOGS)r8   c                0   U R                   n[        U R                  R                  5      [	        [
        45      -   [        U R                  5      -   [        U R                  R                  5      -   [        S5      -   S-   [        UR                  5       5      -   [        UR                  5       5      -   nU R                  X#5      nU(       d  U R                  SS5        gUR                  U R                  5        UR                  U R                   5        g)zn
This is MSG_USERAUTH_PK.  Our public key is valid, so we create a
signature and try to authenticate with it.
r      rz   r8   N)r   r   r   r   r   r   r%   r   r   sshTyper   signDatar   rZ   _cbSignedDatar\   r   )r3   r^   	publicKeyr   r`   s        r5   ssh_USERAUTH_PK_OK_publickey.SSHUserAuthClient.ssh_USERAUTH_PK_OK_publickey  s    
 &&	t~~''()+,-m ##$% 	
  ""$%& !"# 	
 MM)'OOGS)	d(()	T\\"r8   c                (  ^ ^ [        US5      u  mp#S=T l        T l        T R                  S5      nUR	                  T R
                  T R                  5      nUR                  UU 4S j5        UR	                  T R                  T R                  5        g)z
This is MSG_USERAUTH_PASSWD_CHANGEREQ.  The password given has expired.
We ask for an old password and a new password, then send both back to
the server.
r   Ns   Old Password: c                &   > TR                  T5      $ r   )getPassword)r   promptr3   s    r5   <lambda>?SSHUserAuthClient.ssh_USERAUTH_PK_OK_password.<locals>.<lambda>%  s    d&6&6v&>r8   )	r   _oldPass_newPassr   addCallbacks_setOldPassr   rZ   _setNewPass)r3   r^   languager_   r`   r   s   `    @r5   ssh_USERAUTH_PK_OK_password-SSHUserAuthClient.ssh_USERAUTH_PK_OK_password  st     "'vq!1(,,./NN4++T\\:	>?	t''6r8   c                   [        US5      u  p#pE[        R                  " SUSS 5      S   nUSS n/ n[        U5       H>  n[        U5      u  p[	        [        USS 5      5      n
USS nUR                  X45        M@     U R                  X#U5      nUR                  U R                  5        UR                  U R                  5        g)z
This is MSG_USERAUTH_INFO_RESPONSE.  The server has sent us the
questions it wants us to answer, so we ask the user and sent the
responses.
rV   !LN   r   r   )r   structunpackrangeboolr   r,   getGenericAnswersrZ   _cbGenericAnswersr\   r   )r3   r^   r   instructionlangrO   
numPromptspromptsr4   r   echor`   s               r5   'ssh_USERAUTH_PK_OK_keyboard_interactive9SSHUserAuthClient.ssh_USERAUTH_PK_OK_keyboard_interactive(  s     ).fa(8%4]]4bq215
ABxz"A ;LFD1I'D8DNNF>*	 #
 ""4g>	d,,-	T\\"r8   c                    U R                   nU R                  SS[        UR                  5       5      -   [        UR	                  5       5      -   [        U5      -   5        g)z
Called back out of self.signData with the signed data.  Send the
authentication request with the signature.

@param signedData: the data signed by the user's private key.
@type signedData: L{bytes}
r   r   N)r   r   r   r   r   )r3   
signedDatar   s      r5   r   SSHUserAuthClient._cbSignedData;  sN     &&	b**,--9>>3C0DDr*~U	
r8   c                    Xl         g)z
Called back when we are choosing a new password.  Simply store the old
password for now.

@param op: the old password as entered by the user
@type op: L{bytes}
N)r   )r3   ops     r5   r  SSHUserAuthClient._setOldPassI  s	     r8   c                ~    U R                   nSU l         U R                  SS[        U5      -   [        U5      -   5        g)z
Called back when we are choosing a new password.  Get the old password
and send the authentication message with both.

@param np: the new password as entered by the user
@type np: L{bytes}
Nr    rq   )r   r   r   )r3   npr  s      r5   r  SSHUserAuthClient._setNewPassS  s4     ]]Wr"v%52%>?r8   c                    [         R                  " S[        U5      5      nU H   nU[        UR	                  S5      5      -  nM"     U R
                  R                  [        U5        g)z
Called back when we are finished answering keyboard-interactive
questions.  Send the info back to the server in a
MSG_USERAUTH_INFO_RESPONSE.

@param responses: a list of L{bytes} responses
@type responses: L{list}
r  UTF8N)r	  packr   r   encoder   rh   MSG_USERAUTH_INFO_RESPONSE)r3   	responsesrO   rs       r5   r  #SSHUserAuthClient._cbGenericAnswers_  sO     {{4Y0ABqxx'((D !!"<dCr8   c                t    [         R                  " U R                  5      R                  U R                  5      $ )z
Try to authenticate with a public key.  Ask the user for a public key;
if the user has one, send the request to the server and return True.
Otherwise, return False.
)r   r   getPublicKeyaddBoth_cbGetPublicKeyr;   s    r5   r    SSHUserAuthClient.auth_publickeym  s,     ""4#4#45==d>R>RSSr8   c                l   [        U[        R                  5      (       d  S nUb  Xl        U R                  R                  U5        U R                  R                  SUR                  5       S9  U R                  SS[        UR                  5       5      -   [        UR                  5       5      -   5        gg)Nzusing key of type {keyType})keyTyper   r|   TF)
isinstancer	   r   r   r   r,   rH   rI   typer   r   r   r   )r3   r   s     r5   r*  !SSHUserAuthClient._cbGetPublicKeyu  s    )TXX..I !*  ''	2IIOO99>>CSOTOOg9+<+<+>(??"Y^^EUBVV r8   c                    U R                  5       nU(       a'  UR                  U R                  U R                  5        gg)z
Try to authenticate with a password.  Ask the user for a password.
If the user will return a password, return True.  Otherwise, return
False.
TF)r   r   _cbPasswordr   )r3   r`   s     r5   r   SSHUserAuthClient.auth_password  s3     NN4++T\\:r8   c                    U R                   R                  S5        U R                  S[        S5      [        S5      -   5        g)zp
Try to authenticate with keyboard-interactive authentication.  Send
the request to the server and return True.
z!authing with keyboard-interactiver   r8   T)rH   rI   r   r   r;   s    r5   auth_keyboard_interactive+SSHUserAuthClient.auth_keyboard_interactive  s4    
 			;</C2c71BCr8   c                @    U R                  SS[        U5      -   5        g)z~
Called back when the user gives a password.  Send the request to the
server.

@param password: the password the user entered
r    r|   N)r   r   )r3   r   s     r5   r2  SSHUserAuthClient._cbPassword  s     	Wr(|%;<r8   c                j    U R                  5       nU(       d  gUR                  U R                  U5      $ )a  
Sign the given data with the given public key.

By default, this will call getPrivateKey to get the private key, then
sign the data using Key.sign().

This method is factored out so that it can be overridden to use
alternate methods, such as a key agent.

@param publicKey: The public key object returned from L{getPublicKey}

@param signData: the data to be signed by the private key.

@return: a Deferred that's called back with the signature
N)getPrivateKeyrZ   _cbSignData)r3   r   r   r   s       r5   r   SSHUserAuthClient.signData  s/        "t//::r8   c                $    UR                  U5      $ )z
Called back when the private key is returned.  Sign the data and return
the signature.

@param privateKey: the private key object

@param signData: the data to be signed by the private key.

@return: the signature
)sign)r3   
privateKeyr   s      r5   r;  SSHUserAuthClient._cbSignData  s     x((r8   c                    g)z
Return a public key for the user.  If no more public keys are
available, return L{None}.

This implementation always returns L{None}.  Override it in a
subclass to actually find and return a public key object.
Nr   r;   s    r5   r(  SSHUserAuthClient.getPublicKey  s     r8   c                >    [         R                  " [        5       5      $ )z
Return a L{Deferred} that will be called back with the private key
object corresponding to the last public key from getPublicKey().
If the private key is not available, errback on the Deferred.
r   rJ   NotImplementedErrorr;   s    r5   r:  SSHUserAuthClient.getPrivateKey  s     zz-/00r8   Nc                >    [         R                  " [        5       5      $ )z
Return a L{Deferred} that will be called back with a password.
prompt is a string to display for the password, or None for a generic
'user@hostname's password: '.

@type prompt: L{bytes}/L{None}
@rtype: L{defer.Deferred}
rD  )r3   r   s     r5   r   SSHUserAuthClient.getPassword  s     zz-/00r8   c                >    [         R                  " [        5       5      $ )ao  
Returns a L{Deferred} with the responses to the promopts.

@param name: The name of the authentication currently in progress.
@param instruction: Describes what the authentication wants.
@param prompts: A list of (prompt, echo) pairs, where prompt is a
string to display and echo is a boolean indicating whether the
user's response should be echoed as they type it.
rD  )r3   r   r  r  s       r5   r  #SSHUserAuthClient.getGenericAnswers  s     zz-/00r8   )r   r   r#   r   r   r   r   r%   )r%   r   r   zservice.SSHService)r   r   )rC   r   r   r   r   r   )rC   r   r   zNone | Deferred[bool])r   zDeferred[bool])r   zKey | failure.Failure | Noner   r  )r   r  )r   r   r   r   )r   keys.Keyr   r   r   zDeferred[bytes] | None)r?  rK  r   r   r   r   )r   z
Key | None)r   zDeferred[Key]r   )$r   r   r   r   r   r   r   r   r   r6   r   rS   r   r   r   r   r   r   r  r  r   r  r  r  r   r*  r   r5  r2  r   r;  r(  r:  r   r  r   r   r8   r5   r   r   X  s    2 "D%!#NK !&

.&16@p* #07#&

@DT$=;*)1	1
1r8   r   2   3   4   5   =   <   r  MSG_)9r   
__future__r   r	  typingr   r   r   twisted.conchr   r   twisted.conch.sshr	   r
   r   twisted.conch.ssh.commonr   r   twisted.conch.ssh.keysr   twisted.credr   twisted.cred.errorr   twisted.internetr   r   twisted.internet.deferr   twisted.internet.interfacesr   twisted.loggerr   twisted.pythonr   twisted.python.compatr   r   r   
SSHServicer   r   r   rt   ri   MSG_USERAUTH_BANNERr#  r   messageslistlocalsitemskvprotocolMessagesMSG_USERAUTH_PASSWD_CHANGEREQMSG_USERAUTH_INFO_REQUESTr   r8   r5   <module>rl     s  
 #  ( ( + 6 6 . & $ 0 + + 4 ! " .		!6!6T8JJ 
s** sl	Y1** Y1x       !"DAq!u # &.  "%-  " !#  r8   