
    VhZ                        d Z ddlZddlZddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ 	 ddlmamZ ddlma ddlmZmZ ddlm Z   G d dejB                        Z" G d dejB                        Z# G d dejH                        Z% G d dejH                        Z& e ejN                         G d dejH                               Z(d Z)d Z* G d d      Z+t.         G d dt2        jX                        Z- G d  d!ee      Z. G d" d#e      Z/ G d$ d%e/      Z0 G d& d'e      Z1 G d( d)ee+      Z2 G d* d+      Z3 G d, d-e      Z4 G d. d/e      Z5y# e$ r d Z e        Y w xY w)0z 
Tests for twisted SSL support.
    N)defer
interfacesprotocolreactor)ConnectionDone)waitUntilAllDisconnected)basic)FilePath)platform)ProperlyCloseFilesMixin)TestCase)SSLcrypto)ssl)ClientTLSContextcertPathc                      d xa ay N)r   r        E/home/dcms/DCMS/lib/python3.12/site-packages/twisted/test/test_ssl.py_noSSLr      s     cr   )implementerc                   8    e Zd ZdZg dZddgZd Zd Zd Zd Z	y	)
UnintelligentProtocola  
    @ivar deferred: a deferred that will fire at connection lost.
    @type deferred: L{defer.Deferred}

    @cvar pretext: text sent before TLS is set up.
    @type pretext: C{bytes}

    @cvar posttext: text sent after TLS is set up.
    @type posttext: C{bytes}
    )s
   first lines   last thing before tls starts   STARTTLSs   first thing after tls starteds   last thing everc                 6    t        j                         | _        y r   r   Deferreddeferredselfs    r   __init__zUnintelligentProtocol.__init__7       (r   c                 H    | j                   D ]  }| j                  |        y r   )pretextsendLine)r"   ls     r   connectionMadez$UnintelligentProtocol.connectionMade:   s!     	AMM!	r   c                     |dk(  ru| j                   j                  t               | j                  j                         | j
                  D ]  }| j                  |        | j                   j                          y y )N   READY)	transportstartTLSr   factoryclientposttextr'   loseConnection)r"   liner(   s      r   lineReceivedz"UnintelligentProtocol.lineReceived>   s`    8NN##$4$68K8KL]] !a !NN))+	 r   c                 :    | j                   j                  d        y r   r    callbackr"   reasons     r   connectionLostz$UnintelligentProtocol.connectionLostE       t$r   N)
__name__
__module____qualname____doc__r&   r0   r#   r)   r3   r9   r   r   r   r   r   '   s.    	 LG02DEH),%r   r   c                   0    e Zd ZdZddZd Zd Zd Zd Zy)	LineCollectoraJ  
    @ivar deferred: a deferred that will fire at connection lost.
    @type deferred: L{defer.Deferred}

    @ivar doTLS: whether the protocol is initiate TLS or not.
    @type doTLS: C{bool}

    @ivar fillBuffer: if set to True, it will send lots of data once
        C{STARTTLS} is received.
    @type fillBuffer: C{bool}
    c                 R    || _         || _        t        j                         | _        y r   )doTLS
