Your IP : 3.140.195.8


Current Path : /opt/alt/python36/lib64/python3.6/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/__pycache__/ssl.cpython-36.opt-2.pyc

3

��2a���@sdddlZddlZddlZddlZddlZddlmZddlmZ	m
ZmZ
ddlZddlmZmZmZddlmZmZmZddlmZmZmZmZmZmZddlmZmZddlmZm Z m!Z!m"Z"ydd	lm#Z#Wne$k
r�YnXdd
lm%Z%m&Z&m'Z'm(Z(m)Z)ddlm*Z*ej+de,d
d�ed�e
j+de,dd�ed�ej+de,dd�ed�ej+de,dd�ed�e
j+de,dd�ed�ej+de,dd�ed�e-j.Z/e-_/dd�e-j0j1�D�Z2e3e-dd�Z4ej5dk�r�ddlm6Z6m7Z7ddl8m8Z8m9Z9m:Z:m;Z;dd l8m<Z<m=Z=ddl>Z>ddl?Z?ddl@Z@eAZBejC�r.d!gZDngZDd"ZEd#ZFGd$d%�d%eG�ZHdRd'd(�ZId)d*�ZJd+d,�ZKed-d.�ZLd/d0�ZMGd1d2�d2ed2d3��ZNGd4d5�d5eNe	�ZOGd6d7�d7e�ZPeOjQfdddd8�d9d:�ZRe.fdd;eOjQdddddd<�d=d>�ZSeRZTeSZUGd?d@�d@�ZVGdAdB�dBe8�ZWddd;eXe.ddCdCdf	dDdE�ZYdFdG�ZZdHZ[dIZ\dJdK�Z]dLdM�Z^e.dfdNdO�Z_dPdQ�Z`dS)S�N)�
namedtuple)�Enum�IntEnum�IntFlag)�OPENSSL_VERSION_NUMBER�OPENSSL_VERSION_INFO�OPENSSL_VERSION)�_SSLContext�	MemoryBIO�
SSLSession)�SSLError�SSLZeroReturnError�SSLWantReadError�SSLWantWriteError�SSLSyscallError�SSLEOFError)�txt2obj�nid2obj)�RAND_status�RAND_add�
RAND_bytes�RAND_pseudo_bytes)�RAND_egd)�HAS_SNI�HAS_ECDH�HAS_NPN�HAS_ALPN�HAS_TLSv1_3)�_OPENSSL_API_VERSION�
_SSLMethodcCs|jd�o|dkS)NZ	PROTOCOL_�PROTOCOL_SSLv23)�
startswith)�name�r#�(/opt/alt/python36/lib64/python3.6/ssl.py�<lambda>|sr%)�source�OptionscCs
|jd�S)NZOP_)r!)r"r#r#r$r%�sZAlertDescriptioncCs
|jd�S)NZALERT_DESCRIPTION_)r!)r"r#r#r$r%�sZSSLErrorNumbercCs
|jd�S)NZ
SSL_ERROR_)r!)r"r#r#r$r%�s�VerifyFlagscCs
|jd�S)NZVERIFY_)r!)r"r#r#r$r%�s�
VerifyModecCs
|jd�S)NZCERT_)r!)r"r#r#r$r%�scCsi|]\}}||�qSr#r#)�.0r"�valuer#r#r$�
<dictcomp>�sr,ZPROTOCOL_SSLv2�win32)�enum_certificates�	enum_crls)�socket�AF_INET�SOCK_STREAM�create_connection)�
SOL_SOCKET�SO_TYPEz
tls-uniquez�TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:!aNULL:!eNULL:!MD5:!3DESz�TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:!aNULL:!eNULL:!MD5:!DSS:!RC4:!3DESc@seZdZdS)�CertificateErrorN)�__name__�
__module__�__qualname__r#r#r#r$r6�sr6�c	Cs�g}|sdS|jd�^}}|jd�}||kr<tdt|���|sP|j�|j�kS|dkrd|jd�n>|jd�sx|jd�r�|jtj|��n|jtj|�j	dd��x|D]}|jtj|��q�Wtj
d	d
j|�dtj�}|j
|�S)NF�.�*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)�split�countr6�repr�lower�appendr!�re�escape�replace�compile�join�
IGNORECASE�match)	Zdn�hostnameZ
max_wildcardsZpatsZleftmostZ	remainderZ	wildcardsZfragZpatr#r#r$�_dnsname_match�s&

