HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/oscrypto/_mac/__pycache__/tls.cpython-39.pyc
a

�,�h���
@szddlmZmZmZmZddlZddlZddlZddlZ	ddl
Z
ddlZddlZddl
Z
ddlmZmZmZmZddlmZmZmZddlmZmZmZddlmZdd	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/m0Z0m1Z1ddl2m3Z3ddl4m5Z5dd
l6m7Z7m8Z8m9Z9ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMddlNmOZOmZddlPmQZQejRdk�r�eSZTejRdk�r�ejUZVnejVZVddgZWejXejYejZej[ej\d�Z]ejXdejYdejZdej[dej\diZ^e�_d�Z`e�_d�Zae
�b�ZciZddd�Zedd �Zfd!d"�Zge#ed#ee�Zhe#ed$eg�ZiGd%d�dej�ZkGd&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.2rCrDrErFrGs(
|
|
)zGanon|PSK|SEED|RC4|MD5|NULL|CAMELLIA|ARIA|SRP|KRB5|EXPORT|(?<!3)DES|IDEAc
Cs`d}�zt�|�}|s"t�|�}n|j}|s6|s6WdSt|�}|��}d}d}z�t|�|kr�|dur�|dkr�t�|ggg|�\}	}
}
t|	�dkr�t�	t
jd��|�|t|��}||7}|dkrPt|�dkr�|dur�t
jWWSt
jWWSq�qPWn.tj	�y}z|j
}WYd}~n
d}~00|du�r\|t
jk�r\|t
jk�sL|t
jk�rTt
jWSt
jWS|�r�|j�s�t|�dk�r�t|j�dk�r�|dd�tdd	g�v}
|dd�tgd
��v}|
�r�|�s�|j|t|�7_t
jWS|j|7_t||�t|t|��t|�|k�rt
jWSWdSt�yZ}z|�r@||_t
jWYd}~Sd}~00dS)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��)sssss)�_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_callbackfsb



rqc	Cs^d}|��}z@z|�d�||�d�7}Wntjy>Yn0W|�|�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
    rHrI� )rP�
settimeoutrWrSrT)rh�outputZold_timeoutrororpr_�s
r_c

Cs&z�t�|�}|st�|�}n|j}|s0|s0WdSt|�}t||�}|rZ|jsZ|j|7_d}z|�|�}Wn,t	j
y�}	z|	j}WYd}	~	n
d}	~	00|dur�|tjkr�|tj
ks�|tjkr�tjWStjWS||kr�t||�tjWSWdSt�y }	z|	|_tjWYd}	~	Sd}	~	00dS)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
    rN)rLrMrNrOrrr\�
_client_hello�sendrSrTrUrVrZr[r
rXrYrrarbrcZerrSSLPeerUserCancelled)
rdrerfrgrhZdata_lengthrjrT�sentrnrororp�_write_callback�s6



rxZSSLReadFuncZSSLWriteFuncc@s.eZdZdZdZdZdZdZdZddd�Z	dS)rAzj
    A TLS session object that multiple TLSSocket objects can share for the
    sake of session reuse
    NFc	CsNt|t�sttdt|����||_|dur6tgd��}t|t�rLt|g�}nt|t�shttdt|����|tgd��}|r�ttdt	|����||_
g|_|�r@|D]�}t|t�r�|j
}nxt|t�r�t|�}ndt|t��rt|d��}t|���}Wd�n1�s0Ynt|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)rErFrGzu
                protocol must be a unicode string or set of unicode strings,
                not %s
                )rDrErFrGz�
                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�	TypeErrorrr!�_manual_validationr^r"�
ValueError�repr�
_protocols�_extra_trust_rootsrZasn1r#r>�open�read�Asn1Certificate�appendr&�_peer_id)rg�protocol�manual_validationZextra_trust_rootsZunsupported_protocolsZextra_trust_root�frororp�__init__ sN
�

��


.�zTLSSession.__init__)NFN)
�__name__�
__module__�__qualname__�__doc__r�Z_ciphersr~r�r�r�rorororprAsc@steZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdZdZdZdZdZed=dd��Zd>dd�Zd	d
�Zdd�Zd?d
d�Zdd�Zdd�Zdd�Zdd�Z dd�Z!d@dd�Z"dd�Z#dd�Z$dd �Z%d!d"�Z&d#d$�Z'e(d%d&��Z)e(d'd(��Z*e(d)d*��Z+e(d+d,��Z,e(d-d.��Z-e(d/d0��Z.e(d1d2��Z/e(d3d4��Z0e(d5d6��Z1e(d7d8��Z2e(d9d:��Z3d;d<�Z4dS)ArBz8
    A wrapper around a socket.socket that adds TLS
    NFcCs�t|tj�sttdt|����t|t�s:ttdt|����|dur^t|t�s^ttdt|����|dd|d�}||_||_	|�
�|S)az
        Takes an existing socket and adds TLS

        :param socket:
            A socket.socket object to wrap with TLS

        :param hostname:
            A unicode string of the hostname or IP the socket is connected to

        :param session:
            An existing TLSSession object to allow for session reuse, specific
            protocol or manual certificate validation

        :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
        zU
                socket must be an instance of socket.socket, not %s
                zK
                hostname must be a unicode string, not %s
                N�`
                session must be an instance of oscrypto.tls.TLSSession, not %s
                )�session)r{rSrhr}rr!r"rArO�	_hostname�
_handshake)�clsrh�hostnamer�Z
new_socketrororp�wrap�s(�
��zTLSSocket.wrap�
cCs�d|_d|_d|_d|_|dur0|dur0d|_n|t|t�sLttdt	|����t|t
�shttdt	|����|dur�t|tj�s�ttdt	|����t
�||f|�|_|j�|�|dur�t�}nt|t�s�ttdt	|����||_|jr�||_|��dS)a�
        :param address:
            A unicode string of the domain name or IP address to connect to

        :param port:
            An integer of the port number to connect to

        :param timeout:
            An integer timeout to use for the socket

        :param session:
            An oscrypto.tls.TLSSession object to allow for session reuse and
            controlling the protocols and validation performed
        FrHNzR
                    address must be a unicode string, not %s
                    zI
                    port must be an integer, not %s
                    zJ
                    timeout must be a number, not %s
                    r�)r\r]ru�_decrypted_bytesrOr{r"r}rr!r$�numbers�NumberrS�create_connectionrsrA�_sessionr�r�)rg�address�portrir�rororpr��sD
�
��
�zTLSSocket.__init__c\	Cs2d}d}d}d}d}d}d}d}�z��
z�tdkrXttd�}	t�d|	�}
t|
�t|	�}nt�t�tj	tj
�}t�|tt
�}
t|
�t|�d|_|t|j<|jt|j<t�||j�}
t|
�|j�d�}t�||t|��}
t|
�tdk�r|jjp�|jj}|jj�o|jj}
nd}|jj}
tdk�r|d	D]0}t|}||jjv}t�|||�}
t|
��q.|�r�t�|d�}
t|
�nhd
d�|jjD�}t|�}t |�}t�!||�}
t|
�t�"||�}
t|
�|�r�t�#|tj$d�}
t|
�ttd�}t�%||�}
t|
�t&|�}t'|d
�}t(td|�}t�)|||�}
t|
�t&|�}t*td||�}g}|D]<}t+|dd�}t,�-||�}t.�/|�du}|�rV|�0|��qVt|�}ttd|�}t1||�t(td|�} t�2|| |�}
t|
�|jj3|j�d�}!t�4||!t|!��}
t|
�t�5|�}"|j6du�r(|j6}#d|_6|#�|"tj7k�r^t�5|�}"|j6du�r(|j6}#d|_6|#��q(tdk�r�tdk�r�|
�o~|"dk}$n|
�o�|"tj8k}$|$�r�ttd�}%t�9||%�}
t|
�t|%�}t:�;|j�}&t�<d|&�}t=�>|&�}
t?|
�t@td�}'t|'�}(ttjA�|(_Bt'tjA�})t(td|)�|(_Cttd�}*t�DtjE|'t�|*�}
t|
�t|*�}ttd�}+t�F||+�}
t|
�t|+�}t@td�},t|,�}-tjG|-_HtjItjJB|-_KtL|,�}.t@td�}/t|/�}0t|.�|0_Bt'|.�}1t(td|1�|0_Ct�M||/�}
t|
�t@td�}2t|2�}3ttjN�|3_Bt'tjN�}4t(td|4�|3_Cttd�}5t�DtjE|2t�|5�}
t|
�t|5�}ttd�}6t�F||6�}
t|
�t|6�}t@td�}7t|7�}8tjO|8_Hd|8_PtL|7�}9t@td�}/t|/�}0t|9�|0_Bt'|9�}:t(td|:�|0_Ct�M||/�}
t|
�t:�Q|||g�}t�R||�}
t|
�|jj�rvg};g}<|jjD]$}=tS|=�}>|<�0|>�|;�0|>jT��qt�U|d�}
t|
�t:�Q|;�}?t�V||?�}
t|
�ttd�}@t�W||@�}
t|
�t&|@�}AtXtjYtjZg�}B|A|Bv�r�tj[}"n$t�5|�}"|"tj7k�r�t�5|�}"�q�d|_\tXtj[tj]tj^tj_tj`tjatjbg�}C|"|Cv�r�|�r*t=�>|�d}ttd�}%t�9||%�}
t|
�t|%�}ttd�}Dt�c||D�}
t&|D�}Etd|je�}Fd}Gd}Hd}Id}Jd}Kd}=d}L|F�r@|Fd}=tS|=�}M|Mjf}G|Etjgk}H|G�o�|Etjhk}K|Etjik}I|Etjjk}J|Etjkk}L|Etjlk}Ntdk�r@|=d d!}O|Od"jmjn}P|Od#jmjn}Qtojo�ptqjr�}R|Q|Rk}I|P|Rk}J|F�rj|FdjstXd$d%g�v�rjtt|Fd�|H�rxtu|=�|L�r�tv|=|j�nD|I�s�|J�r�tw|=�n.|K�r�tx|=�n|G�r�ty|=�n|N�r�tz|=�t{|je��r�t|�t}|=�|"tj~k�	rt{|je��	rt|�t�|"tj�k�	r t��|"tj�k�	r2t��|"tXtj�tj�g�v�	rf|jet�|j�7_et�|je�|"tXtj�tj�g�v�	r�|j\�	s�|jet�|j�7_et�|je��	r�t�|je�t��tdk�	r�t�|je�}S|Sdu�	r�|Sd&k�	r�t��|"tj7k}T|"tj8k}U|jj�
o|U}V|T�
s|V�
st|"t��||_�ttd'�}Wt��||W�}
t|
�t&|W�}t�||_�ttd(�}Xt��||X�}
t|
�t&|X�}Yt+|Ydd�}Zt,�-|Z|Z�|_�t�|je|j��}[|[d)|_�|[d*|_�|[d+|_�Wn`t�t�j�f�y|�r
tdk�
r�t��|�}
t|
�nt=�>|�}
t?|
�d|_�|����Yn0W|�r>t=�>|�}
t?|
�d}|�rZt=�>|�}
t?|
�d}|�rvt=�>|�}
t?|
�d}|�r�t=�>|�}
t?|
�d}|�r.t=�>|�d}n�|�r�t=�>|�}
t?|
�d}|�r�t=�>|�}
t?|
�d}|�r�t=�>|�}
t?|
�d}|�rt=�>|�}
t?|
�d}|�r,t=�>|�d}0dS),z2
        Perform an initial TLS handshake
        N�r�rzzSSLContextRef *Fi���zutf-8)r�r�T)rCrDrEcSsg|]}t|�qSro)�_PROTOCOL_STRING_CONST_MAP)�.0r�rororp�
<listcomp>_rHz(TLSSocket._handshake.<locals>.<listcomp>�size_t *�z
uint32_t *Zuint32_tr)�widthz
uint32_t[])r�r@r�
SecTrustRef *ZCSSM_OIDzchar *zSecPolicySearchRef *zSecPolicyRef *ZCSSM_APPLE_TP_OCSP_OPTIONSZ	CSSM_DATAZCSSM_APPLE_TP_CRL_OPTIONSzSecTrustResultType *z
OSStatus *)r��Ztbs_certificate�validity�
not_before�	not_after�md5Zmd2iz
SSLProtocol *zSSLCipherSuite *�compression�
session_id�session_ticket)�rrrZ
SSLNewContextr	rZSSLCreateContextrr
ZkSSLClientSideZkSSLStreamTypeZ
SSLSetIOFuncs�_read_callback_pointer�_write_callback_pointer�id�_connection_idrLrOrNZSSLSetConnectionr��encodeZSSLSetPeerDomainNamerQr�r~r�r�r�ZSSLSetProtocolVersionEnabledZSSLSetEnableCertVerify�min�maxZSSLSetProtocolVersionMinZSSLSetProtocolVersionMaxZSSLSetSessionOptionZ"kSSLSessionOptionBreakOnServerAuthZSSLGetNumberSupportedCiphersrrrZSSLGetSupportedCiphersrrr%rM�_cipher_blacklist_regex�searchr�rZSSLSetEnabledCiphersr�ZSSLSetPeerIDZSSLHandshakercraZerrSSLServerAuthCompleted�SSLCopyPeerTrustr
Zcf_string_from_unicodeZSecPolicyCreateSSLr�	CFReleaserrZAPPLE_TP_REVOCATION_OCSPZLengthZDataZSecPolicySearchCreateZCSSM_CERT_X_509v3ZSecPolicySearchCopyNextZCSSM_APPLE_TP_OCSP_OPTS_VERSION�VersionZCSSM_TP_ACTION_OCSP_DISABLE_NETZ&CSSM_TP_ACTION_OCSP_CACHE_READ_DISABLE�FlagsrZSecPolicySetValueZAPPLE_TP_REVOCATION_CRLZCSSM_APPLE_TP_CRL_OPTS_VERSIONZCrlFlagsZcf_array_from_listZSecTrustSetPoliciesr=�sec_certificate_refZ!SecTrustSetAnchorCertificatesOnlyZSecTrustSetAnchorCertificatesZSecTrustEvaluater^ZkSecTrustResultProceedZkSecTrustResultUnspecifiedZerrSSLXCertChainInvalidr\ZerrSSLCertExpiredZerrSSLCertNotYetValidZerrSSLUnknownRootCertZerrSSLNoRootCertZerrSSLHostNameMismatchZerrSSLInternalZSecTrustGetCssmResultCoder,r]�self_signedZCSSMERR_TP_CERT_REVOKEDZCSSMERR_TP_NOT_TRUSTEDZCSSMERR_TP_CERT_EXPIREDZCSSMERR_TP_CERT_NOT_VALID_YETZ!CSSMERR_APPLETP_HOSTNAME_MISMATCHZCSSMERR_TP_CERT_SUSPENDEDZchosenZnative�datetime�nowr�utcZ	hash_algor<r9r4r2r6r:r5r*r/r;ZerrSSLPeerHandshakeFailr3ZerrSSLWeakPeerEphemeralDHKeyr0ZerrSSLPeerProtocolVersionr8ZerrSSLRecordOverflowr`r_r7rXrYr+r1r-r'�_session_contextZSSLGetNegotiatedProtocolVersion�_PROTOCOL_CONST_STRING_MAP�	_protocolZSSLGetNegotiatedCipher�
_cipher_suiter.ru�_compression�_session_id�_session_ticket�OSErrorrSrT�SSLDisposeContext�close)\rgZsession_contextZssl_policy_refZcrl_search_refZcrl_policy_refZocsp_search_refZocsp_policy_refZpolicy_array_ref�	trust_refZsession_context_pointer�resultZutf8_domainZdisable_auto_validationZexplicit_validationr�Zprotocol_const�enabledZprotocol_constsZmin_protocolZmax_protocolZsupported_ciphers_pointerZsupported_ciphersZ
cipher_bufferZsupported_cipher_suites_pointerZsupported_cipher_suitesZgood_ciphersZsupported_cipher_suite�cipher_suiteZcipher_suite_nameZgood_cipherZnum_good_ciphersZgood_ciphers_arrayZgood_ciphers_pointerZpeer_idZhandshake_result�	exceptionZ
do_validation�trust_ref_pointerZcf_string_hostnameZocsp_oid_pointerZocsp_oidZocsp_oid_bufferZocsp_search_ref_pointerZocsp_policy_ref_pointerZocsp_struct_pointerZocsp_structZocsp_struct_bytesZcssm_data_pointerZ	cssm_dataZocsp_struct_bufferZcrl_oid_pointerZcrl_oidZcrl_oid_bufferZcrl_search_ref_pointerZcrl_policy_ref_pointerZcrl_struct_pointerZ
crl_structZcrl_struct_bytesZcrl_struct_bufferZca_cert_refs�ca_certs�certZca_certZ	array_refZresult_pointerZtrust_result_codeZinvalid_chain_error_codesZhandshake_error_codesZresult_code_pointerZresult_code�chainr�ZrevokedZexpiredZ
not_yet_validZ	no_issuerZbad_hostnameZ
oscrypto_certZvalidity_too_longr�r�r��utcnowZdh_params_lengthZwould_blockZserver_auth_completer�Zprotocol_const_pointerZcipher_int_pointerZ
cipher_intZcipher_bytesZsession_inforororpr�s 

��
�


�
���
��
�


�



�

��




�



�



�

�


�


















�

��











�




zTLSSocket._handshakec
Cslt|t�sttdt|����|jdurH|jdkr@|j}d|_|S|��t|j�}||kr||jd|�}|j|d�|_|S|dkr�|�	d�s�|j}d|_|S|t|j�}t
|�}ttd�}t�
|j|||�}|jdur�|j}d|_|�|�r|ttjtjg�v�rt|t�|�r:|tjk�r:d|_|�d�|��t|�}	|jt||	�}||d�|_|d|�S)a
        Reads data from the TLS-wrapped socket

        :param max_length:
            The number of bytes to read - output may be less than this

        :raises:
            socket.socket - when a non-TLS socket error occurs
            oscrypto.errors.TLSError - when a TLS-related error occurs
            oscrypto.errors.TLSDisconnectError - when the connection disconnects
            oscrypto.errors.TLSGracefulDisconnectError - when the remote end gracefully closed the connection
            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

        :return:
            A byte string of the data read
        zG
                max_length must be an integer, not %s
                NrHrr�TF)r{r$r}rr!r�r��
_raise_closedrQ�select_readrrrZSSLReadrcr^r
raZerrSSLClosedGracefulr	r'�_gracefully_closed�	_shutdownrr)
rg�
max_lengthrtZbuffered_length�to_readZread_buffer�processed_pointerr�r��
bytes_readrororpr��sV
�



�


zTLSSocket.readcCs8t|j�dkrdSt�|jggg|�\}}}t|�dkS)aZ
        Blocks until the socket is ready to be read from, or the timeout is hit

        :param timeout:
            A float - the period of time to wait for data to be read. None for
            no time limit.

        :return:
            A boolean - if data is ready to be read. Will only be False if
            timeout is not None.
        rT)rQr�rRrO)rgrirkrlrororpr�QszTLSSocket.select_readc
Cs�t|t�s&t|t�s&ttdt|����d}t|t�}t|j�dkrP|j}d|_n|��pZd}|�	|�}t|�}||7}|r�|�
|�}|dur�|��}q�q4td|t|�d�}	|�
||	�}|dkr4|t|�}q�q4||d�|j|_|d|�S)a�
        Reads data from the socket until a marker is found. Data read includes
        the marker.

        :param marker:
            A byte string or regex object from re.compile(). Used to determine
            when to stop reading. Regex objects are more inefficient since
            they must scan the entire byte string of read data each time data
            is read off the socket.

        :return:
            A byte string of the data read, including the marker
        z_
                marker must be a byte string or compiled regex object, not %s
                rHrrrNr���)r{r#�Patternr}rr!rQr��_os_buffered_sizer�r��endr��find)
rg�markerrt�is_regexrmr��offset�matchr��startrororp�
read_untiles4�


zTLSSocket.read_untilcCs(ttd�}t�|j|�}t|�t|�S)a
        Returns the number of bytes of decrypted data stored in the Secure
        Transport read buffer. This amount of data can be read from SSLRead()
        without calling self._socket.recv().

        :return:
            An integer - the number of available bytes
        r�)rrZSSLGetBufferedReadSizer�r	r)rgZnum_bytes_pointerr�rororpr��s

