403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.142.201.222
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib/python3.7/site-packages/OpenSSL/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib/python3.7/site-packages/OpenSSL/__pycache__/SSL.cpython-37.pyc
B

uŹY~1�@sxddlZddlZddlmZddlmZmZddlmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZmZdd	lmZmZmZmZmZ m!Z"m#Z$m%Z&m'Z(dd
l)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ye0Z1Wn$e2k
r�Gdd�de3�Z1YnXye4Z5Wn&e2k
�r Gd
d�de3�Z5YnXej6Z6ej7Z7ej8Z8ej9Z9ej:Z:ej;Z;ej<Z=ej>Z?dZ@dZAdZBdZCdZDdZEejFZGejHZIejJZKejLZMejNZOejPZQejRZSejTZUejVZWejXZYejZZ[ej\Z]ej^Z_ej`ZaejbZcejdZeejfZgejhZiejjZkejlZmejnZoejpZqejrZsejtZuejvZwejxZyejzZ{ej|Z}ej~Zej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej��r�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�ej�Z�dddddgZ�dgZ�dZ�dZ�Gdd�de��Z�eee��Z�e e��Z�Gdd �d e��Z�Gd!d"�d"e��Z�Gd#d$�d$e��Z�Gd%d&�d&e��Z�Gd'd(�d(e��Z�Gd)d*�d*e3�Z�Gd+d,�d,e��Z�Gd-d.�d.e��Z�Gd/d0�d0e��Z�Gd1d2�d2e��Z�Gd3d4�d4e��Z�Gd5d6�d6e��Z�d7d8�Z�d9d:�Z�d;d<�Z�e�ej�d=�Z�e�ej�d>�Z�e�ej�d?�Z�Gd@dA�dAe3�Z�GdBdC�dCe3�Z�ee�e�dDeσZ�GdEdF�dFe3�Z�ee�e�dGeσZ�e�ӡdS)H�N)�platform)�wraps�partial)�count�chain)�WeakValueDictionary)�	errorcode)�
deprecated)�binary_type�
integer_types�int2byte�
indexbytes)	�UNSPECIFIED�exception_from_error_queue�ffi�lib�make_assert�native�path_string�text_to_bytes_and_warn�no_zero_allocator)�FILETYPE_PEM�_PassphraseHelper�PKey�X509Name�X509�	X509Storec@seZdZdS)�_memoryviewN)�__name__�
__module__�__qualname__�r!r!�</opt/alt/python37/lib/python3.7/site-packages/OpenSSL/SSL.pyr!src@seZdZdS)�_bufferN)rrr r!r!r!r"r#'sr#������z"/etc/ssl/certs/ca-certificates.crtz /etc/pki/tls/certs/ca-bundle.crtz/etc/ssl/ca-bundle.pemz/etc/pki/tls/cacert.pemz1/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pemz/etc/ssl/certss$/opt/pyca/cryptography/openssl/certss'/opt/pyca/cryptography/openssl/cert.pemc@seZdZdZdS)�Errorz4
    An error occurred in an `OpenSSL.SSL` API.
    N)rrr �__doc__r!r!r!r"r*�sr*c@seZdZdS)�
WantReadErrorN)rrr r!r!r!r"r,�sr,c@seZdZdS)�WantWriteErrorN)rrr r!r!r!r"r-�sr-c@seZdZdS)�WantX509LookupErrorN)rrr r!r!r!r"r.�sr.c@seZdZdS)�ZeroReturnErrorN)rrr r!r!r!r"r/�sr/c@seZdZdS)�SysCallErrorN)rrr r!r!r!r"r0�sr0c@s eZdZdZdd�Zdd�ZdS)�_CallbackExceptionHelpera�
    A base class for wrapper classes that allow for intelligent exception
    handling in OpenSSL callbacks.

    :ivar list _problems: Any exceptions that occurred while executing in a
        context where they could not be raised in the normal way.  Typically
        this is because OpenSSL has called into some Python code and requires a
        return value.  The exceptions are saved to be raised later when it is
        possible to do so.
    cCs
g|_dS)N)�	_problems)�selfr!r!r"�__init__�sz!_CallbackExceptionHelper.__init__cCs6|jr2y
t�Wntk
r$YnX|j�d��dS)z�
        Raise an exception from the OpenSSL error queue or that was previously
        captured whe running a callback.
        rN)r2�_raise_current_errorr*�pop)r3r!r!r"�raise_if_problem�s
z)_CallbackExceptionHelper.raise_if_problemN)rrr r+r4r7r!r!r!r"r1�s
r1c@seZdZdZdd�ZdS)�
_VerifyHelperz^
    Wrap a callback such that it can be used as a certificate verification
    callback.
    cs2t���t����fdd��}t�d|��_dS)Nc

s�t�t�}t�|�|_t�|�}t�|�}t��}t�||�}t	j
|}y�|||||�}Wn.tk
r�}	z�j�
|	�dSd}	~	XYnX|r�t�|tj�dSdSdS)Nrr$)r�__new__�_libZX509_STORE_CTX_get_current_cert�_x509ZX509_STORE_CTX_get_errorZX509_STORE_CTX_get_error_depthZ"SSL_get_ex_data_X509_STORE_CTX_idxZX509_STORE_CTX_get_ex_data�
Connection�_reverse_mapping�	Exceptionr2�appendZX509_STORE_CTX_set_errorZ	X509_V_OK)
�okZ	store_ctx�certZerror_numberZerror_depth�index�sslZ
connection�result�e)�callbackr3r!r"�wrapper�s"



z'_VerifyHelper.__init__.<locals>.wrapperzint (*)(int, X509_STORE_CTX *))r1r4r�_ffirF)r3rFrGr!)rFr3r"r4�s
z_VerifyHelper.__init__N)rrr r+r4r!r!r!r"r8�sr8c@seZdZdZdd�ZdS)�_NpnAdvertiseHelperzT
    Wrap a callback such that it can be used as an NPN advertisement callback.
    cs2t���t����fdd��}t�d|��_dS)Nc
s�yntj|}�|�}d�t�dd�|D���}t�dt|��t�d|�g|_|jdd|d<|jd|d<dSt	k
r�}z�j
�|�dSd}~XYnXdS)	N�css|]}tt|��|fVqdS)N)r�len)�.0�pr!r!r"�	<genexpr>sz@_NpnAdvertiseHelper.__init__.<locals>.wrapper.<locals>.<genexpr>zunsigned int *zunsigned char[]rr$r%)r<r=�joinr�
from_iterablerH�newrK�_npn_advertise_callback_argsr>r2r?)rC�out�outlen�arg�conn�protos�protostrrE)rFr3r!r"rGs
z-_NpnAdvertiseHelper.__init__.<locals>.wrapperz>int (*)(SSL *, const unsigned char **, unsigned int *, void *))r1r4rrHrF)r3rFrGr!)rFr3r"r4�s

z_NpnAdvertiseHelper.__init__N)rrr r+r4r!r!r!r"rI�srIc@seZdZdZdd�ZdS)�_NpnSelectHelperzP
    Wrap a callback such that it can be used as an NPN selection callback.
    cs2t���t����fdd��}t�d|��_dS)Nc

s�y�tj|}t�||�dd�}g}x<|r`t|d�}	|d|	d�}
|�|
�||	dd�}q&W�||�}t�dt|��t�d|�g|_|jdd|d<|jd|d<dSt	k
r�}z�j
�|�dSd}~XYnXdS)Nrr$zunsigned char *zunsigned char[]r%)r<r=rH�bufferr
r?rQrK�_npn_select_callback_argsr>r2)
rCrSrT�in_�inlenrUrV�instr�	protolist�l�proto�outstrrE)rFr3r!r"rG+s$



z*_NpnSelectHelper.__init__.<locals>.wrapperz^int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *))r1r4rrHrF)r3rFrGr!)rFr3r"r4(s

"z_NpnSelectHelper.__init__N)rrr r+r4r!r!r!r"rY#srYc@seZdZdZdd�ZdS)�_ALPNSelectHelperzQ
    Wrap a callback such that it can be used as an ALPN selection callback.
    cs2t���t����fdd��}t�d|��_dS)Nc