rJcCstj|j��}||kS)N)�	ipaddress�
ip_address�rstrip)Zipname�host_ipZipr#r#r$�_ipaddress_matchsrOcCsP|std��ytj|�}Wntk
r2d}YnXg}|jdf�}xb|D]Z\}}|dkr||dkrpt||�rpdS|j|�qJ|dkrJ|dk	r�t||�r�dS|j|�qJW|s�xF|jdf�D]6}x0|D](\}}|dkr�t||�r�dS|j|�q�Wq�Wt|�dk�r td|d	j	t
t|��f��n,t|�dk�rDtd
||df��ntd��dS)
Nztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDZsubjectAltNameZDNSz
IP AddressZsubjectZ
commonNamer:z&hostname %r doesn't match either of %sz, zhostname %r doesn't match %rrz=no appropriate commonName or subjectAltName fields were found)�
ValueErrorrKrL�getrJrArO�lenr6rF�mapr?)�certrIrNZdnsnamesZsan�keyr+�subr#r#r$�match_hostnames>

rW�DefaultVerifyPathszQcafile capath openssl_cafile_env openssl_cafile openssl_capath_env openssl_capathcCsdtj�}tjj|d|d�}tjj|d|d�}ttjj|�rF|ndtjj|�rX|ndf|��S)Nrr:��)	�_ssl�get_default_verify_paths�os�environrQrX�path�isfile�isdir)�parts�cafile�capathr#r#r$r\Usr\cs@eZdZfZ�fdd�Ze�fdd��Ze�fdd��Z�ZS)�_ASN1Objectcst�j|ft|dd���S)NF)r")�super�__new__�_txt2obj)�cls�oid)�	__class__r#r$rghsz_ASN1Object.__new__cst�j|ft|���S)N)rfrg�_nid2obj)riZnid)rkr#r$�fromnidksz_ASN1Object.fromnidcst�j|ft|dd���S)NT)r")rfrgrh)rir")rkr#r$�fromnameqsz_ASN1Object.fromname)	r7r8r9�	__slots__rg�classmethodrmrn�
__classcell__r#r#)rkr$recsreznid shortname longname oidc@seZdZdZdZdS)�Purposez1.3.6.1.5.5.7.3.1z1.3.6.1.5.5.7.3.2N)r7r8r9�SERVER_AUTH�CLIENT_AUTHr#r#r#r$rrxsrrcs�eZdZd!Zd"Zefdd�Zefdd�Zd#dd
�Zd$dd�Z	dd�Z
dd�Zdd�Ze
jfdd�Ze�fdd��Zej�fdd��Ze�fdd��Zej�fdd��Ze�fdd��Zej�fd d��Z�ZS)%�
SSLContext�protocol�__weakref__�CA�ROOTcOs"tj||�}|tkr|jt�|S)N)r	rg�_SSLv2_IF_EXISTS�set_ciphers�_DEFAULT_CIPHERS)rirv�args�kwargs�selfr#r#r$rg�s
zSSLContext.__new__cCs
||_dS)N)rv)rrvr#r#r$�__init__�szSSLContext.__init__FTNc	Cst|||||||d�S)N)�sock�server_side�do_handshake_on_connect�suppress_ragged_eofs�server_hostname�_context�_session)�	SSLSocket)rr�r�r�r�r��sessionr#r#r$�wrap_socket�s
zSSLContext.wrap_socketcCs|j||||d�}t||d�S)N)r�r�)r�)Z	_wrap_bio�	SSLObject)rZincomingZoutgoingr�r�r��sslobjr#r#r$�wrap_bio�s
zSSLContext.wrap_biocCsdt�}xN|D]F}t|d�}t|�dks2t|�dkr:td��|jt|��|j|�qW|j|�dS)N�asciir�z(NPN protocols must be 1 to 255 in length)�	bytearray�bytesrRrrA�extendZ_set_npn_protocols)r�
npn_protocols�protosrv�br#r#r$�set_npn_protocols�s

zSSLContext.set_npn_protocolscCsdt�}xN|D]F}t|d�}t|�dks2t|�dkr:td��|jt|��|j|�qW|j|�dS)Nr�rr�z)ALPN protocols must be 1 to 255 in length)r�r�rRrrAr�Z_set_alpn_protocols)rZalpn_protocolsr�rvr�r#r#r$�set_alpn_protocols�s

