
[XMc           @   s  d  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 m Z d d l m Z d d l m Z m Z d d	 l Z d d	 l Z y: d d
 l m a m Z d d l m a d d l m Z Wn! e k
 r	d   Z e   n Xe j e d  Z  d e	 j! f d     YZ" d e	 j! f d     YZ# d e j$ f d     YZ% d e j$ f d     YZ& d e j$ f d     YZ' d   Z( d   Z) d d0 d     YZ* t d	 k	 rd t j, f d     YZ- n  d e e j. f d      YZ/ d! e j. f d"     YZ0 d# e0 f d$     YZ1 d% e j. f d&     YZ2 d' e j. e* f d(     YZ3 d) d1 d*     YZ4 d+ e j. f d,     YZ5 d- e j. f d.     YZ6 e j7 e d	  d	 k rx/ e/ e0 e1 e2 e3 e5 e6 g D] Z8 d/ e8 _9 qWn  [ d	 S(2   s    
Tests for twisted SSL support.
i(   t   unittest(   t   protocolt   reactort
   interfacest   defer(   t   basic(   t   util(   t   getClasst   fullyQualifiedName(   t   platform(   t   WriteDataTestCaset   ProperlyCloseFilesMixinN(   t   SSLt   crypto(   t   ssl(   t   ClientTLSContextc           C   s   d  a a d  S(   N(   t   NoneR   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   _noSSL   s    s
   server.pemt   UnintelligentProtocolc           B   sM   e  Z d  Z d d d g Z d d g Z d   Z d   Z d   Z d	   Z RS(
   s
  
    @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{str}

    @cvar posttext: text sent after TLS is set up.
    @type posttext: C{str}
    s
   first lines   last thing before tls startst   STARTTLSs   first thing after tls starteds   last thing everc         C   s   t  j   |  _ d  S(   N(   R   t   Deferredt   deferred(   t   self(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   __init__6   s    c         C   s%   x |  j  D] } |  j |  q
 Wd  S(   N(   t   pretextt   sendLine(   R   t   l(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   connectionMade:   s    c         C   s]   | d k rY |  j  j t   |  j j  x |  j D] } |  j |  q2 W|  j  j   n  d  S(   Nt   READY(   t	   transportt   startTLSR   t   factoryt   clientt   posttextR   t   loseConnection(   R   t   lineR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   lineReceived?   s
    c         C   s   |  j  j d   d  S(   N(   R   t   callbackR   (   R   t   reason(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   connectionLostG   s    (	   t   __name__t
   __module__t   __doc__R   R!   R   R   R$   R'   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   "   s   
					t   LineCollectorc           B   s>   e  Z d  Z e d  Z d   Z d   Z d   Z d   Z RS(   sJ  
    @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         C   s%   | |  _  | |  _ t j   |  _ d  S(   N(   t   doTLSt
   fillBufferR   R   R   (   R   R,   R-   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   Y   s    		c         C   s   d |  j  _ g  |  j  _ d  S(   Nt    (   R   t   rawdatat   lines(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   _   s    c         C   s   |  j  j j |  | d k r |  j rS x( t d  D] } |  j d d  q5 Wn  |  j d  |  j r t d t d t  } |  j	 j
 | |  j  j  q |  j   n  d  S(   NR   i  t   Xi  R   t   privateKeyFileNamet   certificateFileName(   R   R0   t   appendR-   t   rangeR   R,   t   ServerTLSContextt   certPathR   R   t   servert
   setRawMode(   R   R#   t   xt   ctx(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR$   d   s    			c         C   s#   |  j  j | 7_ |  j j   d  S(   N(   R   R/   R   R"   (   R   t   data(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   rawDataReceivedu   s    c         C   s   |  j  j d   d  S(   N(   R   R%   R   (   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR'   z   s    (	   R(   R)   R*   t   FalseR   R   R$   R=   R'   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR+   L   s   			t   SingleLineServerProtocolc           B   s   e  Z d  Z d   Z RS(   sK   
    A protocol that sends a single line of data at C{connectionMade}.
    c         C   s!   |  j  j d  |  j  j   d  S(   Ns   +OK <some crap>
(   R   t   writet   getPeerCertificate(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR      s    (   R(   R)   R*   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR?      s   t   RecordingClientProtocolc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sv   
    @ivar deferred: a deferred that will fire with first received content.
    @type deferred: L{defer.Deferred}
    c         C   s   t  j   |  _ d  S(   N(   R   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR      s    c         C   s   |  j  j   d  S(   N(   R   RA   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR      s    c         C   s   |  j  j |  d  S(   N(   R   R%   (   R   R<   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   dataReceived   s    (   R(   R)   R*   R   R   RC   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyRB      s   		t    ImmediatelyDisconnectingProtocolc           B   s    e  Z d  Z d   Z d   Z RS(   s   
    A protocol that disconnect immediately on connection. It fires the
    C{connectionDisconnected} deferred of its factory on connetion lost.
    c         C   s   |  j  j   d  S(   N(   R   R"   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR      s    c         C   s   |  j  j j d   d  S(   N(   R   t   connectionDisconnectedR%   R   (   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR'      s    (   R(   R)   R*   R   R'   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyRD      s   	c         C   s   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(   s   
    Create a certificate for given C{organization} and C{organizationalUnit}.

    @return: a tuple of (key, request, certificate) objects.
    i   t   md5i   i    i<   (   R   t   PKeyt   generate_keyt   TYPE_RSAt   X509Reqt   get_subjectt   Ot   OUt
   set_pubkeyt   signt   X509t   set_serial_numbert   gmtime_adj_notBeforet   gmtime_adj_notAftert
   set_issuert   set_subjectt
   get_pubkey(   t   organizationt   organizationalUnitt   pkeyt   reqt   subjectt   cert(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   generateCertificateObjects   s"    		c         C   s   t  | |  \ } } } x d | t j f d | t j f d | t j f g D]Y \ } } } t j j |  | f  }	 t |	 d  }
 |
 j	 | t j
 |   |
 j   qL Wd S(   s   
    Create certificate files key, req and cert prefixed by C{basename} for
    given C{organization} and C{organizationalUnit}.
    t   keyRZ   R\   t   wN(   R]   R   t   dump_privatekeyt   dump_certificate_requestt   dump_certificatet   ost   extsept   joint   fileR@   t   FILETYPE_PEMt   close(   t   basenameRW   RX   RY   RZ   R\   t   extt   objt   dumpFunct   fNamet   fObj(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   generateCertificateFiles   s    "t   ContextGeneratingMixinc           B   s    e  Z d  Z d   Z d   Z RS(   s`  
    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
        C{reactor.connectSSL}.
    @type clientCtxFactory: L{ssl.DefaultOpenSSLContextFactory}

    @ivar serverCtxFactory: a generated context factory to be used in
        C{reactor.listenSSL}.
    @type serverCtxFactory: L{ssl.DefaultOpenSSLContextFactory}
    c         O   sb   |  j    } t | | |  t j t j j | d f  t j j | d f  | |  } | | f S(   NR^   R\   (   t   mktempRo   R   t   DefaultOpenSSLContextFactoryRc   Rd   Re   (   R   t   orgt   orgUnitt   argst   kwArgst   baset   serverCtxFactory(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   makeContextFactory   s    c         C   s@   |  j  | |   \ |  _ |  _ |  j  | |   \ |  _ |  _ d  S(   N(   Ry   t
   clientBaset   clientCtxFactoryt
   serverBaseRx   (   R   t
   clientArgst   clientKwArgst
   serverArgst   serverKwArgs(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   setupServerAndClient   s    (   R(   R)   R*   Ry   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyRp      s   	R6   c           B   s   e  Z d  Z e Z d   Z RS(   sU   
        A context factory with a default method set to L{SSL.TLSv1_METHOD}.
        c         O   s'   t  j | d <t j j |  | |  d  S(   Nt	   sslmethod(   R   t   TLSv1_METHODR   Rr   R   (   R   Ru   t   kw(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   
  s    (   R(   R)   R*   R>   t   isClientR   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR6     s   t   StolenTCPTestCasec           B   s8   e  Z d  Z d   Z d   Z d   Z d Z d   Z RS(   sc   
    For SSL transports, test many of the same things which are tested for
    TCP transports.
    c         C   sC   t  j j t t  j    } | j   } t j | | | d | S(   sY   
        Create an SSL server with a certificate using L{IReactorSSL.listenSSL}.
        t	   interface(	   R   t   PrivateCertificatet   loadPEMRf   R7   t   readt   optionsR   t	   listenSSL(   R   t   addresst
   portNumberR   R\   t   contextFactory(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   createServer  s    c         C   s   t  j   } | j | | |  S(   sG   
        Create an SSL client using L{IReactorSSL.connectSSL}.
        (   R   t   CertificateOptionst
   connectSSL(   R   R   R   t   clientCreatorR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   connectClient   s    c         C   s   t  j S(   s   
        Return L{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   t   Error(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   getHandleExceptionType(  s    s0   twisted.internet.iocpreactor.reactor.IOCPReactorc         C   sA   t  t t   } t j   d k r: | |  j k r: t j Sd g S(   s   
        Return the argument L{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.
        t   win32s   SSL routinest	   SSL_writes   protocol is shutdown(   s   SSL routinesR   s   protocol is shutdown(   R   R   R   R	   t   getTypet   _iocpt   errnot   WSAENOTSOCK(   R   t   name(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   getHandleErrorCode3  s    !(   R(   R)   R*   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s   	
			t   TLSTestCasec           B   sP   e  Z d  Z e Z d Z d Z d   Z e d  Z	 d   Z
 d   Z d   Z RS(   s   
    Tests for startTLS support.

    @ivar fillBuffer: forwarded to L{LineCollector.fillBuffer}
    @type fillBuffer: C{bool}
    c         C   sN   |  j  j d  k	 r% |  j  j j   n  |  j j d  k	 rJ |  j j j   n  d  S(   N(   t   clientProtoR   R   R"   t   serverProto(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   tearDownX  s    c            s     |  _  t j   } |  _   f d   | _ | r@ t | _ n	 t | _  |  _ t j	   } |  _
  f d   | _ | r t | _ n	 t | _ t j d | d d } |  j | j  t j d | j   j |  t j   j  j g  S(   s  
        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(   N(    (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   <lambda>o  s    c              s     S(   N(    (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   w  s    i    R   s	   127.0.0.1(   R   R   t   ClientFactoryt   clientFactoryR>   R8   t   TrueR    R   t   ServerFactoryt   serverFactoryR   t	   listenTCPt
   addCleanupt   stopListeningt
   connectTCPt   getHostt   portR   t   gatherResultsR   (   R   R   R   t   clientIsServert   cft   sfR   (    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   _runTest_  s     				c            s=     f d   }   j  t   t t   j   } | j |  S(   s~   
        Test for server and client startTLS: client should received data both
        before and after the startTLS.
        c            s$     j    j j t j t j  d  S(   N(   t   assertEqualsR   R0   R   R   R!   (   t   ignore(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   check  s    	(   R   R   R+   R   R-   t   addCallback(   R   R   t   d(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_TLS  s    c            s=     f d   }   j  t   t t   j   } | j |  S(   s   
        Test for server startTLS not followed by a startTLS in client: the data
        received after server startTLS should be received as raw.
        c            s3     j    j j t j    j   j j d  d  S(   Ns   No encrypted bytes received(   R   R   R0   R   R   t
   failUnlessR/   (   t   ignored(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s
    	
(   R   R   R+   R>   R-   R   (   R   R   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt
   test_unTLS  s    c            s@     f d   }   j  t t   j  t   t  } | j |  S(   s:   
        Test startTLS first initiated by client.
        c            s$     j    j j t j t j  d  S(   N(   R   R   R0   R   R   R!   (   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    	(   R   R+   R   R-   R   R   (   R   R   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_backwardsTLS  s    N(   R(   R)   R*   R>   R-   R   R   R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   K  s   	&		t   SpammyTLSTestCasec           B   s   e  Z d  Z e Z RS(   sA   
    Test TLS features with bytes sitting in the out buffer.
    (   R(   R)   R*   R   R-   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s   t   BufferingTestCasec           B   s&   e  Z d Z d Z d    Z d   Z RS(   c         C   sN   |  j  j d  k	 r% |  j  j j   n  |  j j d  k	 rJ |  j j j   n  d  S(   N(   R   R   R   R"   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    c            s   t     |  _ t     |  _ t j   } t j   } |  _  f d   | _   f d   | _ t j	 t
 t
  } t j   } t j d | | d d } |  j | j  t j d | j   j | |    j j |  j d  S(   Nc              s     S(   N(    (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    c              s     S(   N(    (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    i    R   s	   127.0.0.1s   +OK <some crap>
(   R?   R   RB   R   R   R   R   R    R   Rr   R7   t   ClientContextFactoryR   R   R   R   R   R   R   R   R   R   (   R   R8   R    t   sCTXt   cCTXR   (    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_openSSLBuffering  s    	N(   R(   R)   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s   	t   ConnectionLostTestCasec           B   s#   e  Z d    Z d   Z d   Z RS(   c            s   d }   j  | | d f i  | | d f i   t j   } t j | _ t j d |   j    _ } t j   } t	 | _ t
 j   | _ t j d | j   j |   j  } | j j   f d    S(   Ns   twisted.test.test_ssls   , clients   , serveri    s	   127.0.0.1c            s     j  j   S(   N(   t
   serverPortR   (   t   ignoredResult(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    (   R   R   R   t   ProtocolR   R   Rx   R   R   RD   R   R   RE   R   R   R   R{   R   (   R   Rs   t   serverProtocolFactoryR   t   clientProtocolFactoryt   clientConnector(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   testImmediateDisconnect  s    				c   
         sG  d } |  j  | | d f i  | | d f i   d   } |  j j   j t j |  t j   } t j	     | j
   _ t j   }   f d   | _ t j d | |  j  |  _ } t j   } t j	    | j
  _ t j   }  f d   | _ t j d | j   j | |  j  } t j | | g d	 t }	 |	 j |  j  S(
   Ns   twisted.test.test_ssls   , clients   , serverc          W   s   t  S(   N(   R>   (   t   a(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   verify  s    c              s     S(   N(    (    (   t   serverProtocol(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    i    c              s     S(   N(    (    (   t   clientProtocol(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    s	   127.0.0.1t   consumeErrors(   R   R{   t
   getContextt
   set_verifyR   t   VERIFY_PEERR   R   R   R   R%   R'   R   R   R   Rx   R   R   R   R   R   t   DeferredListR   R   t   _cbLostConns(
   R   Rs   R   t   serverConnLostR   R   t   clientConnLostR   R   t   dl(    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   testFailedVerify  s,    			c         C   s   | \ \ } } \ } } |  j  |  |  j  |  t j g } t j   rj d d l m } | j |  n  | j |   | j |   |  j	 j
   S(   Ni(   t   ConnectionLost(   t   failIfR   R   R	   t	   isWindowst   twisted.internet.errorR   R4   t   trapR   R   (   R   t   resultst   sSuccesst   sResultt   cSuccesst   cResultt   acceptableErrorsR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    
(   R(   R)   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s   		t   FakeContextc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sK   
    L{OpenSSL.SSL.Context} double which can more easily be inspected.
    c         C   s   | |  _  d |  _ d  S(   Ni    (   t   _methodt   _options(   R   t   method(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   5  s    	c         C   s   |  j  | O_  d  S(   N(   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   set_options:  s    c         C   s   d  S(   N(    (   R   t   fileName(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   use_certificate_file>  s    c         C   s   d  S(   N(    (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   use_privatekey_fileB  s    (   R(   R)   R*   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   1  s
   			t!   DefaultOpenSSLContextFactoryTestsc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s8   
    Tests for L{ssl.DefaultOpenSSLContextFactory}.
    c         C   s1   t  j t t d t |  _ |  j j   |  _ d  S(   Nt   _contextFactory(   R   Rr   R7   R   R   R   t   context(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   setUpK  s    c         C   sk   |  j  |  j j t j  |  j |  j j t j @ |  j |  j j t j	 @ |  j |  j j t j
 @ d S(   s   
        L{ssl.DefaultOpenSSLContextFactory.getContext} returns an SSL context
        which can use SSLv3 or TLSv1 but not SSLv2.
        N(   t   assertEqualR   R   R   t   SSLv23_METHODt
   assertTrueR   t   OP_NO_SSLv2t   assertFalset   OP_NO_SSLv3t   OP_NO_TLSv1(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_methodS  s    c         C   s&   |  j  t j t j t |  j    d S(   s   
        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(   t   assertRaisesR   R   R   Rr   R7   Rq   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_missingCertificateFilec  s    c         C   s&   |  j  t j t j |  j   t  d S(   s   
        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   R   R   Rr   Rq   R7   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_missingPrivateKeyFilen  s    (   R(   R)   R*   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   G  s
   			t   ClientContextFactoryTestsc           B   s    e  Z d  Z d   Z d   Z RS(   s0   
    Tests for L{ssl.ClientContextFactory}.
    c         C   s1   t  j   |  _ t |  j _ |  j j   |  _ d  S(   N(   R   R   R   R   R   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   ~  s    c         C   sk   |  j  |  j j t j  |  j |  j j t j @ |  j |  j j t j	 @ |  j |  j j t j
 @ d S(   s~   
        L{ssl.ClientContextFactory.getContext} returns a context which can use
        SSLv3 or TLSv1 but not SSLv2.
        N(   R   R   R   R   R   R   R   R   R   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    (   R(   R)   R*   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   z  s   	s2   Reactor does not support SSL, cannot run SSL tests(    (    (:   R*   t   twisted.trialR    t   twisted.internetR   R   R   R   t   twisted.protocolsR   t   twisted.pythonR   t   twisted.python.reflectR   R   t   twisted.python.runtimeR	   t   twisted.test.test_tcpR
   R   Rc   R   t   OpenSSLR   R   R   t   twisted.test.ssl_helpersR   t   ImportErrorR   t   sibpatht   __file__R7   t   LineReceiverR   R+   R   R?   RB   RD   R]   Ro   Rp   R   Rr   R6   t   TestCaseR   R   R   R   R   R   R   R   t   IReactorSSLt   tCaset   skip(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   <module>   sR   "	*3		(;i#R3