o
    zqf&                     @   s<  U d dl Z d dlZd dlZd dlZd dlZd dlZddlmZmZm	Z	m
Z
 e dkr4ddlmZmZ ne dkrCddlmZmZ nddlmZmZ ejrTd dlmZ eeB e je B e je B Zejed< eeB ejg eeB f B Zejed	< dddZdddZG dd de
Zdejej B dedB d
dfddZ!dS )    N   )_original_SSLContext_original_super_SSLContext#_truststore_SSLContext_dunder_class"_truststore_SSLContext_super_classWindows)_configure_context_verify_peercerts_implDarwin)Buffer_StrOrBytesPath_PasswordTypereturnc                  C   sR   t tdt zddlm  m  m  m}  t | dt W dS  ty(   Y dS w )zqInjects the :class:`truststore.SSLContext` into the ``ssl``
    module by replacing :class:`ssl.SSLContext`.
    
SSLContextr   N)	setattrsslr   pip._vendor.urllib3.util.ssl__vendorurllib3utilssl_ImportErrorurllib3_ssl r   Z/root/parts/websockify/install/lib/python3.10/site-packages/pip/_vendor/truststore/_api.pyinject_into_ssl   s   r   c                  C   sL   t tdt zddlm  m  m  m}  t| _W dS  t	y%   Y dS w )z@Restores the :class:`ssl.SSLContext` class to its original stater   r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   extract_from_ssl.   s   r   c                   @   s  e Zd ZdZedefddZd[deddfddZ			
	
		d\de	j	de
de
de
dedB dejdB dejfddZ				d]dejdejde
dedB dejdB dejfddZ			d^deeB eje B eje B dB deeB eje B eje B dB dejeddf ddfddZ		d_dededB dedB ddfd d!Zejjfd"ejddfd#d$Zd%eje ddfd&d'Z d(eje ddfd)d*Z!d+eddfd,d-Z"dej#fd.d/Z$de%eef fd0d1Z&de%eef fd2d3Z'ej(	4d`d5ej)d	 de*ej# fd6d7Z+ej(d`d5ej)d
 de*e fd8d7Z+ej(d`d5e
dej#fd9d7Z+dad5e
de*ej# e*e B fd:d7Z+ede
fd;d<Z,e,j-d=e
ddfd>d<Z,ede
fd?d@Z.e.j-d=e
ddfdAd@Z.edefdBdCZ/e/j-d=eddfdDdCZ/edej0fdEdFZ1e1j-d=ej0ddfdGdFZ1edej0fdHdIZ2e2j-d=ej0ddfdJdIZ2edej3fdKdLZ4e4j-d=ej3ddfdMdLZ4ede
fdNdOZ5e5j-d=e
ddfdPdOZ5edej6fdQdRZ7edefdSdTZ8edej9fdUdVZ:e:j-d=ej9ddfdWdVZ:edej;fdXdYZ<e<j-d=ej;ddfdZdYZ<dS )br   z=SSLContext API that uses system certificates on all platformsr   c                 C   s   t ptS N)r   r   selfr   r   r   	__class__<   s   zSSLContext.__class__Nprotocolc                 C   s(   t || _G dd dtj}|| j_d S )Nc                       s   e Zd Zd fddZ  ZS )z0SSLContext.__init__.<locals>.TruststoreSSLObjectr   Nc                    s   t   }t| | jd |S )Nserver_hostname)superdo_handshake_verify_peercertsr$   )r    retr!   r   r   r&   K   s   
z=SSLContext.__init__.<locals>.TruststoreSSLObject.do_handshaker   N)__name__
__module____qualname__r&   __classcell__r   r   r)   r   TruststoreSSLObjectF   s    r/   )r   _ctxr   	SSLObjectsslobject_class)r    r"   r/   r   r   r   __init__C   s   

zSSLContext.__init__FTsockserver_sidedo_handshake_on_connectsuppress_ragged_eofsr$   sessionc              	   C   sn   t | j | jj||||||d}W d    n1 sw   Y  z	t||d W |S  ty6   |   w )N)r5   r$   r6   r7   r8   r#   )r   r0   wrap_socketr'   	Exceptionclose)r    r4   r5   r6   r7   r$   r8   ssl_sockr   r   r   r9   R   s"   	zSSLContext.wrap_socketincomingoutgoingc                 C   sF   t | j | jj|||||d}W d    |S 1 sw   Y  |S )N)r$   r5   r8   )r   r0   wrap_bio)r    r=   r>   r5   r$   r8   ssl_objr   r   r   r?   n   s   
zSSLContext.wrap_biocafilecapathcadatar   c                 C      | j j|||dS )N)rA   rB   rC   )r0   load_verify_locations)r    rA   rB   rC   r   r   r   rE         z SSLContext.load_verify_locationscertfilekeyfilepasswordc                 C   rD   )N)rG   rH   rI   )r0   load_cert_chain)r    rG   rH   rI   r   r   r   rJ      rF   zSSLContext.load_cert_chainpurposec                 C      | j |S r   )r0   load_default_certs)r    rK   r   r   r   rM      s   zSSLContext.load_default_certsalpn_protocolsc                 C   rL   r   )r0   set_alpn_protocols)r    rN   r   r   r   rO         zSSLContext.set_alpn_protocolsnpn_protocolsc                 C   rL   r   )r0   set_npn_protocols)r    rQ   r   r   r   rR      rP   zSSLContext.set_npn_protocols_SSLContext__cipherlistc                 C   rL   r   )r0   set_ciphers)r    rS   r   r   r   rT      rP   zSSLContext.set_ciphersc                 C   
   | j  S r   )r0   get_ciphersr   r   r   r   rV         
zSSLContext.get_ciphersc                 C   rU   r   )r0   session_statsr   r   r   r   rX      rW   zSSLContext.session_statsc                 C      t  r   NotImplementedErrorr   r   r   r   cert_store_stats      zSSLContext.cert_store_stats.binary_formc                 C      d S r   r   r    r^   r   r   r   get_ca_certs   s   zSSLContext.get_ca_certsc                 C   r_   r   r   r`   r   r   r   ra         c                 C   r_   r   r   r`   r   r   r   ra      rb   c                 C   rY   r   rZ   r`   r   r   r   ra      r]   c                 C      | j jS r   r0   check_hostnamer   r   r   r   re         zSSLContext.check_hostnamevaluec                 C      || j _d S r   rd   r    rg   r   r   r   re         c                 C   rc   r   r0   hostname_checks_common_namer   r   r   r   rl      rf   z&SSLContext.hostname_checks_common_namec                 C   rh   r   rk   ri   r   r   r   rl      rj   c                 C   rc   r   r0   keylog_filenamer   r   r   r   rn      rf   zSSLContext.keylog_filenamec                 C   rh   r   rm   ri   r   r   r   rn      rj   c                 C   rc   r   )r0   maximum_versionr   r   r   r   ro      rf   zSSLContext.maximum_versionc                 C      t j| j| d S r   )r   ro   __set__r0   ri   r   r   r   ro         c                 C   rc   r   )r0   minimum_versionr   r   r   r   rs      rf   zSSLContext.minimum_versionc                 C   rp   r   )r   rs   rq   r0   ri   r   r   r   rs      rr   c                 C   rc   r   )r0   optionsr   r   r   r   rt      rf   zSSLContext.optionsc                 C   rp   r   )r   rt   rq   r0   ri   r   r   r   rt      rr   c                 C   rc   r   r0   post_handshake_authr   r   r   r   rv      rf   zSSLContext.post_handshake_authc                 C   rh   r   ru   ri   r   r   r   rv      rj   c                 C   rc   r   )r0   r"   r   r   r   r   r"      rf   zSSLContext.protocolc                 C   rc   r   )r0   security_levelr   r   r   r   rw      rf   zSSLContext.security_levelc                 C   rc   r   )r0   verify_flagsr   r   r   r   rx     rf   zSSLContext.verify_flagsc                 C   rp   r   )r   rx   rq   r0   ri   r   r   r   rx     rr   c                 C   rc   r   )r0   verify_moder   r   r   r   ry     rf   zSSLContext.verify_modec                 C   rp   r   )r   ry   rq   r0   ri   r   r   r   ry     rr   r   )FTTNN)FNN)NNN)NN).)F)=r+   r,   r-   __doc__propertytyper!   intr3   socketboolstrr   
SSLSession	SSLSocketr9   	MemoryBIOr1   r?   bytesosPathLiketypingUnionrE   r   r   rJ   PurposeSERVER_AUTHrM   IterablerO   rR   rT   AnyrV   dictrX   r\   overloadLiterallistra   re   setterrl   rn   
TLSVersionro   rs   Optionsrt   rv   
_SSLMethodr"   rw   VerifyFlagsrx   
VerifyModery   r   r   r   r   r   9   s    
 



 "r   sock_or_sslobjr$   c                 C   sd   | }zt |ds|j}t |drW n	 ty   Y nw | p d}dd |D }t| j||d dS )z{
    Verifies the peer certificates from an SSLSocket or SSLObject
    against the certificates in the OS trust store.
    get_unverified_chainr   c                 S   s   g | ]}| tjqS r   )public_bytes_sslENCODING_DER).0certr   r   r   
<listcomp>+  s    z%_verify_peercerts.<locals>.<listcomp>r#   N)hasattr_sslobjAttributeErrorr   r	   context)r   r$   sslobjunverified_chain
cert_bytesr   r   r   r'     s   



r'   r*   )"r   platformr~   r   r   r   _ssl_constantsr   r   r   r   system_windowsr   r	   _macos_opensslTYPE_CHECKINGpip._vendor.typing_extensionsr   r   r   r   r   	TypeAlias__annotations__Callabler   r   r   r   r   r1   r'   r   r   r   r   <module>   s6   
 &$

 _