zSSLContext.set_alpn_protocolscCszt�}y@x:t|�D].\}}}|dkr|dks6|j|kr|j|�qWWntk
rdtjd�YnX|rv|j|d�|S)NZx509_asnTz-unable to enumerate Windows certificate store)�cadata)r�r.rjr��PermissionError�warnings�warn�load_verify_locations)r�	storename�purposeZcertsrT�encodingZtrustr#r#r$�_load_windows_store_certs�sz$SSLContext._load_windows_store_certscCsDt|t�st|��tjdkr8x|jD]}|j||�q$W|j�dS)Nr-)�
isinstancere�	TypeError�sys�platform�_windows_cert_storesr�Zset_default_verify_paths)rr�r�r#r#r$�load_default_certs�s

zSSLContext.load_default_certscstt�j�S)N)r'rf�options)r)rkr#r$r��szSSLContext.optionscsttt�jj||�dS)N)rfrur��__set__)rr+)rkr#r$r��scstt�j�S)N)r(rf�verify_flags)r)rkr#r$r��szSSLContext.verify_flagscsttt�jj||�dS)N)rfrur�r�)rr+)rkr#r$r��scs*t�j}yt|�Stk
r$|SXdS)N)rf�verify_moder)rP)rr+)rkr#r$r��s
zSSLContext.verify_modecsttt�jj||�dS)N)rfrur�r�)rr+)rkr#r$r��s)rvrw)rxry)FTTNN)FNN)r7r8r9ror��PROTOCOL_TLSrgr�r�r�r�r�r�rrrsr��propertyr��setterr�r�rqr#r#)rkr$rus(

ru)rcrdr�cCszt|t�st|��tt�}|tjkr2t|_d|_	n|tj
krF|jt�|sR|sR|rb|j
|||�n|jtkrv|j|�|S)NT)r�rer�rur�rrrs�
CERT_REQUIREDr��check_hostnamertr{�_RESTRICTED_SERVER_CIPHERSr��	CERT_NONEr�)r�rcrdr��contextr#r#r$�create_default_context�s





r�F)�	cert_reqsr�r��certfile�keyfilercrdr�c
Cs�t|t�st|��t|�}	|dk	r(||	_||	_|r@|r@td��|sH|rT|	j||�|s`|s`|rp|	j|||�n|	jt	kr�|	j
|�|	S)Nzcertfile must be specified)r�rer�rur�r�rP�load_cert_chainr�r�r�)
rvr�r�r�r�r�rcrdr�r�r#r#r$�_create_unverified_contexts



r�c@s�eZdZd/dd�Zedd��Zejdd��Zedd��Zejd	d��Zed
d��Zedd
��Z	edd��Z
d0dd�Zdd�Zd1dd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd2d)d*�Zd+d,�Zd-d.�ZdS)3r�NcCs&||_|p||j_|dk	r"||j_dS)N)�_sslobj�ownerr�)rr�r�r�r#r#r$r�GszSSLObject.__init__cCs|jjS)N)r�r�)rr#r#r$r�NszSSLObject.contextcCs||j_dS)N)r�r�)r�ctxr#r#r$r�SscCs|jjS)N)r�r�)rr#r#r$r�WszSSLObject.sessioncCs||j_dS)N)r�r�)rr�r#r#r$r�\scCs|jjS)N)r��session_reused)rr#r#r$r�`szSSLObject.session_reusedcCs|jjS)N)r�r�)rr#r#r$r�eszSSLObject.server_sidecCs|jjS)N)r�r�)rr#r#r$r�jszSSLObject.server_hostname�cCs(|dk	r|jj||�}n|jj|�}|S)N)r��read)rrR�buffer�vr#r#r$r�pszSSLObject.readcCs|jj|�S)N)r��write)r�datar#r#r$r�|szSSLObject.writeFcCs|jj|�S)N)r�Zpeer_certificate)r�binary_formr#r#r$�getpeercert�szSSLObject.getpeercertcCstjr|jj�SdS)N)r[rr��selected_npn_protocol)rr#r#r$r��szSSLObject.selected_npn_protocolcCstjr|jj�SdS)N)r[rr��selected_alpn_protocol)rr#r#r$r��sz SSLObject.selected_alpn_protocolcCs
|jj�S)N)r��cipher)rr#r#r$r��szSSLObject.ciphercCs
|jj�S)N)r��shared_ciphers)rr#r#r$r��szSSLObject.shared_cipherscCs
|jj�S)N)r��compression)rr#r#r$r��szSSLObject.compressioncCs
|jj�S)N)r��pending)rr#r#r$r��szSSLObject.pendingcCs4|jj�|jjr0|js td��t|j�|j�dS)Nz-check_hostname needs server_hostname argument)r��do_handshaker�r�r�rPrWr�)rr#r#r$r��s

