403Webshell
Server IP : 15.235.198.142  /  Your IP : 216.73.216.149
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ballsack 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/xmlstream.cpython-312.pyc
�

Ϫ�f����dZddlmZddlmZddlmZddlmZm	Z	ddl
mZmZddl
mZmZddlmZdd	lmZmZmZdd
lmZmZmZddlmZmZddlmZmZm Z m!Z!	dd
l
m"Z#e#jHsdZ"ne#Z"	ed�Z&ed�Z'dZ(dZ)e*�Z+d�Z,Gd�d�Z-Gd�de-�Z.Gd�de-�Z/Gd�de0�Z1eejd�Gd�d��Z3Gd�de0�Z4Gd �d!e4�Z5Gd"�d#e4�Z6Gd$�d%e4�Z7Gd&�d'e3�Z8Gd(�d)ejr�Z9Gd*�d+ejt�Z:Gd,�d-ejvejx�Z=Gd.�d/e0�Z>d0�Z?Gd1�d2ej��ZAd;d3�ZBeej��Gd4�d5��ZDeej��Gd6�d7��ZFGd8�d9eF�ZGgd:�ZHy#e%$rdZ"Y��hwxYw)<a2
XMPP XML Streams

Building blocks for setting up XML Streams, including helping classes for
doing authentication on either client or server side, and working with XML
Stanzas.

@var STREAM_AUTHD_EVENT: Token dispatched by L{Authenticator} when the
    stream has been completely initialized
@type STREAM_AUTHD_EVENT: L{str}.

@var INIT_FAILED_EVENT: Token dispatched by L{Authenticator} when the
    stream has failed to be initialized
@type INIT_FAILED_EVENT: L{str}.

@var Reset: Token to signal that the XML stream has been reset.
@type Reset: Basic object.
�)�hexlify)�sha1)�intern)�Optional�Tuple)�directlyProvides�implementer)�defer�protocol)�ConnectionLost)�failure�log�	randbytes)�error�ijabber�jid)�domish�	xmlstream)�STREAM_CONNECTED_EVENT�STREAM_END_EVENT�STREAM_ERROR_EVENT�STREAM_START_EVENT)�sslNz//event/stream/authdz//event/xmpp/initfailedz http://etherx.jabber.org/streamszurn:ietf:params:xml:ns:xmpp-tlsc���t|t�std��t|t�std��|�|��}t|j	d��j�S)z�
    Create a SHA1-digest string of a session identifier and password.

    @param sid: The stream session identifier.
    @type sid: C{unicode}.
    @param password: The password to be hashed.
    @type password: C{unicode}.
    z/The session identifier must be a unicode objectz%The password must be a unicode objectzutf-8)�
isinstance�str�	TypeErrorr�encode�	hexdigest)�sid�password�inputs   �J/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/xmlstream.py�hashPasswordr$@s[���c�3���I�J�J��h��$��?�@�@��e�H�:��E�����W�%�&�0�0�2�2�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�
AuthenticatoraD
    Base class for business logic of initializing an XmlStream

    Subclass this object to enable an XmlStream to initialize and authenticate
    to different types of stream hosts (such as clients, components, etc.).

    Rules:
      1. The Authenticator MUST dispatch a L{STREAM_AUTHD_EVENT} when the
         stream has been completely initialized.
      2. The Authenticator SHOULD reset all state information when
         L{associateWithStream} is called.
      3. The Authenticator SHOULD override L{streamStarted}, and start
         initialization there.

    @type xmlstream: L{XmlStream}
    @ivar xmlstream: The XmlStream that needs authentication

    @note: the term authenticator is historical. Authenticators perform
           all steps required to prepare the stream for the exchange
           of XML stanzas.
    c��d|_y�N�r��selfs r#�__init__zAuthenticator.__init__hs	����r%c��y)a|
        Called by the XmlStream when the underlying socket connection is
        in place.

        This allows the Authenticator to send an initial root element, if it's
        connecting, or wait for an inbound root from the peer if it's accepting
        the connection.

        Subclasses can use self.xmlstream.send() to send any initial data to
        the peer.
        N�r+s r#�connectionMadezAuthenticator.connectionMadek��r%c��|jd�r2|djd�}	t|d�t|d�f}nd}t|jj|�|j_y#ttf$rd}Y�CwxYw)a�
        Called by the XmlStream when the stream has started.

        A stream is considered to have started when the start tag of the root
        element has been received.

        This examines C{rootElement} to see if there is a version attribute.
        If absent, C{0.0} is assumed per RFC 3920. Subsequently, the
        minimum of the version from the received stream header and the
        value stored in L{xmlstream} is taken and put back in L{xmlstream}.

        Extensions of this method can extract more information from the
        stream header and perform checks on them, optionally sending
        stream errors and closing the stream.
        �version�.r�)rrN)�hasAttribute�split�int�
