File manager - Edit - /usr/lib/python3/dist-packages/twisted/internet/__pycache__/ssl.cpython-310.pyc
Back
o �b�! � @ sD d Z ddlmZmZmZ ddlmZ ddlmZm Z dZ eej�G dd� d��ZG dd � d e�Z eej�G d d� d��Zeejgdd � ee j�D ��R � G dd� de j��Zeej�G dd� de j��ZG dd� de j�ZG dd� de j�ZddlmZmZmZmZmZmZmZmZmZ m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( g d�Z)dS )a This module implements Transport Layer Security (TLS) support for Twisted. It requires U{PyOpenSSL <https://pypi.python.org/pypi/pyOpenSSL>}. If you wish to establish a TLS connection, please use one of the following APIs: - SSL endpoints for L{servers <twisted.internet.endpoints.SSL4ServerEndpoint>} and L{clients <twisted.internet.endpoints.SSL4ClientEndpoint>} - L{startTLS <twisted.internet.interfaces.ITLSTransport.startTLS>} - L{connectSSL <twisted.internet.interfaces.IReactorSSL.connectSSL>} - L{listenSSL <twisted.internet.interfaces.IReactorSSL.listenSSL>} These APIs all require a C{contextFactory} argument that specifies their security properties, such as certificate, private key, certificate authorities to verify the peer, allowed TLS protocol versions, cipher suites, and so on. The recommended value for this argument is a L{CertificateOptions} instance; see its documentation for an explanation of the available options. The C{contextFactory} name is a bit of an anachronism now, as context factories have been replaced with "connection creators", but these objects serve the same role. Be warned that implementing your own connection creator (i.e.: value for the C{contextFactory}) is both difficult and dangerous; the Twisted team has worked hard to make L{CertificateOptions}' API comprehensible and unsurprising, and the Twisted team is actively maintaining it to ensure that it becomes more secure over time. If you are really absolutely sure that you want to take on the risk of implementing your own connection creator based on the pyOpenSSL API, see the L{server connection creator <twisted.internet.interfaces.IOpenSSLServerConnectionCreator>} and L{client connection creator <twisted.internet.interfaces.IOpenSSLServerConnectionCreator>} interfaces. Developers using Twisted, please ignore the L{Port}, L{Connector}, and L{Client} classes defined here, as these are details of certain reactors' TLS implementations, exposed by accident (and remaining here only for compatibility reasons). If you wish to establish a TLS connection, please use one of the APIs listed above. @note: "SSL" (Secure Sockets Layer) is an antiquated synonym for "TLS" (Transport Layer Security). You may see these terms used interchangeably throughout the documentation. � )� implementedBy�implementer�implementer_only)�SSL)� interfaces�tcpTc @ s e Zd ZdZdZdd� ZdS )�ContextFactoryz>A factory for SSL context objects, for server SSL connections.r c C s t �)z4Return a SSL.Context object. override in subclasses.��NotImplementedError��self� r �6/usr/lib/python3/dist-packages/twisted/internet/ssl.py� getContextJ s zContextFactory.getContextN)�__name__� __module__�__qualname__�__doc__�isClientr r r r r r D s r c @ sF e Zd ZdZdZejejfdd�Zdd� Z dd� Z d d � Zdd� ZdS ) �DefaultOpenSSLContextFactoryaQ L{DefaultOpenSSLContextFactory} is a factory for server-side SSL context objects. These objects define certain parameters related to SSL handshakes and the subsequent connection. @ivar _contextFactory: A callable which will be used to create new context objects. This is typically L{OpenSSL.SSL.Context}. Nc C s$ || _ || _|| _|| _| �� dS )z� @param privateKeyFileName: Name of a file containing a private key @param certificateFileName: Name of a file containing a certificate @param sslmethod: The SSL method to use N)�privateKeyFileName�certificateFileName� sslmethod�_contextFactory�cacheContext)r r r r r r r r �__init__[ s z%DefaultOpenSSLContextFactory.__init__c C sH | j d u r"| �| j�}|�tj� |�| j� |�| j � || _ d S d S �N) �_contextr r �set_optionsr �OP_NO_SSLv2�use_certificate_filer �use_privatekey_filer �r �ctxr r r r q s �z)DefaultOpenSSLContextFactory.cacheContextc C s | j �� }|d= |S )Nr )�__dict__�copy)r �dr r r �__getstate__{ s z)DefaultOpenSSLContextFactory.__getstate__c C s || _ d S r )r$ )r �stater r r �__setstate__� s z)DefaultOpenSSLContextFactory.__setstate__c C s | j S )z( Return an SSL context. )r r r r r r � s z'DefaultOpenSSLContextFactory.getContext) r r r r r r � SSLv23_METHOD�Contextr r r'