
    h;5              
          d dl Z d dlZd dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZ 	 d dlmZ 	 d dl
mZ d	Z	 d dlmZ d dlmZ d dlmZ d	ZdZddZdeeef   de fdZ!esdde"de#dee    dee$   fdZ%ndde"de#dee    dee$   fdZ%esde"deee ef      fdZ&ndedeee ef      fdZ&deeef   de#defdZ'y# e$ r  ed      ZY w xY w# e$ r d
Z ed      ZY w xY w# e$ r d
ZY w xY w)    N)OptionalUnionDictAny)Deferred)IPv4AddressUNIXAddress)
ITransportIProcessTransport)TransportDetails)PipeAddress)IPv6AddressTF)ISSLTransport)TLSMemoryBIOProtocol)
Connection)sleeppeer2strtransport_channel_idextract_peer_certificatecreate_transport_detailsc                 d    |sddl m} t               }|j                  | |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   ds      Q/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/twisted/util.pyr   r   D   s,     ,
AeQZZ.H    	transportreturnc                    t        j                  |       rdj                  | j                        }|S t	        j                  |       r| j                         }t        |t              r(dj                  |j                  |j                        }|S t        r8t        |t              r(dj                  |j                  |j                        }|S t        |t              r-|j                  rdj                  |j                        }|S d}|S t        |t              r%dj                  t        j                                }|S d}|S d}|S )a  
    Return a *peer descriptor* given a Twisted transport, for example:

    * ``tcp4:127.0.0.1:52914``: a TCPv4 socket
    * ``unix:/tmp/server.sock``: a Unix domain socket
    * ``process:142092``: a Pipe originating from a spawning (parent) process
    * ``pipe``: a Pipe terminating in a spawned (child) process

    :returns: Returns a string representation of the peer of the Twisted transport.
    z
process:{}ztcp4:{0}:{1}ztcp6:{0}:{1}zunix:{0}unixzprocess:{0}unknown)r   
providedByformatpidr
   getPeer
isinstancer   hostport	_HAS_IPV6r   r	   namer   osgetppid)r    resaddrs      r   r   r   X   s&    ##I.!!)--0, J+ 
		y	)JSJ[J[J]dK( ''		499=C$ J# :dK8 ''		499=C  J k*yy ''		2 J  J k*  &&rzz|4C J	 C J Jr   	is_serverchannel_id_typec                 <    |yt        dj                  |            )N                                    zUcannot determine TLS channel ID of type "{}" when TLS is not available on this system)RuntimeErrorr&   )r    r2   r3   s      r   r   r      s0    "v}}  N   O  P  Pr   c                    |y|dvrt        dj                  |            t        | t              s$t        dj                  |t	        |                   | j                         }|rt        |t              sJ d}|dk(  r^||k7  r|j                         }n|j                         }|yt        j                         }|j                  |       |j                         S t        dj                  |            )a(  
        Return TLS channel ID of WAMP transport of the given TLS channel ID type.

        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 Twisted TLS transport to extract the TLS channel ID from. If the transport isn't
            TLS based, and non-empty ``channel_id_type`` is requested, ``None`` will be returned. If the transport
            is indeed TLS based, an empty ``channel_id_type`` of ``None`` is requested, 32 NUL bytes will be returned.
        :param is_server: Flag indicating that the transport is a server transport.
        :param channel_id_type: TLS channel ID type, if set currently only ``"tls-unique"`` is supported.
        :returns: The TLS channel ID (32 bytes).
        r5   )
tls-uniquez*invalid TLS channel ID type "{}" requestedz[cannot determine TLS channel ID of type "{}" when TLS is not available on this transport {}Tr8   z7should not arrive here (unhandled channel_id_type "{}"))r6   r&   r)   r   type	getHandler   get_peer_finishedget_finishedhashlibsha256updatedigestNotImplementedError)r    r2   r3   
connectionis_not_resumedtls_finished_msgms          r   r   r      s    & ".0KRRSbcdd)%9:mtt#T)_67 7 "+!4!4!6
jZ@@@ l*N* $.#?#?#A  $.#:#:#< '
 $NN$)*xxz!%&_&f&fgv&wxxr   c                      y)z~
        Dummy when no TLS is available.

        :param transport: Ignored.
        :return: Always return ``None``.
        N )r    s    r   r   r      s     r   c                 (   t        j                  |       rt        | d      sy| j                         }|r]d }dj	                   ||j                  d                  j                         dj	                   ||j                  d                  j                         dj	                   ||j                  d                  j                         t        |j                                ||j                               t        |j                                ||j                               t        |j                                ||j                                ||j                               g d}t!        |j#                               D ]v  }|j%                  |      }dj	                   ||j'                                     dj	                   ||            |j)                         d	k7  d
}|d   j+                  |       x d|j-                         fd|j/                         ffD ]f  \  }}i ||<   |j1                         D ]I  \  }	}
 ||	      }	 ||
      }
