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_checkers.cpython-310.pyc
o

�blz�@s�dZzddlZWneydZYnwdZddlZddlmZddlmZddl	m
Z
ddlmZdd	l
mZdd
lmZmZmZmZddlmZmZddlmZdd
lmZddlmZmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%e!d�r�e!d�r�dZ&ddl'm(Z(ddl)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ndZ&e0edd�dur�dZ1ndZ1Gdd�de%�Z2Gdd�de%�Z3Gd d!�d!e%�Z4Gd"d#�d#e%�Z5Gd$d%�d%e%�Z6Gd&d'�d'e%�Z7Gd(d)�d)e%�Z8ed*d+g�Z9Gd,d-�d-e:�Z;Gd.d/�d/e%�Z<dS)0z&
Tests for L{twisted.conch.checkers}.
�Nzcannot run without crypt module�)�encodebytes)�
namedtuple)�BytesIO)�verifyObject)�'InMemoryUsernamePasswordDatabaseDontUse)�ISSHPrivateKey�IUsernamePassword�
SSHPrivateKey�UsernamePassword)�UnauthorizedLogin�UnhandledCredentials)�util)�Failure)�ShadowDatabase�UserDatabase)�FilePath)�
requireModule)�MockOS)�TestCase�cryptography�pyasn1)�checkers)�NotEnoughAuthentication�ValidPublicKey)�keys)�keydataz)can't run without cryptography and PyASN1�geteuidz0Cannot run without effective UIDs (questionable)c@sXeZdZdZep	eZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�ZdS)�HelperTestszl
    Tests for helper functions L{verifyCryptedPassword}, L{_pwdGetByName} and
    L{_shadowGetByName}.
    cCst�|_dS�N)r�mockos��self�r#�B/usr/lib/python3/dist-packages/twisted/conch/test/test_checkers.py�setUp>szHelperTests.setUpcC�4d}d}t�||�}|�t�||�d�||��dS)z�
        L{verifyCryptedPassword} returns C{True} if the plaintext password
        passed to it matches the encrypted password passed to it.
        �
secret string�saltyz5{!r} supposed to be valid encrypted password for {!r}N��crypt�
assertTruer�verifyCryptedPassword�format�r"�password�salt�cryptedr#r#r$�test_verifyCryptedPasswordA�
��z&HelperTests.test_verifyCryptedPasswordcCr&)z�
        L{verifyCryptedPassword} returns True if the provided cleartext password
        matches the provided MD5 password hash.
        r/z$1$saltz3{!r} supposed to be valid encrypted password for {}Nr)r.r#r#r$�test_verifyCryptedPasswordMD5Pr3z)HelperTests.test_verifyCryptedPasswordMD5cCs4d}d}t�||�}|�t�||�d�||��dS)z�
        L{verifyCryptedPassword} returns C{False} if the plaintext password
        passed to it does not match the encrypted password passed to it.
        z
string secretr'z7{!r} not supposed to be valid encrypted password for {}N)r*�assertFalserr,r-)r"r/�wrongr1r#r#r$�test_refuteCryptedPassword_r3z&HelperTests.test_refuteCryptedPasswordc	CsFt�}|�ddddddd�|�td|�|�t�d�|�d��d	S)
z�
        L{_pwdGetByName} returns a tuple of items from the UNIX /etc/passwd
        database if the L{pwd} module is present.
        �alice�secrit��z
first last�/foo�/bin/sh�pwdN)r�addUser�patchr�assertEqual�
_pwdGetByName�getpwnam�r"�userdbr#r#r$�test_pwdGetByNamenszHelperTests.test_pwdGetByNamecCs"|�tdd�|�t�d��dS)zW
        If the C{pwd} module isn't present, L{_pwdGetByName} returns L{None}.
        r>Nr8)r@r�assertIsNonerBr!r#r#r$�test_pwdGetByNameWithoutPwdxsz'HelperTests.test_pwdGetByNameWithoutPwdcCs�t�}|�ddddddddd	�	|�td
|�d|j_d|j_|�td
|j�|�t�	d�|�
d��|�|jjddg�|�|jjddg�dS)z�
        L{_shadowGetByName} returns a tuple of items from the UNIX /etc/shadow
        database if the L{spwd} is present.
        �bob�
passphraser:r;������spwd�)	���osrN)
rr?r@rr �euid�egidrrA�_shadowGetByName�getspnam�seteuidCalls�setegidCallsrDr#r#r$�test_shadowGetByNamesz HelperTests.test_shadowGetByNamecCsB|�tdd�|�t�d��|�|jjg�|�|jjg�dS)zP
        L{_shadowGetByName} returns L{None} if C{spwd} is not present.
        rPNrI)r@rrGrVrAr rXrYr!r#r#r$�test_shadowGetByNameWithoutSpwd�sz+HelperTests.test_shadowGetByNameWithoutSpwdN)�__name__�
__module__�__qualname__�__doc__�	cryptSkip�dependencySkip�skipr%r2r4r7rFrHrZr[r#r#r#r$r6s
rc@speZdZdZep	eZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�SSHPublicKeyDatabaseTestsz,
    Tests for L{SSHPublicKeyDatabase}.
    c	Cs�t��|_td�|_td�|_d|jd|jd|_t�|_t	|�
��|j_|jj��|�
td|j�|jj�d�|_|j��t�}|�dd	d
dd|jjjd
�||j_dS)N�foobar�eggspamst1 s foo
t2 s egg
rS�.ssh�user�passwordr:r;s
first last�
/bin/shell)r�SSHPublicKeyDatabase�checkerr�key1�key2�contentrr r�mktemp�path�makedirsr@r�child�sshDirrr?�_userdbrDr#r#r$r%�s*



�	zSSHPublicKeyDatabaseTests.setUpcCsL|j|jgd�}|�|ddt�|�|ddd�|�t|�d�dS)zJ
        L{SSHPublicKeyDatabase} is deprecated as of version 15.0
        )�offendingFunctionsr�category�messagez�twisted.conch.checkers.SSHPublicKeyDatabase was deprecated in Twisted 15.0.0: Please use twisted.conch.checkers.SSHPublicKeyChecker, initialized with an instance of twisted.conch.checkers.UNIXAuthorizedKeysFiles instead.r:N)�
flushWarningsr%rA�DeprecationWarning�len)r"�
warningsShownr#r#r$�test_deprecated�s
�z)SSHPublicKeyDatabaseTests.test_deprecatedcCsj|j�|��|j�tdd�}d|_|�|j�|��d|_|�|j�|��d|_|�	|j�|��dS)Nrgrhrdres
notallowed)
rsrr�
setContentrnr�blobr+rk�checkKeyr5)r"�filename�userr#r#r$�
_testCheckKey�s
z'SSHPublicKeyDatabaseTests._testCheckKeycC�.|�d�|�|jjg�|�|jjg�dS)z�
        L{SSHPublicKeyDatabase.checkKey} should retrieve the content of the
        authorized_keys file and check the keys against that file.
        �authorized_keysN�r�rAr rXrYr!r#r#r$�
test_checkKey��
z'SSHPublicKeyDatabaseTests.test_checkKeycCr�)z�
        L{SSHPublicKeyDatabase.checkKey} should retrieve the content of the
        authorized_keys2 file and check the keys against that file.
        �authorized_keys2Nr�r!r#r#r$�test_checkKey2�r�z(SSHPublicKeyDatabaseTests.test_checkKey2cs�|j�d����|j���d�|��jd�|jj���fdd�}d|j_d|j_	|�
|jd|�|�
td	|j�td
d�}d|_
|�|j�|��|�|jjgd
��|�|jjddg�dS)z�
        If the key file is readable, L{SSHPublicKeyDatabase.checkKey} should
        switch its uid/gid to the ones of the authenticated user.
        r�r�cs��d��|�S)Nr�)�chmod)rT��keyFile�savedSeteuidr#r$�seteuid�s
z>SSHPublicKeyDatabaseTests.test_checkKeyAsRoot.<locals>.seteuidrQrRr�rSrgrhrd)rr:rrQr;N)rsrrr}rnr��
addCleanupr r�rTrUr@rrr~r+rkrrArXrY)r"r�r�r#r�r$�test_checkKeyAsRoot�s

