3.3 SSL -- An interface to the SSL-specific parts of OpenSSL
This module handles things specific to SSL. There are two objects defined:
These constants represent the different SSL methods to use when creating a
These constants represent the verification mode used by the Context
object's set_verify method.
File type constants used with the use_certificate_file and
use_privatekey_file methods of Context objects.
Constants used with set_options of Context objects.
OP_SINGLE_DH_USE means to always create a new key when using ephemeral
Diffie-Hellman. OP_EPHEMERAL_RSA means to always use ephemeral RSA keys
when doing RSA operations. OP_NO_SSLv2, OP_NO_SSLv3 and
OP_NO_TLSv1 means to disable those specific protocols. This is
interesting if you're using e.g. SSLv23_METHOD to get an SSLv2-compatible
handshake, but don't want to use SSLv2.
Constants used with SSLeay_version to specify what OpenSSL version
information to retrieve. See the man page for the SSLeay_version C
API for details.
An integer giving the version number of the OpenSSL library used to build this
version of pyOpenSSL. See the man page for the SSLeay_version C API
Retrieve a string describing some aspect of the underlying OpenSSL version. The
type passed in should be one of the SSLEAY_* constants defined in
- class Context(method)
A class representing SSL contexts. Contexts define the parameters of one or
more SSL connections.
method should be SSLv2_METHOD, SSLv3_METHOD,
SSLv23_METHOD or TLSv1_METHOD.
- class Connection(context, socket)
A class representing SSL connections.
context should be an instance of Context and socket
should be a socket 3 object. socket may be
None; in this case, the Connection is created with a memory BIO: see
the bio_read, bio_write, and bio_shutdown
- exception Error
This exception is used as a base class for the other SSL-related
exceptions, but may also be raised directly.
Whenever this exception is raised directly, it has a list of error messages
from the OpenSSL error queue, where each item is a tuple
function, reason). Here lib, function and reason
are all strings, describing where and what the problem is. See err(3)
for more information.
- exception ZeroReturnError
This exception matches the error return code
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.
It may seem a little strange that this is an exception, but it does match an
SSL_ERROR code, and is very convenient.
- exception WantReadError
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.
The wanted read is for dirty data sent over the network, not the
clean data inside the tunnel. For a socket based SSL connection,
read means data coming at us over the network. Until that read
succeeds, the attempted OpenSSL.SSL.Connection.recv,
OpenSSL.SSL.Connection.do_handshake is prevented or incomplete. You
probably want to select() on the socket before trying again.
- exception WantWriteError
See WantReadError. The socket send buffer may be too full to
write more data.
- exception WantX509LookupError
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. Note: This won't occur in this version, as there are no such
callbacks in this version.
- exception SysCallError
The SysCallError occurs when there's an I/O error and OpenSSL'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
- ... socket3
- Actually, all that is required is an object
that behaves like a socket, you could even use files, even though
it'd be tricky to get the handshakes right!