Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/conch/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�b�K�@sFdZddlZddlZddlZddlmZddlmZmZm	Z	zddl
ZWney/dZ
YnweZ
zddl
ZWneyCdZ
YnweZ
ddlmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/e$�Z0dd�Z1dd�Z2ee�Gdd�d��Z3ee�Gdd�d��Z4ee�Gdd�d��Z5e+edddd�de6d�Gd d!�d!e�Z7ej8j9fd"ed#ee:gej8fd$e	ej8fd%d&�Z;d'd(�Z<ee7�Gd)d*�d*��Z=ee7�Gd+d,�d,��Z>ee�Gd-d.�d.��Z?dS)/zO
Provide L{ICredentialsChecker} implementations to be used in Conch protocols.
�N)�decodebytes)�BinaryIO�Callable�Iterator)�	Interface�implementer�
providedBy)�Version��error)�keys)�ICredentialsChecker)�ISSHPrivateKey�IUsernamePassword)�UnauthorizedLogin�UnhandledCredentials)�defer)�Logger)�verifyCryptedPassword)�failure�reflect)�deprecatedModuleAttribute)�FilePath)�runAsEffectiveUsercCstdurdSt�|�S)a
    Look up a user in the /etc/passwd database using the pwd module.  If the
    pwd module is not available, return None.

    @param username: the username of the user to return the passwd database
        information for.
    @type username: L{str}
    N)�pwd�getpwnam)�username�r�8/usr/lib/python3/dist-packages/twisted/conch/checkers.py�
_pwdGetByName2s	
rcCs"tdurtj}ndStdd||�S)z�
    Look up a user in the /etc/shadow database using the spwd module. If it is
    not available, return L{None}.

    @param username: the username of the user to return the shadow database
        information for.
    @type username: L{str}
    Nr)�spwd�getspnamr)r�frrr�_shadowGetByName@s	r#c@s(eZdZdZefZddd�Zdd�ZdS)�UNIXPasswordDatabaseab
    A checker which validates users out of the UNIX password databases, or
    databases of a compatible format.

    @ivar _getByNameFunctions: a C{list} of functions which are called in order
        to valid a user.  The default value is such that the C{/etc/passwd}
        database will be tried first, followed by the C{/etc/shadow} database.
    NcCs|durttg}||_dS�N)rr#�_getByNameFunctions)�self�getByNameFunctionsrrr�__init__]s
zUNIXPasswordDatabase.__init__c	Cs�|j�t���}|j�t���}|jD]5}z||�}Wnty-t�t	d��YSw|durH|d}|dkr;qt
||�rHt�|j�Sqt�t	d��S)Nzinvalid username��zunable to verify password)r�decode�sys�getfilesystemencoding�passwordr&�KeyErrorr�failrr�succeed)r'�credentialsrr/�func�pwnam�cryptedrrr�requestAvatarIdbs 
�
�z$UNIXPasswordDatabase.requestAvatarIdr%)�__name__�
__module__�__qualname__�__doc__r�credentialInterfacesr)r7rrrrr$Ps
	
r$c@sBeZdZdZefZeZdd�Zdd�Z	dd�Z
dd	�Zd
d�ZdS)
�SSHPublicKeyDatabasez�
    Checker that authenticates SSH public keys, based on public keys listed in
    authorized_keys and authorized_keys2 files in user .ssh/ directories.
    cCs,t�|j|�}|�|j|�|�|j�|Sr%)r�
maybeDeferred�checkKey�addCallback�_cbRequestAvatarId�
addErrback�_ebRequestAvatarId�r'r3�drrrr7�sz$SSHPublicKeyDatabase.requestAvatarIdcCs�|s	t�td��S|jst�t���Sztj�|j	�}|�
|j|j�r'|jWSWnt
y=t�d�t�td��YSwt�td��S)aC
        Check whether the credentials themselves are valid, now that we know
        if the key matches the user.

        @param validKey: A boolean indicating whether or not the public key
            matches a key in the user's authorized_keys file.

        @param credentials: The credentials offered by the user.
        @type credentials: L{ISSHPrivateKey} provider

        @raise UnauthorizedLogin: (as a failure) if the key does not match the
            user in C{credentials}. Also raised if the user provides an invalid
            signature.

        @raise ValidPublicKey: (as a failure) if the key matches the user but
            the credentials do not include a signature. See
            L{error.ValidPublicKey} for more information.

        @return: The user's username, if authentication was successful.
        zinvalid key�Error while verifying keyzerror while verifying keyzunable to verify key)r�Failurer�	signaturer�ValidPublicKeyr�Key�
fromString�blob�verify�sigDatar�	Exception�_log)r'�validKeyr3�pubKeyrrrrA�s�
�z'SSHPublicKeyDatabase._cbRequestAvatarIdcs8|j�|j�}t|j��d��ddg}�fdd�|D�S)a�
        Return a list of L{FilePath} instances for I{authorized_keys} files
        which might contain information about authorized keys for the given
        credentials.

        On OpenSSH servers, the default location of the file containing the
        list of authorized public keys is
        U{$HOME/.ssh/authorized_keys<http://www.openbsd.org/cgi-bin/man.cgi?query=sshd_config>}.

        I{$HOME/.ssh/authorized_keys2} is also returned, though it has been
        U{deprecated by OpenSSH since
        2001<http://marc.info/?m=100508718416162>}.

        @return: A list of L{FilePath} instances to files with the authorized keys.
        �.ssh�authorized_keys�authorized_keys2csg|]}��|��qSr��child��.0r"��rootrr�
<listcomp>�sz?SSHPublicKeyDatabase.getAuthorizedKeysFiles.<locals>.<listcomp>)�_userdbrrr�pw_dirrW)r'r3�pwent�filesrrZr�getAuthorizedKeysFiles�sz+SSHPublicKeyDatabase.getAuthorizedKeysFilesc	Cs|j�|j�dd�\}}|�|�D]q}|��sqz|��}Wn!ty@}z|jtjkr5t	|||j�}n�WYd}~nd}~ww|�8|D]-}|�
�}t|�dkrSqFzt|d�|j
krhWWd�dSWqFtjysYqFwWd�n1s~wYqdS)zg
        Retrieve files containing authorized keys and check against user
        credentials.
        ��Nr*TF)r]rrra�exists�open�OSError�errno�EACCESr�split�lenrrL�binascii�Error)	r'r3�ouid�ogid�filepath�lines�e�l�l2rrrr?�s<��������
zSSHPublicKeyDatabase.checkKeycCs,|�t�stjd|jd�t�td��S|S)Nz1Unauthorized login due to internal error: {error}r
zunable to get avatar id)�checkrrPr�valuerrG)r'r"rrrrC�s
�z'SSHPublicKeyDatabase._ebRequestAvatarIdN)
r8r9r:r;rr<rr]r7rArar?rCrrrrr=ys#r=c@sDeZdZdZdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�SSHProtocolCheckera�
    SSHProtocolChecker is a checker that requires multiple authentications
    to succeed.  To add a checker, call my registerChecker method with
    the checker and the interface.

    After each successful authenticate, I call my areDone method with the
    avatar id.  To get a list of the successful credentials for an avatar id,
    use C{SSHProcotolChecker.successfulCredentials[avatarId]}.  If L{areDone}
    returns True, the authentication has succeeded.
    cCsi|_i|_dSr%)�checkers�successfulCredentials�r'rrrr)�s
zSSHProtocolChecker.__init__cCst|j���Sr%)�listrwrryrrrr<�sz'SSHProtocolChecker.credentialInterfacescGs"|s|j}|D]}||j|<qdSr%)r<rw)r'�checkerr<�credentialInterfacerrr�registerChecker�s
�z"SSHProtocolChecker.registerCheckerc	Csft|�}|D]}|j�|�}|dur"t�|j|�}|�|j|�Sqt�t	dd�
ttj
|����S)a�
        Part of the L{ICredentialsChecker} interface.  Called by a portal with
        some credentials to check if they'll authenticate a user.  We check the
        interfaces that the credentials provide against our list of acceptable
        checkers.  If one of them matches, we ask that checker to verify the
        credentials.  If they're valid, we call our L{_cbGoodAuthentication}
        method to continue.

        @param credentials: the credentials the L{Portal} wants us to verify
        NzNo checker for %sz, )rrw�getrr>r7r@�_cbGoodAuthenticationr1r�join�mapr�qual)r'r3�ifac�i�crErrrr7s���z"SSHProtocolChecker.requestAvatarIdcCsB||jvr
g|j|<|j|�|�|�|�r|j|=|St���)a
        Called if a checker has verified the credentials.  We call our
        L{areDone} method to see if the whole of the successful authentications
        are enough.  If they are, we return the avatar ID returned by the first
        checker.
        )rx�append�areDoner�NotEnoughAuthentication)r'�avatarIdr3rrrrs


