%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/cred/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/cred/__pycache__/credentials.cpython-312.pyc

�

Ϫ�f�@��B�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZmZmZddlmZmZdd	lmZdd
lmZddlmZGd�d
e�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Z eee�Gd�d��Z!Gd�d�Z"ee�Gd�d��Z#ee�Gd�d��Z$ee�Gd�d��Z%ee �Gd �d!��Z&Gd"�d#e�Z'ee'�Gd$�d%��Z(y)&z�
This module defines L{ICredentials}, an interface for objects that represent
authentication credentials to provide, and also includes a number of useful
implementations of that interface.
�N)�hexlify)�md5)�	Interface�implementer)�error)�calcHA1�calcHA2�calcResponse)�nativeString�
networkString)�deprecatedModuleAttribute)�secureRandom)�Versionc��eZdZdZy)�ICredentialsz�
    I check credentials.

    Implementors I{must} specify the sub-interfaces of ICredentials
    to which it conforms, using L{zope.interface.implementer}.
    N��__name__�
__module__�__qualname__�__doc__���:/usr/lib/python3/dist-packages/twisted/cred/credentials.pyrrs��rrc��eZdZdZd�Zy)�IUsernameDigestHashz�
    This credential is used when a CredentialChecker has access to the hash
    of the username:realm:password as in an Apache .htdigest file.
    c��y)a-
        @param digestHash: The hashed username:realm:password to check against.

        @return: C{True} if the credentials represented by this object match
            the given hash, C{False} if they do not, or a L{Deferred} which
            will be called back with one of these values.
        Nr)�
digestHashs r�	checkHashzIUsernameDigestHash.checkHash-��rN)rrrrrrrrrr's���
rrc��eZdZdZd�Zy)�IUsernameHashedPassworda�
    I encapsulate a username and a hashed password.

    This credential is used when a hashed password is received from the
    party requesting authentication.  CredentialCheckers which check this
    kind of credential must store the passwords in plaintext (or as
    password-equivalent hashes) form so that they can be hashed in a manner
    appropriate for the particular credentials class.

    @type username: L{bytes}
    @ivar username: The username associated with these credentials.
    c��y�a�
        Validate these credentials against the correct password.

        @type password: L{bytes}
        @param password: The correct, plaintext password against which to
        check.

        @rtype: C{bool} or L{Deferred}
        @return: C{True} if the credentials represented by this object match the
            given password, C{False} if they do not, or a L{Deferred} which will
            be called back with one of these values.
        Nr��passwords r�
checkPasswordz%IUsernameHashedPassword.checkPasswordErrN)rrrrr&rrrr!r!7s���rr!c�6�eZdZUdZeed<eed<dedefd�Zy)�IUsernamePasswordaK
    I encapsulate a username and a plaintext password.

    This encapsulates the case where the password received over the network
    has been hashed with the identity function (That is, not at all).  The
    CredentialsChecker may store the password in whatever format it desires,
    it need only transform the stored password in a similar way before
    performing the comparison.

    @type username: L{bytes}
    @ivar username: The username associated with these credentials.

    @type password: L{bytes}
    @ivar password: The password associated with these credentials.
    �usernamer%�returnc��yr#rr$s rr&zIUsernamePassword.checkPasswordhrrN)rrrr�bytes�__annotations__�boolr&rrrr(r(Ts&��� �O��O����$�rr(c��eZdZdZy)�
IAnonymouszs
    I am an explicitly anonymous request for access.

    @see: L{twisted.cred.checkers.AllowAnonymousAccess}
    Nrrrrr0r0ws��rr0c�"�eZdZdZd�Zd�Zd�Zy)�DigestedCredentialsz?
    Yet Another Simple HTTP Digest authentication scheme.
    c�<�||_||_||_||_y�N)r)�method�realm�fields)�selfr)r5r6r7s     r�__init__zDigestedCredentials.__init__�s�� ��
������
���rc
�:�|jjd�}|jjd�}|jjd�}|jjd�}|jjd�}|jjdd�j�}|jjdd	�}tt	||j
|j|||�t||j||d
�|||||�}	|	|k(S)a
        Verify that the credentials represented by this object agree with the
        given plaintext C{password} by hashing C{password} in the same way the
        response hash represented by this object was generated and comparing
        the results.
        �response�uri�nonce�cnonce�nc�	algorithm�md5�qop�authN)	r7�get�lowerr
