U
    
W[&]                     @   s  d Z ddlmZmZ ddlmZ ddlm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ZddlZz0ddlmamZ ddlma ddlm Z m!Z! W n" e"k
r   dd Z#e#  Y nX zddlm$Z% W n e"k
r   dZ%Y nX ddl&m'Z' G dd dej(Z)G dd dej(Z*G dd de	j+Z,G dd de	j+Z-e'ej.G dd de	j+Z/dd Z0d d! Z1G d"d# d#Z2tdk	rG d$d% d%tj3Z4G d&d' d'eej5Z6G d(d) d)ej5Z7G d*d+ d+e7Z8G d,d- d-ej5Z9G d.d/ d/ej5e2Z:G d0d1 d1Z;G d2d3 d3ej5Z<G d4d5 d5ej5Z=e>e
ddkre6e7e8e9e:e<e=fD ]Z?d6e?_@qxdS )7z 
Tests for twisted SSL support.
    )divisionabsolute_import)FilePath)unittest)protocolreactor
interfacesdefer)ConnectionDone)basic)requireModule)platform)ProperlyCloseFilesMixin)waitUntilAllDisconnectedN)SSLcrypto)ssl)ClientTLSContextcertPathc                   C   s   d  a ad S N)r   r    r   r   7/usr/lib/python3/dist-packages/twisted/test/test_ssl.py_noSSL   s    r   )tls)implementerc                   @   sB   e Zd ZdZdddgZddgZdd Zd	d
 Zdd Zdd Z	dS )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                 C   s   t  | _d S r   r	   Deferreddeferredselfr   r   r   __init__=   s    zUnintelligentProtocol.__init__c                 C   s   | j D ]}| | qd S r   )pretextsendLine)r!   lr   r   r   connectionMadeA   s    
z$UnintelligentProtocol.connectionMadec                 C   s@   |dkr<| j t | jj | jD ]}| | q"| j   d S )N   READY)	transportstartTLSr   factoryclientposttextr$   loseConnection)r!   liner%   r   r   r   lineReceivedF   s
    
z"UnintelligentProtocol.lineReceivedc                 C   s   | j d  d S r   r   callbackr!   reasonr   r   r   connectionLostN   s    z$UnintelligentProtocol.connectionLostN)
__name__
__module____qualname____doc__r#   r,   r"   r&   r/   r4   r   r   r   r   r   )   s   r   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )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}
    Fc                 C   s   || _ || _t | _d S r   )doTLS
fillBufferr	   r   r   )r!   r:   r;   r   r   r   r"   `   s    zLineCollector.__init__c                 C   s   d| j _g | j _d S )N    )r*   rawdatalinesr    r   r   r   r&   f   s    zLineCollector.connectionMadec                 C   sp   | j j| |dkrl| jr4tdD ]}| d q$| d | jrdtttd}| j	
|| j j n|   d S )Nr   i  s  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr'   )ZprivateKeyFileNameZcertificateFileName)r*   r>   appendr;   ranger$   r:   ServerTLSContextr   r(   r)   serverZ
setRawMode)r!   r.   xZctxr   r   r   r/   k   s    
zLineCollector.lineReceivedc                 C   s   | j  j|7  _| j  d S r   )r*   r=   r(   r-   r!   datar   r   r   rawDataReceived|   s    zLineCollector.rawDataReceivedc                 C   s   | j d  d S r   r0   r2   r   r   r   r4      s    zLineCollector.connectionLostN)F)	r5   r6   r7   r8   r"   r&   r/   rF   r4   r   r   r   r   r9   S   s   
r9   c                   @   s   e Zd ZdZdd ZdS )SingleLineServerProtocolzK
    A protocol that sends a single line of data at C{connectionMade}.
    c                 C   s   | j d | j   d S )N   +OK <some crap>
)r(   writegetPeerCertificater    r   r   r   r&      s    z'SingleLineServerProtocol.connectionMadeN)r5   r6   r7   r8   r&   r   r   r   r   rG      s   rG   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	RecordingClientProtocolzv
    @ivar deferred: a deferred that will fire with first received content.
    @type deferred: L{defer.Deferred}
    c                 C   s   t  | _d S r   r   r    r   r   r   r"      s    z RecordingClientProtocol.__init__c                 C   s   | j   d S r   )r(   rJ   r    r   r   r   r&      s    z&RecordingClientProtocol.connectionMadec                 C   s   | j | d S r   r0   rD   r   r   r   dataReceived   s    z$RecordingClientProtocol.dataReceivedN)r5   r6   r7   r8   r"   r&   rL   r   r   r   r   rK      s   rK   c                   @   s    e Zd ZdZdd Zdd ZdS ) ImmediatelyDisconnectingProtocolz
    A protocol that disconnect immediately on connection. It fires the
    C{connectionDisconnected} deferred of its factory on connetion lost.
    c                 C   s   | j   d S r   r(   r-   r    r   r   r   handshakeCompleted   s    z3ImmediatelyDisconnectingProtocol.handshakeCompletedc                 C   s   | j jd  d S r   )r*   connectionDisconnectedr1   r2   r   r   r   r4      s    z/ImmediatelyDisconnectingProtocol.connectionLostN)r5   r6   r7   r8   rO   r4   r   r   r   r   rM      s   rM   c                 C   s   t  }|t jd t  }| }| |_||_|| |	|d t 
 }|d |d |d ||  ||  ||  |	|d |||fS )z
    Create a certificate for given C{organization} and C{organizationalUnit}.

    @return: a tuple of (key, request, certificate) objects.
    i   Zmd5   r   <   )r   ZPKeyZgenerate_keyZTYPE_RSAZX509ReqZget_subjectOZOUZ