�zTLSSocket._os_buffered_sizecCs
|�t�S)z�
        Reads a line from the socket, including the line ending of "\r\n", "\r",
        or "\n"

        :return:
            A byte string of the next line from the socket
        )r��_line_regex�rgrororp�	read_line�s	zTLSSocket.read_linecCs0d}|}|dkr,||�|�7}|t|�}q|S)z�
        Reads exactly the specified number of bytes from the socket

        :param num_bytes:
            An integer - the exact number of bytes to read

        :return:
            A byte string of the data that was read
        rHr)r�rQ)rg�	num_bytesrt�	remainingrororp�read_exactly�szTLSSocket.read_exactlycCs�|jdur|��ttd�}t|�}|r�t|�}t�|j|||�}|jdur\|j}d|_|�t|t	�t
|�}||d�}t|�}|dkr$|��q$dS)a�
        Writes data to the TLS-wrapped socket

        :param data:
            A byte string to write to the socket

        :raises:
            socket.socket - when a non-TLS socket error occurs
            oscrypto.errors.TLSError - when a TLS-related error occurs
            oscrypto.errors.TLSDisconnectError - when the connection disconnects
            oscrypto.errors.TLSGracefulDisconnectError - when the remote end gracefully closed the connection
            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
        Nr�r)r�r�rrrQrZSSLWritercr	r'r�select_write)rgrjr��data_lenZwrite_bufferr�r�Z
