
    af;5              
       L   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 n# e$ r  ed          ZY nw xY w	 d dl
mZ d	Zn# e$ r d
Z ed          ZY nw xY w	 d dlmZ d dlmZ d dlmZ d	Zn# e$ r d
ZY nw xY w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'dS )    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                 j    |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   ds      G/var/www/html/env/lib/python3.11/site-packages/autobahn/twisted/util.pyr   r   D   sF      -,,,,,,

AeQZ...H    	transportreturnc                    t          j        |           rd                    | j                  }nt	          j        |           r |                                 }t          |t                    r!d                    |j        |j	                  }nt          r6t          |t                    r!d                    |j        |j	                  }n{t          |t                    r%|j        rd                    |j                  }nDd}nAt          |t                    r'd                    t          j                              }nd}n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   s1    #I.. !!)-00		y	)	) JSJ[J[J]J]dK(( 	 ''	49==CC 	:dK88 	 ''	49==CCk** 	y  ''	22k** 	  &&rz||44CC CC Jr   	is_serverchannel_id_typec                 N    |dS t          d                    |                    )N                                    zUcannot determine TLS channel ID of type "{}" when TLS is not available on this system)RuntimeErrorr&   )r    r2   r3   s      r   r   r      s>    "<v}}  N   O   O  P  P  Pr   c                 l   |dS |dvr"t          d                    |                    t          | t                    s0t          d                    |t	          |                               |                                 }|rt          |t                    sJ d}|dk    ro||k    r|                                }n|                                }|dS t          j
                    }|                    |           |                                S t          d                    |                    )	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).
        Nr5   )
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      sJ   & "<.00KRRSbccddd)%9:: 	7mtt#T)__6 67 7 7 "+!4!4!6!6
@jZ@@@@@ l**N** $.#?#?#A#A   $.#:#:#<#< '
 $|N$$)***xxzz!%&_&f&fgv&w&wxxxr   c                     dS )z~
        Dummy when no TLS is available.

        :param transport: Ignored.
        :return: Always return ``None``.
        N )r    s    r   r   r      s	     tr   c                    t          j        |           rt          | d          sdS |                                 }|rd }d                     ||                    d                                                              d                     ||                    d                                                              d                     ||                    d                                                              t          |                                           ||	                                          t          |                                           ||                                          t          |                                           ||                                           ||                                          g d}t!          |                                          D ]}|                    |          }d                     ||                                                    d                     ||                    |                                d	k    d
}|d                             |           d|                                fd|                                ffD ]}\  }}i ||<   |                                D ]^\  }	}
 ||	          }	 ||
          }
d                    |
          ||         d                    |	                                          <   _~|S dS )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                 Z    t          | t                    r|                     d          S | S )Nutf8)r)   bytesdecode)_values    r   maybe_bytesz-extract_peer_certificate.<locals>.maybe_bytes   s+    fe,, "!==0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3 		K_8`8` 	4++-- &	" " " {{;;t{{5/A/A#B#BCCIIKKKKF0C0C$D$DEEKKMM++kk$++h2G2G&H&HIIOOQQ 0 0 2 233#D$:$:$<$<==d446677'2{43O3O3Q3Q'R'Rt//1122)k$*<*<*>*>??([):):)<)<==  F 4335566 6 6((++ KKC4F4F4H4H(I(IJJ![[S)9)9:: # 0 0 2 2a 7 
 |$++H5555"+T-=-=-?-?!@8T__M^M^B_ ` R R!#v"&"5"5"7"7 R RJC%+c**C'K..E?C{{5?Q?QF6N4;;s#3#3#9#9#;#;<<R
 MM&	 &	r   c                    t          |           }t          j                    }t          t          d          rt	          j                    }nt	          j                    }d}t          rEt          j	        |           r1d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ikkGy/** ( )++%''F M,Y77  .y)\RR

 (8,Y77			
'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 E E E E E E E 0 0 0 0 0 02222222   $t**KKK444444II   I$t**KKK999999::::::&&&&&&HH   HHH	   ($j*;;< $ $ $ $ $N  EyP P P4 PRZ[^R_ Pkstykz P P P P P>y >y >y4 >yRZ[^R_ >ykstykz >y >y >y >yB  >F xS#X7O     4,@ 4XdSVX[S[nE] 4 4 4 4n(j:K.K(L (Y] (br ( ( ( ( ( (s3   = AAA A21A26B BB