AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/conch/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/conch/test/__pycache__/test_userauth.cpython-310.pyc
o

�b��@sUdZddlmZddlmZddlmZddlmZm	Z	ddl
mZddlm
Z
mZmZddlmZdd	lmZmZdd
lmZmZddlmZddlmZdd
lmZdZeeed<ed�r�ed�r�ddl m!Z!ddl"mZm#Z#m$Z$ddl%m&Z&ddl'm(Z(nGdd�d�Z#Gdd�d�Z$Gdd�de$j)�Z*Gdd�de$j)�Z+Gdd�de$j)�Z,Gd d!�d!e#j-�Z.ee�Gd"d#�d#��Z/ee�Gd$d%�d%��Z0ee�Gd&d'�d'��Z1ee�Gd(d)�d)��Z2Gd*d+�d+ej3�Z4Gd,d-�d-ej3�Z5Gd.d/�d/ej3�Z6Gd0d1�d1ej3�Z7dS)2zT
Tests for the implementation of the ssh-userauth service.

Maintainer: Paul Swartz
�)�
ModuleType)�Optional)�implementer)�
ConchError�ValidPublicKey)�ICredentialsChecker)�
IAnonymous�ISSHPrivateKey�IUsernamePassword)�UnauthorizedLogin)�IRealm�Portal)�defer�task)�loopback)�
requireModule)�unittestN�keys�cryptography�pyasn1)�SSHProtocolChecker)r�	transport�userauth)�NS)�keydatac@�eZdZGdd�d�ZdS)rc@�eZdZdZdS)ztransport.SSHTransportBase�Q
            A stub class so that later class definitions won't die.
            N��__name__�
__module__�__qualname__�__doc__�r#r#�B/usr/lib/python3/dist-packages/twisted/conch/test/test_userauth.py�SSHTransportBase"�r%N)rr r!r%r#r#r#r$r!�rc@r)rc@r)zuserauth.SSHUserAuthClientrNrr#r#r#r$�SSHUserAuthClient(r&r(N)rr r!r(r#r#r#r$r'r'rc@s2eZdZdZdd�Zdd�Zddd�Zd	d
�ZdS)�ClientUserAuthz"
    A mock user auth client.
    cCs(|jr
tj�tj�St�tj�tj��S)z�
        If this is the first time we've been called, return a blob for
        the DSA key.  Otherwise, return a blob
        for the RSA key.
        )	�
lastPublicKeyr�Key�
fromStringr�publicRSA_opensshr�succeed�publicDSA_openssh��selfr#r#r$�getPublicKey3szClientUserAuth.getPublicKeycCst�tj�tj��S)z@
        Return the private key object for the RSA key.
        )rr.rr+r,r�privateRSA_opensshr0r#r#r$�
getPrivateKey>�zClientUserAuth.getPrivateKeyNcC�
t�d�S)z/
        Return 'foo' as the password.
        �foo�rr.)r1�promptr#r#r$�getPasswordD�
zClientUserAuth.getPasswordcCr6)z>
        Return 'foo' as the answer to two questions.
        )�foor<r8)r1�name�information�answersr#r#r$�getGenericAnswersJr;z ClientUserAuth.getGenericAnswers�N)rr r!r"r2r4r:r@r#r#r#r$r).s
r)c@� eZdZdZdd�Zdd�ZdS)�
OldClientAuthz~
    The old SSHUserAuthClient returned a cryptography key object from
    getPrivateKey() and a string from getPublicKey
    cCst�tj�tj�j�SrA)rr.rr+r,rr3�	keyObjectr0r#r#r$r4W�zOldClientAuth.getPrivateKeycCstj�tj���SrA)rr+r,rr-�blobr0r#r#r$r2ZszOldClientAuth.getPublicKeyN�rr r!r"r4r2r#r#r#r$rCQsrCc@rB)�ClientAuthWithoutPrivateKeyzP
    This client doesn't have a private key, but it does have a public key.
    cC�dSrAr#r0r#r#r$r4c�z)ClientAuthWithoutPrivateKey.getPrivateKeycCstj�tj�SrA)rr+r,rr-r0r#r#r$r2f�z(ClientAuthWithoutPrivateKey.getPublicKeyNrGr#r#r#r$rH^srHc@sLeZdZdZGdd�d�ZGdd�d�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