s�y�tj|}t�||�dd�}g}x<|r`t|d�}	|d|	d�}
|�|
�||	dd�}q&W�||�}t|t�s~td��t�	dt
|��t�	d|�g|_|jdd|d<|jd|d<dStk
r�}z�j
�|�dSd}~XYnXdS)Nrr$z'ALPN callback must return a bytestring.zunsigned char *zunsigned char[]r%)r<r=rHrZr
r?�
isinstance�_binary_type�	TypeErrorrQrK�_alpn_select_callback_argsr>r2)
rCrSrTr\r]rUrVr^r_Zencoded_lenrarbrE)rFr3r!r"rG\s(




z+_ALPNSelectHelper.__init__.<locals>.wrapperz^int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *))r1r4rrHrF)r3rFrGr!)rFr3r"r4Ys

$z_ALPNSelectHelper.__init__N)rrr r+r4r!r!r!r"rcTsrcc@seZdZdZdd�ZdS)�_OCSPServerCallbackHelpera�
    Wrap a callback such that it can be used as an OCSP callback for the server
    side.

    Annoyingly, OpenSSL defines one OCSP callback but uses it in two different
    ways. For servers, that callback is expected to retrieve some OCSP data and
    hand it to OpenSSL, and may return only SSL_TLSEXT_ERR_OK,
    SSL_TLSEXT_ERR_FATAL, and SSL_TLSEXT_ERR_NOACK. For clients, that callback
    is expected to check the OCSP data, and returns a negative value on error,
    0 if the response is not acceptable, or positive if it is. These are
    mutually exclusive return code behaviours, and they mean that we need two
    helpers so that we always return an appropriate error code if the user's
    code throws an exception.

    Given that we have to have two helpers anyway, these helpers are a bit more
    helpery than most: specifically, they hide a few more of the OpenSSL
    functions so that the user has an easier time writing these callbacks.

    This helper implements the server side.
    cs2t���t����fdd��}t�d|��_dS)Nc
s�y�tj|}|tjkr"t�|�}nd}�||�}t|t�sBtd��|sJdSt|�}t	�
|�}|t�||�dd�<t	�|||�dSt
k
r�}z�j�|�dSd}~XYnXdS)Nz'OCSP callback must return a bytestring.r&rr%)r<r=rH�NULL�from_handlerdrerfrKr:ZOPENSSL_mallocrZZSSL_set_tlsext_status_ocsp_respr>r2r?)rC�cdatarV�data�	ocsp_dataZocsp_data_lengthZdata_ptrrE)rFr3r!r"rG�s&



	

z3_OCSPServerCallbackHelper.__init__.<locals>.wrapperzint (*)(SSL *, void *))r1r4rrHrF)r3rFrGr!)rFr3r"r4�s
,z"_OCSPServerCallbackHelper.__init__N)rrr r+r4r!r!r!r"rh�srhc@seZdZdZdd�ZdS)�_OCSPClientCallbackHelpera�
    Wrap a callback such that it can be used as an OCSP callback for the client
    side.

    Annoyingly, OpenSSL defines one OCSP callback but uses it in two different
    ways. For servers, that callback is expected to retrieve some OCSP data and
    hand it to OpenSSL, and may return only SSL_TLSEXT_ERR_OK,
    SSL_TLSEXT_ERR_FATAL, and SSL_TLSEXT_ERR_NOACK. For clients, that callback
    is expected to check the OCSP data, and returns a negative value on error,
    0 if the response is not acceptable, or positive if it is. These are
    mutually exclusive return code behaviours, and they mean that we need two
    helpers so that we always return an appropriate error code if the user's
    code throws an exception.

    Given that we have to have two helpers anyway, these helpers are a bit more
    helpery than most: specifically, they hide a few more of the OpenSSL
    functions so that the user has an easier time writing these callbacks.

    This helper implements the client side.
    cs2t���t����fdd��}t�d|��_dS)Nc	
s�yxtj|}|tjkr"t�|�}nd}t�d�}t�||�}|dkrJd}nt�|d|�dd�}�|||�}t	t
|��Stk
r�}z�j�
|�dSd}~XYnXdS)Nzunsigned char **rrJ���)r<r=rHrirjrQr:ZSSL_get_tlsext_status_ocsp_resprZ�int�boolr>r2r?)	rCrkrVrlZocsp_ptrZocsp_lenrmZvalidrE)rFr3r!r"rG�s


z3_OCSPClientCallbackHelper.__init__.<locals>.wrapperzint (*)(SSL *, void *))r1r4rrHrF)r3rFrGr!)rFr3r"r4�s
z"_OCSPClientCallbackHelper.__init__N)rrr r+r4r!r!r!r"rn�srncCsdd}t|t�s(t|dd�}|dk	r(|�}t|t�r6|}t|t�sJtd��n|dkr`td|f��|S)N�filenoz3argument must be an int, or have a fileno() method.rz1file descriptor cannot be a negative integer (%i))rdr�getattrrf�
ValueError)�obj�fd�methr!r!r"�_asFileDescriptor
s



rxcCst�t�|��S)z�
    Return a string describing the version of OpenSSL in use.

    :param type: One of the SSLEAY_ constants defined in this module.
    )rH�stringr:�SSLeay_version)�typer!r!r"rzsrzcs��fdd�}|S)a�
    Builds a decorator that ensures that functions that rely on OpenSSL
    functions that are not present in this build raise NotImplementedError,
    rather than AttributeError coming out of cryptography.

    :param flag: A cryptography flag that guards the functions, e.g.
        ``Cryptography_HAS_NEXTPROTONEG``.
    :param error: The string to be used in the exception if the flag is false.
    cs$�st|��fdd��}|S|SdS)Ncst���dS)N)�NotImplementedError)�args�kwargs)�errorr!r"�explode2sz<_make_requires.<locals>._requires_decorator.<locals>.explode)r)�funcr�)r�flagr!r"�_requires_decorator0sz+_make_requires.<locals>._requires_decoratorr!)r�rr�r!)rr�r"�_make_requires&s
	r�zNPN not availablezALPN not availablezSNI not availablec@seZdZdS)�SessionN)rrr r!r!r!r"r�Ksr�c@s�eZdZdZededededede	diZ
edd	�e
��D��Z
d
d�Z
dcd
d�Zdd�Zdddd�Zdd�Zdd�Zdd�Zdd�Zefdd�Zdd�Zdd �Zd!d"�Zefd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Z d/d0�Z!d1d2�Z"d3d4�Z#d5d6�Z$d7d8�Z%d9d:�Z&d;d<�Z'd=d>�Z(d?d@�Z)dAdB�Z*dCdD�Z+dEdF�Z,dGdH�Z-dIdJ�Z.dKdL�Z/dMdN�Z0dOdP�Z1dQdR�Z2e3dSdT��Z4e5dUdV��Z6e5dWdX��Z7e8dYdZ��Z9e8d[d\��Z:d]d^�Z;ded_d`�Z<dfdadb�Z=dS)g�Contextzn
    :class:`OpenSSL.SSL.Context` instances define the parameters for setting
    up new SSL connections.
    ZSSLv2_methodZSSLv3_methodZ
SSLv23_methodZTLSv1_methodZTLSv1_1_methodZTLSv1_2_methodccs0|](\}}tt|d�dk	r|tt|�fVqdS)N)rsr:)rL�
identifier�namer!r!r"rN]szContext.<genexpr>cCs&t|t�std��y|j|}Wntk
r<td��YnX|�}t|tjk�t	�
|�}t|tjk�t�|t	j�}yt	�
|d�}t|dk�Wntk
r�YnX||_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ |�!t	j"�dS)zo
        :param method: One of SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, or
            TLSv1_METHOD.
        zmethod must be an integerzNo such protocolr$N)#rdrrf�_methods�KeyErrorrt�_openssl_assertrHrir:ZSSL_CTX_new�gcZSSL_CTX_freeZSSL_CTX_set_ecdh_auto�AttributeError�_context�_passphrase_helper�_passphrase_callback�_passphrase_userdata�_verify_helper�_verify_callback�_info_callback�_tlsext_servername_callback�	_app_data�_npn_advertise_helper�_npn_advertise_callback�_npn_select_helper�_npn_select_callback�_alpn_select_helper�_alpn_select_callback�_ocsp_helper�_ocsp_callback�
_ocsp_data�set_modeZSSL_MODE_ENABLE_PARTIAL_WRITE)r3�methodZmethod_funcZ
method_obj�context�resr!r!r"r4asF

