o
    @»BiH  ã                   @   sª   d dl mZ d dlZd dlmZ d dlmZmZ zd dlm	Z	 W n e
y-   edƒZ	Y nw z
d dlmZ dZW n e
yC   dZY nw d	Zdd
d„Zdd„ Zdd„ ZdS )é    )Úabsolute_importN)ÚDeferred)ÚIPv4AddressÚUNIXAddress)ÚPipeAddress)ÚIPv6AddressTF)ÚsleepÚpeer2strÚtransport_channel_idc                 C   s*   |sddl m} tƒ }| | |jd¡ |S )aD  
    Inline sleep for use in co-routines (Twisted ``inlineCallback`` decorated functions).

    .. seealso::
       * `twisted.internet.defer.inlineCallbacks <http://twistedmatrix.com/documents/current/api/twisted.internet.defer.html#inlineCallbacks>`__
       * `twisted.internet.interfaces.IReactorTime <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorTime.html>`__

    :param delay: Time to sleep in seconds.
    :type delay: float
    :param reactor: The Twisted reactor to use.
    :type reactor: None or provider of ``IReactorTime``.
    r   )ÚreactorN)Útwisted.internetr   r   Ú	callLaterÚcallback)Údelayr   Úd© r   úU/var/www/html/Trade-python/venv/lib/python3.10/site-packages/autobahn/twisted/util.pyr   4   s
   r   c                 C   sz   t | tƒrd | j| j¡}|S tr t | tƒr d | j| j¡}|S t | tƒr-d | j¡}|S t | t	ƒr6d}|S d | ¡}|S )zÅ
    Convert a Twisted address as returned from ``self.transport.getPeer()`` to a string.

    :returns: Returns a string representation of the peer on a Twisted transport.
    :rtype: unicode
    ztcp4:{0}:{1}ztcp6:{0}:{1}zunix:{0}z<pipe>z?:{0})
Ú
isinstancer   ÚformatÚhostÚportÚ	_HAS_IPV6r   r   Únamer   )ÚaddrÚresr   r   r   r	   H   s   
ö	
ø
ú
þr	   c                 C   sd   |dvrt d |¡ƒ‚t| dƒr0|r| j ¡ }n| j ¡ }|du r#dS t ¡ }| |¡ | 	¡ S dS )aq  
    Application-layer user authentication protocols are vulnerable to generic
    credential forwarding attacks, where an authentication credential sent by
    a client C to a server M may then be used by M to impersonate C at another
    server S. To prevent such credential forwarding attacks, modern authentication
    protocols rely on channel bindings. For example, WAMP-cryptosign can use
    the tls-unique channel identifier provided by the TLS layer to strongly bind
    authentication credentials to the underlying channel, so that a credential
    received on one TLS channel cannot be forwarded on another.

    )z
tls-uniquezinvalid channel ID type {}Ú_tlsConnectionN)
Ú	Exceptionr   Úhasattrr   Úget_peer_finishedÚget_finishedÚhashlibÚsha256ÚupdateÚdigest)Ú	transportÚ	is_serverÚchannel_id_typeÚtls_finished_msgÚmr   r   r   r
   ^   s   


r
   )N)Ú
__future__r   r    Útwisted.internet.deferr   Útwisted.internet.addressr   r   Útwisted.internet.stdior   ÚImportErrorÚtyper   r   Ú__allr   r	   r
   r   r   r   r   Ú<module>   s&   þÿ
