PHP WebShell

Текущая директория: /usr/lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__

Просмотр файла: sasl_mechanisms.cpython-310.pyc

o

�b"�@s�dZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZGdd�de	�Z
e
e
�Gdd	�d	��Ze
e
�Gd
d�d��Ze
e
�Gdd
�d
��ZdS)zF
Protocol agnostic implementations of SASL authentication mechanisms.
�N)�md5)�	Attribute�	Interface�implementer)�
networkStringc@s$eZdZed�Zdd�Zdd�ZdS)�ISASLMechanismz#Common name for the SASL Mechanism.cC�dS)z�
        Get the initial client response, if defined for this mechanism.

        @return: initial client response string.
        @rtype: C{str}.
        N�r	r	r	�P/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/sasl_mechanisms.py�getInitialResponse�z!ISASLMechanism.getInitialResponsecCr)z�
        Get the response to a server challenge.

        @param challenge: server challenge.
        @type challenge: C{str}.
        @return: client response.
        @rtype: C{str}.
        Nr	)�	challenger	r	r
�getResponse!rzISASLMechanism.getResponseN)�__name__�
__module__�__qualname__r�namerrr	r	r	r
rsrc@s$eZdZdZdZdd�Zdd�ZdS)�	Anonymouszm
    Implements the ANONYMOUS SASL authentication mechanism.

    This mechanism is defined in RFC 2245.
    �	ANONYMOUScC�dS�Nr	��selfr	r	r
r6�zAnonymous.getInitialResponsecCrrr	�rr
r	r	r
r9�zAnonymous.getResponseN)rrr�__doc__rrrr	r	r	r
r,s
rc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�Plainz�
    Implements the PLAIN SASL authentication mechanism.

    The PLAIN SASL authentication mechanism is defined in RFC 2595.
    �PLAINcCs"|pd|_|pd|_|p
d|_dS)a

        @param authzid: The authorization identity.
        @type authzid: L{unicode}

        @param authcid: The authentication identity.
        @type authcid: L{unicode}

        @param password: The plain-text password.
        @type password: L{unicode}
        �N)�authzid�authcid�password)rr r!r"r	r	r
�__init__Hs

zPlain.__init__cCs,|j�d�d|j�d�d|j�d�S)Nzutf-8�)r �encoder!r"rr	r	r
rXs
�
��
��zPlain.getInitialResponsecCrrr	rr	r	r
rarzPlain.getResponseN)rrrrrr#rrr	r	r	r
r>s	rc@sTeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�	DigestMD5z�
    Implements the DIGEST-MD5 SASL authentication mechanism.

    The DIGEST-MD5 SASL authentication mechanism is defined in RFC 2831.
    z
DIGEST-MD5cCsF||_||_||_|�d|��|_|dur!|jd|��7_dSdS)a�
        @param serv_type: An indication of what kind of server authentication
            is being attempted against.  For example, C{u"xmpp"}.
        @type serv_type: C{unicode}

        @param host: The authentication hostname.  Also known as the realm.
            This is used as a scope to help select the right credentials.
        @type host: C{unicode}

        @param serv_name: An additional identifier for the server.
        @type serv_name: C{unicode}

        @param username: The authentication username to use to respond to a
            challenge.
        @type username: C{unicode}

        @param password: The authentication password to use to respond to a
            challenge.
        @type password: C{unicode}
        �/N)�usernamer"�defaultRealm�
digest_uri)r�	serv_type�host�	serv_namer(r"r	r	r
r#ps�zDigestMD5.__init__cCrrr	rr	r	r
r�rzDigestMD5.getInitialResponsecCsb|�|�}d|vrdS|d�d�}z|d}Wnty'|j�|�}Ynw|�|||d�S)Nsrspauth��charset�ascii�realm�nonce)�_parse�decode�KeyErrorr)r%�_genResponse)rr
�
directives�charset�realmr	r	r
r�s
�zDigestMD5.getResponsecCs|}i}d}d}|rl|�d|�}|||���}|d7}|||d�dkrE|d7}|�d|�}|||�}	|�d|�d}|dkrDd}n!|�d|�}|dkrZ||d	���}	d}n|||���}	|d}|	||<|s
d
D]}
|
|vr}||
�d�||
<qn|S)z�
        Parses the server challenge.

        Splits the challenge into a dictionary of directives with values.

        @return: challenge directives and their values.
        @rtype: C{dict} of C{str} to C{str}.
        rT�=��"�,F���N)�qop�cipher)�index�lstrip�find�rstrip�split)rr
�s�	paramDict�cur�remainingParams�middler�end�value�paramr	r	r
r3�s:	���zDigestMD5._parsecCsLg}|��D]\}}|dvr|d|}n|d|}|�|�qd�|�S)af
        Create message string from directives.

        @param directives: dictionary of directives (names to their values).
                           For certain directives, extra quotes are added, as
                           needed.
        @type directives: C{dict} of C{str} to C{str}
        @return: message string.
        @rtype: C{str}.
        )�usernamer1�cnoncer2�
digest-urisauthzidr@r:r=)�items�append�join)rr7�directive_listrrL�	directiver	r	r
�_unparse�s	
zDigestMD5._unparsec
s�dd��dd�}�fdd�}	�|d|d|�d|d|}
d|}||	|�|
��|d|d|dd	d|�|����}|S)
z�
        Calculates response with given encoded parameters.

        @return: The I{response} field of a response to a Digest-MD5 challenge
            of the given parameters.
        @rtype: L{bytes}
        cSst|���Sr)r�digest)rFr	r	r
�H�sz'DigestMD5._calculateResponse.<locals>.HcSs
t�|�Sr)�binascii�b2a_hex)�nr	r	r
�HEX�s
z)DigestMD5._calculateResponse.<locals>.HEXcs�|d|�S)N�:r	)�krF�rXr	r
�KD�sz(DigestMD5._calculateResponse.<locals>.KDr]s
AUTHENTICATE:�authr	)
r�cnonce�nc�noncer(r"r9�urir\r`�a1�a2�responser	r_r
�_calculateResponse�s	(
*��zDigestMD5._calculateResponsecCs�z|j�|�}|j�|�}|j�|�}Wnty�wtdd��}|��}d}	|�|||||||�}
||||||	||
|�d�d�	}|�|�S)z�
        Generate response-value.

        Creates a response to a challenge according to section 2.1.2.1 of
        RFC 2831 using the C{charset}, C{realm} and C{nonce} directives
        from the challenge.
        r;�08xrar0)	rNr1r2rOsncr?rPsresponser/)	r(r%r"r*�UnicodeErrorr�
_gen_noncerirV)rr8r9rdr(r"r*rcrb�qoprhr7r	r	r
r6	s0���
zDigestMD5._genResponsecCs4dt��t��t��f}t|�}t|����d�S)Nz%f:%f:%dr0)�random�time�os�getpidrr�	hexdigestr%)r�nonceString�
nonceBytesr	r	r
rl0szDigestMD5._gen_nonceN)
rrrrrr#rrr3rVrir6rlr	r	r	r
r&fs,'r&)rrYrprnro�hashlibr�zope.interfacerrr�twisted.python.compatrrrrr&r	r	r	r
�<module>s'

Выполнить команду


Для локальной разработки. Не используйте в интернете!