Current File : //usr/lib/python3/dist-packages/twisted/protocols/test/__pycache__/test_tls.cpython-312.pyc |
�
Ϫ�ft � � � d Z ddlmZ ddlZddlmZ ddlmZmZm Z ddl
mZ ddlm
Z
mZ ddlmZ dd lmZmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z" dd
l#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA ddlBmCZCmDZDmEZEmFZF ddlmGZG ddlHmIZImJZJ ddlKmLZLmMZM ddlNmOZO ddlPmQZQ ddlRmSZS ddlTmUZU ddlVmWZW ddlXmYZYmZZZ G d� d � Z[ G d!� d"eE� Z\ d5d#�Z] G d$� d%eZ� Z^ d6d&�Z_ G d'� d(eY� Z` G d)� d*eZ� Za G d+� d,eZ� Zb G d-� d.eZ� Zc e e>� G d/� d0eC� � Zd e e>� G d1� d2eF� � Ze G d3� d4eY� Zfy# e2$ r dZ3dxZxZ!xZZ Y ��
w xY w)7z%
Tests for L{twisted.protocols.tls}.
� )�annotationsN)�Union)� Interface�directlyProvides�implementer)�verifyObject)�given�
strategies)�reactor)�Clock�
deferLater)� iterbytes)�crypto) �SSL_CB_HANDSHAKE_DONE�
TLS_METHOD�
Connection�Context�Error�TLSv1_1_METHOD�TLSv1_2_METHOD�TLSv1_METHOD�
WantReadError)�TLSMemoryBIOFactory�TLSMemoryBIOProtocol�_AggregateSmallWrites�_ProducerMembrane�_PullToPush)�PrivateCertificate�optionsForClientTLS)�ClientTLSContext�ServerTLSContext�certPath)�!certificatesForAuthorityAndServerz;pyOpenSSL 16.0.0 or newer required for twisted.protocol.tls)�Deferred�
gatherResults)�ConnectionDone�ConnectionLost)�IHandshakeListener�IOpenSSLClientConnectionCreator�IOpenSSLServerConnectionCreator�IProtocolNegotiationFactory�
IPushProducer�
ISSLTransport�
ISystemHandle)�
ClientFactory�Factory�Protocol�
ServerFactory)�TaskStopped)�NonStreamingProducer�StringTransport)�collapsingPumpPolicy�
loopbackAsync)�log)�Failure)�FilePath)�connectedServerAndClient��ConnectionLostNotifyingProtocol)�SynchronousTestCase�TestCasec �6 � e Zd ZdZefd�Zed� � Zd� Zd� Z y)�HandshakeCallbackContextFactorya
L{HandshakeCallbackContextFactory} is a factory for SSL contexts which
allows applications to get notification when the SSL handshake completes.
@ivar _finished: A L{Deferred} which will be called back when the handshake
is done.
c �0 � t � | _ || _ y �N)r$ � _finished�_method)�self�methods �A/usr/lib/python3/dist-packages/twisted/protocols/test/test_tls.py�__init__z(HandshakeCallbackContextFactory.__init__T s � �!������� c �, � | � }||j fS )z�
Create a new L{HandshakeCallbackContextFactory} and return a two-tuple
of it and a L{Deferred} which will fire when a connection created with
it completes a TLS handshake.
)rD )�cls�contextFactorys rH �factoryAndDeferredz2HandshakeCallbackContextFactory.factoryAndDeferredX s � � ����~�7�7�7�7rJ c �N � |t z r| j j d� yy)a
This is the "info callback" on the context. It will be called
periodically by pyOpenSSL with information about the state of a
connection. When it indicates the handshake is complete, it will fire
C{self._finished}.
N)r rD �callback)rF �
connection�where�rets rH �_infoz%HandshakeCallbackContextFactory._infob s$ � � �(�(��N�N�#�#�D�)� )rJ c �f � t | j � }|j | j � |S )zp
Create and return an SSL context configured to use L{self._info} as the
info callback.
)r rE �set_info_callbackrT )rF �contexts rH �
getContextz*HandshakeCallbackContextFactory.getContextl s) � �
�$�,�,�'���!�!�$�*�*�-��rJ N)
�__name__�
__module__�__qualname__�__doc__r rI �classmethodrN rT rX � rJ rH rA rA K s/ � �� )� � �8� �8�*�rJ rA c �( � e Zd ZdZd� Zd� Zd� Zd� Zy)�AccumulatingProtocola.
A protocol which collects the bytes it receives and closes its connection
after receiving a certain minimum of data.
@ivar howMany: The number of bytes of data to wait for before closing the
connection.
@ivar received: A L{list} of L{bytes} of the bytes received so far.
c � � || _ y rC )�howMany)rF rb s rH rI zAccumulatingProtocol.__init__� s � ���rJ c � � g | _ y rC )�received�rF s rH �connectionMadez#AccumulatingProtocol.connectionMade� s � ���
rJ c �� � | j j |� t t t | j � � | j
k\ r| j j � y y rC )rd �append�sum�map�lenrb � transport�loseConnection�rF �datas rH �dataReceivedz!AccumulatingProtocol.dataReceived� sE � ��
�
���T�"��s�3��
�
�&�'�4�<�<�7��N�N�)�)�+� 8rJ c �Z � |j t � st j |� y y rC )�checkr&