fillBufferr   r   r    )r"   rB   rC   s      r   r#   zLineCollector.__init__V   s    
$(r   c                 H    d| j                   _        g | j                   _        y )Nr   )r.   rawdatalinesr!   s    r   r)   zLineCollector.connectionMade[   s    "r   c                    | j                   j                  j                  |       |dk(  r| j                  r!t	        d      D ]  }| j                  d        | j                  d       | j                  rFt        t        t              }| j                  j                  || j                   j                         y | j                          y y )Nr   i  s  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr+   )privateKeyFileNamecertificateFileName)r.   rF   appendrC   ranger'   rB   ServerTLSContextr   r,   r-   server
setRawMode)r"   r2   xctxs       r   r3   zLineCollector.lineReceived_   s    !!$';s /AMM+./MM(#zz&'/(0 ''T\\-@-@A! r   c                 v    | j                   xj                  |z  c_        | j                  j                          y r   )r.   rE   r,   r1   r"   datas     r   rawDataReceivedzLineCollector.rawDataReceivedo   s'    $%%'r   c                 :    | j                   j                  d        y r   r5   r7   s     r   r9   zLineCollector.connectionLosts   r:   r   NF)	r;   r<   r=   r>   r#   r)   r3   rT   r9   r   r   r   r@   r@   I   s     
)
 " (%r   r@   c                       e Zd ZdZd Zy)SingleLineServerProtocolzK
    A protocol that sends a single line of data at C{connectionMade}.
    c                 n    | j                   j                  d       | j                   j                          y )N   +OK <some crap>
)r,   writegetPeerCertificater!   s    r   r)   z'SingleLineServerProtocol.connectionMade|   s%    34))+r   N)r;   r<   r=   r>   r)   r   r   r   rX   rX   w   s    ,r   rX   c                   "    e Zd ZdZd Zd Zd Zy)RecordingClientProtocolzv
    @ivar deferred: a deferred that will fire with first received content.
    @type deferred: L{defer.Deferred}
    c                 6    t        j                         | _        y r   r   r!   s    r   r#   z RecordingClientProtocol.__init__   r$   r   c                 8    | j                   j                          y r   )r,   r\   r!   s    r   r)   z&RecordingClientProtocol.connectionMade   s    ))+r   c                 :    | j                   j                  |       y r   r5   rR   s     r   dataReceivedz$RecordingClientProtocol.dataReceived   r:   r   N)r;   r<   r=   r>   r#   r)   rb   r   r   r   r^   r^      s    
),%r   r^   c                       e Zd ZdZd Zd Zy) ImmediatelyDisconnectingProtocolz
    A protocol that disconnect immediately on connection. It fires the
    C{connectionDisconnected} deferred of its factory on connetion lost.
    c                 8    | j                   j                          y r   r,   r1   r!   s    r   handshakeCompletedz3ImmediatelyDisconnectingProtocol.handshakeCompleted   s    %%'r   c                 N    | j                   j                  j                  d        y r   )r.   connectionDisconnectedr6   r7   s     r   r9   z/ImmediatelyDisconnectingProtocol.connectionLost   s    ++44T:r   N)r;   r<   r=   r>   rg   r9   r   r   r   rd   rd      s    
(;r   rd   c                    t        j                         }|j                  t         j                  d       t        j                         }|j                         }| |_        ||_        |j                  |       |j                  |d       t        j                         }|j                  d       |j                  d       |j                  d       |j                  |j                                |j                  |j                                |j                  |j!                                |j                  |d       |||fS )z
    Create a certificate for given C{organization} and C{organizationalUnit}.

    @return: a tuple of (key, request, certificate) objects.
    i   md5   r   <   )r   PKeygenerate_keyTYPE_RSAX509Reqget_subjectOOU
set_pubkeysignX509set_serial_numbergmtime_adj_notBeforegmtime_adj_notAfter
set_issuerset_subject
get_pubkey)organizationorganizationalUnitpkeyreqsubjectcerts         r   generateCertificateObjectsr      s     ;;=Dfoot,
..
CooGGI#GJNN4HHT5 ;;=D1a R OOCOO%&S__&'OOCNN$%IIdEd?r   c                 d   t        ||      \  }}}d|t        j                  fd|t        j                  fd|t        j                  ffD ]e  \  }}}t
        j                  j                  | |f      j                  d      }	t        |	      j                   |t        j                  |             g y)z
    Create certificate files key, req and cert prefixed by C{basename} for
    given C{organization} and C{organizationalUnit}.
    keyr   r   zutf-8N)r   r   dump_privatekeydump_certificate_requestdump_certificateosextsepjoinencoder
   
setContentFILETYPE_PEM)
basenamer~   r   r   r   r   extobjdumpFuncfNames
             r   generateCertificateFilesr      s    
 1?QROD#t 