zSSLObject.do_handshakecCs
|jj�S)N)r��shutdown)rr#r#r$�unwrap�szSSLObject.unwrap�
tls-uniquecCs0|tkrtd��|dkr&tdj|���|jj�S)Nz Unsupported channel binding typez
tls-uniquez({0} channel binding type not implemented)�CHANNEL_BINDING_TYPESrP�NotImplementedError�formatr�Z
tls_unique_cb)r�cb_typer#r#r$�get_channel_binding�szSSLObject.get_channel_bindingcCs
|jj�S)N)r��version)rr#r#r$r��szSSLObject.versioncCs
|jj�S)N)r��verify_client_post_handshake)rr#r#r$r��sz&SSLObject.verify_client_post_handshake)NN)r�N)F)r�)r7r8r9r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r#r#r#r$r�7s,


		
r�cs�eZdZddddeeddeeddddddddfdd�Zedd��Z	e	j
d	d��Z	ed
d��Zej
dd��Zed
d��Zdd�Z
dUdd�Zdd�ZdVdd�Zdd�ZdWdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdXd&d'�ZdYd(d)�Zd*d+�ZdZd,d-�Zd[�fd.d/�	Zd\d0d1�Zd]d2d3�Zd^d4d5�Zd_d6d7�Z d8d9�Z!d:d;�Z"d<d=�Z#d>d?�Z$d@dA�Z%dBdC�Z&dDdE�Z'd`dFdG�Z(dHdI�Z)dJdK�Z*dLdM�Z+dNdO�Z,dadQdR�Z-dSdT�Z.�Z/S)br�NFTrcCsj|r||_n�|r|rtd��|r0|r0td��|r>|r>|}t|�|_||j_|r`|jj|�|rr|jj||�|r�|jj|�|r�|jj|�||_||_	||_
||_||_||_
|jtt�tkr�td��|r�|r�td��|dk	r�td��|jjo�|�rtd��||_||_||_||_|
|_|dk	�rdtj||j|j|j|j�d�|j|j ��|j!�n,|dk	�r~tj||d�ntj||	|
|d	�y|j"�Wn8t#k
�r�}z|j$t$j%k�r��d
}WYdd}~XnXd}d
|_&d|_'||_(|�rfyN|jj)|||�}t*|||jd�|_'|�r>|j �}|d
k�r6td��|j+�Wn$t#tfk
�rd|j,��YnXdS)Nz5certfile must be specified for server-side operationszcertfile must be specifiedz!only stream sockets are supportedz4server_hostname can only be specified in client modez,session can only be specified in client modez'check_hostname requires server_hostname)�family�type�proto�fileno)r�)r�r�r�FT)r�r�gzHdo_handshake_on_connect should not be specified for non-blocking sockets)-r�rPrur�r�r�r�r{r�r�r��ssl_version�ca_certs�ciphersZ
getsockoptr4r5r2r�r�r�r�r�r�r�r0r�r�r�r�r��
settimeout�
gettimeout�detach�getpeername�OSError�errnoZENOTCONNZ_closedr��
_connected�_wrap_socketr�r��close)rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��eZ	connectedr��timeoutr#r#r$r��s�	