zContext.__init__NcCsN|dkrtj}nt|�}|dkr(tj}nt|�}t�|j||�}|sJt�dS)aX
        Let SSL know where we can find trusted certificates for the certificate
        chain

        :param cafile: In which file we can find the certificates (``bytes`` or
            ``unicode``).
        :param capath: In which directory we can find the certificates
            (``bytes`` or ``unicode``).

        :return: None
        N)rHri�_path_stringr:ZSSL_CTX_load_verify_locationsr�r5)r3�cafile�capathZload_resultr!r!r"�load_verify_locations�szContext.load_verify_locationscs&t����fdd��}tt|ddd�S)Ncs�||�j�S)N)r�)�sizeZverify�userdata)rFr3r!r"rG�sz'Context._wrap_callback.<locals>.wrapperT)Z	more_args�truncate)rrr)r3rFrGr!)rFr3r"�_wrap_callback�szContext._wrap_callbackcCs@t|�std��|�|�|_|jj|_t�|j|j�||_	dS)z�
        Set the passphrase callback

        :param callback: The Python callback to use
        :param userdata: (optional) A Python object which will be given as
                         argument to the callback
        :return: None
        zcallback must be callableN)
�callablerfr�r�rFr�r:ZSSL_CTX_set_default_passwd_cbr�r�)r3rFr�r!r!r"�
set_passwd_cb�s	
zContext.set_passwd_cbcCs�t�|j�}t|dk�t�t����d�}t�t����d�}|�	||�s�t�t�
��}t�t���}|tkr�|t
kr�|�tt�dS)z[
        Use the platform-specific CA certificate locations

        :return: None
        r$�asciiN)r:Z SSL_CTX_set_default_verify_pathsr�r�rHryZX509_get_default_cert_dir_env�decodeZX509_get_default_cert_file_env�_check_env_vars_setZX509_get_default_cert_dirZX509_get_default_cert_file�_CRYPTOGRAPHY_MANYLINUX1_CA_DIR� _CRYPTOGRAPHY_MANYLINUX1_CA_FILE�_fallback_default_verify_paths�_CERTIFICATE_FILE_LOCATIONS�_CERTIFICATE_PATH_LOCATIONS)r3�
set_result�dir_env_var�file_env_varZdefault_dirZdefault_filer!r!r"�set_default_verify_paths�s 


z Context.set_default_verify_pathscCs tj�|�dk	ptj�|�dk	S)zp
        Check to see if the default cert dir/file environment vars are present.

        :return: bool
        N)�os�environ�get)r3r�r�r!r!r"r��szContext._check_env_vars_setcCsRx$|D]}tj�|�r|�|�PqWx&|D]}tj�|�r,|�d|�Pq,WdS)aW
        Default verify paths are based on the compiled version of OpenSSL.
        However, when pyca/cryptography is compiled as a manylinux1 wheel
        that compiled location can potentially be wrong. So, like Go, we
        will try a predefined set of paths and attempt to load roots
        from there.

        :return: None
        N)r��path�isfiler��isdir)r3�	file_pathZdir_pathr�r�r!r!r"r��s



z&Context._fallback_default_verify_pathscCs$t|�}t�|j|�}|s t�dS)z�
        Load a certificate chain from a file

        :param certfile: The name of the certificate chain file (``bytes`` or
            ``unicode``).

        :return: None
        N)r�r:Z"SSL_CTX_use_certificate_chain_filer�r5)r3�certfilerDr!r!r"�use_certificate_chain_files
	
z"Context.use_certificate_chain_filecCs8t|�}t|t�std��t�|j||�}|s4t�dS)z�
        Load a certificate from a file

        :param certfile: The name of the certificate file (``bytes`` or
            ``unicode``).
        :param filetype: (optional) The encoding of the file, default is PEM

        :return: None
        zfiletype must be an integerN)r�rdrrfr:ZSSL_CTX_use_certificate_filer�r5)r3r��filetype�
use_resultr!r!r"�use_certificate_files

zContext.use_certificate_filecCs0t|t�std��t�|j|j�}|s,t�dS)zs
        Load a certificate from a X509 object

        :param cert: The X509 object
        :return: None
        zcert must be an X509 instanceN)rdrrfr:ZSSL_CTX_use_certificater�r;r5)r3rAr�r!r!r"�use_certificate3s

zContext.use_certificatecCsDt|t�std��t�|j�}t�|j|�}|s@t�|�t	�dS)z�
        Add certificate to chain

        :param certobj: The X509 certificate object to add to the chain
        :return: None
        z certobj must be an X509 instanceN)
rdrrfr:�X509_dupr;ZSSL_CTX_add_extra_chain_certr��	X509_freer5)r3Zcertobj�copy�
add_resultr!r!r"�add_extra_chain_certAs

zContext.add_extra_chain_certcCs |jdk	r|j�t�t�dS)N)r�r7r*r5)r3r!r!r"�_raise_passphrase_exceptionRs
z#Context._raise_passphrase_exceptioncCsHt|�}|tkrt}nt|t�s(td��t�|j||�}|sD|�	�dS)z�
        Load a private key from a file

        :param keyfile: The name of the key file (``bytes`` or ``unicode``)
        :param filetype: (optional) The encoding of the file, default is PEM

        :return: None
        zfiletype must be an integerN)
r��_UNSPECIFIEDrrdrrfr:ZSSL_CTX_use_PrivateKey_filer�r�)r3Zkeyfiler�r�r!r!r"�use_privatekey_fileXs	
zContext.use_privatekey_filecCs2t|t�std��t�|j|j�}|s.|��dS)zs
        Load a private key from a PKey object

        :param pkey: The PKey object
        :return: None
        zpkey must be a PKey instanceN)rdrrfr:ZSSL_CTX_use_PrivateKeyr�Z_pkeyr�)r3Zpkeyr�r!r!r"�use_privatekeyms

zContext.use_privatekeycCst�|j�st�dS)z�
        Check that the private key and certificate match up

        :return: None (raises an exception if something's wrong)
        N)r:ZSSL_CTX_check_private_keyr�r5)r3r!r!r"�check_privatekey{szContext.check_privatekeycCs0t�td|��}t|tjk�t�|j|�dS)a%
        Load the trusted certificates that will be sent to the client.  Does
        not actually imply any of the certificates are trusted; that must be
        configured separately.

        :param bytes cafile: The path to a certificates file in PEM format.
        :return: None
        r�N)r:ZSSL_load_client_CA_file�_text_to_bytes_and_warnr�rHri�SSL_CTX_set_client_CA_listr�)r3r�Zca_listr!r!r"�load_client_ca�s	zContext.load_client_cacCs*td|�}tt�|j|t|��dk�dS)aV
        Set the session id to *buf* within which a session can be reused for
        this Context object.  This is needed when doing session resumption,
        because there is no way for a stored session to know which Context
        object it is associated with.

        :param bytes buf: The session id.

        :returns: None
        �bufr$N)r�r�r:ZSSL_CTX_set_session_id_contextr�rK)r3r�r!r!r"�set_session_id�s
zContext.set_session_idcCs t|t�std��t�|j|�S)z�
        Enable/disable session caching and specify the mode used.

        :param mode: One or more of the SESS_CACHE_* flags (combine using
            bitwise or)
        :returns: The previously set caching mode.
        zmode must be an integer)rdrrfr:ZSSL_CTX_set_session_cache_moder�)r3�moder!r!r"�set_session_cache_mode�s
zContext.set_session_cache_modecCst�|j�S)z:
        :returns: The currently used cache mode.
        )r:ZSSL_CTX_get_session_cache_moder�)r3r!r!r"�get_session_cache_mode�szContext.get_session_cache_modecCsLt|t�std��t|�s"td��t|�|_|jj|_t�	|j
||j�dS)aG
        Set the verify mode and verify callback

        :param mode: The verify mode, this is either VERIFY_NONE or
                     VERIFY_PEER combined with possible other flags
        :param callback: The Python callback to use
        :return: None

        See SSL_CTX_set_verify(3SSL) for further details.
        zmode must be an integerzcallback must be callableN)rdrrfr�r8r�rFr�r:ZSSL_CTX_set_verifyr�)r3r�rFr!r!r"�
set_verify�s


