Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47b49bf

Browse files
committed
Merged revisions 57620-57771 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r57771 | thomas.wouters | 2007-08-30 23:54:39 +0200 (Thu, 30 Aug 2007) | 5 lines Don't lie in __all__ attributes when SSL is not available: only add the SSL classes when they are actually created. ........ r57620 | walter.doerwald | 2007-08-28 18:38:26 +0200 (Tue, 28 Aug 2007) | 5 lines Fix title endtag in HTMLCalender.formatyearpage(). Fix documentation for HTMLCalender.formatyearpage() (there's no themonth parameter). This fixes issue1046. ........ r57622 | georg.brandl | 2007-08-28 20:54:44 +0200 (Tue, 28 Aug 2007) | 2 lines Add a crasher for the thread-unsafety of file objects. ........ r57626 | skip.montanaro | 2007-08-29 01:22:52 +0200 (Wed, 29 Aug 2007) | 1 line fixes 813986 ........ r57628 | walter.doerwald | 2007-08-29 01:35:33 +0200 (Wed, 29 Aug 2007) | 2 lines Fix test output. ........ r57631 | skip.montanaro | 2007-08-29 03:24:11 +0200 (Wed, 29 Aug 2007) | 2 lines Install pygettext (once the scriptsinstall target is working again). ........ r57633 | skip.montanaro | 2007-08-29 03:33:45 +0200 (Wed, 29 Aug 2007) | 2 lines Recent items. ........ r57650 | neal.norwitz | 2007-08-29 08:15:33 +0200 (Wed, 29 Aug 2007) | 1 line Add Bill as a developer ........ r57651 | facundo.batista | 2007-08-29 12:28:28 +0200 (Wed, 29 Aug 2007) | 5 lines Ignore test failures caused by 'resource temporarily unavailable' exceptions raised during FailingServerTestCase tests. [GSoC - Alan McIntyre] ........ r57680 | bill.janssen | 2007-08-30 00:35:05 +0200 (Thu, 30 Aug 2007) | 17 lines This contains a number of things: 1) Improve the documentation of the SSL module, with a fuller explanation of certificate usage, another reference, proper formatting of this and that. 2) Fix Windows bug in ssl.py, and general bug in sslsocket.close(). Remove some unused code from ssl.py. Allow accept() to be called on sslsocket sockets. 3) Use try-except-else in import of ssl in socket.py. Deprecate use of socket.ssl(). 4) Remove use of socket.ssl() in every library module, except for test_socket_ssl.py and test_ssl.py. ........ r57714 | georg.brandl | 2007-08-30 12:09:42 +0200 (Thu, 30 Aug 2007) | 2 lines Stronger urge to convert filenames to str before using them as argument to ZipFile.write(). ........ r57716 | georg.brandl | 2007-08-30 12:38:56 +0200 (Thu, 30 Aug 2007) | 2 lines Patch #1680959: add test suite for pipes module. ........ r57717 | georg.brandl | 2007-08-30 14:32:23 +0200 (Thu, 30 Aug 2007) | 3 lines * Skip test_pipes on non-POSIX. * Don't raise TestSkipped within a test function. ........ r57723 | mark.summerfield | 2007-08-30 17:03:03 +0200 (Thu, 30 Aug 2007) | 3 lines Added more cross-references. ........ r57726 | walter.doerwald | 2007-08-30 17:30:09 +0200 (Thu, 30 Aug 2007) | 2 lines Rewrap line. ........ r57727 | walter.doerwald | 2007-08-30 17:34:55 +0200 (Thu, 30 Aug 2007) | 2 lines Set startinpos before calling the error handler. ........ r57730 | bill.janssen | 2007-08-30 19:07:28 +0200 (Thu, 30 Aug 2007) | 3 lines Added docstrings to methods and functions. ........ r57743 | bill.janssen | 2007-08-30 20:08:06 +0200 (Thu, 30 Aug 2007) | 1 line added note on new ssl module and deprecation of socket.ssl ........ r57747 | martin.v.loewis | 2007-08-30 20:14:01 +0200 (Thu, 30 Aug 2007) | 1 line Fix popen usage. ........ r57748 | martin.v.loewis | 2007-08-30 20:15:22 +0200 (Thu, 30 Aug 2007) | 1 line Fix typo. ........ r57750 | martin.v.loewis | 2007-08-30 20:25:47 +0200 (Thu, 30 Aug 2007) | 1 line Bug #1746880: Correctly install DLLs into system32 folder on Win64. ........ r57760 | martin.v.loewis | 2007-08-30 21:04:09 +0200 (Thu, 30 Aug 2007) | 1 line Bug #1709599: Run test_1565150 only if the file system is NTFS. ........ r57762 | martin.v.loewis | 2007-08-30 22:10:57 +0200 (Thu, 30 Aug 2007) | 2 lines Bump autoconf minimum version to 2.61. ........ r57764 | lars.gustaebel | 2007-08-30 22:24:31 +0200 (Thu, 30 Aug 2007) | 2 lines Warn about possible risks when extracting untrusted archives. ........ r57769 | thomas.wouters | 2007-08-30 23:01:17 +0200 (Thu, 30 Aug 2007) | 7 lines Somewhat-preliminary slice-object and extended slicing support for ctypes. The exact behaviour of omitted and negative indices for the Pointer type may need a closer look (especially as it's subtly different from simple slices) but there's time yet before 2.6, and not enough before 3.0a1 :-) ........
1 parent cf1be88 commit 47b49bf