f,,-	V445	v../ GS(
 		#/66w?""8F,?,?#EFGr   c                       e Zd ZdZd Zd Zy)ContextGeneratingMixinah  
    Offer methods to create L{ssl.DefaultOpenSSLContextFactory} for both client
    and server.

    @ivar clientBase: prefix of client certificate files.
    @type clientBase: C{str}

    @ivar serverBase: prefix of server certificate files.
    @type serverBase: C{str}

    @ivar clientCtxFactory: a generated context factory to be used in
        L{IReactorSSL.connectSSL}.
    @type clientCtxFactory: L{ssl.DefaultOpenSSLContextFactory}

    @ivar serverCtxFactory: a generated context factory to be used in
        L{IReactorSSL.listenSSL}.
    @type serverCtxFactory: L{ssl.DefaultOpenSSLContextFactory}
    c                     | j                         }t        |||       t        j                  t        j
                  j                  |df      t        j
                  j                  |df      g|i |}||fS )Nr   r   )mktempr   r   DefaultOpenSSLContextFactoryr   r   r   )r"   orgorgUnitargskwArgsbaseserverCtxFactorys          r   makeContextFactoryz)ContextGeneratingMixin.makeContextFactory   st    {{} sG4;;IINND%=)IINND&>*
 
 	
 %%%r   c                      | j                   |i |\  | _        | _         | j                   |i |\  | _        | _        y r   )r   
clientBaseclientCtxFactory
serverBaser   )r"   
clientArgsclientKwArgs
serverArgsserverKwArgss        r   setupServerAndClientz+ContextGeneratingMixin.setupServerAndClient   sS    1H1H1H2
'2
.. 2I1H1H2
'2
..r   N)r;   r<   r=   r>   r   r   r   r   r   r   r      s    &
&
r   r   c                       e Zd ZdZdZd Zy)rL   zf
        A context factory with a default method set to
        L{OpenSSL.SSL.SSLv23_METHOD}.
        Fc                 p    t         j                  |d<   t        j                  j                  | g|i | y )N	sslmethod)r   SSLv23_METHODr   r   r#   )r"   r   kws      r   r#   zServerTLSContext.__init__   s/    !//B{O,,55dHTHRHr   N)r;   r<   r=   r>   isClientr#   r   r   r   rL   rL      s    	
 	Ir   rL   c                   R    e Zd ZdZ ej
                  ed      dZd Zd Z	d Z
d Zy)StolenTCPTestszc
    For SSL transports, test many of the same things which are tested for
    TCP transports.
    N2Reactor does not support SSL, cannot run SSL testsc                     t         j                  j                  t        t              j                               }|j                         }t        j                  ||||      S )zY
        Create an SSL server with a certificate using L{IReactorSSL.listenSSL}.
        	interface)	r   PrivateCertificateloadPEMr
   r   
getContentoptionsr   	listenSSL)r"   address
portNumberr.   r   contextFactorys         r   createServerzStolenTCPTests.createServer  sK     %%--hx.@.K.K.MN  WnPWXXr   c                 P    t        j                         }|j                  |||      S )zG
        Create an SSL client using L{IReactorSSL.connectSSL}.
        )r   CertificateOptions
connectSSL)r"   r   r   clientCreatorr   s        r   connectClientzStolenTCPTests.connectClient  s'     //1''^LLr   c                 "    t         j                  S )z
        Return L{OpenSSL.SSL.Error} as the expected error type which will be
        raised by a write to the L{OpenSSL.SSL.Connection} object after it has
        been closed.
        )r   Errorr!   s    r   getHandleExceptionTypez%StolenTCPTests.getHandleExceptionType  s     yyr   c                 >   t        j                  t        j                  t        j                  d      t        j                  t        j                  d      t        j                  d      t        j                  d            t        j                  d                  S )a4  
        Return a L{hamcrest.core.matcher.Matcher} for the argument
        L{OpenSSL.SSL.Error} will be constructed with for this case.
        This is basically just a random OpenSSL implementation detail.
        It would be better if this test worked in a way which did not
        require this.
        zSSL routines	SSL_writessl_write_internal zprotocol is shutdown)hamcrestcontainsequal_toany_ofr!   s    r   getHandleErrorCodeMatcherz(StolenTCPTests.getHandleErrorCodeMatcher#  s{       !!.1%%k2%%&:;%%b)
 !!"89

 
	
r   )r;   r<   r=   r>   r   IReactorSSLr   skipr   r   r   r   r   r   r   r   r     s9    
 zgt,4CYM