z-SSHPublicKeyDatabaseTests.test_checkKeyAsRootcs\dd�}���jd|�tddtjdtj�tj��	d��}�j�
|�}�fdd�}|�|�S)	z�
        L{SSHPublicKeyDatabase.requestAvatarId} should return the avatar id
        passed in if its C{_checkKey} method returns True.
        cS�dS�NTr#��ignoredr#r#r$�	_checkKey�zASSHPublicKeyDatabaseTests.test_requestAvatarId.<locals>._checkKeyr�test�ssh-rsa�fooc���|d�dS�Nr��rA��avatarIdr!r#r$�_verify�z?SSHPublicKeyDatabaseTests.test_requestAvatarId.<locals>._verify)r@rkr
r�publicRSA_opensshr�Key�
fromString�privateRSA_openssh�sign�requestAvatarId�addCallback)r"r��credentials�dr�r#r!r$�test_requestAvatarIds�
z.SSHPublicKeyDatabaseTests.test_requestAvatarIdcCsBdd�}|�|jd|�tddtjdd�}|j�|�}|�|t�S)a(
        L{SSHPublicKeyDatabase.requestAvatarId} should raise L{ValidPublicKey}
        if the credentials represent a valid key without a signature.  This
        tells the user that the key is valid for login, but does not actually
        allow that user to do so without a signature.
        cSr�r�r#r�r#r#r$r�"r�zQSSHPublicKeyDatabaseTests.test_requestAvatarIdWithoutSignature.<locals>._checkKeyrr�r�N)r@rkr
rr�r��
assertFailurer�r"r�r�r�r#r#r$�$test_requestAvatarIdWithoutSignatures�z>SSHPublicKeyDatabaseTests.test_requestAvatarIdWithoutSignaturecCs0dd�}|�|jd|�|j�d�}|�|t�S)z�
        If L{SSHPublicKeyDatabase.checkKey} returns False,
        C{_cbRequestAvatarId} should raise L{UnauthorizedLogin}.
        cSr��NFr#r�r#r#r$r�2r�zKSSHPublicKeyDatabaseTests.test_requestAvatarIdInvalidKey.<locals>._checkKeyrN)r@rkr�r�r)r"r�r�r#r#r$�test_requestAvatarIdInvalidKey,sz8SSHPublicKeyDatabaseTests.test_requestAvatarIdInvalidKeycCsRdd�}|�|jd|�tddtjdtj�tj��	d��}|j�
|�}|�|t�S)z�
        Valid keys with invalid signatures should cause
        L{SSHPublicKeyDatabase.requestAvatarId} to return a {UnauthorizedLogin}
        failure
        cSr�r�r#r�r#r#r$r�@r�zQSSHPublicKeyDatabaseTests.test_requestAvatarIdInvalidSignature.<locals>._checkKeyrr�r�r�)
r@rkr
rr�rr�r��privateDSA_opensshr�r�r�rr�r#r#r$�$test_requestAvatarIdInvalidSignature9s�z>SSHPublicKeyDatabaseTests.test_requestAvatarIdInvalidSignaturecsVdd�}���jd|�tddddd�}�j�|�}�fd	d
�}|�|���|t�S)z~
        Exceptions raised while verifying the key should be normalized into an
        C{UnauthorizedLogin} failure.
        cSr�r�r#r�r#r#r$r�Tr�zSSSHPublicKeyDatabaseTests.test_requestAvatarIdNormalizeException.<locals>._checkKeyrr�NsblobssigDatassigcs ��tj�}��t|�d�|S)Nr:)�flushLoggedErrorsr�BadKeyErrorrArz)�failure�errorsr!r#r$�_verifyLoggedException[�z`SSHPublicKeyDatabaseTests.test_requestAvatarIdNormalizeException.<locals>._verifyLoggedException)r@rkr
r��
addErrbackr�r)r"r�r�r�r�r#r!r$�&test_requestAvatarIdNormalizeExceptionNs
z@SSHPublicKeyDatabaseTests.test_requestAvatarIdNormalizeExceptionN)r\r]r^r_�euidSkiprarbr%r|r�r�r�r�r�r�r�r�r�r#r#r#r$rc�s
		