40 files changed

Lines changed: 9499 additions & 8727 deletions

Doc/library/calendar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ it's the base calendar for all computations.
162162
the number of months per row.
163163

164164

165-
.. method:: HTMLCalendar.formatyearpage(theyear, themonth[, width[, css[, encoding]]])
165+
.. method:: HTMLCalendar.formatyearpage(theyear[, width[, css[, encoding]]])
166166

167167
Return a year's calendar as a complete HTML page. *width* (defaulting to 3)
168168
specifies the number of months per row. *css* is the name for the cascading

Doc/library/collections.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,14 @@ Setting the :attr:`default_factory` to :class:`set` makes the
405405
print record
406406

407407
To cast an individual record stored as :class:`list`, :class:`tuple`, or some
408-
other iterable type, use the star-operator to unpack the values::
408+
other iterable type, use the star-operator [#]_ to unpack the values::
409409

410410
>>> Color = NamedTuple('Color', 'name code')
411411
>>> m = dict(red=1, green=2, blue=3)
412412
>>> print Color(*m.popitem())
413413
Color(name='blue', code=3)
414414

415+
.. rubric:: Footnotes
416+
417+
.. [#] For information on the star-operator see
418+
:ref:`tut-unpacking-arguments` and :ref:`calls`.

Doc/library/fpformat.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ numbers representations in 100% pure Python.
1212

1313
.. note::
1414

15-
This module is unneeded: everything here could be done via the ``%`` string
16-
interpolation operator.
15+
This module is unnecessary: everything here can be done using the ``%`` string
16+
interpolation operator described in the :ref:`string-formatting` section.
1717

1818
The :mod:`fpformat` module defines the following functions and an exception:
1919

Doc/library/ssl.rst

Lines changed: 133 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

2-
:mod:`ssl` --- SSL wrapper for socket objects, and utility functions
2+
:mod:`ssl` --- SSL wrapper for socket objects
33
====================================================================
44

55
.. module:: ssl
6-
:synopsis: SSL wrapper for socket objects, and utility functions
6+
:synopsis: SSL wrapper for socket objects
7+
8+
.. moduleauthor:: Bill Janssen <[email protected]>
79

810
.. versionadded:: 2.6
911

12+
.. sectionauthor:: Bill Janssen <[email protected]>
13+
1014

1115
This module provides access to Transport Layer Security (often known
1216
as "Secure Sockets Layer") encryption and peer authentication
@@ -20,10 +24,9 @@ platforms, as long as OpenSSL is installed on that platform.
2024
Some behavior may be platform dependent, since calls are made to the operating
2125
system socket APIs.
2226

23-
This section documents the objects and functions in the `ssl` module;
27+
This section documents the objects and functions in the ``ssl`` module;
2428
for more general information about TLS, SSL, and certificates, the
25-
reader is referred to the paper, *Introducing SSL and Certificates using OpenSSL*, by Frederick J. Hirsch, at
26-
http://old.pseudonym.org/ssl/wwwj-index.html.
29+
reader is referred to the documents in the :ref:`ssl-references` section.
2730

2831
This module defines a class, :class:`ssl.sslsocket`, which is
2932
derived from the :class:`socket.socket` type, and supports additional
@@ -57,25 +60,25 @@ This module defines the following functions, exceptions, and constants:
5760

5861
.. data:: CERT_NONE
5962

60-
Value to pass to the `cert_reqs` parameter to :func:`sslobject`
63+
Value to pass to the ``cert_reqs`` parameter to :func:`sslobject`
6164
when no certificates will be required or validated from the other
6265
side of the socket connection.
6366

6467
.. data:: CERT_OPTIONAL
6568

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

7376
.. data:: CERT_REQUIRED
7477

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

8184
.. data:: PROTOCOL_SSLv2
@@ -99,10 +102,12 @@ This module defines the following functions, exceptions, and constants:
99102
protection, if both sides can speak it.
100103

101104

105+
.. _ssl-certificates:
106+
102107
Certificates
103108
------------
104109

105-
Certificates in general are part of a public-key / private-key system. In this system, each `principal`,
110+
Certificates in general are part of a public-key / private-key system. In this system, each *principal*,
106111
(which may be a machine, or a person, or an organization) is assigned a unique two-part encryption key.
107112
One part of the key is public, and is called the *public key*; the other part is kept secret, and is called
108113
the *private key*. The two parts are related, in that if you encrypt a message with one of the parts, you can
@@ -120,94 +125,122 @@ the certificate. The certificate also contains information about the
120125
time period over which it is valid. This is expressed as two fields,
121126
called "notBefore" and "notAfter".
122127

123-
The underlying system which is used in the Python SSL support is
124-
called "OpenSSL". It contains facilities for constructing and
125-
validating certificates. In the Python use of certificates, the other
126-
side of a network connection can be required to produce a certificate,
127-
and that certificate can be validated against a file filled with
128-
self-signed *root* certificates (so-called because the issuer is the
129-
same as the subject), and and "CA" (certification authority)
130-
certificates assured by those root certificates (and by other CA
131-
certificates). Either side of a connection, client or server, can
132-
request certificates and validation, and the connection can be optionally
133-
set up to fail if a valid certificate is not presented by the other side.
128+
In the Python use of certificates, a client or server
129+
can use a certificate to prove who they are. The other
130+
side of a network connection can also be required to produce a certificate,
131+
and that certificate can be validated to the satisfaction
132+
of the client or server that requires such validation.
133+
The connection can be set to fail automatically if such
134+
validation is not achieved.
135+
136+
Python uses files to contain certificates. They should be formatted
137+
as "PEM" (see :rfc:`1422`), which is a base-64 encoded form wrapped
138+
with a header line and a footer line::
139+
140+
-----BEGIN CERTIFICATE-----
141+
... (certificate in base64 PEM encoding) ...
142+
-----END CERTIFICATE-----
143+
144+
The Python files which contain certificates can contain a sequence
145+
of certificates, sometimes called a *certificate chain*. This chain
146+
should start with the specific certificate for the principal who "is"
147+
the client or server, and then the certificate for the issuer of that
148+
certificate, and then the certificate for the issuer of *that* certificate,
149+
and so on up the chain till you get to a certificate which is *self-signed*,
150+
that is, a certificate which has the same subject and issuer,
151+
sometimes called a *root certificate*. The certificates should just
152+
be concatenated together in the certificate file. For example, suppose
153+
we had a three certificate chain, from our server certificate to the
154+
certificate of the certification authority that signed our server certificate,
155+
to the root certificate of the agency which issued the certification authority's
156+
certificate::
157+
158+
-----BEGIN CERTIFICATE-----
159+
... (certificate for your server)...
160+
-----END CERTIFICATE-----
161+
-----BEGIN CERTIFICATE-----
162+
... (the certificate for the CA)...
163+
-----END CERTIFICATE-----
164+
-----BEGIN CERTIFICATE-----
165+
... (the root certificate for the CA's issuer)...
166+
-----END CERTIFICATE-----
167+
168+
If you are going to require validation of the other side of the connection's
169+
certificate, you need to provide a "CA certs" file, filled with the certificate
170+
chains for each issuer you are willing to trust. Again, this file just
171+
contains these chains concatenated together. For validation, Python will
172+
use the first chain it finds in the file which matches.
173+
Some "standard" root certificates are available at
174+
http://www.thawte.com/roots/ (for Thawte roots) and
175+
http://www.verisign.com/support/roots.html (for Verisign roots).
134176

135177

136178
sslsocket Objects
137179
-----------------
138180

139181
.. class:: sslsocket(sock [, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None])
140182

141-
Takes an instance *sock* of :class:`socket.socket`, and returns an instance of a subtype
183+
Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance of a subtype
142184
of :class:`socket.socket` which wraps the underlying socket in an SSL context.
143185
For client-side sockets, the context construction is lazy; if the underlying socket isn't
144186
connected yet, the context construction will be performed after :meth:`connect` is called
145187
on the socket.
146188

147-
The `keyfile` and `certfile` parameters specify optional files which contain a certificate
148-
to be used to identify the local side of the connection. Often the private key is stored
149-
in the same file as the certificate; in this case, only the `certfile` parameter need be
189+
The ``keyfile`` and ``certfile`` parameters specify optional files which contain a certificate
190+
to be used to identify the local side of the connection. See the above discussion of :ref:`ssl-certificates`
191+
for more information on how the certificate is stored in the ``certfile``.
192+
193+
Often the private key is stored
194+
in the same file as the certificate; in this case, only the ``certfile`` parameter need be
150195
passed. If the private key is stored in a separate file, both parameters must be used.
196+
If the private key is stored in the ``certfile``, it should come before the first certificate
197+
in the certificate chain::
151198

152-
The parameter `server_side` is a boolean which identifies whether server-side or client-side
199+
-----BEGIN RSA PRIVATE KEY-----
200+
... (private key in base64 encoding) ...
201+
-----END RSA PRIVATE KEY-----
202+
-----BEGIN CERTIFICATE-----
203+
... (certificate in base64 PEM encoding) ...
204+
-----END CERTIFICATE-----
205+
206+
The parameter ``server_side`` is a boolean which identifies whether server-side or client-side
153207
behavior is desired from this socket.
154208

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

163-
The parameter `ssl_version` specifies which version of the SSL protocol to use. Typically,
217+
The parameter ``ssl_version`` specifies which version of the SSL protocol to use. Typically,
164218
the server specifies this, and a client connecting to it must use the same protocol. An
165219
SSL server using :const:`PROTOCOL_SSLv23` can understand a client connecting via SSL2, SSL3, or TLS1,
166220
but a client using :const:`PROTOCOL_SSLv23` can only connect to an SSL2 server.
167221

168-
The `ca_certs` file contains a set of concatenated "certification authority" certificates,
222+
The ``ca_certs`` file contains a set of concatenated "certification authority" certificates,
169223
which are used to validate certificates passed from the other end of the connection.
170-
This file
171-
contains the certificates in PEM format (IETF RFC 1422) where each certificate is
172-
encoded in base64 encoding and surrounded with a header and footer::
173-
174-
-----BEGIN CERTIFICATE-----
175-
... (CA certificate in base64 encoding) ...
176-
-----END CERTIFICATE-----
177-
178-
The various certificates in the file are just concatenated together::
179-
180-
-----BEGIN CERTIFICATE-----
181-
... (CA certificate in base64 encoding) ...
182-
-----END CERTIFICATE-----
183-
-----BEGIN CERTIFICATE-----
184-
... (a second CA certificate in base64 encoding) ...
185-
-----END CERTIFICATE-----
186-
-----BEGIN CERTIFICATE-----
187-
... (a root certificate in base64 encoding) ...
188-
-----END CERTIFICATE-----
189-
190-
Some "standard" root certificates are available at
191-
http://www.thawte.com/roots/ (for Thawte roots) and
192-
http://www.verisign.com/support/roots.html (for Verisign roots).
224+
See the above discussion of :ref:`ssl-certificates` for more information about how to arrange
225+
the certificates in this file.
193226

194227
.. method:: sslsocket.read([nbytes])
195228

196-
Reads up to `nbytes` bytes from the SSL-encrypted channel and returns them.
229+
Reads up to ``nbytes`` bytes from the SSL-encrypted channel and returns them.
197230

198231
.. method:: sslsocket.write(data)
199232

200-
Writes the `data` to the other side of the connection, using the SSL channel to encrypt. Returns the number
233+
Writes the ``data`` to the other side of the connection, using the SSL channel to encrypt. Returns the number
201234
of bytes written.
202235

203236
.. method:: sslsocket.getpeercert()
204237

205-
If there is no certificate for the peer on the other end of the connection, returns `None`.
206-
If a certificate was received from the peer, but not validated, returns an empty `dict` instance.
207-
If a certificate was received and validated, returns a `dict` instance with the fields
208-
`subject` (the principal for which the certificate was issued), `issuer` (the signer of
209-
the certificate), `notBefore` (the time before which the certificate should not be trusted),
210-
and `notAfter` (the time after which the certificate should not be trusted) filled in.
238+
If there is no certificate for the peer on the other end of the connection, returns ``None``.
239+
If a certificate was received from the peer, but not validated, returns an empty ``dict`` instance.
240+
If a certificate was received and validated, returns a ``dict`` instance with the fields
241+
``subject`` (the principal for which the certificate was issued), ``issuer`` (the signer of
242+
the certificate), ``notBefore`` (the time before which the certificate should not be trusted),
243+
and ``notAfter`` (the time after which the certificate should not be trusted) filled in.
211244

212245
The "subject" and "issuer" fields are themselves dictionaries containing the fields given
213246
in the certificate's data structure for each principal::
@@ -229,12 +262,34 @@ sslsocket Objects
229262
'version': 2}
230263

231264
This certificate is said to be *self-signed*, because the subject
232-
and issuer are the same entity. The *version* field refers the the X509 version
265+
and issuer are the same entity. The *version* field refers to the X509 version
233266
that's used for the certificate.
234267

268+
.. method:: sslsocket.ssl_shutdown()
269+
270+
Closes the SSL context (if any) over the socket, but leaves the socket connection
271+
open for further use, if both sides are willing. This is different from :meth:`socket.socket.shutdown`,
272+
which will close the connection, but leave the local socket available for further use.
273+
274+
235275
Examples
236276
--------
237277

278+
Testing for SSL support
279+
^^^^^^^^^^^^^^^^^^^^^^^
280+
281+
To test for the presence of SSL support in a Python installation, user code should use the following idiom::
282+
283+
try:
284+
import ssl
285+
except ImportError:
286+
pass
287+
else:
288+
[ do something that requires SSL support ]
289+
290+
Client-side operation
291+
^^^^^^^^^^^^^^^^^^^^^
292+
238293
This example connects to an SSL server, prints the server's address and certificate,
239294
sends some bytes, and reads part of the response::
240295

@@ -281,6 +336,9 @@ looked like this::
281336
'notBefore': 'May 9 00:00:00 2007 GMT',
282337
'version': 2}
283338

339+
Server-side operation
340+
^^^^^^^^^^^^^^^^^^^^^
341+
284342
For server operation, typically you'd need to have a server certificate, and private key, each in a file.
285343
You'd open a socket, bind it to a port, call :meth:`listen` on it, then start waiting for clients
286344
to connect::
@@ -300,7 +358,7 @@ end, and use :func:`sslsocket` to create a server-side SSL context for it::
300358
keyfile="mykeyfile", ssl_protocol=ssl.PROTOCOL_TLSv1)
301359
deal_with_client(connstream)
302360

