File: //var/opt/nydus/ops/oscrypto/_mac/__pycache__/tls.cpython-39.pyc
a
�,�h�� �
@ sz d dl mZmZmZmZ d dlZd dlZd dlZd dlZ d dl
Z
d dlZd dlZd dl
Z
ddlmZmZmZmZ ddlmZmZmZ ddlmZmZmZ ddlmZ dd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, dd
l-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 dd
l6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZM ddlNmOZOmZ ddlPmQZQ ejRdk �r�eSZTejRdk �r�ejUZVnejVZVddgZWejXejYejZej[ej\d�Z]ejXdejYdejZdej[dej\diZ^e�_d�Z`e�_d�Zae
�b� Zci Zddd� Zedd � Zfd!d"� Zge#ed#ee�Zhe#ed$eg�ZiG d%d� dej�ZkG d&d� dej�ZldS )'� )�unicode_literals�division�absolute_import�print_functionN� )�Security�osx_version_info�handle_sec_error�
SecurityConst)�CoreFoundation�handle_cf_error� CFHelpers� )�Certificate�int_to_bytes�timezone)�pretty_message)�array_from_pointer� array_set�buffer_from_bytes�bytes_from_buffer�callback�cast�deref�new�null�pointer_set�struct�struct_bytes�unwrap�write_to_buffer)� type_name�str_cls�byte_cls� int_types)�CIPHER_SUITE_MAP)�
rand_bytes)�TLSError�TLSDisconnectError�TLSGracefulDisconnectError)�detect_client_auth_request�detect_other_protocol�
extract_chain�get_dh_params_length�parse_session_info�raise_client_auth�raise_dh_params�raise_disconnection�raise_expired_not_yet_valid�raise_handshake�raise_hostname�raise_lifetime_too_long�raise_no_issuer�raise_protocol_error�raise_protocol_version�
raise_revoked�raise_self_signed�raise_verification�raise_weak_signature)�load_certificater )�parse_certificate)� )r? � �
TLSSession� TLSSocket)�SSLv2�SSLv3�TLSv1�TLSv1.1�TLSv1.2rC rD rE rF rG s (
|
|
)zGanon|PSK|SEED|RC4|MD5|NULL|CAMELLIA|ARIA|SRP|KRB5|EXPORT|(?<!3)DES|IDEAc
C s` d}�zt �| �}|s"t�| �}n|j}|s6|s6W dS t|�}|�� }d}d}z�t|�|k r�|dur�|dkr�t�|gg g |�\} }
}
t| �dkr�t� t
jd��|�|t|� �}||7 }|dkrPt|�dkr�|du r�t
jW W S t
jW W S q�qPW n. tj �y } z|j
}W Y d}~n
d}~0 0 |du�r\|t
jk�r\|t
jk�sL|t
jk�rTt
jW S t
jW S |�r�|j�s�t|�dk�r�t|j�dk�r�|dd� tdd g�v }
|dd� tg d
��v }|
�r�|�s�| j|t|� 7 _t
jW S | j|7 _t||� t|t|�� t|�|k�rt
jW S W dS t�yZ } z|�r@||_t
jW Y d}~S d}~0 0 dS )a�
Callback called by Secure Transport to actually read the socket
:param connection_id:
An integer identifying the connection
:param data_buffer:
A char pointer FFI type to write the data to
:param data_length_pointer:
A size_t pointer FFI type of the amount of data to read. Will be
overwritten with the amount of data read on return.
:return:
An integer status code of the result - 0 for success
Nr � � z timed outr? r � � )s s s s s )�_connection_refs�get�_socket_refs�_socketr �
gettimeout�len�select�socket_�error�errno�EAGAIN�recvr
�errSSLClosedNoNotify�errSSLClosedAbort�
ECONNRESET�EPIPE�_done_handshake�
_server_hello�set�_read_remaining�errSSLProtocolr r �errSSLWouldBlock�KeyboardInterrupt�
_exception)�
connection_id�data_buffer�data_length_pointer�self�socketZbytes_requested�timeoutrT �data�
read_ready�_�chunk�eZvalid_record_typeZvalid_protocol_version� ro �B/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/oscrypto/_mac/tls.py�_read_callbackf sb
rq c C s^ d}| � � }z@z| �d� || �d�7 }W n tjy> Y n0 W | �|� n| �|� 0 |S )z�
Reads everything available from the socket - used for debugging when there
is a protocol error
:param socket:
The socket to read from
:return:
A byte string of the remaining data
rH rI � )rP �
settimeoutrW rS rT )rh �outputZold_timeoutro ro rp r_ � s
r_ c
C s& z�t �| �}|st�| �}n|j}|s0|s0W dS t|�}t||�}|rZ|jsZ| j|7 _d}z|�|�}W n, t j
y� } z| j}W Y d} ~ n
d} ~ 0 0 |dur�|tjkr�|tj
ks�|tjkr�tjW S tjW S ||kr�t||� tjW S W dS t�y } z| |_tjW Y d} ~ S d} ~ 0 0 dS )a�
Callback called by Secure Transport to actually write to the socket
:param connection_id:
An integer identifying the connection
:param data_buffer:
A char pointer FFI type containing the data to write
:param data_length_pointer:
A size_t pointer FFI type of the amount of data to write. Will be
overwritten with the amount of data actually written on return.
:return:
An integer status code of the result - 0 for success
r N)rL rM rN rO r r r\ �
_client_hello�sendrS rT rU rV rZ r[ r
rX rY r ra rb rc ZerrSSLPeerUserCancelled)
rd re rf rg rh Zdata_lengthrj rT �sentrn ro ro rp �_write_callback� s6
rx ZSSLReadFuncZSSLWriteFuncc @ s. e Zd ZdZdZdZdZdZdZddd�Z dS )rA zj
A TLS session object that multiple TLSSocket objects can share for the
sake of session reuse
NFc C sN t |t�sttdt|����|| _|du r6tg d��}t |t�rLt|g�}nt |t�shttdt|����|tg d�� }|r�ttdt |����|| _
g | _|�r@|D ]�}t |t�r�|j
}nxt |t�r�t|�}ndt |t��rt|d��}t|�� �}W d � n1 �s0 Y nt |t��s2ttdt|����| j�|� q�td �| _dS )
a]
:param protocol:
A unicode string or set of unicode strings representing allowable
protocols to negotiate with the server:
- "TLSv1.2"
- "TLSv1.1"
- "TLSv1"
- "SSLv3"
Default is: {"TLSv1", "TLSv1.1", "TLSv1.2"}
:param manual_validation:
If certificate and certificate path validation should be skipped
and left to the developer to implement
:param extra_trust_roots:
A list containing one or more certificates to be treated as trust
roots, in one of the following formats:
- A byte string of the DER encoded certificate
- A unicode string of the certificate filename
- An asn1crypto.x509.Certificate object
- An oscrypto.asymmetric.Certificate object
:raises:
ValueError - when any of the parameters contain an invalid value
TypeError - when any of the parameters are of the wrong type
OSError - when an error is returned by the OS crypto library
zM
manual_validation must be a boolean, not %s
N)rE rF rG zu
protocol must be a unicode string or set of unicode strings,
not %s
)rD rE rF rG z�
protocol must contain only the unicode strings "SSLv3", "TLSv1",
"TLSv1.1", "TLSv1.2", not %s
�rbz�
extra_trust_roots must be a list of byte strings, unicode
strings, asn1crypto.x509.Certificate objects or
oscrypto.asymmetric.Certificate objects, not %s
� )�
isinstance�bool� TypeErrorr r! �_manual_validationr^ r"