zContext.set_verifycCs$t|t�std��t�|j|�dS)zz
        Set the verify depth

        :param depth: An integer specifying the verify depth
        :return: None
        zdepth must be an integerN)rdrrfr:ZSSL_CTX_set_verify_depthr�)r3�depthr!r!r"�set_verify_depth�s
zContext.set_verify_depthcCst�|j�S)zG
        Get the verify mode

        :return: The verify mode
        )r:ZSSL_CTX_get_verify_moder�)r3r!r!r"�get_verify_mode�szContext.get_verify_modecCst�|j�S)zI
        Get the verify depth

        :return: The verify depth
        )r:ZSSL_CTX_get_verify_depthr�)r3r!r!r"�get_verify_depth�szContext.get_verify_depthcCsht|�}t�|d�}|tjkr$t�t�|tj�}t�|tjtjtj�}t�|tj	�}t�
|j|�dS)z�
        Load parameters for Ephemeral Diffie-Hellman

        :param dhfile: The file to load EDH parameters from (``bytes`` or
            ``unicode``).

        :return: None
        �rN)r�r:ZBIO_new_filerHrir5r�ZBIO_freeZPEM_read_bio_DHparamsZDH_freeZSSL_CTX_set_tmp_dhr�)r3Zdhfile�bioZdhr!r!r"�load_tmp_dh�s	
zContext.load_tmp_dhcCst�|j|���dS)a
        Select a curve to use for ECDHE key exchange.

        :param curve: A curve object to use as returned by either
            :py:meth:`OpenSSL.crypto.get_elliptic_curve` or
            :py:meth:`OpenSSL.crypto.get_elliptic_curves`.

        :return: None
        N)r:ZSSL_CTX_set_tmp_ecdhr�Z
_to_EC_KEY)r3Zcurver!r!r"�set_tmp_ecdh�s
zContext.set_tmp_ecdhcCs6td|�}t|t�std��tt�|j|�dk�dS)z�
        Set the list of ciphers to be used in this context.

        See the OpenSSL manual for more information (e.g.
        :manpage:`ciphers(1)`).

        :param bytes cipher_list: An OpenSSL cipher string.
        :return: None
        �cipher_listz"cipher_list must be a byte string.r$N)r�rd�bytesrfr�r:ZSSL_CTX_set_cipher_listr�)r3r�r!r!r"�set_cipher_lists



zContext.set_cipher_listcCs�t��}t|tjk�yjxd|D]\}t|t�s@tdt|�j	f��t�
|j�}t|tjk�t�||�}|st�
|�t�qWWnt�|��YnXt�|j|�dS)a?
        Set the list of preferred client certificate signers for this server
        context.

        This list of certificate authorities will be sent to the client when
        the server requests a client certificate.

        :param certificate_authorities: a sequence of X509Names.
        :return: None
        z3client CAs must be X509Name objects, not %s objectsN)r:Zsk_X509_NAME_new_nullr�rHrirdrrfr{r�
X509_NAME_dup�_nameZsk_X509_NAME_push�X509_NAME_freer5Zsk_X509_NAME_freer�r�)r3Zcertificate_authoritiesZ
name_stackZca_namer�Zpush_resultr!r!r"�set_client_ca_lists$



zContext.set_client_ca_listcCs2t|t�std��t�|j|j�}t|dk�dS)aI
        Add the CA certificate to the list of preferred signers for this
        context.

        The list of certificate authorities will be sent to the client when the
        server requests a client certificate.

        :param certificate_authority: certificate authority's X509 certificate.
        :return: None
        z.certificate_authority must be an X509 instancer$N)rdrrfr:ZSSL_CTX_add_client_CAr�r;r�)r3Zcertificate_authorityr�r!r!r"�
add_client_caAs

zContext.add_client_cacCs t|t�std��t�|j|�S)z�
        Set session timeout

        :param timeout: The timeout in seconds
        :return: The previous session timeout
        ztimeout must be an integer)rdrrfr:ZSSL_CTX_set_timeoutr�)r3�timeoutr!r!r"�set_timeoutSs
zContext.set_timeoutcCst�|j�S)zO
        Get the session timeout

        :return: The session timeout
        )r:ZSSL_CTX_get_timeoutr�)r3r!r!r"�get_timeout_szContext.get_timeoutcs6t���fdd��}t�d|�|_t�|j|j�dS)zr
        Set the info callback

        :param callback: The Python callback to use
        :return: None
        cs�tj|||�dS)N)r<r=)rC�whereZreturn_code)rFr!r"rGnsz*Context.set_info_callback.<locals>.wrapperzvoid (*)(const SSL *, int, int)N)rrHrFr�r:ZSSL_CTX_set_info_callbackr�)r3rFrGr!)rFr"�set_info_callbackgs
zContext.set_info_callbackcCs|jS)zo
        Get the application data (supplied via set_app_data())

        :return: The application data
        )r�)r3r!r!r"�get_app_datauszContext.get_app_datacCs
||_dS)z�
        Set the application data (will be returned from get_app_data())

        :param data: Any Python object
        :return: None
        N)r�)r3rlr!r!r"�set_app_data}szContext.set_app_datacCs.t�|j�}|tjkrdSt�t�}||_|S)z�
        Get the certificate store for the context.

        :return: A X509Store object or None if it does not have one.
        N)r:ZSSL_CTX_get_cert_storer�rHrirr9Z_store)r3�storeZpystorer!r!r"�get_cert_store�s

zContext.get_cert_storecCs t|t�std��t�|j|�S)z�
        Add options. Options set before are not cleared!

        :param options: The options to add.
        :return: The new option bitmask.
        zoptions must be an integer)rdrrfr:ZSSL_CTX_set_optionsr�)r3�optionsr!r!r"�set_options�s
zContext.set_optionscCs t|t�std��t�|j|�S)z�
        Add modes via bitmask. Modes set before are not cleared!

        :param mode: The mode to add.
        :return: The new mode bitmask.
        zmode must be an integer)rdrrfr:ZSSL_CTX_set_moder�)r3r�r!r!r"r��s
zContext.set_modecs6t���fdd��}t�d|�|_t�|j|j�dS)z�
        Specify a callback function to be called when clients specify a server
        name.

        :param callback: The callback function.  It will be invoked with one
            argument, the Connection instance.
        cs�tj|�dS)Nr)r<r=)rCZalertrU)rFr!r"rG�sz7Context.set_tlsext_servername_callback.<locals>.wrapperz#int (*)(const SSL *, int *, void *)N)rrHrFr�r:Z&SSL_CTX_set_tlsext_servername_callbackr�)r3rFrGr!)rFr"�set_tlsext_servername_callback�s
	
z&Context.set_tlsext_servername_callbackcCs,t|�|_|jj|_t�|j|jtj�dS)a�
        Specify a callback function that will be called when offering `Next
        Protocol Negotiation
        <https://technotes.googlecode.com/git/nextprotoneg.html>`_ as a server.

        :param callback: The callback function.  It will be invoked with one
            argument, the Connection instance.  It should return a list of
            bytestrings representing the advertised protocols, like
            ``[b'http/1.1', b'spdy/2']``.
        N)	rIr�rFr�r:Z%SSL_CTX_set_next_protos_advertised_cbr�rHri)r3rFr!r!r"�set_npn_advertise_callback�s

z"Context.set_npn_advertise_callbackcCs,t|�|_|jj|_t�|j|jtj�dS)a�
        Specify a callback function that will be called when a server offers
        Next Protocol Negotiation options.

        :param callback: The callback function.  It will be invoked with two
            arguments: the Connection, and a list of offered protocols as
            bytestrings, e.g. ``[b'http/1.1', b'spdy/2']``.  It should return
            one of those bytestrings, the chosen protocol.
        N)	rYr�rFr�r:Z SSL_CTX_set_next_proto_select_cbr�rHri)r3rFr!r!r"�set_npn_select_callback�s

zContext.set_npn_select_callbackcCs>d�t�dd�|D���}t�d|�}t�|j|t|��dS)ag
        Specify the clients ALPN protocol list.

        These protocols are offered to the server during protocol negotiation.

        :param protos: A list of the protocols to be offered to the server.
            This list should be a Python list of bytestrings representing the
            protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
        rJcss|]}tt|��|fVqdS)N)rrK)rLrMr!r!r"rN�sz*Context.set_alpn_protos.<locals>.<genexpr>zunsigned char[]N)	rOrrPrHrQr:ZSSL_CTX_set_alpn_protosr�rK)r3rWrX�	input_strr!r!r"�set_alpn_protos�s
