
Vc           @   s  d  d l  Z  d  d l 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 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 m Z m Z m Z m  Z! m" Z# d  d l$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* y
 e+ Z, Wn' e- k
 r9d e. f d     YZ, n Xy
 e/ Z0 Wn' e- k
 rmd e. f d     YZ0 n Xe j1 Z1 e j2 Z2 e j3 Z3 e j4 Z4 e j5 Z5 e j6 Z6 e j7 Z8 e j9 Z: d Z; d Z< d Z= d Z> d Z? d Z@ e jA ZB e jC ZD e jE ZF eG e d d  ZH eG e d d  ZI y e jJ ZK Wn eL k
 r9n Xe jM ZN e jO ZP e jQ ZR e jS ZT e jU ZV e jW ZX e jY ZZ e j[ Z\ y e j] Z^ Wn eL k
 rn Xe j_ Z` e ja Zb e jc Zd e je Zf e jg Zh e ji Zj e jk Zl e jm Zn e jo Zp e jq Zr y e js Zt Wn eL k
 rn Xe ju Zv e jw Zx y e jy Zz Wn eL k
 rPn Xe j{ Z| e j} Z~ e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z d e f d     YZ e e e  Z e e  Z d e f d     YZ d e f d     YZ d e f d      YZ d! e f d"     YZ d# e f d$     YZ d% e. f d&     YZ d' e f d(     YZ d) e f d*     YZ d+ e f d,     YZ d- e f d.     YZ d/   Z d0   Z d1   Z d2   Z d3 e. f d4     YZ d5 e. f d6     YZ e Z d7 e. f d8     YZ e Z e j   d S(9   iN(   t   platform(   t   wrapst   partial(   t   countt   chain(   t   WeakValueDictionary(   t	   errorcode(   t   binary_type(   t   integer_types(   t   int2bytet
   indexbytes(   t   UNSPECIFIEDt   exception_from_error_queuet   ffit   libt   make_assertt   nativet   path_stringt   text_to_bytes_and_warn(   t   FILETYPE_PEMt   _PassphraseHelpert   PKeyt   X509Namet   X509t	   X509Storet   _memoryviewc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR      s   t   _bufferc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR   #   s   i   i   i   i   i   i   t   SSL_OP_NO_TLSv1_1i    t   SSL_OP_NO_TLSv1_2t   Errorc           B   s   e  Z d  Z RS(   s4   
    An error occurred in an `OpenSSL.SSL` API.
    (   R   R   t   __doc__(    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR      s   t   WantReadErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR!      s   t   WantWriteErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR"      s   t   WantX509LookupErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR#      s   t   ZeroReturnErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR$      s   t   SysCallErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR%      s   t   _CallbackExceptionHelperc           B   s    e  Z d  Z d   Z d   Z RS(   s  
    A base class for wrapper classes that allow for intelligent exception
    handling in OpenSSL callbacks.

    :ivar list _problems: Any exceptions that occurred while executing in a
        context where they could not be raised in the normal way.  Typically
        this is because OpenSSL has called into some Python code and requires a
        return value.  The exceptions are saved to be raised later when it is
        possible to do so.
    c         C   s   g  |  _  d  S(   N(   t	   _problems(   t   self(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   __init__   s    c         C   sA   |  j  r= y t   Wn t k
 r' n X|  j  j d   n  d S(   s   
        Raise an exception from the OpenSSL error queue or that was previously
        captured whe running a callback.
        i    N(   R'   t   _raise_current_errorR   t   pop(   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   raise_if_problem   s    	(   R   R   R    R)   R,   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR&      s   
	t   _VerifyHelperc           B   s   e  Z d  Z d   Z RS(   s^   
    Wrap a callback such that it can be used as a certificate verification
    callback.
    c            sD   t  j   t       f d    } t j d |   _ d  S(   Nc   
         s   t  j t   } t j |  | _ t j |  } t j |  } t j   } t j | |  } t	 j
 | } y   | | | | |   } Wn$ t k
 r }	  j j |	  d SX| r t j | t j  d Sd Sd  S(   Ni    i   (   R   t   __new__t   _libt   X509_STORE_CTX_get_current_certt   _x509t   X509_STORE_CTX_get_errort   X509_STORE_CTX_get_error_deptht"   SSL_get_ex_data_X509_STORE_CTX_idxt   X509_STORE_CTX_get_ex_datat
   Connectiont   _reverse_mappingt	   ExceptionR'   t   appendt   X509_STORE_CTX_set_errort	   X509_V_OK(
   t   okt	   store_ctxt   certt   error_numbert   error_deptht   indext   sslt
   connectiont   resultt   e(   t   callbackR(   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   wrapper   s"    s   int (*)(int, X509_STORE_CTX *)(   R&   R)   R   t   _ffiRF   (   R(   RF   RG   (    (   RF   R(   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR)      s    (   R   R   R    R)   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR-      s   t   _NpnAdvertiseHelperc           B   s   e  Z d  Z d   Z RS(   sT   
    Wrap a callback such that it can be used as an NPN advertisement callback.
    c            sD   t  j   t       f d    } t j d |   _ d  S(   Nc            s   y t  j |  }   |  } d j t j d   | D   } t j d t |   t j d |  g | _ | j d d | d <| j d | d <d SWn$ t	 k
 r }  j
 j |  d SXd  S(   Nt    c         s   s'   |  ] } t  t |   | f Vq d  S(   N(   R	   t   len(   t   .0t   p(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pys	   <genexpr>  s    s   unsigned int *s   unsigned char[]i    i   i   (   R6   R7   t   joinR   t   from_iterableRH   t   newRK   t   _npn_advertise_callback_argsR8   R'   R9   (   RB   t   outt   outlent   argt   connt   protost   protostrRE   (   RF   R(   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG      s    s>   int (*)(SSL *, const unsigned char **, unsigned int *, void *)(   R&   R)   R   RH   RF   (   R(   RF   RG   (    (   RF   R(   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR)      s
    (   R   R   R    R)   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRI      s   t   _NpnSelectHelperc           B   s   e  Z d  Z d   Z RS(   sP   
    Wrap a callback such that it can be used as an NPN selection callback.
    c            sD   t  j   t       f d    } t j d |   _ d  S(   Nc            s  y t  j |  } t j | |  } g  } xE | rp t | d  }	 | d |	 d !}
 | j |
  | |	 d } q, W  | |  } t j d t |   t j d |  g | _ | j d d | d <| j d | d <d SWn$ t	 k
 r }  j
 j |  d SXd  S(   Ni    i   s   unsigned char *s   unsigned char[]i   (   R6   R7   RH   t   bufferR
   R9   RP   RK   t   _npn_select_callback_argsR8   R'   (   RB   RR   RS   t   in_t   inlenRT   RU   t   instrt	   protolistt   lt   protot   outstrRE   (   RF   R(   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG   !  s$    	s^   int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *)(   R&   R)   R   RH   RF   (   R(   RF   RG   (    (   RF   R(   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR)     s
    "(   R   R   R    R)   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRX     s   t   _ALPNSelectHelperc           B   s   e  Z d  Z d   Z RS(   sQ   
    Wrap a callback such that it can be used as an ALPN selection callback.
    c            sD   t  j   t       f d    } t j d |   _ d  S(   Nc            s!  y t  j |  } t j | |  } g  } xE | rp t | d  }	 | d |	 d !}
 | j |
  | |	 d } q, W  | |  } t | t  s t d   n  t j	 d t
 |   t j	 d |  g | _ | j d d | d <| j d | d <d SWn$ t k
 r}  j j |  d SXd  S(   Ni    i   s'   ALPN callback must return a bytestring.s   unsigned char *s   unsigned char[]i   (   R6   R7   RH   RY   R
   R9   t
   isinstancet   _binary_typet	   TypeErrorRP   RK   t   _alpn_select_callback_argsR8   R'   (   RB   RR   RS   R[   R\   RT   RU   R]   R^   t   encoded_lenR`   Ra   RE   (   RF   R(   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG   R  s(    	s^   int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *)(   R&   R)   R   RH   RF   (   R(   RF   RG   (    (   RF   R(   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR)   O  s
    $(   R   R   R    R)   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRb   J  s   c         C   s   d  } t |  t  sB t |  d d   } | d  k	 rB |   }  qB n  t |  t  rZ |  } n  t | t  sx t d   n" | d k  r t d | f   n  | S(   Nt   filenos3   argument must be an int, or have a fileno() method.i    s1   file descriptor cannot be a negative integer (%i)(   t   NoneRc   R   t   getattrRe   t
   ValueError(   t   objt   fdt   meth(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _asFileDescriptor}  s    	c         C   s   t  j t j |    S(   s   
    Return a string describing the version of OpenSSL in use.

    :param type: One of the SSLEAY_ constants defined in this module.
    (   RH   t   stringR/   t   SSLeay_version(   t   type(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRq     s    c            s   t       f d    } | S(   s   
    Wraps any function that requires NPN support in OpenSSL, ensuring that
    NotImplementedError is raised if NPN is not present.
    c             s%   t  j s t d   n    |  |   S(   Ns   NPN not available.(   R/   t   Cryptography_HAS_NEXTPROTONEGt   NotImplementedError(   t   argst   kwargs(   t   func(    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG     s    	(   R   (   Rw   RG   (    (   Rw   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _requires_npn  s    c            s   t       f d    } | S(   s   
    Wraps any function that requires ALPN support in OpenSSL, ensuring that
    NotImplementedError is raised if ALPN support is not present.
    c             s%   t  j s t d   n    |  |   S(   Ns   ALPN not available.(   R/   t   Cryptography_HAS_ALPNRt   (   Ru   Rv   (   Rw   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG     s    	(   R   (   Rw   RG   (    (   Rw   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _requires_alpn  s    t   Sessionc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR{     s   t   Contextc           B   s  e  Z d  Z i d e 6d e 6d e 6d e 6d e 6d e 6Z	 e
 d   e	 j   D  Z	 d   Z d/ d	  Z d
   Z d/ d  Z d   Z d   Z e d  Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d    Z' d!   Z( d"   Z) d#   Z* d$   Z+ d%   Z, d&   Z- d'   Z. d(   Z/ d)   Z0 d*   Z1 e2 d+    Z3 e2 d,    Z4 e5 d-    Z6 e5 d.    Z7 RS(0   sn   
    :class:`OpenSSL.SSL.Context` instances define the parameters for setting
    up new SSL connections.
    t   SSLv2_methodt   SSLv3_methodt   SSLv23_methodt   TLSv1_methodt   TLSv1_1_methodt   TLSv1_2_methodc         c   sB   |  ]8 \ } } t  t | d   d  k	 r | t  t |  f Vq d  S(   N(   Rj   R/   Ri   (   RL   t
   identifiert   name(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pys	   <genexpr>  s   	c         C   sI  t  | t  s t d   n  y |  j | } Wn t k
 rN t d   n X|   } | t j k rq t   n  t	 j
 |  } | t j k r t   n  t j | t	 j  } | |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ |  j t	 j  d S(   so   
        :param method: One of SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, or
            TLSv1_METHOD.
        s   method must be an integers   No such protocolN(   Rc   R   Re   t   _methodst   KeyErrorRk   RH   t   NULLR*   R/   t   SSL_CTX_newt   gct   SSL_CTX_freet   _contextRi   t   _passphrase_helpert   _passphrase_callbackt   _passphrase_userdatat   _verify_helpert   _verify_callbackt   _info_callbackt   _tlsext_servername_callbackt	   _app_datat   _npn_advertise_helpert   _npn_advertise_callbackt   _npn_select_helpert   _npn_select_callbackt   _alpn_select_helpert   _alpn_select_callbackt   set_modet   SSL_MODE_ENABLE_PARTIAL_WRITE(   R(   t   methodt   method_funct
   method_objt   context(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR)     s:    	

															c         C   st   | d k r t j } n t |  } | d k r< t j } n t |  } t j |  j | |  } | sp t   n  d S(   sX  
        Let SSL know where we can find trusted certificates for the certificate
        chain

        :param cafile: In which file we can find the certificates (``bytes`` or
            ``unicode``).
        :param capath: In which directory we can find the certificates
            (``bytes`` or ``unicode``).

        :return: None
        N(   Ri   RH   R   t   _path_stringR/   t   SSL_CTX_load_verify_locationsR   R*   (   R(   t   cafilet   capatht   load_result(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   load_verify_locations  s    c            s7   t        f d    } t t | d t d t S(   Nc            s     |  |  j   S(   N(   R   (   t   sizet   verifyt   userdata(   RF   R(   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG     s    t	   more_argst   truncate(   R   R   R   t   True(   R(   RF   RG   (    (   RF   R(   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _wrap_callback  s    c         C   s_   t  |  s t d   n  |  j |  |  _ |  j j |  _ t j |  j |  j  | |  _	 d S(   s   
        Set the passphrase callback

        :param callback: The Python callback to use
        :param userdata: (optional) A Python object which will be given as
                         argument to the callback
        :return: None
        s   callback must be callableN(
   t   callableRe   R   R   RF   R   R/   t   SSL_CTX_set_default_passwd_cbR   R   (   R(   RF   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_passwd_cb  s    	c         C   s&   t  j |  j  } | s" t   n  d S(   s[   
        Use the platform-specific CA certificate locations

        :return: None
        N(   R/   t    SSL_CTX_set_default_verify_pathsR   R*   (   R(   t
   set_result(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_default_verify_paths0  s    c         C   s5   t  |  } t j |  j |  } | s1 t   n  d S(   s   
        Load a certificate chain from a file

        :param certfile: The name of the certificate chain file (``bytes`` or
            ``unicode``).

        :return: None
        N(   R   R/   t"   SSL_CTX_use_certificate_chain_fileR   R*   (   R(   t   certfileRD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   use_certificate_chain_file;  s
    	c         C   sV   t  |  } t | t  s* t d   n  t j |  j | |  } | sR t   n  d S(   s   
        Load a certificate from a file

        :param certfile: The name of the certificate file (``bytes`` or
            ``unicode``).
        :param filetype: (optional) The encoding of the file, default is PEM

        :return: None
        s   filetype must be an integerN(   R   Rc   R   Re   R/   t   SSL_CTX_use_certificate_fileR   R*   (   R(   R   t   filetypet
   use_result(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   use_certificate_fileL  s    
c         C   sJ   t  | t  s t d   n  t j |  j | j  } | sF t   n  d S(   ss   
        Load a certificate from a X509 object

        :param cert: The X509 object
        :return: None
        s   cert must be an X509 instanceN(   Rc   R   Re   R/   t   SSL_CTX_use_certificateR   R1   R*   (   R(   R>   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   use_certificate`  s
    c         C   sf   t  | t  s t d   n  t j | j  } t j |  j |  } | sb t j |  t	   n  d S(   s   
        Add certificate to chain

        :param certobj: The X509 certificate object to add to the chain
        :return: None
        s    certobj must be an X509 instanceN(
   Rc   R   Re   R/   t   X509_dupR1   t   SSL_CTX_add_extra_chain_certR   t	   X509_freeR*   (   R(   t   certobjt   copyt
   add_result(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   add_extra_chain_certn  s    c         C   sD   |  j  d  k r t   n  |  j  j t  } | d  k	 r@ |  n  d  S(   N(   R   Ri   R*   R,   R   (   R(   t	   exception(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _raise_passphrase_exception  s
    
c         C   sn   t  |  } | t k r! t } n t | t  s? t d   n  t j |  j | |  } | sj |  j	   n  d S(   s   
        Load a private key from a file

        :param keyfile: The name of the key file (``bytes`` or ``unicode``)
        :param filetype: (optional) The encoding of the file, default is PEM

        :return: None
        s   filetype must be an integerN(
   R   t   _UNSPECIFIEDR   Rc   R   Re   R/   t   SSL_CTX_use_PrivateKey_fileR   R   (   R(   t   keyfileR   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   use_privatekey_file  s    		c         C   sM   t  | t  s t d   n  t j |  j | j  } | sI |  j   n  d S(   ss   
        Load a private key from a PKey object

        :param pkey: The PKey object
        :return: None
        s   pkey must be a PKey instanceN(   Rc   R   Re   R/   t   SSL_CTX_use_PrivateKeyR   t   _pkeyR   (   R(   t   pkeyR   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   use_privatekey  s
    c         C   s    t  j |  j  s t   n  d S(   s   
        Check that the private key and certificate match up

        :return: None (raises an exception if something's wrong)
        N(   R/   t   SSL_CTX_check_private_keyR   R*   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   check_privatekey  s    c         C   sB   t  j t d |   } t | t j k  t  j |  j |  d S(   s%  
        Load the trusted certificates that will be sent to the client.  Does
        not actually imply any of the certificates are trusted; that must be
        configured separately.

        :param bytes cafile: The path to a certificates file in PEM format.
        :return: None
        R   N(   R/   t   SSL_load_client_CA_filet   _text_to_bytes_and_warnt   _openssl_assertRH   R   t   SSL_CTX_set_client_CA_listR   (   R(   R   t   ca_list(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   load_client_ca  s    	c         C   s;   t  d |  } t t j |  j | t |   d k  d S(   sV  
        Set the session id to *buf* within which a session can be reused for
        this Context object.  This is needed when doing session resumption,
        because there is no way for a stored session to know which Context
        object it is associated with.

        :param bytes buf: The session id.

        :returns: None
        t   bufi   N(   R   R   R/   t   SSL_CTX_set_session_id_contextR   RK   (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_session_id  s    c         C   s1   t  | t  s t d   n  t j |  j |  S(   s   
        Enable/disable session caching and specify the mode used.

        :param mode: One or more of the SESS_CACHE_* flags (combine using
            bitwise or)
        :returns: The previously set caching mode.
        s   mode must be an integer(   Rc   R   Re   R/   t   SSL_CTX_set_session_cache_modeR   (   R(   t   mode(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_session_cache_mode  s    c         C   s   t  j |  j  S(   s:   
        :returns: The currently used cache mode.
        (   R/   t   SSL_CTX_get_session_cache_modeR   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_session_cache_mode  s    c         C   st   t  | t  s t d   n  t |  s9 t d   n  t |  |  _ |  j j |  _ t j	 |  j
 | |  j  d S(   sG  
        Set the verify mode and verify callback

        :param mode: The verify mode, this is either VERIFY_NONE or
                     VERIFY_PEER combined with possible other flags
        :param callback: The Python callback to use
        :return: None

        See SSL_CTX_set_verify(3SSL) for further details.
        s   mode must be an integers   callback must be callableN(   Rc   R   Re   R   R-   R   RF   R   R/   t   SSL_CTX_set_verifyR   (   R(   R   RF   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt
   set_verify  s    c         C   s5   t  | t  s t d   n  t j |  j |  d S(   sz   
        Set the verify depth

        :param depth: An integer specifying the verify depth
        :return: None
        s   depth must be an integerN(   Rc   R   Re   R/   t   SSL_CTX_set_verify_depthR   (   R(   t   depth(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_verify_depth  s    c         C   s   t  j |  j  S(   sG   
        Get the verify mode

        :return: The verify mode
        (   R/   t   SSL_CTX_get_verify_modeR   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_verify_mode
  s    c         C   s   t  j |  j  S(   sI   
        Get the verify depth

        :return: The verify depth
        (   R/   t   SSL_CTX_get_verify_depthR   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_verify_depth  s    c         C   s   t  |  } t j | d  } | t j k r7 t   n  t j | t j  } t j | t j t j t j  } t j | t j	  } t j
 |  j |  d S(   s   
        Load parameters for Ephemeral Diffie-Hellman

        :param dhfile: The file to load EDH parameters from (``bytes`` or
            ``unicode``).

        :return: None
        t   rN(   R   R/   t   BIO_new_fileRH   R   R*   R   t   BIO_freet   PEM_read_bio_DHparamst   DH_freet   SSL_CTX_set_tmp_dhR   (   R(   t   dhfilet   biot   dh(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   load_tmp_dh  s    	
!c         C   s   t  j |  j | j    d S(   s  
        Select a curve to use for ECDHE key exchange.

        :param curve: A curve object to use as returned by either
            :py:meth:`OpenSSL.crypto.get_elliptic_curve` or
            :py:meth:`OpenSSL.crypto.get_elliptic_curves`.

        :return: None
        N(   R/   t   SSL_CTX_set_tmp_ecdhR   t
   _to_EC_KEY(   R(   t   curve(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_tmp_ecdh.  s    
c         C   sP   t  d |  } t | t  s- t d   n  t t j |  j |  d k  d S(   s   
        Set the list of ciphers to be used in this context.

        See the OpenSSL manual for more information (e.g.
        :manpage:`ciphers(1)`).

        :param bytes cipher_list: An OpenSSL cipher string.
        :return: None
        t   cipher_lists"   cipher_list must be a byte string.i   N(   R   Rc   t   bytesRe   R   R/   t   SSL_CTX_set_cipher_listR   (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_cipher_list:  s
    
c         C   s   t  j   } | t j k r% t   n  y x | D] } t | t  sc t d t |  j	 f   n  t  j
 | j  } | t j k r t   n  t  j | |  } | s/ t  j |  t   q/ q/ WWn t  j |    n Xt  j |  j |  d S(   s?  
        Set the list of preferred client certificate signers for this server
        context.

        This list of certificate authorities will be sent to the client when
        the server requests a client certificate.

        :param certificate_authorities: a sequence of X509Names.
        :return: None
        s3   client CAs must be X509Name objects, not %s objectsN(   R/   t   sk_X509_NAME_new_nullRH   R   R*   Rc   R   Re   Rr   R   t   X509_NAME_dupt   _namet   sk_X509_NAME_pusht   X509_NAME_freet   sk_X509_NAME_freeR   R   (   R(   t   certificate_authoritiest
   name_stackt   ca_nameR   t   push_result(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_client_ca_listM  s(    

c         C   sJ   t  | t  s t d   n  t j |  j | j  } | sF t   n  d S(   sI  
        Add the CA certificate to the list of preferred signers for this
        context.

        The list of certificate authorities will be sent to the client when the
        server requests a client certificate.

        :param certificate_authority: certificate authority's X509 certificate.
        :return: None
        s.   certificate_authority must be an X509 instanceN(   Rc   R   Re   R/   t   SSL_CTX_add_client_CAR   R1   R*   (   R(   t   certificate_authorityR   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   add_client_cat  s    c         C   s1   t  | t  s t d   n  t j |  j |  S(   s   
        Set session timeout

        :param timeout: The timeout in seconds
        :return: The previous session timeout
        s   timeout must be an integer(   Rc   R   Re   R/   t   SSL_CTX_set_timeoutR   (   R(   t   timeout(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_timeout  s    c         C   s   t  j |  j  S(   sO   
        Get the session timeout

        :return: The session timeout
        (   R/   t   SSL_CTX_get_timeoutR   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_timeout  s    c            sJ   t       f d    } t j d |  |  _ t j |  j |  j  d S(   sr   
        Set the info callback

        :param callback: The Python callback to use
        :return: None
        c            s     t  j |  | |  d  S(   N(   R6   R7   (   RB   t   wheret   return_code(   RF   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG     s    s   void (*)(const SSL *, int, int)N(   R   RH   RF   R   R/   t   SSL_CTX_set_info_callbackR   (   R(   RF   RG   (    (   RF   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_info_callback  s    c         C   s   |  j  S(   so   
        Get the application data (supplied via set_app_data())

        :return: The application data
        (   R   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_app_data  s    c         C   s   | |  _  d S(   s   
        Set the application data (will be returned from get_app_data())

        :param data: Any Python object
        :return: None
        N(   R   (   R(   t   data(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_app_data  s    c         C   sA   t  j |  j  } | t j k r% d St j t  } | | _ | S(   s   
        Get the certificate store for the context.

        :return: A X509Store object or None if it does not have one.
        N(	   R/   t   SSL_CTX_get_cert_storeR   RH   R   Ri   R   R.   t   _store(   R(   t   storet   pystore(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_cert_store  s    	c         C   s1   t  | t  s t d   n  t j |  j |  S(   s   
        Add options. Options set before are not cleared!

        :param options: The options to add.
        :return: The new option bitmask.
        s   options must be an integer(   Rc   R   Re   R/   t   SSL_CTX_set_optionsR   (   R(   t   options(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_options  s    c         C   s1   t  | t  s t d   n  t j |  j |  S(   s   
        Add modes via bitmask. Modes set before are not cleared!

        :param mode: The mode to add.
        :return: The new mode bitmask.
        s   mode must be an integer(   Rc   R   Re   R/   t   SSL_CTX_set_modeR   (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR     s    c            sJ   t       f d    } t j d |  |  _ t j |  j |  j  d S(   s   
        Specify a callback function to be called when clients specify a server
        name.

        :param callback: The callback function.  It will be invoked with one
            argument, the Connection instance.
        c            s     t  j |   d S(   Ni    (   R6   R7   (   RB   t   alertRT   (   RF   (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRG     s    s#   int (*)(const SSL *, int *, void *)N(   R   RH   RF   R   R/   t&   SSL_CTX_set_tlsext_servername_callbackR   (   R(   RF   RG   (    (   RF   s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_tlsext_servername_callback  s
    c         C   s>   t  |  |  _ |  j j |  _ t j |  j |  j t j  d S(   s  
        Specify a callback function that will be called when offering `Next
        Protocol Negotiation
        <https://technotes.googlecode.com/git/nextprotoneg.html>`_ as a server.

        :param callback: The callback function.  It will be invoked with one
            argument, the Connection instance.  It should return a list of
            bytestrings representing the advertised protocols, like
            ``[b'http/1.1', b'spdy/2']``.
        N(	   RI   R   RF   R   R/   t%   SSL_CTX_set_next_protos_advertised_cbR   RH   R   (   R(   RF   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_npn_advertise_callback  s    c         C   s>   t  |  |  _ |  j j |  _ t j |  j |  j t j  d S(   s  
        Specify a callback function that will be called when a server offers
        Next Protocol Negotiation options.

        :param callback: The callback function.  It will be invoked with two
            arguments: the Connection, and a list of offered protocols as
            bytestrings, e.g. ``[b'http/1.1', b'spdy/2']``.  It should return
            one of those bytestrings, the chosen protocol.
        N(	   RX   R   RF   R   R/   t    SSL_CTX_set_next_proto_select_cbR   RH   R   (   R(   RF   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_npn_select_callback  s    c         C   sf   d j  t j d   | D   } t j d |  } t j d t |   } t j |  j	 | |  d S(   sg  
        Specify the clients ALPN protocol list.

        These protocols are offered to the server during protocol negotiation.

        :param protos: A list of the protocols to be offered to the server.
            This list should be a Python list of bytestrings representing the
            protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
        RJ   c         s   s'   |  ] } t  t |   | f Vq d  S(   N(   R	   RK   (   RL   RM   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pys	   <genexpr>#  s    s   unsigned char[]t   unsignedN(
   RN   R   RO   RH   RP   t   castRK   R/   t   SSL_CTX_set_alpn_protosR   (   R(   RV   RW   t	   input_strt   input_str_len(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_alpn_protos  s
    c         C   s>   t  |  |  _ |  j j |  _ t j |  j |  j t j  d S(   sb  
        Set the callback to handle ALPN protocol choice.

        :param callback: The callback function.  It will be invoked with two
            arguments: the Connection, and a list of offered protocols as
            bytestrings, e.g ``[b'http/1.1', b'spdy/2']``.  It should return
            one of those bytestrings, the chosen protocol.
        N(	   Rb   R   RF   R   R/   t   SSL_CTX_set_alpn_select_cbR   RH   R   (   R(   RF   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_alpn_select_callback,  s    
N(8   R   R   R    t   SSLv2_METHODt   SSLv3_METHODt   SSLv23_METHODt   TLSv1_METHODt   TLSv1_1_METHODt   TLSv1_2_METHODR   t   dictt   itemsR)   Ri   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  Rx   R  R!  Rz   R'  R)  (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR|     sd   
	.																					'											R6   c           B   s6  e  Z d  Z e   Z d9 d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	 d
  Z e Z d	 d  Z d9 d  Z e Z d9 d9 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d    Z& d!   Z' d"   Z( d#   Z) d$   Z* d%   Z+ d&   Z, d'   Z- d(   Z. d)   Z/ d*   Z0 d+   Z1 d,   Z2 d-   Z3 d.   Z4 d/   Z5 d0   Z6 d1   Z7 d2   Z8 d3   Z9 d4   Z: d5   Z; e< d6    Z= e> d7    Z? e> d8    Z@ RS(:   s   
    c         C   sd  t  | t  s t d   n  t j | j  } t j | t j  |  _	 | |  _ d |  _ d |  _ d |  _ d |  _ |  |  j |  j	 <| d k rd |  _ t j t j    |  _ t j t j    |  _ |  j t j k s |  j t j k r t   n  t j |  j	 |  j |  j  nI d |  _ d |  _ | |  _ t j |  j	 t |  j   } | s`t   n  d S(   s   
        Create a new Connection object, using the given OpenSSL.SSL.Context
        instance and socket.

        :param context: An SSL Context to use for this connection
        :param socket: The socket to use for transport layer
        s"   context must be a Context instanceN(   Rc   R|   Re   R/   t   SSL_newR   RH   R   t   SSL_freet   _sslRi   R   RQ   RZ   Rf   R7   t   _sockett   BIO_newt	   BIO_s_memt	   _into_sslt	   _from_sslR   R*   t   SSL_set_biot
   SSL_set_fdRo   (   R(   R   t   socketRB   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR)   C  s0    						$
			c         C   sB   |  j  d k r. t d |  j j | f   n t |  j  |  Sd S(   sy   
        Look up attributes on the wrapped socket object if they are not found
        on the Connection object.
        s!   '%s' object has no attribute '%s'N(   R5  Ri   t   AttributeErrort	   __class__R   Rj   (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   __getattr__w  s    c         C   s  |  j  j d  k	 r% |  j  j j   n  |  j  j d  k	 rJ |  j  j j   n  |  j  j d  k	 ro |  j  j j   n  |  j  j d  k	 r |  j  j j   n  t j | |  } | t j	 k r t
    n | t j k r t    n | t j k r t    n | t j k rt    n | t j k rt j   d k r| d k  rt d k r^t j   d } n	 t j } t | t j |    qt d d   qt   n | t j k rn t   d  S(   Ni    t   win32is   Unexpected EOF(   R   R   Ri   R,   R   R   R   R/   t   SSL_get_errort   SSL_ERROR_WANT_READR!   t   SSL_ERROR_WANT_WRITER"   t   SSL_ERROR_ZERO_RETURNR$   t   SSL_ERROR_WANT_X509_LOOKUPR#   t   SSL_ERROR_SYSCALLt   ERR_peek_errorR    RH   t   getwinerrort   errnoR%   R   t   getR*   t   SSL_ERROR_NONE(   R(   RB   RD   t   errorRI  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _raise_ssl_error  s:    	
c         C   s   |  j  S(   s%   
        Get session context
        (   R   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_context  s    c         C   sA   t  | t  s t d   n  t j |  j | j  | |  _ d S(   s   
        Switch this connection to a new session context

        :param context: A :py:class:`Context` instance giving the new session
            context to use.
        s"   context must be a Context instanceN(   Rc   R|   Re   R/   t   SSL_set_SSL_CTXR4  R   (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_context  s    c         C   s8   t  j |  j t  j  } | t j k r+ d St j |  S(   s   
        Retrieve the servername extension value if provided in the client hello
        message, or None if there wasn't one.

        :return: A byte string giving the server name or :py:data:`None`.
        N(   R/   t   SSL_get_servernameR4  t   TLSEXT_NAMETYPE_host_nameRH   R   Ri   Rp   (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_servername  s
    c         C   sP   t  | t  s t d   n d | k r9 t d   n  t j |  j |  d S(   s   
        Set the value of the servername extension to send in the client hello.

        :param name: A byte string giving the name.
        s   name must be a byte stringt    s   name must not contain NUL byteN(   Rc   R   Re   R/   t   SSL_set_tlsext_host_nameR4  (   R(   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_tlsext_host_name  s
    c         C   s   t  j |  j  S(   s   
        Get the number of bytes that can be safely read from the connection

        :return: The number of bytes available in the receive buffer.
        (   R/   t   SSL_pendingR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   pending  s    i    c         C   s   t  d |  } t | t  r- | j   } n  t | t  rK t |  } n  t | t  si t d   n  t j	 |  j
 | t |   } |  j |  j
 |  | S(   s  
        Send data on the connection. NOTE: If you get one of the WantRead,
        WantWrite or WantX509Lookup exceptions on this, you have to call the
        method again with the SAME buffer.

        :param buf: The string, buffer or memoryview to send
        :param flags: (optional) Included for compatibility with the socket
                      API, the value is ignored
        :return: The number of bytes written
        R   s0   data must be a memoryview, buffer or byte string(   R   Rc   R   t   tobytesR   t   strR   Re   R/   t	   SSL_writeR4  RK   RM  (   R(   R   t   flagsRD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   send  s    c         C   s   t  d |  } t | t  r- | j   } n  t | t  rK t |  } n  t | t  si t d   n  t |  } d } t	 j
 d |  } xM | r t j |  j | | |  } |  j |  j |  | | 7} | | 8} q Wd S(   s  
        Send "all" data on the connection. This calls send() repeatedly until
        all data is sent. If an error occurs, it's impossible to tell how much
        data has been sent.

        :param buf: The string, buffer or memoryview to send
        :param flags: (optional) Included for compatibility with the socket
                      API, the value is ignored
        :return: The number of bytes written
        R   s/   buf must be a memoryview, buffer or byte stringi    s   char[]N(   R   Rc   R   RY  R   RZ  R   Re   RK   RH   RP   R/   R[  R4  RM  (   R(   R   R\  t   left_to_sendt
   total_sentR  RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   sendall  s    	
c         C   s   t  j d |  } | d k	 rF | t j @rF t j |  j | |  } n t j |  j | |  } |  j	 |  j |  t  j
 | |  S(   s  
        Receive data on the connection. NOTE: If you get one of the WantRead,
        WantWrite or WantX509Lookup exceptions on this, you have to call the
        method again with the SAME buffer.

        :param bufsiz: The maximum number of bytes to read
        :param flags: (optional) The only supported flag is ``MSG_PEEK``,
            all other flags are ignored.
        :return: The string read from the Connection
        s   char[]N(   RH   RP   Ri   R<  t   MSG_PEEKR/   t   SSL_peekR4  t   SSL_readRM  RY   (   R(   t   bufsizR\  R   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   recv  s    c         C   s   | d k r t |  } n t | t |   } t j d |  } | d k	 rv | t j @rv t j |  j	 | |  } n t j
 |  j	 | |  } |  j |  j	 |  y  t t j | |   | | *Wn' t k
 r t j | |  | | *n X| S(   sW  
        Receive data on the connection and store the data into a buffer rather
        than creating a new string.

        :param buffer: The buffer to copy into.
        :param nbytes: (optional) The maximum number of bytes to read into the
            buffer. If not present, defaults to the size of the buffer. If
            larger than the size of the buffer, is reduced to the size of the
            buffer.
        :param flags: (optional) The only supported flag is ``MSG_PEEK``,
            all other flags are ignored.
        :return: The number of bytes read into the buffer.
        s   char[]N(   Ri   RK   t   minRH   RP   R<  Ra  R/   Rb  R4  Rc  RM  t
   memoryviewRY   t	   NameError(   R(   RY   t   nbytesR\  R   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt	   recv_into-  s     c         C   s}   t  j |  rr t  j |  r* t    qy t  j |  rE t    qy t  j |  rc t d   qy t d   n t   d  S(   Nt   BIO_should_io_specials   unknown bio failure(	   R/   t   BIO_should_retryt   BIO_should_readR!   t   BIO_should_writeR"   Rk  Rk   R*   (   R(   R   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _handle_bio_errorsV  s    c         C   s   |  j  d k r t d   n  t | t  s< t d   n  t j d |  } t j |  j  | |  } | d k r |  j	 |  j  |  n  t j
 | |  S(   s   
        When using non-socket connections this function reads the "dirty" data
        that would have traveled away on the network.

        :param bufsiz: The maximum number of bytes to read
        :return: The string read.
        s   Connection sock was not Nones   bufsiz must be an integers   char[]i    N(   R9  Ri   Re   Rc   R   RH   RP   R/   t   BIO_readRo  RY   (   R(   Rd  R   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   bio_readh  s    c         C   sq   t  d |  } |  j d k r- t d   n  t j |  j | t |   } | d k rm |  j |  j |  n  | S(   s   
        When using non-socket connections this function sends "dirty" data that
        would have traveled in on the network.

        :param buf: The string to put into the memory BIO.
        :return: The number of bytes written
        R   s   Connection sock was not Nonei    N(   R   R8  Ri   Re   R/   t	   BIO_writeRK   Ro  (   R(   R   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt	   bio_write}  s    c         C   s0   |  j    s, t t j |  j  d k  t St S(   s   
        Renegotiate the session.

        :return: True if the renegotiation can be started, False otherwise
        :rtype: bool
        i   (   t   renegotiate_pendingR   R/   t   SSL_renegotiateR4  R   t   False(   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   renegotiate  s    c         C   s)   t  j |  j  } |  j |  j |  d S(   s   
        Perform an SSL handshake (usually called after renegotiate() or one of
        set_*_state()). This can raise the same exceptions as send and recv.

        :return: None.
        N(   R/   t   SSL_do_handshakeR4  RM  (   R(   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   do_handshake  s    c         C   s   t  j |  j  d k S(   s   
        Check if there's a renegotiation in progress, it will return False once
        a renegotiation is finished.

        :return: Whether there's a renegotiation in progress
        :rtype: bool
        i   (   R/   t   SSL_renegotiate_pendingR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyRt    s    c         C   s   t  j |  j  S(   s   
        Find out the total number of renegotiations.

        :return: The number of renegotiations.
        :rtype: int
        (   R/   t   SSL_total_renegotiationsR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   total_renegotiations  s    c         C   s    t  j |  j  |  j j |  S(   s   
        Connect to remote host and set up client-side SSL

        :param addr: A remote address
        :return: What the socket's connect method returns
        (   R/   t   SSL_set_connect_stateR4  R5  t   connect(   R(   t   addr(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR~    s    c         C   s    |  j  j } |  j   | |  S(   s  
        Connect to remote host and set up client-side SSL. Note that if the
        socket's connect_ex method doesn't return 0, SSL won't be initialized.

        :param addr: A remove address
        :return: What the socket's connect_ex method returns
        (   R5  t
   connect_ext   set_connect_state(   R(   R  R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR    s    
c         C   s;   |  j  j   \ } } t |  j |  } | j   | | f S(   s   
        Accept incoming connection and set up SSL on it

        :return: A (conn,addr) pair where conn is a Connection and addr is an
                 address
        (   R5  t   acceptR6   R   t   set_accept_state(   R(   t   clientR  RU   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR    s    
c         C   s5   |  j  d k r t d   n  t j |  j d  d S(   s   
        When using non-socket connections this function signals end of
        data on the input for this connection.

        :return: None
        s   Connection sock was not Nonei    N(   R9  Ri   Re   R/   t   BIO_set_mem_eof_returnR8  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   bio_shutdown  s    c         C   sL   t  j |  j  } | d k  r4 |  j |  j |  n | d k rD t St Sd S(   s  
        Send closure alert

        :return: True if the shutdown completed successfully (i.e. both sides
                 have sent closure alerts), false otherwise (i.e. you have to
                 wait for a ZeroReturnError on a recv() method call
        i    N(   R/   t   SSL_shutdownR4  RM  R   Rv  (   R(   RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   shutdown  s    c         C   sb   g  } xU t    D]J } t j |  j |  } | t j k r> Pn  | j t t j |    q W| S(   s   
        Retrieve the list of ciphers used by the Connection object.

        :return: A list of native cipher strings.
        (	   R   R/   t   SSL_get_cipher_listR4  RH   R   R9   t   _nativeRp   (   R(   t   cipherst   iRD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_cipher_list  s     c         C   s   t  j |  j  } | t j k r% g  Sg  } x t t  j |   D]t } t  j | |  } t  j |  } | t j k r t	   n  t
 j t
  } t j | t  j  | _ | j |  qA W| S(   s  
        Get CAs whose certificates are suggested for client authentication.

        :return: If this is a server connection, a list of X509Names
            representing the acceptable CAs as set by
            :py:meth:`OpenSSL.SSL.Context.set_client_ca_list` or
            :py:meth:`OpenSSL.SSL.Context.add_client_ca`.  If this is a client
            connection, the list of such X509Names sent by the server, or an
            empty list if that has not yet happened.
        (   R/   t   SSL_get_client_CA_listR4  RH   R   t   ranget   sk_X509_NAME_numt   sk_X509_NAME_valueR   R*   R   R.   R   R   R   R9   (   R(   t   ca_namesRD   R  R   R   t   pyname(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_client_ca_list  s    
c         C   s   t  d   d S(   s   
        The makefile() method is not implemented, since there is no dup
        semantics for SSL connections

        :raise: NotImplementedError
        s1   Cannot make file object of OpenSSL.SSL.ConnectionN(   Rt   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   makefile!  s    c         C   s   |  j  S(   sM   
        Get application data

        :return: The application data
        (   R   (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR  +  s    c         C   s   | |  _  d S(   sh   
        Set application data

        :param data - The application data
        :return: None
        N(   R   (   R(   R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR  3  s    c         C   s   t  j |  j  S(   s   
        Get shutdown state

        :return: The shutdown state, a bitvector of SENT_SHUTDOWN,
            RECEIVED_SHUTDOWN.
        (   R/   t   SSL_get_shutdownR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_shutdown<  s    c         C   s5   t  | t  s t d   n  t j |  j |  d S(   s   
        Set shutdown state

        :param state - bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
        :return: None
        s   state must be an integerN(   Rc   R   Re   R/   t   SSL_set_shutdownR4  (   R(   t   state(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_shutdownE  s    c         C   s   t  j t j |  j   S(   s   
        Retrieve a verbose string detailing the state of the Connection.

        :return: A string representing the state
        :rtype: bytes
        (   RH   Rp   R/   t   SSL_state_string_longR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_state_stringQ  s    c         C   s6   |  j  j t j k r d St j |  j  j j t j	  S(   si   
        Get a copy of the server hello nonce.

        :return: A string representing the state
        N(
   R4  t   sessionRH   R   Ri   RY   t   s3t   server_randomR/   t   SSL3_RANDOM_SIZE(   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR  Z  s
    c         C   s6   |  j  j t j k r d St j |  j  j j t j	  S(   si   
        Get a copy of the client hello nonce.

        :return: A string representing the state
        N(
   R4  R  RH   R   Ri   RY   R  t   client_randomR/   R  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR  f  s
    c         C   s<   |  j  j t j k r d St j |  j  j j |  j  j j  S(   sa   
        Get a copy of the master key.

        :return: A string representing the state
        N(   R4  R  RH   R   Ri   RY   t
   master_keyt   master_key_length(   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR  r  s
    c         O   s   |  j  j | |   S(   s_   
        See shutdown(2)

        :return: What the socket's shutdown() method returns
        (   R5  R  (   R(   Ru   Rv   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   sock_shutdown~  s    c         C   sP   t  j |  j  } | t j k rL t j t  } t j | t  j  | _	 | Sd S(   si   
        Retrieve the other side's certificate (if any)

        :return: The peer's certificate
        N(   R/   t   SSL_get_peer_certificateR4  RH   R   R   R.   R   R   R1   Ri   (   R(   R>   t   pycert(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_peer_certificate  s    c         C   s   t  j |  j  } | t j k r% d Sg  } xl t t  j |   D]U } t  j t  j	 | |   } t
 j t
  } t j | t  j  | _ | j |  qA W| S(   s   
        Retrieve the other side's certificate (if any)

        :return: A list of X509 instances giving the peer's certificate chain,
                 or None if it does not have one.
        N(   R/   t   SSL_get_peer_cert_chainR4  RH   R   Ri   R  t   sk_X509_numR   t   sk_X509_valueR   R.   R   R   R1   R9   (   R(   t
   cert_stackRD   R  R>   R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_peer_cert_chain  s    c         C   s   t  j |  j  S(   s   
        Checks if more data has to be read from the transport layer to complete
        an operation.

        :return: True iff more data has to be read
        (   R/   t   SSL_want_readR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt	   want_read  s    c         C   s   t  j |  j  S(   s   
        Checks if there is data to write to the transport layer to complete an
        operation.

        :return: True iff there is data to write
        (   R/   t   SSL_want_writeR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt
   want_write  s    c         C   s   t  j |  j  d S(   s   
        Set the connection to work in server mode. The handshake will be
        handled automatically by read/write.

        :return: None
        N(   R/   t   SSL_set_accept_stateR4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR    s    c         C   s   t  j |  j  d S(   s   
        Set the connection to work in client mode. The handshake will be
        handled automatically by read/write.

        :return: None
        N(   R/   R}  R4  (   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR    s    c         C   sP   t  j |  j  } | t j k r% d St j t  } t j | t  j	  | _
 | S(   s   
        Returns the Session currently used.

        @return: An instance of :py:class:`OpenSSL.SSL.Session` or
            :py:obj:`None` if no session exists.
        N(   R/   t   SSL_get1_sessionR4  RH   R   Ri   R{   R.   R   t   SSL_SESSION_freet   _session(   R(   R  t	   pysession(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_session  s    c         C   sJ   t  | t  s t d   n  t j |  j | j  } | sF t   n  d S(   s   
        Set the session to be used when the TLS/SSL connection is established.

        :param session: A Session instance representing the session to use.
        :returns: None
        s"   session must be a Session instanceN(   Rc   R{   Re   R/   t   SSL_set_sessionR4  R  R*   (   R(   R  RD   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   set_session  s
    c         C   sm   t  j d d  } | |  j | d  } | d k r7 d St  j d |  } | |  j | |  t  j | |  S(   s  
        Helper to implement :py:meth:`get_finished` and
        :py:meth:`get_peer_finished`.

        :param function: Either :py:data:`SSL_get_finished`: or
            :py:data:`SSL_get_peer_finished`.

        :return: :py:data:`None` if the desired message has not yet been
            received, otherwise the contents of the message.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`
        s   char[]i    N(   RH   RP   R4  Ri   RY   (   R(   t   functiont   emptyR   R   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   _get_finished_message  s    c         C   s   |  j  t j  S(   s  
        Obtain the latest `handshake finished` message sent to the peer.

        :return: The contents of the message or :py:obj:`None` if the TLS
            handshake has not yet completed.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`
        (   R  R/   t   SSL_get_finished(   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_finished
  s    c         C   s   |  j  t j  S(   s
  
        Obtain the latest `handshake finished` message received from the peer.

        :return: The contents of the message or :py:obj:`None` if the TLS
            handshake has not yet completed.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`
        (   R  R/   t   SSL_get_peer_finished(   R(   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_peer_finished  s    c         C   sN   t  j |  j  } | t j k r% d St j t  j |   } | j d  Sd S(   s   
        Obtain the name of the currently used cipher.

        :returns: The name of the currently used cipher or :py:obj:`None`
            if no connection has been established.
        :rtype: :py:class:`unicode` or :py:class:`NoneType`
        s   utf-8N(	   R/   t   SSL_get_current_cipherR4  RH   R   Ri   Rp   t   SSL_CIPHER_get_namet   decode(   R(   t   cipherR   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_cipher_name  s
    c         C   s<   t  j |  j  } | t j k r% d St  j | t j  Sd S(   s  
        Obtain the number of secret bits of the currently used cipher.

        :returns: The number of secret bits of the currently used cipher
            or :py:obj:`None` if no connection has been established.
        :rtype: :py:class:`int` or :py:class:`NoneType`
        N(   R/   R  R4  RH   R   Ri   t   SSL_CIPHER_get_bits(   R(   R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_cipher_bits-  s    c         C   sN   t  j |  j  } | t j k r% d St j t  j |   } | j d  Sd S(   s  
        Obtain the protocol version of the currently used cipher.

        :returns: The protocol name of the currently used cipher
            or :py:obj:`None` if no connection has been established.
        :rtype: :py:class:`unicode` or :py:class:`NoneType`
        s   utf-8N(	   R/   R  R4  RH   R   Ri   Rp   t   SSL_CIPHER_get_versionR  (   R(   R  t   version(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_cipher_version;  s
    c         C   s(   t  j t j |  j   } | j d  S(   s?  
        Obtain the protocol version of the current connection.

        :returns: The TLS version of the current connection, for example
            the value for TLS 1.2 would be ``TLSv1.2``or ``Unknown``
            for connections that were not successfully established.
        :rtype: :py:class:`unicode`
        s   utf-8(   RH   Rp   R/   t   SSL_get_versionR4  R  (   R(   R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_protocol_version_nameJ  s    	c         C   s   t  j |  j  } | S(   s   
        Obtain the protocol version of the current connection.

        :returns: The TLS version of the current connection, for example
            the value for TLS 1 would be 0x769.
        :rtype: :py:class:`int`
        (   R/   t   SSL_versionR4  (   R(   R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_protocol_versionV  s    c         C   sM   t  j d  } t  j d  } t j |  j | |  t  j | d | d  S(   s>   
        Get the protocol that was negotiated by NPN.
        s   unsigned char **s   unsigned int *i    (   RH   RP   R/   t   SSL_get0_next_proto_negotiatedR4  RY   (   R(   R  t   data_len(    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_next_proto_negotiateda  s    c         C   sf   d j  t j d   | D   } t j d |  } t j d t |   } t j |  j	 | |  d S(   sh  
        Specify the client's ALPN protocol list.

        These protocols are offered to the server during protocol negotiation.

        :param protos: A list of the protocols to be offered to the server.
            This list should be a Python list of bytestrings representing the
            protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
        RJ   c         s   s'   |  ] } t  t |   | f Vq d  S(   N(   R	   RK   (   RL   RM   (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pys	   <genexpr>{  s    s   unsigned char[]R"  N(
   RN   R   RO   RH   RP   R#  RK   R/   t   SSL_set_alpn_protosR4  (   R(   RV   RW   R%  R&  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR'  m  s
    c         C   sW   t  j d  } t  j d  } t j |  j | |  | s> d St  j | d | d  S(   s?   
        Get the protocol that was negotiated by ALPN.
        s   unsigned char **s   unsigned int *RJ   i    (   RH   RP   R/   t   SSL_get0_alpn_selectedR4  RY   (   R(   R  R  (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   get_alpn_proto_negotiated  s    N(A   R   R   R    R   R7   Ri   R)   R?  RM  RN  RP  RS  RV  RX  R]  t   writeR`  Re  t   readRj  Ro  Rq  Rs  Rw  Ry  Rt  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  Rx   R  Rz   R'  R  (    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyR6   >  sv   	4		&					)					
	
			
							
																									"	
	
					(   R<  t   sysR    t	   functoolsR   R   t	   itertoolsR   R   t   weakrefR   RI  R   t   sixR   Rd   R   R	   R
   t   OpenSSL._utilR   R   R   t   _exception_from_error_queueR   RH   R   R/   R   t   _make_assertR   R  R   R   R   R   t   OpenSSL.cryptoR   R   R   R   R   R   Rg  R   Rh  t   objectRY   R   t   OPENSSL_VERSION_NUMBERt   SSLEAY_VERSIONt   SSLEAY_CFLAGSt   SSLEAY_PLATFORMt
   SSLEAY_DIRt   SSLEAY_BUILT_ONt   SSL_SENT_SHUTDOWNt   SENT_SHUTDOWNt   SSL_RECEIVED_SHUTDOWNt   RECEIVED_SHUTDOWNR*  R+  R,  R-  R.  R/  t   SSL_OP_NO_SSLv2t   OP_NO_SSLv2t   SSL_OP_NO_SSLv3t   OP_NO_SSLv3t   SSL_OP_NO_TLSv1t   OP_NO_TLSv1Rj   t   OP_NO_TLSv1_1t   OP_NO_TLSv1_2t   SSL_MODE_RELEASE_BUFFERSt   MODE_RELEASE_BUFFERSR=  t   SSL_OP_SINGLE_DH_USEt   OP_SINGLE_DH_USEt   SSL_OP_SINGLE_ECDH_USEt   OP_SINGLE_ECDH_USEt   SSL_OP_EPHEMERAL_RSAt   OP_EPHEMERAL_RSAt   SSL_OP_MICROSOFT_SESS_ID_BUGt   OP_MICROSOFT_SESS_ID_BUGt   SSL_OP_NETSCAPE_CHALLENGE_BUGt   OP_NETSCAPE_CHALLENGE_BUGt'   SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGt#   OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGt"   SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUGt   OP_SSLREF2_REUSE_CERT_TYPE_BUGt!   SSL_OP_MICROSOFT_BIG_SSLV3_BUFFERt   OP_MICROSOFT_BIG_SSLV3_BUFFERt   SSL_OP_MSIE_SSLV2_RSA_PADDINGt   OP_MSIE_SSLV2_RSA_PADDINGt   SSL_OP_SSLEAY_080_CLIENT_DH_BUGt   OP_SSLEAY_080_CLIENT_DH_BUGt   SSL_OP_TLS_D5_BUGt   OP_TLS_D5_BUGt   SSL_OP_TLS_BLOCK_PADDING_BUGt   OP_TLS_BLOCK_PADDING_BUGt"   SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSt   OP_DONT_INSERT_EMPTY_FRAGMENTSt   SSL_OP_CIPHER_SERVER_PREFERENCEt   OP_CIPHER_SERVER_PREFERENCEt   SSL_OP_TLS_ROLLBACK_BUGt   OP_TLS_ROLLBACK_BUGt   SSL_OP_PKCS1_CHECK_1t   OP_PKCS1_CHECK_1t   SSL_OP_PKCS1_CHECK_2t   OP_PKCS1_CHECK_2t   SSL_OP_NETSCAPE_CA_DN_BUGt   OP_NETSCAPE_CA_DN_BUGt&   SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGt"   OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGt   SSL_OP_NO_COMPRESSIONt   OP_NO_COMPRESSIONt   SSL_OP_NO_QUERY_MTUt   OP_NO_QUERY_MTUt   SSL_OP_COOKIE_EXCHANGEt   OP_COOKIE_EXCHANGEt   SSL_OP_NO_TICKETt   OP_NO_TICKETt
   SSL_OP_ALLt   OP_ALLt   SSL_VERIFY_PEERt   VERIFY_PEERt   SSL_VERIFY_FAIL_IF_NO_PEER_CERTt   VERIFY_FAIL_IF_NO_PEER_CERTt   SSL_VERIFY_CLIENT_ONCEt   VERIFY_CLIENT_ONCEt   SSL_VERIFY_NONEt   VERIFY_NONEt   SSL_SESS_CACHE_OFFt   SESS_CACHE_OFFt   SSL_SESS_CACHE_CLIENTt   SESS_CACHE_CLIENTt   SSL_SESS_CACHE_SERVERt   SESS_CACHE_SERVERt   SSL_SESS_CACHE_BOTHt   SESS_CACHE_BOTHt   SSL_SESS_CACHE_NO_AUTO_CLEARt   SESS_CACHE_NO_AUTO_CLEARt!   SSL_SESS_CACHE_NO_INTERNAL_LOOKUPt   SESS_CACHE_NO_INTERNAL_LOOKUPt    SSL_SESS_CACHE_NO_INTERNAL_STOREt   SESS_CACHE_NO_INTERNAL_STOREt   SSL_SESS_CACHE_NO_INTERNALt   SESS_CACHE_NO_INTERNALt   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_DONER8   R   R*   R   R!   R"   R#   R$   R%   R&   R-   RI   RX   Rb   Ro   Rq   Rx   Rz   R{   R|   t   ContextTypeR6   t   ConnectionTypet   SSL_library_init(    (    (    s/   /usr/lib/python2.7/dist-packages/OpenSSL/SSL.pyt   <module>   s  :.

																																																																&)13					     Y