HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/site-packages/M2Crypto/SSL/__pycache__/Context.cpython-36.opt-1.pyc
3

YݧZ�B�@s�ddlmZddlmZmZmZmZmZmZddl	m
Z
ddlmZddl
mZejrrddlmZmZmZmZmZddd	gZGd
d�de�Zdd�ZeZGd
d�de�ZdS)�)�absolute_import)�BIO�Err�RSA�X509�m2�util)�cb)�Session)�WeakValueDictionary)�Any�AnyStr�Callable�Optional�Union�ctxmap�Context�mapc@s0eZdZdZdd�Zdd�Zdd�Zdd	�ZdS)
�_ctxmapNcCst�|_dS)z Simple WeakReffed list.
        N)rr)�self�r�/usr/lib64/python3.6/Context.py�__init__sz_ctxmap.__init__cCs
|j|S)N)r)r�keyrrr�__getitem__sz_ctxmap.__getitem__cCs||j|<dS)N)r)rr�valuerrr�__setitem__sz_ctxmap.__setitem__cCs|j|=dS)N)r)rrrrr�__delitem__"sz_ctxmap.__delitem__)�__name__�
__module__�__qualname__�	singletonrrrrrrrrrs
rcCstjdkrt�t_tjS)N)rr!rrrrr's
c@s"eZdZdZejZd<dd�Zdd�Zdd	�Z	de
jfd
d�Zde
jfdd
�Z
dd�ZeZZd=dd�ZeZdd�Zdd�Zdd�Zdd�Zd>dd�Zdd�Zdd�Zd d!�Zd?d"d#�Zd$d%�Zd@d&d'�Zejfd(d)�Z d*d+�Z!d,d-�Z"d.d/�Z#d0d1�Z$d2d3�Z%d4d5�Z&d6d7�Z'd8d9�Z(d:d;�Z)dS)Arz'Context' for SSL connections.�tlsNcCs�tt|dd�}|dkr8|dkr,ttd�}ntd|��tj|��|_d|_||_|t�t|j�<tj	|jd�|dkr�|dkr�|j
tjtjBtj
B�dS)	N�_methodr"Z
sslv23_methodzno such protocol '%s'r��sslv23)r%r")�getattrr�
ValueErrorZssl_ctx_new�ctx�allow_unknown_ca�post_connection_checkr�intZssl_ctx_set_cache_size�set_optionsZ
SSL_OP_ALLZSSL_OP_NO_SSLv2ZSSL_OP_NO_SSLv3)rZprotocolZweak_cryptor*�protorrrr6szContext.__init__cCst|dd�r|j|j�dS)Nr()r&�m2_ssl_ctx_freer()rrrr�__del__IszContext.__del__cCst�t|j�=dS)N)rr+r()rrrr�closeNsz
Context.closecCsJtj|j|�tj|j|�|s$|}tj|j|�tj|j�sFtd��dS)a4Load certificate and private key into the context.

        :param certfile: File that contains the PEM-encoded certificate.
        :param keyfile:  File that contains the PEM-encoded private key.
                         Default value of None indicates that the private key
                         is to be found in 'certfile'.
        :param callback: Callable object to be invoked if the private key is
                         passphrase-protected. Default callback provides a
                         simple terminal-style input for the passphrase.
        zpublic/private key mismatchN)r�ssl_ctx_passphrase_callbackr(Zssl_ctx_use_cert�ssl_ctx_use_privkey�ssl_ctx_check_privkeyr')rZcertfile�keyfile�callbackrrr�	load_certRs
zContext.load_certcCsJtj|j|�tj|j|�|s$|}tj|j|�tj|j�sFtd��dS)a�Load certificate chain and private key into the context.

        :param certchainfile: File object containing the PEM-encoded
                              certificate chain.
        :param keyfile:       File object containing the PEM-encoded private
                              key. Default value of None indicates that the
                              private key is to be found in 'certchainfile'.
        :param callback:      Callable object to be invoked if the private key
                              is passphrase-protected. Default callback
                              provides a simple terminal-style input for the
                              passphrase.
        zpublic/private key mismatchN)rr1r(Zssl_ctx_use_cert_chainr2r3r')rZ
certchainfiler4r5rrr�load_cert_chaingszContext.load_cert_chaincCstj|j|�dS)z�Load CA certs into the context. These CA certs are sent to the
        peer during *SSLv3 certificate request*.

        :param cafile: File object containing one or more PEM-encoded CA
                       certificates concatenated together.
        N)rZ$ssl_ctx_set_client_CA_list_from_filer()r�cafilerrr�set_client_CA_list_from_file~sz$Context.set_client_CA_list_from_filecCs(|dkr|dkrtd��tj|j||�S)a�Load CA certs into the context.

        These CA certs are used during verification of the peer's
        certificate.

        :param cafile: File containing one or more PEM-encoded CA
                       certificates concatenated together.

        :param capath: Directory containing PEM-encoded CA certificates
                       (one certificate per file).

        :return: 0 if the operation failed because CAfile and CApath are NULL
                  or the processing at one of the locations specified failed.
                  Check the error stack to find out the reason.

                1 The operation succeeded.
        Nz'cafile and capath can not both be None.)r'rZssl_ctx_load_verify_locationsr()rr8Zcapathrrr�load_verify_locations�szContext.load_verify_locationscCs&tj|j|�}|s"tjtj�d��dS)atSets the session id for the SSL.Context w/in a session can be reused.

        :param id: Sessions are generated within a certain context. When
                   exporting/importing sessions with
                   i2d_SSL_SESSION/d2i_SSL_SESSION it would be possible,
                   to re-import a session generated from another context
                   (e.g. another application), which might lead to
                   malfunctions. Therefore each application must set its
                   own session id context sid_ctx which is used to
                   distinguish the contexts and is stored in exported
                   sessions. The sid_ctx can be any kind of binary data
                   with a given length, it is therefore possible to use
                   e.g. the name of the application and/or the hostname
                   and/or service name.
        �N)rZssl_ctx_set_session_id_contextr(rZSSLErrorZget_error_code)r�id�retrrr�set_session_id_ctx�szContext.set_session_id_ctxcCstj|j�}|std��dS)a
        Specifies that the default locations from which CA certs are
        loaded should be used.

        There is one default directory and one default file. The default
        CA certificates directory is called "certs" in the default
        OpenSSL directory. Alternatively the SSL_CERT_DIR environment
        variable can be defined to override this location. The default
        CA certificates file is called "cert.pem" in the default OpenSSL
        directory. Alternatively the SSL_CERT_FILE environment variable
        can be defined to override this location.

        @return 0 if the operation failed. A missing default location is
                  still treated as a success. No error code is set.

                1 The operation succeeded.
        z)Cannot use default SSL certificate store!N)rZ ssl_ctx_set_default_verify_pathsr(r')rr=rrr�set_default_verify_paths�sz Context.set_default_verify_pathscCs
||_dS)z�Set the context to accept/reject a peer certificate if the
        certificate's CA is unknown.

        :param ok:       True to accept, False to reject.
        N)r))r�okrrr�set_allow_unknown_ca�szContext.set_allow_unknown_cacCs|jS)z�Get the context's setting that accepts/rejects a peer
        certificate if the certificate's CA is unknown.

        FIXME 2Bconverted to bool
        )r))rrrr�get_allow_unknown_ca�szContext.get_allow_unknown_cacCs:|dkrtj|j|�ntj|j||�tj|j|�dS)a[
        Set verify options. Most applications will need to call this
        method with the right options to make a secure SSL connection.

        :param mode:     The verification mode to use. Typically at least
                         SSL.verify_peer is used. Clients would also typically
                         add SSL.verify_fail_if_no_peer_cert.
        :param depth:    The maximum allowed depth of the certificate chain
                         returned by the peer.
        :param callback: Callable that can be used to specify custom
                         verification checks.
        N)rZssl_ctx_set_verify_defaultr(Zssl_ctx_set_verifyZssl_ctx_set_verify_depth)r�mode�depthr5rrr�
