[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.22.27.41: ~ $
:mod:`ssl` --- TLS/SSL wrapper for socket objects
=================================================

.. module:: ssl
   :synopsis: TLS/SSL wrapper for socket objects

.. moduleauthor:: Bill Janssen <bill.janssen@gmail.com>
.. sectionauthor::  Bill Janssen <bill.janssen@gmail.com>


.. index:: single: OpenSSL; (use in module ssl)

.. index:: TLS, SSL, Transport Layer Security, Secure Sockets Layer

.. versionadded:: 2.6

**Source code:** :source:`Lib/ssl.py`

--------------

This module provides access to Transport Layer Security (often known as "Secure
Sockets Layer") encryption and peer authentication facilities for network
sockets, both client-side and server-side.  This module uses the OpenSSL
library. It is available on all modern Unix systems, Windows, Mac OS X, and
probably additional platforms, as long as OpenSSL is installed on that platform.

.. note::

   Some behavior may be platform dependent, since calls are made to the
   operating system socket APIs.  The installed version of OpenSSL may also
   cause variations in behavior.

This section documents the objects and functions in the ``ssl`` module; for more
general information about TLS, SSL, and certificates, the reader is referred to
the documents in the "See Also" section at the bottom.

This module provides a class, :class:`ssl.SSLSocket`, which is derived from the
:class:`socket.socket` type, and provides a socket-like wrapper that also
encrypts and decrypts the data going over the socket with SSL.  It supports
additional :meth:`read` and :meth:`write` methods, along with a method,
:meth:`getpeercert`, to retrieve the certificate of the other side of the
connection, and a method, :meth:`cipher`, to retrieve the cipher being used for
the secure connection.

Functions, Constants, and Exceptions
------------------------------------

.. exception:: SSLError

   Raised to signal an error from the underlying SSL implementation.  This
   signifies some problem in the higher-level encryption and authentication
   layer that's superimposed on the underlying network connection.  This error
   is a subtype of :exc:`socket.error`, which in turn is a subtype of
   :exc:`IOError`.

.. function:: wrap_socket (sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version={see docs}, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None)

   Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance
   of :class:`ssl.SSLSocket`, a subtype of :class:`socket.socket`, which wraps
   the underlying socket in an SSL context.  For client-side sockets, the
   context construction is lazy; if the underlying socket isn't connected yet,
   the context construction will be performed after :meth:`connect` is called on
   the socket.  For server-side sockets, if the socket has no remote peer, it is
   assumed to be a listening socket, and the server-side SSL wrapping is
   automatically performed on client connections accepted via the :meth:`accept`
   method.  :func:`wrap_socket` may raise :exc:`SSLError`.

   The ``keyfile`` and ``certfile`` parameters specify optional files which
   contain a certificate to be used to identify the local side of the
   connection.  See the discussion of :ref:`ssl-certificates` for more
   information on how the certificate is stored in the ``certfile``.

   Often the private key is stored in the same file as the certificate; in this
   case, only the ``certfile`` parameter need be passed.  If the private key is
   stored in a separate file, both parameters must be used.  If the private key
   is stored in the ``certfile``, it should come before the first certificate in
   the certificate chain::

      -----BEGIN RSA PRIVATE KEY-----
      ... (private key in base64 encoding) ...
      -----END RSA PRIVATE KEY-----
      -----BEGIN CERTIFICATE-----
      ... (certificate in base64 PEM encoding) ...
      -----END CERTIFICATE-----

   The parameter ``server_side`` is a boolean which identifies whether
   server-side or client-side behavior is desired from this socket.

   The parameter ``cert_reqs`` specifies whether a certificate is required from
   the other side of the connection, and whether it will be validated if
   provided.  It must be one of the three values :const:`CERT_NONE`
   (certificates ignored), :const:`CERT_OPTIONAL` (not required, but validated
   if provided), or :const:`CERT_REQUIRED` (required and validated).  If the
   value of this parameter is not :const:`CERT_NONE`, then the ``ca_certs``
   parameter must point to a file of CA certificates.

   The ``ca_certs`` file contains a set of concatenated "certification
   authority" certificates, which are used to validate certificates passed from
   the other end of the connection.  See the discussion of
   :ref:`ssl-certificates` for more information about how to arrange the
   certificates in this file.

   The parameter ``ssl_version`` specifies which version of the SSL protocol to
   use.  Typically, the server chooses a particular protocol version, and the
   client must adapt to the server's choice.  Most of the versions are not
   interoperable with the other versions.  If not specified, the default is
   :data:`PROTOCOL_SSLv23`; it provides the most compatibility with other
   versions.

   Here's a table showing which versions in a client (down the side) can connect
   to which versions in a server (along the top):

     .. table::

       ========================  =========  =========  ==========  =========
        *client* / **server**    **SSLv2**  **SSLv3**  **SSLv23**  **TLSv1**
       ------------------------  ---------  ---------  ----------  ---------
        *SSLv2*                    yes        no         yes         no
        *SSLv3*                    no         yes        yes         no
        *SSLv23*                   yes        no         yes         no
        *TLSv1*                    no         no         yes         yes
       ========================  =========  =========  ==========  =========

   .. note::

      Which connections succeed will vary depending on the version of
      OpenSSL.  For instance, in some older versions of OpenSSL (such
      as 0.9.7l on OS X 10.4), an SSLv2 client could not connect to an
      SSLv23 server.  Another example: beginning with OpenSSL 1.0.0,
      an SSLv23 client will not actually attempt SSLv2 connections
      unless you explicitly enable SSLv2 ciphers; for example, you
      might specify ``"ALL"`` or ``"SSLv2"`` as the *ciphers* parameter
      to enable them.

   The *ciphers* parameter sets the available ciphers for this SSL object.
   It should be a string in the `OpenSSL cipher list format
   <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.

   The parameter ``do_handshake_on_connect`` specifies whether to do the SSL
   handshake automatically after doing a :meth:`socket.connect`, or whether the
   application program will call it explicitly, by invoking the
   :meth:`SSLSocket.do_handshake` method.  Calling
   :meth:`SSLSocket.do_handshake` explicitly gives the program control over the
   blocking behavior of the socket I/O involved in the handshake.

   The parameter ``suppress_ragged_eofs`` specifies how the
   :meth:`SSLSocket.read` method should signal unexpected EOF from the other end
   of the connection.  If specified as :const:`True` (the default), it returns a
   normal EOF in response to unexpected EOF errors raised from the underlying
   socket; if :const:`False`, it will raise the exceptions back to the caller.

   .. versionchanged:: 2.7
      New optional argument *ciphers*.

.. function:: RAND_status()

   Returns True if the SSL pseudo-random number generator has been seeded with
   'enough' randomness, and False otherwise.  You can use :func:`ssl.RAND_egd`
   and :func:`ssl.RAND_add` to increase the randomness of the pseudo-random
   number generator.

.. function:: RAND_egd(path)

   If you are running an entropy-gathering daemon (EGD) somewhere, and ``path``
   is the pathname of a socket connection open to it, this will read 256 bytes
   of randomness from the socket, and add it to the SSL pseudo-random number
   generator to increase the security of generated secret keys.  This is
   typically only necessary on systems without better sources of randomness.

   See http://egd.sourceforge.net/ or http://prngd.sourceforge.net/ for sources
   of entropy-gathering daemons.

.. function:: RAND_add(bytes, entropy)

   Mixes the given ``bytes`` into the SSL pseudo-random number generator.  The
   parameter ``entropy`` (a float) is a lower bound on the entropy contained in
   string (so you can always use :const:`0.0`).  See :rfc:`1750` for more
   information on sources of entropy.

.. function:: cert_time_to_seconds(timestring)

   Returns a floating-point value containing a normal seconds-after-the-epoch
   time value, given the time-string representing the "notBefore" or "notAfter"
   date from a certificate.

   Here's an example::

     >>> import ssl
     >>> ssl.cert_time_to_seconds("May  9 00:00:00 2007 GMT")
     1178694000.0
     >>> import time
     >>> time.ctime(ssl.cert_time_to_seconds("May  9 00:00:00 2007 GMT"))
     'Wed May  9 00:00:00 2007'
     >>>

.. function:: get_server_certificate (addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None)

   Given the address ``addr`` of an SSL-protected server, as a (*hostname*,
   *port-number*) pair, fetches the server's certificate, and returns it as a
   PEM-encoded string.  If ``ssl_version`` is specified, uses that version of
   the SSL protocol to attempt to connect to the server.  If ``ca_certs`` is
   specified, it should be a file containing a list of root certificates, the
   same format as used for the same parameter in :func:`wrap_socket`.  The call
   will attempt to validate the server certificate against that set of root
   certificates, and will fail if the validation attempt fails.

.. function:: DER_cert_to_PEM_cert (DER_cert_bytes)

   Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded
   string version of the same certificate.

.. function:: PEM_cert_to_DER_cert (PEM_cert_string)

   Given a certificate as an ASCII PEM string, returns a DER-encoded sequence of
   bytes for that same certificate.

.. data:: CERT_NONE

   Value to pass to the ``cert_reqs`` parameter to :func:`sslobject` when no
   certificates will be required or validated from the other side of the socket
   connection.

.. data:: CERT_OPTIONAL

   Value to pass to the ``cert_reqs`` parameter to :func:`sslobject` when no
   certificates will be required from the other side of the socket connection,
   but if they are provided, will be validated.  Note that use of this setting
   requires a valid certificate validation file also be passed as a value of the
   ``ca_certs`` parameter.

.. data:: CERT_REQUIRED

   Value to pass to the ``cert_reqs`` parameter to :func:`sslobject` when
   certificates will be required from the other side of the socket connection.
   Note that use of this setting requires a valid certificate validation file
   also be passed as a value of the ``ca_certs`` parameter.

.. data:: PROTOCOL_SSLv2

   Selects SSL version 2 as the channel encryption protocol.

   This protocol is not available if OpenSSL is compiled with OPENSSL_NO_SSL2
   flag.

   .. warning::

      SSL version 2 is insecure.  Its use is highly discouraged.

.. data:: PROTOCOL_SSLv23

   Selects SSL version 2 or 3 as the channel encryption protocol.  This is a
   setting to use with servers for maximum compatibility with the other end of
   an SSL connection, but it may cause the specific ciphers chosen for the
   encryption to be of fairly low quality.

.. data:: PROTOCOL_SSLv3

   Selects SSL version 3 as the channel encryption protocol.  For clients, this
   is the maximally compatible SSL variant.

.. data:: PROTOCOL_TLSv1

   Selects TLS version 1 as the channel encryption protocol.  This is the most
   modern version, and probably the best choice for maximum protection, if both
   sides can speak it.

.. data:: OPENSSL_VERSION

   The version string of the OpenSSL library loaded by the interpreter::

    >>> ssl.OPENSSL_VERSION
    'OpenSSL 0.9.8k 25 Mar 2009'

   .. versionadded:: 2.7

.. data:: OPENSSL_VERSION_INFO

   A tuple of five integers representing version information about the
   OpenSSL library::

    >>> ssl.OPENSSL_VERSION_INFO
    (0, 9, 8, 11, 15)

   .. versionadded:: 2.7

.. data:: OPENSSL_VERSION_NUMBER

   The raw version number of the OpenSSL library, as a single integer::

    >>> ssl.OPENSSL_VERSION_NUMBER
    9470143L
    >>> hex(ssl.OPENSSL_VERSION_NUMBER)
    '0x9080bfL'

   .. versionadded:: 2.7


SSLSocket Objects
-----------------

SSL sockets provide the following methods of :ref:`socket-objects`:

- :meth:`~socket.socket.accept()`
- :meth:`~socket.socket.bind()`
- :meth:`~socket.socket.close()`
- :meth:`~socket.socket.connect()`
- :meth:`~socket.socket.fileno()`
- :meth:`~socket.socket.getpeername()`, :meth:`~socket.socket.getsockname()`
- :meth:`~socket.socket.getsockopt()`, :meth:`~socket.socket.setsockopt()`
- :meth:`~socket.socket.gettimeout()`, :meth:`~socket.socket.settimeout()`,
  :meth:`~socket.socket.setblocking()`
- :meth:`~socket.socket.listen()`
- :meth:`~socket.socket.makefile()`
- :meth:`~socket.socket.recv()`, :meth:`~socket.socket.recv_into()`
  (but passing a non-zero ``flags`` argument is not allowed)
- :meth:`~socket.socket.send()`, :meth:`~socket.socket.sendall()` (with
  the same limitation)
- :meth:`~socket.socket.shutdown()`

However, since the SSL (and TLS) protocol has its own framing atop
of TCP, the SSL sockets abstraction can, in certain respects, diverge from
the specification of normal, OS-level sockets.

SSL sockets also have the following additional methods and attributes:

.. method:: SSLSocket.getpeercert(binary_form=False)

   If there is no certificate for the peer on the other end of the connection,
   returns ``None``.

   If the ``binary_form`` parameter is :const:`False`, and a certificate was
   received from the peer, this method returns a :class:`dict` instance.  If the
   certificate was not validated, the dict is empty.  If the certificate was
   validated, it returns a dict with the keys ``subject`` (the principal for
   which the certificate was issued), and ``notAfter`` (the time after which the
   certificate should not be trusted).  The certificate was already validated,
   so the ``notBefore`` and ``issuer`` fields are not returned.  If a
   certificate contains an instance of the *Subject Alternative Name* extension
   (see :rfc:`3280`), there will also be a ``subjectAltName`` key in the
   dictionary.

   The "subject" field is a tuple containing the sequence of relative
   distinguished names (RDNs) given in the certificate's data structure for the
   principal, and each RDN is a sequence of name-value pairs::

      {'notAfter': 'Feb 16 16:54:50 2013 GMT',
       'subject': ((('countryName', u'US'),),
                   (('stateOrProvinceName', u'Delaware'),),
                   (('localityName', u'Wilmington'),),
                   (('organizationName', u'Python Software Foundation'),),
                   (('organizationalUnitName', u'SSL'),),
                   (('commonName', u'somemachine.python.org'),))}

   If the ``binary_form`` parameter is :const:`True`, and a certificate was
   provided, this method returns the DER-encoded form of the entire certificate
   as a sequence of bytes, or :const:`None` if the peer did not provide a
   certificate.  Whether the peer provides a certificate depends on the SSL
   socket's role:

   * for a client SSL socket, the server will always provide a certificate,
     regardless of whether validation was required;

   * for a server SSL socket, the client will only provide a certificate
     when requested by the server; therefore :meth:`getpeercert` will return
     :const:`None` if you used :const:`CERT_NONE` (rather than
     :const:`CERT_OPTIONAL` or :const:`CERT_REQUIRED`).

.. method:: SSLSocket.cipher()

   Returns a three-value tuple containing the name of the cipher being used, the
   version of the SSL protocol that defines its use, and the number of secret
   bits being used.  If no connection has been established, returns ``None``.

.. method:: SSLSocket.do_handshake()

   Perform a TLS/SSL handshake.  If this is used with a non-blocking socket, it
   may raise :exc:`SSLError` with an ``arg[0]`` of :const:`SSL_ERROR_WANT_READ`
   or :const:`SSL_ERROR_WANT_WRITE`, in which case it must be called again until
   it completes successfully.  For example, to simulate the behavior of a
   blocking socket, one might write::

        while True:
            try:
                s.do_handshake()
                break
            except ssl.SSLError as err:
                if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                    select.select([s], [], [])
                elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                    select.select([], [s], [])
                else:
                    raise

.. method:: SSLSocket.unwrap()

   Performs the SSL shutdown handshake, which removes the TLS layer from the
   underlying socket, and returns the underlying socket object.  This can be
   used to go from encrypted operation over a connection to unencrypted.  The
   socket instance returned should always be used for further communication with
   the other side of the connection, rather than the original socket instance
   (which may not function properly after the unwrap).

.. index:: single: certificates

.. index:: single: X509 certificate

.. _ssl-certificates:

Certificates
------------

Certificates in general are part of a public-key / private-key system.  In this
system, each *principal*, (which may be a machine, or a person, or an
organization) is assigned a unique two-part encryption key.  One part of the key
is public, and is called the *public key*; the other part is kept secret, and is
called the *private key*.  The two parts are related, in that if you encrypt a
message with one of the parts, you can decrypt it with the other part, and
**only** with the other part.

A certificate contains information about two principals.  It contains the name
of a *subject*, and the subject's public key.  It also contains a statement by a
second principal, the *issuer*, that the subject is who he claims to be, and
that this is indeed the subject's public key.  The issuer's statement is signed
with the issuer's private key, which only the issuer knows.  However, anyone can
verify the issuer's statement by finding the issuer's public key, decrypting the
statement with it, and comparing it to the other information in the certificate.
The certificate also contains information about the time period over which it is
valid.  This is expressed as two fields, called "notBefore" and "notAfter".

In the Python use of certificates, a client or server can use a certificate to
prove who they are.  The other side of a network connection can also be required
to produce a certificate, and that certificate can be validated to the
satisfaction of the client or server that requires such validation.  The
connection attempt can be set to raise an exception if the validation fails.
Validation is done automatically, by the underlying OpenSSL framework; the
application need not concern itself with its mechanics.  But the application
does usually need to provide sets of certificates to allow this process to take
place.

Python uses files to contain certificates.  They should be formatted as "PEM"
(see :rfc:`1422`), which is a base-64 encoded form wrapped with a header line
and a footer line::

      -----BEGIN CERTIFICATE-----
      ... (certificate in base64 PEM encoding) ...
      -----END CERTIFICATE-----

The Python files which contain certificates can contain a sequence of
certificates, sometimes called a *certificate chain*.  This chain should start
with the specific certificate for the principal who "is" the client or server,
and then the certificate for the issuer of that certificate, and then the
certificate for the issuer of *that* certificate, and so on up the chain till
you get to a certificate which is *self-signed*, that is, a certificate which
has the same subject and issuer, sometimes called a *root certificate*.  The
certificates should just be concatenated together in the certificate file.  For
example, suppose we had a three certificate chain, from our server certificate
to the certificate of the certification authority that signed our server
certificate, to the root certificate of the agency which issued the
certification authority's certificate::

      -----BEGIN CERTIFICATE-----
      ... (certificate for your server)...
      -----END CERTIFICATE-----
      -----BEGIN CERTIFICATE-----
      ... (the certificate for the CA)...
      -----END CERTIFICATE-----
      -----BEGIN CERTIFICATE-----
      ... (the root certificate for the CA's issuer)...
      -----END CERTIFICATE-----

If you are going to require validation of the other side of the connection's
certificate, you need to provide a "CA certs" file, filled with the certificate
chains for each issuer you are willing to trust.  Again, this file just contains
these chains concatenated together.  For validation, Python will use the first
chain it finds in the file which matches.

Some "standard" root certificates are available from various certification
authorities: `CACert.org <http://www.cacert.org/index.php?id=3>`_, `Thawte
<http://www.thawte.com/roots/>`_, `Verisign
<http://www.verisign.com/support/roots.html>`_, `Positive SSL
<http://www.PositiveSSL.com/ssl-certificate-support/cert_installation/UTN-USERFirst-Hardware.crt>`_
(used by python.org), `Equifax and GeoTrust
<http://www.geotrust.com/resources/root_certificates/index.asp>`_.

In general, if you are using SSL3 or TLS1, you don't need to put the full chain
in your "CA certs" file; you only need the root certificates, and the remote
peer is supposed to furnish the other certificates necessary to chain from its
certificate to a root certificate.  See :rfc:`4158` for more discussion of the
way in which certification chains can be built.

If you are going to create a server that provides SSL-encrypted connection
services, you will need to acquire a certificate for that service.  There are
many ways of acquiring appropriate certificates, such as buying one from a
certification authority.  Another common practice is to generate a self-signed
certificate.  The simplest way to do this is with the OpenSSL package, using
something like the following::

  % openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
  Generating a 1024 bit RSA private key
  .......++++++
  .............................++++++
  writing new private key to 'cert.pem'
  -----
  You are about to be asked to enter information that will be incorporated
  into your certificate request.
  What you are about to enter is what is called a Distinguished Name or a DN.
  There are quite a few fields but you can leave some blank
  For some fields there will be a default value,
  If you enter '.', the field will be left blank.
  -----
  Country Name (2 letter code) [AU]:US
  State or Province Name (full name) [Some-State]:MyState
  Locality Name (eg, city) []:Some City
  Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc.
  Organizational Unit Name (eg, section) []:My Group
  Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com
  Email Address []:ops@myserver.mygroup.myorganization.com
  %

The disadvantage of a self-signed certificate is that it is its own root
certificate, and no one else will have it in their cache of known (and trusted)
root certificates.


Examples
--------

Testing for SSL support
^^^^^^^^^^^^^^^^^^^^^^^

To test for the presence of SSL support in a Python installation, user code
should use the following idiom::

   try:
       import ssl
   except ImportError:
       pass
   else:
       ... # do something that requires SSL support

Client-side operation
^^^^^^^^^^^^^^^^^^^^^

This example connects to an SSL server, prints the server's address and
certificate, sends some bytes, and reads part of the response::

   import socket, ssl, pprint

   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

   # require a certificate from the server
   ssl_sock = ssl.wrap_socket(s,
                              ca_certs="/etc/ca_certs_file",
                              cert_reqs=ssl.CERT_REQUIRED)

   ssl_sock.connect(('www.verisign.com', 443))

   print repr(ssl_sock.getpeername())
   print ssl_sock.cipher()
   print pprint.pformat(ssl_sock.getpeercert())

   # Set a simple HTTP request -- use httplib in actual code.
   ssl_sock.write("""GET / HTTP/1.0\r
   Host: www.verisign.com\r\n\r\n""")

   # Read a chunk of data.  Will not necessarily
   # read all the data returned by the server.
   data = ssl_sock.read()

   # note that closing the SSLSocket will also close the underlying socket
   ssl_sock.close()

As of September 6, 2007, the certificate printed by this program looked like
this::

      {'notAfter': 'May  8 23:59:59 2009 GMT',
       'subject': ((('serialNumber', u'2497886'),),
                   (('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
                   (('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
                   (('countryName', u'US'),),
                   (('postalCode', u'94043'),),
                   (('stateOrProvinceName', u'California'),),
                   (('localityName', u'Mountain View'),),
                   (('streetAddress', u'487 East Middlefield Road'),),
                   (('organizationName', u'VeriSign, Inc.'),),
                   (('organizationalUnitName',
                     u'Production Security Services'),),
                   (('organizationalUnitName',
                     u'Terms of use at www.verisign.com/rpa (c)06'),),
                   (('commonName', u'www.verisign.com'),))}

which is a fairly poorly-formed ``subject`` field.

Server-side operation
^^^^^^^^^^^^^^^^^^^^^

For server operation, typically you'd need to have a server certificate, and
private key, each in a file.  You'd open a socket, bind it to a port, call
:meth:`listen` on it, then start waiting for clients to connect::

   import socket, ssl

   bindsocket = socket.socket()
   bindsocket.bind(('myaddr.mydomain.com', 10023))
   bindsocket.listen(5)

When one did, you'd call :meth:`accept` on the socket to get the new socket from
the other end, and use :func:`wrap_socket` to create a server-side SSL context
for it::

   while True:
       newsocket, fromaddr = bindsocket.accept()
       connstream = ssl.wrap_socket(newsocket,
                                    server_side=True,
                                    certfile="mycertfile",
                                    keyfile="mykeyfile",
                                    ssl_version=ssl.PROTOCOL_TLSv1)
       try:
           deal_with_client(connstream)
       finally:
           connstream.shutdown(socket.SHUT_RDWR)
           connstream.close()

Then you'd read data from the ``connstream`` and do something with it till you
are finished with the client (or the client is finished with you)::

   def deal_with_client(connstream):
       data = connstream.read()
       # null data means the client is finished with us
       while data:
           if not do_something(connstream, data):
               # we'll assume do_something returns False
               # when we're finished with client
               break
           data = connstream.read()
       # finished with client

And go back to listening for new client connections.


.. seealso::

   Class :class:`socket.socket`
            Documentation of underlying :mod:`socket` class

   `TLS (Transport Layer Security) and SSL (Secure Socket Layer) <http://www3.rad.com/networks/applications/secure/tls.htm>`_
      Debby Koren

   `RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management <http://www.ietf.org/rfc/rfc1422>`_
       Steve Kent

   `RFC 1750: Randomness Recommendations for Security <http://www.ietf.org/rfc/rfc1750>`_
       D. Eastlake et. al.

   `RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile <http://www.ietf.org/rfc/rfc3280>`_
       Housley et. al.

Filemanager

Name Type Size Permission Actions
2to3.txt File 12.37 KB 0644
__builtin__.txt File 1.45 KB 0644
__future__.txt File 4.84 KB 0644
__main__.txt File 535 B 0644
_winreg.txt File 22.76 KB 0644
abc.txt File 6.99 KB 0644
aepack.txt File 4.16 KB 0644
aetools.txt File 3.45 KB 0644
aetypes.txt File 4.16 KB 0644
aifc.txt File 6.91 KB 0644
al.txt File 5.18 KB 0644
allos.txt File 695 B 0644
anydbm.txt File 3.87 KB 0644
archiving.txt File 424 B 0644
argparse.txt File 68.77 KB 0644
array.txt File 10.4 KB 0644
ast.txt File 9.7 KB 0644
asynchat.txt File 8.99 KB 0644
asyncore.txt File 12.37 KB 0644
atexit.txt File 3.81 KB 0644
audioop.txt File 10.15 KB 0644
autogil.txt File 1015 B 0644
base64.txt File 5.93 KB 0644
basehttpserver.txt File 9.98 KB 0644
bastion.txt File 2.55 KB 0644
bdb.txt File 12.14 KB 0644
binascii.txt File 6.04 KB 0644
binhex.txt File 1.87 KB 0644
bisect.txt File 5.29 KB 0644
bsddb.txt File 7.4 KB 0644
bz2.txt File 7.72 KB 0644
calendar.txt File 11.01 KB 0644
carbon.txt File 15.58 KB 0644
cd.txt File 11.69 KB 0644
cgi.txt File 22.12 KB 0644
cgihttpserver.txt File 2.72 KB 0644
cgitb.txt File 2.81 KB 0644
chunk.txt File 4.82 KB 0644
cmath.txt File 7.45 KB 0644
cmd.txt File 8.14 KB 0644
code.txt File 6.93 KB 0644
codecs.txt File 63.19 KB 0644
codeop.txt File 3.69 KB 0644
collections.txt File 40.08 KB 0644
colorpicker.txt File 913 B 0644
colorsys.txt File 1.78 KB 0644
commands.txt File 2.53 KB 0644
compileall.txt File 4.49 KB 0644
compiler.txt File 36.59 KB 0644
configparser.txt File 19 KB 0644
constants.txt File 2.18 KB 0644
contextlib.txt File 5.36 KB 0644
cookie.txt File 9.3 KB 0644
cookielib.txt File 27.09 KB 0644
copy.txt File 3.29 KB 0644
copy_reg.txt File 2.27 KB 0644
crypt.txt File 2.24 KB 0644
crypto.txt File 771 B 0644
csv.txt File 21.07 KB 0644
ctypes.txt File 86.41 KB 0644
curses.ascii.txt File 8.8 KB 0644
curses.panel.txt File 2.68 KB 0644
curses.txt File 70.87 KB 0644
custominterp.txt File 570 B 0644
datatypes.txt File 864 B 0644
datetime.txt File 68.78 KB 0644
dbhash.txt File 3.77 KB 0644
dbm.txt File 2.89 KB 0644
debug.txt File 446 B 0644
decimal.txt File 68.95 KB 0644
development.txt File 640 B 0644
difflib.txt File 29.85 KB 0644
dircache.txt File 1.77 KB 0644
dis.txt File 20.82 KB 0644
distutils.txt File 1.13 KB 0644
dl.txt File 3.31 KB 0644
doctest.txt File 71.42 KB 0644
docxmlrpcserver.txt File 3.66 KB 0644
dumbdbm.txt File 2.62 KB 0644
dummy_thread.txt File 1.03 KB 0644
dummy_threading.txt File 799 B 0644
easydialogs.txt File 10.1 KB 0644
email-examples.txt File 1.24 KB 0644
email.charset.txt File 9.42 KB 0644
email.encoders.txt File 2.32 KB 0644
email.errors.txt File 3.73 KB 0644
email.generator.txt File 5.99 KB 0644
email.header.txt File 7.35 KB 0644
email.iterators.txt File 2.28 KB 0644
email.message.txt File 24.56 KB 0644
email.mime.txt File 9.42 KB 0644
email.parser.txt File 9.71 KB 0644
email.txt File 14.61 KB 0644
email.util.txt File 6.43 KB 0644
errno.txt File 6.55 KB 0644
exceptions.txt File 18.01 KB 0644
fcntl.txt File 6.65 KB 0644
filecmp.txt File 5.22 KB 0644
fileformats.txt File 302 B 0644
fileinput.txt File 7.06 KB 0644
filesys.txt File 806 B 0644
fl.txt File 17.23 KB 0644
fm.txt File 2.64 KB 0644
fnmatch.txt File 3.03 KB 0644
formatter.txt File 12.92 KB 0644
fpectl.txt File 4.07 KB 0644
fpformat.txt File 1.71 KB 0644
fractions.txt File 5.17 KB 0644
framework.txt File 11.18 KB 0644
frameworks.txt File 378 B 0644
ftplib.txt File 14.79 KB 0644
functions.txt File 72.74 KB 0644
functools.txt File 7.15 KB 0644
future_builtins.txt File 1.86 KB 0644
gc.txt File 8.76 KB 0644
gdbm.txt File 4.71 KB 0644
gensuitemodule.txt File 3.04 KB 0644
getopt.txt File 6.51 KB 0644
getpass.txt File 1.9 KB 0644
gettext.txt File 28.35 KB 0644
gl.txt File 5.87 KB 0644
glob.txt File 2.31 KB 0644
grp.txt File 2.2 KB 0644
gzip.txt File 4.62 KB 0644
hashlib.txt File 5.01 KB 0644
heapq.txt File 12.64 KB 0644
hmac.txt File 1.82 KB 0644
hotshot.txt File 4.19 KB 0644
htmllib.txt File 7.03 KB 0644
htmlparser.txt File 11.34 KB 0644
httplib.txt File 35.65 KB 0644
i18n.txt File 409 B 0644
ic.txt File 4.89 KB 0644
idle.txt File 7.88 KB 0644
imageop.txt File 3.91 KB 0644
imaplib.txt File 16.77 KB 0644
imgfile.txt File 2.7 KB 0644
imghdr.txt File 2.57 KB 0644
imp.txt File 12.3 KB 0644
importlib.txt File 1.1 KB 0644
imputil.txt File 6.86 KB 0644
index.txt File 2.23 KB 0644
inspect.txt File 27.21 KB 0644
internet.txt File 950 B 0644
intro.txt File 2.74 KB 0644
io.txt File 36.31 KB 0644
ipc.txt File 631 B 0644
itertools.txt File 34.69 KB 0644
jpeg.txt File 3.77 KB 0644
json.txt File 23.39 KB 0644
keyword.txt File 617 B 0644
language.txt File 523 B 0644
linecache.txt File 1.84 KB 0644
locale.txt File 24.19 KB 0644
logging.config.txt File 29.76 KB 0644
logging.handlers.txt File 26.45 KB 0644
logging.txt File 43.67 KB 0644
mac.txt File 791 B 0644
macos.txt File 3.73 KB 0644
macosa.txt File 3.87 KB 0644
macostools.txt File 3.92 KB 0644
macpath.txt File 650 B 0644
mailbox.txt File 66.51 KB 0644
mailcap.txt File 3.59 KB 0644
markup.txt File 1.22 KB 0644
marshal.txt File 5.47 KB 0644
math.txt File 10.64 KB 0644
md5.txt File 2.75 KB 0644
mhlib.txt File 3.87 KB 0644
mimetools.txt File 4.4 KB 0644
mimetypes.txt File 9.3 KB 0644
mimewriter.txt File 3.2 KB 0644
mimify.txt File 3.44 KB 0644
miniaeframe.txt File 2.5 KB 0644
misc.txt File 248 B 0644
mm.txt File 447 B 0644
mmap.txt File 10.02 KB 0644
modulefinder.txt File 3.3 KB 0644
modules.txt File 382 B 0644
msilib.txt File 18.94 KB 0644
msvcrt.txt File 4.24 KB 0644
multifile.txt File 6.46 KB 0644
multiprocessing.txt File 79.92 KB 0644
mutex.txt File 1.89 KB 0644
netdata.txt File 432 B 0644
netrc.txt File 2.54 KB 0644
new.txt File 2.59 KB 0644
nis.txt File 2.06 KB 0644
nntplib.txt File 14.18 KB 0644
numbers.txt File 7.82 KB 0644
numeric.txt File 751 B 0644
operator.txt File 21.57 KB 0644
optparse.txt File 75.22 KB 0644
os.path.txt File 12.45 KB 0644
os.txt File 79.94 KB 0644
ossaudiodev.txt File 16.9 KB 0644
othergui.txt File 2.73 KB 0644
parser.txt File 15.02 KB 0644
pdb.txt File 15.61 KB 0644
persistence.txt File 826 B 0644
pickle.txt File 36.25 KB 0644
pickletools.txt File 1.95 KB 0644
pipes.txt File 3.7 KB 0644
pkgutil.txt File 7.53 KB 0644
platform.txt File 9.15 KB 0644
plistlib.txt File 4.02 KB 0644
popen2.txt File 6.86 KB 0644
poplib.txt File 6.07 KB 0644
posix.txt File 3.51 KB 0644
posixfile.txt File 7.03 KB 0644
pprint.txt File 8.86 KB 0644
profile.txt File 27.81 KB 0644
pty.txt File 1.72 KB 0644
pwd.txt File 2.66 KB 0644
py_compile.txt File 2.42 KB 0644
pyclbr.txt File 3.22 KB 0644
pydoc.txt File 3.34 KB 0644
pyexpat.txt File 27.83 KB 0644
python.txt File 531 B 0644
queue.txt File 6.8 KB 0644
quopri.txt File 2.61 KB 0644
random.txt File 12.71 KB 0644
re.txt File 51.28 KB 0644
readline.txt File 7.08 KB 0644
repr.txt File 4.57 KB 0644
resource.txt File 9.61 KB 0644
restricted.txt File 3.24 KB 0644
rexec.txt File 11.47 KB 0644
rfc822.txt File 13.71 KB 0644
rlcompleter.txt File 2.44 KB 0644
robotparser.txt File 2.14 KB 0644
runpy.txt File 6.46 KB 0644
sched.txt File 4.49 KB 0644
scrolledtext.txt File 1.32 KB 0644
select.txt File 20.17 KB 0644
sets.txt File 14.54 KB 0644
sgi.txt File 322 B 0644
sgmllib.txt File 10.41 KB 0644
sha.txt File 2.74 KB 0644
shelve.txt File 7.96 KB 0644
shlex.txt File 10.82 KB 0644
shutil.txt File 12.88 KB 0644
signal.txt File 10.33 KB 0644
simplehttpserver.txt File 4.34 KB 0644
simplexmlrpcserver.txt File 9.7 KB 0644
site.txt File 7.4 KB 0644
smtpd.txt File 2.31 KB 0644
smtplib.txt File 14.1 KB 0644
sndhdr.txt File 1.72 KB 0644
socket.txt File 39.7 KB 0644
socketserver.txt File 20.12 KB 0644
someos.txt File 599 B 0644
spwd.txt File 2.76 KB 0644
sqlite3.txt File 34.28 KB 0644
ssl.txt File 27.8 KB 0644
stat.txt File 7.59 KB 0644
statvfs.txt File 1.27 KB 0644
stdtypes.txt File 115.81 KB 0644
string.txt File 42.78 KB 0644
stringio.txt File 4 KB 0644
stringprep.txt File 4.15 KB 0644
strings.txt File 746 B 0644
struct.txt File 16.7 KB 0644
subprocess.txt File 32.68 KB 0644
sun.txt File 249 B 0644
sunau.txt File 6.96 KB 0644
sunaudio.txt File 5.71 KB 0644
symbol.txt File 975 B 0644
symtable.txt File 4.89 KB 0644
sys.txt File 45.76 KB 0644
sysconfig.txt File 7.38 KB 0644
syslog.txt File 3.84 KB 0644
tabnanny.txt File 1.97 KB 0644
tarfile.txt File 26.51 KB 0644
telnetlib.txt File 7.31 KB 0644
tempfile.txt File 10.23 KB 0644
termios.txt File 3.66 KB 0644
test.txt File 17.06 KB 0644
textwrap.txt File 8.35 KB 0644
thread.txt File 6.59 KB 0644
threading.txt File 31.1 KB 0644
time.txt File 24.79 KB 0644
timeit.txt File 11.25 KB 0644
tix.txt File 22.17 KB 0644
tk.txt File 1.57 KB 0644
tkinter.txt File 30.56 KB 0644
token.txt File 2.39 KB 0644
tokenize.txt File 5 KB 0644
trace.txt File 6.57 KB 0644
traceback.txt File 10.45 KB 0644
ttk.txt File 56.02 KB 0644
tty.txt File 1011 B 0644
turtle.txt File 62.57 KB 0644
types.txt File 6.04 KB 0644
undoc.txt File 6.4 KB 0644
unicodedata.txt File 5.59 KB 0644
unittest.txt File 80.78 KB 0644
unix.txt File 490 B 0644
urllib.txt File 22.47 KB 0644
urllib2.txt File 33.13 KB 0644
urlparse.txt File 15.61 KB 0644
user.txt File 2.68 KB 0644
userdict.txt File 8.69 KB 0644
uu.txt File 2.31 KB 0644
uuid.txt File 8.17 KB 0644
warnings.txt File 19.32 KB 0644
wave.txt File 4.93 KB 0644
weakref.txt File 12.66 KB 0644
webbrowser.txt File 8.97 KB 0644
whichdb.txt File 931 B 0644
windows.txt File 273 B 0644
winsound.txt File 4.87 KB 0644
wsgiref.txt File 29.84 KB 0644
xdrlib.txt File 7.89 KB 0644
xml.dom.minidom.txt File 10.91 KB 0644
xml.dom.pulldom.txt File 1.53 KB 0644
xml.dom.txt File 39.2 KB 0644
xml.etree.elementtree.txt File 31.82 KB 0644
xml.sax.handler.txt File 14.93 KB 0644
xml.sax.reader.txt File 11.65 KB 0644
xml.sax.txt File 6.06 KB 0644
xml.sax.utils.txt File 3.4 KB 0644
xml.txt File 5.56 KB 0644
xmlrpclib.txt File 21.4 KB 0644
zipfile.txt File 17.22 KB 0644
zipimport.txt File 5.78 KB 0644
zlib.txt File 10.13 KB 0644