FakeTransporta_
    L{userauth.SSHUserAuthServer} expects an SSH transport which has a factory
    attribute which has a portal attribute. Because the portal is important for
    testing authentication, we need to be able to provide an interesting portal
    object to the L{SSHUserAuthServer}.

    In addition, we want to be able to capture any packets sent over the
    transport.

    @ivar packets: a list of 2-tuples: (messageType, data).  Each 2-tuple is
        a sent packet.
    @type packets: C{list}
    @param lostConnecion: True if loseConnection has been called on us.
    @type lostConnection: L{bool}
    c@seZdZdZdZdd�ZdS)zFakeTransport.ServicezW
        A mock service, representing the other service offered by the server.
        �nancycCrIrAr#r0r#r#r$�serviceStarted�rJz$FakeTransport.Service.serviceStartedN)rr r!r"r=rNr#r#r#r$�Service{srOc@�eZdZdZdd�ZdS)zFakeTransport.Factoryzg
        A mock factory, representing the factory that spawned this user auth
        service.
        cCs|dkrtjSdS)z2
            Return our fake service.
            �noneN)rLrO)r1r�servicer#r#r$�
getService�s�z FakeTransport.Factory.getServiceN)rr r!r"rSr#r#r#r$�Factory�srTcCs(|��|_||j_d|_||_g|_dS�NF)rT�factory�portal�lostConnectionr�packets)r1rWr#r#r$�__init__�s


zFakeTransport.__init__cCs|j�||f�dS)z8
        Record the packet sent by the service.
        N)rY�append)r1�messageType�messager#r#r$�
sendPacket�r5zFakeTransport.sendPacketcC�dS)z�
        Pretend that this transport encrypts traffic in both directions. The
        SSHUserAuthServer disables password authentication if the transport
        isn't encrypted.
        Tr#)r1�	directionr#r#r$�isEncrypted�szFakeTransport.isEncryptedcCs
d|_dS�NT)rXr0r#r#r$�loseConnection�s
zFakeTransport.loseConnectionN)
rr r!r"rOrTrZr^rarcr#r#r#r$rLjs

rLc@rP)�Realmz�
    A mock realm for testing L{userauth.SSHUserAuthServer}.

    This realm is not actually used in the course of testing, so it returns the
    simplest thing that could possibly work.
    cGst�|dddd�f�S)NrcSrIrAr#r#r#r#r$�<lambda>��z%Realm.requestAvatar.<locals>.<lambda>r8)r1�avatarId�mind�
interfacesr#r#r$�
requestAvatar�szRealm.requestAvatarN)rr r!r"rjr#r#r#r$rd�srdc@�eZdZdZefZdd�ZdS)�PasswordCheckerz�
    A very simple username/password checker which authenticates anyone whose
    password matches their username and rejects all others.
    cCs&|j|jkrt�|j�St�td��S)NzInvalid username/password pair)�username�passwordrr.�failr)r1�credsr#r#r$�requestAvatarId�szPasswordChecker.requestAvatarIdN)rr r!r"r
�credentialInterfacesrqr#r#r#r$rl��rlc@rk)�PrivateKeyCheckerz�
    A very simple public key checker which authenticates anyone whose
    public/private keypair is the same keydata.public/privateRSA_openssh.
    cCsX|jtj�tj���kr)|jdur&tj�|j�}|�|j|j�r#|j	St��t