set_verify�szContext.set_verifycCstj|j�S)N)rZssl_ctx_get_verify_moder()rrrr�get_verify_mode�szContext.get_verify_modecCstj|j�S)z?Returns the verification mode currently set in the SSL Context.)rZssl_ctx_get_verify_depthr()rrrr�get_verify_depth�szContext.get_verify_depthcCs&tj|�}tj|j��}tj|j|�S)z�Load ephemeral DH parameters into the context.

        :param dhpfile: Filename of the file containing the PEM-encoded
                        DH parameters.
        )rZopenfilerZdh_read_parametersZbio_ptrZssl_ctx_set_tmp_dhr()rZdhpfile�fZdhprrr�
set_tmp_dhs
zContext.set_tmp_dhcCs|dk	rtj|j|�dS)z�Sets the callback function for SSL.Context.

        :param callback: Callable to be used when a DH parameters are required.
        N)rZssl_ctx_set_tmp_dh_callbackr()rr5rrr�set_tmp_dh_callbackszContext.set_tmp_dh_callbackcCs,t|tj�rtj|j|j�Std|��dS)zXLoad ephemeral RSA key into the context.

        :param rsa: RSA.RSA instance.
        z(Expected an instance of RSA.RSA, got %s.N)�
isinstancerrZssl_ctx_set_tmp_rsar(�rsa�	TypeError)rrLrrr�set_tmp_rsaszContext.set_tmp_rsacCs|dk	rtj|j|�dS)zfSets the callback function to be used when
        a temporary/ephemeral RSA key is required.
        N)rZssl_ctx_set_tmp_rsa_callbackr()rr5rrr�set_tmp_rsa_callbackszContext.set_tmp_rsa_callbackcCstj|j|�dS)a!Set a callback function to get state information.

        It can be used to get state information about the SSL
        connections that are created from this context.

        :param callback: Callback function. The default prints
                         information to stderr.
        N)rZssl_ctx_set_info_callbackr()rr5rrr�set_info_callback's