z(SSHProtocolChecker._cbGoodAuthenticationcC�dS)a
        Override to determine if the authentication is finished for a given
        avatarId.

        @param avatarId: the avatar returned by the first checker.  For
            this checker to function correctly, all the checkers must
            return the same avatar ID.
        Tr)r'r�rrrr�)s	zSSHProtocolChecker.areDoneN)r8r9r:r;r)�propertyr<r}r7rr�rrrrrv�s
rv�Twisted�z�Please use twisted.conch.checkers.SSHPublicKeyChecker, initialized with an instance of twisted.conch.checkers.UNIXAuthorizedKeysFiles instead.c@seZdZdZdd�ZdS)�IAuthorizedKeysDBzb
    An object that provides valid authorized ssh keys mapped to usernames.

    @since: 15.0
    cCr�)aL
        Gets an iterable of authorized keys that are valid for the given
        C{avatarId}.

        @param avatarId: the ID of the avatar
        @type avatarId: valid return value of
            L{twisted.cred.checkers.ICredentialsChecker.requestAvatarId}

        @return: an iterable of L{twisted.conch.ssh.keys.Key}
        Nr)r�rrr�getAuthorizedKeysHsz#IAuthorizedKeysDB.getAuthorizedKeysN)r8r9r:r;r�rrrrr�Asr��fileobj�parseKey�returnccsl�|D]0}|��}|r3|�d�s3z||�VWqtjy2}ztjd||d�WYd}~qd}~wwqdS)a
    Reads keys from an authorized keys file.  Any non-comment line that cannot
    be parsed as a key will be ignored, although that particular line will
    be logged.

    @param fileobj: something from which to read lines which can be parsed
        as keys
    @param parseKey: a callable that takes bytes and returns a
        L{twisted.conch.ssh.keys.Key}, mainly to be used for testing.  The
        default is L{twisted.conch.ssh.keys.Key.fromString}.
    @return: an iterable of L{twisted.conch.ssh.keys.Key}
    @since: 15.0
    �#z1Unable to parse line {line!r} as a key: {error!s})�linerN)�strip�
startswithr�BadKeyErrorrPr)r�r�r�rqrrr�readAuthorizedKeyFileUs ������r�ccs��|D]@}|��rCz|���}t||�EdHWd�n1s!wYWqtyB}ztjd|j|d�WYd}~qd}~wwqdS)a�
    Helper function that turns an iterable of filepaths into a generator of
    keys.  If any file cannot be read, a message is logged but it is
    otherwise ignored.

    @param filepaths: iterable of L{twisted.python.filepath.FilePath}.
    @type filepaths: iterable

    @param parseKey: a callable that takes a string and returns a
        L{twisted.conch.ssh.keys.Key}
    @type parseKey: L{callable}

    @return: generator of L{twisted.conch.ssh.keys.Key}
    @rtype: generator

    @since: 15.0
    Nz"Unable to read {path!r}: {error!s})�pathr)rdrer�rfrPrr�)�	filepathsr��fpr"rqrrr�_keysFromFilepathsrs�
������r�c@s eZdZdZdd�Zdd�ZdS)�InMemorySSHKeyDBz�
    Object that provides SSH public keys based on a dictionary of usernames
    mapped to L{twisted.conch.ssh.keys.Key}s.

    @since: 15.0
    cC�
||_dS)z�
        Initializes a new L{InMemorySSHKeyDB}.

        @param mapping: mapping of usernames to iterables of
            L{twisted.conch.ssh.keys.Key}s
        @type mapping: L{dict}

        N)�_mapping)r'�mappingrrrr)�s
	zInMemorySSHKeyDB.__init__cCs|j�|g�Sr%)r�r~)r'rrrrr��sz"InMemorySSHKeyDB.getAuthorizedKeysN)r8r9r:r;r)r�rrrrr��sr�c@s*eZdZdZdejjfdd�Zdd�ZdS)�UNIXAuthorizedKeysFilesa
    Object that provides SSH public keys based on public keys listed in
    authorized_keys and authorized_keys2 files in UNIX user .ssh/ directories.
    If any of the files cannot be read, a message is logged but that file is
    otherwise ignored.

    @since: 15.0
    NcCs"||_||_|durt|_dSdS)a�
        Initializes a new L{UNIXAuthorizedKeysFiles}.

        @param userdb: access to the Unix user account and password database
            (default is the Python module L{pwd})
        @type userdb: L{pwd}-like object

        @param parseKey: a callable that takes a string and returns a
            L{twisted.conch.ssh.keys.Key}, mainly to be used for testing.  The
            default is L{twisted.conch.ssh.keys.Key.fromString}.
        @type parseKey: L{callable}
        N)r]�	_parseKeyr)r'�userdbr�rrrr)�s