IndexError�
ValueError�minrr3)r,�rootElementr3s   r#�
streamStartedzAuthenticator.streamStartedxs��� �#�#�I�.�!�)�,�2�2�3�7�G�
!��w�q�z�?�C���
�O�<���G�!$�T�^�^�%;�%;�W�!E�������
�+�
!� ��
!�s�A6�6B
�	B
c��||_y)a�
        Called by the XmlStreamFactory when a connection has been made
        to the requested peer, and an XmlStream object has been
        instantiated.

        The default implementation just saves a handle to the new
        XmlStream.

        @type xmlstream: L{XmlStream}
        @param xmlstream: The XmlStream that will be passing events to this
                          Authenticator.

        Nr*�r,rs  r#�associateWithStreamz!Authenticator.associateWithStream�s��#��r%N)�__name__�
__module__�__qualname__�__doc__r-r0r=r@r/r%r#r'r'Qs���,��F�6#r%r'c�>�eZdZUdZdZeeed<d�Zd�Z	d�Z
d�Zy)�ConnectAuthenticatorz0
    Authenticator for initiating entities.
    N�	namespacec��||_yr))�	otherHost)r,rIs  r#r-zConnectAuthenticator.__init__�s	��"��r%c���|j|j_tj|j�|j_|jj
�yr))rGrr�	internJIDrI�otherEntity�
sendHeaderr+s r#r0z#ConnectAuthenticator.connectionMade�s;��#'�>�>���� �%(�]�]�4�>�>�%B����"����!�!�#r%c�������fd�����fd��tjd�}|j��|j�jj
t�y)a�
        Perform stream initialization procedures.

        An L{XmlStream} holds a list of initializer objects in its
        C{initializers} attribute. This method calls these initializers in
        order and dispatches the L{STREAM_AUTHD_EVENT} event when the list has
        been successfully processed. Otherwise it dispatches the
        C{INIT_FAILED_EVENT} event with the failure.

        Initializers may return the special L{Reset} object to halt the
        initialization processing. It signals that the current initializer was
        successfully processed, but that the XML Stream has been reset. An
        example is the TLSInitiatingInitializer.
        c�R���jjjd�|S)Nr)r�initializers�pop)�resultr,s �r#�remove_firstz;ConnectAuthenticator.initializeStream.<locals>.remove_first�s ����N�N�'�'�+�+�A�.��Mr%c�B��|tury	�jjd}tj|j
�}|j
��|j
��|S#t$r-�jj�jt�YywxYw)z�
            Take the first initializer and process it.

            On success, the initializer is removed from the list and
            then next initializer will be tried.
            Nr)
�ResetrrPr
�
maybeDeferred�
initialize�addCallbackr9�dispatch�STREAM_AUTHD_EVENT)rR�init�d�do_nextrSr,s   ���r#r]z6ConnectAuthenticator.initializeStream.<locals>.do_next�s��������	
��~�~�2�2�1�5��
�'�'����8���
�
�l�+��
�
�g�&�����
����'�'����8J�K��
�s�A(�(3B�BN)r
�succeedrX�
addErrbackrrY�INIT_FAILED_EVENT)r,r\r]rSs` @@r#�initializeStreamz%ConnectAuthenticator.initializeStream�sB��� 	�
	�,
�M�M�$���	�
�
�g��	���T�^�^�,�,�.?�@r%c���tj�|�|jd��j_|jd�r't
j|d��j_�jjdk\r)�fd�}�jjdtz|�y�j�y)a
        Called by the XmlStream when the stream has started.

        This extends L{Authenticator.streamStarted} to extract further stream
        headers from C{rootElement}, optionally wait for stream features being
        received and then call C{initializeStream}.
        �id�from�r5rc���i}|j�D]}|||j|jf<�|�j_�j�yr))�elements�uri�namer�featuresra)�elementrj�featurer,s   �r#�
onFeaturesz6ConnectAuthenticator.streamStarted.<locals>.onFeatures�sS�����&�/�/�1�D�G�<C�H�g�k�k�7�<�<�8�9�D�+3����'��%�%�'r%z/features[@xmlns="%s"]N)
r'r=�getAttributerr r6rrKrLr3�addOnetimeObserver�
NS_STREAMSra)r,r<rms`  r#r=z"ConnectAuthenticator.streamStarted�s����	�#�#�D�+�6�(�5�5�d�;������#�#�F�+�),���{�6�7J�)K�D�N�N�&��>�>�!�!�V�+�
(�
�N�N�-�-�(�:�5�z�
�
�!�!�#r%)rArBrCrDrGrr�__annotations__r-r0rar=r/r%r#rFrF�s-��� $�I�x��}�#�#�$�
-A�^$r%rFc�2�eZdZUdZdZeeed<d�Zd�Z	y)�ListenAuthenticatorz/
    Authenticator for receiving entities.
    NrGc�R�tj||�d|j_y)z�
        Called by the XmlStreamFactory when a connection has been made.

        Extend L{Authenticator.associateWithStream} to set the L{XmlStream}
        to be non-initiating.
        FN)r'r@r�
initiatingr?s  r#r@z'ListenAuthenticator.associateWithStreams ��	�)�)�$�	�:�$)����!r%c���tj||�|j|j_|jd�r't
j|d�|j_i|j_	|jj�D]\}}||jj|<� ttjd��jd�|j_y)z�
        Called by the XmlStream when the stream has started.

        This extends L{Authenticator.streamStarted} to extract further
        information from the stream headers from C{rootElement}.
        �to��asciiN)r'r=�
defaultUrirrGr6rrK�
thisEntity�prefixes�
localPrefixes�itemsrr�secureRandom�decoder )r,r<�prefixrhs    r#r=z!ListenAuthenticator.streamStarteds���	�#�#�D�+�6�#.�#9�#9���� ��#�#�D�)�(+�
�
�k�$�6G�(H�D�N�N�%�"$�����&�4�4�:�:�<�	2�K�F�C�+1�D�N�N�#�#�C�(�	2�%�Y�%;�%;�A�%>�?�F�F�w�O����r%)
rArBrCrDrGrrrqr@r=r/r%r#rsrss"��� $�I�x��}�#�*�Pr%rsc��eZdZdZy)�FeatureNotAdvertizedzp
    Exception indicating a stream feature was not advertized, while required by
    the initiating entity.
    N�rArBrCrDr/r%r#r�r�*���r%r�c�D�eZdZUdZdZeeeefed<dd�Z	d�Z
d�Zy)� BaseFeatureInitiatingInitializera�
    Base class for initializers with a stream feature.

    This assumes the associated XmlStream represents the initiating entity
    of the connection.

    @cvar feature: tuple of (uri, name) of the stream feature root element.
    @type feature: tuple of (C{str}, C{str})

    @ivar required: whether the stream feature is required to be advertized
                    by the receiving entity.
    @type required: C{bool}
    Nrlc� �||_||_yr))r�required)r,�xsr�s   r#r-z)BaseFeatureInitiatingInitializer.__init__Cs����� ��
r%c��|j|jjvr|j�S|jrt
�y)a_
        Initiate the initialization.

        Checks if the receiving entity advertizes the stream feature. If it
        does, the initialization is started. If it is not advertized, and the
        C{required} instance variable is C{True}, it raises
        L{FeatureNotAdvertized}. Otherwise, the initialization silently
        succeeds.
        N)rlrrj�startr�r�r+s r#rWz+BaseFeatureInitiatingInitializer.initializeGs6���<�<�4�>�>�2�2�2��:�:�<��
�]�]�&�&�r%c��y)zr
        Start the actual initialization.

        May return a deferred for asynchronous initialization.
        Nr/r+s r#r�z&BaseFeatureInitiatingInitializer.startYr1r%)F)rArBrCrDrlrrrrqr-rWr�r/r%r#r�r�1s/���*.�G�X�e�C��H�o�
&�-�!��$r%r�c��eZdZdZy)�TLSErrorz
    TLS base exception.
    Nr�r/r%r#r�r�a���r%r�c��eZdZdZy)�	TLSFailedz5
    Exception indicating failed TLS negotiation
    Nr�r/r%r#r�r�gr�r%r�c��eZdZdZy)�TLSRequiredz�
    Exception indicating required TLS negotiation.

    This exception is raised when the receiving entity requires TLS
    negotiation and the initiating does not desire to negotiate TLS.
    Nr�r/r%r#r�r�m���r%r�c��eZdZdZy)�TLSNotSupportedz�
    Exception indicating missing TLS support.

    This exception is raised when the initiating entity wants and requires to
    negotiate TLS when the OpenSSL library is not available.
    Nr�r/r%r#r�r�vr�r%r�c�J��eZdZdZedfZdZdZdZd	�fd�	Z	d�Z
d�Zd�Z�xZ
S)
�TLSInitiatingInitializera

    TLS stream initializer for the initiating entity.

    It is strongly required to include this initializer in the list of
    initializers for an XMPP stream. By default it will try to negotiate TLS.
    An XMPP server may indicate that TLS is required. If TLS is not desired,
    set the C{wanted} attribute to False instead of removing it from the list
    of initializers, so a proper exception L{TLSRequired} can be raised.

    @ivar wanted: indicates if TLS negotiation is wanted.
    @type wanted: C{bool}
    �starttlsTNc�6��t�|�||��||_y)a4
        @param configurationForTLS: An object which creates appropriately
            configured TLS connections. This is passed to C{startTLS} on the
            transport and is preferably created using
            L{twisted.internet.ssl.optionsForClientTLS}.  If C{None}, the
            default is to verify the server certificate against the trust roots
            as provided by the platform. See
            L{twisted.internet._sslverify.platformTrust}.
        @type configurationForTLS: L{IOpenSSLClientConnectionCreator} or
            C{None}
        )r�N)�superr-�_configurationForTLS)r,r�r��configurationForTLS�	__class__s    �r#r-z!TLSInitiatingInitializer.__init__�s���	����h��/�$7��!r%c���|jjd|j�|jr