rr)r6r	r5)
r8r%r;r<r=r>r?�algorB�expecteds
          rr&z!DigestedCredentials.checkPassword�s����;�;�?�?�:�.���k�k�o�o�e�$��������(��������*��
�[�[�_�_�T�
"���{�{���{�F�3�9�9�;���k�k�o�o�e�W�-����D�$�-�-����X�u�f�M��D�$�+�+�s�C��6������
���8�#�#rc��|jjd�}|jjd�}|jjd�}|jjd�}|jjd�}|jjdd�j�}|jjdd	�}tt	|d
d
d
|||��t||j||d
�|||||�}	|	|k(S)a4
        Verify that the credentials represented by this object agree with the
        credentials represented by the I{H(A1)} given in C{digestHash}.

        @param digestHash: A precomputed H(A1) value based on the username,
            realm, and password associate with this credentials object.
        r;r<r=r>r?r@rArBrCN)�preHA1)r7rDrEr
rr	r5)
r8rr;r<r=r>r?rFrBrGs
          rrzDigestedCredentials.checkHash�s����;�;�?�?�:�.���k�k�o�o�e�$��������(��������*��
�[�[�_�_�T�
"���{�{���{�F�3�9�9�;���k�k�o�o�e�W�-����D�$��d�E�6�*�M��D�$�+�+�s�C��6������
���8�#�#rN)rrrrr9r&rrrrr2r2s����$�6$rr2c�f�eZdZdZej
d�ZdZdZd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zy)
�DigestCredentialFactoryar
    Support for RFC2617 HTTP Digest Authentication

    @cvar CHALLENGE_LIFETIME_SECS: The number of seconds for which an
        opaque should be valid.

    @type privateKey: L{bytes}
    @ivar privateKey: A random string used for generating the secure opaque.

    @type algorithm: L{bytes}
    @param algorithm: Case insensitive string specifying the hash algorithm to
        use.  Must be either C{'md5'} or C{'sha'}.  C{'md5-sess'} is B{not}
        supported.

    @type authenticationRealm: L{bytes}
    @param authenticationRealm: case sensitive string that specifies the realm
        portion of the challenge
    s ([^= ]+)=(?:"([^"]*)"|([^,]+)),?i�sdigestc�@�||_||_td�|_y)N�)r@�authenticationRealmr�
privateKey)r8r@rNs   rr9z DigestCredentialFactory.__init__�s��"���#6�� �&�r�*��rc�~�|j�}|j||�}||d|j|jd�S)a
        Generate the challenge for use in the WWW-Authenticate header.

        @param address: The client address to which this challenge is being
            sent.

        @return: The L{dict} that can be used to generate a WWW-Authenticate
            header.
        rC)r=�opaquerBr@r6)�_generateNonce�_generateOpaquer@rN)r8�address�c�os    r�getChallengez$DigestCredentialFactory.getChallenge�sI��
���!��� � ��G�,���������-�-�
�	
rc�*�ttd��S)z�
        Create a random value suitable for use as the nonce parameter of a
        WWW-Authenticate challenge.

        @rtype: L{bytes}
        rM)rr�r8s rrRz&DigestCredentialFactory._generateNonces���|�B�'�(�(rc�*�tj�S)z�
        Parameterize the time based seed used in C{_generateOpaque}
        so we can deterministically unittest it's behavior.
        )�timerYs r�_getTimez DigestCredentialFactory._getTime	s��
�y�y�{�rc�~�dt|j��fz}|sd}n!t|t�r|j	d�}dj|||f�}t
t||jz�j��}tj|�}dj||jdd�f�S)z�
        Generate an opaque to be returned to the client.  This is a unique
        string that can be returned to us and verified.
        s%dr�ascii�,�-�
)
�intr\�
isinstance�str�encode�joinrrrO�digest�base64�	b64encode�replace)r8r=�clientip�now�keyrg�ekeys       rrSz'DigestCredentialFactory._generateOpaques����s�4�=�=�?�+�-�-����H�
��#�
&����w�/�H��i�i���#�.�/����S�4�?�?�2�3�:�:�<�=������$���y�y�&�$�,�,�u�c�":�;�<�<rc�B�|jd�}t|�dk7rtjd��|sd}n!t	|t
�r|j
d�}tj|d�}|jd�}t|�dk7rtjd��|d	|k7rtjd
��|d|k7rtjd��	t|d�}t|j��|z
tjkDrtjd
��tt||j z�j#��}||d	k7rtjd��y#t$rtjd��wxYw)a�
        Given the opaque and nonce from the request, as well as the client IP
        that made the request, verify that the opaque was generated by us.
        And that it's not too old.

        @param opaque: The opaque value from the Digest response
        @param nonce: The nonce value from the Digest response
        @param clientip: The remote IP address of the client making the request
            or L{None} if the request was submitted over a channel where this
            does not make sense.

        @return: C{True} if the opaque was successfully verified.

        @raise error.LoginFailed: if C{opaque} could not be parsed or
            contained the wrong values.
        r`�z&Invalid response, invalid opaque valuerr^�r_�rz2Invalid response, incompatible opaque/nonce valuesz3Invalid response, incompatible opaque/client valuesz,Invalid response, invalid opaque/time valuesz3Invalid response, incompatible opaque/nonce too oldT)�split�lenr�LoginFailedrcrdrerh�	b64decoderb�
ValueErrorr\rK�CHALLENGE_LIFETIME_SECSrrrOrg)	r8rQr=rk�opaquePartsrm�keyParts�whenrgs	         r�
_verifyOpaquez%DigestCredentialFactory._verifyOpaque#s���$�l�l�4�(���{��q� ��#�#�$L�M�M���H�
��#�
&����w�/�H����{�1�~�.���9�9�T�?���x�=�A���#�#�$L�M�M��A�;�%���#�#�D��
��A�;�(�"��#�#�E��
�	T��x��{�#�D�

��
�
�� �4�'�%�=�=�
>��#�#�E��
�
��S�4�?�?�2�3�:�:�<�=���[��^�#��#�#�$L�M�M���!�	T��#�#�$R�S�S�	T�s�"E?�?Fc�8�dj|j��}|jj|�}i}|D]6\}}}|xs|j	�}	|	|t|j	��<�8|j
d�}
|
stjd��d|vrtjd��d|vrtjd��|j|j
d�|j
d�|�rt|
||j|�Sy)	a�
        Decode the given response and attempt to generate a
        L{DigestedCredentials} from it.

        @type response: L{bytes}
        @param response: A string of comma separated key=value pairs

        @type method: L{bytes}
        @param method: The action requested to which this response is addressed
            (GET, POST, INVITE, OPTIONS, etc).

        @type host: L{bytes}
        @param host: The address the request was sent from.

        @raise error.LoginFailed: If the response does not contain a username,
            a nonce, an opaque, or if the opaque is invalid.

        @return: L{DigestedCredentials}
        � r)z$Invalid response, no username given.rQz"Invalid response, no opaque given.r=z!Invalid response, no nonce given.N)rf�
splitlines�_parseparts�findall�striprrDrrur|r2rN)r8r;r5�host�parts�authrm�bare�quoted�valuer)s           r�decodezDigestCredentialFactory.decodecs��(�9�9�X�0�0�2�3��� � �(�(��2����!&�	4��C��v��^�t�*�*�,�E�.3�D��c�i�i�k�*�+�	4��8�8�J�'����#�#�$J�K�K��4���#�#�$H�I�I��$���#�#�$G�H�H����d�h�h�x�0�$�(�(�7�2C�T�J�&�x���9Q�9Q�SW�X�X�KrN)rrrr�re�compiler�rx�schemer9rWrRr\rSr|r�rrrrKrK�sP���&�"�*�*�	�	�K�&��
�F�+�

�*)��=�&>�@'YrrKc�<�eZdZdZdZdZdZd	d�Zd�Zd�Z	d�Z
d�Zy)
�CramMD5Credentialsas
    An encapsulation of some CramMD5 hashed credentials.

    @ivar challenge: The challenge to be sent to the client.
    @type challenge: L{bytes}

    @ivar response: The hashed response from the client.
    @type response: L{bytes}

    @ivar username: The username from the response from the client.
    @type username: L{bytes} or L{None} if not yet provided.
    Nrc��||_yr4)r�)r8r�s  rr9zCramMD5Credentials.__init__�s	����	rc�
�|jr|jStjd�}tj�}t	d|||j
rt
|j
�ndfz�|_|jS)Ni���z
<%d.%d@%s>)�	challenge�random�	randranger[rr�r)r8�r�ts   rrWzCramMD5Credentials.getChallenge�sh���>�>��>�>�!�
���Z�(���I�I�K��&��A�q�T�Y�Y�,�t�y�y�"9�D�Q�Q�
����~�~�rc�B�|jdd�\|_|_y)Nrq)rsr)r;)r8r;s  r�setResponsezCramMD5Credentials.setResponse�s��'/�~�~�d�A�'>�$��
�t�}rc��y)NFrrYs r�moreChallengesz!CramMD5Credentials.moreChallenges�s��rc��ttj||jt��j��}||jk(S)N)�	digestmod)r�hmac�HMACr�rrgr;)r8r%�verifys   rr&z CramMD5Credentials.checkPassword�s5������8�T�^�^�s�K�R�R�T�U������&�&rr4)rrrrr)r�r;r9rWr�r�r&rrrr�r��s1����H��I��H��� ?��'rr�c�@�eZdZeedddd�ddd�d�Zd�Zy	)
�UsernameHashedPassword�Twisted�rprz6Use twisted.cred.credentials.UsernamePassword instead.ztwisted.cred.credentialsc� �||_||_yr4)r)�hashed)r8r)r�s   rr9zUsernameHashedPassword.__init__�s�� ��
���rc� �|j|k(Sr4)r��r8r%s  rr&z$UsernameHashedPassword.checkPassword�s���{�{�h�&�&rN)rrrr
rr9r&rrrr�r��s+����	�2�q�!�$�@�"� �	��'rr�c�0�eZdZdededdfd�Zdedefd�Zy)�UsernamePasswordr)r%r*Nc� �||_||_yr4)r)r%)r8r)r%s   rr9zUsernamePassword.__init__�s�� ��
� ��
rc� �|j|k(Sr4r$r�s  rr&zUsernamePassword.checkPassword�s���}�}��(�(r)rrrr,r9r.r&rrrr�r��s/��!��!�%�!�D�!�)�e�)��)rr�c��eZdZy)�	AnonymousN)rrrrrrr�r��s��rr�c��eZdZdZy)�ISSHPrivateKeyaj
    L{ISSHPrivateKey} credentials encapsulate an SSH public key to be checked
    against a user's private key.

    @ivar username: The username associated with these credentials.
    @type username: L{bytes}

    @ivar algName: The algorithm name for the blob.
    @type algName: L{bytes}

    @ivar blob: The public key blob as sent by the client.
    @type blob: L{bytes}

    @ivar sigData: The data the signature was made from.
    @type sigData: L{bytes}

    @ivar signature: The signed data.  This is checked to verify that the user
        owns the private key.
    @type signature: L{bytes} or L{None}
    Nrrrrr�r��s��rr�c��eZdZd�Zy)�
SSHPrivateKeyc�J�||_||_||_||_||_yr4)r)�algName�blob�sigData�	signature)r8r)r�r�r�r�s      rr9zSSHPrivateKey.__init__�s%�� ��
������	����"��rN)rrrr9rrrr�r��s��#rr�))rrhr�r�r�r[�binasciir�hashlibr�zope.interfacerr�twisted.credr�twisted.cred._digestrr	r
�twisted.python.compatrr�twisted.python.deprecater
�twisted.python.randbytesr�twisted.python.versionsrrrr!r(r0r2rKr�r�r�r�r�r�rrr�<module>r�sQ��
���
�	����1��?�?�=�>�1�+��9��
�,�
� �l��: �� �F���
�
$�&9�:�@$�@$�;�@$�FGY�GY�T
�
$�%�-'�-'�&�-'�`
�
$�%�
'�
'�&�
'� 
�
��)�)� �)�
�Z��	�	��	��\��.
�^��#�#��#r

Zerion Mini Shell 1.0