blob: bc55262d91abbd4d62d716db5bde5a2b687b5847 [file] [log] [blame]
Thomas Wouters47b49bf2007-08-30 22:15:33 +00001:mod:`ssl` --- SSL wrapper for socket objects
Georg Brandl7f01a132009-09-16 15:58:14 +00002=============================================
Thomas Woutersed03b412007-08-28 21:37:11 +00003
4.. module:: ssl
Thomas Wouters47b49bf2007-08-30 22:15:33 +00005 :synopsis: SSL wrapper for socket objects
6
7.. moduleauthor:: Bill Janssen <bill.janssen@gmail.com>
Thomas Wouters47b49bf2007-08-30 22:15:33 +00008.. sectionauthor:: Bill Janssen <bill.janssen@gmail.com>
9
Thomas Woutersed03b412007-08-28 21:37:11 +000010
Thomas Wouters1b7f8912007-09-19 03:06:30 +000011.. index:: single: OpenSSL; (use in module ssl)
12
13.. index:: TLS, SSL, Transport Layer Security, Secure Sockets Layer
14
Georg Brandl7f01a132009-09-16 15:58:14 +000015This module provides access to Transport Layer Security (often known as "Secure
16Sockets Layer") encryption and peer authentication facilities for network
17sockets, both client-side and server-side. This module uses the OpenSSL
18library. It is available on all modern Unix systems, Windows, Mac OS X, and
19probably additional platforms, as long as OpenSSL is installed on that platform.
Thomas Woutersed03b412007-08-28 21:37:11 +000020
21.. note::
22
Georg Brandl7f01a132009-09-16 15:58:14 +000023 Some behavior may be platform dependent, since calls are made to the
24 operating system socket APIs. The installed version of OpenSSL may also
25 cause variations in behavior.
Thomas Woutersed03b412007-08-28 21:37:11 +000026
Georg Brandl7f01a132009-09-16 15:58:14 +000027This section documents the objects and functions in the ``ssl`` module; for more
28general information about TLS, SSL, and certificates, the reader is referred to
29the documents in the "See Also" section at the bottom.
Thomas Woutersed03b412007-08-28 21:37:11 +000030
Georg Brandl7f01a132009-09-16 15:58:14 +000031This module provides a class, :class:`ssl.SSLSocket`, which is derived from the
32:class:`socket.socket` type, and provides a socket-like wrapper that also
33encrypts and decrypts the data going over the socket with SSL. It supports
34additional :meth:`read` and :meth:`write` methods, along with a method,
35:meth:`getpeercert`, to retrieve the certificate of the other side of the
36connection, and a method, :meth:`cipher`, to retrieve the cipher being used for
37the secure connection.
Thomas Woutersed03b412007-08-28 21:37:11 +000038
Antoine Pitrou152efa22010-05-16 18:19:27 +000039For more sophisticated applications, the :class:`ssl.SSLContext` class
40helps manage settings and certificates, which can then be inherited
41by SSL sockets created through the :meth:`SSLContext.wrap_socket` method.
42
43
Thomas Wouters1b7f8912007-09-19 03:06:30 +000044Functions, Constants, and Exceptions
45------------------------------------
46
47.. exception:: SSLError
48
Georg Brandl48310cd2009-01-03 21:18:54 +000049 Raised to signal an error from the underlying SSL implementation. This
Georg Brandl7f01a132009-09-16 15:58:14 +000050 signifies some problem in the higher-level encryption and authentication
51 layer that's superimposed on the underlying network connection. This error
52 is a subtype of :exc:`socket.error`, which in turn is a subtype of
53 :exc:`IOError`.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000054
Antoine Pitrou2d9cb9c2010-04-17 17:40:45 +000055.. 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)
Thomas Wouters1b7f8912007-09-19 03:06:30 +000056
Georg Brandl7f01a132009-09-16 15:58:14 +000057 Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance
58 of :class:`ssl.SSLSocket`, a subtype of :class:`socket.socket`, which wraps
59 the underlying socket in an SSL context. For client-side sockets, the
60 context construction is lazy; if the underlying socket isn't connected yet,
61 the context construction will be performed after :meth:`connect` is called on
62 the socket. For server-side sockets, if the socket has no remote peer, it is
63 assumed to be a listening socket, and the server-side SSL wrapping is
64 automatically performed on client connections accepted via the :meth:`accept`
65 method. :func:`wrap_socket` may raise :exc:`SSLError`.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000066
Georg Brandl7f01a132009-09-16 15:58:14 +000067 The ``keyfile`` and ``certfile`` parameters specify optional files which
68 contain a certificate to be used to identify the local side of the
69 connection. See the discussion of :ref:`ssl-certificates` for more
70 information on how the certificate is stored in the ``certfile``.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000071
Georg Brandl7f01a132009-09-16 15:58:14 +000072 The parameter ``server_side`` is a boolean which identifies whether
73 server-side or client-side behavior is desired from this socket.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000074
Georg Brandl7f01a132009-09-16 15:58:14 +000075 The parameter ``cert_reqs`` specifies whether a certificate is required from
76 the other side of the connection, and whether it will be validated if
77 provided. It must be one of the three values :const:`CERT_NONE`
78 (certificates ignored), :const:`CERT_OPTIONAL` (not required, but validated
79 if provided), or :const:`CERT_REQUIRED` (required and validated). If the
80 value of this parameter is not :const:`CERT_NONE`, then the ``ca_certs``
81 parameter must point to a file of CA certificates.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000082
Georg Brandl7f01a132009-09-16 15:58:14 +000083 The ``ca_certs`` file contains a set of concatenated "certification
84 authority" certificates, which are used to validate certificates passed from
85 the other end of the connection. See the discussion of
86 :ref:`ssl-certificates` for more information about how to arrange the
87 certificates in this file.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000088
Georg Brandl7f01a132009-09-16 15:58:14 +000089 The parameter ``ssl_version`` specifies which version of the SSL protocol to
90 use. Typically, the server chooses a particular protocol version, and the
91 client must adapt to the server's choice. Most of the versions are not
92 interoperable with the other versions. If not specified, for client-side
93 operation, the default SSL version is SSLv3; for server-side operation,
94 SSLv23. These version selections provide the most compatibility with other
95 versions.
Thomas Wouters1b7f8912007-09-19 03:06:30 +000096
Georg Brandl7f01a132009-09-16 15:58:14 +000097 Here's a table showing which versions in a client (down the side) can connect
98 to which versions in a server (along the top):
Thomas Wouters1b7f8912007-09-19 03:06:30 +000099
100 .. table::
101
102 ======================== ========= ========= ========== =========
103 *client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1**
Christian Heimes255f53b2007-12-08 15:33:56 +0000104 ------------------------ --------- --------- ---------- ---------
Antoine Pitrou2d9cb9c2010-04-17 17:40:45 +0000105 *SSLv2* yes no yes no
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000106 *SSLv3* yes yes yes no
107 *SSLv23* yes no yes no
108 *TLSv1* no no yes yes
109 ======================== ========= ========= ========== =========
110
Antoine Pitrou2d9cb9c2010-04-17 17:40:45 +0000111 .. note::
112
113 This information varies depending on the version of OpenSSL.
114 For instance, in some older versions of OpenSSL (such as 0.9.7l on
115 OS X 10.4), an SSLv2 client could not connect to an SSLv23 server.
116 Conversely, starting from 1.0.0, an SSLv23 client will actually
117 try the SSLv3 protocol unless you explicitly enable SSLv2 ciphers.
118
119 The parameter ``ciphers`` sets the available ciphers for this SSL object.
120 It should be a string in the `OpenSSL cipher list format
121 <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000122
Bill Janssen48dc27c2007-12-05 03:38:10 +0000123 The parameter ``do_handshake_on_connect`` specifies whether to do the SSL
124 handshake automatically after doing a :meth:`socket.connect`, or whether the
Georg Brandl7f01a132009-09-16 15:58:14 +0000125 application program will call it explicitly, by invoking the
126 :meth:`SSLSocket.do_handshake` method. Calling
127 :meth:`SSLSocket.do_handshake` explicitly gives the program control over the
128 blocking behavior of the socket I/O involved in the handshake.
Bill Janssen48dc27c2007-12-05 03:38:10 +0000129
Georg Brandl7f01a132009-09-16 15:58:14 +0000130 The parameter ``suppress_ragged_eofs`` specifies how the
131 :meth:`SSLSocket.read` method should signal unexpected EOF from the other end
132 of the connection. If specified as :const:`True` (the default), it returns a
133 normal EOF in response to unexpected EOF errors raised from the underlying
134 socket; if :const:`False`, it will raise the exceptions back to the caller.
Bill Janssen48dc27c2007-12-05 03:38:10 +0000135
Ezio Melotti4d5195b2010-04-20 10:57:44 +0000136 .. versionchanged:: 3.2
Antoine Pitrou2d9cb9c2010-04-17 17:40:45 +0000137 New optional argument *ciphers*.
138
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000139.. function:: RAND_status()
140
Georg Brandl7f01a132009-09-16 15:58:14 +0000141 Returns True if the SSL pseudo-random number generator has been seeded with
142 'enough' randomness, and False otherwise. You can use :func:`ssl.RAND_egd`
143 and :func:`ssl.RAND_add` to increase the randomness of the pseudo-random
144 number generator.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000145
146.. function:: RAND_egd(path)
147
148 If you are running an entropy-gathering daemon (EGD) somewhere, and ``path``
Georg Brandl7f01a132009-09-16 15:58:14 +0000149 is the pathname of a socket connection open to it, this will read 256 bytes
150 of randomness from the socket, and add it to the SSL pseudo-random number
151 generator to increase the security of generated secret keys. This is
152 typically only necessary on systems without better sources of randomness.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000153
Georg Brandl7f01a132009-09-16 15:58:14 +0000154 See http://egd.sourceforge.net/ or http://prngd.sourceforge.net/ for sources
155 of entropy-gathering daemons.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000156
157.. function:: RAND_add(bytes, entropy)
158
Georg Brandl7f01a132009-09-16 15:58:14 +0000159 Mixes the given ``bytes`` into the SSL pseudo-random number generator. The
160 parameter ``entropy`` (a float) is a lower bound on the entropy contained in
161 string (so you can always use :const:`0.0`). See :rfc:`1750` for more
162 information on sources of entropy.
Thomas Woutersed03b412007-08-28 21:37:11 +0000163
164.. function:: cert_time_to_seconds(timestring)
165
Georg Brandl7f01a132009-09-16 15:58:14 +0000166 Returns a floating-point value containing a normal seconds-after-the-epoch
167 time value, given the time-string representing the "notBefore" or "notAfter"
168 date from a certificate.
Thomas Woutersed03b412007-08-28 21:37:11 +0000169
170 Here's an example::
171
172 >>> import ssl
173 >>> ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT")
174 1178694000.0
175 >>> import time
176 >>> time.ctime(ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT"))
177 'Wed May 9 00:00:00 2007'
Georg Brandl48310cd2009-01-03 21:18:54 +0000178 >>>
Thomas Woutersed03b412007-08-28 21:37:11 +0000179
Georg Brandl7f01a132009-09-16 15:58:14 +0000180.. function:: get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None)
Thomas Woutersed03b412007-08-28 21:37:11 +0000181
Georg Brandl7f01a132009-09-16 15:58:14 +0000182 Given the address ``addr`` of an SSL-protected server, as a (*hostname*,
183 *port-number*) pair, fetches the server's certificate, and returns it as a
184 PEM-encoded string. If ``ssl_version`` is specified, uses that version of
185 the SSL protocol to attempt to connect to the server. If ``ca_certs`` is
186 specified, it should be a file containing a list of root certificates, the
187 same format as used for the same parameter in :func:`wrap_socket`. The call
188 will attempt to validate the server certificate against that set of root
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000189 certificates, and will fail if the validation attempt fails.
190
Georg Brandl7f01a132009-09-16 15:58:14 +0000191.. function:: DER_cert_to_PEM_cert(DER_cert_bytes)
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000192
193 Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded
194 string version of the same certificate.
195
Georg Brandl7f01a132009-09-16 15:58:14 +0000196.. function:: PEM_cert_to_DER_cert(PEM_cert_string)
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000197
Georg Brandl7f01a132009-09-16 15:58:14 +0000198 Given a certificate as an ASCII PEM string, returns a DER-encoded sequence of
199 bytes for that same certificate.
Thomas Woutersed03b412007-08-28 21:37:11 +0000200
201.. data:: CERT_NONE
202
Antoine Pitrou152efa22010-05-16 18:19:27 +0000203 Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
204 parameter to :func:`wrap_socket`. In this mode (the default), no
205 certificates will be required from the other side of the socket connection.
206 If a certificate is received from the other end, no attempt to validate it
207 is made.
208
209 See the discussion of :ref:`ssl-security` below.
Thomas Woutersed03b412007-08-28 21:37:11 +0000210
211.. data:: CERT_OPTIONAL
212
Antoine Pitrou152efa22010-05-16 18:19:27 +0000213 Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
214 parameter to :func:`wrap_socket`. In this mode no certificates will be
215 required from the other side of the socket connection; but if they
216 are provided, validation will be attempted and an :class:`SSLError`
217 will be raised on failure.
218
219 Use of this setting requires a valid set of CA certificates to
220 be passed, either to :meth:`SSLContext.load_verify_locations` or as a
221 value of the ``ca_certs`` parameter to :func:`wrap_socket`.
Thomas Woutersed03b412007-08-28 21:37:11 +0000222
223.. data:: CERT_REQUIRED
224
Antoine Pitrou152efa22010-05-16 18:19:27 +0000225 Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
226 parameter to :func:`wrap_socket`. In this mode, certificates are
227 required from the other side of the socket connection; an :class:`SSLError`
228 will be raised if no certificate is provided, or if its validation fails.
229
230 Use of this setting requires a valid set of CA certificates to
231 be passed, either to :meth:`SSLContext.load_verify_locations` or as a
232 value of the ``ca_certs`` parameter to :func:`wrap_socket`.
Thomas Woutersed03b412007-08-28 21:37:11 +0000233
234.. data:: PROTOCOL_SSLv2
235
236 Selects SSL version 2 as the channel encryption protocol.
237
Antoine Pitrou8eac60d2010-05-16 14:19:41 +0000238 .. warning::
239
240 SSL version 2 is insecure. Its use is highly discouraged.
241
Thomas Woutersed03b412007-08-28 21:37:11 +0000242.. data:: PROTOCOL_SSLv23
243
Georg Brandl7f01a132009-09-16 15:58:14 +0000244 Selects SSL version 2 or 3 as the channel encryption protocol. This is a
245 setting to use with servers for maximum compatibility with the other end of
246 an SSL connection, but it may cause the specific ciphers chosen for the
247 encryption to be of fairly low quality.
Thomas Woutersed03b412007-08-28 21:37:11 +0000248
249.. data:: PROTOCOL_SSLv3
250
Georg Brandl7f01a132009-09-16 15:58:14 +0000251 Selects SSL version 3 as the channel encryption protocol. For clients, this
252 is the maximally compatible SSL variant.
Thomas Woutersed03b412007-08-28 21:37:11 +0000253
254.. data:: PROTOCOL_TLSv1
255
Georg Brandl7f01a132009-09-16 15:58:14 +0000256 Selects TLS version 1 as the channel encryption protocol. This is the most
257 modern version, and probably the best choice for maximum protection, if both
258 sides can speak it.
Thomas Woutersed03b412007-08-28 21:37:11 +0000259
Antoine Pitroub5218772010-05-21 09:56:06 +0000260.. data:: OP_ALL
261
262 Enables workarounds for various bugs present in other SSL implementations.
263 This option is set by default.
264
265 .. versionadded:: 3.2
266
267.. data:: OP_NO_SSLv2
268
269 Prevents an SSLv2 connection. This option is only applicable in
270 conjunction with :const:`PROTOCOL_SSLv23`. It prevents the peers from
271 choosing SSLv2 as the protocol version.
272
273 .. versionadded:: 3.2
274
275.. data:: OP_NO_SSLv3
276
277 Prevents an SSLv3 connection. This option is only applicable in
278 conjunction with :const:`PROTOCOL_SSLv23`. It prevents the peers from
279 choosing SSLv3 as the protocol version.
280
281 .. versionadded:: 3.2
282
283.. data:: OP_NO_TLSv1
284
285 Prevents a TLSv1 connection. This option is only applicable in
286 conjunction with :const:`PROTOCOL_SSLv23`. It prevents the peers from
287 choosing TLSv1 as the protocol version.
288
289 .. versionadded:: 3.2
290
Antoine Pitrou04f6a322010-04-05 21:40:07 +0000291.. data:: OPENSSL_VERSION
292
293 The version string of the OpenSSL library loaded by the interpreter::
294
295 >>> ssl.OPENSSL_VERSION
296 'OpenSSL 0.9.8k 25 Mar 2009'
297
Antoine Pitrou43a94c312010-04-05 21:44:48 +0000298 .. versionadded:: 3.2
Antoine Pitrou04f6a322010-04-05 21:40:07 +0000299
300.. data:: OPENSSL_VERSION_INFO
301
302 A tuple of five integers representing version information about the
303 OpenSSL library::
304
305 >>> ssl.OPENSSL_VERSION_INFO
306 (0, 9, 8, 11, 15)
307
Antoine Pitrou43a94c312010-04-05 21:44:48 +0000308 .. versionadded:: 3.2
Antoine Pitrou04f6a322010-04-05 21:40:07 +0000309
310.. data:: OPENSSL_VERSION_NUMBER
311
312 The raw version number of the OpenSSL library, as a single integer::
313
314 >>> ssl.OPENSSL_VERSION_NUMBER
Antoine Pitrou43a94c312010-04-05 21:44:48 +0000315 9470143
Antoine Pitrou04f6a322010-04-05 21:40:07 +0000316 >>> hex(ssl.OPENSSL_VERSION_NUMBER)
Antoine Pitrou43a94c312010-04-05 21:44:48 +0000317 '0x9080bf'
Antoine Pitrou04f6a322010-04-05 21:40:07 +0000318
Antoine Pitrou43a94c312010-04-05 21:44:48 +0000319 .. versionadded:: 3.2
Antoine Pitrou04f6a322010-04-05 21:40:07 +0000320
Thomas Woutersed03b412007-08-28 21:37:11 +0000321
Antoine Pitrou152efa22010-05-16 18:19:27 +0000322SSL Sockets
323-----------
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000324
Bill Janssen48dc27c2007-12-05 03:38:10 +0000325.. method:: SSLSocket.read(nbytes=1024, buffer=None)
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000326
327 Reads up to ``nbytes`` bytes from the SSL-encrypted channel and returns them.
Georg Brandl7f01a132009-09-16 15:58:14 +0000328 If the ``buffer`` is specified, it will attempt to read into the buffer the
329 minimum of the size of the buffer and ``nbytes``, if that is specified. If
330 no buffer is specified, an immutable buffer is allocated and returned with
331 the data read from the socket.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000332
333.. method:: SSLSocket.write(data)
334
Georg Brandl7f01a132009-09-16 15:58:14 +0000335 Writes the ``data`` to the other side of the connection, using the SSL
336 channel to encrypt. Returns the number of bytes written.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000337
Bill Janssen48dc27c2007-12-05 03:38:10 +0000338.. method:: SSLSocket.do_handshake()
339
Georg Brandl7f01a132009-09-16 15:58:14 +0000340 Performs the SSL setup handshake. If the socket is non-blocking, this method
341 may raise :exc:`SSLError` with the value of the exception instance's
342 ``args[0]`` being either :const:`SSL_ERROR_WANT_READ` or
343 :const:`SSL_ERROR_WANT_WRITE`, and should be called again until it stops
344 raising those exceptions. Here's an example of how to do that::
Bill Janssen48dc27c2007-12-05 03:38:10 +0000345
346 while True:
347 try:
348 sock.do_handshake()
349 break
350 except ssl.SSLError as err:
351 if err.args[0] == ssl.SSL_ERROR_WANT_READ:
352 select.select([sock], [], [])
353 elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
354 select.select([], [sock], [])
355 else:
356 raise
357
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000358.. method:: SSLSocket.getpeercert(binary_form=False)
359
Georg Brandl7f01a132009-09-16 15:58:14 +0000360 If there is no certificate for the peer on the other end of the connection,
361 returns ``None``.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000362
Georg Brandl7f01a132009-09-16 15:58:14 +0000363 If the parameter ``binary_form`` is :const:`False`, and a certificate was
364 received from the peer, this method returns a :class:`dict` instance. If the
365 certificate was not validated, the dict is empty. If the certificate was
366 validated, it returns a dict with the keys ``subject`` (the principal for
367 which the certificate was issued), and ``notAfter`` (the time after which the
368 certificate should not be trusted). The certificate was already validated,
369 so the ``notBefore`` and ``issuer`` fields are not returned. If a
370 certificate contains an instance of the *Subject Alternative Name* extension
371 (see :rfc:`3280`), there will also be a ``subjectAltName`` key in the
372 dictionary.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000373
374 The "subject" field is a tuple containing the sequence of relative
Georg Brandl7f01a132009-09-16 15:58:14 +0000375 distinguished names (RDNs) given in the certificate's data structure for the
376 principal, and each RDN is a sequence of name-value pairs::
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000377
378 {'notAfter': 'Feb 16 16:54:50 2013 GMT',
Ezio Melotti985e24d2009-09-13 07:54:02 +0000379 'subject': ((('countryName', 'US'),),
380 (('stateOrProvinceName', 'Delaware'),),
381 (('localityName', 'Wilmington'),),
382 (('organizationName', 'Python Software Foundation'),),
383 (('organizationalUnitName', 'SSL'),),
384 (('commonName', 'somemachine.python.org'),))}
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000385
Georg Brandl7f01a132009-09-16 15:58:14 +0000386 If the ``binary_form`` parameter is :const:`True`, and a certificate was
387 provided, this method returns the DER-encoded form of the entire certificate
388 as a sequence of bytes, or :const:`None` if the peer did not provide a
389 certificate. This return value is independent of validation; if validation
390 was required (:const:`CERT_OPTIONAL` or :const:`CERT_REQUIRED`), it will have
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000391 been validated, but if :const:`CERT_NONE` was used to establish the
392 connection, the certificate, if present, will not have been validated.
393
394.. method:: SSLSocket.cipher()
395
Georg Brandl7f01a132009-09-16 15:58:14 +0000396 Returns a three-value tuple containing the name of the cipher being used, the
397 version of the SSL protocol that defines its use, and the number of secret
398 bits being used. If no connection has been established, returns ``None``.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000399
400
Benjamin Peterson4aeec042008-08-19 21:42:13 +0000401.. method:: SSLSocket.unwrap()
402
Georg Brandl7f01a132009-09-16 15:58:14 +0000403 Performs the SSL shutdown handshake, which removes the TLS layer from the
404 underlying socket, and returns the underlying socket object. This can be
405 used to go from encrypted operation over a connection to unencrypted. The
406 returned socket should always be used for further communication with the
407 other side of the connection, rather than the original socket.
Benjamin Peterson4aeec042008-08-19 21:42:13 +0000408
Antoine Pitrou152efa22010-05-16 18:19:27 +0000409
Antoine Pitrouec883db2010-05-24 21:20:20 +0000410.. attribute:: SSLSocket.context
411
412 The :class:`SSLContext` object this SSL socket is tied to. If the SSL
413 socket was created using the top-level :func:`wrap_socket` function
414 (rather than :meth:`SSLContext.wrap_socket`), this is a custom context
415 object created for this SSL socket.
416
417 .. versionadded:: 3.2
418
419
Antoine Pitrou152efa22010-05-16 18:19:27 +0000420SSL Contexts
421------------
422
Antoine Pitroucafaad42010-05-24 15:58:43 +0000423.. versionadded:: 3.2
424
Antoine Pitrou152efa22010-05-16 18:19:27 +0000425.. class:: SSLContext(protocol)
426
427 An object holding various data longer-lived than single SSL connections,
428 such as SSL configuration options, certificate(s) and private key(s).
429 You must pass *protocol* which must be one of the ``PROTOCOL_*`` constants
430 defined in this module. :data:`PROTOCOL_SSLv23` is recommended for
431 maximum interoperability.
432
433:class:`SSLContext` objects have the following methods and attributes:
434
435.. method:: SSLContext.load_cert_chain(certfile, keyfile=None)
436
437 Load a private key and the corresponding certificate. The *certfile*
438 string must be the path to a single file in PEM format containing the
439 certificate as well as any number of CA certificates needed to establish
440 the certificate's authenticity. The *keyfile* string, if present, must
441 point to a file containing the private key in. Otherwise the private
442 key will be taken from *certfile* as well. See the discussion of
443 :ref:`ssl-certificates` for more information on how the certificate
444 is stored in the *certfile*.
445
446 An :class:`SSLError` is raised if the private key doesn't
447 match with the certificate.
448
449.. method:: SSLContext.load_verify_locations(cafile=None, capath=None)
450
451 Load a set of "certification authority" (CA) certificates used to validate
452 other peers' certificates when :data:`verify_mode` is other than
453 :data:`CERT_NONE`. At least one of *cafile* or *capath* must be specified.
454
455 The *cafile* string, if present, is the path to a file of concatenated
456 CA certificates in PEM format. See the discussion of
457 :ref:`ssl-certificates` for more information about how to arrange the
458 certificates in this file.
459
460 The *capath* string, if present, is
461 the path to a directory containing several CA certificates in PEM format,
462 following an `OpenSSL specific layout
463 <http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html>`_.
464
465.. method:: SSLContext.set_ciphers(ciphers)
466
467 Set the available ciphers for sockets created with this context.
468 It should be a string in the `OpenSSL cipher list format
469 <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.
470 If no cipher can be selected (because compile-time options or other
471 configuration forbids use of all the specified ciphers), an
472 :class:`SSLError` will be raised.
473
474 .. note::
475 when connected, the :meth:`SSLSocket.cipher` method of SSL sockets will
476 give the currently selected cipher.
477
478.. method:: SSLContext.wrap_socket(sock, server_side=False, do_handshake_on_connect=True, suppress_ragged_eofs=True)
479
480 Wrap an existing Python socket *sock* and return an :class:`SSLSocket`
481 object. The SSL socket is tied to the context, its settings and
482 certificates. The parameters *server_side*, *do_handshake_on_connect*
483 and *suppress_ragged_eofs* have the same meaning as in the top-level
484 :func:`wrap_socket` function.
485
Antoine Pitroub5218772010-05-21 09:56:06 +0000486.. attribute:: SSLContext.options
487
488 An integer representing the set of SSL options enabled on this context.
489 The default value is :data:`OP_ALL`, but you can specify other options
490 such as :data:`OP_NO_SSLv2` by ORing them together.
491
492 .. note::
493 With versions of OpenSSL older than 0.9.8m, it is only possible
494 to set options, not to clear them. Attempting to clear an option
495 (by resetting the corresponding bits) will raise a ``ValueError``.
496
Antoine Pitrou152efa22010-05-16 18:19:27 +0000497.. attribute:: SSLContext.protocol
498
499 The protocol version chosen when constructing the context. This attribute
500 is read-only.
501
502.. attribute:: SSLContext.verify_mode
503
504 Whether to try to verify other peers' certificates and how to behave
505 if verification fails. This attribute must be one of
506 :data:`CERT_NONE`, :data:`CERT_OPTIONAL` or :data:`CERT_REQUIRED`.
507
508
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000509.. index:: single: certificates
510
511.. index:: single: X509 certificate
512
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000513.. _ssl-certificates:
514
Thomas Woutersed03b412007-08-28 21:37:11 +0000515Certificates
516------------
517
Georg Brandl7f01a132009-09-16 15:58:14 +0000518Certificates in general are part of a public-key / private-key system. In this
519system, each *principal*, (which may be a machine, or a person, or an
520organization) is assigned a unique two-part encryption key. One part of the key
521is public, and is called the *public key*; the other part is kept secret, and is
522called the *private key*. The two parts are related, in that if you encrypt a
523message with one of the parts, you can decrypt it with the other part, and
524**only** with the other part.
Thomas Woutersed03b412007-08-28 21:37:11 +0000525
Georg Brandl7f01a132009-09-16 15:58:14 +0000526A certificate contains information about two principals. It contains the name
527of a *subject*, and the subject's public key. It also contains a statement by a
528second principal, the *issuer*, that the subject is who he claims to be, and
529that this is indeed the subject's public key. The issuer's statement is signed
530with the issuer's private key, which only the issuer knows. However, anyone can
531verify the issuer's statement by finding the issuer's public key, decrypting the
532statement with it, and comparing it to the other information in the certificate.
533The certificate also contains information about the time period over which it is
534valid. This is expressed as two fields, called "notBefore" and "notAfter".
Thomas Woutersed03b412007-08-28 21:37:11 +0000535
Georg Brandl7f01a132009-09-16 15:58:14 +0000536In the Python use of certificates, a client or server can use a certificate to
537prove who they are. The other side of a network connection can also be required
538to produce a certificate, and that certificate can be validated to the
539satisfaction of the client or server that requires such validation. The
540connection attempt can be set to raise an exception if the validation fails.
541Validation is done automatically, by the underlying OpenSSL framework; the
542application need not concern itself with its mechanics. But the application
543does usually need to provide sets of certificates to allow this process to take
544place.
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000545
Georg Brandl7f01a132009-09-16 15:58:14 +0000546Python uses files to contain certificates. They should be formatted as "PEM"
547(see :rfc:`1422`), which is a base-64 encoded form wrapped with a header line
548and a footer line::
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000549
550 -----BEGIN CERTIFICATE-----
551 ... (certificate in base64 PEM encoding) ...
552 -----END CERTIFICATE-----
553
Antoine Pitrou152efa22010-05-16 18:19:27 +0000554Certificate chains
555^^^^^^^^^^^^^^^^^^
556
Georg Brandl7f01a132009-09-16 15:58:14 +0000557The Python files which contain certificates can contain a sequence of
558certificates, sometimes called a *certificate chain*. This chain should start
559with the specific certificate for the principal who "is" the client or server,
560and then the certificate for the issuer of that certificate, and then the
561certificate for the issuer of *that* certificate, and so on up the chain till
562you get to a certificate which is *self-signed*, that is, a certificate which
563has the same subject and issuer, sometimes called a *root certificate*. The
564certificates should just be concatenated together in the certificate file. For
565example, suppose we had a three certificate chain, from our server certificate
566to the certificate of the certification authority that signed our server
567certificate, to the root certificate of the agency which issued the
568certification authority's certificate::
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000569
570 -----BEGIN CERTIFICATE-----
571 ... (certificate for your server)...
572 -----END CERTIFICATE-----
573 -----BEGIN CERTIFICATE-----
574 ... (the certificate for the CA)...
575 -----END CERTIFICATE-----
576 -----BEGIN CERTIFICATE-----
577 ... (the root certificate for the CA's issuer)...
578 -----END CERTIFICATE-----
579
Antoine Pitrou152efa22010-05-16 18:19:27 +0000580CA certificates
581^^^^^^^^^^^^^^^
582
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000583If you are going to require validation of the other side of the connection's
584certificate, you need to provide a "CA certs" file, filled with the certificate
Georg Brandl7f01a132009-09-16 15:58:14 +0000585chains for each issuer you are willing to trust. Again, this file just contains
586these chains concatenated together. For validation, Python will use the first
587chain it finds in the file which matches. Some "standard" root certificates are
588available from various certification authorities: `CACert.org
589<http://www.cacert.org/index.php?id=3>`_, `Thawte
590<http://www.thawte.com/roots/>`_, `Verisign
591<http://www.verisign.com/support/roots.html>`_, `Positive SSL
592<http://www.PositiveSSL.com/ssl-certificate-support/cert_installation/UTN-USERFirst-Hardware.crt>`_
593(used by python.org), `Equifax and GeoTrust
594<http://www.geotrust.com/resources/root_certificates/index.asp>`_.
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000595
Georg Brandl7f01a132009-09-16 15:58:14 +0000596In general, if you are using SSL3 or TLS1, you don't need to put the full chain
597in your "CA certs" file; you only need the root certificates, and the remote
598peer is supposed to furnish the other certificates necessary to chain from its
599certificate to a root certificate. See :rfc:`4158` for more discussion of the
600way in which certification chains can be built.
Thomas Woutersed03b412007-08-28 21:37:11 +0000601
Antoine Pitrou152efa22010-05-16 18:19:27 +0000602Combined key and certificate
603^^^^^^^^^^^^^^^^^^^^^^^^^^^^
604
605Often the private key is stored in the same file as the certificate; in this
606case, only the ``certfile`` parameter to :meth:`SSLContext.load_cert_chain`
607and :func:`wrap_socket` needs to be passed. If the private key is stored
608with the certificate, it should come before the first certificate in
609the certificate chain::
610
611 -----BEGIN RSA PRIVATE KEY-----
612 ... (private key in base64 encoding) ...
613 -----END RSA PRIVATE KEY-----
614 -----BEGIN CERTIFICATE-----
615 ... (certificate in base64 PEM encoding) ...
616 -----END CERTIFICATE-----
617
618Self-signed certificates
619^^^^^^^^^^^^^^^^^^^^^^^^
620
Georg Brandl7f01a132009-09-16 15:58:14 +0000621If you are going to create a server that provides SSL-encrypted connection
622services, you will need to acquire a certificate for that service. There are
623many ways of acquiring appropriate certificates, such as buying one from a
624certification authority. Another common practice is to generate a self-signed
625certificate. The simplest way to do this is with the OpenSSL package, using
626something like the following::
Thomas Woutersed03b412007-08-28 21:37:11 +0000627
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000628 % openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
629 Generating a 1024 bit RSA private key
630 .......++++++
631 .............................++++++
632 writing new private key to 'cert.pem'
633 -----
634 You are about to be asked to enter information that will be incorporated
635 into your certificate request.
636 What you are about to enter is what is called a Distinguished Name or a DN.
637 There are quite a few fields but you can leave some blank
638 For some fields there will be a default value,
639 If you enter '.', the field will be left blank.
640 -----
641 Country Name (2 letter code) [AU]:US
642 State or Province Name (full name) [Some-State]:MyState
643 Locality Name (eg, city) []:Some City
644 Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc.
645 Organizational Unit Name (eg, section) []:My Group
646 Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com
647 Email Address []:ops@myserver.mygroup.myorganization.com
648 %
Thomas Woutersed03b412007-08-28 21:37:11 +0000649
Georg Brandl7f01a132009-09-16 15:58:14 +0000650The disadvantage of a self-signed certificate is that it is its own root
651certificate, and no one else will have it in their cache of known (and trusted)
652root certificates.
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000653
654
Thomas Woutersed03b412007-08-28 21:37:11 +0000655Examples
656--------
657
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000658Testing for SSL support
659^^^^^^^^^^^^^^^^^^^^^^^
660
Georg Brandl7f01a132009-09-16 15:58:14 +0000661To test for the presence of SSL support in a Python installation, user code
662should use the following idiom::
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000663
664 try:
665 import ssl
666 except ImportError:
667 pass
668 else:
669 [ do something that requires SSL support ]
670
671Client-side operation
672^^^^^^^^^^^^^^^^^^^^^
673
Georg Brandl7f01a132009-09-16 15:58:14 +0000674This example connects to an SSL server, prints the server's address and
675certificate, sends some bytes, and reads part of the response::
Thomas Woutersed03b412007-08-28 21:37:11 +0000676
677 import socket, ssl, pprint
678
679 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000680
681 # require a certificate from the server
682 ssl_sock = ssl.wrap_socket(s,
683 ca_certs="/etc/ca_certs_file",
684 cert_reqs=ssl.CERT_REQUIRED)
Thomas Woutersed03b412007-08-28 21:37:11 +0000685
686 ssl_sock.connect(('www.verisign.com', 443))
687
Georg Brandl6911e3c2007-09-04 07:15:32 +0000688 print(repr(ssl_sock.getpeername()))
689 pprint.pprint(ssl_sock.getpeercert())
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000690 print(pprint.pformat(ssl_sock.getpeercert()))
Thomas Woutersed03b412007-08-28 21:37:11 +0000691
Georg Brandl24420152008-05-26 16:32:26 +0000692 # Set a simple HTTP request -- use http.client in actual code.
Antoine Pitrou152efa22010-05-16 18:19:27 +0000693 ssl_sock.write(b"GET / HTTP/1.0\r\nHost: www.verisign.com\r\n\r\n")
Thomas Woutersed03b412007-08-28 21:37:11 +0000694
695 # Read a chunk of data. Will not necessarily
696 # read all the data returned by the server.
697 data = ssl_sock.read()
698
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000699 # note that closing the SSLSocket will also close the underlying socket
Thomas Woutersed03b412007-08-28 21:37:11 +0000700 ssl_sock.close()
701
Georg Brandl7f01a132009-09-16 15:58:14 +0000702As of September 6, 2007, the certificate printed by this program looked like
703this::
Thomas Woutersed03b412007-08-28 21:37:11 +0000704
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000705 {'notAfter': 'May 8 23:59:59 2009 GMT',
Ezio Melotti985e24d2009-09-13 07:54:02 +0000706 'subject': ((('serialNumber', '2497886'),),
707 (('1.3.6.1.4.1.311.60.2.1.3', 'US'),),
708 (('1.3.6.1.4.1.311.60.2.1.2', 'Delaware'),),
709 (('countryName', 'US'),),
710 (('postalCode', '94043'),),
711 (('stateOrProvinceName', 'California'),),
712 (('localityName', 'Mountain View'),),
713 (('streetAddress', '487 East Middlefield Road'),),
714 (('organizationName', 'VeriSign, Inc.'),),
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000715 (('organizationalUnitName',
Ezio Melotti985e24d2009-09-13 07:54:02 +0000716 'Production Security Services'),),
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000717 (('organizationalUnitName',
Ezio Melotti985e24d2009-09-13 07:54:02 +0000718 'Terms of use at www.verisign.com/rpa (c)06'),),
719 (('commonName', 'www.verisign.com'),))}
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000720
721which is a fairly poorly-formed ``subject`` field.
Thomas Woutersed03b412007-08-28 21:37:11 +0000722
Antoine Pitrou152efa22010-05-16 18:19:27 +0000723This other example first creates an SSL context, instructs it to verify
724certificates sent by peers, and feeds it a set of recognized certificate
725authorities (CA)::
726
727 >>> context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
728 >>> context.verify_mode = ssl.CERT_OPTIONAL
729 >>> context.load_verify_locations("/etc/ssl/certs/ca-bundle.crt")
730
731(it is assumed your operating system places a bundle of all CA certificates
732in ``/etc/ssl/certs/ca-bundle.crt``; if not, you'll get an error and have
733to adjust the location)
734
735When you use the context to connect to a server, :const:`CERT_OPTIONAL`
736validates the server certificate: it ensures that the server certificate
737was signed with one of the CA certificates, and checks the signature for
738correctness::
739
740 >>> conn = context.wrap_socket(socket.socket(socket.AF_INET))
741 >>> conn.connect(("linuxfr.org", 443))
742
743You should then fetch the certificate and check its fields for conformity.
744Here, the ``commonName`` field in the ``subject`` matches the desired HTTPS
745host ``linuxfr.org``::
746
747 >>> pprint.pprint(conn.getpeercert())
748 {'notAfter': 'Jun 26 21:41:46 2011 GMT',
749 'subject': ((('commonName', 'linuxfr.org'),),),
750 'subjectAltName': (('DNS', 'linuxfr.org'), ('othername', '<unsupported>'))}
751
752Now that you are assured of its authenticity, you can proceed to talk with
753the server::
754
755 >>> conn.write(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n")
756 38
757 >>> pprint.pprint(conn.read().split(b"\r\n"))
758 [b'HTTP/1.1 302 Found',
759 b'Date: Sun, 16 May 2010 13:43:28 GMT',
760 b'Server: Apache/2.2',
761 b'Location: https://linuxfr.org/pub/',
762 b'Vary: Accept-Encoding',
763 b'Connection: close',
764 b'Content-Type: text/html; charset=iso-8859-1',
765 b'',
766 b'']
767
768
769See the discussion of :ref:`ssl-security` below.
770
771
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000772Server-side operation
773^^^^^^^^^^^^^^^^^^^^^
774
Antoine Pitrou152efa22010-05-16 18:19:27 +0000775For server operation, typically you'll need to have a server certificate, and
776private key, each in a file. You'll first create a context holding the key
777and the certificate, so that clients can check your authenticity. Then
778you'll open a socket, bind it to a port, call :meth:`listen` on it, and start
779waiting for clients to connect::
Thomas Woutersed03b412007-08-28 21:37:11 +0000780
781 import socket, ssl
782
Antoine Pitrou152efa22010-05-16 18:19:27 +0000783 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
784 context.load_cert_chain(certfile="mycertfile", keyfile="mykeyfile")
785
Thomas Woutersed03b412007-08-28 21:37:11 +0000786 bindsocket = socket.socket()
787 bindsocket.bind(('myaddr.mydomain.com', 10023))
788 bindsocket.listen(5)
789
Antoine Pitrou152efa22010-05-16 18:19:27 +0000790When a client connects, you'll call :meth:`accept` on the socket to get the
791new socket from the other end, and use the context's :meth:`SSLContext.wrap_socket`
792method to create a server-side SSL socket for the connection::
Thomas Woutersed03b412007-08-28 21:37:11 +0000793
794 while True:
795 newsocket, fromaddr = bindsocket.accept()
Antoine Pitrou152efa22010-05-16 18:19:27 +0000796 connstream = context.wrap_socket(newsocket, server_side=True)
797 try:
798 deal_with_client(connstream)
799 finally:
800 connstream.close()
Thomas Woutersed03b412007-08-28 21:37:11 +0000801
Antoine Pitrou152efa22010-05-16 18:19:27 +0000802Then you'll read data from the ``connstream`` and do something with it till you
Georg Brandl7f01a132009-09-16 15:58:14 +0000803are finished with the client (or the client is finished with you)::
Thomas Woutersed03b412007-08-28 21:37:11 +0000804
805 def deal_with_client(connstream):
Thomas Woutersed03b412007-08-28 21:37:11 +0000806 data = connstream.read()
Antoine Pitrou152efa22010-05-16 18:19:27 +0000807 # empty data means the client is finished with us
Thomas Woutersed03b412007-08-28 21:37:11 +0000808 while data:
809 if not do_something(connstream, data):
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000810 # we'll assume do_something returns False
811 # when we're finished with client
Thomas Woutersed03b412007-08-28 21:37:11 +0000812 break
813 data = connstream.read()
814 # finished with client
Thomas Woutersed03b412007-08-28 21:37:11 +0000815
Antoine Pitrou152efa22010-05-16 18:19:27 +0000816And go back to listening for new client connections (of course, a real server
817would probably handle each client connection in a separate thread, or put
818the sockets in non-blocking mode and use an event loop).
819
820
821.. _ssl-security:
822
823Security considerations
824-----------------------
825
826Verifying certificates
827^^^^^^^^^^^^^^^^^^^^^^
828
829:const:`CERT_NONE` is the default. Since it does not authenticate the other
830peer, it can be insecure, especially in client mode where most of time you
831would like to ensure the authenticity of the server you're talking to.
832Therefore, when in client mode, it is highly recommended to use
833:const:`CERT_REQUIRED`. However, it is in itself not sufficient; you also
834have to check that the server certificate (obtained with
835:meth:`SSLSocket.getpeercert`) matches the desired service. The exact way
836of doing so depends on the higher-level protocol used; for example, with
837HTTPS, you'll check that the host name in the URL matches either the
838``commonName`` field in the ``subjectName``, or one of the ``DNS`` fields
839in the ``subjectAltName``.
840
841In server mode, if you want to authenticate your clients using the SSL layer
842(rather than using a higher-level authentication mechanism), you'll also have
843to specify :const:`CERT_REQUIRED` and similarly check the client certificate.
844
845 .. note::
846
847 In client mode, :const:`CERT_OPTIONAL` and :const:`CERT_REQUIRED` are
848 equivalent unless anonymous ciphers are enabled (they are disabled
849 by default).
Thomas Woutersed03b412007-08-28 21:37:11 +0000850
Antoine Pitroub5218772010-05-21 09:56:06 +0000851Protocol versions
852^^^^^^^^^^^^^^^^^
853
854SSL version 2 is considered insecure and is therefore dangerous to use. If
855you want maximum compatibility between clients and servers, it is recommended
856to use :const:`PROTOCOL_SSLv23` as the protocol version and then disable
857SSLv2 explicitly using the :data:`SSLContext.options` attribute::
858
859 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
860 context.options |= ssl.OP_NO_SSLv2
861
862The SSL context created above will allow SSLv3 and TLSv1 connections, but
863not SSLv2.
864
Georg Brandl48310cd2009-01-03 21:18:54 +0000865
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000866.. seealso::
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000867
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000868 Class :class:`socket.socket`
869 Documentation of underlying :mod:`socket` class
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000870
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000871 `Introducing SSL and Certificates using OpenSSL <http://old.pseudonym.org/ssl/wwwj-index.html>`_
872 Frederick J. Hirsch
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000873
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000874 `RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management <http://www.ietf.org/rfc/rfc1422>`_
875 Steve Kent
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000876
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000877 `RFC 1750: Randomness Recommendations for Security <http://www.ietf.org/rfc/rfc1750>`_
878 D. Eastlake et. al.
Thomas Wouters89d996e2007-09-08 17:39:28 +0000879
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000880 `RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile <http://www.ietf.org/rfc/rfc3280>`_
881 Housley et. al.