|j}n3tj|jjj�}|jjj|�|jj�|jj�|jjt�y)zH
        Proceed with TLS negotiation and reset the XML stream.
        �/failureN)r�removeObserver�	onFailurer�r�optionsForClientTLSrL�host�	transport�startTLS�resetrM�	_deferred�callbackrU)r,�obj�ctxs   r#�	onProceedz"TLSInitiatingInitializer.onProceed�s���
	
���%�%�j�$�.�.�A��$�$��+�+�C��)�)�$�.�.�*D�*D�*I�*I�J�C���� � �)�)�#�.����������!�!�#�������&r%c��|jjd|j�|jj	t��y)N�/proceed)rr�r�r��errbackr��r,r�s  r#r�z"TLSInitiatingInitializer.onFailure�s.�����%�%�j�$�.�.�A������y�{�+r%c��|jrEt�>|jrtjt��Stjd�Sn_|jj|jjrtjt��Stjd�Stj�|_|jjd|j�|jjd|j�|jj!t#j$t&df��|jS)a�
        Start TLS negotiation.

        This checks if the receiving entity requires TLS, the SSL library is
        available and uses the C{required} and C{wanted} instance variables to
        determine what to do in the various different cases.

        For example, if the SSL library is not available, and wanted and
        required by the user, it raises an exception. However if it is not
        required by both parties, initialization silently succeeds, moving
        on to the next step.
        Nr�r�r�)�wantedrr�r
�failr�r^rrjrlr��Deferredr�ror�r��sendr�Element�NS_XMPP_TLSr+s r#r�zTLSInitiatingInitializer.start�s����;�;��{��=�=� �:�:�o�&7�8�8� �=�=��.�.��
�^�^�
$�
$�T�\�\�
2�
;�
;��:�:�k�m�,�,��=�=��&�&����)������)�)�*�d�n�n�E����)�)�*�d�n�n�E������F�N�N�K��+D�E�F��~�~�r%)TN)rArBrCrDr�rlr�r�r�r-r�r�r��
__classcell__)r�s@r#r�r�s8�����J�'�G�
�F��I���
8�
'�,�r%r�c�h�eZdZdZdZdZdZdZdZdZ	dZ
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zy)�	XmlStreama}
    XMPP XML Stream protocol handler.

    @ivar version: XML stream version as a tuple (major, minor). Initially,
                   this is set to the minimally supported version. Upon
                   receiving the stream header of the peer, it is set to the
                   minimum of that value and the version on the received
                   header.
    @type version: (C{int}, C{int})
    @ivar namespace: default namespace URI for stream
    @type namespace: C{unicode}
    @ivar thisEntity: JID of this entity
    @type thisEntity: L{JID}
    @ivar otherEntity: JID of the peer entity
    @type otherEntity: L{JID}
    @ivar sid: session identifier
    @type sid: C{unicode}
    @ivar initiating: True if this is the initiating stream
    @type initiating: C{bool}
    @ivar features: map of (uri, name) to stream features element received from
                    the receiving entity.
    @type features: C{dict} of (C{unicode}, C{unicode}) to L{domish.Element}.
    @ivar prefixes: map of URI to prefixes that are to appear on stream
                    header.
    @type prefixes: C{dict} of C{unicode} to C{unicode}
    @ivar initializers: list of stream initializer objects
    @type initializers: C{list} of objects that provide L{IInitializer}
    @ivar authenticator: associated authenticator that uses C{initializers} to
                         initialize the XML stream.
    re�invalidNTFc��tjj|�tdi|_||_g|_i|_|j|�y)N�stream)	rr�r-rpr|�
authenticatorrPrjr@�r,r�s  r#r-zXmlStream.__init__�sI�����$�$�T�*�#�X�.��
�*��������
�	�)�)�$�/r%c�2�ddlm}|j|i|��S)Nr)�reactor)�twisted.internetr��	callLater)r,�args�kwargsr�s    r#�
_callLaterzXmlStream._callLater	s��,� �w� � �$�1�&�1�1r%c�2�d|_|j�y)z�
        Reset XML Stream.

        Resets the XML Parser for incoming data. This is to be used after
        successfully negotiating a new layer, e.g. TLS and SASL. Note that
        registered event observers will continue to be in place.
        FN)�_headerSent�_initializeStreamr+s r#r�zXmlStream.resets��!������ r%c��|jtjtj|��t
�|jj�y)a-
        Called when a stream:error element has been received.

        Dispatches a L{STREAM_ERROR_EVENT} event with the error element to
        allow for cleanup actions and drops the connection.

        @param errelem: The received error element.
        @type errelem: L{domish.Element}
        N)rYr