bytes_writtenrororp�write�s,

�

zTLSSocket.writecCs&t�g|jgg|�\}}}t|�dkS)aw
        Blocks until the socket is ready to be written to, or the timeout is hit

        :param timeout:
            A float - the period of time to wait for the socket to be ready to
            written to. None for no time limit.

        :return:
            A boolean - if the socket is ready for writing. Will only be False
            if timeout is not None.
        r)rRrOrQ)rgrirlZwrite_readyrororpr��s
zTLSSocket.select_writecCs�|jdurdSt�|j�}tdkr8t�|j�}t|�nt�|j�}t|�d|_|r\d|_	z|j
�tj
�Wntjy�Yn0dS)z�
        Shuts down the TLS session and then shuts down the underlying socket

        :param manual:
            A boolean if the connection was manually shutdown
        Nr�T)r�rZSSLCloserr�r	rr�r�
_local_closedrO�shutdownrS�	SHUT_RDWRrT)rgZmanualr�rororpr�	s

zTLSSocket._shutdowncCs|�d�dS)zV
        Shuts down the TLS session and then shuts down the underlying socket
        TN)r�r�rororpr�(szTLSSocket.shutdowncCs�zN|��W|jr<z|j��Wntjy4Yn0d|_|jtvr�t|j=nD|jr�z|j��WntjyxYn0d|_|jtvr�t|j=0dS)zN
        Shuts down the TLS session and socket and forcibly closes it
        N)r�rOr�rSrTr�rNr�rororpr�/s$


