o
    >h                     @   s   d dl Z d dlmZ d dlmZ d dlZd dlmZ d dlmZ dZ	dde
dee d	efd
dZdejjd	efddZdd Zde
d	efddZdS )    N)Popen)Optional)sleep)TransportDetails)r   peer2strtransport_channel_idcreate_transport_details	is_serverchannel_id_typereturnc                 C   s   |du rdS |dvrt d|| d}|du rt dt|ds't d|jd	d
}t|tkr5dS t }|	| |
 }|S )a  
    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.

    :param transport: The asyncio TLS transport to extract the TLS channel ID from.
    :param is_server: Flag indicating the transport is for a server.
    :param channel_id_type: TLS channel ID type, currently only "tls-unique" is supported.
    :returns: The TLS channel id (32 bytes).
    Ns                                    )
tls-uniquezinvalid channel ID type {}
ssl_objectzUTLS transport channel_id for tls-unique requested, but ssl_obj not found on transportget_channel_bindingz_TLS transport channel_id for tls-unique requested, but get_channel_binding not found on ssl_objr   )cb_type)	Exceptionformatget_extra_infohasattrr   typebyteshashlibsha256updatedigest)	transportr	   r
   ssl_objtls_finished_msgm
channel_id r   u/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/asyncio/util.pyr   +   s    


r   r   c                 C   s   z1|  d}t|tr!t|dkrdnd}d|d |d |W S t|tr,d|W S d	|W S    Y z|  d
}d|jW S    Y z|  d}d|W S    Y dS )Npeername         ztcp{2}:{0}:{1}r      zunix:{0}z?:{0}
subprocessz
process:{}pipezpipe:{}unknown)r   
isinstancetuplelenr   strpid)r   peerip_verprocr'   r   r   r    r   V   s*   




r   c                     s8   ddl m  g d} ttdd t fdd| } | S )Nr   
serializer)CBORSerializerMsgPackSerializerUBJSONSerializerJsonSerializerc                 S   s   | S Nr   )xr   r   r    <lambda>z   s    z!get_serializers.<locals>.<lambda>c                    s   t  | r
t | S d S r7   )r   getattr)sr1   r   r    r9   z   s    )autobahn.wampr2   listfiltermap)serializersr   r1   r    get_serializersv   s   rA   c              	   C   sb   t | }| dd d u}|rdt| |di}tj}d }ni }tj}d }tj}t|||||||dS )Npeercertr   )channel_typechannel_framingr.   r	   	is_securer   	peer_cert)r   r   r   r   CHANNEL_TYPE_TLSCHANNEL_TYPE_TCPCHANNEL_FRAMING_WEBSOCKET)r   r	   r.   rE   r   rC   rF   rD   r   r   r    r      s   r   r7   )r   r&   r   typingr   asyncior   autobahn.wamp.typesr   __allboolr,   r   r   
transportsBaseTransportr   rA   r   r   r   r   r    <module>   s   + 	