r   r   c                   f    e Zd ZdZ ej
                  ed      dZdZdZ	dZ
d Zd
dZd Zd Zd	 Zy)TLSTestsz
    Tests for startTLS support.

    @ivar fillBuffer: forwarded to L{LineCollector.fillBuffer}
    @type fillBuffer: C{bool}
    Nr   Fc                     | j                   j                  $| j                   j                  j                          | j                  j                  %| j                  j                  j                          y y r   )clientProtor,   r1   serverProtor!   s    r   tearDownzTLSTests.tearDownJ  s[    %%1&&557%%1&&557 2r   c                    | _         t        j                         x}| _        fd|_        |rd|_        nd|_        | _        t        j                         x}| _        fd|_        |rd|_        nd|_        t        j                  d|d      }| j                  |j                         t        j                  d|j                         j                  |       t!        j"                  j$                  j$                  g      S )a  
        Helper method to run TLS tests.

        @param clientProto: protocol instance attached to the client
            connection.
        @param serverProto: protocol instance attached to the server
            connection.
        @param clientIsServer: flag indicated if client should initiate
            startTLS instead of server.

        @return: a L{defer.Deferred} that will fire when both connections are
            lost.
        c                       S r   r   r   s   r   <lambda>z#TLSTests._runTest.<locals>.<lambda>`      k r   FTc                       S r   r   r   s   r   r   z#TLSTests._runTest.<locals>.<lambda>h  r   r   r   	127.0.0.1r   )r   r   ClientFactoryclientFactoryrM   r/   r   ServerFactoryserverFactoryr   	listenTCP
