Sophie

Sophie

distrib > Mageia > 6 > armv7hl > by-pkgid > be48589b7b9611719bcc10d42dba172d > files > 76

python-OpenSSL-doc-16.1.0-1.mga6.noarch.rpm



<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>SSL — An interface to the SSL-specific parts of OpenSSL &mdash; pyOpenSSL 16.1.0 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="pyOpenSSL 16.1.0 documentation" href="../index.html"/>
        <link rel="up" title="OpenSSL — Python interface to OpenSSL" href="../api.html"/>
        <link rel="next" title="Internals" href="../internals.html"/>
        <link rel="prev" title="rand — An interface to the OpenSSL pseudo random number generator" href="rand.html"/> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> pyOpenSSL
          

          
          </a>

          
            
            
              <div class="version">
                16.1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">Installation</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../api.html"><code class="docutils literal"><span class="pre">OpenSSL</span></code> &#8212; Python interface to OpenSSL</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="crypto.html"><code class="docutils literal"><span class="pre">crypto</span></code> &#8212; Generic cryptographic module</a></li>
<li class="toctree-l2"><a class="reference internal" href="rand.html"><code class="docutils literal"><span class="pre">rand</span></code> &#8212; An interface to the OpenSSL pseudo random number generator</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#"><code class="docutils literal"><span class="pre">SSL</span></code> &#8212; An interface to the SSL-specific parts of OpenSSL</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#context-objects">Context objects</a></li>
<li class="toctree-l3"><a class="reference internal" href="#session-objects">Session objects</a></li>
<li class="toctree-l3"><a class="reference internal" href="#connection-objects">Connection objects</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../internals.html">Internals</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../backward-compatibility.html">Backward Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="../changelog.html">Changelog</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">pyOpenSSL</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          

 



<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../api.html"><code class="docutils literal"><span class="pre">OpenSSL</span></code> &#8212; Python interface to OpenSSL</a> &raquo;</li>
      
    <li><code class="docutils literal"><span class="pre">SSL</span></code> &#8212; An interface to the SSL-specific parts of OpenSSL</li>
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../_sources/api/ssl.txt" rel="nofollow"> View page source</a>
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="module-OpenSSL.SSL">
<span id="ssl-an-interface-to-the-ssl-specific-parts-of-openssl"></span><span id="openssl-ssl"></span><h1><code class="xref py py-mod docutils literal"><span class="pre">SSL</span></code> &#8212; An interface to the SSL-specific parts of OpenSSL<a class="headerlink" href="#module-OpenSSL.SSL" title="Permalink to this headline">¶</a></h1>
<p>This module handles things specific to SSL. There are two objects defined:
Context, Connection.</p>
<dl class="data">
<dt id="OpenSSL.SSL.SSLv2_METHOD">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLv2_METHOD</code><a class="headerlink" href="#OpenSSL.SSL.SSLv2_METHOD" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SSLv3_METHOD">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLv3_METHOD</code><a class="headerlink" href="#OpenSSL.SSL.SSLv3_METHOD" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SSLv23_METHOD">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLv23_METHOD</code><a class="headerlink" href="#OpenSSL.SSL.SSLv23_METHOD" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.TLSv1_METHOD">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">TLSv1_METHOD</code><a class="headerlink" href="#OpenSSL.SSL.TLSv1_METHOD" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.TLSv1_1_METHOD">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">TLSv1_1_METHOD</code><a class="headerlink" href="#OpenSSL.SSL.TLSv1_1_METHOD" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.TLSv1_2_METHOD">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">TLSv1_2_METHOD</code><a class="headerlink" href="#OpenSSL.SSL.TLSv1_2_METHOD" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants represent the different SSL methods to use when creating a
context object.  If the underlying OpenSSL build is missing support for any
of these protocols, constructing a <a class="reference internal" href="#OpenSSL.SSL.Context" title="OpenSSL.SSL.Context"><code class="xref py py-class docutils literal"><span class="pre">Context</span></code></a> using the
corresponding <code class="xref py py-const docutils literal"><span class="pre">*_METHOD</span></code> will raise an exception.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.VERIFY_NONE">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">VERIFY_NONE</code><a class="headerlink" href="#OpenSSL.SSL.VERIFY_NONE" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.VERIFY_PEER">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">VERIFY_PEER</code><a class="headerlink" href="#OpenSSL.SSL.VERIFY_PEER" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">VERIFY_FAIL_IF_NO_PEER_CERT</code><a class="headerlink" href="#OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants represent the verification mode used by the Context
object&#8217;s <code class="xref py py-meth docutils literal"><span class="pre">set_verify()</span></code> method.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.FILETYPE_PEM">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">FILETYPE_PEM</code><a class="headerlink" href="#OpenSSL.SSL.FILETYPE_PEM" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.FILETYPE_ASN1">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">FILETYPE_ASN1</code><a class="headerlink" href="#OpenSSL.SSL.FILETYPE_ASN1" title="Permalink to this definition">¶</a></dt>
<dd><p>File type constants used with the <code class="xref py py-meth docutils literal"><span class="pre">use_certificate_file()</span></code> and
<code class="xref py py-meth docutils literal"><span class="pre">use_privatekey_file()</span></code> methods of Context objects.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.OP_SINGLE_DH_USE">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_SINGLE_DH_USE</code><a class="headerlink" href="#OpenSSL.SSL.OP_SINGLE_DH_USE" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.OP_SINGLE_ECDH_USE">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_SINGLE_ECDH_USE</code><a class="headerlink" href="#OpenSSL.SSL.OP_SINGLE_ECDH_USE" title="Permalink to this definition">¶</a></dt>
<dd><p>Constants used with <code class="xref py py-meth docutils literal"><span class="pre">set_options()</span></code> of Context objects.</p>
<p>When these options are used, a new key will always be created when using
ephemeral (Elliptic curve) Diffie-Hellman.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.OP_EPHEMERAL_RSA">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_EPHEMERAL_RSA</code><a class="headerlink" href="#OpenSSL.SSL.OP_EPHEMERAL_RSA" title="Permalink to this definition">¶</a></dt>
<dd><p>Constant used with <code class="xref py py-meth docutils literal"><span class="pre">set_options()</span></code> of Context objects.</p>
<p>When this option is used, ephemeral RSA keys will always be used when doing
RSA operations.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.OP_NO_TICKET">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_TICKET</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_TICKET" title="Permalink to this definition">¶</a></dt>
<dd><p>Constant used with <code class="xref py py-meth docutils literal"><span class="pre">set_options()</span></code> of Context objects.</p>
<p>When this option is used, the session ticket extension will not be used.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.OP_NO_COMPRESSION">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_COMPRESSION</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_COMPRESSION" title="Permalink to this definition">¶</a></dt>
<dd><p>Constant used with <code class="xref py py-meth docutils literal"><span class="pre">set_options()</span></code> of Context objects.</p>
<p>When this option is used, compression will not be used.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.OP_NO_SSLv2">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_SSLv2</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_SSLv2" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.OP_NO_SSLv3">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_SSLv3</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_SSLv3" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.OP_NO_TLSv1">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_TLSv1</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_TLSv1" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.OP_NO_TLSv1_1">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_TLSv1_1</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_TLSv1_1" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.OP_NO_TLSv1_2">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OP_NO_TLSv1_2</code><a class="headerlink" href="#OpenSSL.SSL.OP_NO_TLSv1_2" title="Permalink to this definition">¶</a></dt>
<dd><p>Constants used with <code class="xref py py-meth docutils literal"><span class="pre">set_options()</span></code> of Context objects.</p>
<p>Each of these options disables one version of the SSL/TLS protocol.  This
is interesting if you&#8217;re using e.g. <a class="reference internal" href="#OpenSSL.SSL.SSLv23_METHOD" title="OpenSSL.SSL.SSLv23_METHOD"><code class="xref py py-const docutils literal"><span class="pre">SSLv23_METHOD</span></code></a> to get an
SSLv2-compatible handshake, but don&#8217;t want to use SSLv2.  If the underlying
OpenSSL build is missing support for any of these protocols, the
<code class="xref py py-const docutils literal"><span class="pre">OP_NO_*</span></code> constant may be undefined.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.SSLEAY_VERSION">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLEAY_VERSION</code><a class="headerlink" href="#OpenSSL.SSL.SSLEAY_VERSION" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SSLEAY_CFLAGS">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLEAY_CFLAGS</code><a class="headerlink" href="#OpenSSL.SSL.SSLEAY_CFLAGS" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SSLEAY_BUILT_ON">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLEAY_BUILT_ON</code><a class="headerlink" href="#OpenSSL.SSL.SSLEAY_BUILT_ON" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SSLEAY_PLATFORM">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLEAY_PLATFORM</code><a class="headerlink" href="#OpenSSL.SSL.SSLEAY_PLATFORM" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SSLEAY_DIR">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLEAY_DIR</code><a class="headerlink" href="#OpenSSL.SSL.SSLEAY_DIR" title="Permalink to this definition">¶</a></dt>
<dd><p>Constants used with <a class="reference internal" href="#OpenSSL.SSL.SSLeay_version" title="OpenSSL.SSL.SSLeay_version"><code class="xref py py-meth docutils literal"><span class="pre">SSLeay_version()</span></code></a> to specify what OpenSSL version
information to retrieve.  See the man page for the <a class="reference internal" href="#OpenSSL.SSL.SSLeay_version" title="OpenSSL.SSL.SSLeay_version"><code class="xref py py-func docutils literal"><span class="pre">SSLeay_version()</span></code></a> C
API for details.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.SESS_CACHE_OFF">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_OFF</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_OFF" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_CLIENT">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_CLIENT</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_CLIENT" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_SERVER">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_SERVER</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_SERVER" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_BOTH">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_BOTH</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_BOTH" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_NO_AUTO_CLEAR">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_NO_AUTO_CLEAR</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_NO_AUTO_CLEAR" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_LOOKUP">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_NO_INTERNAL_LOOKUP</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_LOOKUP" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_STORE">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_NO_INTERNAL_STORE</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_STORE" title="Permalink to this definition">¶</a></dt>
<dt id="OpenSSL.SSL.SESS_CACHE_NO_INTERNAL">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SESS_CACHE_NO_INTERNAL</code><a class="headerlink" href="#OpenSSL.SSL.SESS_CACHE_NO_INTERNAL" title="Permalink to this definition">¶</a></dt>
<dd><p>Constants used with <a class="reference internal" href="#OpenSSL.SSL.Context.set_session_cache_mode" title="OpenSSL.SSL.Context.set_session_cache_mode"><code class="xref py py-meth docutils literal"><span class="pre">Context.set_session_cache_mode()</span></code></a> to specify
the behavior of the session cache and potential session reuse.  See the man
page for the <code class="xref py py-func docutils literal"><span class="pre">SSL_CTX_set_session_cache_mode()</span></code> C API for details.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.OPENSSL_VERSION_NUMBER">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">OPENSSL_VERSION_NUMBER</code><a class="headerlink" href="#OpenSSL.SSL.OPENSSL_VERSION_NUMBER" title="Permalink to this definition">¶</a></dt>
<dd><p>An integer giving the version number of the OpenSSL library used to build this
version of pyOpenSSL.  See the man page for the <a class="reference internal" href="#OpenSSL.SSL.SSLeay_version" title="OpenSSL.SSL.SSLeay_version"><code class="xref py py-func docutils literal"><span class="pre">SSLeay_version()</span></code></a> C API
for details.</p>
</dd></dl>