zSSLSocket.__init__cCs|jS)N)r�)rr#r#r$r�7szSSLSocket.contextcCs||_||j_dS)N)r�r�r�)rr�r#r#r$r�;scCs|jdk	r|jjSdS)N)r�r�)rr#r#r$r�@s
zSSLSocket.sessioncCs||_|jdk	r||j_dS)N)r�r�r�)rr�r#r#r$r�Fs
cCs|jdk	r|jjSdS)N)r�r�)rr#r#r$r�Ls
zSSLSocket.session_reusedcCstd|jj��dS)NzCan't dup() %s instances)r�rkr7)rr#r#r$�dupRsz
SSLSocket.dupcCsdS)Nr#)r�msgr#r#r$�_checkClosedVszSSLSocket._checkClosedcCs|js|j�dS)N)r�r�)rr#r#r$�_check_connectedZszSSLSocket._check_connected�cCst|j�|jstd��y|jj||�Stk
rn}z.|jdtkr\|jr\|dk	rVdSdSn�WYdd}~XnXdS)Nz'Read on closed or unwrapped SSL socket.r�)r�r�rPr�rr}Z
SSL_ERROR_EOFr�)rrRr��xr#r#r$r�bszSSLSocket.readcCs"|j�|jstd��|jj|�S)Nz(Write on closed or unwrapped SSL socket.)r�r�rPr�)rr�r#r#r$r�tszSSLSocket.writecCs|j�|j�|jj|�S)N)r�r�r�r�)rr�r#r#r$r�}szSSLSocket.getpeercertcCs*|j�|jstjrdS|jj�SdS)N)r�r�r[rr�)rr#r#r$r��szSSLSocket.selected_npn_protocolcCs*|j�|jstjrdS|jj�SdS)N)r�r�r[rr�)rr#r#r$r��sz SSLSocket.selected_alpn_protocolcCs |j�|jsdS|jj�SdS)N)r�r�r�)rr#r#r$r��szSSLSocket.ciphercCs|j�|jsdS|jj�S)N)r�r�r�)rr#r#r$r��szSSLSocket.shared_cipherscCs |j�|jsdS|jj�SdS)N)r�r�r�)rr#r#r$r��szSSLSocket.compressioncCsB|j�|jr0|dkr$td|j��|jj|�Stj|||�SdS)Nrz3non-zero flags not allowed in calls to send() on %s)r�r�rPrkr�r0�send)rr��flagsr#r#r$r��s
zSSLSocket.sendcCsH|j�|jrtd|j��n&|dkr4tj|||�Stj||||�SdS)Nz%sendto not allowed on instances of %s)r�r�rPrkr0�sendto)rr�Z
flags_or_addr�addrr#r#r$r��szSSLSocket.sendtocOstd|j��dS)Nz&sendmsg not allowed on instances of %s)r�rk)rr}r~r#r#r$�sendmsg�szSSLSocket.sendmsgcCs�|j�|jr�|dkr$td|j��d}t|��L}|jd��6}t|�}x&||krl|j||d��}||7}qHWWdQRXWdQRXntj	|||�SdS)Nrz6non-zero flags not allowed in calls to sendall() on %s�B)
r�r�rPrk�
memoryview�castrRr�r0�sendall)rr�r�r>ZviewZ	byte_view�amountr�r#r#r$r��s

"zSSLSocket.sendallcs,|jdkrt�j|||�S|j|||�SdS)N)r�rf�sendfileZ_sendfile_use_send)r�file�offsetr>)rkr#r$r��s
zSSLSocket.sendfilecCs@|j�|jr.|dkr$td|j��|j|�Stj|||�SdS)Nrz3non-zero flags not allowed in calls to recv() on %s)r�r�rPrkr�r0�recv)r�buflenr�r#r#r$r��s

zSSLSocket.recvcCsf|j�|r|dkrt|�}n|dkr*d}|jrR|dkrFtd|j��|j||�Stj||||�SdS)Nirz8non-zero flags not allowed in calls to recv_into() on %s)r�rRr�rPrkr�r0�	recv_into)rr��nbytesr�r#r#r$r��s

zSSLSocket.recv_intocCs0|j�|jrtd|j��ntj|||�SdS)Nz'recvfrom not allowed on instances of %s)r�r�rPrkr0�recvfrom)rr�r�r#r#r$r�s
zSSLSocket.recvfromcCs2|j�|jrtd|j��ntj||||�SdS)Nz,recvfrom_into not allowed on instances of %s)r�r�rPrkr0�
recvfrom_into)rr�r�r�r#r#r$rs
zSSLSocket.recvfrom_intocOstd|j��dS)Nz&recvmsg not allowed on instances of %s)r�rk)rr}r~r#r#r$�recvmsgszSSLSocket.recvmsgcOstd|j��dS)Nz+recvmsg_into not allowed on instances of %s)r�rk)rr}r~r#r#r$�recvmsg_intoszSSLSocket.recvmsg_intocCs |j�|jr|jj�SdSdS)Nr)r�r�r�)rr#r#r$r�s
zSSLSocket.pendingcCs|j�d|_tj||�dS)N)r�r�r0r�)rZhowr#r#r$r�szSSLSocket.shutdowncCs.|jr|jj�}d|_|Stdt|���dS)NzNo SSL wrapper around )r�r�rP�str)r�sr#r#r$r�s

