
    h                         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
Zdej                  j                  d	efdZd Zde
d	efdZy)    N)Popen)Optional)sleep)TransportDetails)r   peer2strtransport_channel_idcreate_transport_details	is_serverchannel_id_typereturnc                 f   |y|dvrt        dj                  |            | j                  d      }|t        d      t        |d      st        d      |j	                  d	      }t        |      t        k7  ryt        j                         }|j                  |       |j                         }|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).
    s                                    )
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_ids          Q/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/asyncio/util.pyr   r   +   s       n,4;;OLMM&&|4Gopp712yzz &99,9O&NN	!"XXZ
    r   c                    	 | j                  d      }t        |t              r+t        |      dk(  rdnd}dj	                  |d   |d   |      S t        |t
              rdj	                  |      S d	j	                  |      S #  Y nxY w	 | j                  d
      }dj	                  |j                        S #  Y nxY w	 | j                  d      }dj	                  |      S #  Y yxY w)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*   s        r!   r   r   V   s    
''
3dE"d)q.QaF#**47DGVDDc"$$T**>>$''..|<""488,,''/%% s0   AB   B  /B   B+B4 4B8<!C C"c            	      b    ddl m g d} t        t        d t	        fd|                   } | S )Nr   )
serializer)CBORSerializerMsgPackSerializerUBJSONSerializerJsonSerializerc                     | S N )xs    r!   <lambda>z!get_serializers.<locals>.<lambda>z   s    r"   c                 8    t        |       rt        |       S d S r;   )r   getattr)sr5   s    r!   r>   z!get_serializers.<locals>.<lambda>z   s%    SZ[eghSiQ9O :948:9r"   )autobahn.wampr5   listfiltermap)serializersr5   s    @r!   get_serializersrG   v   s6    (_Kvk3 09:E,G H IKr"   c           	          t        |       }| j                  dd       d u}|r"dt        | |d      i}t        j                  }d }ni }t        j
                  }d }t        j                  }t        |||||||      S )Npeercertr   )channel_typechannel_framingr1   r
   	is_securer    	peer_cert)r   r   r   r   CHANNEL_TYPE_TLSCHANNEL_TYPE_TCPCHANNEL_FRAMING_WEBSOCKET)r   r
   r1   rL   r    rJ   rM   rK   s           r!   r	   r	      s    ID ((T:$FI.y)\R

 (88	
'88	&@@O!%i'1YH Hr"   r;   )r   r)   r   typingr   asyncior   autobahn.wamp.typesr   __allboolr/   r   r   
transportsBaseTransportr   rG   r	   r<   r"   r!   <module>rX      s|   6      0	(t (hsm (_d (V**88 S @H4 H<L Hr"   