<dl class="function">
<dt id="OpenSSL.SSL.SSLeay_version">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">SSLeay_version</code><span class="sig-paren">(</span><em>type</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.SSLeay_version" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve a string describing some aspect of the underlying OpenSSL version.  The
type passed in should be one of the <code class="xref py py-const docutils literal"><span class="pre">SSLEAY_*</span></code> constants defined in
this module.</p>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.ContextType">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">ContextType</code><a class="headerlink" href="#OpenSSL.SSL.ContextType" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#OpenSSL.SSL.Context" title="OpenSSL.SSL.Context"><code class="xref py py-class docutils literal"><span class="pre">Context</span></code></a>.</p>
</dd></dl>

<dl class="class">
<dt id="OpenSSL.SSL.Context">
<em class="property">class </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">Context</code><span class="sig-paren">(</span><em>method</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context" title="Permalink to this definition">¶</a></dt>
<dd><p>A class representing SSL contexts.  Contexts define the parameters of one or
more SSL connections.</p>
<p><em>method</em> should be <a class="reference internal" href="#OpenSSL.SSL.SSLv2_METHOD" title="OpenSSL.SSL.SSLv2_METHOD"><code class="xref py py-const docutils literal"><span class="pre">SSLv2_METHOD</span></code></a>, <a class="reference internal" href="#OpenSSL.SSL.SSLv3_METHOD" title="OpenSSL.SSL.SSLv3_METHOD"><code class="xref py py-const docutils literal"><span class="pre">SSLv3_METHOD</span></code></a>,
<a class="reference internal" href="#OpenSSL.SSL.SSLv23_METHOD" title="OpenSSL.SSL.SSLv23_METHOD"><code class="xref py py-const docutils literal"><span class="pre">SSLv23_METHOD</span></code></a>, <a class="reference internal" href="#OpenSSL.SSL.TLSv1_METHOD" title="OpenSSL.SSL.TLSv1_METHOD"><code class="xref py py-const docutils literal"><span class="pre">TLSv1_METHOD</span></code></a>, <a class="reference internal" href="#OpenSSL.SSL.TLSv1_1_METHOD" title="OpenSSL.SSL.TLSv1_1_METHOD"><code class="xref py py-const docutils literal"><span class="pre">TLSv1_1_METHOD</span></code></a>,
or <a class="reference internal" href="#OpenSSL.SSL.TLSv1_2_METHOD" title="OpenSSL.SSL.TLSv1_2_METHOD"><code class="xref py py-const docutils literal"><span class="pre">TLSv1_2_METHOD</span></code></a>.</p>
</dd></dl>