zContext.set_alpn_protoscCs,t|�|_|jj|_t�|j|jtj�dS)ab
        Set the callback to handle ALPN protocol choice.

        :param callback: The callback function.  It will be invoked with two
            arguments: the Connection, and a list of offered protocols as
            bytestrings, e.g ``[b'http/1.1', b'spdy/2']``.  It should return
            one of those bytestrings, the chosen protocol.
        N)	rcr�rFr�r:ZSSL_CTX_set_alpn_select_cbr�rHri)r3rFr!r!r"�set_alpn_select_callback�s


z Context.set_alpn_select_callbackcCsh||_|j|_|dkr tj|_nt�|�|_t�|j	|j�}t
|dk�t�|j	|j�}t
|dk�dS)z�
        This internal helper does the common work for
        ``set_ocsp_server_callback`` and ``set_ocsp_client_callback``, which is
        almost all of it.
        Nr$)r�rFr�rHrir�Z
new_handler:ZSSL_CTX_set_tlsext_status_cbr�r�ZSSL_CTX_set_tlsext_status_arg)r3�helperrl�rcr!r!r"�_set_ocsp_callbacks
zContext._set_ocsp_callbackcCst|�}|�||�dS)a�
        Set a callback to provide OCSP data to be stapled to the TLS handshake
        on the server side.

        :param callback: The callback function. It will be invoked with two
            arguments: the Connection, and the optional arbitrary data you have
            provided. The callback must return a bytestring that contains the
            OCSP data to staple to the handshake. If no OCSP data is available
            for this connection, return the empty bytestring.
        :param data: Some opaque data that will be passed into the callback
            function when called. This can be used to avoid needing to do
            complex data lookups or to keep track of what context is being
            used. This parameter is optional.
        N)rhr�)r3rFrlr�r!r!r"�set_ocsp_server_callbacksz Context.set_ocsp_server_callbackcCst|�}|�||�dS)a�
        Set a callback to validate OCSP data stapled to the TLS handshake on
        the client side.

        :param callback: The callback function. It will be invoked with three
            arguments: the Connection, a bytestring containing the stapled OCSP
            assertion, and the optional arbitrary data you have provided. The
            callback must return a boolean that indicates the result of
            validating the OCSP data: ``True`` if the OCSP data is valid and
            the certificate can be trusted, or ``False`` if either the OCSP
            data is invalid or the certificate has been revoked.
        :param data: Some opaque data that will be passed into the callback
            function when called. This can be used to avoid needing to do
            complex data lookups or to keep track of what context is being
            used. This parameter is optional.
        N)rnr�)r3rFrlr�r!r!r"�set_ocsp_client_callback,sz Context.set_ocsp_client_callback)N)N)N)N)>rrr r+�SSLv2_METHOD�SSLv3_METHOD�
SSLv23_METHOD�TLSv1_METHOD�TLSv1_1_METHOD�TLSv1_2_METHODr��dict�itemsr4r�r�r�r�r�r�r�rr�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�r�r��
_requires_snir��
_requires_npnr�r��_requires_alpnr�r�r�r�r�r!r!r!r"r�Osl2

'	
#	
r�z4ContextType has been deprecated, use Context insteadc@s�eZdZdZe�Zdtdd�Zdd�Zdd�Zd	d
�Z	dd�Z
ed
d��Zedd��Z
dd�Zdudd�ZeZdvdd�Zdwdd�ZeZdxdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Z d4d5�Z!d6d7�Z"d8d9�Z#d:d;�Z$d<d=�Z%d>d?�Z&d@dA�Z'dBdC�Z(dDdE�Z)dFdG�Z*dHdI�Z+dJdK�Z,dLdM�Z-dNdO�Z.dPdQ�Z/dRdS�Z0dTdU�Z1dVdW�Z2dXdY�Z3dZd[�Z4d\d]�Z5d^d_�Z6d`da�Z7dbdc�Z8ddde�Z9dfdg�Z:dhdi�Z;djdk�Z<e=dldm��Z>e?dndo��Z@e?dpdq��ZAdrds�ZBdS)yr<z
    NcCs�t|t�std��t�|j�}t�|tj�|_	||_d|_
d|_d|_d|_
||j|j	<|dkr�d|_t�t���|_t|jtjk�t�t���|_t|jtjk�t�|j	|j|j�n2d|_d|_||_t�|j	t|j��}t|dk�dS)z�
        Create a new Connection object, using the given OpenSSL.SSL.Context
        instance and socket.

        :param context: An SSL Context to use for this connection
        :param socket: The socket to use for transport layer
        z"context must be a Context instanceNr$)rdr�rfr:ZSSL_newr�rHr�ZSSL_free�_sslr�rRr[rgr=�_socketZBIO_newZ	BIO_s_mem�	_into_sslr�ri�	_from_sslZSSL_set_bioZ
SSL_set_fdrx)r3r��socketrCr�r!r!r"r4Ls.
zConnection.__init__cCs0|jdkr td|jj|f��nt|j|�SdS)zy
        Look up attributes on the wrapped socket object if they are not found
        on the Connection object.
        Nz!'%s' object has no attribute '%s')rr��	__class__rrs)r3r�r!r!r"�__getattr__}s
zConnection.__getattr__cCsT|jjdk	r|jj��|jjdk	r0|jj��|jjdk	rH|jj��|jjdk	r`|jj��|jjdk	rx|jj��t�||�}|tj	kr�t
��n�|tjkr�t��n�|tj
kr�t��n�|tjkr�t��n�|tjk�r<t��dk�r4|dk�r(tdk�rt��d}ntj}|dk�r(t|t�|���tdd��nt�n|tjk�rJnt�dS)Nr�win32rozUnexpected EOF)r�r�r7r�r�r�r�r:Z
SSL_get_errorZSSL_ERROR_WANT_READr,ZSSL_ERROR_WANT_WRITEr-ZSSL_ERROR_ZERO_RETURNr/ZSSL_ERROR_WANT_X509_LOOKUPr.ZSSL_ERROR_SYSCALLZERR_peek_errorrrHZgetwinerror�errnor0rr�r5ZSSL_ERROR_NONE)r3rCrDrrr!r!r"�_raise_ssl_error�s@






zConnection._raise_ssl_errorcCs|jS)z%
        Get session context
        )r�)r3r!r!r"�get_context�szConnection.get_contextcCs,t|t�std��t�|j|j�||_dS)z�
        Switch this connection to a new session context

        :param context: A :py:class:`Context` instance giving the new session
            context to use.
        z"context must be a Context instanceN)rdr�rfr:ZSSL_set_SSL_CTXrr�)r3r�r!r!r"�set_context�s
zConnection.set_contextcCs(t�|jtj�}|tjkrdSt�|�S)z�
        Retrieve the servername extension value if provided in the client hello
        message, or None if there wasn't one.

        :return: A byte string giving the server name or :py:data:`None`.
        N)r:ZSSL_get_servernamerZTLSEXT_NAMETYPE_host_namerHriry)r3r�r!r!r"�get_servername�s

zConnection.get_servernamecCs6t|t�std��nd|kr$td��t�|j|�dS)z�
        Set the value of the servername extension to send in the client hello.

        :param name: A byte string giving the name.
        zname must be a byte string�zname must not contain NUL byteN)rdr�rfr:ZSSL_set_tlsext_host_namer)r3r�r!r!r"�set_tlsext_host_name�s


zConnection.set_tlsext_host_namecCst�|j�S)z�
        Get the number of bytes that can be safely read from the connection

        :return: The number of bytes available in the receive buffer.
        )r:ZSSL_pendingr)r3r!r!r"�pending�szConnection.pendingrcCsztd|�}t|t�r|��}t|t�r.t|�}t|t�s@td��t|�dkrTt	d��t
�|j|t|��}|�
|j|�|S)a�
        Send data on the connection. NOTE: If you get one of the WantRead,
        WantWrite or WantX509Lookup exceptions on this, you have to call the
        method again with the SAME buffer.

        :param buf: The string, buffer or memoryview to send
        :param flags: (optional) Included for compatibility with the socket
                      API, the value is ignored
        :return: The number of bytes written
        r�z0data must be a memoryview, buffer or byte stringi���z,Cannot send more than 2**31-1 bytes at once.)r�rdr�tobytesr#�strr�rfrKrtr:�	SSL_writerr)r3r��flagsrDr!r!r"�send�s



zConnection.sendcCs�td|�}t|t�r|��}t|t�r.t|�}t|t�s@td��t|�}d}t	�
d|�}x@|r�t�|j
||t|d��}|�|j
|�||7}||8}qZWdS)a�
        Send "all" data on the connection. This calls send() repeatedly until
        all data is sent. If an error occurs, it's impossible to tell how much
        data has been sent.

        :param buf: The string, buffer or memoryview to send
        :param flags: (optional) Included for compatibility with the socket
                      API, the value is ignored
        :return: The number of bytes written
        r�z/buf must be a memoryview, buffer or byte stringrzchar[]i���N)r�rdrrr#rr�rfrKrHrQr:rr�minr)r3r�rZleft_to_send�
total_sentrlrDr!r!r"�sendalls$



zConnection.sendallcCs`td|�}|dk	r.|tj@r.t�|j||�}nt�|j||�}|�|j|�t�	||�dd�S)a
        Receive data on the connection.

        :param bufsiz: The maximum number of bytes to read
        :param flags: (optional) The only supported flag is ``MSG_PEEK``,
            all other flags are ignored.
        :return: The string read from the Connection
        zchar[]N)