�Failurer�exceptionFromStreamErrorrr��loseConnection)r,�errelems  r#�
onStreamErrorzXmlStream.onStreamErrors<��	
�
�
��O�O�E�:�:�7�C�D�FX�	
�	
���%�%�'r%c�T�i}|jj�D]\}}|tk7s�|||<�tjtdf|j
|��}|jr|jj�|d<|jr|jj�|d<|js|jr|j|d<|jdk\rd|jz|d<|j|j|jd	�
��d|_y)
z%
        Send stream header.
        r�)r}rwrdrcrez%d.%dr3r)r|�closeElementTN)r|r~rprr�rGrL�userhostr{rur r3r��toXmlr�)r,r}rhr�r<s     r#rMzXmlStream.sendHeader(s���
�
��=�=�.�.�0�	,�K�C���j� �(+�
�f�%�	,��n�n�
��"�D�N�N�-�
����� $� 0� 0� 9� 9� ;�K����?�?�"&�/�/�":�":�"<�K������4�8�8� $���K����<�<�6�!�%,�t�|�|�%;�K�	�"��	�	�+�#�#�T�]�]��#�K�L���r%c�&�|jd�y)z%
        Send stream footer.
        z</stream:stream>N)r�r+s r#�
sendFooterzXmlStream.sendFooterEs��	
�	�	�$�%r%c��|js|js|j�|jr/|j|j	��|j�|jj�y)a^
        Send stream level error.

        If we are the receiving entity, and haven't sent the header yet,
        we sent one first.

        After sending the stream error, the stream is closed and the transport
        connection dropped.

        @param streamError: stream error instance
        @type streamError: L{error.StreamError}
        N)r�rurMr��
getElementr�r�r�)r,�streamErrors  r#�sendStreamErrorzXmlStream.sendStreamErrorKsU���������O�O������I�I�k�,�,�.�/��O�O�����%�%�'r%c��tjj|�rI|j|j|j
t
|jj����}tjj||�y)aV
        Send data over the stream.

        This overrides L{xmlstream.XmlStream.send} to use the default namespace
        of the stream header when serializing L{domish.IElement}s. It is
        assumed that if you pass an object that provides L{domish.IElement},
        it represents a direct child of the stream's root element.
        )r|rz�prefixesInScopeN)r�IElement�
providedByr�r|rG�list�valuesrr�r�r�s  r#r�zXmlStream.sendasd���?�?�%�%�c�*��)�)�����>�>� $�T�]�]�%9�%9�%;� <���C�	��� � ��s�+r%c�v�tjj|�|jj�y)zx
        Called when a connection is made.

        Notifies the authenticator when a connection has been made.
        N)rr�r0r�r+s r#r0zXmlStream.connectionMadess*��	���*�*�4�0����)�)�+r%c��tjj||�|jdtz|j
�|jj|�y)a�
        Called when the stream header has been received.

        Extracts the header's C{id} and C{version} attributes from the root
        element. The C{id} attribute is stored in our C{sid} attribute and the
        C{version} attribute is parsed and the minimum of the version we sent
        and the parsed C{version} attribute is stored as a tuple (major, minor)
        in this class' C{version} attribute. If no C{version} attribute was
        present, we assume version 0.0.

        If appropriate (we are the initiating stream and the minimum of our and
        the other party's version is at least 1.0), a one-time observer is
        registered for getting the stream features. The registered function is
        C{onFeatures}.

        Ultimately, the authenticator's C{streamStarted} method will be called.

        @param rootElement: The root element.
        @type rootElement: L{domish.Element}
        z/error[@xmlns='%s']N)rr��onDocumentStartrorpr�r�r=)r,r<s  r#r�zXmlStream.onDocumentStart|sL��*	���+�+�D�+�>�	
��� 5�
� B�D�DV�DV�W����(�(��5r%)rArBrCrDr3rGr{rLr rur�r-r�r�r�rMr�r�r�r0r�r/r%r#r�r��s^���>�G��I��J��K�
�C��J��K�	0�2�
	!�
(� �:&�(�,,�$,�6r%r�c��eZdZdZeZd�Zy)�XmlStreamFactoryz�
    Factory for Jabber XmlStream objects as a reconnecting client.

    Note that this differs from L{xmlstream.XmlStreamFactory} in that
    it generates Jabber specific L{XmlStream} instances that have
    authenticators.
    c�R�tjj||�||_yr))rr�r-r�r�s  r#r-zXmlStreamFactory.__init__�s ���"�"�+�+�D�-�@�*��r%N)rArBrCrDr�rr-r/r%r#r�r��s����H�+r%r�c� �eZdZdZeZd�Zd�Zy)�XmlStreamServerFactorya
    Factory for Jabber XmlStream objects as a server.

    @since: 8.2.
    @ivar authenticatorFactory: Factory callable that takes no arguments, to
                                create a fresh authenticator to be associated
                                with the XmlStream.
    c�P�tjj|�||_yr))r�BootstrapMixinr-�authenticatorFactory)r,r�s  r#r-zXmlStreamServerFactory.__init__�s��� � �)�)�$�/�$8��!r%c�x�|j�}|j|�}||_|j|�|S)z�
        Create an instance of XmlStream.

        A new authenticator instance will be created and passed to the new
        XmlStream. Registered bootstrap event observers are installed as well.
        )r�r�factory�installBootstraps)r,�addrr�r�s    r#�
buildProtocolz$XmlStreamServerFactory.buildProtocol�s:���1�1�3�
�
�]�]�=�
)����
����r�"��	r%N)rArBrCrDr�rr-r�r/r%r#r�r��s����H�9�r%r�c��eZdZdZy)�TimeoutErrorzc
    Exception raised when no IQ response has been received before the
    configured timeout.
    Nr�r/r%r#r�r��r�r%r�c����fd�}�fd�}i�_t�dd��_�jtj
|��jd|��jd|�t
�tj�y)a0
    Enhances an XmlStream for iq response tracking.

    This makes an L{XmlStream} object provide L{IIQResponseTracker}. When a
    response is an error iq stanza, the deferred has its errback invoked with a
    failure that holds a L{StanzaError<error.StanzaError>} that is
    easier to examine.
    c���t|dd�ry	�j|d}�j|d=d|_|ddk(r%|jt	j
|��y|j
|�y#t$rYywxYw)zC
        Handle iq response by firing associated deferred.
        �handledFNrcT�typer)�getattr�iqDeferredsr�r�r�exceptionFromStanzar��KeyError)�iqr\r�s  �r#r�z.upgradeWithIQResponseTracker.<locals>.callback�s�����2�y�%�(��
	����r�$�x�(�A����r�$�x�(��B�J��&�z�W�$��	�	�%�3�3�B�7�8��
�
�2����	��	�s�A9�9	B�Bc����j}i�_|j�D]}|jt���y)z�
        Make sure deferreds do not linger on after disconnect.

        This errbacks all deferreds of iq's for which no response has been
        received with a L{ConnectionLost} failure. Otherwise, the deferreds
        will never be fired.
        N)r�r�r�r)�_r�r\r�s   �r#�disconnectedz2upgradeWithIQResponseTracker.<locals>.disconnected�s<����n�n������#�#�%�	(�A�
�I�I�n�&�'�	(r%�iqDefaultTimeoutNz/iq[@type="result"]z/iq[@type="error"])	r�r�r��addObserverrrrr�IIQResponseTracker)r�r�r�s`  r#�upgradeWithIQResponseTrackerr�sj����&(��B�N�!�"�&8�$�?�B���N�N�9�-�-�|�<��N�N�(�(�3��N�N�'��2��R��3�3�4r%c�$�eZdZdZdZdd�Zdd�Zy)�IQa�
    Wrapper for an iq stanza.

    Iq stanzas are used for communications with a request-response behaviour.
    Each iq request is associated with an XML stream and has its own unique id
    to be able to track the response.

    @ivar timeout: if set, a timeout period after which the deferred returned
                   by C{send} will have its errback called with a
                   L{TimeoutError} failure.
    @type timeout: C{float}
    Nc�|�tjj|d�|j�||d<||_y)z�
        @type xmlstream: L{xmlstream.XmlStream}
        @param xmlstream: XmlStream to use for transmission of this IQ

        @type stanzaType: C{str}
        @param stanzaType: IQ type identifier ('get' or 'set')
        )Nr�r�N)rr�r-�addUniqueId�
_xmlstream)r,r�
stanzaTypes   r#r-zIQ.__init__s4��	������l�3�����!��V��#��r%c������|�|�d<tjj�j�st	�j�tj����jj�d<�jxs�jj}|�8��fd�}�jj||���fd�}�j|��jj���S)a�
        Send out this iq.

        Returns a deferred that is fired when an iq response with the same id
        is received. Result responses will be passed to the deferred callback.
        Error responses will be transformed into a
        L{StanzaError<error.StanzaError>} and result in the errback of the
        deferred being invoked.

        @rtype: L{defer.Deferred}
        rwrcc�n���jj�d=�jtd��y)NrczIQ timed out)rr�r�r�)r\r,s��r#�	onTimeoutzIQ.send.<locals>.onTimeout6s*����O�O�/�/��T�
�;��	�	�,�~�6�7r%c�H���j�r�j�|Sr))�active�cancel)rR�calls �r#�
cancelTimeoutzIQ.send.<locals>.cancelTimeout<s����;�;�=��K�K�M��
r%)
rrr�rrr
r�r��timeoutr�r��addBothr�)r,rwrrrrr\s`    @@r#r�zIQ.sends�����>��D��J��)�)�4�4�T�_�_�E�(����9��N�N���23����#�#�D��J�/��,�,�B�$�/�/�"B�"B����
8��?�?�-�-�g�y�A�D�
�
�I�I�m�$������T�"��r%)�setr))rArBrCrDrr-r�r/r%r#rrs����G�$�'r%rc���|jd�}|jd�}|jd�}tjd|jf�}|r||d<|r||d<|r||d<|r||d<|S)a�
    Create a response stanza from another stanza.

    This takes the addressing and id attributes from a stanza to create a (new,
    empty) response stanza. The addressing attributes are swapped and the id
    copied. Optionally, the stanza type of the response can be specified.

    @param stanza: the original stanza
    @type stanza: L{domish.Element}
    @param stanzaType: optional response stanza type
    @type stanzaType: C{str}
    @return: the response stanza.
    @rtype: L{domish.Element}
    rdrwrcNr�)rnrr�ri)�stanzar�toAddr�fromAddr�stanzaID�responses      r#�
toResponserHs��� �
 �
 ��
(�F��"�"�4�(�H��"�"�4�(�H��~�~�t�V�[�[�1�2�H�
������#�����!�����%�����Or%c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�XMPPHandlerz�
    XMPP protocol handler.

    Classes derived from this class implement (part of) one or more XMPP
    extension protocols, and are referred to as a subprotocol implementation.
    c� �d|_d|_yr))�parentrr+s r#r-zXMPPHandler.__init__rs�������r%c�H�||_|jj|�yr))r�
addHandler�r,rs  r#�setHandlerParentzXMPPHandler.setHandlerParentvs����������t�$r%c�H�|jj|�d|_yr))r�
removeHandlerr!s  r#�disownHandlerParentzXMPPHandler.disownHandlerParentzs�����!�!�$�'���r%c�2�||_|j�yr))rr0)r,r�s  r#�makeConnectionzXMPPHandler.makeConnection~s��������r%c��y)z�
        Called after a connection has been established.

        Can be overridden to perform work before stream initialization.
        Nr/r+s r#r0zXMPPHandler.connectionMade�r1r%c��y)z�
        The XML stream has been initialized.

        Can be overridden to perform work after stream initialization, e.g. to
        set up observers and start exchanging XML stanzas.
        Nr/r+s r#�connectionInitializedz!XMPPHandler.connectionInitialized�r1r%c��d|_y)z�
        The XML stream has been closed.

        This method can be extended to inspect the C{reason} argument and
        act on it.
        Nr*�r,�reasons  r#�connectionLostzXMPPHandler.connectionLost�s����r%c�:�|jj|�y)a�
        Send data over the managed XML stream.

        @note: The stream manager maintains a queue for data sent using this
               method when there is no current initialized XML stream. This
               data is then sent as soon as a new stream has been established
               and initialized. Subsequently, L{connectionInitialized} will be
               called again. If this queueing is not desired, use C{send} on
               C{self.xmlstream}.

        @param obj: data to be sent over the XML stream. This is usually an
                    object providing L{domish.IElement}, or serialized XML. See
                    L{xmlstream.XmlStream} for details.
        N)rr�r�s  r#r�zXMPPHandler.send�s��	
������r%N)rArBrCrDr-r"r%r'r0r*r.r�r/r%r#rris/����%������r%rc�(�eZdZdZd�Zd�Zd�Zd�Zy)�XMPPHandlerCollectiona3
    Collection of XMPP subprotocol handlers.

    This allows for grouping of subprotocol handlers, but is not an
    L{XMPPHandler} itself, so this is not recursive.

    @ivar handlers: List of protocol handlers.
    @type handlers: C{list} of objects providing
                      L{IXMPPHandler}
    c��g|_yr))�handlersr+s r#r-zXMPPHandlerCollection.__init__�s	����
r%c�,�t|j�S)z2
        Act as a container for handlers.
        )�iterr3r+s r#�__iter__zXMPPHandlerCollection.__iter__�s���D�M�M�"�"r%c�:�|jj|�y)zs
        Add protocol handler.

        Protocol handlers are expected to provide L{ijabber.IXMPPHandler}.
        N)r3�append�r,�handlers  r#r z XMPPHandlerCollection.addHandler�s��	
�
�
���W�%r%c�:�|jj|�y)z*
        Remove protocol handler.
        N)r3�remover9s  r#r$z#XMPPHandlerCollection.removeHandler�s��	
�
�
���W�%r%N)rArBrCrDr-r6r r$r/r%r#r1r1�s��	��#�&�&r%r1c�>�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�
StreamManagera,
    Business logic representing a managed XMPP connection.

    This maintains a single XMPP connection and provides facilities for packet
    routing and transmission. Business logic modules are objects providing
    L{ijabber.IXMPPHandler} (like subclasses of L{XMPPHandler}), and added
    using L{addHandler}.

    @ivar xmlstream: currently managed XML stream
    @type xmlstream: L{XmlStream}
    @ivar logTraffic: if true, log all traffic.
    @type logTraffic: C{bool}
    @ivar _initialized: Whether the stream represented by L{xmlstream} has
                        been initialized. This is used when caching outgoing
                        stanzas.
    @type _initialized: C{bool}
    @ivar _packetQueue: internal buffer of unsent data. See L{send} for details.
    @type _packetQueue: C{list}
    Fc�f�tj|�d|_g|_d|_|jt|j�|jt|j�|jt|j�|jt|j�||_y)NF)r1r-r�_packetQueue�_initialized�addBootstrapr�
_connectedrZ�_authdr`�initializationFailedr�
_disconnectedr�)r,r�s  r#r-zStreamManager.__init__�s����&�&�t�,�������!������3�T�_�_�E����/����=����.��0I�0I�J����-�t�/A�/A�B���r%c��tj||�|jr9|jr,|j	|j�|j�yyy)z�
        Add protocol handler.

        When an XML stream has already been established, the handler's
        C{connectionInitialized} will be called to get it up to speed.
        N)r1r rrAr'r*r9s  r#r zStreamManager.addHandler�sJ��	�(�(��w�7��>�>�d�/�/��"�"�4�>�>�2��)�)�+�0�>r%c��d�}d�}|jr||_||_||_|D]}|j	|��y)z�
        Called when the transport connection has been established.

        Here we optionally set up traffic logging (depending on L{logTraffic})
        and call each handler's C{makeConnection} method with the L{XmlStream}
        instance.
        c�4�tjd|z�y)NzRECV: %r�r�msg��bufs r#�	logDataInz+StreamManager._connected.<locals>.logDataIn����G�G�J��$�%r%c�4�tjd|z�y)NzSEND: %rrJrLs r#�
logDataOutz,StreamManager._connected.<locals>.logDataOutrOr%N)�
logTraffic�rawDataInFn�rawDataOutFnrr')r,r�rNrQ�es     r#rCzStreamManager._connectedsG��	&�	&��?�?�&�B�N�(�B�O�����	!�A�
���R� �	!r%c��|jD]}|j|��g|_d|_|D]}|j��y)z�
        Called when the stream has been initialized.

        Send out cached stanzas and call each handler's
        C{connectionInitialized} method.
        TN)r@r�rAr*)r,r��prUs    r#rDzStreamManager._authdsQ���"�"�	�A��G�G�A�J�	���� ����	&�A�
�#�#�%�	&r%c��y)a�
        Called when stream initialization has failed.

        Stream initialization has halted, with the reason indicated by
        C{reason}. It may be retried by calling the authenticator's
        C{initializeStream}. See the respective authenticators for details.

        @param reason: A failure instance indicating why stream initialization
                       failed.
        @type reason: L{failure.Failure}
        Nr/r,s  r#rEz"StreamManager.initializationFailed-r1r%c�P�d|_d|_|D]}|j|��y)a
        Called when the stream has been closed.

        From this point on, the manager doesn't interact with the
        L{XmlStream} anymore and notifies each handler that the connection
        was lost by calling its C{connectionLost} method.
        NF)rrAr.)r,r-rUs   r#rFzStreamManager._disconnected:s2�����!����	%�A�
���V�$�	%r%c��|jr|jj|�y|jj	|�y)aA
        Send data over the XML stream.

        When there is no established XML stream, the data is queued and sent
        out when a new XML stream has been established and initialized.

        @param obj: data to be sent over the XML stream. See
                    L{xmlstream.XmlStream.send} for details.
        N)rArr�r@r8r�s  r#r�zStreamManager.sendJs3������N�N����$����$�$�S�)r%N)rArBrCrDrRr-r rCrDrErFr�r/r%r#r>r>�s1���(�J�
�
,�!�0&�$�%� 
*r%r>)r'r�rFr�r`rrsrpr�rUrZrrrrr>r�r�r�r�r�r�rr1r�r�r�r$rrr))IrD�binasciir�hashlibr�sysr�typingrr�zope.interfacerr	r�r
r�twisted.internet.errorr�twisted.pythonr
rr�twisted.words.protocols.jabberrrr�twisted.words.xishrr�twisted.words.xish.xmlstreamrrrrr�_ssl�	supported�ImportErrorrZr`rpr��objectrUr$r'rFrs�	Exceptionr��IInitiatingInitializerr�r�r�r�r�r�r�r�r��
ServerFactoryr�r�rr�rr�IXMPPHandlerr�IXMPPHandlerCollectionr1r>�__all__r/r%r#�<module>ros���(���"�8�,�1�2�2�>�>�0����,��>�>������2�3���4�5��
/�
�/�����3�"P#�P#�f]$�=�]$�@#P�-�#P�L�9��
�W�
+�
+�,�,�,�-�,�^�y������(���h��S�?�S�lA6�	�#�#�A6�H
+�y�1�1�
+� �Y�5�5�x�7M�7M��>�9��/5�dD����D�N�B
�W�
!�
!�"�?�?�#�?�D
�W�
+�
+�,�!&�!&�-�!&�HF*�)�F*�R���W!��
�C��s�G�G�G

Youez - 2016 - github.com/yon3zu
LinuXploit