��t��rA)rFrr+r,rr-�	signature�verify�sigDatarmrr)r1rp�objr#r#r$rq�s
�z!PrivateKeyChecker.requestAvatarIdN)rr r!r"r	rrrqr#r#r#r$rt�rsrtc@rk)�AnonymousCheckerzI
    A simple checker which isn't supported by L{SSHUserAuthServer}.
    cCrIrAr#)r1�credentialsr#r#r$rq�sz AnonymousChecker.requestAvatarIdN)rr r!r"rrrrqr#r#r#r$ry�sryc@s�eZdZdZedurdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�ZdS),�SSHUserAuthServerTestsz&
    Tests for SSHUserAuthServer.
    N�cannot run without cryptographycCsbt�|_t|j�|_|j�t��|j�t��t��|_	t
|j�|j	_|j	��|j	j
��dSrA)rd�realmr
rW�registerCheckerrlrtr�SSHUserAuthServer�
authServerrLrrN�supportedAuthentications�sortr0r#r#r$�setUp�s

zSSHUserAuthServerTests.setUpcC�|j��d|_dSrA)r��serviceStoppedr0r#r#r$�tearDown��

zSSHUserAuthServerTests.tearDowncCs(|�|jjjdtjtd�df�dS)z;
        Check that the authentication has failed.
        ���spassword,publickey�N)�assertEqualr�rrYr�MSG_USERAUTH_FAILUREr�r1�ignoredr#r#r$�_checkFailed�s�z#SSHUserAuthServerTests._checkFailedcCs,|j�td�td�td��}|�|j�S)z�
        A client may request a list of authentication 'method name' values
        that may continue by using the "none" authentication 'method name'.

        See RFC 4252 Section 5.2.
        r7sservicerQ)r��ssh_USERAUTH_REQUESTr�addCallbackr�)r1�dr#r#r$�test_noneAuthentications�z.SSHUserAuthServerTests.test_noneAuthenticationcsFd�td�td�td�dtd�g�}�j�|�}�fdd�}|�|�S)z�
        When provided with correct password authentication information, the
        server should respond by sending a MSG_USERAUTH_SUCCESS message with
        no other data.

        See RFC 4252, Section 5.1.
        �r7rQ�passwordr�c����jjjtjdfg�dS�Nr��r�r�rrYr�MSG_USERAUTH_SUCCESS�r�r0r#r$�check�
�zKSSHUserAuthServerTests.test_successfulPasswordAuthentication.<locals>.check)�joinrr�r�r��r1�packetr�r�r#r0r$�%test_successfulPasswordAuthentications$
z<SSHUserAuthServerTests.test_successfulPasswordAuthenticationcCshd�td�td�td�dtd�g�}t��|j_|j�|�}|�|jjj	g�|jj�
d�|�|j�S)a;
        When provided with invalid authentication details, the server should
        respond by sending a MSG_USERAUTH_FAILURE message which states whether
        the authentication was partially successful, and provides other, open
        options for authentication.

        See RFC 4252, Section 5.1.
        r�r7rQr�r��bar�)
r�rr�Clockr��clockr�r�rrY�advancer�r��r1r�r�r#r#r$�!test_failedPasswordAuthentication's$
z8SSHUserAuthServerTests.test_failedPasswordAuthenticationcs�tj�tj���}tj�tj�}td�td�td�dt|���t|�}d�j	j
_|�td�t
tjf�|�}|t|�7}�j	�|�}�fdd�}|�|�S)zN
        Test that private key authentication completes successfully,
        r7rQ�	publickey���testcr�r�r�r�r0r#r$r�Mr�zMSSHUserAuthServerTests.test_successfulPrivateKeyAuthentication.<locals>.check)rr+r,rr-rFr3r�sshTyper�r�	sessionID�sign�bytesr�MSG_USERAUTH_REQUESTr�r�)r1rFrxr�rur�r�r#r0r$�'test_successfulPrivateKeyAuthentication8s,���
���
�
z>SSHUserAuthServerTests.test_successfulPrivateKeyAuthenticationcs�t���dd�}dd�}�fdd�}|�|jd|�|�|jd|�|�|jd	|�td
�td�td�td
�}|j�|�|��t�S)z�
        ssh_USERAUTH_REQUEST should raise a ConchError if tryAuth returns
        None. Added to catch a bug noticed by pyflakes.
        cSs|�d�dS)Nz&request should have raised ConochError)ror�r#r#r$�mockCbFinishedAuth\rKzOSSHUserAuthServerTests.test_requestRaisesConchError.<locals>.mockCbFinishedAuthcSrIrAr#)�kind�user�datar#r#r$�mockTryAuth_rJzHSSHUserAuthServerTests.test_requestRaisesConchError.<locals>.mockTryAuthcs��|j�dSrA)�errback�value)�reason�r�r#r$�
mockEbBadAuthbszJSSHUserAuthServerTests.test_requestRaisesConchError.<locals>.mockEbBadAuth�tryAuth�_cbFinishedAuth�
_ebBadAuthsuserrQs
public-keysdata)r�Deferred�patchr�rr��
assertFailurer)r1r�r�r�r�r#r�r$�test_requestRaisesConchErrorUs z3SSHUserAuthServerTests.test_requestRaisesConchErrorcsbtj�tj����td�td�td�dtd�t��}�j�|�}��fdd�}|�	|�S)z@
        Test that verifying a valid private key works.
        r7rQr�r��ssh-rsacs*���jjjtjtd�t��fg�dS)Nr�)r�r�rrYr�MSG_USERAUTH_PK_OKrr��rFr1r#r$r�~s�z@SSHUserAuthServerTests.test_verifyValidPrivateKey.<locals>.check)
rr+r,rr-rFrr�r�r�r�r#r�r$�test_verifyValidPrivateKeyos ������
z1SSHUserAuthServerTests.test_verifyValidPrivateKeycCsVtj�tj���}td�td�td�dtd�t|�}|j�|�}|�	|j
�S)�d
        Test that private key authentication fails when the public key
        is invalid.
        r7rQr�r�sssh-dsa�rr+r,rr/rFrr�r�r�r��r1rFr�r�r#r#r$�3test_failedPrivateKeyAuthenticationWithoutSignature�s������zJSSHUserAuthServerTests.test_failedPrivateKeyAuthenticationWithoutSignaturecCs|tj�tj���}tj�tj�}td�td�td�dtd�t|�t|�|��}d|j	j
_|j	�|�}|�
|j�S)r�r7rQr�r�r�r�)rr+r,rr-rFr3rr�r�rr�r�r�r�)r1rFrxr�r�r#r#r$�0test_failedPrivateKeyAuthenticationWithSignature�s&�������
	zGSSHUserAuthServerTests.test_failedPrivateKeyAuthenticationWithSignaturecCsjtj�tj���}td�|dd�}td�td�td�dtd�t|�}|j�|�}|�	|j
�S)	z�
        Private key authentication fails when the public key type is
        unsupported or the public key is corrupt.
        sssh-bad-type�Nr7rQr�r�r�r�r�r#r#r$�test_unsupported_publickey�s ������z1SSHUserAuthServerTests.test_unsupported_publickeycCsRt��}t|j�|_|j�t��|��|��|j	�
�|�|j	ddg�dS)ah
        L{SSHUserAuthServer} sets up
        C{SSHUserAuthServer.supportedAuthentications} by checking the portal's
        credentials interfaces and mapping them to SSH authentication method
        strings.  If the Portal advertises an interface that
        L{SSHUserAuthServer} can't map, it should be ignored.  This is a white
        box test.
        r�r�N)rrrLrWrr~ryrNr�r�r�r��r1�serverr#r#r$� test_ignoreUnknownCredInterfaces�s	