�_no_zero_allocatorr�MSG_PEEKr:�SSL_peekr�SSL_readrrHrZ)r3�bufsizrr�rDr!r!r"�recv,s	
zConnection.recvcCs�|dkrt|�}nt|t|��}td|�}|dk	rN|tj@rNt�|j||�}nt�|j||�}|�	|j|�yt
t�||��|d|�<Wn(t
k
r�t�||�|d|�<YnX|S)aW
        Receive data on the connection and store the data into a buffer rather
        than creating a new string.

        :param buffer: The buffer to copy into.
        :param nbytes: (optional) The maximum number of bytes to read into the
            buffer. If not present, defaults to the size of the buffer. If
            larger than the size of the buffer, is reduced to the size of the
            buffer.
        :param flags: (optional) The only supported flag is ``MSG_PEEK``,
            all other flags are ignored.
        :return: The number of bytes read into the buffer.
        Nzchar[])rKr r#rr$r:r%rr&r�
memoryviewrHrZ�	NameError)r3rZ�nbytesrr�rDr!r!r"�	recv_into>s

zConnection.recv_intocCsVt�|�rLt�|�rt��qRt�|�r.t��qRt�|�rBtd��qRtd��nt�dS)N�BIO_should_io_specialzunknown bio failure)	r:ZBIO_should_retryZBIO_should_readr,ZBIO_should_writer-r-rtr5)r3r�rDr!r!r"�_handle_bio_errorsgs





zConnection._handle_bio_errorscCsh|jdkrtd��t|t�s$td��td|�}t�|j||�}|dkrT|�|j|�t�	||�dd�S)z�
        When using non-socket connections this function reads the "dirty" data
        that would have traveled away on the network.

        :param bufsiz: The maximum number of bytes to read
        :return: The string read.
        NzConnection sock was not Nonezbufsiz must be an integerzchar[]r)
rrfrdrr#r:ZBIO_readr.rHrZ)r3r'r�rDr!r!r"�bio_readys


zConnection.bio_readcCsJtd|�}|jdkrtd��t�|j|t|��}|dkrF|�|j|�|S)z�
        When using non-socket connections this function sends "dirty" data that
        would have traveled in on the network.

        :param buf: The string to put into the memory BIO.
        :return: The number of bytes written
        r�NzConnection sock was not Noner)r�r
rfr:Z	BIO_writerKr.)r3r�rDr!r!r"�	bio_write�s

zConnection.bio_writecCs$|��s tt�|j�dk�dSdS)z�
        Renegotiate the session.

        :return: True if the renegotiation can be started, False otherwise
        :rtype: bool
        r$TF)�renegotiate_pendingr�r:ZSSL_renegotiater)r3r!r!r"�renegotiate�szConnection.renegotiatecCst�|j�}|�|j|�dS)z�
        Perform an SSL handshake (usually called after renegotiate() or one of
        set_*_state()). This can raise the same exceptions as send and recv.

        :return: None.
        N)r:ZSSL_do_handshakerr)r3rDr!r!r"�do_handshake�szConnection.do_handshakecCst�|j�dkS)z�
        Check if there's a renegotiation in progress, it will return False once
        a renegotiation is finished.

        :return: Whether there's a renegotiation in progress
        :rtype: bool
        r$)r:ZSSL_renegotiate_pendingr)r3r!r!r"r1�szConnection.renegotiate_pendingcCst�|j�S)z�
        Find out the total number of renegotiations.

        :return: The number of renegotiations.
        :rtype: int
        )r:ZSSL_total_renegotiationsr)r3r!r!r"�total_renegotiations�szConnection.total_renegotiationscCst�|j�|j�|�S)z�
        Connect to remote host and set up client-side SSL

        :param addr: A remote address
        :return: What the socket's connect method returns
        )r:�SSL_set_connect_staterr�connect)r3�addrr!r!r"r6�szConnection.connectcCs|jj}|��||�S)a
        Connect to remote host and set up client-side SSL. Note that if the
        socket's connect_ex method doesn't return 0, SSL won't be initialized.

        :param addr: A remove address
        :return: What the socket's connect_ex method returns
        )r�
connect_ex�set_connect_state)r3r7r8r!r!r"r8�szConnection.connect_excCs*|j��\}}t|j|�}|��||fS)z�
        Accept incoming connection and set up SSL on it

        :return: A (conn,addr) pair where conn is a Connection and addr is an
                 address
        )r�acceptr<r��set_accept_state)r3Zclientr7rVr!r!r"r:�szConnection.acceptcCs$|jdkrtd��t�|jd�dS)z�
        When using non-socket connections this function signals end of
        data on the input for this connection.

        :return: None
        NzConnection sock was not Noner)rrfr:ZBIO_set_mem_eof_returnr
)r3r!r!r"�bio_shutdown�s
zConnection.bio_shutdowncCs8t�|j�}|dkr$|�|j|�n|dkr0dSdSdS)a
        Send closure alert

        :return: True if the shutdown completed successfully (i.e. both sides
                 have sent closure alerts), false otherwise (i.e. you have to
                 wait for a ZeroReturnError on a recv() method call
        rTFN)r:ZSSL_shutdownrr)r3rDr!r!r"�shutdown�szConnection.shutdowncCsFg}x<t�D]2}t�|j|�}|tjkr*P|�tt�|���qW|S)z�
        Retrieve the list of ciphers used by the Connection object.

        :return: A list of native cipher strings.
        )	rr:ZSSL_get_cipher_listrrHrir?�_nativery)r3Zciphers�irDr!r!r"�get_cipher_lists
zConnection.get_cipher_listcCs�t�|j�}|tjkrgSg}x^tt�|��D]L}t�||�}t�|�}t	|tjk�t
�t
�}t�|tj
�|_|�|�q.W|S)a�
        Get CAs whose certificates are suggested for client authentication.

        :return: If this is a server connection, a list of X509Names
            representing the acceptable CAs as set by
            :py:meth:`OpenSSL.SSL.Context.set_client_ca_list` or
            :py:meth:`OpenSSL.SSL.Context.add_client_ca`.  If this is a client
            connection, the list of such X509Names sent by the server, or an
            empty list if that has not yet happened.
        )r:ZSSL_get_client_CA_listrrHri�rangeZsk_X509_NAME_numZsk_X509_NAME_valuer�r�rr9r�r�r�r?)r3Zca_namesrDr?r�r�Zpynamer!r!r"�get_client_ca_lists


zConnection.get_client_ca_listcCstd��dS)z�
        The makefile() method is not implemented, since there is no dup
        semantics for SSL connections

        :raise: NotImplementedError
        z1Cannot make file object of OpenSSL.SSL.ConnectionN)r|)r3r!r!r"�makefile0szConnection.makefilecCs|jS)zM
        Get application data

        :return: The application data
        )r�)r3r!r!r"r�:szConnection.get_app_datacCs