zSSLSocket.unwrapcCs$|jr|jj�Stdt|���dS)NzNo SSL wrapper around )r�r�rPr)rr#r#r$r�$s
z&SSLSocket.verify_client_post_handshakecCsd|_tj|�dS)N)r�r0�_real_close)rr#r#r$r*szSSLSocket._real_closecCsF|j�|j�}z$|dkr(|r(|jd�|jj�Wd|j|�XdS)Ng)r�r�r�r�r�)r�blockr�r#r#r$r�.s
zSSLSocket.do_handshakecCs�|jrtd��|jrtd��|jj|d|j�}t|||jd�|_y>|rTt	j
||�}nd}t	j||�|s|d|_|jr||j
�|Sttfk
r�d|_�YnXdS)Nz!can't connect in server-side modez/attempt to connect already-connected SSLSocket!F)r�r�T)r�rPr�r�r�r�r�r�r�r0�
connect_ex�connectr�r�r�)rr�rr�Zrcr#r#r$�
_real_connect9s(zSSLSocket._real_connectcCs|j|d�dS)NF)r
)rr�r#r#r$r	RszSSLSocket.connectcCs|j|d�S)NT)r
)rr�r#r#r$rWszSSLSocket.connect_excCs.tj|�\}}|jj||j|jdd�}||fS)NT)r�r�r�)r0�acceptr�r�r�r�)rZnewsockr�r#r#r$r\szSSLSocket.accept�
tls-uniquecCs|jdkrdS|jj|�S)N)r�r�)rr�r#r#r$r�hs
zSSLSocket.get_channel_bindingcCs|jdkrdS|jj�S)N)r�r�)rr#r#r$r�qs
zSSLSocket.version)N)r�N)F)r)N)r)rN)r�r)Nr)r�r)Nr)F)r)0r7r8r9r�r�r1r2r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�r�r�r�rr�r
r	rrr�r�rqr#r#)rkr$r��s^Z

	












	r�Tc

Cst||||||||||	d�
S)N)
r�r�r�r�r�r�r�r�r�r�)r�)
r�r�r�r�r�r�r�r�r�r�r#r#r$r�{sr�c
Cs�ddlm}ddlm}d}d}y|j|dd�j��d}Wn$tk
rbtd||f��Yn0X||dd�|�}||d|f|dd��SdS)Nr)�strptime)�timegm�Jan�Feb�Mar�Apr�May�Jun�Jul�Aug�Sep�Oct�Nov�Decz %d %H:%M:%S %Y GMTrZr:z*time data %r does not match format "%%b%s"rY�)rrrrrrrrrrrr)Ztimer
Zcalendarr�index�titlerP)Z	cert_timer
rZmonthsZtime_formatZmonth_number�ttr#r#r$�cert_time_to_seconds�s
rz-----BEGIN CERTIFICATE-----z-----END CERTIFICATE-----cCs2ttj|�dd�}tdtj|d�dtdS)N�ASCII�strict�
�@)r�base64Zstandard_b64encode�
PEM_HEADER�textwrap�fill�
PEM_FOOTER)Zder_cert_bytes�fr#r#r$�DER_cert_to_PEM_cert�sr*cCs\|jt�stdt��|j�jt�s0tdt��|j�tt�tt��}tj|j	dd��S)Nz(Invalid PEM encoding; must start with %sz&Invalid PEM encoding; must end with %sr r!)
r!r%rP�strip�endswithr(rRr$Zdecodebytes�encode)Zpem_cert_string�dr#r#r$�PEM_cert_to_DER_cert�s
r/c
Csd|\}}|dk	rt}nt}t|||d�}t|��&}|j|��}|jd�}	WdQRXWdQRXt|	�S)N)r�rcT)r�r��_create_stdlib_contextr3r�r�r*)
r�r�r��hostZportr�r�r�ZsslsockZdercertr#r#r$�get_server_certificate�s
r2cCstj|d�S)Nz	<unknown>)�_PROTOCOL_NAMESrQ)Z
protocol_coder#r#r$�get_protocol_name�sr4)r:)arKr&rBr�r]�collectionsr�enumrZ_EnumrZ_IntEnumrZ_IntFlagr[rrrr	r
rrr
rrrrrrhrrlrrrrr�ImportErrorrrrrrr�_convertr7rr�r �__members__�itemsr3�getattrrzr�r.r/r0r1r2r3r4r5r$r�r�r�Zsocket_errorZHAS_TLS_UNIQUEr�r|r�rPr6rJrOrWrXr\rerrrursr�r�Z_create_default_https_contextr0r�r�r�r�rr%r(r*r/r2r4r#r#r#r$�<module>]s� 
14i%-
	


?>