rcc@�DeZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�SSHProtocolCheckerTestsz*
    Tests for L{SSHProtocolChecker}.
    cCsLt��}|�|jg�|�t���|�|jtg�|�|jttj�dS)z�
        L{SSHProcotolChecker.registerChecker} should add the given checker to
        the list of registered checkers.
        N)r�SSHProtocolCheckerrA�credentialInterfaces�registerCheckerrjr�assertIsInstance�r"rkr#r#r$�test_registerCheckerks��z,SSHProtocolCheckerTests.test_registerCheckercCsNt��}|�|jg�|�t��t�|�|jtg�|�|jttj�dS)z�
        If a specific interface is passed into
        L{SSHProtocolChecker.registerChecker}, that interface should be
        registered instead of what the checker specifies in
        credentialIntefaces.
        N)rr�rAr�r�rjr	r�r�r#r#r$�!test_registerCheckerWithInterfacezs�z9SSHProtocolCheckerTests.test_registerCheckerWithInterfacecsJt��}t�}|�dd�|�|�|�tdd��}�fdd�}|�|�S)z�
        L{SSHProtocolChecker.requestAvatarId} should defer to one if its
        registered checkers to authenticate a user.
        r�cr�r�r�r�r!r#r$�	_callback�r�z?SSHProtocolCheckerTests.test_requestAvatarId.<locals>._callback)rr�rr?r�r�rr�)r"rk�passwordDatabaser�r�r#r!r$r��s

z,SSHProtocolCheckerTests.test_requestAvatarIdcCsVt��}dd�}|�|d|�t�}|�dd�|�|�|�tdd��}|�|t	�S)z�
        If the client indicates that it is never satisfied, by always returning
        False from _areDone, then L{SSHProtocolChecker} should raise
        L{NotEnoughAuthentication}.
        cSr�r�r#r�r#r#r$�_areDone�r�zYSSHProtocolCheckerTests.test_requestAvatarIdWithNotEnoughAuthentication.<locals>._areDone�areDoner�)
rr�r@rr?r�r�rr�r)r"rkr�r�r�r#r#r$�/test_requestAvatarIdWithNotEnoughAuthentication�s
zGSSHProtocolCheckerTests.test_requestAvatarIdWithNotEnoughAuthenticationcCs$t��}|�tdd��}|�|t�S)z�
        If the passed credentials aren't handled by any registered checker,
        L{SSHProtocolChecker} should raise L{UnhandledCredentials}.
        r�)rr�r�rr�r
)r"rkr�r#r#r$�%test_requestAvatarIdInvalidCredential�sz=SSHProtocolCheckerTests.test_requestAvatarIdInvalidCredentialcCs|�t���d��dS)zV
        The default L{SSHProcotolChecker.areDone} should simply return True.
        N)r+rr�r�r!r#r#r$�test_areDone�sz$SSHProtocolCheckerTests.test_areDoneN)r\r]r^r_rarbr�r�r�r�r�r�r#r#r#r$r�ds	r�c@s`eZdZdZep	eZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�ZdS)�UNIXPasswordDatabaseTestsz,
    Tests for L{UNIXPasswordDatabase}.
    cCsPg}|�|j�|�t|�dd�t|dt�r|d��|�|d|�dS)a�
        Assert that the L{Deferred} passed in is called back with the value
        'username'.  This represents a valid login for this TestCase.

        NOTE: To work, this method's return value must be returned from the
        test method, or otherwise hooked up to the test machinery.

        @param d: a L{Deferred} from an L{IChecker.requestAvatarId} method.
        @type d: L{Deferred}
        @rtype: L{Deferred}
        r:zlogin incompleterN)�addBoth�appendrArz�
isinstancer�raiseException)r"r��username�resultr#r#r$�assertLoggedIn�sz(UNIXPasswordDatabaseTests.assertLoggedIncCs<t��}dd�}t�}|�d|dd�ddddd	�|�d
ddddd
d	�t�}|�ddddddddd�	|�d
|d
d�ddddddd�	|�td|�|�td|�t�}|�td|�d|_d|_	t
d d!�}|�|�|�d �|�
|jg�|�
|jg�d"|_|�|�|�d"�|�
|jd#dg�|�
|jd#dg�d$S)%z�
        L{UNIXPasswordDatabase} with no arguments has checks the C{pwd} database
        and then the C{spwd} database.
        cSs t�||�}t�|d|�}|S)Nz$1$)r*)r�r/r0r1r#r#r$r1�r�z?UNIXPasswordDatabaseTests.test_defaultCheckers.<locals>.cryptedr8r/r:r;�foor<r=rI�x�bar�/barr6rKrLrMrNrO��	�
���
�r>rPrSrQrR�alicerh�bobrN)r�UNIXPasswordDatabaserr?rr@rrrTrUrr�r�rArXrYr�)r"rkr1r>rPr �credr#r#r$�test_defaultCheckers�s0� 
z.UNIXPasswordDatabaseTests.test_defaultCheckerscCs|�tj|j|d�dS)a�
        Asserts that the L{Deferred} passed in is erred back with an
        L{UnauthorizedLogin} L{Failure}.  This reprsents an invalid login for
        this TestCase.

        NOTE: To work, this method's return value must be returned from the
        test method, or otherwise hooked up to the test machinery.

        @param d: a L{Deferred} from an L{IChecker.requestAvatarId} method.
        @type d: L{Deferred}
        @rtype: L{None}
        zbogus valueN)�assertRaisesrrr��r"r�r#r#r$�assertUnauthorizedLogin�s
�z1UNIXPasswordDatabaseTests.assertUnauthorizedLoginc	CsRt�dd�}t�}|�d|ddddd�t�|jg�}|�|�tdd	��d�d
S)zo
        L{UNIXPasswordDatabase} takes a list of functions to check for UNIX
        user information.
        �secret�anybodyr:r;r�r�r=sanybodyssecretN)	r*rr?rr�rCr�r�r)r"r/rErkr#r#r$�test_passInCheckerss�z-UNIXPasswordDatabaseTests.test_passInCheckerscCsJdd�}dd�}|�td|�t�|g�}tdd�}|�|�|�d�dS)z�
        If the encrypted password provided by the getpwnam function is valid
        (verified by the L{verifyCryptedPassword} function), we callback the
        C{requestAvatarId} L{Deferred} with the username.
        cS�||kSrr#�r1�pwr#r#r$r,#�zLUNIXPasswordDatabaseTests.test_verifyPassword.<locals>.verifyCryptedPasswordcS�||gSrr#�r�r#r#r$rC&r�z?UNIXPasswordDatabaseTests.test_verifyPassword.<locals>.getpwnamr,�usernameN�r@rr�rr�r��r"r,rCrk�
credentialr#r#r$�test_verifyPasswords
z-UNIXPasswordDatabaseTests.test_verifyPasswordcCs2dd�}t�|g�}tdd�}|�|�|��dS)z}
        If the getpwnam function raises a KeyError, the login fails with an
        L{UnauthorizedLogin} exception.
        cSst|��r)�KeyErrorr�r#r#r$rC4r�z?UNIXPasswordDatabaseTests.test_failOnKeyError.<locals>.getpwnamr�N)rr�rr�r�)r"rCrkr�r#r#r$�test_failOnKeyError.s
z-UNIXPasswordDatabaseTests.test_failOnKeyErrorcCsHdd�}dd�}|�td|�t�|g�}tdd�}|�|�|��dS)z�
        If the verifyCryptedPassword function doesn't verify the password, the
        login fails with an L{UnauthorizedLogin} exception.
        cSr�r�r#r�r#r#r$r,Ar�zOUNIXPasswordDatabaseTests.test_failOnBadPassword.<locals>.verifyCryptedPasswordcSr�rr#r�r#r#r$rCDr�zBUNIXPasswordDatabaseTests.test_failOnBadPassword.<locals>.getpwnamr,r�N)r@rr�rr�r�r�r#r#r$�test_failOnBadPassword;s