||_dS)zh
        Set application data

        :param data - The application data
        :return: None
        N)r�)r3rlr!r!r"r�BszConnection.set_app_datacCst�|j�S)z�
        Get shutdown state

        :return: The shutdown state, a bitvector of SENT_SHUTDOWN,
            RECEIVED_SHUTDOWN.
        )r:ZSSL_get_shutdownr)r3r!r!r"�get_shutdownKszConnection.get_shutdowncCs$t|t�std��t�|j|�dS)z�
        Set shutdown state

        :param state - bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
        :return: None
        zstate must be an integerN)rdrrfr:ZSSL_set_shutdownr)r3�stater!r!r"�set_shutdownTs
zConnection.set_shutdowncCst�t�|j��S)z�
        Retrieve a verbose string detailing the state of the Connection.

        :return: A string representing the state
        :rtype: bytes
        )rHryr:ZSSL_state_string_longr)r3r!r!r"�get_state_string`szConnection.get_state_stringcCsft�|j�}|tjkrdSt�|jtjd�}|dks8t�td|�}t�|j||�t�||�dd�S)zi
        Get a copy of the server hello nonce.

        :return: A string representing the state
        Nrzunsigned char[])	r:�SSL_get_sessionrrHriZSSL_get_server_random�AssertionErrorr#rZ)r3�session�length�outpr!r!r"�
server_randomis

zConnection.server_randomcCsft�|j�}|tjkrdSt�|jtjd�}|dks8t�td|�}t�|j||�t�||�dd�S)zi
        Get a copy of the client hello nonce.

        :return: A string representing the state
        Nrzunsigned char[])	r:rHrrHriZSSL_get_client_randomrIr#rZ)r3rJrKrLr!r!r"�
client_randomxs

zConnection.client_randomcCsbt�|j�}|tjkrdSt�|tjd�}|dks6t�td|�}t�|||�t�||�dd�S)za
        Get a copy of the master key.

        :return: A string representing the state
        Nrzunsigned char[])	r:rHrrHriZSSL_SESSION_get_master_keyrIr#rZ)r3rJrKrLr!r!r"�
master_key�s

zConnection.master_keycOs|jj||�S)z_
        See shutdown(2)

        :return: What the socket's shutdown() method returns
        )rr=)r3r}r~r!r!r"�
sock_shutdown�szConnection.sock_shutdowncCs8t�|j�}|tjkr4t�t�}t�|tj�|_	|SdS)zi
        Retrieve the other side's certificate (if any)

        :return: The peer's certificate
        N)
r:ZSSL_get_peer_certificaterrHrirr9r�r�r;)r3rA�pycertr!r!r"�get_peer_certificate�s

zConnection.get_peer_certificatecCspt�|j�}|tjkrdSg}xLtt�|��D]:}t�t�||��}t	�
t	�}t�|tj�|_
|�|�q.W|S)z�
        Retrieve the other side's certificate (if any)

        :return: A list of X509 instances giving the peer's certificate chain,
                 or None if it does not have one.
        N)r:ZSSL_get_peer_cert_chainrrHrirAZsk_X509_numr�Z
sk_X509_valuerr9r�r�r;r?)r3Z
cert_stackrDr?rArQr!r!r"�get_peer_cert_chain�s

zConnection.get_peer_cert_chaincCst�|j�S)z�
        Checks if more data has to be read from the transport layer to complete
        an operation.

        :return: True iff more data has to be read
        )r:Z
SSL_want_readr)r3r!r!r"�	want_read�szConnection.want_readcCst�|j�S)z�
        Checks if there is data to write to the transport layer to complete an
        operation.

        :return: True iff there is data to write
        )r:ZSSL_want_writer)r3r!r!r"�
want_write�szConnection.want_writecCst�|j�dS)z�
        Set the connection to work in server mode. The handshake will be
        handled automatically by read/write.

        :return: None
        N)r:ZSSL_set_accept_stater)r3r!r!r"r;�szConnection.set_accept_statecCst�|j�dS)z�
        Set the connection to work in client mode. The handshake will be
        handled automatically by read/write.

        :return: None
        N)r:r5r)r3r!r!r"r9�szConnection.set_connect_statecCs8t�|j�}|tjkrdSt�t�}t�|tj�|_	|S)z�
        Returns the Session currently used.

        @return: An instance of :py:class:`OpenSSL.SSL.Session` or
            :py:obj:`None` if no session exists.
        N)
r:ZSSL_get1_sessionrrHrir�r9r�ZSSL_SESSION_free�_session)r3rJZ	pysessionr!r!r"�get_session�s

zConnection.get_sessioncCs0t|t�std��t�|j|j�}|s,t�dS)z�
        Set the session to be used when the TLS/SSL connection is established.

        :param session: A Session instance representing the session to use.
        :returns: None
        z"session must be a Session instanceN)rdr�rfr:ZSSL_set_sessionrrVr5)r3rJrDr!r!r"�set_session�s

zConnection.set_sessioncCsRt�dd�}||j|d�}|dkr&dStd|�}||j||�t�||�dd�S)a�
        Helper to implement :py:meth:`get_finished` and
        :py:meth:`get_peer_finished`.

        :param function: Either :py:data:`SSL_get_finished`: or
            :py:data:`SSL_get_peer_finished`.

        :return: :py:data:`None` if the desired message has not yet been
            received, otherwise the contents of the message.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`
        zchar[]rN)rHrQrr#rZ)r3�function�emptyr�r�r!r!r"�_get_finished_messages
z Connection._get_finished_messagecCs|�tj�S)a
        Obtain the latest `handshake finished` message sent to the peer.

        :return: The contents of the message or :py:obj:`None` if the TLS
            handshake has not yet completed.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`
        )r[r:ZSSL_get_finished)r3r!r!r"�get_finished$szConnection.get_finishedcCs|�tj�S)a

        Obtain the latest `handshake finished` message received from the peer.

        :return: The contents of the message or :py:obj:`None` if the TLS
            handshake has not yet completed.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`
        )r[r:ZSSL_get_peer_finished)r3r!r!r"�get_peer_finished.szConnection.get_peer_finishedcCs8t�|j�}|tjkrdSt�t�|��}|�d�SdS)z�
        Obtain the name of the currently used cipher.

        :returns: The name of the currently used cipher or :py:obj:`None`
            if no connection has been established.
        :rtype: :py:class:`unicode` or :py:class:`NoneType`
        Nzutf-8)r:�SSL_get_current_cipherrrHriryZSSL_CIPHER_get_namer�)r3�cipherr�r!r!r"�get_cipher_name8s

zConnection.get_cipher_namecCs,t�|j�}|tjkrdSt�|tj�SdS)a
        Obtain the number of secret bits of the currently used cipher.

        :returns: The number of secret bits of the currently used cipher
            or :py:obj:`None` if no connection has been established.
        :rtype: :py:class:`int` or :py:class:`NoneType`
        N)r:r^rrHriZSSL_CIPHER_get_bits)r3r_r!r!r"�get_cipher_bitsGs
zConnection.get_cipher_bitscCs8t�|j�}|tjkrdSt�t�|��}|�d�SdS)a
        Obtain the protocol version of the currently used cipher.

        :returns: The protocol name of the currently used cipher
            or :py:obj:`None` if no connection has been established.
        :rtype: :py:class:`unicode` or :py:class:`NoneType`
        Nzutf-8)r:r^rrHriryZSSL_CIPHER_get_versionr�)r3r_�versionr!r!r"�get_cipher_versionUs

zConnection.get_cipher_versioncCst�t�|j��}|�d�S)a?
        Obtain the protocol version of the current connection.

        :returns: The TLS version of the current connection, for example
            the value for TLS 1.2 would be ``TLSv1.2``or ``Unknown``
            for connections that were not successfully established.
        :rtype: :py:class:`unicode`
        zutf-8)rHryr:ZSSL_get_versionrr�)r3rbr!r!r"�get_protocol_version_nameds	z$Connection.get_protocol_version_namecCst�|j�}|S)z�
        Obtain the protocol version of the current connection.

        :returns: The TLS version of the current connection, for example
            the value for TLS 1 would be 0x769.
        :rtype: :py:class:`int`
        )r:ZSSL_versionr)r3rbr!r!r"�get_protocol_versionpszConnection.get_protocol_versioncCs@t�d�}t�d�}t�|j||�t�|d|d�dd�S)z>
        Get the protocol that was negotiated by NPN.
        zunsigned char **zunsigned int *rN)rHrQr:ZSSL_get0_next_proto_negotiatedrrZ)r3rl�data_lenr!r!r"�get_next_proto_negotiated{s

z$Connection.get_next_proto_negotiatedcCs>d�t�dd�|D���}t�d|�}t�|j|t|��dS)ah
        Specify the client's ALPN protocol list.

        These protocols are offered to the server during protocol negotiation.

        :param protos: A list of the protocols to be offered to the server.
            This list should be a Python list of bytestrings representing the
            protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
        rJcss|]}tt|��|fVqdS)N)rrK)rLrMr!r!r"rN�sz-Connection.set_alpn_protos.<locals>.<genexpr>zunsigned char[]N)	rOrrPrHrQr:ZSSL_set_alpn_protosrrK)r3rWrXr�r!r!r"r��s
zConnection.set_alpn_protoscCsHt�d�}t�d�}t�|j||�|s,dSt�|d|d�dd�S)z?
        Get the protocol that was negotiated by ALPN.
        zunsigned char **zunsigned int *rJrN)rHrQr:ZSSL_get0_alpn_selectedrrZ)r3rlrfr!r!r"�get_alpn_proto_negotiated�s

z$Connection.get_alpn_proto_negotiatedcCs t�|jtj�}t|dk�dS)a
        Called to request that the server sends stapled OCSP data, if
        available. If this is not called on the client side then the server
        will not send OCSP data. Should be used in conjunction with
        :meth:`Context.set_ocsp_client_callback`.
        r$N)r:ZSSL_set_tlsext_status_typerZTLSEXT_STATUSTYPE_ocspr�)r3r�r!r!r"�request_ocsp�szConnection.request_ocsp)N)r)r)N)NN)Crrr r+rr=r4rrrrrrrrr�writer"r(�readr,r.r/r0r2r3r1r4r6r8r:r<r=r@rBrCr�r�rDrFrGrMrNrOrPrRrSrTrUr;r9rWrXr[r\r]r`rarcrdrer	rgr