set_pubkeyZsignZX509Zset_serial_numberZgmtime_adj_notBeforeZgmtime_adj_notAfterZ
set_issuerZset_subjectZ
get_pubkey)organizationorganizationalUnitpkeyreqZsubjectcertr   r   r   generateCertificateObjects   s"    



rY   c           
      C   sn   t ||\}}}d|tjfd|tjfd|tjffD ]6\}}}tj| |fd}	t	|	
|tj| q2dS )z
    Create certificate files key, req and cert prefixed by C{basename} for
    given C{organization} and C{organizationalUnit}.
    keyrW   rX   zutf-8N)rY   r   Zdump_privatekeyZdump_certificate_requestZdump_certificateosextsepjoinencoder   Z
setContentZFILETYPE_PEM)
basenamerT   rU   rV   rW   rX   ZextobjZdumpFuncZfNamer   r   r   generateCertificateFiles   s    


ra   c                   @   s    e Zd ZdZdd Zdd ZdS )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                 O   sH   |   }t||| tjtj|dftj|dff||}||fS )NrZ   rX   )mktempra   r   DefaultOpenSSLContextFactoryr[   r\   r]   )r!   orgZorgUnitargsZkwArgsbaseserverCtxFactoryr   r   r   makeContextFactory   s    z)ContextGeneratingMixin.makeContextFactoryc                 C   s,   | j ||\| _| _| j ||\| _| _d S r   )ri   Z
clientBaseclientCtxFactoryZ
serverBaserh   )r!   Z
clientArgsZclientKwArgsZ
serverArgsZserverKwArgsr   r   r   setupServerAndClient   s      z+ContextGeneratingMixin.setupServerAndClientN)r5   r6   r7   r8   ri   rk   r   r   r   r   rb      s   rb   c                   @   s   e Zd ZdZdZdd ZdS )rA   ze
        A context factory with a default method set to
        L{OpenSSL.SSL.TLSv1_METHOD}.
        Fc                 O   s"   t j|d< tjj| f|| d S )NZ	sslmethod)r   ZTLSv1_METHODr   rd   r"   )r!   rf   kwr   r   r   r"     s    
zServerTLSContext.__init__N)r5   r6   r7   r8   ZisClientr"   r   r   r   r   rA   
  s   rA   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )StolenTCPTestszc
    For SSL transports, test many of the same things which are tested for
    TCP transports.
    c                 C   s.   t jtt }| }tj||||dS )zY
        Create an SSL server with a certificate using L{IReactorSSL.listenSSL}.
        Z	interface)	r   ZPrivateCertificateZloadPEMr   r   Z