z0UNIXPasswordDatabaseTests.test_failOnBadPasswordcCsTdd�}dd�}dd�}|�td|�t�||g�}tdd�}|�|�|�d�d	S)
a
        UNIXPasswordDatabase.requestAvatarId loops through each getpwnam
        function associated with it and returns a L{Deferred} which fires with
        the result of the first one which returns a value other than None.
        ones do not verify the password.
        cSr�rr#r�r#r#r$r,Tr�zRUNIXPasswordDatabaseTests.test_loopThroughFunctions.<locals>.verifyCryptedPasswordcSs|dgS)Nznot the passwordr#r�r#r#r$�	getpwnam1Wr�zFUNIXPasswordDatabaseTests.test_loopThroughFunctions.<locals>.getpwnam1cSr�rr#r�r#r#r$�	getpwnam2Zr�zFUNIXPasswordDatabaseTests.test_loopThroughFunctions.<locals>.getpwnam2r,r�Nr�)r"r,r�r�rkr�r#r#r$�test_loopThroughFunctionsLs
z3UNIXPasswordDatabaseTests.test_loopThroughFunctionsc	Cs�t�}|�ddddddd�|�ddddddd�|�d	d
ddddd�|�td|�t�tjg�}tdd
�}|�|�|��tdd�}|�|�|��tdd�}|�|�|��dS)z�
        If the password returned by any function is C{""}, C{"x"}, or C{"*"} it
        is not compared against the supplied password.  Instead it is skipped.
        r8rr:r;r�r�rIr��carol�*r>r��r��xscarol�*N)	rr?r@rr�rBrr�r�)r"r>rkr�r#r#r$�test_failOnSpecialbs


z,UNIXPasswordDatabaseTests.test_failOnSpecialN)r\r]r^r_r`rarbr�r�r�r�r�r�r�r�rr#r#r#r$r��s(

r�c@�,eZdZdZeZdd�Zdd�Zdd�ZdS)	�AuthorizedKeyFileReaderTestsz5
    Tests for L{checkers.readAuthorizedKeyFile}
    cCs0td�}t�|dd��}|�ddgt|��dS)zg
        L{checkers.readAuthorizedKeyFile} does not attempt to turn comments
        into keys
        sE# this comment is ignored
this is not
# this is again
and this is notcS�|Srr#�r�r#r#r$�<lambda>��zCAuthorizedKeyFileReaderTests.test_ignoresComments.<locals>.<lambda>sthis is notsand this is notN�rr�readAuthorizedKeyFilerA�list�r"�fileobjr�r#r#r$�test_ignoresCommentss
�z1AuthorizedKeyFileReaderTests.test_ignoresCommentscCs0td�}tj|dd�d�}|�dgt|��dS)zw
        L{checkers.readAuthorizedKeyFile} ignores leading whitespace in
        lines, as well as empty lines
        sg
                           # ignore
                           not ignored
                           cSrrr#rr#r#r$r�rzYAuthorizedKeyFileReaderTests.test_ignoresLeadingWhitespaceAndEmptyLines.<locals>.<lambda>��parseKeysnot ignoredNrr
r#r#r$�*test_ignoresLeadingWhitespaceAndEmptyLines�s
�zGAuthorizedKeyFileReaderTests.test_ignoresLeadingWhitespaceAndEmptyLinescCs4dd�}td�}tj||d�}|�dgt|��dS)z�
        L{checkers.readAuthorizedKeyFile} does not raise an exception
        when a key fails to parse (raises a
        L{twisted.conch.ssh.keys.BadKeyError}), but rather just keeps going
        cSs|�d�r
t�d��|S)N�fzfailed to parse)�
startswithrr�)�liner#r#r$�
failOnSome�s

zKAuthorizedKeyFileReaderTests.test_ignoresUnparsableKeys.<locals>.failOnSomesfailed key
good keyr
sgood keyNr)r"rrr�r#r#r$�test_ignoresUnparsableKeys�sz7AuthorizedKeyFileReaderTests.test_ignoresUnparsableKeysN)	r\r]r^r_rarbrrrr#r#r#r$rxsrc@r)	�InMemorySSHKeyDBTestsz0
    Tests for L{checkers.InMemorySSHKeyDB}
    cCs t�ddgi�}ttj|�dS)z_
        L{checkers.InMemorySSHKeyDB} implements
        L{checkers.IAuthorizedKeysDB}
        r�skeyN)r�InMemorySSHKeyDBr�IAuthorizedKeysDB�r"�keydbr#r#r$�test_implementsInterface�sz.InMemorySSHKeyDBTests.test_implementsInterfacecCs*t�ddgi�}|�gt|�d���dS)z�
        If the user is not in the mapping provided to
        L{checkers.InMemorySSHKeyDB}, an empty iterator is returned
        by L{checkers.InMemorySSHKeyDB.getAuthorizedKeys}
        r�skeysr�N�rrrAr	�getAuthorizedKeysrr#r#r$�test_noKeysForUnauthorizedUser�sz4InMemorySSHKeyDBTests.test_noKeysForUnauthorizedUsercCs0t�dddgi�}|�ddgt|�d���dS)z�
        If the user is in the mapping provided to
        L{checkers.InMemorySSHKeyDB}, an iterator with all the keys
        is returned by L{checkers.InMemorySSHKeyDB.getAuthorizedKeys}
        r��a�bNrrr#r#r$�test_allKeysForAuthorizedUser�sz3InMemorySSHKeyDBTests.test_allKeysForAuthorizedUserN)	r\r]r^r_rarbrrr r#r#r#r$r�s	rc@r�)�UNIXAuthorizedKeysFilesTestsz8
    Tests for L{checkers.UNIXAuthorizedKeysFiles}.
    c	Cs~t�}t|���|_|j��t�|_|j�ddddd|jjd�|j�d�|_	|j	��|j	�d�}|�
d	�d
dg|_dS)Nr�rhr:r;salice lastnamerirfr�skey 1
key 2skey 1skey 2)rrrorprqrrEr?rrrsr}�expectedKeys)r"r �authorizedKeysr#r#r$r%�s$
�


z"UNIXAuthorizedKeysFilesTests.setUpcCst�|j�}ttj|�dS)zg
        L{checkers.UNIXAuthorizedKeysFiles} implements
        L{checkers.IAuthorizedKeysDB}.
        N)r�UNIXAuthorizedKeysFilesrErrrr#r#r$r�sz5UNIXAuthorizedKeysFilesTests.test_implementsInterfacecCs.tj|jdd�d�}|�gt|�d���dS)z�
        If the user is not in the user database provided to
        L{checkers.UNIXAuthorizedKeysFiles}, an empty iterator is returned
        by L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys}.
        cSrrr#rr#r#r$r�rzMUNIXAuthorizedKeysFilesTests.test_noKeysForUnauthorizedUser.<locals>.<lambda>r
rIN)rr$rErAr	rrr#r#r$r�sz;UNIXAuthorizedKeysFilesTests.test_noKeysForUnauthorizedUsercCsH|j�d��d�tj|jdd�d�}|�|jdgt|�	d���dS)a
        If the user is in the user database provided to
        L{checkers.UNIXAuthorizedKeysFiles}, an iterator with all the keys in
        C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} is returned
        by L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys}.
        r�skey 3cSrrr#rr#r#r$rrz`UNIXAuthorizedKeysFilesTests.test_allKeysInAllAuthorizedFilesForAuthorizedUser.<locals>.<lambda>r