zContext.set_info_callbackcCstj|j|�S)z�Sets the list of available ciphers.

        :param cipher_list: The format of the string is described in
                            ciphers(1).
        :return: 1 if any cipher could be selected and 0 on complete
                 failure.
        )rZssl_ctx_set_cipher_listr()rZcipher_listrrr�set_cipher_list3s	zContext.set_cipher_listcCstj|j|j��S)z�Add the session to the context.

        :param session: the session to be added.

        :return: 0 The operation failed. It was tried to add the same
                   (identical) session twice.

                 1 The operation succeeded.
        )rZssl_ctx_add_sessionr(�_ptr)r�sessionrrr�add_session>szContext.add_sessioncCstj|j|j��S)z�Remove the session from the context.

        :param session: the session to be removed.

        :return: 0 The operation failed. The session was not found in
                   the cache.

                 1 The operation succeeded.
        )rZssl_ctx_remove_sessionr(rR)rrSrrr�remove_sessionKszContext.remove_sessioncCstj|j�S)a�Get current session timeout.

        Whenever a new session is created, it is assigned a maximum
        lifetime.  This lifetime is specified by storing the creation
        time of the session and the timeout value valid at this time. If
        the actual time is later than creation time plus timeout, the
        session is not reused.

        Due to this realization, all sessions behave according to the
        timeout value valid at the time of the session negotiation.
        Changes of the timeout value do not affect already established
        sessions.

        Expired sessions are removed from the internal session cache,
        whenever SSL_CTX_flush_sessions(3) is called, either directly by
        the application or automatically (see
        SSL_CTX_set_session_cache_mode(3))

        The default value for session timeout is decided on a per
        protocol basis, see SSL_get_default_timeout(3).  All currently
        supported protocols have the same default timeout value of 300
        seconds.

        SSL_CTX_set_timeout() returns the previously set timeout value.

        :return: the currently set timeout value.
        )rZssl_ctx_get_session_timeoutr()rrrr�get_session_timeoutXszContext.get_session_timeoutcCstj|j|�S)z�Set new session timeout.

        See self.get_session_timeout() for explanation of the session
        timeouts.

        :param timeout: new timeout value.

        :return: the previously set timeout value.
        )rZssl_ctx_set_session_timeoutr()rZtimeoutrrr�set_session_timeoutwszContext.set_session_timeoutcCstj|j|�S)z�Enables/disables session caching.

        The mode is set by using m2.SSL_SESS_CACHE_* constants.

        :param mode: new mode value.

        :return: the previously set cache mode value.
        )rZssl_ctx_set_session_cache_moder()rrCrrr�set_session_cache_mode�s
zContext.set_session_cache_modecCstj|j�S)z�Gets the current session caching.

        The mode is set to m2.SSL_SESS_CACHE_* constants.

        :return: the previously set cache mode value.
        )rZssl_ctx_get_session_cache_moder()rrrr�get_session_cache_mode�szContext.get_session_cache_modecCstj|j|�S)a)Adds the options set via bitmask in options to the Context.

        !!! Options already set before are not cleared!

        The behaviour of the SSL library can be changed by setting
        several options.  The options are coded as bitmasks and can be
        combined by a logical or operation (|).

        SSL.Context.set_options() and SSL.set_options() affect the
        (external) protocol behaviour of the SSL library. The (internal)
        behaviour of the API can be changed by using the similar
        SSL.Context.set_mode() and SSL.set_mode() functions.

        During a handshake, the option settings of the SSL object are
        used. When a new SSL object is created from a context using
        SSL(), the current option setting is copied. Changes to ctx
        do not affect already created SSL objects. SSL.clear() does not
        affect the settings.

        :param op: bitmask of additional options specified in
                   SSL_CTX_set_options(3) manpage.

        :return: the new options bitmask after adding options.
        )rZssl_ctx_set_optionsr()r�oprrrr,�szContext.set_optionscCstjtj|j��S)z�
        Get the certificate store associated with this context.

        :warning: The store is NOT refcounted, and as such can not be relied
                  to be valid once the context goes away or is changed.
        )rZ
X509_StorerZssl_ctx_get_cert_storer()rrrr�get_cert_store�szContext.get_cert_store)r"NN)NN)N)N)N)*rrr �__doc__rZssl_ctx_freer.rr/r0rZpassphrase_callbackr6r7r9Zload_client_CAZload_client_car:Zload_verify_infor>r?rArBrErFrGrIrJrNrOr	Zssl_info_callbackrPrQrTrUrVrWrXrYr,r[rrrrr0sF

		

	




N)Z
__future__rZM2CryptorrrrrrZM2Crypto.SSLr	ZM2Crypto.SSL.Sessionr
�weakrefrZpy27plusZtypingrr
rrr�__all__�objectrrrrrrrr�<module>s