getContentoptionsr   	listenSSL)r!   address
portNumberr*   rX   contextFactoryr   r   r   createServer  s       zStolenTCPTests.createServerc                 C   s   t  }||||S )zG
        Create an SSL client using L{IReactorSSL.connectSSL}.
        )r   ZCertificateOptions
connectSSL)r!   rq   rr   ZclientCreatorrs   r   r   r   connectClient'  s    zStolenTCPTests.connectClientc                 C   s   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    r   r   r   getHandleExceptionType/  s    z%StolenTCPTests.getHandleExceptionTypec                 C   s$   t ddkrt dkrtjS dgS )a  
        Return 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twisted.protocols.tlsNZwin32)zSSL routinesZ	SSL_writezprotocol is shutdown)r   r   ZgetTypeerrnoZWSAENOTSOCKr    r   r   r   getHandleErrorCode8  s    z!StolenTCPTests.getHandleErrorCodeN)r5   r6   r7   r8   rt   rv   rx   rz   r   r   r   r   rm     s
   
	rm   c                   @   sF   e Zd ZdZdZdZdZdd ZdddZdd	 Z	d
d Z
dd ZdS )TLSTestsz
    Tests for startTLS support.

    @ivar fillBuffer: forwarded to L{LineCollector.fillBuffer}
    @type fillBuffer: C{bool}
    FNc                 C   s4   | j jd k	r| j j  | jjd k	r0| jj  d S r   )clientProtor(   r-   serverProtor    r   r   r   tearDownc  s    zTLSTests.tearDownc                    s    | _ t  }| _ fdd|_|r.d|_nd|_| _t  }| _fdd|_|rbd|_nd|_t	j
d|dd}| |j t	d| j| t 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    S r   r   r   r|   r   r   <lambda>z  r<   z#TLSTests._runTest.<locals>.<lambda>FTc                      s    S r   r   r   r}   r   r   r     r<   r   	127.0.0.1rn   )r|   r   ClientFactoryclientFactoryrB   r+   r}   ServerFactoryserverFactoryr   Z	listenTCP
addCleanupstopListeningZ
connectTCPgetHostportr	   gatherResultsr   )r!   r|   r}   ZclientIsServerZcfZsfr   r   r|   r}   r   _runTestj  s     zTLSTests._runTestc                    s,    fdd}  t td j}||S )z~
        Test for server and client startTLS: client should received data both
        before and after the startTLS.
        c                    s      jjtjtj  d S r   )assertEqualr   r>   r   r#   r,   )ignorer    r   r   check  s    
z TLSTests.test_TLS.<locals>.checkTr   r   r9   r;   addCallbackr!   r   dr   r    r   test_TLS  s
    
zTLSTests.test_TLSc                    s,    fdd}  t td 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                    s&      jjtj   jjd d S )NzNo encrypted bytes received)r   r   r>   r   r#   Z
assertTruer=   Zignoredr    r   r   r     s    
z"TLSTests.test_unTLS.<locals>.checkFr   r   r   r    r   
test_unTLS  s
    
zTLSTests.test_unTLSc                    s.    fdd}  td jt d}||S )z:
        Test startTLS first initiated by client.
        c                    s      jjtjtj  d S r   )r   r   r>   r   r#   r,   r   r    r   r   r     s    