<dl class="class">
<dt id="OpenSSL.SSL.Session">
<em class="property">class </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">Session</code><a class="headerlink" href="#OpenSSL.SSL.Session" title="Permalink to this definition">¶</a></dt>
<dd><p>A class representing an SSL session.  A session defines certain connection
parameters which may be re-used to speed up the setup of subsequent
connections.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="OpenSSL.SSL.ConnectionType">
<code class="descclassname">OpenSSL.SSL.</code><code class="descname">ConnectionType</code><a class="headerlink" href="#OpenSSL.SSL.ConnectionType" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>.</p>
</dd></dl>

<dl class="class">
<dt id="OpenSSL.SSL.Connection">
<em class="property">class </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">Connection</code><span class="sig-paren">(</span><em>context</em>, <em>socket</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection" title="Permalink to this definition">¶</a></dt>
<dd><p>A class representing SSL connections.</p>
<p><em>context</em> should be an instance of <a class="reference internal" href="#OpenSSL.SSL.Context" title="OpenSSL.SSL.Context"><code class="xref py py-class docutils literal"><span class="pre">Context</span></code></a> and <em>socket</em>
should be a socket <a class="footnote-reference" href="#connection-context-socket" id="id1">[1]</a>  object.  <em>socket</em> may be
<em>None</em>; in this case, the Connection is created with a memory BIO: see
the <a class="reference internal" href="#OpenSSL.SSL.Connection.bio_read" title="OpenSSL.SSL.Connection.bio_read"><code class="xref py py-meth docutils literal"><span class="pre">bio_read()</span></code></a>, <a class="reference internal" href="#OpenSSL.SSL.Connection.bio_write" title="OpenSSL.SSL.Connection.bio_write"><code class="xref py py-meth docutils literal"><span class="pre">bio_write()</span></code></a>, and <a class="reference internal" href="#OpenSSL.SSL.Connection.bio_shutdown" title="OpenSSL.SSL.Connection.bio_shutdown"><code class="xref py py-meth docutils literal"><span class="pre">bio_shutdown()</span></code></a>
methods.</p>
</dd></dl>

<dl class="exception">
<dt id="OpenSSL.SSL.Error">
<em class="property">exception </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">Error</code><a class="headerlink" href="#OpenSSL.SSL.Error" title="Permalink to this definition">¶</a></dt>
<dd><p>This exception is used as a base class for the other SSL-related
exceptions, but may also be raised directly.</p>
<p>Whenever this exception is raised directly, it has a list of error messages
from the OpenSSL error queue, where each item is a tuple <em>(lib, function,
reason)</em>. Here <em>lib</em>, <em>function</em> and <em>reason</em> are all strings, describing
where and what the problem is. See <em class="manpage">err(3)</em> for more information.</p>
</dd></dl>

<dl class="exception">
<dt id="OpenSSL.SSL.ZeroReturnError">
<em class="property">exception </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">ZeroReturnError</code><a class="headerlink" href="#OpenSSL.SSL.ZeroReturnError" title="Permalink to this definition">¶</a></dt>
<dd><p>This exception matches the error return code
<code class="xref py py-data docutils literal"><span class="pre">SSL_ERROR_ZERO_RETURN</span></code>, and is raised when the SSL Connection has
been closed. In SSL 3.0 and TLS 1.0, this only occurs if a closure alert has
occurred in the protocol, i.e.  the connection has been closed cleanly. Note
that this does not necessarily mean that the transport layer (e.g. a socket)
has been closed.</p>
<p>It may seem a little strange that this is an exception, but it does match an
<code class="xref py py-data docutils literal"><span class="pre">SSL_ERROR</span></code> code, and is very convenient.</p>
</dd></dl>

<dl class="exception">
<dt id="OpenSSL.SSL.WantReadError">
<em class="property">exception </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">WantReadError</code><a class="headerlink" href="#OpenSSL.SSL.WantReadError" title="Permalink to this definition">¶</a></dt>
<dd><p>The operation did not complete; the same I/O method should be called again
later, with the same arguments. Any I/O method can lead to this since new
handshakes can occur at any time.</p>
<p>The wanted read is for <strong>dirty</strong> data sent over the network, not the
<strong>clean</strong> data inside the tunnel.  For a socket based SSL connection,
<strong>read</strong> means data coming at us over the network.  Until that read
succeeds, the attempted <a class="reference internal" href="#OpenSSL.SSL.Connection.recv" title="OpenSSL.SSL.Connection.recv"><code class="xref py py-meth docutils literal"><span class="pre">OpenSSL.SSL.Connection.recv()</span></code></a>,
<a class="reference internal" href="#OpenSSL.SSL.Connection.send" title="OpenSSL.SSL.Connection.send"><code class="xref py py-meth docutils literal"><span class="pre">OpenSSL.SSL.Connection.send()</span></code></a>, or
<a class="reference internal" href="#OpenSSL.SSL.Connection.do_handshake" title="OpenSSL.SSL.Connection.do_handshake"><code class="xref py py-meth docutils literal"><span class="pre">OpenSSL.SSL.Connection.do_handshake()</span></code></a> is prevented or incomplete. You
probably want to <code class="xref py py-meth docutils literal"><span class="pre">select()</span></code> on the socket before trying again.</p>
</dd></dl>

<dl class="exception">
<dt id="OpenSSL.SSL.WantWriteError">
<em class="property">exception </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">WantWriteError</code><a class="headerlink" href="#OpenSSL.SSL.WantWriteError" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#OpenSSL.SSL.WantReadError" title="OpenSSL.SSL.WantReadError"><code class="xref py py-exc docutils literal"><span class="pre">WantReadError</span></code></a>.  The socket send buffer may be too full to
write more data.</p>
</dd></dl>

<dl class="exception">
<dt id="OpenSSL.SSL.WantX509LookupError">
<em class="property">exception </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">WantX509LookupError</code><a class="headerlink" href="#OpenSSL.SSL.WantX509LookupError" title="Permalink to this definition">¶</a></dt>
<dd><p>The operation did not complete because an application callback has asked to be
called again. The I/O method should be called again later, with the same
arguments.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This won&#8217;t occur in this version, as there are no such
callbacks in this version.</p>
</div>
</dd></dl>

<dl class="exception">
<dt id="OpenSSL.SSL.SysCallError">
<em class="property">exception </em><code class="descclassname">OpenSSL.SSL.</code><code class="descname">SysCallError</code><a class="headerlink" href="#OpenSSL.SSL.SysCallError" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="#OpenSSL.SSL.SysCallError" title="OpenSSL.SSL.SysCallError"><code class="xref py py-exc docutils literal"><span class="pre">SysCallError</span></code></a> occurs when there&#8217;s an I/O error and OpenSSL&#8217;s
error queue does not contain any information. This can mean two things: An
error in the transport protocol, or an end of file that violates the protocol.
The parameter to the exception is always a pair <em>(errnum,
errstr)</em>.</p>
</dd></dl>