r�rhrir!r!r!r"r<Gsx
1)


$

)

	

			
				"

r<z:ConnectionType has been deprecated, use Connection instead)�r�r�sysr�	functoolsrr�	itertoolsrr�weakrefrrrZcryptography.utilsr	�sixr
rerrr
Z
OpenSSL._utilrr�rZ_exception_from_error_queuerrHrr:rZ_make_assertrr>rr�rr�rr#ZOpenSSL.cryptorrrrrrr)rr*�objectrZr#ZOPENSSL_VERSION_NUMBERZSSLEAY_VERSIONZ
SSLEAY_CFLAGSZSSLEAY_PLATFORMZ
SSLEAY_DIRZSSLEAY_BUILT_ONZSSL_SENT_SHUTDOWNZ
SENT_SHUTDOWNZSSL_RECEIVED_SHUTDOWNZRECEIVED_SHUTDOWNrrrrrrZSSL_OP_NO_SSLv2ZOP_NO_SSLv2ZSSL_OP_NO_SSLv3ZOP_NO_SSLv3ZSSL_OP_NO_TLSv1ZOP_NO_TLSv1ZSSL_OP_NO_TLSv1_1Z
OP_NO_TLSv1_1ZSSL_OP_NO_TLSv1_2Z
OP_NO_TLSv1_2ZSSL_MODE_RELEASE_BUFFERSZMODE_RELEASE_BUFFERSZSSL_OP_SINGLE_DH_USEZOP_SINGLE_DH_USEZSSL_OP_SINGLE_ECDH_USEZOP_SINGLE_ECDH_USEZSSL_OP_EPHEMERAL_RSAZOP_EPHEMERAL_RSAZSSL_OP_MICROSOFT_SESS_ID_BUGZOP_MICROSOFT_SESS_ID_BUGZSSL_OP_NETSCAPE_CHALLENGE_BUGZOP_NETSCAPE_CHALLENGE_BUGZ'SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGZ#OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGZ"SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUGZOP_SSLREF2_REUSE_CERT_TYPE_BUGZ!SSL_OP_MICROSOFT_BIG_SSLV3_BUFFERZOP_MICROSOFT_BIG_SSLV3_BUFFERZSSL_OP_MSIE_SSLV2_RSA_PADDINGZOP_MSIE_SSLV2_RSA_PADDINGZSSL_OP_SSLEAY_080_CLIENT_DH_BUGZOP_SSLEAY_080_CLIENT_DH_BUGZSSL_OP_TLS_D5_BUGZ
OP_TLS_D5_BUGZSSL_OP_TLS_BLOCK_PADDING_BUGZOP_TLS_BLOCK_PADDING_BUGZ"SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSZOP_DONT_INSERT_EMPTY_FRAGMENTSZSSL_OP_CIPHER_SERVER_PREFERENCEZOP_CIPHER_SERVER_PREFERENCEZSSL_OP_TLS_ROLLBACK_BUGZOP_TLS_ROLLBACK_BUGZSSL_OP_PKCS1_CHECK_1ZOP_PKCS1_CHECK_1ZSSL_OP_PKCS1_CHECK_2ZOP_PKCS1_CHECK_2ZSSL_OP_NETSCAPE_CA_DN_BUGZOP_NETSCAPE_CA_DN_BUGZ&SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGZ"OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGZSSL_OP_NO_COMPRESSIONZOP_NO_COMPRESSIONZSSL_OP_NO_QUERY_MTUZOP_NO_QUERY_MTUZSSL_OP_COOKIE_EXCHANGEZOP_COOKIE_EXCHANGEZSSL_OP_NO_TICKETZOP_NO_TICKETZ
SSL_OP_ALLZOP_ALLZSSL_VERIFY_PEERZVERIFY_PEERZSSL_VERIFY_FAIL_IF_NO_PEER_CERTZVERIFY_FAIL_IF_NO_PEER_CERTZSSL_VERIFY_CLIENT_ONCEZVERIFY_CLIENT_ONCEZSSL_VERIFY_NONEZVERIFY_NONEZSSL_SESS_CACHE_OFFZSESS_CACHE_OFFZSSL_SESS_CACHE_CLIENTZSESS_CACHE_CLIENTZSSL_SESS_CACHE_SERVERZSESS_CACHE_SERVERZSSL_SESS_CACHE_BOTHZSESS_CACHE_BOTHZSSL_SESS_CACHE_NO_AUTO_CLEARZSESS_CACHE_NO_AUTO_CLEARZ!SSL_SESS_CACHE_NO_INTERNAL_LOOKUPZSESS_CACHE_NO_INTERNAL_LOOKUPZ SSL_SESS_CACHE_NO_INTERNAL_STOREZSESS_CACHE_NO_INTERNAL_STOREZSSL_SESS_CACHE_NO_INTERNALZSESS_CACHE_NO_INTERNALZSSL_ST_CONNECTZ
SSL_ST_ACCEPTZSSL_ST_MASKZCryptography_HAS_SSL_STZSSL_ST_INITZ
SSL_ST_BEFOREZ	SSL_ST_OKZSSL_ST_RENEGOTIATEZSSL_CB_LOOPZSSL_CB_EXITZSSL_CB_READZSSL_CB_WRITEZSSL_CB_ALERTZSSL_CB_READ_ALERTZSSL_CB_WRITE_ALERTZSSL_CB_ACCEPT_LOOPZSSL_CB_ACCEPT_EXITZSSL_CB_CONNECT_LOOPZSSL_CB_CONNECT_EXITZSSL_CB_HANDSHAKE_STARTZSSL_CB_HANDSHAKE_DONEr�r�r�r�r>r*r5r�r,r-r.r/r0r1r8rIrYrcrhrnrxrzr�ZCryptography_HAS_NEXTPROTONEGr	ZCryptography_HAS_ALPNr
Z Cryptography_HAS_TLSEXT_HOSTNAMErr�r�r�DeprecationWarningZContextTyper<ZConnectionTypeZSSL_library_initr!r!r!r"�<module>s*, 
&)13H;	


wx

Youez - 2016 - github.com/yon3zu
LinuXploit