ó
§ùþMc           @   s<  d  Z  d d l m Z m Z m Z d d l m Z d d l m Z m Z d d l	 m
 Z
 d d l m Z d d l m Z d d l m Z m Z m Z d d	 l m Z m Z m Z d d
 l m Z m Z d d l m Z m Z d d l m Z m Z d d l m Z m Z m Z m  Z  d d l m! Z! m" Z" m# Z# d d l m$ Z$ m% Z% m& Z& d d l m' Z' m( Z( m) Z) m* Z* d d l m+ Z+ m, Z, m- Z- m. Z. d d l/ m0 Z0 m1 Z1 m2 Z2 d d l3 m4 Z4 m5 Z5 d d l3 m6 Z6 m7 Z7 d d l3 m8 Z8 m9 Z9 m: Z: y d d l m; Z; Wn e< k
 r!e= Z; n Xy d d l m> Z> Wn e< k
 rOe= Z> n Xy d d l m? Z? Wn e< k
 r}e= Z? n Xd d l m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI mJ ZJ mK ZK mL ZL mM ZM mN ZN mO ZO mP ZP mQ ZQ mR ZR mS ZS d ZT d „  ZU d „  ZV d „  ZW d f  d „  ƒ  YZX d  e0 eX f d! „  ƒ  YZY d" e0 eX f d# „  ƒ  YZZ d$ e0 f d% „  ƒ  YZ[ d& e0 eX f d' „  ƒ  YZ\ d( e0 eX f d) „  ƒ  YZ] d* e0 eX f d+ „  ƒ  YZ^ d, e0 f d- „  ƒ  YZ_ d. e0 f d/ „  ƒ  YZ` d0 e0 eX f d1 „  ƒ  YZa d2 e0 f d3 „  ƒ  YZb ec d4 k r8e ƒ  n  d5 S(6   s    
