
T6[c           @   s  d  Z  d d l m Z m Z d d l m Z m Z m Z m Z m	 Z	 d d l
 m Z m Z d d l 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 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# m$ Z$ m% Z% d d l m& Z& m' Z' d d l m( Z( m) Z) d d l m* Z* d d l+ m, Z, m- Z- m. Z. d d l+ m/ Z/ m0 Z0 m1 Z1 d d l+ m2 Z2 m3 Z3 d d l+ m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 d d l+ m: Z: m; Z; m< Z< d d l+ m= Z= m> Z> m? Z? m@ Z@ d d l+ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH d d l+ mI ZI mJ ZJ mK ZK mL ZL mM ZM d d l+ mN ZN mO ZO mP ZP mQ ZQ mR ZR mS ZS d d lT mU ZV d d lW mX ZX mY ZY mZ ZZ m[ Z[ d d l\ m] Z] m^ Z^ m_ Z_ m` Z` ma Za mb Zb mc Zc y d d l+ md Zd Wn ee k
 r9ef Zd n Xy d d l+ mg Zg Wn ee k
 rgef Zg n Xy d d l+ mh Zh Wn ee k
 ref Zh n Xy d d  l+ mi Zi Wn ee k
 ref Zi n Xy d d! l+ mj Zj Wn ee k
 ref Zj n Xy  d d" l+ mk Zk ml Zl mm Zm Wn ee k
 r3ef Zk Zl Zm n Xd d# l+ mn Zn mo Zo mp Zp mq Zq mr Zr ms Zs mt Zt mu Zu mv Zv mw Zw mx Zx my Zy mz Zz m{ Z{ m| Z| m} Z} m~ Z~ m Z m Z m Z d$ Z d%   Z d&   Z d'   Z d(   Z d)   Z d* f  d+     YZ d, eZ f d-     YZ d. eZ e f d/     YZ d0 eZ e f d1     YZ d2 eZ e f d3     YZ d4 eZ e f d5     YZ d6 eZ f d7     YZ d8 eZ e f d9     YZ d: eZ f d;     YZ d< eZ e f d=     YZ d>   Z d? eZ e f d@     YZ dA eZ e f dB     YZ dC eZ e f dD     YZ dE eZ f dF     YZ dG eZ f dH     YZ dI eZ e f dJ     YZ dK eZ f dL     YZ dM eZ f dN     YZ e dO k re   n  dP S(Q   s'   
Unit tests for :py:obj:`OpenSSL.SSL`.
i(   t   collectt   get_referrers(   t   ECONNREFUSEDt   EINPROGRESSt   EWOULDBLOCKt   EPIPEt	   ESHUTDOWN(   t   platformt   getfilesystemencoding(   t	   SHUT_RDWRt   errort   socket(   t   makedirs(   t   join(   t   main(   t   ref(   t   catch_warningst   simplefilter(   t   PY3t	   text_typet   u(   t   TYPE_RSAt   FILETYPE_PEM(   t   PKeyt   X509t   X509Extensiont	   X509Store(   t   dump_privatekeyt   load_privatekey(   t   dump_certificatet   load_certificate(   t   get_elliptic_curves(   t   OPENSSL_VERSION_NUMBERt   SSLEAY_VERSIONt   SSLEAY_CFLAGS(   t   SSLEAY_PLATFORMt
   SSLEAY_DIRt   SSLEAY_BUILT_ON(   t   SENT_SHUTDOWNt   RECEIVED_SHUTDOWN(   t   SSLv2_METHODt   SSLv3_METHODt   SSLv23_METHODt   TLSv1_METHODt   TLSv1_1_METHODt   TLSv1_2_METHOD(   t   OP_SINGLE_DH_USEt   OP_NO_SSLv2t   OP_NO_SSLv3(   t   VERIFY_PEERt   VERIFY_FAIL_IF_NO_PEER_CERTt   VERIFY_CLIENT_ONCEt   VERIFY_NONE(   t   SESS_CACHE_OFFt   SESS_CACHE_CLIENTt   SESS_CACHE_SERVERt   SESS_CACHE_BOTHt   SESS_CACHE_NO_AUTO_CLEARt   SESS_CACHE_NO_INTERNAL_LOOKUPt   SESS_CACHE_NO_INTERNAL_STOREt   SESS_CACHE_NO_INTERNAL(   t   Errort   SysCallErrort   WantReadErrort   WantWriteErrort   ZeroReturnError(   t   Contextt   ContextTypet   Sessiont
   Connectiont   ConnectionTypet   SSLeay_version(   t   lib(   t   WARNING_TYPE_EXPECTEDt	   NON_ASCIIt   TestCaset   b(   t   cleartextCertificatePEMt   cleartextPrivateKeyPEMt   client_cert_pemt   client_key_pemt   server_cert_pemt   server_key_pemt   root_cert_pem(   t   OP_NO_QUERY_MTU(   t   OP_COOKIE_EXCHANGE(   t   OP_NO_TICKET(   t   OP_NO_COMPRESSION(   t   MODE_RELEASE_BUFFERS(   t   OP_NO_TLSv1t   OP_NO_TLSv1_1t   OP_NO_TLSv1_2(   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   sj   t  |   t  |  k r% t |  |  St |  t  rM t |  | j t     St |  | j t     Sd S(   s   
    Join two path components of either ``bytes`` or ``unicode``.

    The return type is the same as the type of ``prefix``.
    N(   t   typeR   t
   isinstanceR   t   decodeR   t   encode(   t   prefixt   suffix(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   join_bytes_or_unicodec   s
    c         C   s   | S(   N(    (   t   connt   certt   errnumt   deptht   ok(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   verify_cbt   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(   R}   i    (   R   t   bindt   listent   setblockingt   Falset
   connect_ext   getsocknamet   Truet   acceptt   sendRL   t   recvt   AssertionError(   t   portt   clientt   server(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   socket_pairx   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   connsRw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   handshake   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   RL   R   R   t   generate_keyR   R   t   get_subjectt
   commonNamet
   set_issuert
   set_pubkeyt   set_notBeforet   set_notAftert   add_extensionst   set_serial_numbert   signR   (   t   caextt   cakeyt   cacertt   ikeyt   icertt   skeyt   scert(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _create_certificate_chain   sH    						"t   _LoopbackMixinc           B   sA   e  Z d  Z d   Z d   Z d d 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   | S(   N(   RE   RB   R+   t   set_connect_state(   t   selfR   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _loopbackClientFactory   s    
c         C   sU   t  t  } | j t t t   | j t t t   t	 | |  } | j
   | S(   N(   RB   R+   t   use_privatekeyR   R   RR   t   use_certificateR   RQ   RE   t   set_accept_state(   R   R   t   ctxR   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _loopbackServerFactory   s    
c         C   s   | d  k r |  j } n  | d  k r0 |  j } n  t   \ } } | |  } | |  } t | |  | j t  | j t  | | f S(   N(   t   NoneR   R   R   R   R   R   (   R   t   serverFactoryt   clientFactoryR   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   _loopback   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 :py:obj:`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 :py:obj:`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   (   R   R   R   R?   t   bio_readt	   bio_write(   R   t   client_connt   server_connt   wrotet   readt   writet   datat   dirty(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _interactInMemory   s"    		
	c         C   sa   | j    | j   x6 | | g D]( } y | j   Wq! t k
 rH q! Xq! W|  j | |  d S(   s   
        Perform the TLS handshake between two :py:class:`Connection` instances
        connected to each other via memory BIOs.
        N(   R   R   R   R?   R   (   R   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _handshakeInMemory,  s    

N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR      s   				/t   VersionTestsc           B   s    e  Z d  Z d   Z d   Z RS(   s   
    Tests for version information exposed by
    :py:obj:`OpenSSL.SSL.SSLeay_version` and
    :py:obj:`OpenSSL.SSL.OPENSSL_VERSION_NUMBER`.
    c         C   s   |  j  t t t   d S(   s   
        :py:obj:`OPENSSL_VERSION_NUMBER` is an integer with status in the low
        byte and the patch, fix, minor, and major versions in the
        nibbles above that.
        N(   t
   assertTrueRq   R    t   int(   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_OPENSSL_VERSION_NUMBERD  s    c         C   sl   i  } xI t  t t t t g D]2 } t |  } | | | <|  j t | t   q W|  j	 t
 |  d  d S(   s   
        :py:obj:`SSLeay_version` takes a version type indicator and returns
        one of a number of version strings based on that indicator.
        i   N(   R!   R"   R%   R#   R$   RG   R   Rq   t   bytest   assertEqualt   len(   R   t   versionst   tt   version(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_SSLeay_versionM  s    
(   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR   >  s   		t   ContextTestsc           B   sq  e  Z d  Z d   Z e s' d   Z n  d   Z d   Z d   Z d   Z	 d   Z
 d   Z e so d	   Z n  d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e s d   Z n  d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e s#d   Z n  d   Z e  dV k	 rVd   Z" e sVd   Z# qVn  d   Z$ d    Z% d!   Z& e sd"   Z' n  d#   Z( d$   Z) d%   Z* e sd&   Z+ n  d'   Z, d(   Z- d)   Z. d*   Z/ d+   Z0 d,   Z1 d-   Z2 d.   Z3 d/   Z4 d0   Z5 d1   Z6 d2   Z7 d3   Z8 d4   Z9 d5   Z: d6   Z; d7   Z< e= d8 k rXn	 d9   Z> d:   Z? d;   Z@ d<   ZA d=   ZB d>   ZC d?   ZD d@   ZE dA   ZF dB   ZG dC   ZH dD   ZI dE   ZJ dF   ZK e sdG   ZL n  dH   ZM dI   ZN dJ   ZO dK   ZP dL   ZQ dM   ZR dN   ZS dO   ZT dP   ZU dQ   ZV dR   ZW dS   ZX e sfdT   ZY n  dU   ZZ RS(W   s7   
    Unit tests for :py:obj:`OpenSSL.SSL.Context`.
    c         C   s   t  t t g } x | D] } t |  q Wt t t g } x6 | D]. } y t |  Wq@ t t f k
 rm q@ Xq@ W|  j	 t
 t d  |  j	 t t d  d S(   s   
        :py:obj:`Context` can be instantiated with one of :py:obj:`SSLv2_METHOD`,
        :py:obj:`SSLv3_METHOD`, :py:obj:`SSLv23_METHOD`, :py:obj:`TLSv1_METHOD`,
        :py:obj:`TLSv1_1_METHOD`, or :py:obj:`TLSv1_2_METHOD`.
        R}   i
   N(   R)   R*   R+   RB   R(   R,   R-   R=   t
   ValueErrort   assertRaisest	   TypeError(   R   t   methodst   metht   maybe(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_method`  s    c         C   s   t  t t   d S(   s   
            On Python 2 :py:class:`Context` accepts values of type
            :py:obj:`long` as well as :py:obj:`int`.
            N(   RB   t   longR+   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_method_longz  s    c         C   s'   |  j  t t  |  j t d t  d S(   s   
        :py:obj:`Context` and :py:obj:`ContextType` refer to the same type object and can be
        used to create instances of that type.
        RB   N(   t   assertIdenticalRB   RC   t   assertConsistentTypeR+   (   R   (    (    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(   sc   
        :py:obj:`Context.use_privatekey` takes an :py:obj:`OpenSSL.crypto.PKey` instance.
        i   R}   N(   R   R   R   RB   R+   R   R   R   (   R   t   keyR   (    (    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    d S(   s   
        :py:obj:`Context.use_privatekey_file` raises :py:obj:`OpenSSL.SSL.Error`
        when passed the name of a file which does not exist.
        N(   RB   R+   R   R=   t   use_privatekey_filet   mktemp(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    test_use_privatekey_file_missing  s    c         C   sp   t    } | j t d  t | d  & } | j t t |  j d   Wd QXt t	  } | j
 | |  d S(   s   
        Verify that calling ``Context.use_privatekey_file`` with the given
        arguments does not raise an exception.
        i   t   wtt   asciiN(   R   R   R   t   openR   R   R   Rr   RB   R+   R   (   R   t   pemfilet   filetypeR   t   pemR   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _use_privatekey_file_test  s    	c         C   s*   |  j  |  j   t j t    t  d S(   s   
        A private key can be specified from a file by passing a ``bytes``
        instance giving the file name to ``Context.use_privatekey_file``.
        N(   R   R   RJ   Rs   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_privatekey_file_bytes  s    c         C   s*   |  j  |  j   j t    t t  d S(   s   
        A private key can be specified from a file by passing a ``unicode``
        instance giving the file name to ``Context.use_privatekey_file``.
        N(   R   R   Rr   R   RJ   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    test_use_privatekey_file_unicode  s    c         C   s    |  j  |  j   t t   d S(   s   
            On Python 2 :py:obj:`Context.use_privatekey_file` accepts a
            filetype of type :py:obj:`long` as well as :py:obj:`int`.
            N(   R   R   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_privatekey_file_long  s    c         C   sU   t  t  } |  j t | j  |  j t | j d  |  j t | j t   d  d S(   s   
        :py:obj:`Context.use_certificate_wrong_args` raises :py:obj:`TypeError`
        when not passed exactly one :py:obj:`OpenSSL.crypto.X509` instance as an
        argument.
        s   hello, worldN(   RB   R+   R   R   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_certificate_wrong_args  s    c         C   s)   t  t  } |  j t | j t    d S(   s   
        :py:obj:`Context.use_certificate` raises :py:obj:`OpenSSL.SSL.Error`
        when passed a :py:obj:`OpenSSL.crypto.X509` instance which has not been
        initialized (ie, which does not actually have any certificate data).
        N(   RB   R+   R   R=   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt"   test_use_certificate_uninitialized  s    c         C   s&   t  t  } | j t t t   d S(   s   
        :py:obj:`Context.use_certificate` sets the certificate which will be
        used to identify connections created using the context.
        N(   RB   R+   R   R   R   RM   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_certificate  s    	c         C   s   t  t  } |  j t | j  |  j t | j d t    |  j t | j d t t    |  j t | j t   t  |  j t | j d t    d S(   s   
        :py:obj:`Context.use_certificate_file` raises :py:obj:`TypeError` if
        called with zero arguments or more than two arguments, or if the first
        argument is not a byte string or the second argumnent is not an integer.
        t   somefileN(   RB   R+   R   R   t   use_certificate_filet   objectR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt$   test_use_certificate_file_wrong_args  s    c         C   s,   t  t  } |  j t | j |  j    d S(   s   
        :py:obj:`Context.use_certificate_file` raises
        `:py:obj:`OpenSSL.SSL.Error` if passed the name of a file which does not
        exist.
        N(   RB   R+   R   R=   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt!   test_use_certificate_file_missing  s    c         C   sB   t  | d   } | j t  Wd QXt t  } | j |  d S(   s   
        Verify that calling ``Context.use_certificate_file`` with the given
        filename doesn't raise an exception.
        t   wbN(   R   R   RM   RB   R+   R   (   R   t   certificate_filet   pem_fileR   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _use_certificate_file_test  s    	c         C   s-   |  j    t j t    } |  j |  d S(   s   
        :py:obj:`Context.use_certificate_file` sets the certificate (given as a
        ``bytes`` filename) which will be used to identify connections created
        using the context.
        N(   R   RJ   Rs   R   R   (   R   t   filename(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_certificate_file_bytes  s    c         C   s-   |  j    j t    t } |  j |  d S(   s   
        :py:obj:`Context.use_certificate_file` sets the certificate (given as a
        ``bytes`` filename) which will be used to identify connections created
        using the context.
        N(   R   Rr   R   RJ   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt!   test_use_certificate_file_unicode(  s    c         C   sW   |  j    } t | d   } | j t  Wd QXt t  } | j | t t   d S(   s   
            On Python 2 :py:obj:`Context.use_certificate_file` accepts a
            filetype of type :py:obj:`long` as well as :py:obj:`int`.
            R   N(	   R   R   R   RM   RB   R+   R   R   R   (   R   t   pem_filenameR   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_use_certificate_file_long3  s
    c         C   s^   t  t t  } t t t  } t t  } | j |  | j |  |  j	 d | j    d S(   s   
        :py:obj:`Context.check_privatekey` returns :py:obj:`None` if the
        :py:obj:`Context` instance has been configured to use a matched key and
        certificate pair.
        N(   R   R   RP   R   RO   RB   R+   R   R   t   assertIsR   t   check_privatekey(   R   R   Rx   t   context(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_check_privatekey_valid@  s    c         C   s[   t  t t  } t t t  } t t  } | j |  | j |  |  j	 t
 | j  d S(   s   
        :py:obj:`Context.check_privatekey` raises :py:obj:`Error` if the
        :py:obj:`Context` instance has been configured to use a key and
        certificate pair which don't relate to each other.
        N(   R   R   RP   R   RQ   RB   R+   R   R   R   R=   R   (   R   R   Rx   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_check_privatekey_invalidN  s    c         C   s)   t  t  } |  j t | j t    d S(   s   
        :py:obj:`Context.check_privatekey` raises :py:obj:`TypeError` if called
        with other than no arguments.
        N(   RB   R+   R   R   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    test_check_privatekey_wrong_args\  s    c         C   s<   t  t  } |  j t | j  |  j t | j d d  d S(   s{   
        :py:obj:`Context.set_app_data` raises :py:obj:`TypeError` if called with other than
        one argument.
        N(   RB   R+   R   R   t   set_app_dataR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_app_data_wrong_argse  s    c         C   s&   t  t  } |  j t | j d  d S(   sq   
        :py:obj:`Context.get_app_data` raises :py:obj:`TypeError` if called with any
        arguments.
        N(   RB   R+   R   R   t   get_app_dataR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_app_data_wrong_argso  s    c         C   s<   t    } t t  } | j |  |  j | j   |  d S(   s   
        :py:obj:`Context.set_app_data` stores an object for later retrieval using
        :py:obj:`Context.get_app_data`.
        N(   R   RB   R+   R  R   R  (   R   t   app_dataR   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_app_datax  s    	c         C   sR   t  t  } |  j t | j  |  j t | j d  |  j t | j d d  d S(   s   
        :py:obj:`Context.set_options` raises :py:obj:`TypeError` if called with the wrong
        number of arguments or a non-:py:obj:`int` argument.
        i   N(   RB   R+   R   R   t   set_optionsR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_options_wrong_args  s    c         C   s0   t  t  } | j t  } |  j t | @ d S(   sN   
        :py:obj:`Context.set_options` returns the new options value.
        N(   RB   R+   R  R/   R   (   R   R   t   options(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_options  s    c         C   s6   t  t  } | j t t   } |  j t | @ d S(   s   
            On Python 2 :py:obj:`Context.set_options` accepts values of type
            :py:obj:`long` as well as :py:obj:`int`.
            N(   RB   R+   R  R   R/   R   (   R   R   R
  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_options_long  s    c         C   sR   t  t  } |  j t | j  |  j t | j d  |  j t | j d d  d S(   s   
        :py:obj:`Context.set`mode} raises :py:obj:`TypeError` if called with the wrong
        number of arguments or a non-:py:obj:`int` argument.
        i   N(   RB   R+   R   R   t   set_modeR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_mode_wrong_args  s    c         C   s*   t  t  } |  j t | j t  @ d S(   sy   
            :py:obj:`Context.set_mode` accepts a mode bitvector and returns the newly
            set mode.
            N(   RB   R+   R   RX   R  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_mode  s    c         C   s6   t  t  } | j t t   } |  j t | @ d S(   s   
                On Python 2 :py:obj:`Context.set_mode` accepts values of type
                :py:obj:`long` as well as :py:obj:`int`.
                N(   RB   R+   R  R   RX   R   (   R   R   t   mode(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_mode_long  s    c         C   sR   t  t  } |  j t | j  |  j t | j d  |  j t | j d d  d S(   s   
        :py:obj:`Context.set_timeout` raises :py:obj:`TypeError` if called with the wrong
        number of arguments or a non-:py:obj:`int` argument.
        i   N(   RB   R+   R   R   t   set_timeoutR   (   R   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(   sh   
        :py:obj:`Context.get_timeout` raises :py:obj:`TypeError` if called with any arguments.
        N(   RB   R+   R   R   t   get_timeoutR   (   R   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   
        :py:obj:`Context.set_timeout` sets the session timeout for all connections
        created using the context object.  :py:obj:`Context.get_timeout` retrieves this
        value.
        i  N(   RB   R+   R  t   assertEqualsR  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_timeout  s    c         C   s9   t  t  } | j t d   |  j | j   d  d S(   s}   
            On Python 2 :py:obj:`Context.set_timeout` accepts values of type
            `long` as well as int.
            i  N(   RB   R+   R  R   R  R  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_timeout_long  s    c         C   sR   t  t  } |  j t | j  |  j t | j d  |  j t | j d d  d S(   s   
        :py:obj:`Context.set_verify_depth` raises :py:obj:`TypeError` if called with the wrong
        number of arguments or a non-:py:obj:`int` argument.
        i   N(   RB   R+   R   R   t   set_verify_depthR   (   R   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(   sm   
        :py:obj:`Context.get_verify_depth` raises :py:obj:`TypeError` if called with any arguments.
        N(   RB   R+   R   R   t   get_verify_depthR   (   R   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   
        :py:obj:`Context.set_verify_depth` sets the number of certificates in a chain
        to follow before giving up.  The value can be retrieved with
        :py:obj:`Context.get_verify_depth`.
        i   N(   RB   R+   R  R  R  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_verify_depth   s    c         C   s9   t  t  } | j t d   |  j | j   d  d S(   s   
            On Python 2 :py:obj:`Context.set_verify_depth` accepts values of
            type `long` as well as int.
            i   N(   RB   R+   R  R   R  R  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_verify_depth_long  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   blowfishR   (
   R   R   R   R   R   R   R   R   Rr   t   close(   R   t
   passphraseR   t   pemFilet   fObjR   (    (    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   
        :py:obj:`Context.set_passwd_cb` raises :py:obj:`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>-  s    N(   RB   R+   R   R   t   set_passwd_cbR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_passwd_cb_wrong_args%  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   
        :py:obj:`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   passphraseCallback8  s    i   i    i   N(   RL   R%  RB   R+   R'  R   R   R   Rq   R   R   R   (   R   R#  R/  R   (    (   R.  R"  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_passwd_cb0  s    c         C   sQ   |  j  t d   } d   } t t  } | j |  |  j t | j |  d S(   s{   
        :py:obj:`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/  J  s    N(   R%  RL   RB   R+   R'  R   R1  R   (   R   R#  R/  R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_exceptionD  s
    	c         C   sQ   |  j  t d   } d   } t t  } | j |  |  j t | j |  d S(   s   
        :py:obj:`Context.use_privatekey_file` raises :py:obj:`OpenSSL.SSL.Error` if the
        passphrase callback returns a false value.
        s   monkeys are nicec         S   s   d S(   NR}   (    (   R+  R,  R-  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR/  X  s    N(   R%  RL   RB   R+   R'  R   R=   R   (   R   R#  R/  R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_falseR  s
    	c         C   sQ   |  j  t d   } d   } t t  } | j |  |  j t | j |  d S(   s   
        :py:obj:`Context.use_privatekey_file` raises :py:obj:`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/  f  s    N(   R%  RL   RB   R+   R'  R   R   R   (   R   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.
        R~   i   c            s    |  d k s t     t d  S(   Ni   R   (   R   RL   (   R+  R,  R-  (   R"  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR/  v  s    N(   RL   R%  RB   R+   R'  R   (   R   R#  R/  R   (    (   R"  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_passwd_callback_too_longn  s    c            s   t    \ } } t t t  |  } | j   g      f d   } t t  } | j |  | j t t t	   | j
 t t t   t | |  } | j   t | |  g    D]$ \ } } }	 t | t  s | ^ q }
 |  j g  |
 d  d S(   s   
        :py:obj:`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*  (   Rw   t   wheret   ret(   t   called(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   info  s    s:   Some info callback arguments were not Connection instaces.N(   R   RE   RB   R+   R   t   set_info_callbackR   R   R   RM   R   R   RN   R   R   Rq   R   (   R   R   R   t	   clientSSLR9  R   t	   serverSSLRw   R6  R7  t   notConnections(    (   R8  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 :py:obj:`load_verify_locations` method with the given arguments.
        Then connect it to a server and ensure that the handshake succeeds.
        c         S   s   | S(   N(    (   Rw   Rx   t   errnoRz   t   preverify_ok(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR&    s    s   Testing Root CAN(   R   RB   R+   t   load_verify_locationst
   set_verifyR1   RE   R   R   R   R   RM   R   R   RN   R   R   t   get_peer_certificateR   R   t   CN(	   R   t   argsR   R   t   clientContextR;  t   serverContextR<  Rx   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _load_verify_locations_test  s$    


c         C   s@   t  | d  } | j t j d   | j   |  j |  d S(   s   
        Verify that if path to a file containing a certificate is passed to
        ``Context.load_verify_locations`` for the ``cafile`` parameter, that
        certificate is used as a trust root for the purposes of verifying
        connections created using that ``Context``.
        R  R   N(   R   R   RM   Rr   R!  RH  (   R   t   cafileR$  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _load_verify_cafile  s    
c         C   s-   |  j    t j t    } |  j |  d S(   s   
        :py:obj:`Context.load_verify_locations` accepts a file name as a
        ``bytes`` instance and uses the certificates within for verification
        purposes.
        N(   R   RJ   Rs   R   RJ  (   R   RI  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_verify_bytes_cafile  s    c         C   s'   |  j  |  j   j t    t  d S(   s   
        :py:obj:`Context.load_verify_locations` accepts a file name as a
        ``unicode`` instance and uses the certificates within for verification
        purposes.
        N(   RJ  R   Rr   R   RJ   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_verify_unicode_cafile  s    c         C   s,   t  t  } |  j t | j |  j    d S(   s{   
        :py:obj:`Context.load_verify_locations` raises :py:obj:`Error` when passed a
        non-existent cafile.
        N(   RB   R+   R   R=   RA  R   (   R   RF  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_verify_invalid_file  s    c         C   sr   t  |  xQ d d g D]C } t | |  } t | d   } | j t j d   Wd QXq W|  j d |  d S(   s+  
        Verify that if path to a directory containing certificate files is
        passed to ``Context.load_verify_locations`` for the ``capath``
        parameter, those certificates are used as trust roots for the purposes
        of verifying connections created using that ``Context``.
        s
   c7adac82.0s
   c3705638.0R  R   N(   R   Rv   R   R   RM   Rr   RH  R   (   R   t   capatht   nameRI  R$  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt'   _load_verify_directory_locations_capath  s    
 c         C   s'   |  j  |  j   t j t     d S(   s   
        :py:obj:`Context.load_verify_locations` accepts a directory name as a
        ``bytes`` instance and uses the certificates within for verification
        purposes.
        N(   RP  R   RJ   Rs   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt'   test_load_verify_directory_bytes_capath  s    c         C   s'   |  j  |  j   j t    t  d S(   s   
        :py:obj:`Context.load_verify_locations` accepts a directory name as a
        ``unicode`` instance and uses the certificates within for verification
        purposes.
        N(   RP  R   Rr   R   RJ   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt)   test_load_verify_directory_unicode_capath  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   
        :py:obj:`Context.load_verify_locations` raises :py:obj:`TypeError` if called with
        the wrong number of arguments or with non-:py:obj:`str` arguments.
        N(   RB   R+   R   R   RA  R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt%   test_load_verify_locations_wrong_args#  s
    t   win32c         C   s   d S(   s   
            :py:obj:`Context.set_default_verify_paths` causes the platform-specific CA
            certificate locations to be used for verification purposes.
            N(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_default_verify_paths3  s    c         C   sR   t  t  } |  j t | j d  |  j t | j d  |  j t | j d  d S(   s   
        :py:obj:`Context.set_default_verify_paths` takes no arguments and raises
        :py:obj:`TypeError` if given any.
        i   R}   N(   RB   R+   R   R   t   set_default_verify_pathsR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt'   test_set_default_verify_paths_signatureQ  s    c         C   s[   t  t  } |  j t | j  |  j t | j t    |  j t | j t   t    d S(   s   
        :py:obj:`Context.add_extra_chain_cert` raises :py:obj:`TypeError` if called with
        other than one argument or if called with an object which is not an
        instance of :py:obj:`X509`.
        N(   RB   R+   R   R   t   add_extra_chain_certR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt&   test_add_extra_chain_cert_invalid_cert\  s    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   RE   R   R   t   rangeR   R?   (	   R   RG  RF  t   serverSockett   clientSocketR   R   t   it   s(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _handshake_testh  s    

c         C   s   t  t  } | j t t t   | j t t t   t	 | d  } d t f d     Y} |   } t  t  } | j t | j  t	 | d  } | j   |  j | |  |  j | j |  d S(   s   
        The first argument passed to the verify callback is the
        :py:class:`Connection` instance for which verification is taking place.
        t   VerifyCallbackc           B   s   e  Z d    Z RS(   c         W   s   | |  _  d S(   Ni   (   t
   connection(   R   Ra  RE  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   callback  s    	(   R   R   Rb  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR`    s   N(   RB   R+   R   R   R   RN   R   R   RM   RE   R   R   RB  R1   Rb  R   R   R   Ra  (   R   RG  t   serverConnectionR`  R,  RF  t   clientConnection(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt,   test_set_verify_callback_connection_argument  s    	
c         C   s   t  t  } | j t t t   | j t t t   t	 | d  } d   } t  t  } | j t |  t	 | d  } | j   |  j | |  d S(   s  
        We had a bug where the X509 cert instantiated in the callback wrapper
        didn't __init__ so it was missing objects needed when calling
        get_subject. This test sets up a handshake where we call get_subject
        on the cert provided to the verify callback.
        c         S   s   | j    s t  d S(   Ni   (   R   R   (   Rw   Rx   Ry   Rz   R{   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   verify_cb_get_subject  s    N(   RB   R+   R   R   R   RN   R   R   RM   RE   R   RB  R1   R   R   (   R   RG  Rc  Rf  RF  Rd  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_x509_in_verify_works  s    	
c         C   s   t  t  } | j t t t   | j t t t   t  t  } d   } | j	 t
 |  |  j t |  j | |  } |  j d t |   d S(   s   
        If the verify callback passed to :py:obj:`Context.set_verify` raises an
        exception, verification fails and the exception is propagated to the
        caller of :py:obj:`Connection.do_handshake`.
        c          W   s   t  d   d  S(   Ns   silly verify failure(   t	   Exception(   RE  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   verify_callback  s    s   silly verify failureN(   RB   R+   R   R   R   RN   R   R   RM   RB  R1   R   Rh  R_  R   t   str(   R   RG  RF  Ri  t   exc(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt"   test_set_verify_callback_exception  s    	c         C   sr  t    } | \ \ } } \ } } \ } } xg | d f | d f | d f g D]D \ } }	 t |	 d  }
 |
 j t t |  j d   |
 j   qL 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  
        :py:obj:`Context.add_extra_chain_cert` accepts an :py:obj:`X509` instance to add to
        the certificate chain.

        See :py:obj:`_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   R   R   R   Rr   R!  R   RB   R+   R   R   RX  RB  R1   R2   R|   RA  R_  (   R   t   chainR   R   R   R   R   R   Rx   RO  R$  R   RG  RF  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_add_extra_chain_cert  s&    	!..c      	   C   sJ  t    } | \ \ } } \ } } \ } } t |  t | d  }	 t | d  }
 t |	 d  I } | j t t |   | j t t |   | j t t |   Wd QXt |
 d  & } | j t t |  j d   Wd QXt t	  } | j
 |	  | j |  t t	  } | j t t Bt  | j |
  |  j | |  d S(   s-  
        Verify that :py:obj:`Context.use_certificate_chain_file` reads a
        certificate chain from a 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.
        s	   chain.pems   ca.pemR   NR  R   (   R   R   Rv   R   R   R   R   Rr   RB   R+   t   use_certificate_chain_fileR   RB  R1   R2   R|   RA  R_  (   R   t   certdirRm  R   R   R   R   R   R   t	   chainFilet   caFileR$  RG  RF  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    _use_certificate_chain_file_test  s&    		!
%c         C   s'   |  j  |  j   t j t     d S(   s   
        ``Context.use_certificate_chain_file`` accepts the name of a file (as
        an instance of ``bytes``) to specify additional certificates to use to
        construct and verify a trust chain.
        N(   Rs  R   RJ   Rs   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt%   test_use_certificate_chain_file_bytes  s    c         C   s'   |  j  |  j   j t    t  d S(   s   
        ``Context.use_certificate_chain_file`` accepts the name of a file (as
        an instance of ``unicode``) to specify additional certificates to use
        to construct and verify a trust chain.
        N(   Rs  R   Rr   R   RJ   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt'   test_use_certificate_chain_file_unicode(  s    c         C   st   t  t  } |  j t | j  |  j t | j t    |  j t | j d t    |  j t | j |  j    d S(   sZ  
        :py:obj:`Context.use_certificate_chain_file` raises :py:obj:`TypeError`
        if passed zero or more than one argument or when passed a non-byte
        string single argument.  It also raises :py:obj:`OpenSSL.SSL.Error` when
        passed a bad chain file name (for example, the name of a file which does
        not exist).
        t   fooN(   RB   R+   R   R   Ro  R   R=   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt*   test_use_certificate_chain_file_wrong_args3  s
    c         C   s&   t  t  } |  j t | j d  d S(   st   
        :py:obj:`Context.get_verify_mode` raises :py:obj:`TypeError` if called with any
        arguments.
        N(   RB   R+   R   R   t   get_verify_modeR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_verify_mode_wrong_argsE  s    c         C   sW   t  t  } |  j | j   d  | j t t Bd    |  j | j   t t B d S(   s   
        :py:obj:`Context.get_verify_mode` returns the verify mode flags previously
        passed to :py:obj:`Context.set_verify`.
        i    c          W   s   d  S(   N(   R   (   RE  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR&  V  s    N(   RB   R+   R  Rx  RB  R1   R3   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_verify_modeN  s    c         C   s]   t  t  } |  j | j   d  | j t t t B d    |  j | j   t t B d S(   s   
            On Python 2 :py:obj:`Context.set_verify_mode` accepts values of
            type :py:obj:`long` as well as :py:obj:`int`.
            i    c          W   s   d  S(   N(   R   (   RE  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR&  d  s    N(   RB   R+   R  Rx  RB  R   R1   R3   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_verify_mode_long\  s    c         C   sU   t  t  } |  j t | j  |  j t | j d d  |  j t | j t    d S(   s   
        :py:obj:`Context.load_tmp_dh` raises :py:obj:`TypeError` if called with the wrong
        number of arguments or with a non-:py:obj:`str` argument.
        Rv  N(   RB   R+   R   R   t   load_tmp_dhR   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh_wrong_argsi  s    c         C   s&   t  t  } |  j t | j d  d S(   s   
        :py:obj:`Context.load_tmp_dh` raises :py:obj:`OpenSSL.SSL.Error` if the specified file
        does not exist.
        t   helloN(   RB   R+   R   R=   R|  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh_missing_filet  s    c         C   sB   t  t  } t | d   } | j t  Wd QX| j |  d S(   sz   
        Verify that calling ``Context.load_tmp_dh`` with the given filename
        does not raise an exception.
        R  N(   RB   R+   R   R   t   dhparamR|  (   R   t
   dhfilenameR   t   dhfile(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _load_tmp_dh_test}  s    c         C   s'   |  j  |  j   t j t     d S(   s   
        :py:obj:`Context.load_tmp_dh` loads Diffie-Hellman parameters from the
        specified file (given as ``bytes``).
        N(   R  R   RJ   Rs   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh_bytes  s    c         C   s'   |  j  |  j   j t    t  d S(   s   
        :py:obj:`Context.load_tmp_dh` loads Diffie-Hellman parameters from the
        specified file (given as ``unicode``).
        N(   R  R   Rr   R   RJ   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_load_tmp_dh_unicode  s    c         C   s1   t  t  } x t   D] } | j |  q Wd S(   s{   
        :py:obj:`Context.set_tmp_ecdh` sets the elliptic curve for
        Diffie-Hellman to the specified curve.
        N(   RB   R+   R   t   set_tmp_ecdh(   R   R   t   curve(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_tmp_ecdh  s    c         C   sE   t  t  } | j d  t | d  } |  j | j   d g  d S(   s   
        :py:obj:`Context.set_cipher_list` accepts a :py:obj:`bytes` 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(   RB   R+   t   set_cipher_listRE   R   R  t   get_cipher_list(   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_cipher_list_bytes  s    c         C   sK   t  t  } | j t d   t | d  } |  j | j   d g  d S(   s   
        :py:obj:`Context.set_cipher_list` accepts a :py:obj:`unicode` 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(   RB   R+   R  R   RE   R   R  R  (   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_cipher_list_text  s    c         C   sn   t  t  } |  j t | j  |  j t | j t    |  j t | j d t    |  j t | j d  d S(   s  
        :py:obj:`Context.set_cipher_list` raises :py:obj:`TypeError` when
        passed zero arguments or more than one argument or when passed a
        non-string single argument and raises :py:obj:`OpenSSL.SSL.Error` when
        passed an incorrect cipher list string.
        s   EXP-RC4-MD5s   imaginary-cipherN(   RB   R+   R   R   R  R   R=   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_cipher_list_wrong_args  s
    c         C   s<   t  t  } |  j t | j  |  j t | j t    d S(   s   
        :py:obj:`Context.set_session_cache_mode` raises :py:obj:`TypeError` if
        called with other than one integer argument.
        N(   RB   R+   R   R   t   set_session_cache_modeR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt&   test_set_session_cache_mode_wrong_args  s    c         C   s&   t  t  } |  j t | j d  d S(   s{   
        :py:obj:`Context.get_session_cache_mode` raises :py:obj:`TypeError` if
        called with any arguments.
        i   N(   RB   R+   R   R   t   get_session_cache_mode(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt&   test_get_session_cache_mode_wrong_args  s    c         C   sR   t  t  } | j t  | j t  } |  j t |  |  j t | j    d S(   s   
        :py:obj:`Context.set_session_cache_mode` specifies how sessions are
        cached.  The setting can be retrieved via
        :py:obj:`Context.get_session_cache_mode`.
        N(   RB   R+   R  R5   R8   R   R  (   R   R   t   off(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_session_cache_mode  s
    c         C   s9   t  t  } | j t t   |  j t | j    d S(   s   
            On Python 2 :py:obj:`Context.set_session_cache_mode` accepts values
            of type :py:obj:`long` as well as :py:obj:`int`.
            N(   RB   R+   R  R   R8   R   R  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_session_cache_mode_long  s    c         C   s,   t  t  } | j   } |  j | t  d S(   sZ   
        :py:obj:`Context.get_cert_store` returns a :py:obj:`X509Store` instance.
        N(   RB   R+   t   get_cert_storet   assertIsInstanceR   (   R   R   t   store(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_cert_store  s    N([   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  RX   R   R  R  R  R  R  R  R  R  R  R  R%  R(  R0  R2  R3  R4  R5  R>  RH  RJ  RK  RL  RM  RP  RQ  RR  RS  R   RU  RW  RY  R_  Re  Rg  Rl  Rn  Rs  Rt  Ru  Rw  Ry  Rz  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   ServerNameCallbackTestsc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sw   
    Tests for :py:obj:`Context.set_tlsext_servername_callback` and its interaction with
    :py:obj:`Connection`.
    c         C   s<   t  t  } |  j t | j  |  j t | j d d  d S(   s   
        :py:obj:`Context.set_tlsext_servername_callback` raises :py:obj:`TypeError` if called
        with other than one argument.
        i   i   N(   RB   R+   R   R   t   set_tlsext_servername_callback(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_wrong_args  s    c         C   s   d   } d   } t  t  } | j |  t |  } ~ | j |  t   t   |   } | d k	 r t |  } t |  d k r |  j d | f  q n  d S(   s   
        If :py:obj:`Context.set_tlsext_servername_callback` is used to specify a new
        callback, the one it replaces is dereferenced.
        c         S   s   d  S(   N(    (   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRb    s    c         S   s   d  S(   N(    (   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   replacement  s    i   s   Some references remain: %rN(	   RB   R+   R  R   R    R   R   R   t   fail(   R   Rb  R  R   t   trackert	   referrers(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_old_callback_forgotten  s    			c            s   g      f d   } t  t  } | j |  ~ t   | j t t t   | j t	 t t
   t | d  } | j   t t  t  d  } | j   |  j | |  |  j | d f g    d S(   s   
        When a client specifies no server name, the callback passed to
        :py:obj:`Context.set_tlsext_servername_callback` is invoked and the result of
        :py:obj:`Connection.get_servername` is :py:obj:`None`.
        c            s     j  |  |  j   f  d  S(   N(   R*  t   get_servername(   Rw   (   RE  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   servername>  s    N(   RB   R+   R  R    R   R   R   RR   R   R   RQ   RE   R   R   R   R   R   (   R   R  R   R   R   (    (   RE  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_no_servername7  s    

c            s   g      f d   } t  t  } | j |  | j t t t   | j t t t	   t
 | d  } | j   t
 t  t  d  } | j   | j t d   |  j | |  |  j | t d  f g    d S(   s   
        When a client specifies a server name in its hello message, the callback
        passed to :py:obj:`Contexts.set_tlsext_servername_callback` is invoked and the
        result of :py:obj:`Connection.get_servername` is that server name.
        c            s     j  |  |  j   f  d  S(   N(   R*  R  (   Rw   (   RE  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  _  s    s   foo1.example.comN(   RB   R+   R  R   R   R   RR   R   R   RQ   RE   R   R   R   t   set_tlsext_host_nameRL   R   R   (   R   R  R   R   R   (    (   RE  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_servernameX  s    

(   R   R   R   R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s
   		!	!t   NextProtoNegotiationTestsc           B   sG   e  Z d  Z e j r< d   Z d   Z d   Z d   Z n	 d   Z	 RS(   s:   
    Test for Next Protocol Negotiation in PyOpenSSL.
    c            s/  g    g     f d   }  f d   } t  t  } | j |  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j | |  |  j | f g    |  j | d d g f g   |  j | j   d  |  j | j   d  d S(   s   
            Tests that clients and servers that agree on the negotiated next
            protocol can correct establish a connection, and that the agreed
            protocol is reported by the connections.
            c            s     j  |  f  d d g S(   Ns   http/1.1s   spdy/2(   R*  (   Rw   (   t   advertise_args(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   advertise  s    c            s     j  |  | f  d S(   Ns   spdy/2(   R*  (   Rw   R
  (   t   select_args(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   select  s    s   http/1.1s   spdy/2N(   RB   R+   t   set_npn_advertise_callbackt   set_npn_select_callbackR   R   R   RR   R   R   RQ   RE   R   R   R   R   R   t   get_next_proto_negotiated(   R   R  R  t   server_contextt   client_contextR   R   (    (   R  R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_npn_successz  s*    

c            s  g    g     f d   }  f d   } t  t  } | j |  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j t |  j | |  |  j | f g    |  j | d d g f g   d S(   s   
            Tests that when clients and servers cannot agree on what protocol
            to use next that the TLS connection does not get established.
            c            s     j  |  f  d d g S(   Ns   http/1.1s   spdy/2(   R*  (   Rw   (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    c            s     j  |  | f  d S(   NR}   (   R*  (   Rw   R
  (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    s   http/1.1s   spdy/2N(   RB   R+   R  R  R   R   R   RR   R   R   RQ   RE   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.pyt   test_npn_client_fail  s&    

c            s   g      f d   } d   } t  t  } | j |  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j t |  j | |  |  j | f g    d S(   s   
            Test that we can handle exceptions in the select callback. If
            select fails it should be fatal to the connection.
            c            s     j  |  f  d d g S(   Ns   http/1.1s   spdy/2(   R*  (   Rw   (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    c         S   s
   t   d  S(   N(   R   (   Rw   R
  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    N(   RB   R+   R  R  R   R   R   RR   R   R   RQ   RE   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.pyt   test_npn_select_error  s$    	

c            s   g    d   }   f d   } t  t  } | j |  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j t |  j | |  |  j g     d S(   s   
            Test that we can handle exceptions in the advertise callback. If
            advertise fails no NPN is advertised to the client.
            c         S   s
   t   d  S(   N(   R   (   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    c            s     j  |  | f  d S(   NR}   (   R*  (   Rw   R
  (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    N(   RB   R+   R  R  R   R   R   RR   R   R   RQ   RE   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.pyt   test_npn_advertise_error  s$    	

c         C   s   t  t  } | j | j g } x! | D] } |  j t | d   q% Wt |  } | j g } x | D] } |  j t |  qa Wd  S(   N(	   RB   R+   R  R  R   t   NotImplementedErrorR   RE   R  (   R   R   t   fail_methodst   methodRw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_npn_not_implemented  s    (
   R   R   R   t   _libt   Cryptography_HAS_NEXTPROTONEGR  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  u  s   		+	(	&'t%   ApplicationLayerProtoNegotiationTestsc           B   sP   e  Z d  Z e j rE d   Z d   Z d   Z d   Z d   Z	 n	 d   Z
 RS(   s&   
    Tests for ALPN in PyOpenSSL.
    c            s
  g      f d   } t  t  } | j d d g  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j | |  |  j | d d g f g    |  j | j   d  |  j | j   d  d S(   s   
            Clients and servers that agree on the negotiated ALPN protocol can
            correct establish a connection, and the agreed protocol is reported
            by the connections.
            c            s     j  |  | f  d S(   Ns   spdy/2(   R*  (   Rw   R
  (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  >  s    s   http/1.1s   spdy/2N(   RB   R+   t   set_alpn_protost   set_alpn_select_callbackR   R   R   RR   R   R   RQ   RE   R   R   R   R   R   t   get_alpn_proto_negotiated(   R   R  R  R  R   R   (    (   R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_alpn_success7  s$    

c            s
  g      f d   } t  t  } t  t  } | j |  | j t t t   | j t t t	   t
 | d  } | j   t
 | d  } | j d d g  | j   |  j | |  |  j | d d g f g    |  j | j   d  |  j | j   d  d S(   s   
            The same as test_alpn_success, but setting the ALPN protocols on
            the connection rather than the context.
            c            s     j  |  | f  d S(   Ns   spdy/2(   R*  (   Rw   R
  (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  c  s    s   http/1.1s   spdy/2N(   RB   R+   R  R   R   R   RR   R   R   RQ   RE   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.pyt   test_alpn_set_on_connection]  s$    

c            s   g      f d   } t  t  } | j d d g  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j t |  j | |  |  j | d d g f g    d S(   s   
            When clients and servers cannot agree on what protocol to use next
            the TLS connection does not get established.
            c            s     j  |  | f  d S(   NR}   (   R*  (   Rw   R
  (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    s   http/1.1s   spdy/2N(   RB   R+   R  R  R   R   R   RR   R   R   RQ   RE   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.pyt   test_alpn_server_fail  s     

c         C   s   t  t  } | j d d g  t  t  } | j t t t   | j t t t	   t
 | d  } | j   t
 | d  } | j   |  j | |  |  j | j   d  d S(   s   
            When clients and servers cannot agree on what protocol to use next
            because the server doesn't offer ALPN, no protocol is negotiated.
            s   http/1.1s   spdy/2R}   N(   RB   R+   R  R   R   R   RR   R   R   RQ   RE   R   R   R   R   R   R  (   R   R  R  R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_alpn_no_server  s    

c            s   g      f d   } t  t  } | j d d g  t  t  } | j |  | j t t t   | j t	 t t
   t | d  } | j   t | d  } | j   |  j t |  j | |  |  j | d d g f g    d S(   sO   
            We can handle exceptions in the ALPN select callback.
            c            s      j  |  | f  t    d  S(   N(   R*  R   (   Rw   R
  (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    s   http/1.1s   spdy/2N(   RB   R+   R  R  R   R   R   RR   R   R   RQ   RE   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.pyt   test_alpn_callback_exception  s"    

c         C   s^   t  t  } |  j t | j d  |  j t | j d  t |  } |  j t | j d  d S(   sY   
            If ALPN is not in OpenSSL, we should raise NotImplementedError.
            N(   RB   R+   R   R  R  R   R  RE   (   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_alpn_not_implemented  s    (   R   R   R   R  t   Cryptography_HAS_ALPNR  R  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  0  s   		&	'	#	#t   SessionTestsc           B   s    e  Z d  Z d   Z d   Z RS(   s7   
    Unit tests for :py:obj:`OpenSSL.SSL.Session`.
    c         C   s#   t    } |  j t | t    d S(   sy   
        :py:class:`Session` can be constructed with no arguments, creating a new
        instance of that type.
        N(   RD   R   Rq   (   R   t   new_session(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_construction   s    	c         C   s@   |  j  t t d  |  j  t t d  |  j  t t t    d S(   sl   
        If any arguments are passed to :py:class:`Session`, :py:obj:`TypeError`
        is raised.
        i{   R~  N(   R   R   RD   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_construction_wrong_args	  s    (   R   R   R   R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s   		t   ConnectionTestsc           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 e d k r n	 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e s d   Z 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& d$   Z' d%   Z( d&   Z) d'   Z* d(   Z+ d)   Z, d*   Z- d+   Z. d,   Z/ d-   Z0 d.   Z1 d/   Z2 RS(0   s:   
    Unit tests for :py:obj:`OpenSSL.SSL.Connection`.
    c         C   s6   |  j  t t  t t  } |  j t d | d  d S(   s   
        :py:obj:`Connection` and :py:obj:`ConnectionType` refer to the same type object and
        can be used to create instances of that type.
        RE   N(   R   RE   RF   RB   R+   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR   (  s    c         C   s5   t  t  } t | d  } |  j | j   |  d S(   s   
        :py:obj:`Connection.get_context` returns the :py:obj:`Context` instance used to
        construct the :py:obj:`Connection` instance.
        N(   RB   R+   RE   R   R   t   get_context(   R   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_context2  s    c         C   s/   t  t t  d  } |  j t | j d  d S(   ss   
        :py:obj:`Connection.get_context` raises :py:obj:`TypeError` if called with any
        arguments.
        N(   RE   RB   R+   R   R   R   R  (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_context_wrong_args<  s    c         C   s   t  t  } t | d  } |  j t | j  |  j t | j t    |  j t | j d  |  j t | j d  |  j t | j d d  |  j t | j t  t  d  |  j | | j	    d S(   s   
        :py:obj:`Connection.set_context` raises :py:obj:`TypeError` if called with a
        non-:py:obj:`Context` instance argument or with any number of arguments other
        than 1.
        R~  i   i   N(
   RB   R+   RE   R   R   R   t   set_contextR   R   R  (   R   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_context_wrong_argsE  s    c         C   s[   t  t  } t  t  } t | d  } | j |  |  j | | j    ~ ~ t   d S(   s   
        :py:obj:`Connection.set_context` specifies a new :py:obj:`Context` instance to be used
        for the connection.
        N(	   RB   R*   R+   RE   R   R  R   R  R    (   R   t   originalR  Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_contextW  s    c         C   s   t  t t  d  } |  j t | j  |  j t | j t    |  j t | j d d  |  j t | j t d   t	 r |  j t | j t d  j
 d   n  d S(   s   
        If :py:obj:`Connection.set_tlsext_host_name` is called with a non-byte string
        argument or a byte string with an embedded NUL or other than one
        argument, :py:obj:`TypeError` is raised.
        i{   i  t	   with nulls   example.comR   N(   RE   RB   R+   R   R   R   R  R   RL   R   Rr   (   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt$   test_set_tlsext_host_name_wrong_argsg  s    c         C   s^   t  t t  d  } |  j t | j t    |  j t | j d  |  j t | j d  d S(   sv   
        :py:obj:`Connection.get_servername` raises :py:obj:`TypeError` if called with any
        arguments.
        i   R~  N(   RE   RB   R+   R   R   R   R  R   (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_servername_wrong_args{  s    c         C   s/   t  t t  d  } |  j | j   d  d S(   sp   
        :py:obj:`Connection.pending` returns the number of bytes available for
        immediate read.
        i    N(   RE   RB   R+   R   R  t   pending(   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_pending  s    c         C   s/   t  t t  d  } |  j t | j d  d S(   sg   
        :py:obj:`Connection.pending` raises :py:obj:`TypeError` if called with any arguments.
        N(   RE   RB   R+   R   R   R   R  (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_pending_wrong_args  s    c         C   s^   t  t t  t    } |  j t | j d  |  j t | j  |  j t | j d d  d S(   s   
        :py:obj:`Connection.connect` raises :py:obj:`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   (   RE   RB   R+   R   R   R   t   connectR   (   R   Ra  (    (    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(   s   
        :py:obj:`Connection.connect` raises :py:obj:`socket.error` if the underlying socket
        connect method raises it.
        s	   127.0.0.1i   i    N(   s	   127.0.0.1i   (
   R   RB   R+   RE   R   R
   R  R  RE  R   (   R   R   R   R;  Rk  (    (    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(   sa   
        :py:obj:`Connection.connect` establishes a connection to the specified address.
        R}   i    i   s	   127.0.0.1i   N(   R}   i    (   R   R   R   RE   RB   R+   R  R   (   R   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, :py:obj:`Connection.connect_ex` returns the
            errno instead of raising an exception.
            R}   i    i   s   %r not in %rN(   R}   i    (   R   R   R   RE   RB   R+   R   R   R   R   R   R   R   (   R   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(   sf   
        :py:obj:`Connection.accept` raises :py:obj:`TypeError` if called with any arguments.
        N(   RE   RB   R+   R   R   R   R   R   (   R   Ra  (    (    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   
        :py:obj:`Connection.accept` accepts a pending connection attempt and returns a
        tuple of a new :py:obj:`Connection` (the accepted client) and the address the
        connection originated from.
        R}   i    i   s	   127.0.0.1i   N(   R}   i    (   RB   R+   R   R   R   RR   R   R   RQ   R   RE   R   R   R  R   R   R   Rq   R   R  R  (   R   R   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   
        :py:obj:`Connection.shutdown` raises :py:obj:`TypeError` if called with the wrong
        number of arguments or with arguments other than integers.
        i    i   N(	   RE   RB   R+   R   R   R   t   shutdownt   get_shutdownt   set_shutdown(   R   Ra  (    (    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(   sZ   
        :py:obj:`Connection.shutdown` performs an SSL-level connection shutdown.
        i   N(
   R   t   assertFalseR  R  R  R&   R   RA   R   R'   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_shutdown  s    
c         C   su   |  j    \ } } | j d  |  j t | j  } t d k rZ |  j | j d t  n |  j | j d t	  d S(   s   
        If the underlying socket is closed, :py:obj:`Connection.shutdown` propagates the
        write error from the low level write call.
        i   RT  i    N(
   R   t   sock_shutdownR   R>   R  R   R   RE  R   R   (   R   R   R   Rk  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_shutdown_closed	  s    c         C   s   t  t  } t  t  } | j t t t   | j t t t   t	 | d  } t	 | d  } |  j | |  |  j | j   t  |  j t | j  | j   |  j t | j  d S(   sw   
        If the underlying connection is truncated, :obj:`Connection.shutdown`
        raises an :obj:`Error`.
        N(   RB   R+   R   R   R   RR   R   R   RQ   RE   R   R   R   R  R   R   R?   t   bio_shutdownR=   (   R   t
   server_ctxt
   client_ctxR   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_shutdown_truncated	  s    
c         C   s?   t  t t  t    } | j t  |  j | j   t  d S(   sr   
        :py:obj:`Connection.set_shutdown` sets the state of the SSL connection shutdown
        process.
        N(   RE   RB   R+   R   R  R'   R  R  (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_shutdown0	  s    c         C   sE   t  t t  t    } | j t t   |  j | j   t  d S(   s   
            On Python 2 :py:obj:`Connection.set_shutdown` accepts an argument
            of type :py:obj:`long` as well as :py:obj:`int`.
            N(	   RE   RB   R+   R   R  R   R'   R  R  (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_shutdown_long;	  s    c         C   s[   t  t t  d  } |  j t | j d  |  j t | j  |  j t | j d d  d S(   s   
        :py:obj:`Connection.set_app_data` raises :py:obj:`TypeError` if called with other than
        one argument.  :py:obj:`Connection.get_app_data` raises :py:obj:`TypeError` if called
        with any arguments.
        N(   RE   RB   R+   R   R   R   R  R  (   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_app_data_wrong_argsE	  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
        :py:obj:`Connection.set_app_data` and later retrieved with
        :py:obj:`Connection.get_app_data`.
        N(   RE   RB   R+   R   R   R  R   R  (   R   Rw   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  Q	  s    	c         C   s,   t  t t  d  } |  j t | j  d S(   s   
        :py:obj:`Connection.makefile` is not implemented and calling that method raises
        :py:obj:`NotImplementedError`.
        N(   RE   RB   R+   R   R   R  t   makefile(   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_makefile]	  s    c         C   st   t  t t  d  } |  j t | j d  |  j t | j d  |  j t | j t    |  j t | j g   d S(   s{   
        :py:obj:`Connection.get_peer_cert_chain` raises :py:obj:`TypeError` if called with any
        arguments.
        i   Rv  N(   RE   RB   R+   R   R   R   t   get_peer_cert_chainR   (   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt#   test_get_peer_cert_chain_wrong_argsf	  s
    c         C   sE  t    } | \ \ } } \ } } \ } } t t  } | j |  | j |  | j |  | j |  t | d  }	 |	 j   t t  }
 |
 j	 t
 t  t |
 d  } | j   |  j | |	  | j   } |  j t |  d  |  j d | d j   j  |  j d | d j   j  |  j d | d j   j  d S(	   s   
        :py:obj:`Connection.get_peer_cert_chain` returns a list of certificates which
        the connected server returned for the certification verification.
        i   s   Server Certificatei    s   Intermediate Certificatei   s   Authority Certificatei   N(   R   RB   R+   R   R   RX  RE   R   R   RB  R4   R|   R   R   R  R   R   R   RD  (   R   Rm  R   R   R   R   R   R   RG  R   RF  R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_peer_cert_chainr	  s,    	!

c         C   s   t  t  } | j t t t   | j t t t   t	 | d  } | j   t	 t  t  d  } | j   |  j | |  |  j d | j    d S(   s   
        :py:obj:`Connection.get_peer_cert_chain` returns :py:obj:`None` if the peer sends no
        certificate chain.
        N(   RB   R+   R   R   R   RR   R   R   RQ   RE   R   R   R   R   R   R  (   R   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_peer_cert_chain_none	  s    

c         C   sd   t  t  } t | d  } |  j t | j d  |  j t | j d  |  j t | j t    d S(   ss   
        :py:obj:`Connection.get_session` raises :py:obj:`TypeError` if called
        with any arguments.
        i{   R~  N(   RB   R+   RE   R   R   R   t   get_sessionR   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_session_wrong_args	  s
    c         C   s;   t  t  } t | d  } | j   } |  j d |  d S(   s   
        :py:obj:`Connection.get_session` returns :py:obj:`None` when used with
        an object which has not been connected.
        N(   RB   R+   RE   R   R  R   (   R   R   R   t   session(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_session_unconnected	  s    c         C   s2   |  j    \ } } | j   } |  j | t  d S(   s   
        On the server side of a connection, :py:obj:`Connection.get_session`
        returns a :py:class:`Session` instance representing the SSL session for
        that connection.
        N(   R   R  R  RD   (   R   R   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_server_get_session	  s    c         C   s2   |  j    \ } } | j   } |  j | t  d S(   s   
        On the client side of a connection, :py:obj:`Connection.get_session`
        returns a :py:class:`Session` instance representing the SSL session for
        that connection.
        N(   R   R  R  RD   (   R   R   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_client_get_session	  s    c         C   s   t  t  } t | d  } |  j t | j  |  j t | j d  |  j t | j d  |  j t | j t    |  j t | j t   t    d S(   s   
        If called with an object that is not an instance of :py:class:`Session`,
        or with other than one argument, :py:obj:`Connection.set_session` raises
        :py:obj:`TypeError`.
        i{   R~  N(	   RB   R+   RE   R   R   R   t   set_sessionR   RD   (   R   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_session_wrong_args	  s    c   	         s   t  t t  } t t t  } t t      j |    j |    j	 d    f d   }  j
 d |  \ } } | j      f d   }  j
 d | d |  \ } }  j | j   | j    d S(   s  
        :py:obj:`Connection.set_session`, when used prior to a connection being
        established, accepts a :py:class:`Session` instance and causes an
        attempt to re-use the session it represents when the SSL handshake is
        performed.
        s
   unity-testc            s   t    |   } | j   | S(   N(   RE   R   (   R   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   makeServer	  s    
R   c            s     j  |   } | j    | S(   N(   R   R  (   R   R   (   t   originalSessionR   (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   makeClient	  s    R   N(   R   R   RR   R   RQ   RB   R+   R   R   t   set_session_idR   R  R   t
   master_key(	   R   R   Rx   R   t   originalServert   originalClientR  t   resumedServert   resumedClient(    (   R   R  R   s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_client_set_session	  s     		c            s   t  t t  } t t t  } t t      j |    j |    j	 d    f d   } |  j
 d |  \ } } | j     f d   } |  j t |  j
 d | d | d S(   s   
        If :py:obj:`Connection.set_session` is passed a :py:class:`Session`
        instance associated with a context using a different SSL method than the
        :py:obj:`Connection` is using, a :py:class:`OpenSSL.SSL.Error` is
        raised.
        s
   unity-testc            s   t    |   } | j   | S(   N(   RE   R   (   R   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR   
  s    
R   c            s0   t  t t  |   } | j   | j    | S(   N(   RE   RB   R)   R   R  (   R   R   (   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  !
  s    
R   N(   R   R   RR   R   RQ   RB   R+   R   R   R  R   R  R   R=   (   R   R   Rx   R   R  R  R  (    (   R   R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_session_wrong_method

  s    	c         C   s   t    \ } } d } x^ t d  D]C } y | j |  Wq" t k
 rd } | j t k r^ Pn    q" Xq" W|  j d  t t  } t	 | |  } | j
   |  j t | j  d S(   s   
        :py:obj:`Connection` methods which generate output raise
        :py:obj:`OpenSSL.SSL.WantWriteError` if writing to the connection's BIO
        fail indicating a should-write state.
        R~   i   i   s8   Failed to fill socket buffer, cannot test BIO want writeNi   i  @ (   R   RZ  R   R
   R?  R   R  RB   R+   RE   R   R   R@   R   (   R   t   client_sockett   server_sockett   msgR]  t   eR   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_wantWriteError-
  s    
c         C   s5   t  t  } t | d  } |  j | j   d  d S(   su   
        :py:obj:`Connection.get_finished` returns :py:obj:`None` before TLS
        handshake is completed.
        N(   RB   R+   RE   R   R   t   get_finished(   R   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt    test_get_finished_before_connectN
  s    c         C   s5   t  t  } t | d  } |  j | j   d  d S(   sz   
        :py:obj:`Connection.get_peer_finished` returns :py:obj:`None` before
        TLS handshake is completed.
        N(   RB   R+   RE   R   R   t   get_peer_finished(   R   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt%   test_get_peer_finished_before_connectX
  s    c         C   sK   |  j    \ } } |  j | j   d  |  j t | j    d k  d S(   s   
        :py:obj:`Connection.get_finished` method returns the TLS Finished
        message send from client, or server. Finished messages are send during
        TLS handshake.
        i    N(   R   t   assertNotEqualR  R   R   R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_finishedb
  s    c         C   sK   |  j    \ } } |  j | j   d  |  j t | j    d k  d S(   s   
        :py:obj:`Connection.get_peer_finished` method returns the TLS Finished
        message received from client, or server. Finished messages are send
        during TLS handshake.
        i    N(   R   R  R  R   R   R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_peer_finishedo
  s    c         C   sN   |  j    \ } } |  j | j   | j    |  j | j   | j    d S(   s   
        The TLS Finished message send by server must be the TLS Finished message
        received by client.

        The TLS Finished message send by client must be the TLS Finished message
        received by server.
        N(   R   R   R  R  (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt"   test_tls_finished_message_symmetry{
  s    c         C   s5   t  t  } t | d  } |  j | j   d  d S(   s|   
        :py:obj:`Connection.get_cipher_name` returns :py:obj:`None` if no
        connection has been established.
        N(   RB   R+   RE   R   R   t   get_cipher_name(   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt#   test_get_cipher_name_before_connect
  s    c         C   s_   |  j    \ } } | j   | j   } } |  j | t  |  j | t  |  j | |  d S(   s   
        :py:obj:`Connection.get_cipher_name` returns a :py:class:`unicode`
        string giving the name of the currently used cipher.
        N(   R   R  R  R   R   (   R   R   R   t   server_cipher_namet   client_cipher_name(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_cipher_name
  s
    c         C   s5   t  t  } t | d  } |  j | j   d  d S(   s   
        :py:obj:`Connection.get_cipher_version` returns :py:obj:`None` if no
        connection has been established.
        N(   RB   R+   RE   R   R   t   get_cipher_version(   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt&   test_get_cipher_version_before_connect
  s    c         C   s_   |  j    \ } } | j   | j   } } |  j | t  |  j | t  |  j | |  d S(   s   
        :py:obj:`Connection.get_cipher_version` returns a :py:class:`unicode`
        string giving the protocol name of the currently used cipher.
        N(   R   R  R  R   R   (   R   R   R   t   server_cipher_versiont   client_cipher_version(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_cipher_version
  s
    c         C   s5   t  t  } t | d  } |  j | j   d  d S(   s|   
        :py:obj:`Connection.get_cipher_bits` returns :py:obj:`None` if no
        connection has been established.
        N(   RB   R+   RE   R   R   t   get_cipher_bits(   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt#   test_get_cipher_bits_before_connect
  s    c         C   s_   |  j    \ } } | j   | j   } } |  j | t  |  j | t  |  j | |  d S(   s~   
        :py:obj:`Connection.get_cipher_bits` returns the number of secret bits
        of the currently used cipher.
        N(   R   R"  R  R   R   (   R   R   R   t   server_cipher_bitst   client_cipher_bits(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_get_cipher_bits
  s
    (3   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  R  R  R  R  R  R  R  R  R!  R#  R&  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    sd   	
	
																				

						"							)	#	!	
	
				
		
		
t   ConnectionGetCipherListTestsc           B   s    e  Z d  Z d   Z d   Z RS(   s9   
    Tests for :py:obj:`Connection.get_cipher_list`.
    c         C   s/   t  t t  d  } |  j t | j d  d S(   sw   
        :py:obj:`Connection.get_cipher_list` raises :py:obj:`TypeError` if called with any
        arguments.
        N(   RE   RB   R+   R   R   R   R  (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  
  s    c         C   sb   t  t t  d  } | j   } |  j t | t   x$ | D] } |  j t | t   q> Wd S(   s   
        :py:obj:`Connection.get_cipher_list` returns a :py:obj:`list` of
        :py:obj:`bytes` giving the names of the ciphers which might be used.
        N(	   RE   RB   R+   R   R  R   Rq   t   listRj  (   R   Ra  t   cipherst   cipher(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_result
  s
    (   R   R   R   R  R+  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR'  
  s   		t   ConnectionSendTestsc           B   ss   e  Z d  Z d   Z d   Z d   Z y e Wn e k
 rB n
 Xd   Z y e	 Wn e k
 rg n
 Xd   Z
 RS(   s-   
    Tests for :py:obj:`Connection.send`
    c         C   sd   t  t t  d  } |  j t | j  |  j t | j t    |  j t | j d t   d  d S(   s   
        When called with arguments other than string argument for its first
        parameter or more than two arguments, :py:obj:`Connection.send` raises
        :py:obj:`TypeError`.
        Rv  t   barN(   RE   RB   R+   R   R   R   R   R   (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  
  s    c         C   sZ   |  j    \ } } | j t d   } |  j | d  |  j | j d  t d   d S(   s   
        When passed a short byte string, :py:obj:`Connection.send` transmits all of it
        and returns the number of bytes sent.
        t   xyi   N(   R   R   RL   R  R   (   R   R   R   t   count(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_short_bytes
  s    c      	   C   s   |  j    \ } } t d t  f } t d  | j d j d   } |  j d j t  t	 | d j
   |  j | d j t  Wd QX|  j | d  |  j | j d  d  d S(	   s   
        When passed a text, :py:obj:`Connection.send` transmits all of it and
        returns the number of bytes sent. It also raises a DeprecationWarning.
        t   recordt   alwaysR.  R   s,   {0} for buf is no longer accepted, use bytesiNi   (   R   R   R   R   R   Rr   R   t   formatRI   Rj  t   messageR   t   categoryt   DeprecationWarningR  R   (   R   R   R   R  R/  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   test_text
  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,
            :py:obj:`Connection.send` transmits all of them and returns the number of
            bytes sent.
            R.  i   N(   R   R   t
   memoryviewRL   R  R   (   R   R   R   R/  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_short_memoryview"  s    c         C   s`   |  j    \ } } | j t t d    } |  j | d  |  j | j d  t d   d S(   s   
            When passed a buffer containing a small number of bytes,
            :py:obj:`Connection.send` transmits all of them and returns the number of
            bytes sent.
            R.  i   N(   R   R   t   bufferRL   R  R   (   R   R   R   R/  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_short_buffer3  s    (   R   R   R   R  R0  R7  R8  t	   NameErrorR9  R:  R;  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR,  
  s   				c         C   s   t  t |    S(   s[   
    Create a new ``memoryview`` wrapped around a ``bytearray`` of the given
    size.
    (   R8  t	   bytearray(   t   size(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _make_memoryview@  s    t   ConnectionRecvIntoTestsc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 y e Wn e k
 ro n% Xd	   Z d
   Z d   Z d   Z RS(   s2   
    Tests for :py:obj:`Connection.recv_into`
    c         C   sj   | d  } |  j    \ } } | j t d   |  j | j |  d  |  j | t t d    d S(   s   
        Assert that when the given buffer is passed to
        ``Connection.recv_into``, whatever bytes are available to be received
        that fit into that buffer are written into that buffer.
        i   R.  i   t   xy   N(   R   R   RL   R   t	   recv_intoR=  (   R   t   factoryt   output_bufferR   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _no_length_testM  s
    c         C   s   |  j  t  d S(   s   
        :py:obj:`Connection.recv_into` can be passed a ``bytearray`` instance
        and data in the receive buffer is written to it.
        N(   RE  R=  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_bytearray_no_length\  s    c         C   sm   | d  } |  j    \ } } | j t d   |  j | j | d  d  |  j | t t d    d S(   s   
        Assert that when the given buffer is passed to ``Connection.recv_into``
        along with a value for ``nbytes`` that is less than the size of that
        buffer, only ``nbytes`` bytes are written into the buffer.
        i
   t
   abcdefghiji   t
   abcde     N(   R   R   RL   R   RB  R=  (   R   RC  RD  R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _respects_length_testd  s    c         C   s   |  j  t  d S(   s   
        When called with a ``bytearray`` instance,
        :py:obj:`Connection.recv_into` respects the ``nbytes`` parameter and
        doesn't copy in more than that number of bytes.
        N(   RI  R=  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_bytearray_respects_lengthu  s    c         C   s   | d  } |  j    \ } } | j t d   |  j | j |  d  |  j | t t d    | j d  } |  j t d  |  d S(   s   
        Assert that if there are more bytes available to be read from the
        receive buffer than would fit into the buffer passed to
        :py:obj:`Connection.recv_into`, only as many as fit are written into
        it.
        i   RG  t   abcdet   fghijN(   R   R   RL   R   RB  R=  R   (   R   RC  RD  R   R   t   rest(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _doesnt_overfill_test~  s    c         C   s   |  j  t  d S(   s   
        When called with a ``bytearray`` instance,
        :py:obj:`Connection.recv_into` respects the size of the array and
        doesn't write more bytes into it than will fit.
        N(   RN  R=  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_bytearray_doesnt_overfill  s    c         C   s   | d  } |  j    \ } } | j t d   |  j | j | d  d  |  j | t t d    | j d  } |  j t d  |  d S(   s   
        Assert that if the value given by ``nbytes`` is greater than the actual
        size of the output buffer passed to :py:obj:`Connection.recv_into`, the
        behavior is as if no value was given for ``nbytes`` at all.
        i   RG  i2   RK  RL  N(   R   R   RL   R   RB  R=  R   (   R   RC  RD  R   R   RM  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _really_doesnt_overfill_test  s    c         C   s   |  j  t  d S(   s  
        When called with a ``bytearray`` instance and an ``nbytes`` value that
        is too large, :py:obj:`Connection.recv_into` respects the size of the
        array and not the ``nbytes`` value and doesn't write more bytes into
        the buffer than will fit.
        N(   RN  R=  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt%   test_bytearray_really_doesnt_overfill  s    c         C   s   |  j  t  d S(   s   
            :py:obj:`Connection.recv_into` can be passed a ``memoryview``
            instance and data in the receive buffer is written to it.
            N(   RE  R?  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_memoryview_no_length  s    c         C   s   |  j  t  d S(   s   
            When called with a ``memoryview`` instance,
            :py:obj:`Connection.recv_into` respects the ``nbytes`` parameter
            and doesn't copy more than that number of bytes in.
            N(   RI  R?  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_memoryview_respects_length  s    c         C   s   |  j  t  d S(   s   
            When called with a ``memoryview`` instance,
            :py:obj:`Connection.recv_into` respects the size of the array and
            doesn't write more bytes into it than will fit.
            N(   RN  R?  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_memoryview_doesnt_overfill  s    c         C   s   |  j  t  d S(   s*  
            When called with a ``memoryview`` instance and an ``nbytes`` value
            that is too large, :py:obj:`Connection.recv_into` respects the size
            of the array and not the ``nbytes`` value and doesn't write more
            bytes into the buffer than will fit.
            N(   RN  R?  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt&   test_memoryview_really_doesnt_overfill  s    (   R   R   R   RE  RF  RI  RJ  RN  RO  RP  RQ  R8  R<  RR  RS  RT  RU  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR@  I  s"   										
					t   ConnectionSendallTestsc           B   s   e  Z d  Z d   Z d   Z d   Z y e Wn e k
 rB n
 Xd   Z y e	 Wn e k
 rg n
 Xd   Z
 d   Z d   Z RS(   s1   
    Tests for :py:obj:`Connection.sendall`.
    c         C   sd   t  t t  d  } |  j t | j  |  j t | j t    |  j t | j d t   d  d S(   s   
        When called with arguments other than a string argument for its first
        parameter or with more than two arguments, :py:obj:`Connection.sendall`
        raises :py:obj:`TypeError`.
        Rv  R-  N(   RE   RB   R+   R   R   R   t   sendallR   (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s
    c         C   sH   |  j    \ } } | j t d   |  j | j d  t d   d S(   sm   
        :py:obj:`Connection.sendall` transmits all of the bytes in the string passed to
        it.
        R~   i   N(   R   RW  RL   R  R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   test_short  s    c      	   C   s   |  j    \ } } t d t  d } t d  | j d j d   |  j d j t  t	 | d j
   |  j | d j t  Wd QX|  j | j d  d  d S(	   s   
        :py:obj:`Connection.sendall` transmits all the content in the string
        passed to it raising a DeprecationWarning in case of this being a text.
        R1  R2  R~   R   s,   {0} for buf is no longer accepted, use bytesiNi   (   R   R   R   R   RW  Rr   R   R3  RI   Rj  R4  R   R5  R6  R  R   (   R   R   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR7    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,
            :py:obj:`Connection.sendall` transmits all of them.
            R~   i   N(   R   RW  R8  RL   R  R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR9    s    c         C   sN   |  j    \ } } | j t t d    |  j | j d  t d   d S(   s   
            When passed a buffer containing a small number of bytes,
            :py:obj:`Connection.sendall` transmits all of them.
            R~   i   N(   R   RW  R:  RL   R  R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_short_buffers   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   
        :py:obj:`Connection.sendall` transmits all of the bytes in the string passed to
        it even if this requires multiple calls of an underlying write function.
        R~   i   i    i   R   i    R}   Ni   i  (   R   RL   RW  R   R   R*  R  R   (   R   R   R   R4  t   accumt   receivedR   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   test_long*  s    c         C   sx   |  j    \ } } | j d  |  j t | j d  } t d k r] |  j | j d t  n |  j | j d t	  d S(   s   
        If the underlying socket is closed, :py:obj:`Connection.sendall` propagates the
        write error from the low level write call.
        i   s   hello, worldRT  i    N(
   R   R  R   R>   RW  R   R   RE  R   R   (   R   R   R   Rk  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_closed>  s    (   R   R   R   R  RX  R7  R8  R<  R9  R:  RY  R\  R]  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRV    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(   ss   
        :py:obj:`Connection.renegotiate` raises :py:obj:`TypeError` if called with any
        arguments.
        N(   RE   RB   R+   R   R   R   t   renegotiate(   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_renegotiate_wrong_argsQ  s    c         C   s/   t  t t  d  } |  j t | j d  d S(   s|   
        :py:obj:`Connection.total_renegotiations` raises :py:obj:`TypeError` if called with
        any arguments.
        N(   RE   RB   R+   R   R   R   t   total_renegotiations(   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt$   test_total_renegotiations_wrong_argsZ  s    c         C   s/   t  t t  d  } |  j | j   d  d S(   s   
        :py:obj:`Connection.total_renegotiations` returns :py:obj:`0` before any
        renegotiations have happened.
        i    N(   RE   RB   R+   R   R  Ra  (   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_total_renegotiationsc  s    (   R   R   R   R`  Rb  Rc  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR^  M  s   				t
   ErrorTestsc           B   s   e  Z d  Z d   Z RS(   s5   
    Unit tests for :py:obj:`OpenSSL.SSL.Error`.
    c         C   s-   |  j  t t t   |  j t j d  d S(   s7   
        :py:obj:`Error` is an exception type.
        R=   N(   R   t
   issubclassR=   Rh  R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR     s    (   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRd    s   t   ConstantsTestsc           B   s   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  e
 d k	 rl d   Z n  d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z RS(   s   
    Tests for the values of constants exposed in :py:obj:`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 :py:obj:`OpenSSL.SSL.OP_NO_QUERY_MTU` is 0x1000, the value of
            :py:const:`SSL_OP_NO_QUERY_MTU` defined by :file:`openssl/ssl.h`.
            i   N(   R   RT   (   R   (    (    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 :py:obj:`OpenSSL.SSL.OP_COOKIE_EXCHANGE` is 0x2000, the value
            of :py:const:`SSL_OP_COOKIE_EXCHANGE` defined by :file:`openssl/ssl.h`.
            i    N(   R   RU   (   R   (    (    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 :py:obj:`OpenSSL.SSL.OP_NO_TICKET` is 0x4000, the value of
            :py:const:`SSL_OP_NO_TICKET` defined by :file:`openssl/ssl.h`.
            i @  N(   R   RV   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_op_no_ticket  s    c         C   s   |  j  t d  d S(   s   
            The value of :py:obj:`OpenSSL.SSL.OP_NO_COMPRESSION` is 0x20000, the value
            of :py:const:`SSL_OP_NO_COMPRESSION` defined by :file:`openssl/ssl.h`.
            i   N(   R   RW   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_op_no_compression  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_OFF` 0x0, the value of
        :py:obj:`SSL_SESS_CACHE_OFF` defined by ``openssl/ssl.h``.
        i    N(   R   R5   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_sess_cache_off  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_CLIENT` 0x1, the value of
        :py:obj:`SSL_SESS_CACHE_CLIENT` defined by ``openssl/ssl.h``.
        i   N(   R   R6   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_sess_cache_client  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_SERVER` 0x2, the value of
        :py:obj:`SSL_SESS_CACHE_SERVER` defined by ``openssl/ssl.h``.
        i   N(   R   R7   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_sess_cache_server  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_BOTH` 0x3, the value of
        :py:obj:`SSL_SESS_CACHE_BOTH` defined by ``openssl/ssl.h``.
        i   N(   R   R8   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_sess_cache_both  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_NO_AUTO_CLEAR` 0x80, the
        value of :py:obj:`SSL_SESS_CACHE_NO_AUTO_CLEAR` defined by
        ``openssl/ssl.h``.
        i   N(   R   R9   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_sess_cache_no_auto_clear  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_LOOKUP` 0x100,
        the value of :py:obj:`SSL_SESS_CACHE_NO_INTERNAL_LOOKUP` defined by
        ``openssl/ssl.h``.
        i   N(   R   R:   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt"   test_sess_cache_no_internal_lookup  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_STORE` 0x200,
        the value of :py:obj:`SSL_SESS_CACHE_NO_INTERNAL_STORE` defined by
        ``openssl/ssl.h``.
        i   N(   R   R;   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt!   test_sess_cache_no_internal_store  s    c         C   s   |  j  d t  d S(   s   
        The value of :py:obj:`OpenSSL.SSL.SESS_CACHE_NO_INTERNAL` 0x300, the
        value of :py:obj:`SSL_SESS_CACHE_NO_INTERNAL` defined by
        ``openssl/ssl.h``.
        i   N(   R   R<   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_sess_cache_no_internal  s    N(   R   R   R   RT   R   Rg  RU   Rh  RV   Ri  RW   Rj  Rk  Rl  Rm  Rn  Ro  Rp  Rq  Rr  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyRf    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 d   Z RS(   sH   
    Tests for :py:obj:`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(   sq   
        Create a new server-side SSL :py:obj:`Connection` object wrapped around
        :py:obj:`sock`.
        (   RB   R+   R  R/   R0   R.   RB  R1   R2   R3   R|   R  R   R   R   RR   R   R   RQ   R   t   add_certRS   RE   R   (   R   t   sockR  t   server_storeR   (    (    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(   sq   
        Create a new client-side SSL :py:obj:`Connection` object wrapped around
        :py:obj:`sock`.
        (   RB   R+   R  R/   R0   R.   RB  R1   R2   R3   R|   R  R   R   R   RP   R   R   RO   R   Rt  RS   RE   R   (   R   Ru  R  t   client_storeR   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   _client#  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 :py:obj:`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(   Rw  R   Ry  R   R  t   client_randomt   server_randomR   t   assertNotIdenticalR  t   assertNotEqualsRL   R   (   R   R   R   t   important_message(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_memoryConnect7  s.    c         C   s   |  j    \ } } t d  } | j |  | j d  } |  j | |  | d d d  } | j |  | j d  } |  j | |  d S(   s  
        Just like :py:obj:`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 :py:obj:`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(   R   RL   R   R   R   (   R   R   R   R~  R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_socketConnectc  s    
c         C   sg   t  t  } t   } t | |  } |  j t | j d  |  j t | j d  |  j t | j  d S(   s   
        Test that :py:obj:`OpenSSL.SSL.bio_read` and :py:obj:`OpenSSL.SSL.bio_write` don't
        work on :py:obj:`OpenSSL.SSL.Connection`() that use sockets.
        id   Rv  N(	   RB   R)   R   RE   R   R   R   R   R  (   R   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
        :py:obj:`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   R~   Ni   (	   Rw  R   Ry  R   R   R   R   R  R   (   R   R   R   R>  t   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   
        :py:obj:`Connection.bio_shutdown` signals the end of the data stream from
        which the :py:obj:`Connection` reads.
        i   N(   Rw  R   R  R   R=   R   R  t	   __class__(   R   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s    
c         C   sN   |  j    \ } } | j t  |  j t | j d  } |  j | j d  d S(   s   
        If the connection is lost before an orderly SSL shutdown occurs,
        :py:obj:`OpenSSL.SSL.SysCallError` is raised with a message of
        "Unexpected EOF".
        i   is   Unexpected EOFN(   is   Unexpected EOF(   R   R  R	   R   R>   R   R   RE  (   R   R   R   Rk  (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_unexpectedEndOfFile  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 :py:obj:`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 :py:obj:`get_client_ca_list` returns the proper value at various
            times.
        N(   Rw  R   Ry  R   t   get_client_ca_listR  R   (   R   t   funcR   R   R   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   
        :py:obj:`Context.set_client_ca_list` raises a :py:obj:`TypeError` if called with a
        non-list or a list that contains objects other than X509Names.
        t   spamN(   RB   R+   R   R   t   set_client_ca_listR   R   (   R   R   (    (    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, :py:obj:`Context.set_client_ca_list` configures the
        context to send no CA names to the client and, on both the server and
        client sides, :py:obj:`Connection.get_client_ca_list` returns an empty list
        after the connection is set up.
        c         S   s   |  j  g   g  S(   N(   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   no_ca  s    N(   R  (   R   R  (    (    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(   sY  
        If passed a list containing a single X509Name,
        :py:obj:`Context.set_client_ca_list` configures the context to send that CA
        name to the client and, on both the server and client sides,
        :py:obj:`Connection.get_client_ca_list` returns a list containing that
        X509Name after the connection is set up.
        c            s   |  j    g    g S(   N(   R  (   R   (   t   cadesc(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt	   single_ca  s    N(   R   R   RS   R   R  (   R   R   R  (    (   R  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(   se  
        If passed a list containing multiple X509Name objects,
        :py:obj:`Context.set_client_ca_list` configures the context to send those CA
        names to the client and, on both the server and client sides,
        :py:obj:`Connection.get_client_ca_list` returns a list containing those
        X509Names after the connection is set up.
        c            s      g } |  j  |  | S(   N(   R  (   R   t   L(   t   cldesct   sedesc(    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   multiple_ca
  s    N(   R   R   RQ   R   R  (   R   t   secertt   clcertR  (    (   R  R  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 :py:obj:`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(   R  (   R   (   R  R  R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   changed_ca  s    N(   R   R   RS   RQ   R   R  (   R   R   R  R  R  (    (   R  R  R  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 :py:obj:`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(   R  R*  (   R   R  (   R  R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt
   mutated_ca2  s    	N(   R   R   RS   RQ   R   R  (   R   R   R  R  (    (   R  R  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   
        :py:obj:`Context.add_client_ca` raises :py:obj:`TypeError` if called with a non-X509
        object or with a number of arguments other than one.
        R  N(   RB   R+   R   R   RS   R   R   t   add_client_ca(   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_add_client_ca_errors:  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 :py:obj:`Context.add_client_ca`.
        c            s   |  j      g S(   N(   R  (   R   (   R   R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  M  s    N(   R   R   RS   R   R  (   R   R  (    (   R   R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_one_add_client_caF  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
        :py:obj:`Context.add_client_ca` with multiple X509 objects.
        c            s$   |  j     |  j      g S(   N(   R  (   R   (   R   R  R  R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR  ^  s    N(   R   R   RS   RQ   R   R  (   R   R  (    (   R   R  R  R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_multiple_add_client_caS  s    c            sz   t  t t  } t  t t  } t  t t   | j     | j     j         f d   } |  j |  d S(   s   
        A call to :py:obj:`Context.set_client_ca_list` followed by a call to
        :py:obj:`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(   R  R  (   R   (   R  R  R  R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   mixed_set_add_cas  s    N(   R   R   RS   RQ   R   R  (   R   R   R  R  (    (   R  R  R  R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_and_add_client_cae  s    c            sn   t  t t  } t  t t   t  t t   | j      j         f d   } |  j |  d S(   s   
        A call to :py:obj:`Context.set_client_ca_list` after a call to
        :py:obj:`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  R  (   R   (   R  R  R  R  (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   set_replaces_add_ca  s    N(   R   R   RS   RQ   R   R  (   R   R   R  (    (   R  R  R  R  s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_set_after_add_client_caz  s    (   R   R   R   Rw  Ry  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.pyRs  	  s*   			,																t   ConnectionBIOTestsc           B   s2   e  Z d  Z d   Z d   Z e s0 d   Z n  RS(   sU   
    Tests for :py:obj:`Connection.bio_read` and :py:obj:`Connection.bio_write`.
    c         C   s5   t  t  } t | d  } |  j t | j d  d S(   s   
        :py:obj:`Connection.bio_read` raises :py:obj:`OpenSSL.SSL.WantReadError`
        if there are no bytes available to be read from the BIO.
        i   N(   RB   R+   RE   R   R   R?   R   (   R   R   Rw   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_wantReadError  s    c         C   sp   t  t  } t | d  } | j   y | j   Wn t k
 rF n X| j d  } |  j d t	 |   d S(   s   
        :py:obj:`Connection.bio_read` accepts an integer giving the maximum
        number of bytes to read and return.
        i   N(
   RB   R+   RE   R   R   R   R?   R   R   R   (   R   R   Rw   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_buffer_size  s    
c         C   sv   t  t  } t | d  } | j   y | j   Wn t k
 rF n X| j t d   } |  j	 d t
 |   d S(   s   
            On Python 2 :py:obj:`Connection.bio_read` accepts values of type
            :py:obj:`long` as well as :py:obj:`int`.
            i   N(   RB   R+   RE   R   R   R   R?   R   R   R   R   (   R   R   Rw   R   (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_buffer_size_long  s    
(   R   R   R   R  R  R   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    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(   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rh   Ri   Rj   Rk   Rl   Rm   Rn   Ro   R   Rq   R   (   R   t   const(    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   test_integers  s    			(   R   R   R   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyR    s   t   __main__N(   R   t   gcR    R   R?  R   R   R   R   R   t   sysR   R   R   R	   R
   t   osR   t   os.pathR   t   unittestR   t   weakrefR   t   warningsR   R   t   sixR   R   R   t   OpenSSL.cryptoR   R   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/   R0   R1   R2   R3   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   R@   RA   RB   RC   RD   RE   RF   RG   t   OpenSSL._utilRH   R  t   OpenSSL.test.utilRI   RJ   RK   RL   t   OpenSSL.test.test_cryptoRM   RN   RO   RP   RQ   RR   RS   RT   t   ImportErrorR   RU   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rh   Ri   Rj   Rk   Rl   Rm   Rn   Ro   R  Rv   R|   R   R   R   R   R   R   R  R  R  R  R  R'  R,  R?  R@  RV  R^  Rd  Rf  Rs  R  R  R   (    (    (    s9   /usr/lib/python2.7/dist-packages/OpenSSL/test/test_ssl.pyt   <module>   s   (".":(."4




 					6f    o  Q		o5z 1