z)TLSTests.test_backwardsTLS.<locals>.checkT)r   r9   r;   r   r   r   r   r    r   test_backwardsTLS  s     zTLSTests.test_backwardsTLS)F)r5   r6   r7   r8   r;   r|   r}   r~   r   r   r   r   r   r   r   r   r{   V  s   
&r{   c                   @   s   e Zd ZdZdZdS )SpammyTLSTestszA
    Test TLS features with bytes sitting in the out buffer.
    TN)r5   r6   r7   r8   r;   r   r   r   r   r     s   r   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )BufferingTestsNc                 C   sB   | j jd k	r| j j  | jjd k	r0| jj  tt| j | jgS r   )r}   r(   r-   r|   r   r   r    r   r   r   r~     s     
zBufferingTests.tearDownc                    s   t   | _t   | _t }t  }| _fdd|_ fdd|_t	t
t
}t }tjd||dd}| |j td| j||}| |j  j| jdS )Nc                      s    S r   r   r   r   r   r   r     r<   z6BufferingTests.test_openSSLBuffering.<locals>.<lambda>c                      s    S r   r   r   r   r   r   r     r<   r   r   rn   rH   )rG   r}   rK   r|   r   r   r   r+   r   rd   r   ClientContextFactoryr   rp   r   r   ru   r   r   Z
disconnectr   r   r   )r!   rB   r+   ZsCTXZcCTXr   ZclientConnectorr   r   r   test_openSSLBuffering  s&      z$BufferingTests.test_openSSLBuffering)r5   r6   r7   r}   r|   r~   r   r   r   r   r   r     s   
r   c                   @   s>   e Zd ZdZdd Zdd Zedkr*de_dd	 Zd
d Z	dS )ConnectionLostTestsz'
    SSL connection closing tests.
    c                    s   d}  ||d fi ||d fi  t }tj|_td| j  _}t }t	|_t
 |_td| j| j |j fddS )Ntwisted.test.test_ssl, client, serverr   r   c                    s
    j  S r   )
serverPortr   )ZignoredResultr    r   r   r     r<   z=ConnectionLostTests.testImmediateDisconnect.<locals>.<lambda>)rk   r   r   Protocolr   rp   rh   r   r   rM   r	   r   rP   ru   r   r   rj   r   )r!   re   serverProtocolFactoryr   clientProtocolFactoryr   r    r   testImmediateDisconnect  s0    
 
  

  
z+ConnectionLostTests.testImmediateDisconnectc                    s   t tjG dd dtj}d}| ||d fi ||d fi  | t }fdd|_td|| j	}| 
|j |  t } fd	d|_td
| j|| j dd }t 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                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	zMConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshakeFc                 S   s   t  | _d S r   )r	   r   doner    r   r   r   r"     s    zVConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.__init__c                 S   s   | j   d S r   rN   r    r   r   r   rO     s    z`ConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.handshakeCompletedc                 S   s   | j | | ` d S r   )r   Zerrbackr2   r   r   r   r4     s    z\ConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.connectionLostN)r5   r6   r7   ZgotDatar"   rO   r4   r   r   r   r   CloseAfterHandshake  s   r   r   r   r   c                      s    S r   r   r   serverProtocolr   r   r   &  r<   zBConnectionLostTests.test_bothSidesLoseConnection.<locals>.<lambda>r   c                      s    S r   r   r   clientProtocolr   r   r   -  r<   r   c                 S   s   |  t d S r   )trapr
   )Zfailurer   r   r   checkResult1  s    zEConnectionLostTests.test_bothSidesLoseConnection.<locals>.checkResult)r   r   IHandshakeListenerr   r   rk   r   r   rp   rh   r   r   r   ru   r   r   rj   r	   r   r   Z
addErrback)r!   r   re   r   r   r   r   r   r   r   r   test_bothSidesLoseConnection  s>    
 
    

z0ConnectionLostTests.test_bothSidesLoseConnectionNz*Old SSL code doesn't always close cleanly.c           	         s   d}|  ||d fi ||d fi  dd }| j tj| t }t	 |j
_t }fdd|_td|| j | _}t }t	  |j
 _t } fd	d|_td
| j|| j tj||gdd}|| jS )Nr   r   r   c                  W   s   dS )NFr   )ar   r   r   verifyA  s    z4ConnectionLostTests.testFailedVerify.<locals>.verifyc                      s    S r   r   r   r   r   r   r   I  r<   z6ConnectionLostTests.testFailedVerify.<locals>.<lambda>r   c                      s    S r   r   r   r   r   r   r   Q  r<   r   T)ZconsumeErrors)rk   rj   
getContextZ
set_verifyr   ZVERIFY_PEERr	   r   r   r   r1   r4   r   r   rp   rh   r   r   ru   r   r   ZDeferredListr   _cbLostConns)	r!   re   r   ZserverConnLostr   r   ZclientConnLostr   Zdlr   r   r   testFailedVerify;  s<    
 
  
  z$ConnectionLostTests.testFailedVerifyc                 C   sh   |\\}}\}}|  | |  | tjg}t rJddlm} || |j|  |j|  | j	
 S )Nr   )ConnectionLost)assertFalser   rw   r   Z	isWindowstwisted.internet.errorr   r?   r   r   r   )r!   ZresultsZsSuccessZsResultZcSuccessZcResultZacceptableErrorsr   r   r   r   r   Y  s    