<div class="section" id="context-objects">
<span id="openssl-context"></span><h2>Context objects<a class="headerlink" href="#context-objects" title="Permalink to this headline">¶</a></h2>
<p>Context objects have the following methods:</p>
<dl class="method">
<dt id="OpenSSL.SSL.Context.check_privatekey">
<code class="descclassname">Context.</code><code class="descname">check_privatekey</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.check_privatekey" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if the private key (loaded with <a class="reference internal" href="#OpenSSL.SSL.Context.use_privatekey" title="OpenSSL.SSL.Context.use_privatekey"><code class="xref py py-meth docutils literal"><span class="pre">use_privatekey()</span></code></a>) matches the
certificate (loaded with <a class="reference internal" href="#OpenSSL.SSL.Context.use_certificate" title="OpenSSL.SSL.Context.use_certificate"><code class="xref py py-meth docutils literal"><span class="pre">use_certificate()</span></code></a>).  Returns
<code class="xref py py-data docutils literal"><span class="pre">None</span></code> if they match, raises <a class="reference internal" href="#OpenSSL.SSL.Error" title="OpenSSL.SSL.Error"><code class="xref py py-exc docutils literal"><span class="pre">Error</span></code></a> otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.get_app_data">
<code class="descclassname">Context.</code><code class="descname">get_app_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.get_app_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve application data as set by <a class="reference internal" href="#OpenSSL.SSL.Context.set_app_data" title="OpenSSL.SSL.Context.set_app_data"><code class="xref py py-meth docutils literal"><span class="pre">set_app_data()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.get_cert_store">
<code class="descclassname">Context.</code><code class="descname">get_cert_store</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.get_cert_store" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the certificate store (a X509Store object) that the context uses.
This can be used to add &#8220;trusted&#8221; certificates without using the
<a class="reference internal" href="#OpenSSL.SSL.Context.load_verify_locations" title="OpenSSL.SSL.Context.load_verify_locations"><code class="xref py py-meth docutils literal"><span class="pre">load_verify_locations()</span></code></a> method.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.get_timeout">
<code class="descclassname">Context.</code><code class="descname">get_timeout</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.get_timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve session timeout, as set by <a class="reference internal" href="#OpenSSL.SSL.Context.set_timeout" title="OpenSSL.SSL.Context.set_timeout"><code class="xref py py-meth docutils literal"><span class="pre">set_timeout()</span></code></a>. The default is 300
seconds.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.get_verify_depth">
<code class="descclassname">Context.</code><code class="descname">get_verify_depth</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.get_verify_depth" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the Context object&#8217;s verify depth, as set by
<a class="reference internal" href="#OpenSSL.SSL.Context.set_verify_depth" title="OpenSSL.SSL.Context.set_verify_depth"><code class="xref py py-meth docutils literal"><span class="pre">set_verify_depth()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.get_verify_mode">
<code class="descclassname">Context.</code><code class="descname">get_verify_mode</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.get_verify_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the Context object&#8217;s verify mode, as set by <a class="reference internal" href="#OpenSSL.SSL.Context.set_verify" title="OpenSSL.SSL.Context.set_verify"><code class="xref py py-meth docutils literal"><span class="pre">set_verify()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_client_ca_list">
<code class="descclassname">Context.</code><code class="descname">set_client_ca_list</code><span class="sig-paren">(</span><em>certificate_authorities</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_client_ca_list" title="Permalink to this definition">¶</a></dt>
<dd><p>Replace the current list of preferred certificate signers that would be
sent to the client when requesting a client certificate with the
<em>certificate_authorities</em> sequence of <code class="xref py py-class docutils literal"><span class="pre">OpenSSL.crypto.X509Name</span></code>&#8216;s.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.10.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.add_client_ca">
<code class="descclassname">Context.</code><code class="descname">add_client_ca</code><span class="sig-paren">(</span><em>certificate_authority</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.add_client_ca" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract a <code class="xref py py-class docutils literal"><span class="pre">OpenSSL.crypto.X509Name</span></code> from the <em>certificate_authority</em>
<code class="xref py py-class docutils literal"><span class="pre">OpenSSL.crypto.X509</span></code> certificate and add it to the list of preferred
certificate signers sent to the client when requesting a client certificate.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.10.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.load_verify_locations">
<code class="descclassname">Context.</code><code class="descname">load_verify_locations</code><span class="sig-paren">(</span><em>pemfile</em>, <em>capath</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.load_verify_locations" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify where CA certificates for verification purposes are located. These
are trusted certificates. Note that the certificates have to be in PEM
format.  If capath is passed, it must be a directory prepared using the
<code class="docutils literal"><span class="pre">c_rehash</span></code> tool included with OpenSSL.  Either, but not both, of
<em>pemfile</em> or <em>capath</em> may be <code class="xref py py-data docutils literal"><span class="pre">None</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_default_verify_paths">
<code class="descclassname">Context.</code><code class="descname">set_default_verify_paths</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_default_verify_paths" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify that the platform provided CA certificates are to be used for
verification purposes.  This method may not work properly on OS X.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.load_tmp_dh">
<code class="descclassname">Context.</code><code class="descname">load_tmp_dh</code><span class="sig-paren">(</span><em>dhfile</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.load_tmp_dh" title="Permalink to this definition">¶</a></dt>
<dd><p>Load parameters for Ephemeral Diffie-Hellman from <em>dhfile</em>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_tmp_ecdh">
<code class="descclassname">Context.</code><code class="descname">set_tmp_ecdh</code><span class="sig-paren">(</span><em>curve</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_tmp_ecdh" title="Permalink to this definition">¶</a></dt>
<dd><p>Select a curve to use for ECDHE key exchange.</p>
<p>The valid values of <em>curve</em> are the objects returned by
<a class="reference internal" href="crypto.html#OpenSSL.crypto.get_elliptic_curves" title="OpenSSL.crypto.get_elliptic_curves"><code class="xref py py-func docutils literal"><span class="pre">OpenSSL.crypto.get_elliptic_curves()</span></code></a> or
<a class="reference internal" href="crypto.html#OpenSSL.crypto.get_elliptic_curve" title="OpenSSL.crypto.get_elliptic_curve"><code class="xref py py-func docutils literal"><span class="pre">OpenSSL.crypto.get_elliptic_curve()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_app_data">
<code class="descclassname">Context.</code><code class="descname">set_app_data</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_app_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Associate <em>data</em> with this Context object. <em>data</em> can be retrieved
later using the <a class="reference internal" href="#OpenSSL.SSL.Context.get_app_data" title="OpenSSL.SSL.Context.get_app_data"><code class="xref py py-meth docutils literal"><span class="pre">get_app_data()</span></code></a> method.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_info_callback">
<code class="descclassname">Context.</code><code class="descname">set_info_callback</code><span class="sig-paren">(</span><em>callback</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_info_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the information callback to <em>callback</em>. This function will be called
from time to time during SSL handshakes.</p>
<p><em>callback</em> should take three arguments: a Connection object and two integers.
The first integer specifies where in the SSL handshake the function was
called, and the other the return code from a (possibly failed) internal
function call.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_options">
<code class="descclassname">Context.</code><code class="descname">set_options</code><span class="sig-paren">(</span><em>options</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_options" title="Permalink to this definition">¶</a></dt>
<dd><p>Add SSL options. Options you have set before are not cleared!
This method should be used with the <code class="xref py py-const docutils literal"><span class="pre">OP_*</span></code> constants.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_mode">
<code class="descclassname">Context.</code><code class="descname">set_mode</code><span class="sig-paren">(</span><em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Add SSL mode. Modes you have set before are not cleared!  This method should
be used with the <code class="xref py py-const docutils literal"><span class="pre">MODE_*</span></code> constants.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_passwd_cb">
<code class="descclassname">Context.</code><code class="descname">set_passwd_cb</code><span class="sig-paren">(</span><em>callback</em><span class="optional">[</span>, <em>userdata</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_passwd_cb" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the passphrase callback to <em>callback</em>. This function will be called
when a private key with a passphrase is loaded. <em>callback</em> must accept
three positional arguments.  First, an integer giving the maximum length of
the passphrase it may return.  If the returned passphrase is longer than
this, it will be truncated.  Second, a boolean value which will be true if
the user should be prompted for the passphrase twice and the callback should
verify that the two values supplied are equal. Third, the value given as the
<em>userdata</em> parameter to <a class="reference internal" href="#OpenSSL.SSL.Context.set_passwd_cb" title="OpenSSL.SSL.Context.set_passwd_cb"><code class="xref py py-meth docutils literal"><span class="pre">set_passwd_cb()</span></code></a>.  If an error occurs,
<em>callback</em> should return a false value (e.g. an empty string).</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_session_cache_mode">
<code class="descclassname">Context.</code><code class="descname">set_session_cache_mode</code><span class="sig-paren">(</span><em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_session_cache_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the behavior of the session cache used by all connections using this
Context.  The previously set mode is returned.  See <code class="xref py py-const docutils literal"><span class="pre">SESS_CACHE_*</span></code>
for details about particular modes.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.get_session_cache_mode">
<code class="descclassname">Context.</code><code class="descname">get_session_cache_mode</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.get_session_cache_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the current session cache mode.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_timeout">
<code class="descclassname">Context.</code><code class="descname">set_timeout</code><span class="sig-paren">(</span><em>timeout</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the timeout for newly created sessions for this Context object to
<em>timeout</em>. <em>timeout</em> must be given in (whole) seconds. The default
value is 300 seconds. See the OpenSSL manual for more information (e.g.
<em class="manpage">SSL_CTX_set_timeout(3)</em>).</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_verify">
<code class="descclassname">Context.</code><code class="descname">set_verify</code><span class="sig-paren">(</span><em>mode</em>, <em>callback</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_verify" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the verification flags for this Context object to <em>mode</em> and specify
that <em>callback</em> should be used for verification callbacks. <em>mode</em> should be
one of <a class="reference internal" href="#OpenSSL.SSL.VERIFY_NONE" title="OpenSSL.SSL.VERIFY_NONE"><code class="xref py py-const docutils literal"><span class="pre">VERIFY_NONE</span></code></a> and <a class="reference internal" href="#OpenSSL.SSL.VERIFY_PEER" title="OpenSSL.SSL.VERIFY_PEER"><code class="xref py py-const docutils literal"><span class="pre">VERIFY_PEER</span></code></a>. If
<a class="reference internal" href="#OpenSSL.SSL.VERIFY_PEER" title="OpenSSL.SSL.VERIFY_PEER"><code class="xref py py-const docutils literal"><span class="pre">VERIFY_PEER</span></code></a> is used, <em>mode</em> can be OR:ed with
<a class="reference internal" href="#OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT" title="OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT"><code class="xref py py-const docutils literal"><span class="pre">VERIFY_FAIL_IF_NO_PEER_CERT</span></code></a> and <code class="xref py py-const docutils literal"><span class="pre">VERIFY_CLIENT_ONCE</span></code>
to further control the behaviour.</p>
<p><em>callback</em> should take five arguments: A Connection object, an X509 object,
and three integer variables, which are in turn potential error number, error
depth and return code. <em>callback</em> should return true if verification passes
and false otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_verify_depth">
<code class="descclassname">Context.</code><code class="descname">set_verify_depth</code><span class="sig-paren">(</span><em>depth</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_verify_depth" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the maximum depth for the certificate chain verification that shall be
allowed for this Context object.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.use_certificate">
<code class="descclassname">Context.</code><code class="descname">use_certificate</code><span class="sig-paren">(</span><em>cert</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.use_certificate" title="Permalink to this definition">¶</a></dt>
<dd><p>Use the certificate <em>cert</em> which has to be a X509 object.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.add_extra_chain_cert">
<code class="descclassname">Context.</code><code class="descname">add_extra_chain_cert</code><span class="sig-paren">(</span><em>cert</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.add_extra_chain_cert" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds the certificate <em>cert</em>, which has to be a X509 object, to the
certificate chain presented together with the certificate.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.use_certificate_chain_file">
<code class="descclassname">Context.</code><code class="descname">use_certificate_chain_file</code><span class="sig-paren">(</span><em>file</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.use_certificate_chain_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a certificate chain from <em>file</em> which must be PEM encoded.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.use_privatekey">
<code class="descclassname">Context.</code><code class="descname">use_privatekey</code><span class="sig-paren">(</span><em>pkey</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.use_privatekey" title="Permalink to this definition">¶</a></dt>
<dd><p>Use the private key <em>pkey</em> which has to be a PKey object.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.use_certificate_file">
<code class="descclassname">Context.</code><code class="descname">use_certificate_file</code><span class="sig-paren">(</span><em>file</em><span class="optional">[</span>, <em>format</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.use_certificate_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the first certificate found in <em>file</em>. The certificate must be in the
format specified by <em>format</em>, which is either <a class="reference internal" href="#OpenSSL.SSL.FILETYPE_PEM" title="OpenSSL.SSL.FILETYPE_PEM"><code class="xref py py-const docutils literal"><span class="pre">FILETYPE_PEM</span></code></a> or
<a class="reference internal" href="#OpenSSL.SSL.FILETYPE_ASN1" title="OpenSSL.SSL.FILETYPE_ASN1"><code class="xref py py-const docutils literal"><span class="pre">FILETYPE_ASN1</span></code></a>. The default is <a class="reference internal" href="#OpenSSL.SSL.FILETYPE_PEM" title="OpenSSL.SSL.FILETYPE_PEM"><code class="xref py py-const docutils literal"><span class="pre">FILETYPE_PEM</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.use_privatekey_file">
<code class="descclassname">Context.</code><code class="descname">use_privatekey_file</code><span class="sig-paren">(</span><em>file</em><span class="optional">[</span>, <em>format</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.use_privatekey_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the first private key found in <em>file</em>. The private key must be in the
format specified by <em>format</em>, which is either <a class="reference internal" href="#OpenSSL.SSL.FILETYPE_PEM" title="OpenSSL.SSL.FILETYPE_PEM"><code class="xref py py-const docutils literal"><span class="pre">FILETYPE_PEM</span></code></a> or
<a class="reference internal" href="#OpenSSL.SSL.FILETYPE_ASN1" title="OpenSSL.SSL.FILETYPE_ASN1"><code class="xref py py-const docutils literal"><span class="pre">FILETYPE_ASN1</span></code></a>. The default is <a class="reference internal" href="#OpenSSL.SSL.FILETYPE_PEM" title="OpenSSL.SSL.FILETYPE_PEM"><code class="xref py py-const docutils literal"><span class="pre">FILETYPE_PEM</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_tlsext_servername_callback">
<code class="descclassname">Context.</code><code class="descname">set_tlsext_servername_callback</code><span class="sig-paren">(</span><em>callback</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_tlsext_servername_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify a one-argument callable to use as the TLS extension server name
callback.  When a connection using the server name extension is made using
this context, the callback will be invoked with the <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>
instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.13.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_npn_advertise_callback">
<code class="descclassname">Context.</code><code class="descname">set_npn_advertise_callback</code><span class="sig-paren">(</span><em>callback</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_npn_advertise_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify a callback function that will be called when offering <a class="reference external" href="https://technotes.googlecode.com/git/nextprotoneg.html">Next
Protocol Negotiation</a> as a server.</p>
<p><em>callback</em> should be the callback function.  It will be invoked with one
argument, the <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a> instance.  It should return a list of
bytestrings representing the advertised protocols, like
<code class="docutils literal"><span class="pre">[b'http/1.1',</span> <span class="pre">b'spdy/2']</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt>
<code class="descname">Context.set_npn_select_callback(callback):</code></dt>
<dd><p>Specify a callback function that will be called when a server offers Next
Protocol Negotiation options.</p>
<p><em>callback</em> should be the callback function.  It will be invoked with two
arguments: the <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>, and a list of offered protocols as
bytestrings, e.g. <code class="docutils literal"><span class="pre">[b'http/1.1',</span> <span class="pre">b'spdy/2']</span></code>.  It should return one of
those bytestrings, the chosen protocol.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_alpn_protos">
<code class="descclassname">Context.</code><code class="descname">set_alpn_protos</code><span class="sig-paren">(</span><em>protos</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_alpn_protos" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify the protocols that the client is prepared to speak after the TLS
connection has been negotiated using Application Layer Protocol
Negotiation.</p>
<p><em>protos</em> should be a list of protocols that the client is offering, each
as a bytestring. For example, <code class="docutils literal"><span class="pre">[b'http/1.1',</span> <span class="pre">b'spdy/2']</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Context.set_alpn_select_callback">
<code class="descclassname">Context.</code><code class="descname">set_alpn_select_callback</code><span class="sig-paren">(</span><em>callback</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Context.set_alpn_select_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify a callback function that will be called on the server when a client
offers protocols using Application Layer Protocol Negotiation.</p>
<p><em>callback</em> should be the callback function. It will be invoked with two
arguments: the <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a> and a list of offered protocols as
bytestrings, e.g. <code class="docutils literal"><span class="pre">[b'http/1.1',</span> <span class="pre">b'spdy/2']</span></code>. It should return one of
these bytestrings, the chosen protocol.</p>
</dd></dl>

</div>
<div class="section" id="session-objects">
<span id="openssl-session"></span><h2>Session objects<a class="headerlink" href="#session-objects" title="Permalink to this headline">¶</a></h2>
<p>Session objects have no methods.</p>
</div>
<div class="section" id="connection-objects">
<span id="openssl-connection"></span><h2>Connection objects<a class="headerlink" href="#connection-objects" title="Permalink to this headline">¶</a></h2>
<p>Connection objects have the following methods:</p>
<dl class="method">
<dt id="OpenSSL.SSL.Connection.accept">
<code class="descclassname">Connection.</code><code class="descname">accept</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.accept" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.accept" title="OpenSSL.SSL.Connection.accept"><code class="xref py py-meth docutils literal"><span class="pre">accept()</span></code></a> method of the underlying socket and set up SSL on the
returned socket, using the Context object supplied to this Connection object at
creation. Returns a pair <em>(conn, address)</em>. where <em>conn</em> is the new
Connection object created, and <em>address</em> is as returned by the socket&#8217;s
<a class="reference internal" href="#OpenSSL.SSL.Connection.accept" title="OpenSSL.SSL.Connection.accept"><code class="xref py py-meth docutils literal"><span class="pre">accept()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.bind">
<code class="descclassname">Connection.</code><code class="descname">bind</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.bind" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.bind" title="OpenSSL.SSL.Connection.bind"><code class="xref py py-meth docutils literal"><span class="pre">bind()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.close">
<code class="descclassname">Connection.</code><code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.close" title="OpenSSL.SSL.Connection.close"><code class="xref py py-meth docutils literal"><span class="pre">close()</span></code></a> method of the underlying socket. Note: If you want
correct SSL closure, you need to call the <a class="reference internal" href="#OpenSSL.SSL.Connection.shutdown" title="OpenSSL.SSL.Connection.shutdown"><code class="xref py py-meth docutils literal"><span class="pre">shutdown()</span></code></a> method first.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.connect">
<code class="descclassname">Connection.</code><code class="descname">connect</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.connect" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.connect" title="OpenSSL.SSL.Connection.connect"><code class="xref py py-meth docutils literal"><span class="pre">connect()</span></code></a> method of the underlying socket and set up SSL on the
socket, using the Context object supplied to this Connection object at
creation.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.connect_ex">
<code class="descclassname">Connection.</code><code class="descname">connect_ex</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.connect_ex" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.connect_ex" title="OpenSSL.SSL.Connection.connect_ex"><code class="xref py py-meth docutils literal"><span class="pre">connect_ex()</span></code></a> method of the underlying socket and set up SSL on
the socket, using the Context object supplied to this Connection object at
creation. Note that if the <a class="reference internal" href="#OpenSSL.SSL.Connection.connect_ex" title="OpenSSL.SSL.Connection.connect_ex"><code class="xref py py-meth docutils literal"><span class="pre">connect_ex()</span></code></a> method of the socket doesn&#8217;t
return 0, SSL won&#8217;t be initialized.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.do_handshake">
<code class="descclassname">Connection.</code><code class="descname">do_handshake</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.do_handshake" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform an SSL handshake (usually called after <code class="xref py py-meth docutils literal"><span class="pre">renegotiate()</span></code> or one of
<a class="reference internal" href="#OpenSSL.SSL.Connection.set_accept_state" title="OpenSSL.SSL.Connection.set_accept_state"><code class="xref py py-meth docutils literal"><span class="pre">set_accept_state()</span></code></a> or <a class="reference internal" href="#OpenSSL.SSL.Connection.set_accept_state" title="OpenSSL.SSL.Connection.set_accept_state"><code class="xref py py-meth docutils literal"><span class="pre">set_accept_state()</span></code></a>). This can raise the
same exceptions as <a class="reference internal" href="#OpenSSL.SSL.Connection.send" title="OpenSSL.SSL.Connection.send"><code class="xref py py-meth docutils literal"><span class="pre">send()</span></code></a> and <a class="reference internal" href="#OpenSSL.SSL.Connection.recv" title="OpenSSL.SSL.Connection.recv"><code class="xref py py-meth docutils literal"><span class="pre">recv()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.fileno">
<code class="descclassname">Connection.</code><code class="descname">fileno</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.fileno" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the file descriptor number for the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.listen">
<code class="descclassname">Connection.</code><code class="descname">listen</code><span class="sig-paren">(</span><em>backlog</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.listen" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.listen" title="OpenSSL.SSL.Connection.listen"><code class="xref py py-meth docutils literal"><span class="pre">listen()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_app_data">
<code class="descclassname">Connection.</code><code class="descname">get_app_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_app_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve application data as set by <a class="reference internal" href="#OpenSSL.SSL.Connection.set_app_data" title="OpenSSL.SSL.Connection.set_app_data"><code class="xref py py-meth docutils literal"><span class="pre">set_app_data()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_protocol_version">
<code class="descclassname">Connection.</code><code class="descname">get_protocol_version</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_protocol_version" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the version of the SSL or TLS protocol used by the Connection.
For example, it will return <code class="docutils literal"><span class="pre">0x769</span></code> for connections made over TLS
version 1.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_protocol_version_name">
<code class="descclassname">Connection.</code><code class="descname">get_protocol_version_name</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_protocol_version_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the version of the SSL or TLS protocol used by the Connection as
a unicode string. For example, it will return <code class="docutils literal"><span class="pre">TLSv1</span></code> for connections
made over TLS version 1, or <code class="docutils literal"><span class="pre">Unknown</span></code> for connections that were not
successfully established.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_client_ca_list">
<code class="descclassname">Connection.</code><code class="descname">get_client_ca_list</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_client_ca_list" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the list of preferred client certificate issuers sent by the server
as <code class="xref py py-class docutils literal"><span class="pre">OpenSSL.crypto.X509Name</span></code> objects.</p>
<p>If this is a client <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>, the list will be empty until the
connection with the server is established.</p>
<p>If this is a server <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>, return the list of certificate
authorities that will be sent or has been sent to the client, as controlled
by this <a class="reference internal" href="#OpenSSL.SSL.Connection" title="OpenSSL.SSL.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>&#8216;s <a class="reference internal" href="#OpenSSL.SSL.Context" title="OpenSSL.SSL.Context"><code class="xref py py-class docutils literal"><span class="pre">Context</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.10.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_context">
<code class="descclassname">Connection.</code><code class="descname">get_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_context" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the Context object associated with this Connection.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_context">
<code class="descclassname">Connection.</code><code class="descname">set_context</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_context" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify a replacement Context object for this Connection.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_peer_certificate">
<code class="descclassname">Connection.</code><code class="descname">get_peer_certificate</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_peer_certificate" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the other side&#8217;s certificate (if any)</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_peer_cert_chain">
<code class="descclassname">Connection.</code><code class="descname">get_peer_cert_chain</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_peer_cert_chain" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the tuple of the other side&#8217;s certificate chain (if any)</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.getpeername">
<code class="descclassname">Connection.</code><code class="descname">getpeername</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.getpeername" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.getpeername" title="OpenSSL.SSL.Connection.getpeername"><code class="xref py py-meth docutils literal"><span class="pre">getpeername()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.getsockname">
<code class="descclassname">Connection.</code><code class="descname">getsockname</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.getsockname" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.getsockname" title="OpenSSL.SSL.Connection.getsockname"><code class="xref py py-meth docutils literal"><span class="pre">getsockname()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.getsockopt">
<code class="descclassname">Connection.</code><code class="descname">getsockopt</code><span class="sig-paren">(</span><em>level</em>, <em>optname</em><span class="optional">[</span>, <em>buflen</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.getsockopt" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.getsockopt" title="OpenSSL.SSL.Connection.getsockopt"><code class="xref py py-meth docutils literal"><span class="pre">getsockopt()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.pending">
<code class="descclassname">Connection.</code><code class="descname">pending</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.pending" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the number of bytes that can be safely read from the SSL buffer
(<strong>not</strong> the underlying transport buffer).</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.recv">
<code class="descclassname">Connection.</code><code class="descname">recv</code><span class="sig-paren">(</span><em>bufsize</em><span class="optional">[</span>, <em>flags</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.recv" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive data from the Connection. The return value is a string representing the
data received. The maximum amount of data to be received at once, is specified
by <em>bufsize</em>. The only supported flag is <code class="docutils literal"><span class="pre">MSG_PEEK</span></code>, all other flags are
ignored.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.recv_into">
<code class="descclassname">Connection.</code><code class="descname">recv_into</code><span class="sig-paren">(</span><em>buffer</em><span class="optional">[</span>, <em>nbytes</em><span class="optional">[</span>, <em>flags</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.recv_into" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive data from the Connection and copy it directly into the provided
buffer. The return value is the number of bytes read from the connection.
The maximum amount of data to be received at once is specified by <em>nbytes</em>.
The only supported flag is <code class="docutils literal"><span class="pre">MSG_PEEK</span></code>, all other flags are ignored.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.bio_write">
<code class="descclassname">Connection.</code><code class="descname">bio_write</code><span class="sig-paren">(</span><em>bytes</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.bio_write" title="Permalink to this definition">¶</a></dt>
<dd><p>If the Connection was created with a memory BIO, this method can be used to add
bytes to the read end of that memory BIO.  The Connection can then read the
bytes (for example, in response to a call to <a class="reference internal" href="#OpenSSL.SSL.Connection.recv" title="OpenSSL.SSL.Connection.recv"><code class="xref py py-meth docutils literal"><span class="pre">recv()</span></code></a>).</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.send">
<code class="descclassname">Connection.</code><code class="descname">send</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.send" title="Permalink to this definition">¶</a></dt>
<dd><p>Send the <em>string</em> data to the Connection.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.bio_read">
<code class="descclassname">Connection.</code><code class="descname">bio_read</code><span class="sig-paren">(</span><em>bufsize</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.bio_read" title="Permalink to this definition">¶</a></dt>
<dd><p>If the Connection was created with a memory BIO, this method can be used to
read bytes from the write end of that memory BIO.  Many Connection methods will
add bytes which must be read in this manner or the buffer will eventually fill
up and the Connection will be able to take no further actions.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.sendall">
<code class="descclassname">Connection.</code><code class="descname">sendall</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.sendall" title="Permalink to this definition">¶</a></dt>
<dd><p>Send all of the <em>string</em> data to the Connection. This calls <a class="reference internal" href="#OpenSSL.SSL.Connection.send" title="OpenSSL.SSL.Connection.send"><code class="xref py py-meth docutils literal"><span class="pre">send()</span></code></a>
repeatedly until all data is sent. If an error occurs, it&#8217;s impossible to tell
how much data has been sent.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_accept_state">
<code class="descclassname">Connection.</code><code class="descname">set_accept_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_accept_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the connection to work in server mode. The handshake will be handled
automatically by read/write.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_app_data">
<code class="descclassname">Connection.</code><code class="descname">set_app_data</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_app_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Associate <em>data</em> with this Connection object. <em>data</em> can be retrieved
later using the <a class="reference internal" href="#OpenSSL.SSL.Connection.get_app_data" title="OpenSSL.SSL.Connection.get_app_data"><code class="xref py py-meth docutils literal"><span class="pre">get_app_data()</span></code></a> method.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_connect_state">
<code class="descclassname">Connection.</code><code class="descname">set_connect_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_connect_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the connection to work in client mode. The handshake will be handled
automatically by read/write.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.setblocking">
<code class="descclassname">Connection.</code><code class="descname">setblocking</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.setblocking" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.setblocking" title="OpenSSL.SSL.Connection.setblocking"><code class="xref py py-meth docutils literal"><span class="pre">setblocking()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.setsockopt">
<code class="descclassname">Connection.</code><code class="descname">setsockopt</code><span class="sig-paren">(</span><em>level</em>, <em>optname</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.setsockopt" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.setsockopt" title="OpenSSL.SSL.Connection.setsockopt"><code class="xref py py-meth docutils literal"><span class="pre">setsockopt()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.shutdown">
<code class="descclassname">Connection.</code><code class="descname">shutdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Send the shutdown message to the Connection. Returns true if the shutdown
message exchange is completed and false otherwise (in which case you call
<a class="reference internal" href="#OpenSSL.SSL.Connection.recv" title="OpenSSL.SSL.Connection.recv"><code class="xref py py-meth docutils literal"><span class="pre">recv()</span></code></a> or <a class="reference internal" href="#OpenSSL.SSL.Connection.send" title="OpenSSL.SSL.Connection.send"><code class="xref py py-meth docutils literal"><span class="pre">send()</span></code></a> when the connection becomes
readable/writeable.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_shutdown">
<code class="descclassname">Connection.</code><code class="descname">get_shutdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the shutdown state of the Connection.  Returns a bitvector of either or
both of <em>SENT_SHUTDOWN</em> and <em>RECEIVED_SHUTDOWN</em>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_shutdown">
<code class="descclassname">Connection.</code><code class="descname">set_shutdown</code><span class="sig-paren">(</span><em>state</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the shutdown state of the Connection.  <em>state</em> is a bitvector of
either or both of <em>SENT_SHUTDOWN</em> and <em>RECEIVED_SHUTDOWN</em>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.sock_shutdown">
<code class="descclassname">Connection.</code><code class="descname">sock_shutdown</code><span class="sig-paren">(</span><em>how</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.sock_shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the <a class="reference internal" href="#OpenSSL.SSL.Connection.shutdown" title="OpenSSL.SSL.Connection.shutdown"><code class="xref py py-meth docutils literal"><span class="pre">shutdown()</span></code></a> method of the underlying socket.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.bio_shutdown">
<code class="descclassname">Connection.</code><code class="descname">bio_shutdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.bio_shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>If the Connection was created with a memory BIO, this method can be used to
indicate that <em>end of file</em> has been reached on the read end of that memory
BIO.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.client_random">
<code class="descclassname">Connection.</code><code class="descname">client_random</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.client_random" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the random value used with the client hello message.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.server_random">
<code class="descclassname">Connection.</code><code class="descname">server_random</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.server_random" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the random value used with the server hello message.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.master_key">
<code class="descclassname">Connection.</code><code class="descname">master_key</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.master_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the value of the master key for this session.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.want_read">
<code class="descclassname">Connection.</code><code class="descname">want_read</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.want_read" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if more data has to be read from the transport layer to complete an
operation.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.want_write">
<code class="descclassname">Connection.</code><code class="descname">want_write</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.want_write" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if there is data to write to the transport layer to complete an
operation.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_tlsext_host_name">
<code class="descclassname">Connection.</code><code class="descname">set_tlsext_host_name</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_tlsext_host_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify the byte string to send as the server name in the client hello message.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.13.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_servername">
<code class="descclassname">Connection.</code><code class="descname">get_servername</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_servername" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the value of the server name received in the client hello message.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.13.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_session">
<code class="descclassname">Connection.</code><code class="descname">get_session</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_session" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a <a class="reference internal" href="#OpenSSL.SSL.Session" title="OpenSSL.SSL.Session"><code class="xref py py-class docutils literal"><span class="pre">Session</span></code></a> instance representing the SSL session in use by
the connection, or <code class="xref py py-obj docutils literal"><span class="pre">None</span></code> if there is no session.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_session">
<code class="descclassname">Connection.</code><code class="descname">set_session</code><span class="sig-paren">(</span><em>session</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_session" title="Permalink to this definition">¶</a></dt>
<dd><p>Set a new SSL session (using a <a class="reference internal" href="#OpenSSL.SSL.Session" title="OpenSSL.SSL.Session"><code class="xref py py-class docutils literal"><span class="pre">Session</span></code></a> instance) to be used by
the connection.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_finished">
<code class="descclassname">Connection.</code><code class="descname">get_finished</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_finished" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain latest TLS Finished message that we sent, or <code class="xref py py-obj docutils literal"><span class="pre">None</span></code> if
handshake is not completed.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_peer_finished">
<code class="descclassname">Connection.</code><code class="descname">get_peer_finished</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_peer_finished" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain latest TLS Finished message that we expected from peer, or
<code class="xref py py-obj docutils literal"><span class="pre">None</span></code> if handshake is not completed.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_cipher_name">
<code class="descclassname">Connection.</code><code class="descname">get_cipher_name</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_cipher_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain the name of the currently used cipher.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_cipher_bits">
<code class="descclassname">Connection.</code><code class="descname">get_cipher_bits</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_cipher_bits" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain the number of secret bits of the currently used cipher.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_cipher_version">
<code class="descclassname">Connection.</code><code class="descname">get_cipher_version</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_cipher_version" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain the protocol name of the currently used cipher.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt>
<code class="descname">Connection.get_next_proto_negotiated():</code></dt>
<dd><p>Get the protocol that was negotiated by Next Protocol Negotiation. Returns
a bytestring of the protocol name. If no protocol has been negotiated yet,
returns an empty string.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.15.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.set_alpn_protos">
<code class="descclassname">Connection.</code><code class="descname">set_alpn_protos</code><span class="sig-paren">(</span><em>protos</em><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.set_alpn_protos" title="Permalink to this definition">¶</a></dt>
<dd><p>Specify the protocols that the client is prepared to speak after the TLS
connection has been negotiated using Application Layer Protocol
Negotiation.</p>
<p><em>protos</em> should be a list of protocols that the client is offering, each
as a bytestring. For example, <code class="docutils literal"><span class="pre">[b'http/1.1',</span> <span class="pre">b'spdy/2']</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="OpenSSL.SSL.Connection.get_alpn_proto_negotiated">
<code class="descclassname">Connection.</code><code class="descname">get_alpn_proto_negotiated</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#OpenSSL.SSL.Connection.get_alpn_proto_negotiated" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the protocol that was negotiated by Application Layer Protocol
Negotiation. Returns a bytestring of the protocol name. If no protocol has
been negotiated yet, returns an empty string.</p>
</dd></dl>

<p class="rubric">Footnotes</p>
<table class="docutils footnote" frame="void" id="connection-context-socket" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Actually, all that is required is an object that
<strong>behaves</strong> like a socket, you could even use files, even though it&#8217;d be
tricky to get the handshakes right!</td></tr>
</tbody>
</table>
</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../internals.html" class="btn btn-neutral float-right" title="Internals" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="rand.html" class="btn btn-neutral" title="rand — An interface to the OpenSSL pseudo random number generator" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2001-2017, The pyOpenSSL developers.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'16.1.0',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>