303-
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)::
361+
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)::
304362

305363
def deal_with_client(connstream):
306364

@@ -317,3 +375,14 @@ Then you'd read data from the `connstream` and do something with it till you are
317375
And go back to listening for new client connections.
318376

319377

378+
.. _ssl-references:
379+
380+
References
381+
----------
382+
383+
Class :class:`socket.socket`
384+
Documentation of underlying :mod:`socket` class
385+
386+
`Introducing SSL and Certificates using OpenSSL <http://old.pseudonym.org/ssl/wwwj-index.html>`_, by Frederick J. Hirsch
387+
388+
`Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management`, :rfc:`1422`, by Steve Kent

Doc/library/stringio.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
This module implements a file-like class, :class:`StringIO`, that reads and
1010
writes a string buffer (also known as *memory files*). See the description of
11-
file objects for operations (section :ref:`bltin-file-objects`).
11+
file objects for operations (section :ref:`bltin-file-objects`). (For
12+
standard strings, see :class:`str` and :class:`unicode`.)
1213

1314

1415
.. class:: StringIO([buffer])

Doc/library/tarfile.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ object, see :ref:`tarinfo-objects` for details.
338338
reset each time a file is created in it. And, if a directory's permissions do
339339
not allow writing, extracting files to it will fail.
340340

341+
.. warning::
342+
343+
Never extract archives from untrusted sources without prior inspection.
344+
It is possible that files are created outside of *path*, e.g. members
345+
that have absolute filenames starting with ``"/"`` or filenames with two
346+
dots ``".."``.
347+
341348
.. versionadded:: 2.5
342349

343350

@@ -354,6 +361,10 @@ object, see :ref:`tarinfo-objects` for details.
354361
are some issues you must take care of yourself. See the description for
355362
:meth:`extractall` above.
356363

364+
.. warning::
365+
366+
See the warning for :meth:`extractall`.
367+
357368

358369
.. method:: TarFile.extractfile(member)
359370

0 commit comments

Comments
 (0)