z ConnectionLostTests._cbLostConns)
r5   r6   r7   r8   r   r   newTLSskipr   r   r   r   r   r   r     s   ,r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )FakeContextzK
    L{OpenSSL.SSL.Context} double which can more easily be inspected.
    c                 C   s   || _ d| _d S )Nr   )_method_options)r!   methodr   r   r   r"   x  s    zFakeContext.__init__c                 C   s   |  j |O  _ d S r   )r   )r!   ro   r   r   r   set_options}  s    zFakeContext.set_optionsc                 C   s   d S r   r   r!   ZfileNamer   r   r   use_certificate_file  s    z FakeContext.use_certificate_filec                 C   s   d S r   r   r   r   r   r   use_privatekey_file  s    zFakeContext.use_privatekey_fileN)r5   r6   r7   r8   r"   r   r   r   r   r   r   r   r   t  s
   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )!DefaultOpenSSLContextFactoryTestsz8
    Tests for L{ssl.DefaultOpenSSLContextFactory}.
    c                 C   s"   t jtttd| _| j | _d S )N)_contextFactory)r   rd   r   r   rs   r   contextr    r   r   r   setUp  s      z'DefaultOpenSSLContextFactoryTests.setUpc                 C   sV   |  | jjtj |  | jjtj@ tj | | jjtj@  | | jjtj	@  dS )z
        L{ssl.DefaultOpenSSLContextFactory.getContext} returns an SSL context
        which can use SSLv3 or TLSv1 but not SSLv2.
        N
r   r   r   r   ZSSLv23_METHODr   ZOP_NO_SSLv2r   ZOP_NO_SSLv3ZOP_NO_TLSv1r    r   r   r   test_method  s    z-DefaultOpenSSLContextFactoryTests.test_methodc                 C   s   |  tjtjt|   dS )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   rw   r   rd   r   rc   r    r   r   r   test_missingCertificateFile  s      z=DefaultOpenSSLContextFactoryTests.test_missingCertificateFilec                 C   s   |  tjtj|  t dS )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)r   r   rw   r   rd   rc   r   r    r   r   r   test_missingPrivateKeyFile  s      z<DefaultOpenSSLContextFactoryTests.test_missingPrivateKeyFileN)r5   r6   r7   r8   r   r   r   r   r   r   r   r   r     s
   r   c                   @   s    e Zd ZdZdd Zdd ZdS )ClientContextFactoryTestsz0
    Tests for L{ssl.ClientContextFactory}.
    c                 C   s"   t  | _t| j_| j | _d S r   )r   r   rs   r   r   r   r   r    r   r   r   r     s    
zClientContextFactoryTests.setUpc                 C   sV   |  | jjtj |  | jjtj@ tj | | jjtj@  | | jjtj	@  dS )z~
        L{ssl.ClientContextFactory.getContext} returns a context which can use
        SSLv3 or TLSv1 but not SSLv2.
        Nr   r    r   r   r   r     s    z%ClientContextFactoryTests.test_methodN)r5   r6   r7   r8   r   r   r   r   r   r   r     s   r   z2Reactor does not support SSL, cannot run SSL tests)Ar8   Z
__future__r   r   Ztwisted.python.filepathr   Ztwisted.trialr   Ztwisted.internetr   r   r   r	   r   r
   Ztwisted.protocolsr   Ztwisted.python.reflectr   Ztwisted.python.runtimer   Ztwisted.test.test_tcpr   Ztwisted.test.proto_helpersr   r[   ry   ZOpenSSLr   r   r   Ztwisted.test.ssl_helpersr   r   ImportErrorr   r   r   Zzope.interfacer   ZLineReceiverr   r9   r   rG   rK   r   rM   rY   ra   rb   rd   rA   ZTestCaserm   r{   r   r   r   r   r   r   ZIReactorSSLZtCaser   r   r   r   r   <module>   sf   
*3(
?i( 4 