r�N)
rsrrr}rr$rErAr"r	rrr#r#r$�1test_allKeysInAllAuthorizedFilesForAuthorizedUser�s
�zNUNIXAuthorizedKeysFilesTests.test_allKeysInAllAuthorizedFilesForAuthorizedUsercCs0tj|jdd�d�}|�|jt|�d���dS)z�
        L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys} returns only
        the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2}
        if they exist.
        cSrrr#rr#r#r$rrzJUNIXAuthorizedKeysFilesTests.test_ignoresNonexistantFile.<locals>.<lambda>r
r�N)rr$rErAr"r	rrr#r#r$�test_ignoresNonexistantFile
sz8UNIXAuthorizedKeysFilesTests.test_ignoresNonexistantFilecCs@|j�d���tj|jdd�d�}|�|jt|�	d���dS)z�
        L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys} returns only
        the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2}
        if they are readable.
        r�cSrrr#rr#r#r$rrzIUNIXAuthorizedKeysFilesTests.test_ignoresUnreadableFile.<locals>.<lambda>r
r�N)
rsrrrqrr$rErAr"r	rrr#r#r$�test_ignoresUnreadableFilesz7UNIXAuthorizedKeysFilesTests.test_ignoresUnreadableFileN)r\r]r^r_rarbr%rrr%r&r'r#r#r#r$r!�s	
	r!�_KeyDBrc@seZdZdZdS)�_DummyExceptionz0
    Fake exception to be used for testing.
    N)r\r]r^r_r#r#r#r$r)!sr)c@sLeZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�SSHPublicKeyCheckerTestsz4
    Tests for L{checkers.SSHPublicKeyChecker}.
    cCsDtddtjdtj�tj��d��|_t	dd��|_