addCleanupstopListening
connectTCPgetHostportr   gatherResultsr    )r"   r   r   clientIsServercfsfr   s    ``    r   _runTestzTLSTests._runTestP  s     '"*"8"8"::T)BIBI&"*"8"8"::T)BIBI  B+>**+;(;(;R@""K$8$8+:N:N#OPPr   c                       fd} j                  t               t        d j                              }|j	                  |      S )z~
        Test for server and client startTLS: client should received data both
        before and after the startTLS.
        c                     j                  j                  j                  t        j                  t        j
                  z          y r   )assertEqualr   rF   r   r&   r0   )ignorer"   s    r   checkz TLSTests.test_TLS.<locals>.check{  5    ""((%--0E0N0NNr   Tr   r   r@   rC   addCallbackr"   r   ds   `  r   test_TLSzTLSTests.test_TLSu  s8    	 MM/1=t3WX}}U##r   c                       fd} j                  t               t        d j                              }|j	                  |      S )z
        Test for server startTLS not followed by a startTLS in client: the data
        received after server startTLS should be received as raw.
        c                     j                  j                  j                  t        j                         j                  j                  j                  d       y )NzNo encrypted bytes received)r   r   rF   r   r&   
assertTruerE   ignoredr"   s    r   r   z"TLSTests.test_unTLS.<locals>.check  sA    T//557L7T7TUOOD..668UVr   Fr   r   s   `  r   
test_unTLSzTLSTests.test_unTLS  s=    	W MM!#]5$//%J
 }}U##r   c                       fd} j                  t        d j                        t               d      }|j	                  |      S )z:
        Test startTLS first initiated by client.
        c                     j                  j                  j                  t        j                  t        j
                  z          y r   )r   r   rF   r   r&   r0   r   s    r   r   z)TLSTests.test_backwardsTLS.<locals>.check  r   r   T)r   r@   rC   r   r   r   s   `  r   test_backwardsTLSzTLSTests.test_backwardsTLS  s?    
	 MM$02G2I4
 }}U##r   rV   )r;   r<   r=   r>   r   r   r   r   rC   r   r   r   r   r   r   r  r   r   r   r   r   :  sM     zgt,4CJKK8#QJ$$$r   r   c                   >    e Zd ZdZ ej
                  ed      dZdZy)SpammyTLSTestszA
    Test TLS features with bytes sitting in the out buffer.
    Nr   T)	r;   r<   r=   r>   r   r   r   r   rC   r   r   r   r  r    s(     zgt,4CJr   r  c                   J    e Zd Z ej                  ed      dZdZdZd Z	d Z
y)BufferingTestsNr   c                 6   | j                   j                  $| j                   j                  j                          | j                  j                  $| j                  j                  j                          t	        t
        | j                   | j                  g      S r   )r   r,   r1   r   r   r   r!   s    r   r   zBufferingTests.tearDown  st    %%1&&557%%1&&557'$2B2BDDTDT1UVVr   c                 ~   t               x| _        t               x| _        t	        j
                         }t	        j                         x}| _        fd|_        fd|_        t        j                  t        t              }t        j                         }t        j                  d||d      }| j                  |j                         t        j                   d|j#                         j$                  ||      }| j                  |j&                         j(                  j+                  | j,                  d      S )Nc                       S r   r   r   s   r   r   z6BufferingTests.test_openSSLBuffering.<locals>.<lambda>      + r   c                       S r   r   r   s   r   r   z6BufferingTests.test_openSSLBuffering.<locals>.<lambda>  r  r   r   r   r   rZ   )rX   r   r^   r   r   r   r   r/   r   r   r   ClientContextFactoryr   r   r   r   r   r   r   
disconnectr    r   r   )	r"   rM   r/   sCTXcCTXr   clientConnectorr   r   s	          @@r   test_openSSLBufferingz$BufferingTests.test_openSSLBuffering  s    )A)CCd&)@)BBd&'')'5577--//(C'')  FDKH**+!,,,,fd
 	223##//4
 	
r   )r;   r<   r=   r   r   r   r   r   r   r   r  r   r   r   r  r    s1    zgt,4CKKW
r   r  c                   R    e Zd ZdZ ej
                  ed      dZd Zd Z	d Z
d Zy)ConnectionLostTestsz'
    SSL connection closing tests.
    Nr   c                     d} j                  ||dz   fi ||dz   fi        t        j                         }t        j                  |_        t	        j
                  d| j                        x _        }t        j                         }t        |_        t        j                         |_        t	        j                  d|j                         j                  | j                          |j                  j#                   fd      S )Ntwisted.test.test_ssl, client, serverr   r   c                 8    j                   j                         S r   )
serverPortr   )ignoredResultr"   s    r   r   z=ConnectionLostTests.testImmediateDisconnect.<locals>.<lambda>  s    $//"?"?"A r   )r   r   r   Protocolr   r   r   r  r   rd   r   r   ri   r   r   r   r   r   )r"   r   serverProtocolFactoryr  clientProtocolFactorys   `    r   testImmediateDisconnectz+ConnectionLostTests.testImmediateDisconnect  s    %!!#
"#R#sZ/?)@"	
 !) 6 6 8)1):):&'.'8'8$d&;&;(
 	
* !) 6 6 8)I&7<~~7G4 %%!!!		
 %;;GGA
 	
