
:Nc           @   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 d d l m Z d d l 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 Xy d d l
 m Z Wn e k
 r+d	 Z 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 d1 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* d2 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 d0 e8 _9 qWn  d	 S(3   s    
Tests for twisted SSL support.
i(   t   unittest(   t   protocolt   reactort
   interfacest   defer(   t   ConnectionDone(   t   basic(   t   util(   t   platform(   t   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    (   t   tlss
   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__<   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   lineReceivedE   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   connectionLostM   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   _   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   e   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   R/   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#   j   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   rawDataReceived{   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&      s    (	   R'   R(   R)   t   FalseR   R   R#   R<   R&   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR*   R   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   R@   (   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   RB   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyRA      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.pyRC      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   keyRY   R[   t   wN(   R\   R   t   dump_privatekeyt   dump_certificate_requestt   dump_certificatet   ost   extsept   joint   fileR?   t   FILETYPE_PEMt   close(   t   basenameRV   RW   RX   RY   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   mktempRn   R   t   DefaultOpenSSLContextFactoryRb   Rc   Rd   (   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(   Rx   t
   clientBaset   clientCtxFactoryt
   serverBaseRw   (   R   t
   clientArgst   clientKwArgst
   serverArgst   serverKwArgs(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   setupServerAndClient   s    (   R'   R(   R)   Rx   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyRo      s   	R5   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   Rq   R   (   R   Rt   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.pyR5   
  s   t   StolenTCPTestCasec           B   s2   e  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   loadPEMRe   R6   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    c         C   sD   y d d l  } Wn* t k
 r< t j   d k r= t j Sn Xd 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.
        iNt   win32s   SSL routinest	   SSL_writes   protocol is shutdown(   s   SSL routinesR   s   protocol is shutdown(   t   twisted.protocols.tlst   ImportErrorR   t   getTypet   errnot   WSAENOTSOCK(   R   t   twisted(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   getHandleErrorCode7  s    (   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   tearDownd  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>{  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.1(   R   R   t   ClientFactoryt   clientFactoryR=   R7   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   _runTestk  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   assertEqualR   R/   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   R/   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   R/   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   W  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   RA   R   R   R   R   R   R   Rq   R6   t   ClientContextFactoryR   R   R   R   R   R   R   R   R   R   (   R   R7   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   sJ   e  Z d  Z d   Z d   Z e d k r6 d e _ n  d   Z d   Z	 RS(   s'   
    SSL connection closing tests.
    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   Rw   R   R   RC   R   R   RD   R   R   R   Rz   R   (   R   Rr   t   serverProtocolFactoryR   t   clientProtocolFactoryt   clientConnector(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   testImmediateDisconnect  s    				c            s  d t  j f d     Y} d } |  j | | d f i  | | d 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(   s   
        Both sides of SSL connection close connection; the connections should
        close cleanly, and only after the underlying TCP connection has
        disconnected.
        t   CloseAfterHandshakec           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         S   s   t  j   |  _ d  S(   N(   R   R   t   done(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    c         S   s   |  j  j d  d  S(   Nt   a(   R   R?   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s    c         S   s   |  j  j   d  S(   N(   R   R!   (   R   R;   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyRB     s    c         S   s   |  j  j |  |  `  d  S(   N(   R   t   errback(   t   self2R%   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR&     s    (   R'   R(   R   R   RB   R&   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     s   			s   twisted.test.test_ssls   , clients   , serverc              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.1c         S   s   |  j  t  d  S(   N(   t   trapR   (   t   failure(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   checkResult.  s    (   R   R   R   R   R   R   Rw   R   R   R   R   R   R   Rz   R   R   R   t
   addErrback(   R   R   Rr   R   R   R   R   R   (    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_bothSidesLoseConnection  s(    					s*   Old SSL code doesn't always close cleanly.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=   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   verify>  s    c              s     S(   N(    (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   F  s    i    c              s     S(   N(    (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   N  s    s	   127.0.0.1t   consumeErrors(   R   Rz   t
   getContextt
   set_verifyR
   t   VERIFY_PEERR   R   R   R   R$   R&   R   R   R   Rw   R   R   R   R   R   t   DeferredListR   R   t   _cbLostConns(
   R   Rr   R   t   serverConnLostR   R   t   clientConnLostR   R   t   dl(    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   testFailedVerify8  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   R3   R   R   R   (   R   t   resultst   sSuccesst   sResultt   cSuccesst   cResultt   acceptableErrorsR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   V  s    
N(
   R'   R(   R)   R   R   t   newTLSR   t   skipR   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   u  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_optionsz  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_file  s    (   R'   R(   R)   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR   q  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   Rq   R6   R   R   R   t   context(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   setUp  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(   R   R   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_method  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   Rq   R6   Rp   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_missingCertificateFile  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   Rq   Rp   R6   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   test_missingPrivateKeyFile  s    (   R'   R(   R)   R   R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyR     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    s   	s2   Reactor does not support SSL, cannot run SSL tests(    (    (:   R)   t   twisted.trialR    t   twisted.internetR   R   R   R   R   R   t   twisted.protocolsR   t   twisted.pythonR   t   twisted.python.runtimeR   t   twisted.test.test_tcpR	   Rb   R   t   OpenSSLR
   R   R   t   twisted.test.ssl_helpersR   R   R   R   R   R   t   sibpatht   __file__R6   t   LineReceiverR   R*   R   R>   RA   RC   R\   Rn   Ro   Rq   R5   t   TestCaseR   R   R   R   R   R   R   R  t   IReactorSSLt   tCaseR   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_ssl.pyt   <module>   sX   "	
*3		(Ai#3