�z UNIXAuthorizedKeysFiles.__init__csXz|j�|�}Wn
tyYdSwt|j��d��ddg}t�fdd�|D�|j�S)NrrSrTrUc3s�|]}��|�VqdSr%rVrXrZrr�	<genexpr>�s�z<UNIXAuthorizedKeysFiles.getAuthorizedKeys.<locals>.<genexpr>)r]rr0rr^rWr�r�)r'r�passwdr`rrZrr��s�z)UNIXAuthorizedKeysFiles.getAuthorizedKeys)	r8r9r:r;rrJrKr)r�rrrrr��s	r�c@s>eZdZdZefZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dS)
�SSHPublicKeyCheckera?
    Checker that authenticates SSH public keys, based on public keys listed in
    authorized_keys and authorized_keys2 files in user .ssh/ directories.

    Initializing this checker with a L{UNIXAuthorizedKeysFiles} should be
    used instead of L{twisted.conch.checkers.SSHPublicKeyDatabase}.

    @since: 15.0
    cCr�)z�
        Initializes a L{SSHPublicKeyChecker}.

        @param keydb: a provider of L{IAuthorizedKeysDB}
        @type keydb: L{IAuthorizedKeysDB} provider
        N)�_keydb)r'�keydbrrrr)�s
zSSHPublicKeyChecker.__init__cCs.t�|j|�}|�|j|�|�|j|�|Sr%)rr>�_sanityCheckKeyr@�	_checkKey�
_verifyKeyrDrrrr7�sz#SSHPublicKeyChecker.requestAvatarIdcCs|jst���tj�|j�S)aW
        Checks whether the provided credentials are a valid SSH key with a
        signature (does not actually verify the signature).

        @param credentials: the credentials offered by the user
        @type credentials: L{ISSHPrivateKey} provider

        @raise ValidPublicKey: the credentials do not include a signature. See
            L{error.ValidPublicKey} for more information.

        @raise BadKeyError: The key included with the credentials is not
            recognized as a key.

        @return: the key in the credentials
        @rtype: L{twisted.conch.ssh.keys.Key}
        )rHrrIrrJrKrL)r'r3rrrr��sz#SSHPublicKeyChecker._sanityCheckKeycs,t�fdd�|j�|j�D��r�Std��)ab
        Checks the public key against all authorized keys (if any) for the
        user.

        @param pubKey: the key in the credentials (just to prevent it from
            having to be calculated again)
        @type pubKey:

        @param credentials: the credentials offered by the user
        @type credentials: L{ISSHPrivateKey} provider

        @raise UnauthorizedLogin: If the key is not authorized, or if there
            was any error obtaining a list of authorized keys for the user.

        @return: C{pubKey} if the key is authorized
        @rtype: L{twisted.conch.ssh.keys.Key}
        c3s�|]}|�kVqdSr%r)rY�key�rRrrr�s�
�z0SSHPublicKeyChecker._checkKey.<locals>.<genexpr>zKey not authorized)�anyr�r�rr)r'rRr3rr�rr�s
�zSSHPublicKeyChecker._checkKeyc
CsFz|�|j|j�r
|jWSWtd��ty"}ztd�|�d}~ww)a~
        Checks whether the credentials themselves are valid, now that we know
        if the key matches the user.

        @param pubKey: the key in the credentials (just to prevent it from
            having to be calculated again)
        @type pubKey: L{twisted.conch.ssh.keys.Key}

        @param credentials: the credentials offered by the user
        @type credentials: L{ISSHPrivateKey} provider

        @raise UnauthorizedLogin: If the key signature is invalid or there
            was any error verifying the signature.

        @return: The user's username, if authentication was successful
        @rtype: L{bytes}
        rFNzKey signature invalid.)rMrHrNrrOr)r'rRr3rqrrrr�s��
��zSSHPublicKeyChecker._verifyKeyN)r8r9r:r;rr<r)r7r�r�r�rrrrr��s
	r�)@r;rkrgr-�base64r�typingrrrr�_pwd�ImportErrorr �_spwd�zope.interfacerrr�incrementalr	�
twisted.conchr�twisted.conch.sshr�twisted.cred.checkersr
�twisted.cred.credentialsrr�twisted.cred.errorrr�twisted.internetr�twisted.loggerr�twisted.plugins.cred_unixr�twisted.pythonrr�twisted.python.deprecater�twisted.python.filepathr�twisted.python.utilrrPrr#r$r=rvr8r�rJrK�bytesr�r�r�r�r�rrrr�<module>s~��(mM����
�'

Spamworldpro Mini