dj	                  |
      ||   dj	                  |	      j3                         <   K h |S y)a  
        Extract TLS x509 client certificate information from a Twisted stream transport, and
        return a dict with x509 TLS client certificate information (if the client provided a
        TLS client certificate).

        :param transport: The secure transport from which to extract the peer certificate (if present).
        :returns: If the peer provided a certificate, the parsed certificate information set.
        getPeerCertificateNc                 H    t        | t              r| j                  d      S | S )Nutf8)r)   bytesdecode)_values    r   maybe_bytesz-extract_peer_certificate.<locals>.maybe_bytes   s     fe,!==00!Mr   z{}md5sha1r>   )rP   rQ   r>   expiredhashserialsignature_algorithmversion
not_before	not_after
extensionsr   )r-   valuecriticalrY   subjectissuer)r   r%   hasattrrI   r&   r@   upperboolhas_expiredsubject_name_hashintget_serial_numberget_signature_algorithmget_versionget_notBeforeget_notAfterrangeget_extension_countget_extensionget_short_nameget_criticalappendget_subject
get_issuerget_componentslower)r    certrO   resultiextext_infoentityr-   keyrZ   s              r   r   r      s=    ((3	K_8`++-" {{;t{{5/A#BCIIKKF0C$DEKKM++k$++h2G&HIOOQ 0 0 23#D$:$:$<=d4467'243O3O3Q'Rt//12)$*<*<*>?():):)<= F 43356((+ KKC4F4F4H(IJ![[S)9: # 0 0 2a 7
 |$++H5 7 #,T-=-=-?!@8T__M^B_ `!#v"&"5"5"7JC%c*C'.E?C{{5?QF6N4;;s#3#9#9#;< #8 !a MM r   c                    t        |       }t        j                         }t        t        d      rt	        j
                         }nt	        j                         }d}t        rBt        j                  |       r-dt        | |d      i}t        j                  }t        |       }d}	ni }t        j                  }d}d}	t        j                  }
t        ||
||||||	||
      }|S )aB  
    Create transport details from Twisted transport.

    :param transport: The Twisted transport to extract information from.
    :param is_server: Flag indicating whether this transport side is a "server" (as in TCP server).
    :return: Transport details object filled with information from the Twisted transport.
    get_native_idr8   TNF)
channel_typechannel_framingpeerr2   own_pidown_tidown_fd	is_secure
channel_id	peer_cert)r   r.   getpidr^   	threadingr{   	get_ident_HAS_TLSr   r%   r   r   CHANNEL_TYPE_TLSr   CHANNEL_TYPE_TCPCHANNEL_FRAMING_WEBSOCKET)r    r2   r   r   r   r   r   r}   r   r   r~   tds               r   r   r     s     IDiikGy/* ))+%%'FM,,Y7 .y)\R

 (88,Y7		
'88		 '@@O	|_[_$-wX^$-*PY
[B Ir   )N)(r.   r=   r   typingr   r   r   r   twisted.internet.deferr   twisted.internet.addressr   r	   twisted.internet.interfacesr
   r   autobahn.wamp.typesr   twisted.internet.stdior   ImportErrorr9   r   r,   r   twisted.protocols.tlsr   OpenSSL.SSLr   r   __allr   strr   objectr`   rL   r   r   r   rG   r   r   <module>r      s  6 
   - - + = E 02
4I
9:&H	($j*;;< $ $N P P4 PRZ[^R_ Pkstykz P>y >y4 >yRZ[^R_ >ykstykz >yB F xS#X7O 4,@ 4XdSVX[S[nE] 4n(j:K.K(L (Y] (br (A  t*K  It*K  Hs4   C	 C C1 	CCC.-C.1C;:C;