�
zTLSSocket.closec
	Csd}d}d}z�ttd�}t�|j|�}t|�t|�}t�|�}g|_td|�D]`}t�	||�}t�
|�}t�|�}t
�|�}t|�d}t�|�}	|dkr�|	|_qP|j�|	�qPW|r�t
�|�}t|�|r�t
�|�}t|�n0|r�t
�|�}t|�|�rt
�|�}t|�0dS)zh
        Reads end-entity and intermediate certificate information from the
        TLS session
        Nr�r)rrr�r�r	rZSecTrustGetCertificateCount�_intermediates�rangeZSecTrustGetCertificateAtIndexZSecCertificateCopyDatar
Zcf_data_to_bytesrr�rr��load�_certificater�)
rgr�Zcf_data_refr�r�Znumber_certs�indexr�Z	cert_datar�rororp�_read_certificatesBsN
�
�






�

zTLSSocket._read_certificatescCs,|jrtd��n|jr td��ntd��dS)zi
        Raises an exception describing if the local or remote end closed the
        connection
        z!The connection was already closedz$The remote end closed the connectionzThe connection was closedN)r�r(r�r)r�rororpr�vs


zTLSSocket._raise_closedcCs*|jdur|��|jdur$|��|jS)zu
        An asn1crypto.x509.Certificate object of the end-entity certificate
        presented by the server
        N)r�r�r�r�r�rororp�certificate�s


zTLSSocket.certificatecCs*|jdur|��|jdur$|��|jS)zz
        A list of asn1crypto.x509.Certificate objects that were presented as
        intermediates by the server
        N)r�r�r�r�r�r�rororp�
intermediates�s


zTLSSocket.intermediatescCs|jS)zg
        A unicode string of the IANA cipher suite name of the negotiated
        cipher suite
        )r�r�rororpr��szTLSSocket.cipher_suitecCs|jS)zM
        A unicode string of: "TLSv1.2", "TLSv1.1", "TLSv1", "SSLv3"
        )r�r�rororpr��szTLSSocket.protocolcCs|jS)z5
        A boolean if compression is enabled
        )r�r�rororpr��szTLSSocket.compressioncCs|jS�zM
        A unicode string of "new" or "reused" or None for no ticket
        )r�r�rororpr��szTLSSocket.session_idcCs|jSr�)r�r�rororpr��szTLSSocket.session_ticketcCs|jS)zM
        The oscrypto.tls.TLSSession object used for this connection
        )r�r�rororpr��szTLSSocket.sessioncCs|jS)zN
        A unicode string of the TLS server domain name or IP address
        )r�r�rororpr��szTLSSocket.hostnamecCs|j��dS)zJ
        An integer of the port number the socket is connected to
        r)rh�getpeernamer�rororpr��szTLSSocket.portcCs|jdur|��|jS)z9
        The underlying socket.socket connection
        N)r�r�rOr�rororprh�s
zTLSSocket.socketcCs|��dS)N)r�r�rororp�__del__�szTLSSocket.__del__)N)r�N)N)N)5r�r�r�r�rOr�rcr�r�r�r�r�r�r�r�r�r�r\r]rur�r�r��classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��propertyr�r�r�r�r�r�r�r�r�r�rhr�rorororprB{s~3
FkS
8+
4












)m�
__future__rrrrr��sys�rerhrSrRr�rU�weakrefZ	_securityrrr	r
Z_core_foundationrrr
Z_asn1rr�rr�_errorsrZ_ffirrrrrrrrrrrrrr �_typesr!r"r#r$Z_cipher_suitesr%�utilr&�errorsr'r(r)�_tlsr*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<Z
asymmetricr=�keysr>�version_info�xranger�Z
_pattern_typer��__all__Z
kSSLProtocol2Z
kSSLProtocol3Z
kTLSProtocol1ZkTLSProtocol11ZkTLSProtocol12r�r��compiler�r��WeakValueDictionaryrLrNrqr_rxr�r��objectrArBrorororp�<module>sf@T��	�

[7g