t�|j
�|_
dS)Nr�r�r�cSstj�tj�gSr)rr�r�rr�)�_r#r#r$r8sz0SSHPublicKeyCheckerTests.setUp.<locals>.<lambda>)r
rr�rr�r�r�r�r�r(rr�SSHPublicKeyCheckerrkr!r#r#r$r%0s�zSSHPublicKeyCheckerTests.setUpcCs"d|j_|�|j�|j�t�dS)z�
        Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with
        credentials that do not have a signature fails with L{ValidPublicKey}.
        N)r��	signature�failureResultOfrkr�rr!r#r#r$� test_credentialsWithoutSignature;s�z9SSHPublicKeyCheckerTests.test_credentialsWithoutSignaturecCs$d|j_|�|j�|j�tj�dS)z�
        Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with
        credentials that have a bad key fails with L{keys.BadKeyError}.
        r�N)r�r~r.rkr�rr�r!r#r#r$�test_credentialsWithBadKeyEs�z3SSHPublicKeyCheckerTests.test_credentialsWithBadKeycCs$tj|j_|�|j�|j�t�dS)z�
        If L{checkers.IAuthorizedKeysDB.getAuthorizedKeys} returns no keys
        that match the credentials,
        L{checkers.SSHPublicKeyChecker.requestAvatarId} fails with
        L{UnauthorizedLogin}.
        N)r�publicDSA_opensshr�r~r.rkr�rr!r#r#r$�test_credentialsNoMatchingKeyOs
�z6SSHPublicKeyCheckerTests.test_credentialsNoMatchingKeycCs2tj�tj��d�|j_|�|j	�
|j�t�dS)z�
        Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with
        credentials that are incorrectly signed fails with
        L{UnauthorizedLogin}.
        r�N)rr�r�rr�r�r�r-r.rkr�rr!r#r#r$� test_credentialsInvalidSignature[s���z9SSHPublicKeyCheckerTests.test_credentialsInvalidSignaturecCs<dd�}|�tjd|�|�|j�|j�t�|�t	�dS)z�
        If L{keys.Key.verify} raises an exception,
        L{checkers.SSHPublicKeyChecker.requestAvatarId} fails with
        L{UnauthorizedLogin}.
        c_st��r)r))�args�kwargsr#r#r$�failosz?SSHPublicKeyCheckerTests.test_failureVerifyingKey.<locals>.fail�verifyN)
r@rr�r.rkr�r�rr�r))r"r6r#r#r$�test_failureVerifyingKeyhs�z1SSHPublicKeyCheckerTests.test_failureVerifyingKeycCs$|j�|j�}|�d|�|��dS)zu
        L{checker.SSHPublicKeyChecker.requestAvatarId}, if successful,
        callbacks with the username.
        r�N)rkr�r�rA�successResultOfr�r#r#r$�test_usernameReturnedOnSuccessysz7SSHPublicKeyCheckerTests.test_usernameReturnedOnSuccessN)
r\r]r^r_rarbr%r/r0r2r3r8r:r#r#r#r$r*)s


r*)=r_r*�ImportErrorr`rS�base64r�collectionsr�ior�zope.interface.verifyr�twisted.cred.checkersr�twisted.cred.credentialsrr	r
r�twisted.cred.errorrr
�twisted.pythonr�twisted.python.failurer�twisted.python.fakepwdrr�twisted.python.filepathr�twisted.python.reflectr�twisted.test.test_processr�twisted.trial.unittestrra�
twisted.conchr�twisted.conch.errorrr�twisted.conch.sshr�twisted.conch.testr�getattrr�rrcr�r�rrr!r(�	Exceptionr)r*r#r#r#r$�<module>sX�eJX=4"P

Anon7 - 2022
AnonSec Team