z7SSHUserAuthServerTests.test_ignoreUnknownCredInterfacescCs�|�d|jj�t��}t|j�|_dd�|j_|�	�|�
�|�d|j�t��}t|j�|_dd�|j_|�	�|�
�|�d|j�dS)z�
        Test that the userauth service does not advertise password
        authentication if the password would be send in cleartext.
        r�cSr_rUr#��xr#r#r$re�rfzISSHUserAuthServerTests.test_removePasswordIfUnencrypted.<locals>.<lambda>cS�|dkS�N�inr#r�r#r#r$re��N)�assertInr�r�rrrLrWrrarNr��assertNotIn)r1�clearAuthServer�halfAuthServerr#r#r$� test_removePasswordIfUnencrypted�sz7SSHUserAuthServerTests.test_removePasswordIfUnencryptedcCs�t|j�}|�t��t��}t|�|_dd�|j_|�	�|�
�|�|jdg�t��}t|�|_dd�|j_|�	�|�
�|�|jdg�dS)z�
        If the L{SSHUserAuthServer} is not advertising passwords, then an
        unencrypted connection should not cause any warnings or exceptions.
        This is a white box test.
        cSr_rUr#r�r#r#r$re�rfzSSSHUserAuthServerTests.test_unencryptedConnectionWithoutPasswords.<locals>.<lambda>r�cSr�r�r#r�r#r#r$re�r�N)
r
r}r~rtrrrLrrarNr�r�r�)r1rWr�r�r#r#r$�*test_unencryptedConnectionWithoutPasswords�s


zASSHUserAuthServerTests.test_unencryptedConnectionWithoutPasswordscCs�t��}t��|_t|j�|_|��|j�	d�|�
�|�|jjtj
dttjf�td�td�fg�|�|jj�dS)z0
        Test that the login times out.
        鰚�syou took too longr�N)rrrr�r�rLrWrrNr�r�r�rY�MSG_DISCONNECTr��)DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLEr�
assertTruerX�r1�timeoutAuthServerr#r#r$�test_loginTimeouts(

������z(SSHUserAuthServerTests.test_loginTimeoutcCs\t��}t��|_t|j�|_|��|�	�|j�
d�|�|jjg�|�
|jj�dS)zN
        Test that stopping the service also stops the login timeout.
        r�N)rrrr�r�rLrWrrNr�r�r�rY�assertFalserXr�r#r#r$�test_cancelLoginTimeouts
z.SSHUserAuthServerTests.test_cancelLoginTimeoutcsnd�td�td�td�dtd�g�}t���j_td�D]}�j�|�}�jj�d�q�fd	d
�}|�	|�S)zm
        Test that the server disconnects if the client fails authentication
        too many times.
        r�r7rQr�r�r��r�cs<���jjjdtjdttjf�td�td�f�dS)Nr�r�stoo many bad authsr�)r�r�rrYr�r�r�rr�r0r#r$r�1s
�����z:SSHUserAuthServerTests.test_tooManyAttempts.<locals>.check)
r�rrr�r�r��ranger�r�r�)r1r��ir�r�r#r0r$�test_tooManyAttempts&s$
z+SSHUserAuthServerTests.test_tooManyAttemptscCsHtd�td�td�dtd�}t��|j_|j�|�}|�|j�S)zo
        If the user requests a service that we don't support, the
        authentication should fail.
        r7r�r�r�)rrr�r�r�r�r�r�r�r#r#r$�test_failIfUnknownService?s$z0SSHUserAuthServerTests.test_failIfUnknownServicecsVdd�}���jd|����jdd��fdd�}�j�ddd�}��|t��|�S)	aZ
        tryAuth() has two edge cases that are difficult to reach.

        1) an authentication method auth_* returns None instead of a Deferred.
        2) an authentication type that is defined does not have a matching
           auth_* method.

        Both these cases should return a Deferred which fails with a
        ConchError.
        cSrIrAr#)r�r#r#r$�mockAuthUrJz>SSHUserAuthServerTests.test_tryAuthEdgeCases.<locals>.mockAuth�auth_publickey�
auth_passwordNcs�j�ddd�}��|t�S)Nr�)r�r�r�r)r��d2r0r#r$�
secondTest[sz@SSHUserAuthServerTests.test_tryAuthEdgeCases.<locals>.secondTestr�)r�r�r�r�rr�)r1r�r��d1r#r0r$�test_tryAuthEdgeCasesIsz,SSHUserAuthServerTests.test_tryAuthEdgeCases)rr r!r"r�skipr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r#r#r#r$r{�s0	

r{c@s�eZdZdZedurdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�ZdS)"�SSHUserAuthClientTestsz&
    Tests for SSHUserAuthClient.
    Nr|cCs4tdt���|_td�|j_d|jj_|j��dS)Nr7r�)r)rLrO�
authClientrr�rNr0r#r#r$r�ks
zSSHUserAuthClientTests.setUpcCr�rA)r�r�r0r#r#r$r�qr�zSSHUserAuthClientTests.tearDowncCsT|�|jjd�|�|jjjd�|�|jjjtjt	d�t	d�t	d�fg�dS)z;
        Test that client is initialized properly.
        r7rMrQN)
r�r�r��instancer=rrYrr�rr0r#r#r$�	test_initus�z SSHUserAuthClientTests.test_initcs@dg��fdd�}||jj_|j�d�|��d|jj�dS)z9
        Test that the client succeeds properly.
        Ncs|�d<dS)Nrr#)rR�r�r#r$�stubSetService�szDSSHUserAuthClientTests.test_USERAUTH_SUCCESS.<locals>.stubSetServicer�r)r�r�
setService�ssh_USERAUTH_SUCCESSr�r�)r1r�r#r�r$�test_USERAUTH_SUCCESS�s

z,SSHUserAuthClientTests.test_USERAUTH_SUCCESSc	Cs�|j�td�d�|�|jjjdtjtd�td�td�dtd�ttj	�
tj��
��f�|j�td�d�ttj	�
tj��
��}|�|jjjdtjtd�td�td�dtd�|f�|j�td�ttj	�
tj��
���t|jjj�ttjf�td�td�td�dtd�|}tj	�
tj�}|�|jjjdtjtd�td�td�dtd�|t|�|��f�d	S)
zJ
        Test that the client can authenticate with a public key.
        r�r�r�r7rMsssh-dssr��N)r��ssh_USERAUTH_FAILURErr�rrYrr�rr+r,rr/rFr-�ssh_USERAUTH_PK_OKr�r�r3r�)r1rFrwrxr#r#r$�test_publickey�s��������
��������
��������
��������z%SSHUserAuthClientTests.test_publickeycCsztdt���}td�|_d|j_|��|�d�g|j_|�|�	d��|�
|jjtjt
d�t
d�t
d�fg�dS)z�
        If the SSHUserAuthClient doesn't return anything from signData,
        the client should start the authentication over again by requesting
        'none' authentication.
        r7Nr�r�r�rMrQ)rHrLrOrr�rNr�rY�assertIsNoner�r�rr�r)r1r�r#r#r$�!test_publickey_without_privatekey�s

�z8SSHUserAuthClientTests.test_publickey_without_privatekeycs.dd��j_�j�d�}�fdd�}|�|�S)z{
        If there's no public key, auth_publickey should return a Deferred
        called back with a False value.
        cSrIrAr#r�r#r#r$re�rfz:SSHUserAuthClientTests.test_no_publickey.<locals>.<lambda>r�cs��|�dSrA)r���resultr0r#r$r��rKz7SSHUserAuthClientTests.test_no_publickey.<locals>.check)r�r2r�r�)r1r�r�r#r0r$�test_no_publickey�s
z(SSHUserAuthClientTests.test_no_publickeycCs�|j�td�d�|�|jjjdtjtd�td�td�dtd�f�|j�td�td��|�|jjjdtjtd�td�td�dtd�df�d	S)
zx
        Test that the client can authentication with a password.  This
        includes changing the password.
        r�r�r�r7rMr�r�r�N)	r�r�rr�rrYrr�r�r0r#r#r$�
test_password�s"��&��z$SSHUserAuthClientTests.test_passwordcCs"dd�|j_|�|j�d��dS)zK
        If getPassword returns None, tryAuth should return False.
        cSrIrAr#r#r#r#r$rerfz9SSHUserAuthClientTests.test_no_password.<locals>.<lambda>r�N)r�r:r�r�r0r#r#r$�test_no_passwordsz'SSHUserAuthClientTests.test_no_passwordcCs`|j�td�td�td�dtd�d�|�|jjjdtjdtd�td�f�dS)	zj
        Make sure that the client can authenticate with the keyboard
        interactive method.
        r�ss
Password: r�r�sr7N)r��'ssh_USERAUTH_PK_OK_keyboard_interactiverr�rrYr�MSG_USERAUTH_INFO_RESPONSEr0r#r#r$�test_keyboardInteractives&��������z/SSHUserAuthClientTests.test_keyboardInteractivecCsPd|j_g|jj_|j�d�|�|jjjtjtd�td�td�fg�dS)z�
        If C{SSHUserAuthClient} gets a MSG_USERAUTH_PK_OK packet when it's not
        expecting it, it should fail the current authentication and move on to
        the next type.
        sunknownr�r7rMrQN)	r��lastAuthrrYr�r�rr�rr0r#r#r$�"test_USERAUTH_PK_OK_unknown_methods
�z9SSHUserAuthClientTests.test_USERAUTH_PK_OK_unknown_methodcs��fdd�}�fdd�}|�j_|�j_�j�td�d����jjjdtj	td�td	�td
�dtd�f��j�td�d����jjjd
d�ddg�dS)z�
        ssh_USERAUTH_FAILURE should sort the methods by their position
        in SSHUserAuthClient.preferredOrder.  Methods that are not in
        preferredOrder should be sorted at the end of that list.
        cs�jj�dd�dS)N��here is data�r�rr^r#r0r#r$�auth_firstmethod2szNSSHUserAuthClientTests.test_USERAUTH_FAILURE_sorting.<locals>.auth_firstmethodcs�jj�dd�dS)N��
other dataTr
r#r0r#r$�auth_anothermethod5szPSSHUserAuthClientTests.test_USERAUTH_FAILURE_sorting.<locals>.auth_anothermethodsanothermethod,passwordr�r�r7rMr�s"firstmethod,anothermethod,passwordr����N)rr)rr)
r�rrr�rr�rrYrr�)r1rrr#r0r$�test_USERAUTH_FAILURE_sorting+s$"��
��z4SSHUserAuthClientTests.test_USERAUTH_FAILURE_sortingcCsT|j�td�d�|j�td�d�|�|jjjdtjdtd�df�dS)	z�
        If there are no more available user authentication messages,
        the SSHUserAuthClient should disconnect with code
        DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE.
        r�r�r�r�ss(no more authentication methods availablesN)r�r�rr�rrYr�r0r#r#r$�%test_disconnectIfNoMoreAuthenticationOs����z<SSHUserAuthClientTests.test_disconnectIfNoMoreAuthenticationcCsHg|jj_|j�d�|�|jjjtjtd�td�td�fg�dS)z�
        _ebAuth (the generic authentication error handler) should send
        a request for the 'none' authentication method.
        Nr7rMrQ)r�rrY�_ebAuthr�rr�rr0r#r#r$�test_ebAuthas
�z"SSHUserAuthClientTests.test_ebAuthcs`t�dt�������������fdd�}���fdd��dd�����}|��j��	|�S)z�
        getPublicKey() should return None.  getPrivateKey() should return a
        failed Deferred.  getPassword() should return a failed Deferred.
        getGenericAnswers() should return a failed Deferred.
        r7cs$|�t����}|��j����SrA)�trap�NotImplementedErrorr:r�ro�
addErrback�rr�)r��check2r1r#r$r�vs
z3SSHUserAuthClientTests.test_defaults.<locals>.checkcs*|�t���ddd�}|��j����SrA)rrr@r�rorr)r��check3r1r#r$r{s
z4SSHUserAuthClientTests.test_defaults.<locals>.check2cSs|�t�dSrA)rrrr#r#r$r�rKz4SSHUserAuthClientTests.test_defaults.<locals>.check3)
rr(rLrOr�r2r4r�ror)r1r�r�r#)r�rrr1r$�
test_defaultsmsz$SSHUserAuthClientTests.test_defaults)rr r!r"rr�r�r�r�r�r�rrrrrr
rrrrr#r#r#r$r�cs&
>
$r�c@s.eZdZedur
dZGdd�d�Zdd�ZdS)�
LoopbackTestsN�)cannot run without cryptography or PyASN1c@s"eZdZGdd�d�Zdd�ZdS)zLoopbackTests.Factoryc@rB)zLoopbackTests.Factory.Service�TestServicecCs|j��dSrA)rrcr0r#r#r$rN�rKz,LoopbackTests.Factory.Service.serviceStartedcCrIrAr#r0r#r#r$r��rJz,LoopbackTests.Factory.Service.serviceStoppedN)rr r!r=rNr�r#r#r#r$rO�srOcCs|jSrA)rO)r1�avatarr=r#r#r$rS�sz LoopbackTests.Factory.getServiceN)rr r!rOrSr#r#r#r$rT�s	rTcs t���td�j���}t���_��j_dd��j_t��|_||j_d�j_	|j_	dd��j_
|j_
����j_d�_t
�}t|�}t����t����t���fdd��_|���|�jj_t��j|j�}dd��jj_d	d�|jj_���|����fd
d�}|�|�S)zW
        Test that the userauth server and client play nicely with each other.
        r7cSr_rbr#r�r#r#r$re�rfz-LoopbackTests.test_loopback.<locals>.<lambda>r�cSrIrAr#r#r#r#r$re�rfrcst�j|�dkS)Nr�)�len�successfulCredentials)�aId)�checkerr#r$re�scSr_)N�_ServerLoopbackr#r#r#r#r$re�rfcSr_)N�_ClientLoopbackr#r#r#r#r$re�rfcs���jjjd�dS)Nr )r�rrRr=r�r�r#r$r��rEz*LoopbackTests.test_loopback.<locals>.check)rrr)rTrOrr%rRrar��sendKexInitrV�
passwordDelayrdr
rr~rlrt�areDonerWr�
loopbackAsync�	logPrefixrNr�)r1�clientr}rWr�r�r#)r%r1r�r$�
test_loopback�s4




zLoopbackTests.test_loopback)rr r!rr�rTr.r#r#r#r$r�s

rc@s eZdZedur
dZdd�ZdS)�ModuleInitializationTestsNrcCs,|�tjjdd�|�tjjdd�dS)N�<r�)r�rr�protocolMessagesr(r0r#r#r$�
test_messages�s��z'ModuleInitializationTests.test_messages)rr r!rr�r2r#r#r#r$r/�sr/)8r"�typesr�typingr�zope.interfacer�twisted.conch.errorrr�twisted.cred.checkersr�twisted.cred.credentialsrr	r
�twisted.cred.errorr�twisted.cred.portalrr
�twisted.internetrr�twisted.protocolsr�twisted.python.reflectr�
twisted.trialrr�__annotations__�twisted.conch.checkersr�twisted.conch.sshrr�twisted.conch.ssh.commonr�twisted.conch.testrr(r)rCrHr%rLrdrlrtry�TestCaser{r�rr/r#r#r#r$�<module>sR#
A}&<

Anon7 - 2022
AnonSec Team