r   c                    t        t        j                         G d dt        j                               }d}| j                  ||dz   fi ||dz   fi         |       t        j                         }fd|_        t        j                  d|| j                        }| j                  |j                          |       t        j                         }fd|_        t        j                  d	|j                         j                  || j                          d
 }t#        j$                  j&                  j)                  |      j&                  j)                  |      g      S )z
        Both sides of SSL connection close connection; the connections should
        close cleanly, and only after the underlying TCP connection has
        disconnected.
        c                   "    e Zd ZdZd Zd Zd Zy)MConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshakeFc                 6    t        j                         | _        y r   )r   r   doner!   s    r   r#   zVConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.__init__  s    !NN,	r   c                 8    | j                   j                          y r   rf   r!   s    r   rg   z`ConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.handshakeCompleted
  s    --/r   c                 >    | j                   j                  |       | ` y r   )r$  errbackr7   s     r   r9   z\ConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.connectionLost  s    		!!&)Ir   N)r;   r<   r=   gotDatar#   rg   r9   r   r   r   CloseAfterHandshaker"    s    G-0r   r)  r  r  r  c                       S r   r   serverProtocols   r   r   zBConnectionLostTests.test_bothSidesLoseConnection.<locals>.<lambda>       r   r   c                       S r   r   clientProtocols   r   r   zBConnectionLostTests.test_bothSidesLoseConnection.<locals>.<lambda>  r-  r   r   c                 .    | j                  t               y r   )trapr   )failures    r   checkResultzEConnectionLostTests.test_bothSidesLoseConnection.<locals>.checkResult&  s    LL(r   )r   r   IHandshakeListenerr   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$  
addErrback)	r"   r)  r   r  r  r  r4  r0  r,  s	          @@r   test_bothSidesLoseConnectionz0ConnectionLostTests.test_bothSidesLoseConnection  sF    
Z22	3	("3"3 	 
4	 &!!#
"#R#sZ/?)@"	
 -. ( 6 6 8)?&&&q*?AVAVW

001,. ( 6 6 8)?& %%!!!		
	) ""##..{;##..{;
 	
r   c                 D  	
 d}| j                  ||dz   fi ||dz   fi        d }| j                  j                         j                  t        j
                  |       t        j                         }t        j                         
|j                  
_        t        j                         }
fd|_        t        j                  d|| j                        x| _        }t        j                         }t        j                         	|j                  	_        t        j"                         }	fd|_        t        j$                  d|j'                         j(                  || j                         t        j*                  ||gd	
      }|j-                  | j.                        S )Nr  r  r  c                       y)NFr   )as    r   verifyz4ConnectionLostTests.testFailedVerify.<locals>.verify6  s    r   c                       S r   r   r+  s   r   r   z6ConnectionLostTests.testFailedVerify.<locals>.<lambda>?  r-  r   r   c                       S r   r   r/  s   r   r   z6ConnectionLostTests.testFailedVerify.<locals>.<lambda>H  r-  r   r   T)consumeErrors)r   r   
getContext
set_verifyr   VERIFY_PEERr   r   r   r  r6   r9   r   r   r   r   r  r   r   r   r   DeferredListr   _cbLostConns)r"   r   r;  serverConnLostr  r  clientConnLostr  dlr0  r,  s            @@r   testFailedVerifyz$ConnectionLostTests.testFailedVerify0  sd   %!!#
"#R#sZ/?)@"	
	 	((*55coovN)!**,(6(?(?% ( 6 6 8)?&'.'8'8$d&;&;(
 	
* )!**,(6(?(?% ( 6 6 8)?& %%!!!		
  @PTU~~d//00r   c                 D   |\  \  }}\  }}| j                  |       | j                  |       t        j                  g}t        j                         rddlm} |j                  |        |j                  |   |j                  |  | j                  j                         S )Nr   )ConnectionLost)assertFalser   r   r   	isWindowstwisted.internet.errorrI  rJ   r2  r  r   )r"   resultssSuccesssResultcSuccesscResultacceptableErrorsrI  s           r   rC  z ConnectionLostTests._cbLostConnsS  s    3:070h""II; =##N3&'&',,..r   )r;   r<   r=   r>   r   r   r   r   r  r7  rG  rC  r   r   r   r  r    s9     zgt,4C
82
h!1F/r   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)FakeContextzK
    L{OpenSSL.SSL.Context} double which can more easily be inspected.
    c                      || _         d| _        y )Nr   )_method_options)r"   methods     r   r#   zFakeContext.__init__s  s    r   c                 .    | xj                   |z  c_         y r   )rW  )r"   r   s     r   set_optionszFakeContext.set_optionsw  s     r   c                      y r   r   r"   fileNames     r   use_certificate_filez FakeContext.use_certificate_filez      r   c                      y r   r   r\  s     r   use_privatekey_filezFakeContext.use_privatekey_file}  r_  r   N)r;   r<   r=   r>   r#   rZ  r^  ra  r   r   r   rT  rT  n  s    !r   rT  c                   R    e Zd ZdZ ej
                  ed      dZd Zd Z	d Z
d Zy)!DefaultOpenSSLContextFactoryTestsz8
    Tests for L{ssl.DefaultOpenSSLContextFactory}.
    Nr   c                     t        j                  t        t        t              | _        | j                  j                         | _        y )N)_contextFactory)r   r   r   rT  r   r?  contextr!   s    r   setUpz'DefaultOpenSSLContextFactoryTests.setUp  s6     ">>h
 **557r   c                 b   | j                  | j                  j                  t        j                         | j                  | j                  j
                  t        j                  z  t        j                         | j                  | j                  j
                  t        j                  z         y)z
        L{ssl.DefaultOpenSSLContextFactory.getContext} returns an SSL context
        which can use SSLv3 or TLSv1 but not SSLv2.
        N)	r   rf  rV  r   
TLS_METHODrW  OP_NO_SSLv2rJ  OP_NO_TLSv1_2r!   s    r   test_methodz-DefaultOpenSSLContextFactoryTests.test_method  sp     	--s~~> 	..@#//R 	..1B1BBCr   c                     | j                  t        j                  t        j                  t
        | j                                y)z
        Instantiating L{ssl.DefaultOpenSSLContextFactory} with a certificate
        filename which does not identify an existing file results in the
        initializer raising L{OpenSSL.SSL.Error}.
        N)assertRaisesr   r   r   r   r   r   r!   s    r   test_missingCertificateFilez=DefaultOpenSSLContextFactoryTests.test_missingCertificateFile  s+     	IIs774;;=	
r   c                     | j                  t        j                  t        j                  | j                         t               y)z
        Instantiating L{ssl.DefaultOpenSSLContextFactory} with a private key
        filename which does not identify an existing file results in the
        initializer raising L{OpenSSL.SSL.Error}.
        N)rn  r   r   r   r   r   r   r!   s    r   test_missingPrivateKeyFilez<DefaultOpenSSLContextFactoryTests.test_missingPrivateKeyFile  s+     	IIs77	
r   )r;   r<   r=   r>   r   r   r   r   rg  rl  ro  rq  r   r   r   rc  rc    s8     zgt,4C8D

r   rc  c                   F    e Zd ZdZ ej
                  ed      dZd Zd Z	y)ClientContextFactoryTestsz0
    Tests for L{ssl.ClientContextFactory}.
    Nr   c                     t        j                         | _        t        | j                  _        | j                  j                         | _        y r   )r   r  r   rT  re  r?  rf  r!   s    r   rg  zClientContextFactoryTests.setUp  s7    !668.9+**557r   c                    | j                  | j                  j                  t        j                         | j                  | j                  j
                  t        j                  z  t        j                         | j                  | j                  j
                  t        j                  z         | j                  | j                  j
                  t        j                  z         y)z
        L{ssl.ClientContextFactory.getContext} returns a context which can use
        TLSv1.2 or 1.3 but nothing earlier.
        N)
r   rf  rV  r   ri  rW  rj  r   OP_NO_SSLv3OP_NO_TLSv1r!   s    r   rl  z%ClientContextFactoryTests.test_method  s    
 	--s~~>..@#//R--?@--?@r   )
r;   r<   r=   r>   r   r   r   r   rg  rl  r   r   r   rs  rs    s.     zgt,4C8
Ar   rs  )6r>   r   r   twisted.internetr   r   r   r   rL  r   twisted.internet.testingr   twisted.protocolsr	   twisted.python.filepathr
   twisted.python.runtimer   twisted.test.test_tcpr   twisted.trial.unittestr   OpenSSLr   r   r   twisted.test.ssl_helpersr   r   ImportErrorr   zope.interfacer   LineReceiverr   r@   r  rX   r^   r5  rd   r   r   r   r   rL   r   r   r  r  r  rT  rc  rs  r   r   r   <module>r     st   
  A A 1 = # , + 9 +#$C '%E.. %D+%E&& +%\,x00 ,%h// %  Z**+
;x'8'8 
; ,
;8G &
 &
R ?
I3;; 
I4
,h 4
ng$x g$TX &
X &
RS/($: S/l &0
 0
fA Au   Hs   E% %E87E8