Unit tests for L{OpenSSL.SSL}.
iÿÿÿÿ(   t   ECONNREFUSEDt   EINPROGRESSt   EWOULDBLOCK(   t   platform(   t   errort   socket(   t   makedirs(   t   join(   t   main(   t   TYPE_RSAt   FILETYPE_PEMt   FILETYPE_ASN1(   t   PKeyt   X509t   X509Extension(   t   dump_privatekeyt   load_privatekey(   t   dump_certificatet   load_certificate(   t   SENT_SHUTDOWNt   RECEIVED_SHUTDOWN(   t   SSLv2_METHODt   SSLv3_METHODt   SSLv23_METHODt   TLSv1_METHOD(   t   OP_NO_SSLv2t   OP_NO_SSLv3t   OP_SINGLE_DH_USE(   t   VERIFY_PEERt   VERIFY_FAIL_IF_NO_PEER_CERTt   VERIFY_CLIENT_ONCE(   t   Errort   SysCallErrort   WantReadErrort   ZeroReturnError(   t   Contextt   ContextTypet
   Connectiont   ConnectionType(   t   TestCaset   bytest   b(   t   cleartextCertificatePEMt   cleartextPrivateKeyPEM(   t   client_cert_pemt   client_key_pem(   t   server_cert_pemt   server_key_pemt   root_cert_pem(   t   OP_NO_QUERY_MTU(   t   OP_COOKIE_EXCHANGE(   t   OP_NO_TICKET(   t   SSL_ST_CONNECTt   SSL_ST_ACCEPTt   SSL_ST_MASKt   SSL_ST_INITt   SSL_ST_BEFOREt	   SSL_ST_OKt   SSL_ST_RENEGOTIATEt   SSL_CB_LOOPt   SSL_CB_EXITt   SSL_CB_READt   SSL_CB_WRITEt   SSL_CB_ALERTt   SSL_CB_READ_ALERTt   SSL_CB_WRITE_ALERTt   SSL_CB_ACCEPT_LOOPt   SSL_CB_ACCEPT_EXITt   SSL_CB_CONNECT_LOOPt   SSL_CB_CONNECT_EXITt   SSL_CB_HANDSHAKE_STARTt   SSL_CB_HANDSHAKE_DONEs[   -----BEGIN DH PARAMETERS-----
MBYCEQCobsg29c9WZP/54oAPcwiDAgEC
-----END DH PARAMETERS-----
c         C   s   | S(   N(    (   t   connt   certt   errnumt   deptht   ok(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   verify_cb>   s    c          C   sÿ   t  ƒ  }  |  j d ƒ |  j d ƒ t  ƒ  } | j t ƒ | j d |  j ƒ  d f ƒ | j t ƒ |  j ƒ  d } | j	 t
 d ƒ ƒ | j d ƒ t
 d ƒ k s§ t ‚ | j	 t
 d ƒ ƒ | j d ƒ t
 d ƒ k sÛ t ‚ | j t ƒ | j t ƒ | | f S(	   sQ   
    Establish and return a pair of network sockets connected to each other.
    t    i    i   s	   127.0.0.1t   xi   t   y(   RN   i    (   R   t   bindt   listent   setblockingt   Falset
   connect_ext   getsocknamet   Truet   acceptt   sendR)   t   recvt   AssertionError(   t   portt   clientt   server(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   socket_pairA   s    		!!c         C   s]   |  | g } xJ | rX x= | D]5 } y | j  ƒ  Wn t k
 rC q X| j | ƒ q Wq Wd  S(   N(   t   do_handshakeR!   t   remove(   R]   R^   t   connsRH   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   handshake_   s    	t   _LoopbackMixinc           B   s    e  Z d  Z d „  Z d „  Z RS(   s¦   
    Helper mixin which defines methods for creating a connected socket pair and
    for forcing two connected SSL sockets to talk to each other via memory BIOs.
    c         C   s°   t  ƒ  \ } } t t ƒ } | j t t t ƒ ƒ | j t t t	 ƒ ƒ t
 | | ƒ } | j ƒ  t
 t t ƒ | ƒ } | j ƒ  t | | ƒ | j t ƒ | j t ƒ | | f S(   N(   R_   R#   R   t   use_privatekeyR   R
   R/   t   use_certificateR   R.   R%   t   set_accept_statet   set_connect_stateRc   RS   RW   (   t   selfR^   R]   t   ctx(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   _loopbackp   s    

c         C   s¿   t  } x² | rº t } xŸ | | f | | f g D]… \ } } y | j d ƒ } Wn t k
 r` n X| | f SxE t  r² y | j d ƒ } Wn t k
 r› Pqn Xt  } | j | ƒ qn Wq. Wq	 Wd S(   sÂ  
        Try to read application bytes from each of the two L{Connection}
        objects.  Copy bytes back and forth between their send/receive buffers
        for as long as there is anything to copy.  When there is nothing more
        to copy, return C{None}.  If one of them actually manages to deliver
        some application bytes, return a two-tuple of the connection from which
        the bytes were read and the bytes themselves.
        i   i   i   Ni   (   RW   RT   RZ   R!   t   bio_readt	   bio_write(   Ri   t   client_connt   server_connt   wrotet   readt   writeR(   t   dirty(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _interactInMemory‚   s"    		
	(   t   __name__t
   __module__t   __doc__Rk   Rt   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRd   k   s   	t   ContextTestsc           B   s|  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k rn	 d „  Z d „  Z d „  Z  d „  Z! d  „  Z" d! „  Z# d" „  Z$ d# „  Z% d$ „  Z& d% „  Z' d& „  Z( d' „  Z) d( „  Z* RS()   s0   
    Unit tests for L{OpenSSL.SSL.Context}.
    c         C   sQ   x$ t  t t t g D] } t | ƒ q W|  j t t d ƒ |  j t t d ƒ d S(   sŒ   
        L{Context} can be instantiated with one of L{SSLv2_METHOD},
        L{SSLv3_METHOD}, L{SSLv23_METHOD}, or L{TLSv1_METHOD}.
        RN   i
   N(   R   R   R   R   R#   t   assertRaisest	   TypeErrort
   ValueError(   Ri   t   meth(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_method¶   s    c         C   s'   |  j  t t ƒ |  j t d t ƒ d S(   s‡   
        L{Context} and L{ContextType} refer to the same type object and can be
        used to create instances of that type.
        R#   N(   t   assertIdenticalR#   R$   t   assertConsistentTypeR   (   Ri   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   test_typeÁ   s    c         C   sL   t  ƒ  } | j t d ƒ t t ƒ } | j | ƒ |  j t | j d ƒ d S(   sU   
        L{Context.use_privatekey} takes an L{OpenSSL.crypto.PKey} instance.
        i€   RN   N(   R   t   generate_keyR	   R#   R   Re   Ry   Rz   (   Ri   t   keyRj   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_privatekeyÊ   s
    	c         C   s<   t  t ƒ } |  j t | j ƒ |  j t | j d d ƒ d S(   sm   
        L{Context.set_app_data} raises L{TypeError} if called with other than
        one argument.
        N(   R#   R   Ry   Rz   t   set_app_datat   None(   Ri   t   context(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_app_data_wrong_argsÕ   s    c         C   s&   t  t ƒ } |  j t | j d ƒ d S(   sc   
        L{Context.get_app_data} raises L{TypeError} if called with any
        arguments.
        N(   R#   R   Ry   Rz   t   get_app_dataR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_app_data_wrong_argsß   s    c         C   s<   t  ƒ  } t t ƒ } | j | ƒ |  j | j ƒ  | ƒ d S(   su   
        L{Context.set_app_data} stores an object for later retrieval using
        L{Context.get_app_data}.
        N(   t   objectR#   R   R„   R~   Rˆ   (   Ri   t   app_dataR†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_app_dataè   s    	c         C   sR   t  t ƒ } |  j t | j ƒ |  j t | j d ƒ |  j t | j d d ƒ d S(   s‹   
        L{Context.set_options} raises L{TypeError} if called with the wrong
        number of arguments or a non-C{int} argument.
        i   N(   R#   R   Ry   Rz   t   set_optionsR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_options_wrong_argsó   s    c         C   sR   t  t ƒ } |  j t | j ƒ |  j t | j d ƒ |  j t | j d d ƒ d S(   s‹   
        L{Context.set_timeout} raises L{TypeError} if called with the wrong
        number of arguments or a non-C{int} argument.
        i   N(   R#   R   Ry   Rz   t   set_timeoutR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_timeout_wrong_argsþ   s    c         C   s&   t  t ƒ } |  j t | j d ƒ d S(   sZ   
        L{Context.get_timeout} raises L{TypeError} if called with any arguments.
        N(   R#   R   Ry   Rz   t   get_timeoutR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_timeout_wrong_args	  s    c         C   s3   t  t ƒ } | j d ƒ |  j | j ƒ  d ƒ d S(   sµ   
        L{Context.set_timeout} sets the session timeout for all connections
        created using the context object.  L{Context.get_timeout} retrieves this
        value.
        iÒ  N(   R#   R   R   t   assertEqualsR‘   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_timeout  s    c         C   sR   t  t ƒ } |  j t | j ƒ |  j t | j d ƒ |  j t | j d d ƒ d S(   s   
        L{Context.set_verify_depth} raises L{TypeError} if called with the wrong
        number of arguments or a non-C{int} argument.
        i   N(   R#   R   Ry   Rz   t   set_verify_depthR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    test_set_verify_depth_wrong_args  s    c         C   s&   t  t ƒ } |  j t | j d ƒ d S(   s_   
        L{Context.get_verify_depth} raises L{TypeError} if called with any arguments.
        N(   R#   R   Ry   Rz   t   get_verify_depthR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    test_get_verify_depth_wrong_args'  s    c         C   s3   t  t ƒ } | j d ƒ |  j | j ƒ  d ƒ d S(   sÂ   
        L{Context.set_verify_depth} sets the number of certificates in a chain
        to follow before giving up.  The value can be retrieved with
        L{Context.get_verify_depth}.
        i   N(   R#   R   R•   R“   R—   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_verify_depth/  s    c         C   sm   t  ƒ  } | j t d ƒ |  j ƒ  } t | d ƒ } t t | d | ƒ } | j | j d ƒ ƒ | j	 ƒ  | S(   sŒ   
        Write a new private key out to a new file, encrypted using the given
        passphrase.  Return the path to the new file.
        i€   t   wt   blowfisht   ascii(
   R   R   R	   t   mktempt   openR   R
   Rr   t   decodet   close(   Ri   t
   passphraseR‚   t   pemFilet   fObjt   pem(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _write_encrypted_pem:  s    	
c         C   sX   t  t ƒ } |  j t | j ƒ |  j t | j d ƒ |  j t | j d „  d d ƒ d S(   s   
        L{Context.set_passwd_cb} raises L{TypeError} if called with the
        wrong arguments or with a non-callable first argument.
        c           S   s   d  S(   N(   R…   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   <lambda>Q  s    N(   R#   R   Ry   Rz   t   set_passwd_cbR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_passwd_cb_wrong_argsI  s    c            sÇ   t  d ƒ ‰ |  j ˆ ƒ } g  ‰  ‡  ‡ f d †  } t t ƒ } | j | ƒ | j | ƒ |  j t ˆ  ƒ d ƒ |  j t ˆ  d d t	 ƒ ƒ |  j t ˆ  d d t	 ƒ ƒ |  j
 ˆ  d d d ƒ d S(   s   
        L{Context.set_passwd_cb} accepts a callable which will be invoked when
        a private key is loaded from an encrypted PEM.
        t   foobarc            s   ˆ  j  |  | | f ƒ ˆ S(   N(   t   append(   t   maxlent   verifyt   extra(   t
   calledWithR¡   (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   passphraseCallback\  s    i   i    i   N(   R)   R¥   R#   R   R§   t   use_privatekey_filet
   assertTruet   lent
   isinstancet   intt   assertEqualR…   (   Ri   R¢   R¯   R†   (    (   R®   R¡   s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_passwd_cbT  s    c         C   sQ   |  j  t d ƒ ƒ } d „  } t t ƒ } | j | ƒ |  j t | j | ƒ d S(   st   
        L{Context.use_privatekey_file} propagates any exception raised by the
        passphrase callback.
        s   monkeys are nicec         S   s   t  d ƒ ‚ d  S(   Ns   Sorry, I am a fail.(   t   RuntimeError(   R«   R¬   R­   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¯   n  s    N(   R¥   R)   R#   R   R§   Ry   R·   R°   (   Ri   R¢   R¯   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_exceptionh  s
    	c         C   sQ   |  j  t d ƒ ƒ } d „  } t t ƒ } | j | ƒ |  j t | j | ƒ d S(   s†   
        L{Context.use_privatekey_file} raises L{OpenSSL.SSL.Error} if the
        passphrase callback returns a false value.
        s   monkeys are nicec         S   s   d  S(   N(   R…   (   R«   R¬   R­   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¯   |  s    N(   R¥   R)   R#   R   R§   Ry   R   R°   (   Ri   R¢   R¯   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_falsev  s
    	c         C   sQ   |  j  t d ƒ ƒ } d „  } t t ƒ } | j | ƒ |  j t | j | ƒ d S(   s   
        L{Context.use_privatekey_file} raises L{OpenSSL.SSL.Error} if the
        passphrase callback returns a true non-string value.
        s   monkeys are nicec         S   s   d S(   Ni
   (    (   R«   R¬   R­   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¯   Š  s    N(   R¥   R)   R#   R   R§   Ry   R   R°   (   Ri   R¢   R¯   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_non_string„  s
    	c            sX   t  d ƒ d ‰  |  j ˆ  ƒ } ‡  f d †  } t t ƒ } | j | ƒ | j | ƒ d S(   s›   
        If the passphrase returned by the passphrase callback returns a string
        longer than the indicated maximum length, it is truncated.
        RO   i   c            s    |  d k s t  ‚ ˆ  t d ƒ S(   Ni   RP   (   R[   R)   (   R«   R¬   R­   (   R¡   (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¯   š  s    N(   R)   R¥   R#   R   R§   R°   (   Ri   R¢   R¯   R†   (    (   R¡   s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_too_long’  s    c            sø   t  ƒ  \ } } t t t ƒ | ƒ } | j ƒ  g  ‰  ‡  f d †  } t t ƒ } | j | ƒ | j t t t	 ƒ ƒ | j
 t t t ƒ ƒ t | | ƒ } | j ƒ  xC ˆ  sæ x6 | | f D]( } y | j ƒ  Wq· t k
 rÞ q· Xq· Wq¤ W|  j ˆ  ƒ d S(   sž   
        L{Context.set_info_callback} accepts a callable which will be invoked
        when certain information about an SSL connection is available.
        c            s   ˆ  j  |  | | f ƒ d  S(   N(   Rª   (   RH   t   wheret   ret(   t   called(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   info°  s    N(   R_   R%   R#   R   Rh   t   set_info_callbackRf   R   R
   R*   Re   R   R+   Rg   R`   R!   R±   (   Ri   R^   R]   t	   clientSSLR¿   R†   t	   serverSSLt   ssl(    (   R¾   s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_info_callback¥  s(    

	c   	      G   sÛ   t  ƒ  \ } } t t ƒ } | j | Œ  | j t d „  ƒ t | | ƒ } | j ƒ  t t ƒ } | j t	 t
 t ƒ ƒ | j t t
 t ƒ ƒ t | | ƒ } | j ƒ  t | | ƒ | j ƒ  } |  j | j ƒ  j d ƒ d S(   sá   
        Create a client context which will verify the peer certificate and call
        its C{load_verify_locations} method with C{*args}.  Then connect it to a
        server and ensure that the handshake succeeds.
        c         S   s   | S(   N(    (   RH   RI   t   errnoRK   t   preverify_ok(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¦   Õ  s    s   Testing Root CAN(   R_   R#   R   t   load_verify_locationst
   set_verifyR   R%   Rh   Rf   R   R
   R*   Re   R   R+   Rg   Rc   t   get_peer_certificateRµ   t   get_subjectt   CN(	   Ri   t   argsR^   R]   t   clientContextRÁ   t   serverContextRÂ   RI   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _load_verify_locations_testÇ  s$    


c         C   sL   |  j  ƒ  } t | d ƒ } | j t j d ƒ ƒ | j ƒ  |  j | ƒ d S(   sŠ   
        L{Context.load_verify_locations} accepts a file name and uses the
        certificates within for verification purposes.
        Rš   Rœ   N(   R   Rž   Rr   R*   RŸ   R    RÏ   (   Ri   t   cafileR£   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_verify_fileí  s
    
c         C   s,   t  t ƒ } |  j t | j |  j ƒ  ƒ d S(   sm   
        L{Context.load_verify_locations} raises L{Error} when passed a
        non-existent cafile.
        N(   R#   R   Ry   R   RÇ   R   (   Ri   RÍ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_verify_invalid_fileú  s    c         C   s   |  j  ƒ  } t | ƒ xR d d g D]D } t | | ƒ } t | d ƒ } | j t j d ƒ ƒ | j ƒ  q# W|  j d | ƒ d S(   s   
        L{Context.load_verify_locations} accepts a directory name and uses
        the certificates within for verification purposes.
        s
   c7adac82.0s
   c3705638.0Rš   Rœ   N(
   R   R   R   Rž   Rr   R*   RŸ   R    RÏ   R…   (   Ri   t   capatht   nameRÐ   R£   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_verify_directory  s    
c         C   sw   t  t ƒ } |  j t | j ƒ |  j t | j t ƒ  ƒ |  j t | j t ƒ  t ƒ  ƒ |  j t | j d d d ƒ d S(   s™   
        L{Context.load_verify_locations} raises L{TypeError} if called with
        the wrong number of arguments or with non-C{str} arguments.
        N(   R#   R   Ry   Rz   RÇ   RŠ   R…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt%   test_load_verify_locations_wrong_args  s
    t   win32c         C   s‰   t  t ƒ } | j ƒ  | j t d „  ƒ t ƒ  } | j d ƒ t | | ƒ } | j ƒ  | j	 ƒ  | j
 d ƒ |  j | j d ƒ ƒ d S(   s¥   
            L{Context.set_default_verify_paths} causes the platform-specific CA
            certificate locations to be used for verification purposes.
            c         S   s   | S(   N(    (   RH   RI   RÅ   RK   RÆ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¦   9  s    s   verisign.comi»  s   GET / HTTP/1.0

i   N(   s   verisign.comi»  (   R#   R   t   set_default_verify_pathsRÈ   R   R   t   connectR%   Rh   R`   RY   R±   RZ   (   Ri   R†   R]   RÁ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_default_verify_paths'  s    

	

c         C   sR   t  t ƒ } |  j t | j d ƒ |  j t | j d ƒ |  j t | j d ƒ d S(   sv   
        L{Context.set_default_verify_paths} takes no arguments and raises
        L{TypeError} if given any.
        i   RN   N(   R#   R   Ry   Rz   RØ   R…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt'   test_set_default_verify_paths_signatureD  s    c         C   s[   t  t ƒ } |  j t | j ƒ |  j t | j t ƒ  ƒ |  j t | j t ƒ  t ƒ  ƒ d S(   s½   
        L{Context.add_extra_chain_cert} raises L{TypeError} if called with
        other than one argument or if called with an object which is not an
        instance of L{X509}.
        N(   R#   R   Ry   Rz   t   add_extra_chain_certRŠ   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt&   test_add_extra_chain_cert_invalid_certO  s    c         C   sA  t  t d ƒ t t d ƒ ƒ } t ƒ  } | j t d ƒ t ƒ  } d | j ƒ  _ | j	 | j ƒ  ƒ | j
 | ƒ | j t d ƒ ƒ | j t d ƒ ƒ | j | g ƒ | j d ƒ | j | d ƒ t ƒ  } | j t d ƒ t ƒ  } d	 | j ƒ  _ | j	 | j ƒ  ƒ | j
 | ƒ | j t d ƒ ƒ | j t d ƒ ƒ | j | g ƒ | j d ƒ | j | d ƒ t ƒ  } | j t d ƒ t ƒ  } d
 | j ƒ  _ | j	 | j ƒ  ƒ | j
 | ƒ | j t d ƒ ƒ | j t d ƒ ƒ | j t  t d ƒ t t d ƒ ƒ g ƒ | j d ƒ | j | d ƒ | | f | | f | | f g S(   s  
        Construct and return a chain of certificates.

            1. A new self-signed certificate authority certificate (cacert)
            2. A new intermediate certificate signed by cacert (icert)
            3. A new server certificate signed by icert (scert)
        t   basicConstraintss   CA:truei   s   Authority Certificatet   20000101000000Zt   20200101000000Zi    t   sha1s   Intermediate Certificates   Server Certificates   CA:false(   R   R)   RT   R   R   R	   R   RÊ   t
   commonNamet
   set_issuert
   set_pubkeyt   set_notBeforet   set_notAftert   add_extensionst   set_serial_numbert   signRW   (   Ri   t   caextt   cakeyt   cacertt   ikeyt   icertt   skeyt   scert(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _create_certificate_chain[  sH    						"c   	      C   s•   t  ƒ  \ } } t | | ƒ } | j ƒ  t | | ƒ } | j ƒ  xM t d ƒ D]? } x6 | | g D]( } y | j ƒ  Wqa t k
 rˆ qa Xqa WqN Wd S(   s…   
        Verify that a client and server created with the given contexts can
        successfully handshake and communicate.
        i   N(   R_   R%   Rg   Rh   t   rangeR`   R!   (	   Ri   RÎ   RÍ   t   serverSockett   clientSocketR^   R]   t   it   s(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _handshake_test  s    

c         C   su  |  j  ƒ  } | \ \ } } \ } } \ } } xg | d f | d f | d f g D]D \ } }	 t |	 d ƒ }
 |
 j t t | ƒ j d ƒ ƒ |
 j ƒ  qO Wxg | d f | d f | d f g D]D \ } }	 t |	 d ƒ }
 |
 j t t | ƒ j d ƒ ƒ |
 j ƒ  q¹ Wt t	 ƒ } | j
 | ƒ | j | ƒ | j | ƒ t t	 ƒ } | j t t Bt ƒ | j d ƒ |  j | | ƒ d	 S(
   sƒ  
        L{Context.add_extra_chain_cert} accepts an L{X509} instance to add to
        the certificate chain.

        See L{_create_certificate_chain} for the details of the certificate
        chain tested.

        The chain is tested by starting a server with scert and connecting
        to it with a client which trusts cacert and requires verification to
        succeed.
        s   ca.pems   i.pems   s.pemRš   Rœ   s   ca.keys   i.keys   s.keyN(   Rñ   Rž   Rr   R   R
   RŸ   R    R   R#   R   Re   Rf   RÜ   RÈ   R   R   RM   RÇ   R÷   (   Ri   t   chainRë   Rì   Rí   Rî   Rï   Rð   RI   RÔ   R£   R‚   RÎ   RÍ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_add_extra_chain_cert§  s&    !..c         C   sN  |  j  ƒ  } | \ \ } } \ } } \ } } |  j ƒ  } t | d ƒ }	 |	 j t t | ƒ j d ƒ ƒ |	 j t t | ƒ j d ƒ ƒ |	 j t t | ƒ j d ƒ ƒ |	 j ƒ  t t	 ƒ }
 |
 j
 | ƒ |
 j | ƒ t d d ƒ }	 |	 j t t | ƒ j d ƒ ƒ |	 j ƒ  t t	 ƒ } | j t t Bt ƒ | j d ƒ |  j |
 | ƒ d S(   s  
        L{Context.use_certificate_chain_file} reads a certificate chain from
        the specified file.

        The chain is tested by starting a server with scert and connecting
        to it with a client which trusts cacert and requires verification to
        succeed.
        Rš   Rœ   s   ca.pemN(   Rñ   R   Rž   Rr   R   R
   RŸ   R    R#   R   t   use_certificate_chain_fileRe   RÈ   R   R   RM   RÇ   R÷   (   Ri   Rø   Rë   Rì   Rí   Rî   Rï   Rð   t	   chainFileR£   RÎ   RÍ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_certificate_chain_fileÓ  s&    	!

c         C   s&   t  t ƒ } |  j t | j d ƒ d S(   sf   
        L{Context.get_verify_mode} raises L{TypeError} if called with any
        arguments.
        N(   R#   R   Ry   Rz   t   get_verify_modeR…   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_verify_mode_wrong_argsú  s    c         C   sW   t  t ƒ } |  j | j ƒ  d ƒ | j t t Bd „  ƒ |  j | j ƒ  t t Bƒ d S(   s~   
        L{Context.get_verify_mode} returns the verify mode flags previously
        passed to L{Context.set_verify}.
        i    c          W   s   d  S(   N(   R…   (   RÌ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR¦     s    N(   R#   R   R“   Rý   RÈ   R   R   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_verify_mode  s    c         C   sU   t  t ƒ } |  j t | j ƒ |  j t | j d d ƒ |  j t | j t ƒ  ƒ d S(   s   
        L{Context.load_tmp_dh} raises L{TypeError} if called with the wrong
        number of arguments or with a non-C{str} argument.
        t   fooN(   R#   R   Ry   Rz   t   load_tmp_dhR…   RŠ   (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh_wrong_args  s    c         C   s&   t  t ƒ } |  j t | j d ƒ d S(   sr   
        L{Context.load_tmp_dh} raises L{OpenSSL.SSL.Error} if the specified file
        does not exist.
        t   helloN(   R#   R   Ry   R   R  (   Ri   R†   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh_missing_file  s    c         C   sO   t  t ƒ } |  j ƒ  } t | d ƒ } | j t ƒ | j ƒ  | j | ƒ d S(   si   
        L{Context.load_tmp_dh} loads Diffie-Hellman parameters from the
        specified file.
        Rš   N(   R#   R   R   Rž   Rr   t   dhparamR    R  (   Ri   R†   t
   dhfilenamet   dhfile(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh$  s    
c         C   sE   t  t ƒ } | j d ƒ t | d ƒ } |  j | j ƒ  d g ƒ d S(   s§   
        L{Context.set_cipher_list} accepts a C{str} naming the ciphers which
        connections created with the context object will be able to choose from.
        s   hello world:EXP-RC4-MD5s   EXP-RC4-MD5N(   R#   R   t   set_cipher_listR%   R…   R“   t   get_cipher_list(   Ri   R†   RH   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_cipher_list2  s    (+   Ru   Rv   Rw   R}   R€   Rƒ   R‡   R‰   RŒ   RŽ   R   R’   R”   R–   R˜   R™   R¥   R¨   R¶   R¸   R¹   Rº   R»   RÄ   RÏ   RÑ   RÒ   RÕ   RÖ   R   RÚ   RÛ   RÝ   Rñ   R÷   Rù   Rü   Rþ   Rÿ   R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRx   ²   sT   					
																		"	&		
						5		,	'							t   ConnectionTestsc           B   s¶   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d	 k rc n	 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s3   
    Unit tests for L{OpenSSL.SSL.Connection}.
    c         C   s6   |  j  t t ƒ t t ƒ } |  j t d | d ƒ d S(   s   
        L{Connection} and L{ConnectionType} refer to the same type object and
        can be used to create instances of that type.
        R%   N(   R~   R%   R&   R#   R   R   R…   (   Ri   Rj   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR€   T  s    c         C   s5   t  t ƒ } t | d ƒ } |  j | j ƒ  | ƒ d S(   s   
        L{Connection.get_context} returns the L{Context} instance used to
        construct the L{Connection} instance.
        N(   R#   R   R%   R…   R~   t   get_context(   Ri   R†   t
   connection(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_context^  s    c         C   s/   t  t t ƒ d ƒ } |  j t | j d ƒ d S(   se   
        L{Connection.get_context} raises L{TypeError} if called with any
        arguments.
        N(   R%   R#   R   R…   Ry   Rz   R  (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_context_wrong_argsh  s    c         C   s/   t  t t ƒ d ƒ } |  j | j ƒ  d ƒ d S(   si   
        L{Connection.pending} returns the number of bytes available for
        immediate read.
        i    N(   R%   R#   R   R…   R“   t   pending(   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_pendingq  s    c         C   s/   t  t t ƒ d ƒ } |  j t | j d ƒ d S(   sY   
        L{Connection.pending} raises L{TypeError} if called with any arguments.
        N(   R%   R#   R   R…   Ry   Rz   R  (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_pending_wrong_argsz  s    c         C   s^   t  t t ƒ t ƒ  ƒ } |  j t | j d ƒ |  j t | j ƒ |  j t | j d d ƒ d S(   s   
        L{Connection.connect} raises L{TypeError} if called with a non-address
        argument or with the wrong number of arguments.
        s	   127.0.0.1i   N(   s	   127.0.0.1i   (   R%   R#   R   R   Ry   Rz   RÙ   R…   (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_connect_wrong_args‚  s    c         C   sW   t  ƒ  } t t ƒ } t | | ƒ } |  j t | j d ƒ } |  j | j d t	 ƒ d S(   sy   
        L{Connection.connect} raises L{socket.error} if the underlying socket
        connect method raises it.
        s	   127.0.0.1i   i    N(   s	   127.0.0.1i   (
   R   R#   R   R%   Ry   R   RÙ   R“   RÌ   R    (   Ri   R]   R†   RÁ   t   exc(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_connect_refused  s
    	c         C   s\   t  ƒ  } | j d ƒ | j d ƒ t t t ƒ t  ƒ  ƒ } | j d | j ƒ  d f ƒ d S(   sZ   
        L{Connection.connect} establishes a connection to the specified address.
        RN   i    i   s	   127.0.0.1i   N(   RN   i    (   R   RQ   RR   R%   R#   R   RÙ   RV   (   Ri   R\   RÁ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_connect™  s
    	t   darwinc         C   s   t  ƒ  } | j d ƒ | j d ƒ t t t ƒ t  ƒ  ƒ } | j t ƒ | j | j	 ƒ  ƒ } t
 t f } |  j | | k d | | f ƒ d S(   s‘   
            If there is a connection error, L{Connection.connect_ex} returns the
            errno instead of raising an exception.
            RN   i    i   s   %r not in %rN(   RN   i    (   R   RQ   RR   R%   R#   R   RS   RT   RU   RV   R   R   R±   (   Ri   R\   RÁ   t   resultt   expected(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_connect_ex©  s    	c         C   s2   t  t t ƒ t ƒ  ƒ } |  j t | j d ƒ d S(   sX   
        L{Connection.accept} raises L{TypeError} if called with any arguments.
        N(   R%   R#   R   R   Ry   Rz   RX   R…   (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_accept_wrong_argsº  s    c         C   s÷   t  t ƒ } | j t t t ƒ ƒ | j t t t ƒ ƒ t	 ƒ  } t
 | | ƒ } | j d ƒ | j d ƒ t
 t  t ƒ t	 ƒ  ƒ } | j d | j ƒ  d f ƒ | j ƒ  \ } } |  j t | t
 ƒ ƒ |  j | j ƒ  | ƒ |  j | | j ƒ  ƒ d S(   sÌ   
        L{Connection.accept} accepts a pending connection attempt and returns a
        tuple of a new L{Connection} (the accepted client) and the address the
        connection originated from.
        RN   i    i   s	   127.0.0.1i   N(   RN   i    (   R#   R   Re   R   R
   R/   Rf   R   R.   R   R%   RQ   RR   RÙ   RV   RX   R±   R³   R~   R  R“   (   Ri   Rj   R\   t   portSSLRÁ   RÂ   t   address(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_acceptÂ  s    	c         C   s‡   t  t t ƒ d ƒ } |  j t | j d ƒ |  j t | j d ƒ |  j t | j ƒ |  j t | j d ƒ |  j t | j d d ƒ d S(   s˜   
        L{Connection.shutdown} raises L{TypeError} if called with the wrong
        number of arguments or with arguments other than integers.
        i    i   N(	   R%   R#   R   R…   Ry   Rz   t   shutdownt   get_shutdownt   set_shutdown(   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_shutdown_wrong_argsÝ  s    c         C   s¿   |  j  ƒ  \ } } |  j | j ƒ  ƒ |  j | j ƒ  t ƒ |  j t | j d ƒ |  j | j ƒ  t	 ƒ | j ƒ  |  j | j ƒ  t t	 Bƒ |  j t | j d ƒ |  j | j ƒ  t t	 Bƒ d S(   sS   
        L{Connection.shutdown} performs an SSL-level connection shutdown.
        i   N(
   Rk   t   assertFalseR   R“   R!  R   Ry   R"   RZ   R   (   Ri   R^   R]   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_shutdownê  s    
c         C   s?   t  t t ƒ t ƒ  ƒ } | j t ƒ |  j | j ƒ  t ƒ d S(   sk   
        L{Connection.set_shutdown} sets the state of the SSL connection shutdown
        process.
        N(   R%   R#   R   R   R"  R   R“   R!  (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_shutdownù  s    c         C   s[   t  t t ƒ d ƒ } |  j t | j d ƒ |  j t | j ƒ |  j t | j d d ƒ d S(   sÆ   
        L{Connection.set_app_data} raises L{TypeError} if called with other than
        one argument.  L{Connection.get_app_data} raises L{TypeError} if called
        with any arguments.
        N(   R%   R#   R   R…   Ry   Rz   Rˆ   R„   (   Ri   RH   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_app_data_wrong_args  s    c         C   sE   t  t t ƒ d ƒ } t ƒ  } | j | ƒ |  j | j ƒ  | ƒ d S(   s¤   
        Any object can be set as app data by passing it to
        L{Connection.set_app_data} and later retrieved with
        L{Connection.get_app_data}.
        N(   R%   R#   R   R…   RŠ   R„   R~   Rˆ   (   Ri   RH   R‹   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRŒ     s    	c         C   s,   t  t t ƒ d ƒ } |  j t | j ƒ d S(   sz   
        L{Connection.makefile} is not implemented and calling that method raises
        L{NotImplementedError}.
        N(   R%   R#   R   R…   Ry   t   NotImplementedErrort   makefile(   Ri   RH   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_makefile  s    (   Ru   Rv   Rw   R€   R  R  R  R  R  R  R  R   R  R  R  R#  R%  R&  R'  RŒ   R*  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  >  s(   	
	
														
		t   ConnectionGetCipherListTestsc           B   s    e  Z d  Z d „  Z d „  Z RS(   s2   
    Tests for L{Connection.get_cipher_list}.
    c         C   s/   t  t t ƒ d ƒ } |  j t | j d ƒ d S(   si   
        L{Connection.get_cipher_list} raises L{TypeError} if called with any
        arguments.
        N(   R%   R#   R   R…   Ry   Rz   R
  (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_wrong_args)  s    c         C   sb   t  t t ƒ d ƒ } | j ƒ  } |  j t | t ƒ ƒ x$ | D] } |  j t | t ƒ ƒ q> Wd S(   sˆ   
        L{Connection.get_cipher_list} returns a C{list} of C{str} giving the
        names of the ciphers which might be used.
        N(	   R%   R#   R   R…   R
  R±   R³   t   listt   str(   Ri   R  t   cipherst   cipher(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_result2  s
    (   Ru   Rv   Rw   R,  R1  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR+  %  s   		t   ConnectionSendTestsc           B   sE   e  Z d  Z d „  Z d „  Z y e Wn e k
 r9 n
 Xd „  Z RS(   s&   
    Tests for L{Connection.send}
    c         C   s^   t  t t ƒ d ƒ } |  j t | j ƒ |  j t | j t ƒ  ƒ |  j t | j d d ƒ d S(   sx   
        When called with arguments other than a single string,
        L{Connection.send} raises L{TypeError}.
        R   t   barN(   R%   R#   R   R…   Ry   Rz   RY   RŠ   (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR,  C  s    c         C   sZ   |  j  ƒ  \ } } | j t d ƒ ƒ } |  j | d ƒ |  j | j d ƒ t d ƒ ƒ d S(   s‡   
        When passed a short byte string, L{Connection.send} transmits all of it
        and returns the number of bytes sent.
        t   xyi   N(   Rk   RY   R)   R“   RZ   (   Ri   R^   R]   t   count(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_short_bytesN  s    c         C   s`   |  j  ƒ  \ } } | j t t d ƒ ƒ ƒ } |  j | d ƒ |  j | j d ƒ t d ƒ ƒ d S(   s·   
            When passed a memoryview onto a small number of bytes,
            L{Connection.send} transmits all of them and returns the number of
            bytes sent.
            R4  i   N(   Rk   RY   t
   memoryviewR)   R“   RZ   (   Ri   R^   R]   R5  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_short_memoryview]  s    (   Ru   Rv   Rw   R,  R6  R7  t	   NameErrorR8  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR2  ?  s   		
t   ConnectionSendallTestsc           B   sW   e  Z d  Z d „  Z d „  Z y e Wn e k
 r9 n
 Xd „  Z d „  Z d „  Z	 RS(   s*   
    Tests for L{Connection.sendall}.
    c         C   s^   t  t t ƒ d ƒ } |  j t | j ƒ |  j t | j t ƒ  ƒ |  j t | j d d ƒ d S(   s{   
        When called with arguments other than a single string,
        L{Connection.sendall} raises L{TypeError}.
        R   R3  N(   R%   R#   R   R…   Ry   Rz   t   sendallRŠ   (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR,  n  s    c         C   sH   |  j  ƒ  \ } } | j t d ƒ ƒ |  j | j d ƒ t d ƒ ƒ d S(   sf   
        L{Connection.sendall} transmits all of the bytes in the string passed to
        it.
        RO   i   N(   Rk   R;  R)   R“   RZ   (   Ri   R^   R]   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   test_shorty  s    c         C   sN   |  j  ƒ  \ } } | j t t d ƒ ƒ ƒ |  j | j d ƒ t d ƒ ƒ d S(   s‰   
            When passed a memoryview onto a small number of bytes,
            L{Connection.sendall} transmits all of them.
            RO   i   N(   Rk   R;  R7  R)   R“   RZ   (   Ri   R^   R]   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR8  ˆ  s    c         C   s­   |  j  ƒ  \ } } t d ƒ d
 t d ƒ } | j | ƒ g  } d } xB | t | ƒ k  r‰ | j d ƒ } | j | ƒ | t | ƒ 7} qH W|  j | t d ƒ j | ƒ ƒ d S(   s«   
        L{Connection.sendall} transmits all of the bytes in the string passed to
        it even if this requires multiple calls of an underlying write function.
        RO   i   i    i   RP   i    RN   Ni €  iÿ  (   Rk   R)   R;  R²   RZ   Rª   R“   R   (   Ri   R^   R]   t   messaget   accumt   receivedt   data(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   test_long’  s    c         C   s9   |  j  ƒ  \ } } | j d ƒ |  j t | j d ƒ d S(   s   
        If the underlying socket is closed, L{Connection.sendall} propagates the
        write error from the low level write call.
        i   s   hello, worldN(   Rk   t   sock_shutdownRy   R    R;  (   Ri   R^   R]   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_closed¦  s    (
   Ru   Rv   Rw   R,  R<  R7  R9  R8  RA  RC  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR:  j  s   		
	
	t   ConnectionRenegotiateTestsc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s+   
    Tests for SSL renegotiation APIs.
    c         C   s/   t  t t ƒ d ƒ } |  j t | j d ƒ d S(   se   
        L{Connection.renegotiate} raises L{TypeError} if called with any
        arguments.
        N(   R%   R#   R   R…   Ry   Rz   t   renegotiate(   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_renegotiate_wrong_argsµ  s    c         C   s/   t  t t ƒ d ƒ } |  j t | j d ƒ d S(   sn   
        L{Connection.total_renegotiations} raises L{TypeError} if called with
        any arguments.
        N(   R%   R#   R   R…   Ry   Rz   t   total_renegotiations(   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt$   test_total_renegotiations_wrong_args¾  s    c         C   s/   t  t t ƒ d ƒ } |  j | j ƒ  d ƒ d S(   sr   
        L{Connection.total_renegotiations} returns C{0} before any
        renegotiations have happened.
        i    N(   R%   R#   R   R…   R“   RG  (   Ri   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_total_renegotiationsÇ  s    (   Ru   Rv   Rw   RF  RH  RI  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRD  ±  s   				t
   ErrorTestsc           B   s   e  Z d  Z d „  Z RS(   s.   
    Unit tests for L{OpenSSL.SSL.Error}.
    c         C   s-   |  j  t t t ƒ ƒ |  j t j d ƒ d S(   s0   
        L{Error} is an exception type.
        R   N(   R±   t
   issubclassR   t	   ExceptionRµ   Ru   (   Ri   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR€   ê  s    (   Ru   Rv   Rw   R€   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRJ  æ  s   t   ConstantsTestsc           B   sV   e  Z d  Z e d k	 r$ d „  Z n  e d k	 r< d „  Z n  e d k	 rT d „  Z	 n  RS(   sð   
    Tests for the values of constants exposed in L{OpenSSL.SSL}.

    These are values defined by OpenSSL intended only to be used as flags to
    OpenSSL APIs.  The only assertions it seems can be made about them is
    their values.
    c         C   s   |  j  t d ƒ d S(   s   
            The value of L{OpenSSL.SSL.OP_NO_QUERY_MTU} is 0x1000, the value of
            I{SSL_OP_NO_QUERY_MTU} defined by I{openssl/ssl.h}.
            i   N(   Rµ   R1   (   Ri   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_op_no_query_mtuý  s    c         C   s   |  j  t d ƒ d S(   s£   
            The value of L{OpenSSL.SSL.OP_COOKIE_EXCHANGE} is 0x2000, the value
            of I{SSL_OP_COOKIE_EXCHANGE} defined by I{openssl/ssl.h}.
            i    N(   Rµ   R2   (   Ri   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_op_cookie_exchange  s    c         C   s   |  j  t d ƒ d S(   s—   
            The value of L{OpenSSL.SSL.OP_NO_TICKET} is 0x4000, the value of
            I{SSL_OP_NO_TICKET} defined by I{openssl/ssl.h}.
            i @  N(   Rµ   R3   (   Ri   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_op_no_ticket  s    N(
   Ru   Rv   Rw   R1   R…   RN  R2   RO  R3   RP  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRM  ó  s   

t   MemoryBIOTestsc           B   s¹   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sA   
    Tests for L{OpenSSL.SSL.Connection} using a memory BIO.
    c         C   s®   t  t ƒ } | j t t Bt Bƒ | j t t Bt	 Bt
 ƒ | j ƒ  } | j t t t ƒ ƒ | j t t t ƒ ƒ | j ƒ  | j t t t ƒ ƒ t | | ƒ } | j ƒ  | S(   sc   
        Create a new server-side SSL L{Connection} object wrapped around
        C{sock}.
        (   R#   R   R   R   R   R   RÈ   R   R   R   RM   t   get_cert_storeRe   R   R
   R/   Rf   R   R.   t   check_privatekeyt   add_certR0   R%   Rg   (   Ri   t   sockt
   server_ctxt   server_storeRo   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _server"  s    

c         C   s®   t  t ƒ } | j t t Bt Bƒ | j t t Bt	 Bt
 ƒ | j ƒ  } | j t t t ƒ ƒ | j t t t ƒ ƒ | j ƒ  | j t t t ƒ ƒ t | | ƒ } | j ƒ  | S(   sc   
        Create a new client-side SSL L{Connection} object wrapped around
        C{sock}.
        (   R#   R   R   R   R   R   RÈ   R   R   R   RM   RR  Re   R   R
   R-   Rf   R   R,   RS  RT  R0   R%   Rh   (   Ri   RU  t
   client_ctxt   client_storeRn   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _client8  s    

c         C   s¶  |  j  d ƒ } |  j d ƒ } |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j |  j | | ƒ d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j	 | j ƒ  | j ƒ  ƒ |  j	 | j ƒ  | j ƒ  ƒ |  j
 | j ƒ  | j ƒ  ƒ |  j
 | j ƒ  | j ƒ  ƒ t d ƒ } | j | ƒ |  j	 |  j | | ƒ | | f ƒ | j | d d d … ƒ |  j	 |  j | | ƒ | | d d d … f ƒ d S(   s  
        Two L{Connection}s which use memory BIOs can be manually connected by
        reading from the output of each and writing those bytes to the input of
        the other and in this way establish a connection and exchange
        application-level bytes with each other.
        s   One if by land, two if by sea.Niÿÿÿÿ(   RX  R…   R[  R~   t
   master_keyt   client_randomt   server_randomRt   t   assertNotIdenticalR“   t   assertNotEqualsR)   Rr   (   Ri   Ro   Rn   t   important_message(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_memoryConnectL  s.    c         C   s   |  j  ƒ  \ } } t d ƒ } | j | ƒ | j d ƒ } |  j | | ƒ | d d d … } | j | ƒ | j d ƒ } |  j | | ƒ d S(   s³  
        Just like L{test_memoryConnect} but with an actual socket.

        This is primarily to rule out the memory BIO code as the source of
        any problems encountered while passing data over a L{Connection} (if
        this test fails, there must be a problem outside the memory BIO
        code, as no memory BIO is involved here).  Even though this isn't a
        memory BIO test, it's convenient to have it here.
        s,   Help me Obi Wan Kenobi, you're my only hope.i   Niÿÿÿÿ(   Rk   R)   RY   RZ   Rµ   (   Ri   Ro   Rn   Ra  t   msg(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_socketConnectx  s    
c         C   sg   t  t ƒ } t ƒ  } t | | ƒ } |  j t | j d ƒ |  j t | j d ƒ |  j t | j ƒ d S(   s”   
        Test that L{OpenSSL.SSL.bio_read} and L{OpenSSL.SSL.bio_write} don't
        work on L{OpenSSL.SSL.Connection}() that use sockets.
        id   R   N(	   R#   R   R   R%   Ry   Rz   Rl   Rm   t   bio_shutdown(   Ri   R†   R]   RÁ   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_socketOverridesMemory  s    	c         C   sœ   |  j  d ƒ } |  j d ƒ } |  j | | ƒ d } | j d | ƒ } |  j | | k  ƒ |  j | | ƒ \ } } |  j | | ƒ |  j t | ƒ | ƒ d S(   s   
        If more bytes than can be written to the memory BIO are passed to
        L{Connection.send} at once, the number of bytes which were written is
        returned and that many bytes from the beginning of the input can be
        read from the other end of the connection.
        i   i   RO   Ni €  (	   RX  R…   R[  Rt   RY   R±   R~   R“   R²   (   Ri   R^   R]   t   sizet   sentt   receiverR?  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_outgoingOverflow  s    c         C   sH   |  j  d ƒ } | j ƒ  |  j t | j d ƒ } |  j | j t ƒ d S(   s{   
        L{Connection.bio_shutdown} signals the end of the data stream from
        which the L{Connection} reads.
        i   N(   RX  R…   Re  Ry   R   RZ   R“   t	   __class__(   Ri   R^   t   e(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR%  ¸  s    
c         C   sÎ   |  j  d ƒ } |  j d ƒ } |  j | j ƒ  g  ƒ |  j | j ƒ  g  ƒ | j ƒ  } | | ƒ } |  j | j ƒ  g  ƒ |  j | j ƒ  | ƒ |  j | | ƒ |  j | j ƒ  | ƒ |  j | j ƒ  | ƒ d S(   s  
        Verify the return value of the C{get_client_ca_list} method for server and client connections.

        @param func: A function which will be called with the server context
            before the client and server are connected to each other.  This
            function should specify a list of CAs for the server to send to the
            client and return that same list.  The list will be used to verify
            that C{get_client_ca_list} returns the proper value at various
            times.
        N(   RX  R…   R[  Rµ   t   get_client_ca_listR  Rt   (   Ri   t   funcR^   R]   Rj   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _check_client_ca_listÅ  s    c         C   sX   t  t ƒ } |  j t | j d ƒ |  j t | j d g ƒ |  j | j g  ƒ d ƒ d S(   s   
        L{Context.set_client_ca_list} raises a L{TypeError} if called with a
        non-list or a list that contains objects other than X509Names.
        t   spamN(   R#   R   Ry   Rz   t   set_client_ca_listR~   R…   (   Ri   Rj   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_client_ca_list_errorsÝ  s    c         C   s   d „  } |  j  | ƒ d S(   s  
        If passed an empty list, L{Context.set_client_ca_list} configures the
        context to send no CA names to the client and, on both the server and
        client sides, L{Connection.get_client_ca_list} returns an empty list
        after the connection is set up.
        c         S   s   |  j  g  ƒ g  S(   N(   Rq  (   Rj   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   no_caï  s    N(   Ro  (   Ri   Rs  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_empty_ca_listè  s    	c            s;   t  t t ƒ } | j ƒ  ‰  ‡  f d †  } |  j | ƒ d S(   sK  
        If passed a list containing a single X509Name,
        L{Context.set_client_ca_list} configures the context to send that CA
        name to the client and, on both the server and client sides,
        L{Connection.get_client_ca_list} returns a list containing that
        X509Name after the connection is set up.
        c            s   |  j  ˆ  g ƒ ˆ  g S(   N(   Rq  (   Rj   (   t   cadesc(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   single_caÿ  s    N(   R   R
   R0   RÊ   Ro  (   Ri   Rì   Rv  (    (   Ru  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_one_ca_listõ  s    c            sY   t  t t ƒ } t  t t ƒ } | j ƒ  ‰  | j ƒ  ‰ ‡ ‡  f d †  } |  j | ƒ d S(   sW  
        If passed a list containing multiple X509Name objects,
        L{Context.set_client_ca_list} configures the context to send those CA
        names to the client and, on both the server and client sides,
        L{Connection.get_client_ca_list} returns a list containing those
        X509Names after the connection is set up.
        c            s   ˆ ˆ  g } |  j  | ƒ | S(   N(   Rq  (   Rj   t   L(   t   cldesct   sedesc(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   multiple_ca  s    N(   R   R
   R.   RÊ   Ro  (   Ri   t   secertt   clcertR{  (    (   Rz  Ry  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_multiple_ca_list  s    c            sw   t  t t ƒ } t  t t ƒ } t  t t ƒ } | j ƒ  ‰  | j ƒ  ‰ | j ƒ  ‰ ‡ ‡ ‡  f d †  } |  j | ƒ d S(   s¿   
        If called multiple times, only the X509Names passed to the final call
        of L{Context.set_client_ca_list} are used to configure the CA names
        sent to the client.
        c            s*   |  j  ˆ ˆ  g ƒ |  j  ˆ g ƒ ˆ g S(   N(   Rq  (   Rj   (   Ry  Rz  Ru  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   changed_ca(  s    N(   R   R
   R0   R.   RÊ   Ro  (   Ri   Rì   R|  R}  R  (    (   Ru  Rz  Ry  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_reset_ca_list  s    c            sY   t  t t ƒ } t  t t ƒ } | j ƒ  ‰ | j ƒ  ‰  ‡  ‡ f d †  } |  j | ƒ d S(   sª   
        If the list passed to L{Context.set_client_ca_list} is mutated
        afterwards, this does not affect the list of CA names sent to the
        client.
        c            s-   ˆ g } |  j  ˆ g ƒ | j ˆ  ƒ ˆ g S(   N(   Rq  Rª   (   Rj   Rx  (   Rz  Ru  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   mutated_ca;  s    	N(   R   R
   R0   R.   RÊ   Ro  (   Ri   Rì   R|  R  (    (   Rz  Ru  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_mutated_ca_list/  s    c         C   sa   t  t ƒ } t t t ƒ } |  j t | j ƒ |  j t | j d ƒ |  j t | j | | ƒ d S(   s•   
        L{Context.add_client_ca} raises L{TypeError} if called with a non-X509
        object or with a number of arguments other than one.
        Rp  N(   R#   R   R   R
   R0   Ry   Rz   t   add_client_ca(   Ri   Rj   Rì   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_add_client_ca_errorsC  s
    c            s>   t  t t ƒ ‰ ˆ j ƒ  ‰  ‡ ‡  f d †  } |  j | ƒ d S(   s~   
        A certificate's subject can be added as a CA to be sent to the client
        with L{Context.add_client_ca}.
        c            s   |  j  ˆ  ƒ ˆ g S(   N(   Rƒ  (   Rj   (   Rì   Ru  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRv  V  s    N(   R   R
   R0   RÊ   Ro  (   Ri   Rv  (    (   Ru  Rì   s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_one_add_client_caO  s    c            s_   t  t t ƒ ‰ t  t t ƒ ‰ ˆ j ƒ  ‰ ˆ j ƒ  ‰  ‡ ‡ ‡ ‡  f d †  } |  j | ƒ d S(   s…   
        Multiple CA names can be sent to the client by calling
        L{Context.add_client_ca} with multiple X509 objects.
        c            s$   |  j  ˆ  ƒ |  j  ˆ ƒ ˆ ˆ g S(   N(   Rƒ  (   Rj   (   Rì   R|  Ru  Rz  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR{  g  s    N(   R   R
   R0   R.   RÊ   Ro  (   Ri   R{  (    (   Rz  R|  Ru  Rì   s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_multiple_add_client_ca\  s    c            sz   t  t t ƒ } t  t t ƒ } t  t t ƒ ‰  | j ƒ  ‰ | j ƒ  ‰ ˆ  j ƒ  ‰ ‡ ‡ ‡ ‡  f d †  } |  j | ƒ d S(   sÐ   
        A call to L{Context.set_client_ca_list} followed by a call to
        L{Context.add_client_ca} results in using the CA names from the first
        call and the CA name from the second call.
        c            s-   |  j  ˆ ˆ g ƒ |  j ˆ ƒ ˆ ˆ ˆ  g S(   N(   Rq  Rƒ  (   Rj   (   Ry  Rz  Ru  R}  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   mixed_set_add_ca|  s    N(   R   R
   R0   R.   RÊ   Ro  (   Ri   Rì   R|  R‡  (    (   R}  Ru  Rz  Ry  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_and_add_client_can  s    c            sn   t  t t ƒ } t  t t ƒ ‰ t  t t ƒ ‰  | j ƒ  ‰ ˆ j ƒ  ‰ ‡  ‡ ‡ ‡ f d †  } |  j | ƒ d S(   sÐ   
        A call to L{Context.set_client_ca_list} after a call to
        L{Context.add_client_ca} replaces the CA name specified by the former
        call with the names specified by the latter cal.
        c            s4   |  j  ˆ  ƒ |  j ˆ g ƒ |  j  ˆ ƒ ˆ ˆ g S(   N(   Rƒ  Rq  (   Rj   (   R}  R|  Ru  Rz  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   set_replaces_add_ca  s    N(   R   R
   R0   R.   RÊ   Ro  (   Ri   Rì   R‰  (    (   R}  R|  Ru  Rz  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_after_add_client_caƒ  s    (   Ru   Rv   Rw   RX  R[  Rb  Rd  Rf  Rj  R%  Ro  Rr  Rt  Rw  R~  R€  R‚  R„  R…  R†  Rˆ  RŠ  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRQ    s(   			,															t   InfoConstantTestsc           B   s   e  Z d  Z d „  Z RS(   sI   
    Tests for assorted constants exposed for use in info callbacks.
    c         C   sg   x` t  t t t t t t t t t	 t
 t t t t t t t t t g D] } |  j t | t ƒ ƒ qC Wd S(   s   
        All of the info constants are integers.

        This is a very weak test.  It would be nice to have one that actually
        verifies that as certain info events happen, the value passed to the
        info callback matches up with the constant exposed by OpenSSL.SSL.
        N(   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   R@   RA   RB   RC   RD   RE   RF   RG   R±   R³   R´   (   Ri   t   const(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_integersœ  s    			(   Ru   Rv   Rw   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR‹  ˜  s   t   __main__N(d   Rw   RÅ   R    R   R   t   sysR   R   R   t   osR   t   os.pathR   t   unittestR   t   OpenSSL.cryptoR	   R
   R   R   R   R   R   R   R   R   t   OpenSSL.SSLR   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   t   OpenSSL.test.utilR'   R(   R)   t   OpenSSL.test.test_cryptoR*   R+   R,   R-   R.   R/   R0   R1   t   ImportErrorR…   R2   R3   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   R@   RA   RB   RC   RD   RE   RF   RG   R  RM   R_   Rc   Rd   Rx   R  R+  R2  R:  RD  RJ  RM  RQ  R‹  Ru   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   <module>   sj   """


‚			Gÿ ÿ Žç+G5+ÿ {