Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
# Test the support for SSL and sockets
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
2019-05-31 06:44:05 -03:00
|
|
|
import unittest.mock
|
2024-09-25 18:23:47 -03:00
|
|
|
from ast import literal_eval
|
2024-10-19 18:16:36 -03:00
|
|
|
from threading import Thread
|
2008-05-20 18:35:26 -03:00
|
|
|
from test import support
|
2020-08-03 13:41:24 -03:00
|
|
|
from test.support import import_helper
|
|
|
|
from test.support import os_helper
|
2020-04-25 04:06:29 -03:00
|
|
|
from test.support import socket_helper
|
2020-05-27 19:10:27 -03:00
|
|
|
from test.support import threading_helper
|
2020-08-03 13:41:24 -03:00
|
|
|
from test.support import warnings_helper
|
2022-11-08 11:48:58 -04:00
|
|
|
from test.support import asyncore
|
2023-11-27 13:15:39 -04:00
|
|
|
import array
|
2023-08-22 14:53:15 -03:00
|
|
|
import re
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
import socket
|
2007-11-15 18:23:56 -04:00
|
|
|
import select
|
2023-08-22 14:53:15 -03:00
|
|
|
import struct
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
import time
|
2021-04-21 14:20:44 -03:00
|
|
|
import enum
|
2010-04-23 20:31:47 -03:00
|
|
|
import gc
|
2023-08-22 14:53:15 -03:00
|
|
|
import http.client
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
import os
|
2010-04-23 20:31:47 -03:00
|
|
|
import errno
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
import pprint
|
2010-10-13 07:36:15 -03:00
|
|
|
import urllib.request
|
2017-09-07 13:56:24 -03:00
|
|
|
import threading
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
import traceback
|
2010-04-23 20:10:32 -03:00
|
|
|
import weakref
|
2010-08-04 13:45:21 -03:00
|
|
|
import platform
|
2018-01-29 09:10:18 -04:00
|
|
|
import sysconfig
|
2019-09-26 12:02:59 -03:00
|
|
|
import functools
|
2017-09-07 18:18:21 -03:00
|
|
|
try:
|
|
|
|
import ctypes
|
|
|
|
except ImportError:
|
|
|
|
ctypes = None
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2021-06-24 20:20:40 -03:00
|
|
|
|
2020-08-03 13:41:24 -03:00
|
|
|
ssl = import_helper.import_module("ssl")
|
2021-04-26 10:01:40 -03:00
|
|
|
import _ssl
|
2010-10-13 08:38:36 -03:00
|
|
|
|
2024-03-06 17:44:58 -04:00
|
|
|
from ssl import Purpose, TLSVersion, _TLSContentType, _TLSMessageType, _TLSAlertType
|
2016-03-26 22:53:46 -03:00
|
|
|
|
2022-05-25 19:12:54 -03:00
|
|
|
Py_DEBUG_WIN32 = support.Py_DEBUG and sys.platform == 'win32'
|
2019-06-19 17:09:54 -03:00
|
|
|
|
2013-03-28 18:24:43 -03:00
|
|
|
PROTOCOLS = sorted(ssl._PROTOCOL_NAMES)
|
2020-04-25 04:06:29 -03:00
|
|
|
HOST = socket_helper.HOST
|
2021-04-19 03:31:29 -03:00
|
|
|
IS_OPENSSL_3_0_0 = ssl.OPENSSL_VERSION_INFO >= (3, 0, 0)
|
2018-01-29 09:10:18 -04:00
|
|
|
PY_SSL_DEFAULT_CIPHERS = sysconfig.get_config_var('PY_SSL_DEFAULT_CIPHERS')
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2019-02-19 13:06:03 -04:00
|
|
|
PROTOCOL_TO_TLS_VERSION = {}
|
|
|
|
for proto, ver in (
|
2022-07-21 21:38:15 -03:00
|
|
|
("PROTOCOL_SSLv3", "SSLv3"),
|
2019-02-19 13:06:03 -04:00
|
|
|
("PROTOCOL_TLSv1", "TLSv1"),
|
|
|
|
("PROTOCOL_TLSv1_1", "TLSv1_1"),
|
|
|
|
):
|
|
|
|
try:
|
|
|
|
proto = getattr(ssl, proto)
|
|
|
|
ver = getattr(ssl.TLSVersion, ver)
|
|
|
|
except AttributeError:
|
|
|
|
continue
|
|
|
|
PROTOCOL_TO_TLS_VERSION[proto] = ver
|
|
|
|
|
2013-11-20 22:35:02 -04:00
|
|
|
def data_file(*name):
|
2023-09-16 13:47:18 -03:00
|
|
|
return os.path.join(os.path.dirname(__file__), "certdata", *name)
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2010-10-08 20:06:24 -03:00
|
|
|
# The custom key and certificate files used in test_ssl are generated
|
2023-09-16 13:47:18 -03:00
|
|
|
# using Lib/test/certdata/make_ssl_certs.py.
|
2021-07-26 19:11:55 -03:00
|
|
|
# Other certificates are simply fetched from the internet servers they
|
2010-10-08 20:06:24 -03:00
|
|
|
# are meant to authenticate.
|
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
CERTFILE = data_file("keycert.pem")
|
2010-06-11 20:56:51 -03:00
|
|
|
BYTES_CERTFILE = os.fsencode(CERTFILE)
|
2010-05-16 15:19:27 -03:00
|
|
|
ONLYCERT = data_file("ssl_cert.pem")
|
|
|
|
ONLYKEY = data_file("ssl_key.pem")
|
2010-06-11 20:56:51 -03:00
|
|
|
BYTES_ONLYCERT = os.fsencode(ONLYCERT)
|
|
|
|
BYTES_ONLYKEY = os.fsencode(ONLYKEY)
|
2011-08-25 09:39:44 -03:00
|
|
|
CERTFILE_PROTECTED = data_file("keycert.passwd.pem")
|
|
|
|
ONLYKEY_PROTECTED = data_file("ssl_key.passwd.pem")
|
|
|
|
KEY_PASSWORD = "somepass"
|
2010-05-16 15:19:27 -03:00
|
|
|
CAPATH = data_file("capath")
|
2010-06-11 20:56:51 -03:00
|
|
|
BYTES_CAPATH = os.fsencode(CAPATH)
|
2013-11-20 22:35:02 -04:00
|
|
|
CAFILE_NEURONIO = data_file("capath", "4e1295a3.0")
|
|
|
|
CAFILE_CACERT = data_file("capath", "5ed36f99.0")
|
|
|
|
|
2024-09-25 18:23:47 -03:00
|
|
|
with open(data_file('keycert.pem.reference')) as file:
|
|
|
|
CERTFILE_INFO = literal_eval(file.read())
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2013-11-21 18:56:13 -04:00
|
|
|
# empty CRL
|
|
|
|
CRLFILE = data_file("revocation.crl")
|
|
|
|
|
2013-01-05 16:20:29 -04:00
|
|
|
# Two keys and certs signed by the same CA (for SNI tests)
|
|
|
|
SIGNED_CERTFILE = data_file("keycert3.pem")
|
2024-08-16 17:27:44 -03:00
|
|
|
SINGED_CERTFILE_ONLY = data_file("cert3.pem")
|
2017-09-15 15:27:30 -03:00
|
|
|
SIGNED_CERTFILE_HOSTNAME = 'localhost'
|
2018-01-20 10:16:30 -04:00
|
|
|
|
2024-09-25 18:23:47 -03:00
|
|
|
with open(data_file('keycert3.pem.reference')) as file:
|
|
|
|
SIGNED_CERTFILE_INFO = literal_eval(file.read())
|
2018-01-20 10:16:30 -04:00
|
|
|
|
2013-01-05 16:20:29 -04:00
|
|
|
SIGNED_CERTFILE2 = data_file("keycert4.pem")
|
2017-09-15 15:27:30 -03:00
|
|
|
SIGNED_CERTFILE2_HOSTNAME = 'fakehostname'
|
2018-01-20 10:16:30 -04:00
|
|
|
SIGNED_CERTFILE_ECC = data_file("keycertecc.pem")
|
|
|
|
SIGNED_CERTFILE_ECC_HOSTNAME = 'localhost-ecc'
|
|
|
|
|
2024-03-06 17:44:58 -04:00
|
|
|
# A custom testcase, extracted from `rfc5280::aki::leaf-missing-aki` in x509-limbo:
|
|
|
|
# The leaf (server) certificate has no AKI, which is forbidden under RFC 5280.
|
|
|
|
# See: https://x509-limbo.com/testcases/rfc5280/#rfc5280akileaf-missing-aki
|
|
|
|
LEAF_MISSING_AKI_CERTFILE = data_file("leaf-missing-aki.keycert.pem")
|
|
|
|
LEAF_MISSING_AKI_CERTFILE_HOSTNAME = "example.com"
|
|
|
|
LEAF_MISSING_AKI_CA = data_file("leaf-missing-aki.ca.pem")
|
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
# Same certificate as pycacert.pem, but without extra text in file
|
|
|
|
SIGNING_CA = data_file("capath", "ceff1710.0")
|
2016-09-06 18:25:35 -03:00
|
|
|
# cert with all kinds of subject alt names
|
|
|
|
ALLSANFILE = data_file("allsans.pem")
|
2018-01-29 09:25:13 -04:00
|
|
|
IDNSANSFILE = data_file("idnsans.pem")
|
2021-04-17 05:07:19 -03:00
|
|
|
NOSANFILE = data_file("nosan.pem")
|
|
|
|
NOSAN_HOSTNAME = 'localhost'
|
2013-01-05 16:20:29 -04:00
|
|
|
|
2016-01-14 05:36:00 -04:00
|
|
|
REMOTE_HOST = "self-signed.pythontest.net"
|
2010-05-16 15:19:27 -03:00
|
|
|
|
|
|
|
EMPTYCERT = data_file("nullcert.pem")
|
|
|
|
BADCERT = data_file("badcert.pem")
|
2016-01-29 23:41:43 -04:00
|
|
|
NONEXISTINGCERT = data_file("XXXnonexisting.pem")
|
2010-05-16 15:19:27 -03:00
|
|
|
BADKEY = data_file("badkey.pem")
|
2011-10-01 14:20:25 -03:00
|
|
|
NOKIACERT = data_file("nokia.pem")
|
2013-08-16 19:54:47 -03:00
|
|
|
NULLBYTECERT = data_file("nullbytecert.pem")
|
2019-01-15 18:47:42 -04:00
|
|
|
TALOS_INVALID_CRLDP = data_file("talos-2019-0758.pem")
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2018-08-14 07:54:19 -03:00
|
|
|
DHFILE = data_file("ffdh3072.pem")
|
2011-12-22 05:03:38 -04:00
|
|
|
BYTES_DHFILE = os.fsencode(DHFILE)
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2016-09-10 17:43:48 -03:00
|
|
|
# Not defined in all versions of OpenSSL
|
|
|
|
OP_NO_COMPRESSION = getattr(ssl, "OP_NO_COMPRESSION", 0)
|
|
|
|
OP_SINGLE_DH_USE = getattr(ssl, "OP_SINGLE_DH_USE", 0)
|
|
|
|
OP_SINGLE_ECDH_USE = getattr(ssl, "OP_SINGLE_ECDH_USE", 0)
|
|
|
|
OP_CIPHER_SERVER_PREFERENCE = getattr(ssl, "OP_CIPHER_SERVER_PREFERENCE", 0)
|
2018-02-27 03:55:39 -04:00
|
|
|
OP_ENABLE_MIDDLEBOX_COMPAT = getattr(ssl, "OP_ENABLE_MIDDLEBOX_COMPAT", 0)
|
2016-09-10 17:43:48 -03:00
|
|
|
|
2021-03-18 19:06:50 -03:00
|
|
|
# Ubuntu has patched OpenSSL and changed behavior of security level 2
|
|
|
|
# see https://bugs.python.org/issue41561#msg389003
|
|
|
|
def is_ubuntu():
|
|
|
|
try:
|
|
|
|
# Assume that any references of "ubuntu" implies Ubuntu-like distro
|
|
|
|
# The workaround is not required for 18.04, but doesn't hurt either.
|
|
|
|
with open("/etc/os-release", encoding="utf-8") as f:
|
|
|
|
return "ubuntu" in f.read()
|
|
|
|
except FileNotFoundError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if is_ubuntu():
|
|
|
|
def seclevel_workaround(*ctxs):
|
|
|
|
""""Lower security level to '1' and allow all ciphers for TLS 1.0/1"""
|
|
|
|
for ctx in ctxs:
|
2021-04-12 07:00:38 -03:00
|
|
|
if (
|
|
|
|
hasattr(ctx, "minimum_version") and
|
|
|
|
ctx.minimum_version <= ssl.TLSVersion.TLSv1_1
|
|
|
|
):
|
2021-03-18 19:06:50 -03:00
|
|
|
ctx.set_ciphers("@SECLEVEL=1:ALL")
|
|
|
|
else:
|
|
|
|
def seclevel_workaround(*ctxs):
|
|
|
|
pass
|
|
|
|
|
2013-01-05 16:20:29 -04:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
def has_tls_protocol(protocol):
|
|
|
|
"""Check if a TLS protocol is available and enabled
|
|
|
|
|
|
|
|
:param protocol: enum ssl._SSLMethod member or name
|
|
|
|
:return: bool
|
|
|
|
"""
|
|
|
|
if isinstance(protocol, str):
|
|
|
|
assert protocol.startswith('PROTOCOL_')
|
|
|
|
protocol = getattr(ssl, protocol, None)
|
|
|
|
if protocol is None:
|
|
|
|
return False
|
|
|
|
if protocol in {
|
|
|
|
ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS_SERVER,
|
|
|
|
ssl.PROTOCOL_TLS_CLIENT
|
|
|
|
}:
|
|
|
|
# auto-negotiate protocols are always available
|
|
|
|
return True
|
|
|
|
name = protocol.name
|
|
|
|
return has_tls_version(name[len('PROTOCOL_'):])
|
|
|
|
|
|
|
|
|
|
|
|
@functools.lru_cache
|
|
|
|
def has_tls_version(version):
|
|
|
|
"""Check if a TLS/SSL version is enabled
|
|
|
|
|
|
|
|
:param version: TLS version name or ssl.TLSVersion member
|
|
|
|
:return: bool
|
|
|
|
"""
|
|
|
|
if isinstance(version, str):
|
|
|
|
version = ssl.TLSVersion.__members__[version]
|
|
|
|
|
|
|
|
# check compile time flags like ssl.HAS_TLSv1_2
|
|
|
|
if not getattr(ssl, f'HAS_{version.name}'):
|
|
|
|
return False
|
|
|
|
|
2021-04-09 10:43:06 -03:00
|
|
|
if IS_OPENSSL_3_0_0 and version < ssl.TLSVersion.TLSv1_2:
|
|
|
|
# bpo43791: 3.0.0-alpha14 fails with TLSV1_ALERT_INTERNAL_ERROR
|
|
|
|
return False
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
# check runtime and dynamic crypto policy settings. A TLS version may
|
|
|
|
# be compiled in but disabled by a policy or config option.
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2019-09-26 12:02:59 -03:00
|
|
|
if (
|
2019-09-26 13:23:17 -03:00
|
|
|
hasattr(ctx, 'minimum_version') and
|
2019-09-26 12:02:59 -03:00
|
|
|
ctx.minimum_version != ssl.TLSVersion.MINIMUM_SUPPORTED and
|
|
|
|
version < ctx.minimum_version
|
|
|
|
):
|
|
|
|
return False
|
|
|
|
if (
|
2019-09-26 13:23:17 -03:00
|
|
|
hasattr(ctx, 'maximum_version') and
|
2019-09-26 12:02:59 -03:00
|
|
|
ctx.maximum_version != ssl.TLSVersion.MAXIMUM_SUPPORTED and
|
|
|
|
version > ctx.maximum_version
|
|
|
|
):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def requires_tls_version(version):
|
|
|
|
"""Decorator to skip tests when a required TLS version is not available
|
|
|
|
|
|
|
|
:param version: TLS version name or ssl.TLSVersion member
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
def decorator(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
def wrapper(*args, **kw):
|
|
|
|
if not has_tls_version(version):
|
|
|
|
raise unittest.SkipTest(f"{version} is not available.")
|
|
|
|
else:
|
|
|
|
return func(*args, **kw)
|
|
|
|
return wrapper
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
def handle_error(prefix):
|
2023-04-06 07:08:25 -03:00
|
|
|
exc_format = ' '.join(traceback.format_exception(sys.exception()))
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
sys.stdout.write(prefix + exc_format)
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2018-02-25 04:49:31 -04:00
|
|
|
|
2014-04-28 15:57:36 -03:00
|
|
|
def utc_offset(): #NOTE: ignore issues like #1647654
|
|
|
|
# local time = utc time + utc offset
|
|
|
|
if time.daylight and time.localtime().tm_isdst > 0:
|
|
|
|
return -time.altzone # seconds
|
|
|
|
return -time.timezone
|
|
|
|
|
2013-01-05 16:20:29 -04:00
|
|
|
|
2021-04-19 02:27:10 -03:00
|
|
|
ignore_deprecation = warnings_helper.ignore_warnings(
|
|
|
|
category=DeprecationWarning
|
|
|
|
)
|
|
|
|
|
2010-08-04 14:14:06 -03:00
|
|
|
|
2021-04-19 02:27:10 -03:00
|
|
|
def test_wrap_socket(sock, *,
|
2016-09-10 18:23:33 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE, ca_certs=None,
|
|
|
|
ciphers=None, certfile=None, keyfile=None,
|
|
|
|
**kwargs):
|
2021-04-19 02:27:10 -03:00
|
|
|
if not kwargs.get("server_side"):
|
|
|
|
kwargs["server_hostname"] = SIGNED_CERTFILE_HOSTNAME
|
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
else:
|
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2016-09-10 18:23:33 -03:00
|
|
|
if cert_reqs is not None:
|
2017-09-15 15:27:30 -03:00
|
|
|
if cert_reqs == ssl.CERT_NONE:
|
|
|
|
context.check_hostname = False
|
2016-09-10 18:23:33 -03:00
|
|
|
context.verify_mode = cert_reqs
|
|
|
|
if ca_certs is not None:
|
|
|
|
context.load_verify_locations(ca_certs)
|
|
|
|
if certfile is not None or keyfile is not None:
|
|
|
|
context.load_cert_chain(certfile, keyfile)
|
|
|
|
if ciphers is not None:
|
|
|
|
context.set_ciphers(ciphers)
|
|
|
|
return context.wrap_socket(sock, **kwargs)
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
|
2024-10-19 18:16:36 -03:00
|
|
|
USE_SAME_TEST_CONTEXT = False
|
|
|
|
_TEST_CONTEXT = None
|
|
|
|
|
2021-04-26 10:01:40 -03:00
|
|
|
def testing_context(server_cert=SIGNED_CERTFILE, *, server_chain=True):
|
2017-09-15 15:27:30 -03:00
|
|
|
"""Create context
|
|
|
|
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
"""
|
2024-10-19 18:16:36 -03:00
|
|
|
global _TEST_CONTEXT
|
|
|
|
if USE_SAME_TEST_CONTEXT:
|
|
|
|
if _TEST_CONTEXT is not None:
|
|
|
|
return _TEST_CONTEXT
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
if server_cert == SIGNED_CERTFILE:
|
|
|
|
hostname = SIGNED_CERTFILE_HOSTNAME
|
|
|
|
elif server_cert == SIGNED_CERTFILE2:
|
|
|
|
hostname = SIGNED_CERTFILE2_HOSTNAME
|
2021-04-17 05:07:19 -03:00
|
|
|
elif server_cert == NOSANFILE:
|
|
|
|
hostname = NOSAN_HOSTNAME
|
2017-09-15 15:27:30 -03:00
|
|
|
else:
|
|
|
|
raise ValueError(server_cert)
|
|
|
|
|
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
client_context.load_verify_locations(SIGNING_CA)
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
server_context.load_cert_chain(server_cert)
|
2021-04-26 10:01:40 -03:00
|
|
|
if server_chain:
|
|
|
|
server_context.load_verify_locations(SIGNING_CA)
|
2017-09-15 15:27:30 -03:00
|
|
|
|
2024-10-19 18:16:36 -03:00
|
|
|
if USE_SAME_TEST_CONTEXT:
|
|
|
|
if _TEST_CONTEXT is not None:
|
|
|
|
_TEST_CONTEXT = client_context, server_context, hostname
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
return client_context, server_context, hostname
|
|
|
|
|
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
class BasicSocketTests(unittest.TestCase):
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2010-04-28 18:37:09 -03:00
|
|
|
def test_constants(self):
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
ssl.CERT_NONE
|
|
|
|
ssl.CERT_OPTIONAL
|
|
|
|
ssl.CERT_REQUIRED
|
2011-12-19 08:27:11 -04:00
|
|
|
ssl.OP_CIPHER_SERVER_PREFERENCE
|
2011-12-22 05:03:38 -04:00
|
|
|
ssl.OP_SINGLE_DH_USE
|
2021-04-19 03:31:29 -03:00
|
|
|
ssl.OP_SINGLE_ECDH_USE
|
2021-04-17 06:36:35 -03:00
|
|
|
ssl.OP_NO_COMPRESSION
|
2021-04-19 03:31:29 -03:00
|
|
|
self.assertEqual(ssl.HAS_SNI, True)
|
|
|
|
self.assertEqual(ssl.HAS_ECDH, True)
|
|
|
|
self.assertEqual(ssl.HAS_TLSv1_2, True)
|
|
|
|
self.assertEqual(ssl.HAS_TLSv1_3, True)
|
2017-09-07 22:07:00 -03:00
|
|
|
ssl.OP_NO_SSLv2
|
|
|
|
ssl.OP_NO_SSLv3
|
|
|
|
ssl.OP_NO_TLSv1
|
|
|
|
ssl.OP_NO_TLSv1_3
|
2021-04-17 06:36:35 -03:00
|
|
|
ssl.OP_NO_TLSv1_1
|
|
|
|
ssl.OP_NO_TLSv1_2
|
2017-09-15 15:27:30 -03:00
|
|
|
self.assertEqual(ssl.PROTOCOL_TLS, ssl.PROTOCOL_SSLv23)
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2023-07-17 12:55:30 -03:00
|
|
|
def test_options(self):
|
|
|
|
# gh-106687: SSL options values are unsigned integer (uint64_t)
|
|
|
|
for name in dir(ssl):
|
|
|
|
if not name.startswith('OP_'):
|
|
|
|
continue
|
|
|
|
with self.subTest(option=name):
|
|
|
|
value = getattr(ssl, name)
|
|
|
|
self.assertGreaterEqual(value, 0, f"ssl.{name}")
|
|
|
|
|
2021-05-02 04:47:45 -03:00
|
|
|
def test_ssl_types(self):
|
|
|
|
ssl_types = [
|
|
|
|
_ssl._SSLContext,
|
|
|
|
_ssl._SSLSocket,
|
|
|
|
_ssl.MemoryBIO,
|
|
|
|
_ssl.Certificate,
|
|
|
|
_ssl.SSLSession,
|
|
|
|
_ssl.SSLError,
|
|
|
|
]
|
|
|
|
for ssl_type in ssl_types:
|
|
|
|
with self.subTest(ssl_type=ssl_type):
|
|
|
|
with self.assertRaisesRegex(TypeError, "immutable type"):
|
|
|
|
ssl_type.value = None
|
2021-05-27 03:43:52 -03:00
|
|
|
support.check_disallow_instantiation(self, _ssl.Certificate)
|
2021-05-02 04:47:45 -03:00
|
|
|
|
2018-02-27 05:17:30 -04:00
|
|
|
def test_private_init(self):
|
|
|
|
with self.assertRaisesRegex(TypeError, "public constructor"):
|
|
|
|
with socket.socket() as s:
|
|
|
|
ssl.SSLSocket(s)
|
|
|
|
|
2014-04-18 15:33:08 -03:00
|
|
|
def test_str_for_enums(self):
|
|
|
|
# Make sure that the PROTOCOL_* constants have enum-like string
|
|
|
|
# reprs.
|
2021-04-19 02:27:10 -03:00
|
|
|
proto = ssl.PROTOCOL_TLS_CLIENT
|
2022-01-17 12:52:42 -04:00
|
|
|
self.assertEqual(repr(proto), '<_SSLMethod.PROTOCOL_TLS_CLIENT: %r>' % proto.value)
|
|
|
|
self.assertEqual(str(proto), str(proto.value))
|
2014-04-18 15:33:08 -03:00
|
|
|
ctx = ssl.SSLContext(proto)
|
|
|
|
self.assertIs(ctx.protocol, proto)
|
|
|
|
|
2010-04-28 18:37:09 -03:00
|
|
|
def test_random(self):
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
v = ssl.RAND_status()
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
sys.stdout.write("\n RAND_status is %d (%s)\n"
|
|
|
|
% (v, (v and "sufficient randomness") or
|
|
|
|
"insufficient randomness"))
|
2011-05-24 07:05:19 -03:00
|
|
|
|
|
|
|
if v:
|
|
|
|
data = ssl.RAND_bytes(16)
|
|
|
|
self.assertEqual(len(data), 16)
|
2011-05-25 06:15:16 -03:00
|
|
|
else:
|
|
|
|
self.assertRaises(ssl.SSLError, ssl.RAND_bytes, 16)
|
2011-05-24 07:05:19 -03:00
|
|
|
|
2013-12-19 11:47:04 -04:00
|
|
|
# negative num is invalid
|
|
|
|
self.assertRaises(ValueError, ssl.RAND_bytes, -5)
|
|
|
|
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
ssl.RAND_add("this is a random string", 75.0)
|
2015-03-20 04:00:36 -03:00
|
|
|
ssl.RAND_add(b"this is a random bytes object", 75.0)
|
|
|
|
ssl.RAND_add(bytearray(b"this is a random bytearray object"), 75.0)
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2010-04-28 18:37:09 -03:00
|
|
|
def test_parse_cert(self):
|
2024-10-09 06:16:08 -03:00
|
|
|
self.maxDiff = None
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
# note that this uses an 'unofficial' function in _ssl.c,
|
|
|
|
# provided solely for this test, to exercise the certificate
|
|
|
|
# parsing code
|
2018-01-20 10:16:30 -04:00
|
|
|
self.assertEqual(
|
|
|
|
ssl._ssl._test_decode_cert(CERTFILE),
|
|
|
|
CERTFILE_INFO
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
ssl._ssl._test_decode_cert(SIGNED_CERTFILE),
|
|
|
|
SIGNED_CERTFILE_INFO
|
|
|
|
)
|
|
|
|
|
2011-10-01 14:20:25 -03:00
|
|
|
# Issue #13034: the subjectAltName in some certificates
|
|
|
|
# (notably projects.developer.nokia.com:443) wasn't parsed
|
|
|
|
p = ssl._ssl._test_decode_cert(NOKIACERT)
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n" + pprint.pformat(p) + "\n")
|
|
|
|
self.assertEqual(p['subjectAltName'],
|
|
|
|
(('DNS', 'projects.developer.nokia.com'),
|
|
|
|
('DNS', 'projects.forum.nokia.com'))
|
|
|
|
)
|
2013-11-20 22:40:15 -04:00
|
|
|
# extra OCSP and AIA fields
|
|
|
|
self.assertEqual(p['OCSP'], ('http://ocsp.verisign.com',))
|
|
|
|
self.assertEqual(p['caIssuers'],
|
|
|
|
('http://SVRIntl-G3-aia.verisign.com/SVRIntlG3.cer',))
|
|
|
|
self.assertEqual(p['crlDistributionPoints'],
|
|
|
|
('http://SVRIntl-G3-crl.verisign.com/SVRIntlG3.crl',))
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2019-01-15 18:47:42 -04:00
|
|
|
def test_parse_cert_CVE_2019_5010(self):
|
|
|
|
p = ssl._ssl._test_decode_cert(TALOS_INVALID_CRLDP)
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n" + pprint.pformat(p) + "\n")
|
|
|
|
self.assertEqual(
|
|
|
|
p,
|
|
|
|
{
|
|
|
|
'issuer': (
|
|
|
|
(('countryName', 'UK'),), (('commonName', 'cody-ca'),)),
|
|
|
|
'notAfter': 'Jun 14 18:00:58 2028 GMT',
|
|
|
|
'notBefore': 'Jun 18 18:00:58 2018 GMT',
|
|
|
|
'serialNumber': '02',
|
|
|
|
'subject': ((('countryName', 'UK'),),
|
|
|
|
(('commonName',
|
|
|
|
'codenomicon-vm-2.test.lal.cisco.com'),)),
|
|
|
|
'subjectAltName': (
|
|
|
|
('DNS', 'codenomicon-vm-2.test.lal.cisco.com'),),
|
|
|
|
'version': 3
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2013-08-16 19:54:47 -03:00
|
|
|
def test_parse_cert_CVE_2013_4238(self):
|
|
|
|
p = ssl._ssl._test_decode_cert(NULLBYTECERT)
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n" + pprint.pformat(p) + "\n")
|
|
|
|
subject = ((('countryName', 'US'),),
|
|
|
|
(('stateOrProvinceName', 'Oregon'),),
|
|
|
|
(('localityName', 'Beaverton'),),
|
|
|
|
(('organizationName', 'Python Software Foundation'),),
|
|
|
|
(('organizationalUnitName', 'Python Core Development'),),
|
|
|
|
(('commonName', 'null.python.org\x00example.org'),),
|
|
|
|
(('emailAddress', 'python-dev@python.org'),))
|
|
|
|
self.assertEqual(p['subject'], subject)
|
|
|
|
self.assertEqual(p['issuer'], subject)
|
2013-08-25 09:12:41 -03:00
|
|
|
if ssl._OPENSSL_API_VERSION >= (0, 9, 8):
|
|
|
|
san = (('DNS', 'altnull.python.org\x00example.com'),
|
|
|
|
('email', 'null@python.org\x00user@example.org'),
|
|
|
|
('URI', 'http://null.python.org\x00http://example.org'),
|
|
|
|
('IP Address', '192.0.2.1'),
|
2019-12-07 12:59:36 -04:00
|
|
|
('IP Address', '2001:DB8:0:0:0:0:0:1'))
|
2013-08-25 09:12:41 -03:00
|
|
|
else:
|
|
|
|
# OpenSSL 0.9.7 doesn't support IPv6 addresses in subjectAltName
|
|
|
|
san = (('DNS', 'altnull.python.org\x00example.com'),
|
|
|
|
('email', 'null@python.org\x00user@example.org'),
|
|
|
|
('URI', 'http://null.python.org\x00http://example.org'),
|
|
|
|
('IP Address', '192.0.2.1'),
|
|
|
|
('IP Address', '<invalid>'))
|
|
|
|
|
|
|
|
self.assertEqual(p['subjectAltName'], san)
|
2013-08-16 19:54:47 -03:00
|
|
|
|
2016-09-06 18:25:35 -03:00
|
|
|
def test_parse_all_sans(self):
|
|
|
|
p = ssl._ssl._test_decode_cert(ALLSANFILE)
|
|
|
|
self.assertEqual(p['subjectAltName'],
|
|
|
|
(
|
|
|
|
('DNS', 'allsans'),
|
|
|
|
('othername', '<unsupported>'),
|
|
|
|
('othername', '<unsupported>'),
|
|
|
|
('email', 'user@example.org'),
|
|
|
|
('DNS', 'www.example.org'),
|
|
|
|
('DirName',
|
|
|
|
((('countryName', 'XY'),),
|
|
|
|
(('localityName', 'Castle Anthrax'),),
|
|
|
|
(('organizationName', 'Python Software Foundation'),),
|
|
|
|
(('commonName', 'dirname example'),))),
|
|
|
|
('URI', 'https://www.python.org/'),
|
|
|
|
('IP Address', '127.0.0.1'),
|
2019-12-07 12:59:36 -04:00
|
|
|
('IP Address', '0:0:0:0:0:0:0:1'),
|
2016-09-06 18:25:35 -03:00
|
|
|
('Registered ID', '1.2.3.4.5')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2010-04-28 18:37:09 -03:00
|
|
|
def test_DER_to_PEM(self):
|
2016-01-14 05:36:00 -04:00
|
|
|
with open(CAFILE_CACERT, 'r') as f:
|
2010-04-28 18:37:09 -03:00
|
|
|
pem = f.read()
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
d1 = ssl.PEM_cert_to_DER_cert(pem)
|
|
|
|
p2 = ssl.DER_cert_to_PEM_cert(d1)
|
|
|
|
d2 = ssl.PEM_cert_to_DER_cert(p2)
|
2010-04-27 07:59:39 -03:00
|
|
|
self.assertEqual(d1, d2)
|
2010-04-27 19:08:08 -03:00
|
|
|
if not p2.startswith(ssl.PEM_HEADER + '\n'):
|
|
|
|
self.fail("DER-to-PEM didn't include correct header:\n%r\n" % p2)
|
|
|
|
if not p2.endswith('\n' + ssl.PEM_FOOTER + '\n'):
|
|
|
|
self.fail("DER-to-PEM didn't include correct footer:\n%r\n" % p2)
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2010-04-05 18:40:07 -03:00
|
|
|
def test_openssl_version(self):
|
|
|
|
n = ssl.OPENSSL_VERSION_NUMBER
|
|
|
|
t = ssl.OPENSSL_VERSION_INFO
|
|
|
|
s = ssl.OPENSSL_VERSION
|
|
|
|
self.assertIsInstance(n, int)
|
|
|
|
self.assertIsInstance(t, tuple)
|
|
|
|
self.assertIsInstance(s, str)
|
|
|
|
# Some sanity checks follow
|
2021-04-19 03:31:29 -03:00
|
|
|
# >= 1.1.1
|
|
|
|
self.assertGreaterEqual(n, 0x10101000)
|
2019-12-07 12:59:36 -04:00
|
|
|
# < 4.0
|
|
|
|
self.assertLess(n, 0x40000000)
|
2010-04-05 18:40:07 -03:00
|
|
|
major, minor, fix, patch, status = t
|
2019-12-07 12:59:36 -04:00
|
|
|
self.assertGreaterEqual(major, 1)
|
|
|
|
self.assertLess(major, 4)
|
2010-04-05 18:40:07 -03:00
|
|
|
self.assertGreaterEqual(minor, 0)
|
|
|
|
self.assertLess(minor, 256)
|
|
|
|
self.assertGreaterEqual(fix, 0)
|
|
|
|
self.assertLess(fix, 256)
|
|
|
|
self.assertGreaterEqual(patch, 0)
|
2015-02-05 02:20:13 -04:00
|
|
|
self.assertLessEqual(patch, 63)
|
2010-04-05 18:40:07 -03:00
|
|
|
self.assertGreaterEqual(status, 0)
|
|
|
|
self.assertLessEqual(status, 15)
|
2021-04-19 03:31:29 -03:00
|
|
|
|
|
|
|
libressl_ver = f"LibreSSL {major:d}"
|
2021-12-17 11:17:32 -04:00
|
|
|
if major >= 3:
|
|
|
|
# 3.x uses 0xMNN00PP0L
|
|
|
|
openssl_ver = f"OpenSSL {major:d}.{minor:d}.{patch:d}"
|
|
|
|
else:
|
|
|
|
openssl_ver = f"OpenSSL {major:d}.{minor:d}.{fix:d}"
|
2021-04-19 03:31:29 -03:00
|
|
|
self.assertTrue(
|
2024-03-21 16:16:36 -03:00
|
|
|
s.startswith((openssl_ver, libressl_ver, "AWS-LC")),
|
2021-04-19 03:31:29 -03:00
|
|
|
(s, t, hex(n))
|
|
|
|
)
|
2010-04-05 18:40:07 -03:00
|
|
|
|
2010-04-23 20:10:32 -03:00
|
|
|
@support.cpython_only
|
|
|
|
def test_refcycle(self):
|
|
|
|
# Issue #7943: an SSL object doesn't create reference cycles with
|
|
|
|
# itself.
|
|
|
|
s = socket.socket(socket.AF_INET)
|
2016-09-10 18:23:33 -03:00
|
|
|
ss = test_wrap_socket(s)
|
2010-04-23 20:10:32 -03:00
|
|
|
wr = weakref.ref(ss)
|
2020-08-03 13:41:24 -03:00
|
|
|
with warnings_helper.check_warnings(("", ResourceWarning)):
|
2013-01-12 16:54:44 -04:00
|
|
|
del ss
|
2016-03-21 13:26:04 -03:00
|
|
|
self.assertEqual(wr(), None)
|
2010-04-23 20:10:32 -03:00
|
|
|
|
2010-09-14 11:43:44 -03:00
|
|
|
def test_wrapped_unconnected(self):
|
|
|
|
# Methods on an unconnected SSLSocket propagate the original
|
2012-12-18 17:10:48 -04:00
|
|
|
# OSError raise by the underlying socket object.
|
2010-09-14 11:43:44 -03:00
|
|
|
s = socket.socket(socket.AF_INET)
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(s) as ss:
|
2013-01-12 16:56:56 -04:00
|
|
|
self.assertRaises(OSError, ss.recv, 1)
|
|
|
|
self.assertRaises(OSError, ss.recv_into, bytearray(b'x'))
|
|
|
|
self.assertRaises(OSError, ss.recvfrom, 1)
|
|
|
|
self.assertRaises(OSError, ss.recvfrom_into, bytearray(b'x'), 1)
|
|
|
|
self.assertRaises(OSError, ss.send, b'x')
|
|
|
|
self.assertRaises(OSError, ss.sendto, b'x', ('0.0.0.0', 0))
|
2018-12-06 16:36:55 -04:00
|
|
|
self.assertRaises(NotImplementedError, ss.dup)
|
2018-02-24 16:10:57 -04:00
|
|
|
self.assertRaises(NotImplementedError, ss.sendmsg,
|
|
|
|
[b'x'], (), 0, ('0.0.0.0', 0))
|
2018-12-06 16:36:55 -04:00
|
|
|
self.assertRaises(NotImplementedError, ss.recvmsg, 100)
|
|
|
|
self.assertRaises(NotImplementedError, ss.recvmsg_into,
|
|
|
|
[bytearray(100)])
|
2010-09-14 11:43:44 -03:00
|
|
|
|
2010-04-24 19:04:40 -03:00
|
|
|
def test_timeout(self):
|
|
|
|
# Issue #8524: when creating an SSL socket, the timeout of the
|
|
|
|
# original socket should be retained.
|
|
|
|
for timeout in (None, 0.0, 5.0):
|
|
|
|
s = socket.socket(socket.AF_INET)
|
|
|
|
s.settimeout(timeout)
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(s) as ss:
|
2013-01-12 16:54:44 -04:00
|
|
|
self.assertEqual(timeout, ss.gettimeout())
|
2010-04-24 19:04:40 -03:00
|
|
|
|
2021-06-13 08:46:07 -03:00
|
|
|
def test_openssl111_deprecations(self):
|
|
|
|
options = [
|
|
|
|
ssl.OP_NO_TLSv1,
|
|
|
|
ssl.OP_NO_TLSv1_1,
|
|
|
|
ssl.OP_NO_TLSv1_2,
|
|
|
|
ssl.OP_NO_TLSv1_3
|
|
|
|
]
|
|
|
|
protocols = [
|
|
|
|
ssl.PROTOCOL_TLSv1,
|
|
|
|
ssl.PROTOCOL_TLSv1_1,
|
|
|
|
ssl.PROTOCOL_TLSv1_2,
|
|
|
|
ssl.PROTOCOL_TLS
|
|
|
|
]
|
|
|
|
versions = [
|
|
|
|
ssl.TLSVersion.SSLv3,
|
|
|
|
ssl.TLSVersion.TLSv1,
|
|
|
|
ssl.TLSVersion.TLSv1_1,
|
|
|
|
]
|
|
|
|
|
|
|
|
for option in options:
|
|
|
|
with self.subTest(option=option):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
with self.assertWarns(DeprecationWarning) as cm:
|
|
|
|
ctx.options |= option
|
|
|
|
self.assertEqual(
|
2021-06-17 06:39:57 -03:00
|
|
|
'ssl.OP_NO_SSL*/ssl.OP_NO_TLS* options are deprecated',
|
2021-06-13 08:46:07 -03:00
|
|
|
str(cm.warning)
|
|
|
|
)
|
|
|
|
|
|
|
|
for protocol in protocols:
|
2022-06-28 04:33:06 -03:00
|
|
|
if not has_tls_protocol(protocol):
|
|
|
|
continue
|
2021-06-13 08:46:07 -03:00
|
|
|
with self.subTest(protocol=protocol):
|
|
|
|
with self.assertWarns(DeprecationWarning) as cm:
|
|
|
|
ssl.SSLContext(protocol)
|
|
|
|
self.assertEqual(
|
2022-01-17 11:18:13 -04:00
|
|
|
f'ssl.{protocol.name} is deprecated',
|
2021-06-13 08:46:07 -03:00
|
|
|
str(cm.warning)
|
|
|
|
)
|
|
|
|
|
|
|
|
for version in versions:
|
2022-06-28 04:33:06 -03:00
|
|
|
if not has_tls_version(version):
|
|
|
|
continue
|
2021-06-13 08:46:07 -03:00
|
|
|
with self.subTest(version=version):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
with self.assertWarns(DeprecationWarning) as cm:
|
|
|
|
ctx.minimum_version = version
|
2022-01-17 11:18:13 -04:00
|
|
|
version_text = '%s.%s' % (version.__class__.__name__, version.name)
|
2021-06-13 08:46:07 -03:00
|
|
|
self.assertEqual(
|
2022-01-17 11:18:13 -04:00
|
|
|
f'ssl.{version_text} is deprecated',
|
2021-06-13 08:46:07 -03:00
|
|
|
str(cm.warning)
|
|
|
|
)
|
|
|
|
|
2016-02-01 17:58:11 -04:00
|
|
|
def bad_cert_test(self, certfile):
|
|
|
|
"""Check that trying to use the given client certificate fails"""
|
|
|
|
certfile = os.path.join(os.path.dirname(__file__) or os.curdir,
|
2023-09-16 13:47:18 -03:00
|
|
|
"certdata", certfile)
|
2016-02-01 17:58:11 -04:00
|
|
|
sock = socket.socket()
|
|
|
|
self.addCleanup(sock.close)
|
|
|
|
with self.assertRaises(ssl.SSLError):
|
2016-09-10 18:23:33 -03:00
|
|
|
test_wrap_socket(sock,
|
2017-09-15 15:27:30 -03:00
|
|
|
certfile=certfile)
|
2016-02-01 17:58:11 -04:00
|
|
|
|
|
|
|
def test_empty_cert(self):
|
|
|
|
"""Wrapping with an empty cert file"""
|
|
|
|
self.bad_cert_test("nullcert.pem")
|
|
|
|
|
|
|
|
def test_malformed_cert(self):
|
|
|
|
"""Wrapping with a badly formatted certificate (syntax error)"""
|
|
|
|
self.bad_cert_test("badcert.pem")
|
|
|
|
|
|
|
|
def test_malformed_key(self):
|
|
|
|
"""Wrapping with a badly formatted key (syntax error)"""
|
|
|
|
self.bad_cert_test("badkey.pem")
|
|
|
|
|
2010-10-22 15:19:07 -03:00
|
|
|
def test_server_side(self):
|
|
|
|
# server_hostname doesn't work for server sockets
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2010-10-29 20:41:37 -03:00
|
|
|
with socket.socket() as sock:
|
|
|
|
self.assertRaises(ValueError, ctx.wrap_socket, sock, True,
|
|
|
|
server_hostname="some.hostname")
|
2010-04-05 18:40:07 -03:00
|
|
|
|
2011-07-20 20:11:30 -03:00
|
|
|
def test_unknown_channel_binding(self):
|
|
|
|
# should raise ValueError for unknown type
|
2019-04-08 19:34:02 -03:00
|
|
|
s = socket.create_server(('127.0.0.1', 0))
|
2014-10-05 15:41:53 -03:00
|
|
|
c = socket.socket(socket.AF_INET)
|
|
|
|
c.connect(s.getsockname())
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(c, do_handshake_on_connect=False) as ss:
|
2013-01-12 16:54:44 -04:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ss.get_channel_binding("unknown-type")
|
2014-10-05 15:41:53 -03:00
|
|
|
s.close()
|
2011-07-20 20:11:30 -03:00
|
|
|
|
|
|
|
@unittest.skipUnless("tls-unique" in ssl.CHANNEL_BINDING_TYPES,
|
|
|
|
"'tls-unique' channel binding not available")
|
|
|
|
def test_tls_unique_channel_binding(self):
|
|
|
|
# unconnected should return None for known type
|
|
|
|
s = socket.socket(socket.AF_INET)
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(s) as ss:
|
2013-01-12 16:54:44 -04:00
|
|
|
self.assertIsNone(ss.get_channel_binding("tls-unique"))
|
2011-07-20 20:11:30 -03:00
|
|
|
# the same for server-side
|
|
|
|
s = socket.socket(socket.AF_INET)
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(s, server_side=True, certfile=CERTFILE) as ss:
|
2013-01-12 16:54:44 -04:00
|
|
|
self.assertIsNone(ss.get_channel_binding("tls-unique"))
|
2011-07-20 20:11:30 -03:00
|
|
|
|
2013-01-10 16:16:20 -04:00
|
|
|
def test_dealloc_warn(self):
|
2016-09-10 18:23:33 -03:00
|
|
|
ss = test_wrap_socket(socket.socket(socket.AF_INET))
|
2013-01-10 16:16:20 -04:00
|
|
|
r = repr(ss)
|
|
|
|
with self.assertWarns(ResourceWarning) as cm:
|
|
|
|
ss = None
|
|
|
|
support.gc_collect()
|
|
|
|
self.assertIn(r, str(cm.warning.args[0]))
|
|
|
|
|
2013-06-09 13:02:55 -03:00
|
|
|
def test_get_default_verify_paths(self):
|
|
|
|
paths = ssl.get_default_verify_paths()
|
|
|
|
self.assertEqual(len(paths), 6)
|
|
|
|
self.assertIsInstance(paths, ssl.DefaultVerifyPaths)
|
|
|
|
|
2020-08-03 13:41:24 -03:00
|
|
|
with os_helper.EnvironmentVarGuard() as env:
|
2013-06-09 13:02:55 -03:00
|
|
|
env["SSL_CERT_DIR"] = CAPATH
|
|
|
|
env["SSL_CERT_FILE"] = CERTFILE
|
|
|
|
paths = ssl.get_default_verify_paths()
|
|
|
|
self.assertEqual(paths.cafile, CERTFILE)
|
|
|
|
self.assertEqual(paths.capath, CAPATH)
|
|
|
|
|
2013-06-09 14:03:31 -03:00
|
|
|
@unittest.skipUnless(sys.platform == "win32", "Windows specific")
|
2013-11-21 20:51:30 -04:00
|
|
|
def test_enum_certificates(self):
|
|
|
|
self.assertTrue(ssl.enum_certificates("CA"))
|
|
|
|
self.assertTrue(ssl.enum_certificates("ROOT"))
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, ssl.enum_certificates)
|
|
|
|
self.assertRaises(WindowsError, ssl.enum_certificates, "")
|
|
|
|
|
2013-11-22 11:13:55 -04:00
|
|
|
trust_oids = set()
|
|
|
|
for storename in ("CA", "ROOT"):
|
|
|
|
store = ssl.enum_certificates(storename)
|
|
|
|
self.assertIsInstance(store, list)
|
|
|
|
for element in store:
|
|
|
|
self.assertIsInstance(element, tuple)
|
|
|
|
self.assertEqual(len(element), 3)
|
|
|
|
cert, enc, trust = element
|
|
|
|
self.assertIsInstance(cert, bytes)
|
|
|
|
self.assertIn(enc, {"x509_asn", "pkcs_7_asn"})
|
2019-09-09 13:06:55 -03:00
|
|
|
self.assertIsInstance(trust, (frozenset, set, bool))
|
|
|
|
if isinstance(trust, (frozenset, set)):
|
2013-11-22 11:13:55 -04:00
|
|
|
trust_oids.update(trust)
|
2013-11-21 20:51:30 -04:00
|
|
|
|
|
|
|
serverAuth = "1.3.6.1.5.5.7.3.1"
|
2013-11-22 11:13:55 -04:00
|
|
|
self.assertIn(serverAuth, trust_oids)
|
2013-11-21 20:51:30 -04:00
|
|
|
|
|
|
|
@unittest.skipUnless(sys.platform == "win32", "Windows specific")
|
|
|
|
def test_enum_crls(self):
|
|
|
|
self.assertTrue(ssl.enum_crls("CA"))
|
|
|
|
self.assertRaises(TypeError, ssl.enum_crls)
|
|
|
|
self.assertRaises(WindowsError, ssl.enum_crls, "")
|
|
|
|
|
|
|
|
crls = ssl.enum_crls("CA")
|
|
|
|
self.assertIsInstance(crls, list)
|
|
|
|
for element in crls:
|
|
|
|
self.assertIsInstance(element, tuple)
|
|
|
|
self.assertEqual(len(element), 2)
|
|
|
|
self.assertIsInstance(element[0], bytes)
|
|
|
|
self.assertIn(element[1], {"x509_asn", "pkcs_7_asn"})
|
|
|
|
|
2013-06-09 14:03:31 -03:00
|
|
|
|
2013-11-17 14:59:14 -04:00
|
|
|
def test_asn1object(self):
|
|
|
|
expected = (129, 'serverAuth', 'TLS Web Server Authentication',
|
|
|
|
'1.3.6.1.5.5.7.3.1')
|
|
|
|
|
|
|
|
val = ssl._ASN1Object('1.3.6.1.5.5.7.3.1')
|
|
|
|
self.assertEqual(val, expected)
|
|
|
|
self.assertEqual(val.nid, 129)
|
|
|
|
self.assertEqual(val.shortname, 'serverAuth')
|
|
|
|
self.assertEqual(val.longname, 'TLS Web Server Authentication')
|
|
|
|
self.assertEqual(val.oid, '1.3.6.1.5.5.7.3.1')
|
|
|
|
self.assertIsInstance(val, ssl._ASN1Object)
|
|
|
|
self.assertRaises(ValueError, ssl._ASN1Object, 'serverAuth')
|
|
|
|
|
|
|
|
val = ssl._ASN1Object.fromnid(129)
|
|
|
|
self.assertEqual(val, expected)
|
|
|
|
self.assertIsInstance(val, ssl._ASN1Object)
|
|
|
|
self.assertRaises(ValueError, ssl._ASN1Object.fromnid, -1)
|
2013-11-22 11:20:53 -04:00
|
|
|
with self.assertRaisesRegex(ValueError, "unknown NID 100000"):
|
|
|
|
ssl._ASN1Object.fromnid(100000)
|
2013-11-17 14:59:14 -04:00
|
|
|
for i in range(1000):
|
|
|
|
try:
|
|
|
|
obj = ssl._ASN1Object.fromnid(i)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.assertIsInstance(obj.nid, int)
|
|
|
|
self.assertIsInstance(obj.shortname, str)
|
|
|
|
self.assertIsInstance(obj.longname, str)
|
|
|
|
self.assertIsInstance(obj.oid, (str, type(None)))
|
|
|
|
|
|
|
|
val = ssl._ASN1Object.fromname('TLS Web Server Authentication')
|
|
|
|
self.assertEqual(val, expected)
|
|
|
|
self.assertIsInstance(val, ssl._ASN1Object)
|
|
|
|
self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected)
|
|
|
|
self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'),
|
|
|
|
expected)
|
2013-11-22 11:20:53 -04:00
|
|
|
with self.assertRaisesRegex(ValueError, "unknown object 'serverauth'"):
|
|
|
|
ssl._ASN1Object.fromname('serverauth')
|
2013-11-17 14:59:14 -04:00
|
|
|
|
2013-11-23 08:56:58 -04:00
|
|
|
def test_purpose_enum(self):
|
|
|
|
val = ssl._ASN1Object('1.3.6.1.5.5.7.3.1')
|
|
|
|
self.assertIsInstance(ssl.Purpose.SERVER_AUTH, ssl._ASN1Object)
|
|
|
|
self.assertEqual(ssl.Purpose.SERVER_AUTH, val)
|
|
|
|
self.assertEqual(ssl.Purpose.SERVER_AUTH.nid, 129)
|
|
|
|
self.assertEqual(ssl.Purpose.SERVER_AUTH.shortname, 'serverAuth')
|
|
|
|
self.assertEqual(ssl.Purpose.SERVER_AUTH.oid,
|
|
|
|
'1.3.6.1.5.5.7.3.1')
|
|
|
|
|
|
|
|
val = ssl._ASN1Object('1.3.6.1.5.5.7.3.2')
|
|
|
|
self.assertIsInstance(ssl.Purpose.CLIENT_AUTH, ssl._ASN1Object)
|
|
|
|
self.assertEqual(ssl.Purpose.CLIENT_AUTH, val)
|
|
|
|
self.assertEqual(ssl.Purpose.CLIENT_AUTH.nid, 130)
|
|
|
|
self.assertEqual(ssl.Purpose.CLIENT_AUTH.shortname, 'clientAuth')
|
|
|
|
self.assertEqual(ssl.Purpose.CLIENT_AUTH.oid,
|
|
|
|
'1.3.6.1.5.5.7.3.2')
|
|
|
|
|
2013-12-28 12:26:33 -04:00
|
|
|
def test_unsupported_dtls(self):
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
with self.assertRaises(NotImplementedError) as cx:
|
2016-09-10 18:23:33 -03:00
|
|
|
test_wrap_socket(s, cert_reqs=ssl.CERT_NONE)
|
2013-12-28 12:26:33 -04:00
|
|
|
self.assertEqual(str(cx.exception), "only stream sockets are supported")
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-12-28 12:26:33 -04:00
|
|
|
with self.assertRaises(NotImplementedError) as cx:
|
|
|
|
ctx.wrap_socket(s)
|
|
|
|
self.assertEqual(str(cx.exception), "only stream sockets are supported")
|
|
|
|
|
2014-04-28 15:57:36 -03:00
|
|
|
def cert_time_ok(self, timestring, timestamp):
|
|
|
|
self.assertEqual(ssl.cert_time_to_seconds(timestring), timestamp)
|
|
|
|
|
|
|
|
def cert_time_fail(self, timestring):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ssl.cert_time_to_seconds(timestring)
|
|
|
|
|
|
|
|
@unittest.skipUnless(utc_offset(),
|
|
|
|
'local time needs to be different from UTC')
|
|
|
|
def test_cert_time_to_seconds_timezone(self):
|
|
|
|
# Issue #19940: ssl.cert_time_to_seconds() returns wrong
|
|
|
|
# results if local timezone is not UTC
|
|
|
|
self.cert_time_ok("May 9 00:00:00 2007 GMT", 1178668800.0)
|
|
|
|
self.cert_time_ok("Jan 5 09:34:43 2018 GMT", 1515144883.0)
|
|
|
|
|
|
|
|
def test_cert_time_to_seconds(self):
|
|
|
|
timestring = "Jan 5 09:34:43 2018 GMT"
|
|
|
|
ts = 1515144883.0
|
|
|
|
self.cert_time_ok(timestring, ts)
|
|
|
|
# accept keyword parameter, assert its name
|
|
|
|
self.assertEqual(ssl.cert_time_to_seconds(cert_time=timestring), ts)
|
|
|
|
# accept both %e and %d (space or zero generated by strftime)
|
|
|
|
self.cert_time_ok("Jan 05 09:34:43 2018 GMT", ts)
|
|
|
|
# case-insensitive
|
|
|
|
self.cert_time_ok("JaN 5 09:34:43 2018 GmT", ts)
|
|
|
|
self.cert_time_fail("Jan 5 09:34 2018 GMT") # no seconds
|
|
|
|
self.cert_time_fail("Jan 5 09:34:43 2018") # no GMT
|
|
|
|
self.cert_time_fail("Jan 5 09:34:43 2018 UTC") # not GMT timezone
|
|
|
|
self.cert_time_fail("Jan 35 09:34:43 2018 GMT") # invalid day
|
|
|
|
self.cert_time_fail("Jon 5 09:34:43 2018 GMT") # invalid month
|
|
|
|
self.cert_time_fail("Jan 5 24:00:00 2018 GMT") # invalid hour
|
|
|
|
self.cert_time_fail("Jan 5 09:60:43 2018 GMT") # invalid minute
|
|
|
|
|
|
|
|
newyear_ts = 1230768000.0
|
|
|
|
# leap seconds
|
|
|
|
self.cert_time_ok("Dec 31 23:59:60 2008 GMT", newyear_ts)
|
|
|
|
# same timestamp
|
|
|
|
self.cert_time_ok("Jan 1 00:00:00 2009 GMT", newyear_ts)
|
|
|
|
|
|
|
|
self.cert_time_ok("Jan 5 09:34:59 2018 GMT", 1515144899)
|
|
|
|
# allow 60th second (even if it is not a leap second)
|
|
|
|
self.cert_time_ok("Jan 5 09:34:60 2018 GMT", 1515144900)
|
|
|
|
# allow 2nd leap second for compatibility with time.strptime()
|
|
|
|
self.cert_time_ok("Jan 5 09:34:61 2018 GMT", 1515144901)
|
|
|
|
self.cert_time_fail("Jan 5 09:34:62 2018 GMT") # invalid seconds
|
|
|
|
|
2017-12-14 07:04:53 -04:00
|
|
|
# no special treatment for the special value:
|
2014-04-28 15:57:36 -03:00
|
|
|
# 99991231235959Z (rfc 5280)
|
|
|
|
self.cert_time_ok("Dec 31 23:59:59 9999 GMT", 253402300799.0)
|
|
|
|
|
|
|
|
@support.run_with_locale('LC_ALL', '')
|
|
|
|
def test_cert_time_to_seconds_locale(self):
|
|
|
|
# `cert_time_to_seconds()` should be locale independent
|
|
|
|
|
|
|
|
def local_february_name():
|
|
|
|
return time.strftime('%b', (1, 2, 3, 4, 5, 6, 0, 0, 0))
|
|
|
|
|
|
|
|
if local_february_name().lower() == 'feb':
|
|
|
|
self.skipTest("locale-specific month name needs to be "
|
|
|
|
"different from C locale")
|
|
|
|
|
|
|
|
# locale-independent
|
|
|
|
self.cert_time_ok("Feb 9 00:00:00 2007 GMT", 1170979200.0)
|
|
|
|
self.cert_time_fail(local_february_name() + " 9 00:00:00 2007 GMT")
|
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
def test_connect_ex_error(self):
|
|
|
|
server = socket.socket(socket.AF_INET)
|
|
|
|
self.addCleanup(server.close)
|
2020-04-25 04:06:29 -03:00
|
|
|
port = socket_helper.bind_port(server) # Reserve port but don't listen
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
rc = s.connect_ex((HOST, port))
|
|
|
|
# Issue #19919: Windows machines or VMs hosted on Windows
|
|
|
|
# machines sometimes return EWOULDBLOCK.
|
|
|
|
errors = (
|
|
|
|
errno.ECONNREFUSED, errno.EHOSTUNREACH, errno.ETIMEDOUT,
|
|
|
|
errno.EWOULDBLOCK,
|
|
|
|
)
|
|
|
|
self.assertIn(rc, errors)
|
|
|
|
|
2021-04-19 01:55:30 -03:00
|
|
|
def test_read_write_zero(self):
|
|
|
|
# empty reads and writes now work, bpo-42854, bpo-31711
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server = ThreadedEchoServer(context=server_context)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertEqual(s.recv(0), b"")
|
|
|
|
self.assertEqual(s.send(b""), 0)
|
|
|
|
|
2013-11-17 14:59:14 -04:00
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
class ContextTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_constructor(self):
|
2013-03-28 18:24:43 -03:00
|
|
|
for protocol in PROTOCOLS:
|
2022-06-28 04:33:06 -03:00
|
|
|
if has_tls_protocol(protocol):
|
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx = ssl.SSLContext(protocol)
|
|
|
|
self.assertEqual(ctx.protocol, protocol)
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx = ssl.SSLContext()
|
2016-09-05 18:19:05 -03:00
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS)
|
2010-05-16 15:19:27 -03:00
|
|
|
self.assertRaises(ValueError, ssl.SSLContext, -1)
|
|
|
|
self.assertRaises(ValueError, ssl.SSLContext, 42)
|
|
|
|
|
|
|
|
def test_ciphers(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.set_ciphers("ALL")
|
|
|
|
ctx.set_ciphers("DEFAULT")
|
2010-11-30 22:32:32 -04:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "No cipher can be selected"):
|
2010-05-16 20:46:26 -03:00
|
|
|
ctx.set_ciphers("^$:,;?*'dorothyx")
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2018-01-29 09:10:18 -04:00
|
|
|
@unittest.skipUnless(PY_SSL_DEFAULT_CIPHERS == 1,
|
|
|
|
"Test applies only to Python default ciphers")
|
|
|
|
def test_python_ciphers(self):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
ciphers = ctx.get_ciphers()
|
|
|
|
for suite in ciphers:
|
|
|
|
name = suite['name']
|
|
|
|
self.assertNotIn("PSK", name)
|
|
|
|
self.assertNotIn("SRP", name)
|
|
|
|
self.assertNotIn("MD5", name)
|
|
|
|
self.assertNotIn("RC4", name)
|
|
|
|
self.assertNotIn("3DES", name)
|
|
|
|
|
2016-09-05 19:04:45 -03:00
|
|
|
def test_get_ciphers(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2016-09-06 05:45:44 -03:00
|
|
|
ctx.set_ciphers('AESGCM')
|
2016-09-05 19:04:45 -03:00
|
|
|
names = set(d['name'] for d in ctx.get_ciphers())
|
2022-07-27 04:19:49 -03:00
|
|
|
expected = {
|
|
|
|
'AES128-GCM-SHA256',
|
|
|
|
'ECDHE-ECDSA-AES128-GCM-SHA256',
|
|
|
|
'ECDHE-RSA-AES128-GCM-SHA256',
|
|
|
|
'DHE-RSA-AES128-GCM-SHA256',
|
|
|
|
'AES256-GCM-SHA384',
|
|
|
|
'ECDHE-ECDSA-AES256-GCM-SHA384',
|
|
|
|
'ECDHE-RSA-AES256-GCM-SHA384',
|
|
|
|
'DHE-RSA-AES256-GCM-SHA384',
|
|
|
|
}
|
|
|
|
intersection = names.intersection(expected)
|
|
|
|
self.assertGreaterEqual(
|
|
|
|
len(intersection), 2, f"\ngot: {sorted(names)}\nexpected: {sorted(expected)}"
|
|
|
|
)
|
2016-09-05 19:04:45 -03:00
|
|
|
|
2010-05-21 06:56:06 -03:00
|
|
|
def test_options(self):
|
2023-07-17 12:55:30 -03:00
|
|
|
# Test default SSLContext options
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2015-11-12 02:38:41 -04:00
|
|
|
# OP_ALL | OP_NO_SSLv2 | OP_NO_SSLv3 is the default value
|
2016-09-05 18:19:05 -03:00
|
|
|
default = (ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3)
|
2016-09-10 17:43:48 -03:00
|
|
|
# SSLContext also enables these by default
|
|
|
|
default |= (OP_NO_COMPRESSION | OP_CIPHER_SERVER_PREFERENCE |
|
2018-02-27 03:55:39 -04:00
|
|
|
OP_SINGLE_DH_USE | OP_SINGLE_ECDH_USE |
|
GH-95494: Fix transport EOF handling in OpenSSL 3.0 (GH-95495)
GH-25309 enabled SSL_OP_IGNORE_UNEXPECTED_EOF by default, with a comment
that it restores OpenSSL 1.1.1 behavior, but this wasn't quite right.
That option causes OpenSSL to treat transport EOF as the same as
close_notify (i.e. SSL_ERROR_ZERO_RETURN), whereas Python actually has
distinct SSLEOFError and SSLZeroReturnError exceptions. (The latter is
usually mapped to a zero return from read.) In OpenSSL 1.1.1, the ssl
module would raise them for transport EOF and close_notify,
respectively. In OpenSSL 3.0, both act like close_notify.
Fix this by, instead, just detecting SSL_R_UNEXPECTED_EOF_WHILE_READING
and mapping that to the other exception type.
There doesn't seem to have been any unit test of this error, so fill in
the missing one. This had to be done with the BIO path because it's
actually slightly tricky to simulate a transport EOF with Python's fd
based APIs. (If you instruct the server to close the socket, it gets
confused, probably because the server's SSL object is still referencing
the now dead fd?)
2023-03-22 09:16:26 -03:00
|
|
|
OP_ENABLE_MIDDLEBOX_COMPAT)
|
2016-09-05 18:19:05 -03:00
|
|
|
self.assertEqual(default, ctx.options)
|
2023-07-17 12:55:30 -03:00
|
|
|
|
|
|
|
# disallow TLSv1
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx.options |= ssl.OP_NO_TLSv1
|
2016-09-05 18:19:05 -03:00
|
|
|
self.assertEqual(default | ssl.OP_NO_TLSv1, ctx.options)
|
2023-07-17 12:55:30 -03:00
|
|
|
|
|
|
|
# allow TLSv1
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx.options = (ctx.options & ~ssl.OP_NO_TLSv1)
|
2021-04-17 06:36:35 -03:00
|
|
|
self.assertEqual(default, ctx.options)
|
2023-07-17 12:55:30 -03:00
|
|
|
|
|
|
|
# clear all options
|
2021-04-17 06:36:35 -03:00
|
|
|
ctx.options = 0
|
|
|
|
# Ubuntu has OP_NO_SSLv3 forced on by default
|
|
|
|
self.assertEqual(0, ctx.options & ~ssl.OP_NO_SSLv3)
|
2010-05-21 06:56:06 -03:00
|
|
|
|
2023-07-17 12:55:30 -03:00
|
|
|
# invalid options
|
|
|
|
with self.assertRaises(OverflowError):
|
|
|
|
ctx.options = -1
|
|
|
|
with self.assertRaises(OverflowError):
|
|
|
|
ctx.options = 2 ** 100
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ctx.options = "abc"
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
def test_verify_mode_protocol(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
2010-05-16 15:19:27 -03:00
|
|
|
# Default value
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
|
|
|
ctx.verify_mode = ssl.CERT_OPTIONAL
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_OPTIONAL)
|
|
|
|
ctx.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ctx.verify_mode = None
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.verify_mode = 42
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
|
|
|
self.assertFalse(ctx.check_hostname)
|
|
|
|
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
self.assertTrue(ctx.check_hostname)
|
|
|
|
|
2018-01-27 10:51:38 -04:00
|
|
|
def test_hostname_checks_common_name(self):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertTrue(ctx.hostname_checks_common_name)
|
|
|
|
if ssl.HAS_NEVER_CHECK_COMMON_NAME:
|
|
|
|
ctx.hostname_checks_common_name = True
|
|
|
|
self.assertTrue(ctx.hostname_checks_common_name)
|
|
|
|
ctx.hostname_checks_common_name = False
|
|
|
|
self.assertFalse(ctx.hostname_checks_common_name)
|
|
|
|
ctx.hostname_checks_common_name = True
|
|
|
|
self.assertTrue(ctx.hostname_checks_common_name)
|
|
|
|
else:
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
ctx.hostname_checks_common_name = True
|
2017-09-15 15:27:30 -03:00
|
|
|
|
2021-04-19 02:27:10 -03:00
|
|
|
@ignore_deprecation
|
2018-02-27 06:54:43 -04:00
|
|
|
def test_min_max_version(self):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2019-01-18 11:09:30 -04:00
|
|
|
# OpenSSL default is MINIMUM_SUPPORTED, however some vendors like
|
|
|
|
# Fedora override the setting to TLS 1.0.
|
2019-09-26 12:02:59 -03:00
|
|
|
minimum_range = {
|
|
|
|
# stock OpenSSL
|
|
|
|
ssl.TLSVersion.MINIMUM_SUPPORTED,
|
|
|
|
# Fedora 29 uses TLS 1.0 by default
|
|
|
|
ssl.TLSVersion.TLSv1,
|
|
|
|
# RHEL 8 uses TLS 1.2 by default
|
|
|
|
ssl.TLSVersion.TLSv1_2
|
|
|
|
}
|
2019-12-02 12:15:42 -04:00
|
|
|
maximum_range = {
|
|
|
|
# stock OpenSSL
|
|
|
|
ssl.TLSVersion.MAXIMUM_SUPPORTED,
|
|
|
|
# Fedora 32 uses TLS 1.3 by default
|
|
|
|
ssl.TLSVersion.TLSv1_3
|
|
|
|
}
|
2019-09-26 12:02:59 -03:00
|
|
|
|
2019-01-18 11:09:30 -04:00
|
|
|
self.assertIn(
|
2019-09-26 12:02:59 -03:00
|
|
|
ctx.minimum_version, minimum_range
|
2018-02-27 06:54:43 -04:00
|
|
|
)
|
2019-12-02 12:15:42 -04:00
|
|
|
self.assertIn(
|
|
|
|
ctx.maximum_version, maximum_range
|
2018-02-27 06:54:43 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
ctx.minimum_version = ssl.TLSVersion.TLSv1_1
|
|
|
|
ctx.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
self.assertEqual(
|
|
|
|
ctx.minimum_version, ssl.TLSVersion.TLSv1_1
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
ctx.maximum_version, ssl.TLSVersion.TLSv1_2
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
|
|
|
|
ctx.maximum_version = ssl.TLSVersion.TLSv1
|
|
|
|
self.assertEqual(
|
|
|
|
ctx.minimum_version, ssl.TLSVersion.MINIMUM_SUPPORTED
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
ctx.maximum_version, ssl.TLSVersion.TLSv1
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
|
|
|
|
self.assertEqual(
|
|
|
|
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx.maximum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
|
|
|
|
self.assertIn(
|
|
|
|
ctx.maximum_version,
|
2022-06-28 04:33:06 -03:00
|
|
|
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.TLSv1_1, ssl.TLSVersion.SSLv3}
|
2018-02-27 06:54:43 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
ctx.minimum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
|
|
|
|
self.assertIn(
|
|
|
|
ctx.minimum_version,
|
|
|
|
{ssl.TLSVersion.TLSv1_2, ssl.TLSVersion.TLSv1_3}
|
|
|
|
)
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.minimum_version = 42
|
|
|
|
|
2022-06-28 04:33:06 -03:00
|
|
|
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)
|
2018-02-27 06:54:43 -04:00
|
|
|
|
2022-06-28 04:33:06 -03:00
|
|
|
self.assertIn(
|
|
|
|
ctx.minimum_version, minimum_range
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
|
|
|
|
)
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.maximum_version = ssl.TLSVersion.TLSv1
|
2018-02-27 06:54:43 -04:00
|
|
|
|
2020-07-17 05:59:15 -03:00
|
|
|
@unittest.skipUnless(
|
|
|
|
hasattr(ssl.SSLContext, 'security_level'),
|
|
|
|
"requires OpenSSL >= 1.1.0"
|
|
|
|
)
|
|
|
|
def test_security_level(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2020-07-17 05:59:15 -03:00
|
|
|
# The default security callback allows for levels between 0-5
|
|
|
|
# with OpenSSL defaulting to 1, however some vendors override the
|
|
|
|
# default value (e.g. Debian defaults to 2)
|
|
|
|
security_level_range = {
|
|
|
|
0,
|
|
|
|
1, # OpenSSL default
|
|
|
|
2, # Debian
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
}
|
|
|
|
self.assertIn(ctx.security_level, security_level_range)
|
|
|
|
|
2013-11-21 18:56:13 -04:00
|
|
|
def test_verify_flags(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2015-03-04 23:49:41 -04:00
|
|
|
# default value
|
|
|
|
tf = getattr(ssl, "VERIFY_X509_TRUSTED_FIRST", 0)
|
|
|
|
self.assertEqual(ctx.verify_flags, ssl.VERIFY_DEFAULT | tf)
|
2013-11-21 18:56:13 -04:00
|
|
|
ctx.verify_flags = ssl.VERIFY_CRL_CHECK_LEAF
|
|
|
|
self.assertEqual(ctx.verify_flags, ssl.VERIFY_CRL_CHECK_LEAF)
|
|
|
|
ctx.verify_flags = ssl.VERIFY_CRL_CHECK_CHAIN
|
|
|
|
self.assertEqual(ctx.verify_flags, ssl.VERIFY_CRL_CHECK_CHAIN)
|
|
|
|
ctx.verify_flags = ssl.VERIFY_DEFAULT
|
|
|
|
self.assertEqual(ctx.verify_flags, ssl.VERIFY_DEFAULT)
|
2021-03-18 05:24:01 -03:00
|
|
|
ctx.verify_flags = ssl.VERIFY_ALLOW_PROXY_CERTS
|
|
|
|
self.assertEqual(ctx.verify_flags, ssl.VERIFY_ALLOW_PROXY_CERTS)
|
2013-11-21 18:56:13 -04:00
|
|
|
# supports any value
|
|
|
|
ctx.verify_flags = ssl.VERIFY_CRL_CHECK_LEAF | ssl.VERIFY_X509_STRICT
|
|
|
|
self.assertEqual(ctx.verify_flags,
|
|
|
|
ssl.VERIFY_CRL_CHECK_LEAF | ssl.VERIFY_X509_STRICT)
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ctx.verify_flags = None
|
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
def test_load_cert_chain(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2010-05-16 15:19:27 -03:00
|
|
|
# Combined key and cert in a single file
|
2014-11-03 22:05:01 -04:00
|
|
|
ctx.load_cert_chain(CERTFILE, keyfile=None)
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(CERTFILE, keyfile=CERTFILE)
|
|
|
|
self.assertRaises(TypeError, ctx.load_cert_chain, keyfile=CERTFILE)
|
2012-12-25 10:47:37 -04:00
|
|
|
with self.assertRaises(OSError) as cm:
|
2016-01-29 23:41:43 -04:00
|
|
|
ctx.load_cert_chain(NONEXISTINGCERT)
|
2010-08-29 19:50:39 -03:00
|
|
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(BADCERT)
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(EMPTYCERT)
|
|
|
|
# Separate key and cert
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(ONLYCERT, ONLYKEY)
|
|
|
|
ctx.load_cert_chain(certfile=ONLYCERT, keyfile=ONLYKEY)
|
|
|
|
ctx.load_cert_chain(certfile=BYTES_ONLYCERT, keyfile=BYTES_ONLYKEY)
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(ONLYCERT)
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(ONLYKEY)
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_cert_chain(certfile=ONLYKEY, keyfile=ONLYCERT)
|
|
|
|
# Mismatching key and cert
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = re.compile(r"""(
|
|
|
|
key values mismatch # OpenSSL
|
|
|
|
|
|
|
|
|
KEY_VALUES_MISMATCH # AWS-LC
|
|
|
|
)""", re.X)
|
|
|
|
with self.assertRaisesRegex(ssl.SSLError, regex):
|
2016-01-14 05:36:00 -04:00
|
|
|
ctx.load_cert_chain(CAFILE_CACERT, ONLYKEY)
|
2011-08-25 09:39:44 -03:00
|
|
|
# Password protected key and cert
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=KEY_PASSWORD)
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=KEY_PASSWORD.encode())
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED,
|
|
|
|
password=bytearray(KEY_PASSWORD.encode()))
|
|
|
|
ctx.load_cert_chain(ONLYCERT, ONLYKEY_PROTECTED, KEY_PASSWORD)
|
|
|
|
ctx.load_cert_chain(ONLYCERT, ONLYKEY_PROTECTED, KEY_PASSWORD.encode())
|
|
|
|
ctx.load_cert_chain(ONLYCERT, ONLYKEY_PROTECTED,
|
|
|
|
bytearray(KEY_PASSWORD.encode()))
|
|
|
|
with self.assertRaisesRegex(TypeError, "should be a string"):
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=True)
|
|
|
|
with self.assertRaises(ssl.SSLError):
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password="badpass")
|
|
|
|
with self.assertRaisesRegex(ValueError, "cannot be longer"):
|
|
|
|
# openssl has a fixed limit on the password buffer.
|
|
|
|
# PEM_BUFSIZE is generally set to 1kb.
|
|
|
|
# Return a string larger than this.
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=b'a' * 102400)
|
|
|
|
# Password callback
|
|
|
|
def getpass_unicode():
|
|
|
|
return KEY_PASSWORD
|
|
|
|
def getpass_bytes():
|
|
|
|
return KEY_PASSWORD.encode()
|
|
|
|
def getpass_bytearray():
|
|
|
|
return bytearray(KEY_PASSWORD.encode())
|
|
|
|
def getpass_badpass():
|
|
|
|
return "badpass"
|
|
|
|
def getpass_huge():
|
|
|
|
return b'a' * (1024 * 1024)
|
|
|
|
def getpass_bad_type():
|
|
|
|
return 9
|
|
|
|
def getpass_exception():
|
|
|
|
raise Exception('getpass error')
|
|
|
|
class GetPassCallable:
|
|
|
|
def __call__(self):
|
|
|
|
return KEY_PASSWORD
|
|
|
|
def getpass(self):
|
|
|
|
return KEY_PASSWORD
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_unicode)
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_bytes)
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_bytearray)
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=GetPassCallable())
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED,
|
|
|
|
password=GetPassCallable().getpass)
|
|
|
|
with self.assertRaises(ssl.SSLError):
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_badpass)
|
|
|
|
with self.assertRaisesRegex(ValueError, "cannot be longer"):
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_huge)
|
|
|
|
with self.assertRaisesRegex(TypeError, "must return a string"):
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_bad_type)
|
|
|
|
with self.assertRaisesRegex(Exception, "getpass error"):
|
|
|
|
ctx.load_cert_chain(CERTFILE_PROTECTED, password=getpass_exception)
|
|
|
|
# Make sure the password function isn't called if it isn't needed
|
|
|
|
ctx.load_cert_chain(CERTFILE, password=getpass_exception)
|
2010-05-16 15:19:27 -03:00
|
|
|
|
|
|
|
def test_load_verify_locations(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_verify_locations(CERTFILE)
|
|
|
|
ctx.load_verify_locations(cafile=CERTFILE, capath=None)
|
|
|
|
ctx.load_verify_locations(BYTES_CERTFILE)
|
|
|
|
ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
|
|
|
|
self.assertRaises(TypeError, ctx.load_verify_locations)
|
2013-11-20 22:35:02 -04:00
|
|
|
self.assertRaises(TypeError, ctx.load_verify_locations, None, None, None)
|
2012-12-25 10:47:37 -04:00
|
|
|
with self.assertRaises(OSError) as cm:
|
2016-01-29 23:41:43 -04:00
|
|
|
ctx.load_verify_locations(NONEXISTINGCERT)
|
2010-08-29 19:50:39 -03:00
|
|
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
|
2010-05-16 15:19:27 -03:00
|
|
|
ctx.load_verify_locations(BADCERT)
|
|
|
|
ctx.load_verify_locations(CERTFILE, CAPATH)
|
|
|
|
ctx.load_verify_locations(CERTFILE, capath=BYTES_CAPATH)
|
|
|
|
|
2011-01-29 07:31:20 -04:00
|
|
|
# Issue #10989: crash if the second argument type is invalid
|
|
|
|
self.assertRaises(TypeError, ctx.load_verify_locations, None, True)
|
|
|
|
|
2013-11-20 22:35:02 -04:00
|
|
|
def test_load_verify_cadata(self):
|
|
|
|
# test cadata
|
|
|
|
with open(CAFILE_CACERT) as f:
|
|
|
|
cacert_pem = f.read()
|
|
|
|
cacert_der = ssl.PEM_cert_to_DER_cert(cacert_pem)
|
|
|
|
with open(CAFILE_NEURONIO) as f:
|
|
|
|
neuronio_pem = f.read()
|
|
|
|
neuronio_der = ssl.PEM_cert_to_DER_cert(neuronio_pem)
|
|
|
|
|
|
|
|
# test PEM
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-20 22:35:02 -04:00
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 0)
|
|
|
|
ctx.load_verify_locations(cadata=cacert_pem)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 1)
|
|
|
|
ctx.load_verify_locations(cadata=neuronio_pem)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
# cert already in hash table
|
|
|
|
ctx.load_verify_locations(cadata=neuronio_pem)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
|
|
|
|
# combined
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-20 22:35:02 -04:00
|
|
|
combined = "\n".join((cacert_pem, neuronio_pem))
|
|
|
|
ctx.load_verify_locations(cadata=combined)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
|
|
|
|
# with junk around the certs
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-20 22:35:02 -04:00
|
|
|
combined = ["head", cacert_pem, "other", neuronio_pem, "again",
|
|
|
|
neuronio_pem, "tail"]
|
|
|
|
ctx.load_verify_locations(cadata="\n".join(combined))
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
|
|
|
|
# test DER
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-20 22:35:02 -04:00
|
|
|
ctx.load_verify_locations(cadata=cacert_der)
|
|
|
|
ctx.load_verify_locations(cadata=neuronio_der)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
# cert already in hash table
|
|
|
|
ctx.load_verify_locations(cadata=cacert_der)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
|
|
|
|
# combined
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-20 22:35:02 -04:00
|
|
|
combined = b"".join((cacert_der, neuronio_der))
|
|
|
|
ctx.load_verify_locations(cadata=combined)
|
|
|
|
self.assertEqual(ctx.cert_store_stats()["x509_ca"], 2)
|
|
|
|
|
|
|
|
# error cases
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-20 22:35:02 -04:00
|
|
|
self.assertRaises(TypeError, ctx.load_verify_locations, cadata=object)
|
|
|
|
|
2021-04-23 08:51:40 -03:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
ssl.SSLError,
|
|
|
|
"no start line: cadata does not contain a certificate"
|
|
|
|
):
|
2013-11-20 22:35:02 -04:00
|
|
|
ctx.load_verify_locations(cadata="broken")
|
2021-04-23 08:51:40 -03:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
ssl.SSLError,
|
|
|
|
"not enough data: cadata does not contain a certificate"
|
|
|
|
):
|
2013-11-20 22:35:02 -04:00
|
|
|
ctx.load_verify_locations(cadata=b"broken")
|
2023-03-24 10:04:30 -03:00
|
|
|
with self.assertRaises(ssl.SSLError):
|
|
|
|
ctx.load_verify_locations(cadata=cacert_der + b"A")
|
2013-11-20 22:35:02 -04:00
|
|
|
|
2019-06-19 17:09:54 -03:00
|
|
|
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
|
2011-12-22 05:03:38 -04:00
|
|
|
def test_load_dh_params(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2011-12-22 05:03:38 -04:00
|
|
|
ctx.load_dh_params(DHFILE)
|
|
|
|
if os.name != 'nt':
|
|
|
|
ctx.load_dh_params(BYTES_DHFILE)
|
|
|
|
self.assertRaises(TypeError, ctx.load_dh_params)
|
|
|
|
self.assertRaises(TypeError, ctx.load_dh_params, None)
|
|
|
|
with self.assertRaises(FileNotFoundError) as cm:
|
2016-01-29 23:41:43 -04:00
|
|
|
ctx.load_dh_params(NONEXISTINGCERT)
|
2011-12-22 05:03:38 -04:00
|
|
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
2012-06-22 16:11:52 -03:00
|
|
|
with self.assertRaises(ssl.SSLError) as cm:
|
2011-12-22 05:03:38 -04:00
|
|
|
ctx.load_dh_params(CERTFILE)
|
|
|
|
|
2010-10-12 17:09:02 -03:00
|
|
|
def test_session_stats(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
for proto in {ssl.PROTOCOL_TLS_CLIENT, ssl.PROTOCOL_TLS_SERVER}:
|
2010-10-12 17:09:02 -03:00
|
|
|
ctx = ssl.SSLContext(proto)
|
|
|
|
self.assertEqual(ctx.session_stats(), {
|
|
|
|
'number': 0,
|
|
|
|
'connect': 0,
|
|
|
|
'connect_good': 0,
|
|
|
|
'connect_renegotiate': 0,
|
|
|
|
'accept': 0,
|
|
|
|
'accept_good': 0,
|
|
|
|
'accept_renegotiate': 0,
|
|
|
|
'hits': 0,
|
|
|
|
'misses': 0,
|
|
|
|
'timeouts': 0,
|
|
|
|
'cache_full': 0,
|
|
|
|
})
|
|
|
|
|
2010-11-17 16:29:42 -04:00
|
|
|
def test_set_default_verify_paths(self):
|
|
|
|
# There's not much we can do to test that it acts as expected,
|
|
|
|
# so just check it doesn't crash or raise an exception.
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2010-11-17 16:29:42 -04:00
|
|
|
ctx.set_default_verify_paths()
|
|
|
|
|
2011-12-21 04:27:41 -04:00
|
|
|
@unittest.skipUnless(ssl.HAS_ECDH, "ECDH disabled on this OpenSSL build")
|
2011-12-19 12:16:51 -04:00
|
|
|
def test_set_ecdh_curve(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2011-12-19 12:16:51 -04:00
|
|
|
ctx.set_ecdh_curve("prime256v1")
|
|
|
|
ctx.set_ecdh_curve(b"prime256v1")
|
|
|
|
self.assertRaises(TypeError, ctx.set_ecdh_curve)
|
|
|
|
self.assertRaises(TypeError, ctx.set_ecdh_curve, None)
|
|
|
|
self.assertRaises(ValueError, ctx.set_ecdh_curve, "foo")
|
|
|
|
self.assertRaises(ValueError, ctx.set_ecdh_curve, b"foo")
|
|
|
|
|
2013-01-05 16:20:29 -04:00
|
|
|
def test_sni_callback(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2013-01-05 16:20:29 -04:00
|
|
|
|
|
|
|
# set_servername_callback expects a callable, or None
|
|
|
|
self.assertRaises(TypeError, ctx.set_servername_callback)
|
|
|
|
self.assertRaises(TypeError, ctx.set_servername_callback, 4)
|
|
|
|
self.assertRaises(TypeError, ctx.set_servername_callback, "")
|
|
|
|
self.assertRaises(TypeError, ctx.set_servername_callback, ctx)
|
|
|
|
|
|
|
|
def dummycallback(sock, servername, ctx):
|
|
|
|
pass
|
|
|
|
ctx.set_servername_callback(None)
|
|
|
|
ctx.set_servername_callback(dummycallback)
|
|
|
|
|
|
|
|
def test_sni_callback_refcycle(self):
|
|
|
|
# Reference cycles through the servername callback are detected
|
|
|
|
# and cleared.
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2013-01-05 16:20:29 -04:00
|
|
|
def dummycallback(sock, servername, ctx, cycle=ctx):
|
|
|
|
pass
|
|
|
|
ctx.set_servername_callback(dummycallback)
|
|
|
|
wr = weakref.ref(ctx)
|
|
|
|
del ctx, dummycallback
|
|
|
|
gc.collect()
|
|
|
|
self.assertIs(wr(), None)
|
|
|
|
|
2013-06-17 10:44:12 -03:00
|
|
|
def test_cert_store_stats(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-06-17 10:44:12 -03:00
|
|
|
self.assertEqual(ctx.cert_store_stats(),
|
|
|
|
{'x509_ca': 0, 'crl': 0, 'x509': 0})
|
|
|
|
ctx.load_cert_chain(CERTFILE)
|
|
|
|
self.assertEqual(ctx.cert_store_stats(),
|
|
|
|
{'x509_ca': 0, 'crl': 0, 'x509': 0})
|
|
|
|
ctx.load_verify_locations(CERTFILE)
|
|
|
|
self.assertEqual(ctx.cert_store_stats(),
|
|
|
|
{'x509_ca': 0, 'crl': 0, 'x509': 1})
|
2016-01-14 08:53:56 -04:00
|
|
|
ctx.load_verify_locations(CAFILE_CACERT)
|
2013-06-17 10:44:12 -03:00
|
|
|
self.assertEqual(ctx.cert_store_stats(),
|
|
|
|
{'x509_ca': 1, 'crl': 0, 'x509': 2})
|
|
|
|
|
|
|
|
def test_get_ca_certs(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-06-17 10:44:12 -03:00
|
|
|
self.assertEqual(ctx.get_ca_certs(), [])
|
|
|
|
# CERTFILE is not flagged as X509v3 Basic Constraints: CA:TRUE
|
|
|
|
ctx.load_verify_locations(CERTFILE)
|
|
|
|
self.assertEqual(ctx.get_ca_certs(), [])
|
2016-01-14 08:53:56 -04:00
|
|
|
# but CAFILE_CACERT is a CA cert
|
|
|
|
ctx.load_verify_locations(CAFILE_CACERT)
|
2013-06-17 10:44:12 -03:00
|
|
|
self.assertEqual(ctx.get_ca_certs(),
|
|
|
|
[{'issuer': ((('organizationName', 'Root CA'),),
|
|
|
|
(('organizationalUnitName', 'http://www.cacert.org'),),
|
|
|
|
(('commonName', 'CA Cert Signing Authority'),),
|
|
|
|
(('emailAddress', 'support@cacert.org'),)),
|
2021-04-19 03:31:29 -03:00
|
|
|
'notAfter': 'Mar 29 12:29:49 2033 GMT',
|
|
|
|
'notBefore': 'Mar 30 12:29:49 2003 GMT',
|
2013-06-17 10:44:12 -03:00
|
|
|
'serialNumber': '00',
|
2013-11-20 22:40:15 -04:00
|
|
|
'crlDistributionPoints': ('https://www.cacert.org/revoke.crl',),
|
2013-06-17 10:44:12 -03:00
|
|
|
'subject': ((('organizationName', 'Root CA'),),
|
|
|
|
(('organizationalUnitName', 'http://www.cacert.org'),),
|
|
|
|
(('commonName', 'CA Cert Signing Authority'),),
|
|
|
|
(('emailAddress', 'support@cacert.org'),)),
|
|
|
|
'version': 3}])
|
|
|
|
|
2016-01-14 08:53:56 -04:00
|
|
|
with open(CAFILE_CACERT) as f:
|
2013-06-17 10:44:12 -03:00
|
|
|
pem = f.read()
|
|
|
|
der = ssl.PEM_cert_to_DER_cert(pem)
|
|
|
|
self.assertEqual(ctx.get_ca_certs(True), [der])
|
|
|
|
|
2013-11-23 08:56:58 -04:00
|
|
|
def test_load_default_certs(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 08:56:58 -04:00
|
|
|
ctx.load_default_certs()
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 08:56:58 -04:00
|
|
|
ctx.load_default_certs(ssl.Purpose.SERVER_AUTH)
|
|
|
|
ctx.load_default_certs()
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 08:56:58 -04:00
|
|
|
ctx.load_default_certs(ssl.Purpose.CLIENT_AUTH)
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 08:56:58 -04:00
|
|
|
self.assertRaises(TypeError, ctx.load_default_certs, None)
|
|
|
|
self.assertRaises(TypeError, ctx.load_default_certs, 'SERVER_AUTH')
|
|
|
|
|
2014-10-03 19:17:15 -03:00
|
|
|
@unittest.skipIf(sys.platform == "win32", "not-Windows specific")
|
2014-10-03 18:27:05 -03:00
|
|
|
def test_load_default_certs_env(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2020-08-03 13:41:24 -03:00
|
|
|
with os_helper.EnvironmentVarGuard() as env:
|
2014-10-03 18:27:05 -03:00
|
|
|
env["SSL_CERT_DIR"] = CAPATH
|
|
|
|
env["SSL_CERT_FILE"] = CERTFILE
|
|
|
|
ctx.load_default_certs()
|
|
|
|
self.assertEqual(ctx.cert_store_stats(), {"crl": 0, "x509": 1, "x509_ca": 0})
|
|
|
|
|
2014-10-03 19:17:15 -03:00
|
|
|
@unittest.skipUnless(sys.platform == "win32", "Windows specific")
|
2022-05-25 19:12:54 -03:00
|
|
|
@unittest.skipIf(support.Py_DEBUG,
|
|
|
|
"Debug build does not share environment between CRTs")
|
2014-10-03 19:17:15 -03:00
|
|
|
def test_load_default_certs_env_windows(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2014-10-03 19:17:15 -03:00
|
|
|
ctx.load_default_certs()
|
|
|
|
stats = ctx.cert_store_stats()
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2020-08-03 13:41:24 -03:00
|
|
|
with os_helper.EnvironmentVarGuard() as env:
|
2014-10-03 19:17:15 -03:00
|
|
|
env["SSL_CERT_DIR"] = CAPATH
|
|
|
|
env["SSL_CERT_FILE"] = CERTFILE
|
|
|
|
ctx.load_default_certs()
|
|
|
|
stats["x509"] += 1
|
|
|
|
self.assertEqual(ctx.cert_store_stats(), stats)
|
|
|
|
|
2016-09-10 17:43:48 -03:00
|
|
|
def _assert_context_options(self, ctx):
|
|
|
|
self.assertEqual(ctx.options & ssl.OP_NO_SSLv2, ssl.OP_NO_SSLv2)
|
|
|
|
if OP_NO_COMPRESSION != 0:
|
|
|
|
self.assertEqual(ctx.options & OP_NO_COMPRESSION,
|
|
|
|
OP_NO_COMPRESSION)
|
|
|
|
if OP_SINGLE_DH_USE != 0:
|
|
|
|
self.assertEqual(ctx.options & OP_SINGLE_DH_USE,
|
|
|
|
OP_SINGLE_DH_USE)
|
|
|
|
if OP_SINGLE_ECDH_USE != 0:
|
|
|
|
self.assertEqual(ctx.options & OP_SINGLE_ECDH_USE,
|
|
|
|
OP_SINGLE_ECDH_USE)
|
|
|
|
if OP_CIPHER_SERVER_PREFERENCE != 0:
|
|
|
|
self.assertEqual(ctx.options & OP_CIPHER_SERVER_PREFERENCE,
|
|
|
|
OP_CIPHER_SERVER_PREFERENCE)
|
2022-12-20 03:10:30 -04:00
|
|
|
self.assertEqual(ctx.options & ssl.OP_LEGACY_SERVER_CONNECT,
|
|
|
|
0 if IS_OPENSSL_3_0_0 else ssl.OP_LEGACY_SERVER_CONNECT)
|
2016-09-10 17:43:48 -03:00
|
|
|
|
2013-11-23 10:58:30 -04:00
|
|
|
def test_create_default_context(self):
|
|
|
|
ctx = ssl.create_default_context()
|
2016-09-10 17:43:48 -03:00
|
|
|
|
2021-04-19 02:27:10 -03:00
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 10:58:30 -04:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
2024-03-06 17:44:58 -04:00
|
|
|
self.assertEqual(ctx.verify_flags & ssl.VERIFY_X509_PARTIAL_CHAIN,
|
|
|
|
ssl.VERIFY_X509_PARTIAL_CHAIN)
|
|
|
|
self.assertEqual(ctx.verify_flags & ssl.VERIFY_X509_STRICT,
|
|
|
|
ssl.VERIFY_X509_STRICT)
|
2013-12-01 21:41:19 -04:00
|
|
|
self.assertTrue(ctx.check_hostname)
|
2016-09-10 17:43:48 -03:00
|
|
|
self._assert_context_options(ctx)
|
|
|
|
|
2013-11-23 10:58:30 -04:00
|
|
|
with open(SIGNING_CA) as f:
|
|
|
|
cadata = f.read()
|
|
|
|
ctx = ssl.create_default_context(cafile=SIGNING_CA, capath=CAPATH,
|
|
|
|
cadata=cadata)
|
2021-04-19 02:27:10 -03:00
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 10:58:30 -04:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
2016-09-10 17:43:48 -03:00
|
|
|
self._assert_context_options(ctx)
|
2013-11-23 10:58:30 -04:00
|
|
|
|
|
|
|
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
2021-04-19 02:27:10 -03:00
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_SERVER)
|
2013-11-23 10:58:30 -04:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
2016-09-10 17:43:48 -03:00
|
|
|
self._assert_context_options(ctx)
|
2013-11-23 10:58:30 -04:00
|
|
|
|
2013-11-23 17:43:47 -04:00
|
|
|
def test__create_stdlib_context(self):
|
|
|
|
ctx = ssl._create_stdlib_context()
|
2021-04-19 02:27:10 -03:00
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_CLIENT)
|
2013-11-23 17:43:47 -04:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
2013-12-01 21:41:19 -04:00
|
|
|
self.assertFalse(ctx.check_hostname)
|
2016-09-10 17:43:48 -03:00
|
|
|
self._assert_context_options(ctx)
|
2013-11-23 17:43:47 -04:00
|
|
|
|
2022-06-28 04:33:06 -03:00
|
|
|
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
|
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
|
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
|
|
|
self._assert_context_options(ctx)
|
2013-11-23 17:43:47 -04:00
|
|
|
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx = ssl._create_stdlib_context(
|
|
|
|
ssl.PROTOCOL_TLSv1_2,
|
|
|
|
cert_reqs=ssl.CERT_REQUIRED,
|
|
|
|
check_hostname=True
|
|
|
|
)
|
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1_2)
|
2013-11-23 17:43:47 -04:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
2013-12-02 15:59:28 -04:00
|
|
|
self.assertTrue(ctx.check_hostname)
|
2016-09-10 17:43:48 -03:00
|
|
|
self._assert_context_options(ctx)
|
2013-11-23 17:43:47 -04:00
|
|
|
|
|
|
|
ctx = ssl._create_stdlib_context(purpose=ssl.Purpose.CLIENT_AUTH)
|
2021-04-19 02:27:10 -03:00
|
|
|
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_SERVER)
|
2013-11-23 17:43:47 -04:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
2016-09-10 17:43:48 -03:00
|
|
|
self._assert_context_options(ctx)
|
2013-11-23 10:58:30 -04:00
|
|
|
|
2013-12-01 21:41:19 -04:00
|
|
|
def test_check_hostname(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
2013-12-01 21:41:19 -04:00
|
|
|
self.assertFalse(ctx.check_hostname)
|
2017-09-15 15:29:57 -03:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
2013-12-01 21:41:19 -04:00
|
|
|
|
2017-09-15 15:29:57 -03:00
|
|
|
# Auto set CERT_REQUIRED
|
|
|
|
ctx.check_hostname = True
|
|
|
|
self.assertTrue(ctx.check_hostname)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
ctx.check_hostname = False
|
2013-12-01 21:41:19 -04:00
|
|
|
ctx.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
self.assertFalse(ctx.check_hostname)
|
2017-09-15 15:29:57 -03:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
|
|
|
|
# Changing verify_mode does not affect check_hostname
|
|
|
|
ctx.check_hostname = False
|
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
ctx.check_hostname = False
|
|
|
|
self.assertFalse(ctx.check_hostname)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
|
|
|
# Auto set
|
2013-12-01 21:41:19 -04:00
|
|
|
ctx.check_hostname = True
|
|
|
|
self.assertTrue(ctx.check_hostname)
|
2017-09-15 15:29:57 -03:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
2013-12-01 21:41:19 -04:00
|
|
|
|
2017-09-15 15:29:57 -03:00
|
|
|
ctx.check_hostname = False
|
2013-12-01 21:41:19 -04:00
|
|
|
ctx.verify_mode = ssl.CERT_OPTIONAL
|
2017-09-15 15:29:57 -03:00
|
|
|
ctx.check_hostname = False
|
|
|
|
self.assertFalse(ctx.check_hostname)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_OPTIONAL)
|
|
|
|
# keep CERT_OPTIONAL
|
2013-12-01 21:41:19 -04:00
|
|
|
ctx.check_hostname = True
|
|
|
|
self.assertTrue(ctx.check_hostname)
|
2017-09-15 15:29:57 -03:00
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_OPTIONAL)
|
2013-12-01 21:41:19 -04:00
|
|
|
|
|
|
|
# Cannot set CERT_NONE with check_hostname enabled
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
ctx.check_hostname = False
|
|
|
|
self.assertFalse(ctx.check_hostname)
|
2017-09-15 15:29:57 -03:00
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
2013-12-01 21:41:19 -04:00
|
|
|
|
2016-09-11 19:01:11 -03:00
|
|
|
def test_context_client_server(self):
|
|
|
|
# PROTOCOL_TLS_CLIENT has sane defaults
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertTrue(ctx.check_hostname)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
|
|
|
|
# PROTOCOL_TLS_SERVER has different but also sane defaults
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
self.assertFalse(ctx.check_hostname)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
|
|
|
|
|
2017-09-15 15:26:05 -03:00
|
|
|
def test_context_custom_class(self):
|
|
|
|
class MySSLSocket(ssl.SSLSocket):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class MySSLObject(ssl.SSLObject):
|
|
|
|
pass
|
|
|
|
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
ctx.sslsocket_class = MySSLSocket
|
|
|
|
ctx.sslobject_class = MySSLObject
|
|
|
|
|
|
|
|
with ctx.wrap_socket(socket.socket(), server_side=True) as sock:
|
|
|
|
self.assertIsInstance(sock, MySSLSocket)
|
2021-06-11 04:15:48 -03:00
|
|
|
obj = ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(), server_side=True)
|
2017-09-15 15:26:05 -03:00
|
|
|
self.assertIsInstance(obj, MySSLObject)
|
|
|
|
|
2019-06-03 16:00:10 -03:00
|
|
|
def test_num_tickest(self):
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
self.assertEqual(ctx.num_tickets, 2)
|
|
|
|
ctx.num_tickets = 1
|
|
|
|
self.assertEqual(ctx.num_tickets, 1)
|
|
|
|
ctx.num_tickets = 0
|
|
|
|
self.assertEqual(ctx.num_tickets, 0)
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.num_tickets = -1
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ctx.num_tickets = None
|
|
|
|
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertEqual(ctx.num_tickets, 2)
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.num_tickets = 1
|
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2012-06-22 16:11:52 -03:00
|
|
|
class SSLErrorTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_str(self):
|
|
|
|
# The str() of a SSLError doesn't include the errno
|
|
|
|
e = ssl.SSLError(1, "foo")
|
|
|
|
self.assertEqual(str(e), "foo")
|
|
|
|
self.assertEqual(e.errno, 1)
|
|
|
|
# Same for a subclass
|
|
|
|
e = ssl.SSLZeroReturnError(1, "foo")
|
|
|
|
self.assertEqual(str(e), "foo")
|
|
|
|
self.assertEqual(e.errno, 1)
|
|
|
|
|
2019-06-19 17:09:54 -03:00
|
|
|
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
|
2012-06-22 16:11:52 -03:00
|
|
|
def test_lib_reason(self):
|
|
|
|
# Test the library and reason attributes
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2012-06-22 16:11:52 -03:00
|
|
|
with self.assertRaises(ssl.SSLError) as cm:
|
|
|
|
ctx.load_dh_params(CERTFILE)
|
|
|
|
self.assertEqual(cm.exception.library, 'PEM')
|
2024-03-21 16:16:36 -03:00
|
|
|
regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)"
|
|
|
|
self.assertRegex(cm.exception.reason, regex)
|
2012-06-22 16:11:52 -03:00
|
|
|
s = str(cm.exception)
|
2024-03-21 16:16:36 -03:00
|
|
|
self.assertTrue("NO_START_LINE" in s, s)
|
2012-06-22 16:11:52 -03:00
|
|
|
|
|
|
|
def test_subclass(self):
|
|
|
|
# Check that the appropriate SSLError subclass is raised
|
|
|
|
# (this only tests one of them)
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
ctx.check_hostname = False
|
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
2019-04-08 19:34:02 -03:00
|
|
|
with socket.create_server(("127.0.0.1", 0)) as s:
|
|
|
|
c = socket.create_connection(s.getsockname())
|
2013-01-12 16:54:44 -04:00
|
|
|
c.setblocking(False)
|
|
|
|
with ctx.wrap_socket(c, False, do_handshake_on_connect=False) as c:
|
2012-06-22 16:11:52 -03:00
|
|
|
with self.assertRaises(ssl.SSLWantReadError) as cm:
|
|
|
|
c.do_handshake()
|
|
|
|
s = str(cm.exception)
|
|
|
|
self.assertTrue(s.startswith("The operation did not complete (read)"), s)
|
|
|
|
# For compatibility
|
|
|
|
self.assertEqual(cm.exception.errno, ssl.SSL_ERROR_WANT_READ)
|
|
|
|
|
|
|
|
|
2018-01-27 10:51:38 -04:00
|
|
|
def test_bad_server_hostname(self):
|
|
|
|
ctx = ssl.create_default_context()
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(),
|
|
|
|
server_hostname="")
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(),
|
|
|
|
server_hostname=".example.org")
|
2018-03-25 07:36:13 -03:00
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(),
|
|
|
|
server_hostname="example.org\x00evil.com")
|
2018-01-27 10:51:38 -04:00
|
|
|
|
|
|
|
|
2014-10-05 15:41:53 -03:00
|
|
|
class MemoryBIOTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_read_write(self):
|
|
|
|
bio = ssl.MemoryBIO()
|
|
|
|
bio.write(b'foo')
|
|
|
|
self.assertEqual(bio.read(), b'foo')
|
|
|
|
self.assertEqual(bio.read(), b'')
|
|
|
|
bio.write(b'foo')
|
|
|
|
bio.write(b'bar')
|
|
|
|
self.assertEqual(bio.read(), b'foobar')
|
|
|
|
self.assertEqual(bio.read(), b'')
|
|
|
|
bio.write(b'baz')
|
|
|
|
self.assertEqual(bio.read(2), b'ba')
|
|
|
|
self.assertEqual(bio.read(1), b'z')
|
|
|
|
self.assertEqual(bio.read(1), b'')
|
|
|
|
|
|
|
|
def test_eof(self):
|
|
|
|
bio = ssl.MemoryBIO()
|
|
|
|
self.assertFalse(bio.eof)
|
|
|
|
self.assertEqual(bio.read(), b'')
|
|
|
|
self.assertFalse(bio.eof)
|
|
|
|
bio.write(b'foo')
|
|
|
|
self.assertFalse(bio.eof)
|
|
|
|
bio.write_eof()
|
|
|
|
self.assertFalse(bio.eof)
|
|
|
|
self.assertEqual(bio.read(2), b'fo')
|
|
|
|
self.assertFalse(bio.eof)
|
|
|
|
self.assertEqual(bio.read(1), b'o')
|
|
|
|
self.assertTrue(bio.eof)
|
|
|
|
self.assertEqual(bio.read(), b'')
|
|
|
|
self.assertTrue(bio.eof)
|
|
|
|
|
|
|
|
def test_pending(self):
|
|
|
|
bio = ssl.MemoryBIO()
|
|
|
|
self.assertEqual(bio.pending, 0)
|
|
|
|
bio.write(b'foo')
|
|
|
|
self.assertEqual(bio.pending, 3)
|
|
|
|
for i in range(3):
|
|
|
|
bio.read(1)
|
|
|
|
self.assertEqual(bio.pending, 3-i-1)
|
|
|
|
for i in range(3):
|
|
|
|
bio.write(b'x')
|
|
|
|
self.assertEqual(bio.pending, i+1)
|
|
|
|
bio.read()
|
|
|
|
self.assertEqual(bio.pending, 0)
|
|
|
|
|
|
|
|
def test_buffer_types(self):
|
|
|
|
bio = ssl.MemoryBIO()
|
|
|
|
bio.write(b'foo')
|
|
|
|
self.assertEqual(bio.read(), b'foo')
|
|
|
|
bio.write(bytearray(b'bar'))
|
|
|
|
self.assertEqual(bio.read(), b'bar')
|
|
|
|
bio.write(memoryview(b'baz'))
|
|
|
|
self.assertEqual(bio.read(), b'baz')
|
2023-10-19 19:09:57 -03:00
|
|
|
m = memoryview(bytearray(b'noncontig'))
|
|
|
|
noncontig_writable = m[::-2]
|
|
|
|
with self.assertRaises(BufferError):
|
|
|
|
bio.write(memoryview(noncontig_writable))
|
2014-10-05 15:41:53 -03:00
|
|
|
|
|
|
|
def test_error_types(self):
|
|
|
|
bio = ssl.MemoryBIO()
|
|
|
|
self.assertRaises(TypeError, bio.write, 'foo')
|
|
|
|
self.assertRaises(TypeError, bio.write, None)
|
|
|
|
self.assertRaises(TypeError, bio.write, True)
|
|
|
|
self.assertRaises(TypeError, bio.write, 1)
|
|
|
|
|
|
|
|
|
2018-02-27 05:17:30 -04:00
|
|
|
class SSLObjectTests(unittest.TestCase):
|
|
|
|
def test_private_init(self):
|
|
|
|
bio = ssl.MemoryBIO()
|
|
|
|
with self.assertRaisesRegex(TypeError, "public constructor"):
|
|
|
|
ssl.SSLObject(bio, bio)
|
|
|
|
|
2018-09-22 01:44:12 -03:00
|
|
|
def test_unwrap(self):
|
|
|
|
client_ctx, server_ctx, hostname = testing_context()
|
|
|
|
c_in = ssl.MemoryBIO()
|
|
|
|
c_out = ssl.MemoryBIO()
|
|
|
|
s_in = ssl.MemoryBIO()
|
|
|
|
s_out = ssl.MemoryBIO()
|
|
|
|
client = client_ctx.wrap_bio(c_in, c_out, server_hostname=hostname)
|
|
|
|
server = server_ctx.wrap_bio(s_in, s_out, server_side=True)
|
|
|
|
|
|
|
|
# Loop on the handshake for a bit to get it settled
|
|
|
|
for _ in range(5):
|
|
|
|
try:
|
|
|
|
client.do_handshake()
|
|
|
|
except ssl.SSLWantReadError:
|
|
|
|
pass
|
|
|
|
if c_out.pending:
|
|
|
|
s_in.write(c_out.read())
|
|
|
|
try:
|
|
|
|
server.do_handshake()
|
|
|
|
except ssl.SSLWantReadError:
|
|
|
|
pass
|
|
|
|
if s_out.pending:
|
|
|
|
c_in.write(s_out.read())
|
|
|
|
# Now the handshakes should be complete (don't raise WantReadError)
|
|
|
|
client.do_handshake()
|
|
|
|
server.do_handshake()
|
|
|
|
|
|
|
|
# Now if we unwrap one side unilaterally, it should send close-notify
|
|
|
|
# and raise WantReadError:
|
|
|
|
with self.assertRaises(ssl.SSLWantReadError):
|
|
|
|
client.unwrap()
|
|
|
|
|
|
|
|
# But server.unwrap() does not raise, because it reads the client's
|
|
|
|
# close-notify:
|
|
|
|
s_in.write(c_out.read())
|
|
|
|
server.unwrap()
|
|
|
|
|
|
|
|
# And now that the client gets the server's close-notify, it doesn't
|
|
|
|
# raise either.
|
|
|
|
c_in.write(s_out.read())
|
|
|
|
client.unwrap()
|
2018-02-27 05:17:30 -04:00
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
class SimpleBackgroundTests(unittest.TestCase):
|
|
|
|
"""Tests that connect to a simple server running in the background"""
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
def setUp(self):
|
2021-04-18 08:11:48 -03:00
|
|
|
self.server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
self.server_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
server = ThreadedEchoServer(context=self.server_context)
|
2022-05-08 11:49:09 -03:00
|
|
|
self.enterContext(server)
|
2016-03-26 22:53:46 -03:00
|
|
|
self.server_addr = (HOST, server.port)
|
2010-05-16 15:19:27 -03:00
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
def test_connect(self):
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE) as s:
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
self.assertEqual({}, s.getpeercert())
|
2016-09-24 05:48:05 -03:00
|
|
|
self.assertFalse(s.server_side)
|
2016-03-26 22:53:46 -03:00
|
|
|
|
|
|
|
# this should succeed because we specify the root cert
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED,
|
|
|
|
ca_certs=SIGNING_CA) as s:
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
self.assertTrue(s.getpeercert())
|
2016-09-24 05:48:05 -03:00
|
|
|
self.assertFalse(s.server_side)
|
2016-03-26 22:53:46 -03:00
|
|
|
|
|
|
|
def test_connect_fail(self):
|
|
|
|
# This should fail because we have no verification certs. Connection
|
|
|
|
# failure crashes ThreadedEchoServer, so run this in an independent
|
|
|
|
# test method.
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED)
|
|
|
|
self.addCleanup(s.close)
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = re.compile(r"""(
|
|
|
|
certificate verify failed # OpenSSL
|
|
|
|
|
|
|
|
|
CERTIFICATE_VERIFY_FAILED # AWS-LC
|
|
|
|
)""", re.X)
|
|
|
|
self.assertRaisesRegex(ssl.SSLError, regex,
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect, self.server_addr)
|
2010-09-09 10:31:46 -03:00
|
|
|
|
2011-02-26 19:24:06 -04:00
|
|
|
def test_connect_ex(self):
|
|
|
|
# Issue #11326: check connect_ex() implementation
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED,
|
|
|
|
ca_certs=SIGNING_CA)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
self.assertEqual(0, s.connect_ex(self.server_addr))
|
|
|
|
self.assertTrue(s.getpeercert())
|
2011-02-26 19:24:06 -04:00
|
|
|
|
|
|
|
def test_non_blocking_connect_ex(self):
|
|
|
|
# Issue #11326: non-blocking connect_ex() should allow handshake
|
|
|
|
# to proceed after the socket gets ready.
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED,
|
|
|
|
ca_certs=SIGNING_CA,
|
|
|
|
do_handshake_on_connect=False)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
s.setblocking(False)
|
|
|
|
rc = s.connect_ex(self.server_addr)
|
|
|
|
# EWOULDBLOCK under Windows, EINPROGRESS elsewhere
|
|
|
|
self.assertIn(rc, (0, errno.EINPROGRESS, errno.EWOULDBLOCK))
|
|
|
|
# Wait for connect to finish
|
|
|
|
select.select([], [s], [], 5.0)
|
|
|
|
# Non-blocking handshake
|
|
|
|
while True:
|
2011-02-26 19:24:06 -04:00
|
|
|
try:
|
2016-03-26 22:53:46 -03:00
|
|
|
s.do_handshake()
|
|
|
|
break
|
|
|
|
except ssl.SSLWantReadError:
|
|
|
|
select.select([s], [], [], 5.0)
|
|
|
|
except ssl.SSLWantWriteError:
|
2011-02-26 19:24:06 -04:00
|
|
|
select.select([], [s], [], 5.0)
|
2016-03-26 22:53:46 -03:00
|
|
|
# SSL established
|
|
|
|
self.assertTrue(s.getpeercert())
|
2012-12-28 14:03:43 -04:00
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
def test_connect_with_context(self):
|
2016-03-26 22:53:46 -03:00
|
|
|
# Same as test_connect, but with a separately created context
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
ctx.check_hostname = False
|
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
2016-03-26 22:53:46 -03:00
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s:
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
self.assertEqual({}, s.getpeercert())
|
|
|
|
# Same with a server hostname
|
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET),
|
|
|
|
server_hostname="dummy") as s:
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
ctx.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
# This should succeed because we specify the root cert
|
|
|
|
ctx.load_verify_locations(SIGNING_CA)
|
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s:
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert)
|
|
|
|
|
|
|
|
def test_connect_with_context_fail(self):
|
|
|
|
# This should fail because we have no verification certs. Connection
|
|
|
|
# failure crashes ThreadedEchoServer, so run this in an independent
|
|
|
|
# test method.
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
s = ctx.wrap_socket(
|
|
|
|
socket.socket(socket.AF_INET),
|
|
|
|
server_hostname=SIGNED_CERTFILE_HOSTNAME
|
|
|
|
)
|
2016-03-26 22:53:46 -03:00
|
|
|
self.addCleanup(s.close)
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = re.compile(r"""(
|
|
|
|
certificate verify failed # OpenSSL
|
|
|
|
|
|
|
|
|
CERTIFICATE_VERIFY_FAILED # AWS-LC
|
|
|
|
)""", re.X)
|
|
|
|
self.assertRaisesRegex(ssl.SSLError, regex,
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect, self.server_addr)
|
2010-05-16 15:19:27 -03:00
|
|
|
|
|
|
|
def test_connect_capath(self):
|
|
|
|
# Verify server certificates using the `capath` argument
|
2010-05-16 16:22:44 -03:00
|
|
|
# NOTE: the subject hashing algorithm has been changed between
|
|
|
|
# OpenSSL 0.9.8n and 1.0.0, as a result the capath directory must
|
|
|
|
# contain both versions of each certificate (same content, different
|
2010-05-17 11:13:10 -03:00
|
|
|
# filename) for this test to be portable across OpenSSL releases.
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.load_verify_locations(capath=CAPATH)
|
2021-04-19 02:27:10 -03:00
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET),
|
|
|
|
server_hostname=SIGNED_CERTFILE_HOSTNAME) as s:
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect(self.server_addr)
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert)
|
2018-05-23 17:24:45 -03:00
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
# Same with a bytes `capath` argument
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.load_verify_locations(capath=BYTES_CAPATH)
|
2021-04-19 02:27:10 -03:00
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET),
|
|
|
|
server_hostname=SIGNED_CERTFILE_HOSTNAME) as s:
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect(self.server_addr)
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert)
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2013-11-20 22:35:02 -04:00
|
|
|
def test_connect_cadata(self):
|
2016-03-26 22:53:46 -03:00
|
|
|
with open(SIGNING_CA) as f:
|
2013-11-20 22:35:02 -04:00
|
|
|
pem = f.read()
|
|
|
|
der = ssl.PEM_cert_to_DER_cert(pem)
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.load_verify_locations(cadata=pem)
|
2021-04-19 02:27:10 -03:00
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET),
|
|
|
|
server_hostname=SIGNED_CERTFILE_HOSTNAME) as s:
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect(self.server_addr)
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert)
|
2013-11-20 22:35:02 -04:00
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
# same with DER
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.load_verify_locations(cadata=der)
|
2021-04-19 02:27:10 -03:00
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET),
|
|
|
|
server_hostname=SIGNED_CERTFILE_HOSTNAME) as s:
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect(self.server_addr)
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert)
|
2013-11-20 22:35:02 -04:00
|
|
|
|
2010-04-24 08:13:53 -03:00
|
|
|
@unittest.skipIf(os.name == "nt", "Can't use a socket as a file under Windows")
|
|
|
|
def test_makefile_close(self):
|
|
|
|
# Issue #5238: creating a file-like object with makefile() shouldn't
|
|
|
|
# delay closing the underlying "real socket" (here tested with its
|
|
|
|
# file descriptor, hence skipping the test under Windows).
|
2016-09-10 18:23:33 -03:00
|
|
|
ss = test_wrap_socket(socket.socket(socket.AF_INET))
|
2016-03-26 22:53:46 -03:00
|
|
|
ss.connect(self.server_addr)
|
|
|
|
fd = ss.fileno()
|
|
|
|
f = ss.makefile()
|
|
|
|
f.close()
|
|
|
|
# The fd is still open
|
|
|
|
os.read(fd, 0)
|
|
|
|
# Closing the SSL socket should close the fd too
|
|
|
|
ss.close()
|
|
|
|
gc.collect()
|
|
|
|
with self.assertRaises(OSError) as e:
|
2010-04-24 08:13:53 -03:00
|
|
|
os.read(fd, 0)
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertEqual(e.exception.errno, errno.EBADF)
|
2010-04-24 08:13:53 -03:00
|
|
|
|
2010-04-28 18:37:09 -03:00
|
|
|
def test_non_blocking_handshake(self):
|
2016-03-26 22:53:46 -03:00
|
|
|
s = socket.socket(socket.AF_INET)
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
s.setblocking(False)
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(s,
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE,
|
|
|
|
do_handshake_on_connect=False)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
count = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
count += 1
|
|
|
|
s.do_handshake()
|
|
|
|
break
|
|
|
|
except ssl.SSLWantReadError:
|
|
|
|
select.select([s], [], [])
|
|
|
|
except ssl.SSLWantWriteError:
|
|
|
|
select.select([], [s], [])
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\nNeeded %d calls to do_handshake() to establish session.\n" % count)
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2010-04-28 18:37:09 -03:00
|
|
|
def test_get_server_certificate(self):
|
2016-03-26 22:53:46 -03:00
|
|
|
_test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
|
2011-04-28 14:24:46 -03:00
|
|
|
|
2021-04-18 08:11:48 -03:00
|
|
|
def test_get_server_certificate_sni(self):
|
|
|
|
host, port = self.server_addr
|
|
|
|
server_names = []
|
|
|
|
|
|
|
|
# We store servername_cb arguments to make sure they match the host
|
|
|
|
def servername_cb(ssl_sock, server_name, initial_context):
|
|
|
|
server_names.append(server_name)
|
|
|
|
self.server_context.set_servername_callback(servername_cb)
|
|
|
|
|
|
|
|
pem = ssl.get_server_certificate((host, port))
|
|
|
|
if not pem:
|
|
|
|
self.fail("No server certificate on %s:%s!" % (host, port))
|
|
|
|
|
|
|
|
pem = ssl.get_server_certificate((host, port), ca_certs=SIGNING_CA)
|
|
|
|
if not pem:
|
|
|
|
self.fail("No server certificate on %s:%s!" % (host, port))
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\nVerified certificate for %s:%s is\n%s\n" % (host, port, pem))
|
|
|
|
|
|
|
|
self.assertEqual(server_names, [host, host])
|
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
def test_get_server_certificate_fail(self):
|
|
|
|
# Connection failure crashes ThreadedEchoServer, so run this in an
|
|
|
|
# independent test method
|
|
|
|
_test_get_server_certificate_fail(self, *self.server_addr)
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2021-04-24 01:46:01 -03:00
|
|
|
def test_get_server_certificate_timeout(self):
|
2021-04-24 02:54:08 -03:00
|
|
|
def servername_cb(ssl_sock, server_name, initial_context):
|
|
|
|
time.sleep(0.2)
|
|
|
|
self.server_context.set_servername_callback(servername_cb)
|
|
|
|
|
2021-04-24 01:46:01 -03:00
|
|
|
with self.assertRaises(socket.timeout):
|
|
|
|
ssl.get_server_certificate(self.server_addr, ca_certs=SIGNING_CA,
|
2021-04-24 02:54:08 -03:00
|
|
|
timeout=0.1)
|
2021-04-24 01:46:01 -03:00
|
|
|
|
2010-08-15 20:02:22 -03:00
|
|
|
def test_ciphers(self):
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE, ciphers="ALL") as s:
|
|
|
|
s.connect(self.server_addr)
|
2016-09-10 18:23:33 -03:00
|
|
|
with test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE, ciphers="DEFAULT") as s:
|
|
|
|
s.connect(self.server_addr)
|
|
|
|
# Error checking can happen at instantiation or when connecting
|
|
|
|
with self.assertRaisesRegex(ssl.SSLError, "No cipher can be selected"):
|
|
|
|
with socket.socket(socket.AF_INET) as sock:
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(sock,
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE, ciphers="^$:,;?*'dorothyx")
|
|
|
|
s.connect(self.server_addr)
|
2010-04-21 16:46:23 -03:00
|
|
|
|
2013-06-17 10:44:12 -03:00
|
|
|
def test_get_ca_certs_capath(self):
|
|
|
|
# capath certs are loaded on request
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.load_verify_locations(capath=CAPATH)
|
|
|
|
self.assertEqual(ctx.get_ca_certs(), [])
|
2017-09-15 15:27:30 -03:00
|
|
|
with ctx.wrap_socket(socket.socket(socket.AF_INET),
|
|
|
|
server_hostname='localhost') as s:
|
2016-03-26 22:53:46 -03:00
|
|
|
s.connect(self.server_addr)
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert)
|
|
|
|
self.assertEqual(len(ctx.get_ca_certs()), 1)
|
2013-06-17 10:44:12 -03:00
|
|
|
|
2013-12-05 02:41:08 -04:00
|
|
|
def test_context_setget(self):
|
|
|
|
# Check that the context of a connected socket can be replaced.
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx1 = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
ctx1.load_verify_locations(capath=CAPATH)
|
|
|
|
ctx2 = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
ctx2.load_verify_locations(capath=CAPATH)
|
2016-03-26 22:53:46 -03:00
|
|
|
s = socket.socket(socket.AF_INET)
|
2017-09-15 15:27:30 -03:00
|
|
|
with ctx1.wrap_socket(s, server_hostname='localhost') as ss:
|
2016-03-26 22:53:46 -03:00
|
|
|
ss.connect(self.server_addr)
|
|
|
|
self.assertIs(ss.context, ctx1)
|
|
|
|
self.assertIs(ss._sslobj.context, ctx1)
|
|
|
|
ss.context = ctx2
|
|
|
|
self.assertIs(ss.context, ctx2)
|
|
|
|
self.assertIs(ss._sslobj.context, ctx2)
|
2014-10-05 15:41:53 -03:00
|
|
|
|
|
|
|
def ssl_io_loop(self, sock, incoming, outgoing, func, *args, **kwargs):
|
|
|
|
# A simple IO loop. Call func(*args) depending on the error we get
|
|
|
|
# (WANT_READ or WANT_WRITE) move data between the socket and the BIOs.
|
2019-12-11 06:30:03 -04:00
|
|
|
timeout = kwargs.get('timeout', support.SHORT_TIMEOUT)
|
2014-10-05 15:41:53 -03:00
|
|
|
count = 0
|
2022-06-15 06:42:10 -03:00
|
|
|
for _ in support.busy_retry(timeout):
|
2014-10-05 15:41:53 -03:00
|
|
|
errno = None
|
|
|
|
count += 1
|
|
|
|
try:
|
|
|
|
ret = func(*args)
|
|
|
|
except ssl.SSLError as e:
|
|
|
|
if e.errno not in (ssl.SSL_ERROR_WANT_READ,
|
2016-01-14 09:05:46 -04:00
|
|
|
ssl.SSL_ERROR_WANT_WRITE):
|
2014-10-05 15:41:53 -03:00
|
|
|
raise
|
|
|
|
errno = e.errno
|
|
|
|
# Get any data from the outgoing BIO irrespective of any error, and
|
|
|
|
# send it to the socket.
|
|
|
|
buf = outgoing.read()
|
|
|
|
sock.sendall(buf)
|
|
|
|
# If there's no error, we're done. For WANT_READ, we need to get
|
|
|
|
# data from the socket and put it in the incoming BIO.
|
|
|
|
if errno is None:
|
|
|
|
break
|
|
|
|
elif errno == ssl.SSL_ERROR_WANT_READ:
|
|
|
|
buf = sock.recv(32768)
|
|
|
|
if buf:
|
|
|
|
incoming.write(buf)
|
|
|
|
else:
|
|
|
|
incoming.write_eof()
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("Needed %d calls to complete %s().\n"
|
|
|
|
% (count, func.__name__))
|
|
|
|
return ret
|
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
def test_bio_handshake(self):
|
|
|
|
sock = socket.socket(socket.AF_INET)
|
|
|
|
self.addCleanup(sock.close)
|
|
|
|
sock.connect(self.server_addr)
|
|
|
|
incoming = ssl.MemoryBIO()
|
|
|
|
outgoing = ssl.MemoryBIO()
|
2017-09-15 15:27:30 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertTrue(ctx.check_hostname)
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.load_verify_locations(SIGNING_CA)
|
2017-09-15 15:27:30 -03:00
|
|
|
sslobj = ctx.wrap_bio(incoming, outgoing, False,
|
|
|
|
SIGNED_CERTFILE_HOSTNAME)
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertIs(sslobj._sslobj.owner, sslobj)
|
|
|
|
self.assertIsNone(sslobj.cipher())
|
2017-09-06 01:55:40 -03:00
|
|
|
self.assertIsNone(sslobj.version())
|
2023-03-22 11:08:41 -03:00
|
|
|
self.assertIsNone(sslobj.shared_ciphers())
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertRaises(ValueError, sslobj.getpeercert)
|
2024-03-21 16:16:36 -03:00
|
|
|
# tls-unique is not defined for TLSv1.3
|
|
|
|
# https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
|
|
|
|
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES and sslobj.version() != "TLSv1.3":
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertIsNone(sslobj.get_channel_binding('tls-unique'))
|
|
|
|
self.ssl_io_loop(sock, incoming, outgoing, sslobj.do_handshake)
|
|
|
|
self.assertTrue(sslobj.cipher())
|
2023-03-22 11:08:41 -03:00
|
|
|
self.assertIsNone(sslobj.shared_ciphers())
|
2017-09-06 01:55:40 -03:00
|
|
|
self.assertIsNotNone(sslobj.version())
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertTrue(sslobj.getpeercert())
|
2024-03-21 16:16:36 -03:00
|
|
|
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES and sslobj.version() != "TLSv1.3":
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertTrue(sslobj.get_channel_binding('tls-unique'))
|
|
|
|
try:
|
|
|
|
self.ssl_io_loop(sock, incoming, outgoing, sslobj.unwrap)
|
|
|
|
except ssl.SSLSyscallError:
|
|
|
|
# If the server shuts down the TCP connection without sending a
|
|
|
|
# secure shutdown message, this is reported as SSL_ERROR_SYSCALL
|
|
|
|
pass
|
|
|
|
self.assertRaises(ssl.SSLError, sslobj.write, b'foo')
|
|
|
|
|
|
|
|
def test_bio_read_write_data(self):
|
|
|
|
sock = socket.socket(socket.AF_INET)
|
|
|
|
self.addCleanup(sock.close)
|
|
|
|
sock.connect(self.server_addr)
|
|
|
|
incoming = ssl.MemoryBIO()
|
|
|
|
outgoing = ssl.MemoryBIO()
|
2021-04-19 02:27:10 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
ctx.check_hostname = False
|
2016-03-26 22:53:46 -03:00
|
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
sslobj = ctx.wrap_bio(incoming, outgoing, False)
|
|
|
|
self.ssl_io_loop(sock, incoming, outgoing, sslobj.do_handshake)
|
|
|
|
req = b'FOO\n'
|
|
|
|
self.ssl_io_loop(sock, incoming, outgoing, sslobj.write, req)
|
|
|
|
buf = self.ssl_io_loop(sock, incoming, outgoing, sslobj.read, 1024)
|
|
|
|
self.assertEqual(buf, b'foo\n')
|
|
|
|
self.ssl_io_loop(sock, incoming, outgoing, sslobj.unwrap)
|
|
|
|
|
GH-95494: Fix transport EOF handling in OpenSSL 3.0 (GH-95495)
GH-25309 enabled SSL_OP_IGNORE_UNEXPECTED_EOF by default, with a comment
that it restores OpenSSL 1.1.1 behavior, but this wasn't quite right.
That option causes OpenSSL to treat transport EOF as the same as
close_notify (i.e. SSL_ERROR_ZERO_RETURN), whereas Python actually has
distinct SSLEOFError and SSLZeroReturnError exceptions. (The latter is
usually mapped to a zero return from read.) In OpenSSL 1.1.1, the ssl
module would raise them for transport EOF and close_notify,
respectively. In OpenSSL 3.0, both act like close_notify.
Fix this by, instead, just detecting SSL_R_UNEXPECTED_EOF_WHILE_READING
and mapping that to the other exception type.
There doesn't seem to have been any unit test of this error, so fill in
the missing one. This had to be done with the BIO path because it's
actually slightly tricky to simulate a transport EOF with Python's fd
based APIs. (If you instruct the server to close the socket, it gets
confused, probably because the server's SSL object is still referencing
the now dead fd?)
2023-03-22 09:16:26 -03:00
|
|
|
def test_transport_eof(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
with socket.socket(socket.AF_INET) as sock:
|
|
|
|
sock.connect(self.server_addr)
|
|
|
|
incoming = ssl.MemoryBIO()
|
|
|
|
outgoing = ssl.MemoryBIO()
|
|
|
|
sslobj = client_context.wrap_bio(incoming, outgoing,
|
|
|
|
server_hostname=hostname)
|
|
|
|
self.ssl_io_loop(sock, incoming, outgoing, sslobj.do_handshake)
|
|
|
|
|
|
|
|
# Simulate EOF from the transport.
|
|
|
|
incoming.write_eof()
|
|
|
|
self.assertRaises(ssl.SSLEOFError, sslobj.read)
|
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
|
2021-09-19 09:27:33 -03:00
|
|
|
@support.requires_resource('network')
|
2016-03-26 22:53:46 -03:00
|
|
|
class NetworkedTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_timeout_connect_ex(self):
|
|
|
|
# Issue #12065: on a timeout, connect_ex() should return the original
|
|
|
|
# errno (mimicking the behaviour of non-SSL sockets).
|
2020-04-29 04:36:20 -03:00
|
|
|
with socket_helper.transient_internet(REMOTE_HOST):
|
2016-09-10 18:23:33 -03:00
|
|
|
s = test_wrap_socket(socket.socket(socket.AF_INET),
|
2016-03-26 22:53:46 -03:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED,
|
|
|
|
do_handshake_on_connect=False)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
s.settimeout(0.0000001)
|
|
|
|
rc = s.connect_ex((REMOTE_HOST, 443))
|
|
|
|
if rc == 0:
|
|
|
|
self.skipTest("REMOTE_HOST responded too quickly")
|
2021-03-27 18:52:28 -03:00
|
|
|
elif rc == errno.ENETUNREACH:
|
|
|
|
self.skipTest("Network unreachable.")
|
2016-03-26 22:53:46 -03:00
|
|
|
self.assertIn(rc, (errno.EAGAIN, errno.EWOULDBLOCK))
|
|
|
|
|
2020-04-25 04:06:29 -03:00
|
|
|
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'Needs IPv6')
|
2023-09-05 11:56:30 -03:00
|
|
|
@support.requires_resource('walltime')
|
2016-03-26 22:53:46 -03:00
|
|
|
def test_get_server_certificate_ipv6(self):
|
2020-04-29 04:36:20 -03:00
|
|
|
with socket_helper.transient_internet('ipv6.google.com'):
|
2016-03-26 22:53:46 -03:00
|
|
|
_test_get_server_certificate(self, 'ipv6.google.com', 443)
|
|
|
|
_test_get_server_certificate_fail(self, 'ipv6.google.com', 443)
|
|
|
|
|
2014-10-05 15:41:53 -03:00
|
|
|
|
2016-03-26 22:53:46 -03:00
|
|
|
def _test_get_server_certificate(test, host, port, cert=None):
|
|
|
|
pem = ssl.get_server_certificate((host, port))
|
|
|
|
if not pem:
|
|
|
|
test.fail("No server certificate on %s:%s!" % (host, port))
|
|
|
|
|
|
|
|
pem = ssl.get_server_certificate((host, port), ca_certs=cert)
|
|
|
|
if not pem:
|
|
|
|
test.fail("No server certificate on %s:%s!" % (host, port))
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\nVerified certificate for %s:%s is\n%s\n" % (host, port ,pem))
|
|
|
|
|
|
|
|
def _test_get_server_certificate_fail(test, host, port):
|
2024-02-04 11:28:07 -04:00
|
|
|
with warnings_helper.check_no_resource_warning(test):
|
|
|
|
try:
|
|
|
|
pem = ssl.get_server_certificate((host, port), ca_certs=CERTFILE)
|
|
|
|
except ssl.SSLError as x:
|
|
|
|
#should fail
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("%s\n" % x)
|
|
|
|
else:
|
|
|
|
test.fail("Got server certificate %s for %s:%s!" % (pem, host, port))
|
2014-10-05 15:41:53 -03:00
|
|
|
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
from test.ssl_servers import make_https_server
|
2010-10-13 07:36:15 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
class ThreadedEchoServer(threading.Thread):
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
class ConnectionHandler(threading.Thread):
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
"""A mildly complicated class, because we want it to work both
|
|
|
|
with and without the SSL wrapper around the socket connection, so
|
|
|
|
that we can test the STARTTLS functionality."""
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __init__(self, server, connsock, addr):
|
|
|
|
self.server = server
|
|
|
|
self.running = False
|
|
|
|
self.sock = connsock
|
|
|
|
self.addr = addr
|
2019-09-01 06:12:52 -03:00
|
|
|
self.sock.setblocking(True)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.sslconn = None
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.daemon = True
|
|
|
|
|
|
|
|
def wrap_conn(self):
|
|
|
|
try:
|
|
|
|
self.sslconn = self.server.context.wrap_socket(
|
|
|
|
self.sock, server_side=True)
|
|
|
|
self.server.selected_alpn_protocols.append(self.sslconn.selected_alpn_protocol())
|
2019-05-15 19:38:55 -03:00
|
|
|
except (ConnectionResetError, BrokenPipeError, ConnectionAbortedError) as e:
|
2017-09-07 13:56:24 -03:00
|
|
|
# We treat ConnectionResetError as though it were an
|
|
|
|
# SSLError - OpenSSL on Ubuntu abruptly closes the
|
|
|
|
# connection when asked to use an unsupported protocol.
|
|
|
|
#
|
2018-05-23 17:24:45 -03:00
|
|
|
# BrokenPipeError is raised in TLS 1.3 mode, when OpenSSL
|
|
|
|
# tries to send session tickets after handshake.
|
|
|
|
# https://github.com/openssl/openssl/issues/6342
|
2019-05-15 19:38:55 -03:00
|
|
|
#
|
|
|
|
# ConnectionAbortedError is raised in TLS 1.3 mode, when OpenSSL
|
|
|
|
# tries to send session tickets after handshake when using WinSock.
|
2018-05-23 17:24:45 -03:00
|
|
|
self.server.conn_errors.append(str(e))
|
|
|
|
if self.server.chatty:
|
|
|
|
handle_error("\n server: bad connection attempt from " + repr(self.addr) + ":\n")
|
|
|
|
self.running = False
|
|
|
|
self.close()
|
|
|
|
return False
|
|
|
|
except (ssl.SSLError, OSError) as e:
|
2017-09-07 13:56:24 -03:00
|
|
|
# OSError may occur with wrong protocols, e.g. both
|
|
|
|
# sides use PROTOCOL_TLS_SERVER.
|
|
|
|
#
|
|
|
|
# XXX Various errors can have happened here, for example
|
|
|
|
# a mismatching protocol version, an invalid certificate,
|
|
|
|
# or a low-level bug. This should be made more discriminating.
|
|
|
|
#
|
|
|
|
# bpo-31323: Store the exception as string to prevent
|
|
|
|
# a reference leak: server -> conn_errors -> exception
|
|
|
|
# -> traceback -> self (ConnectionHandler) -> server
|
|
|
|
self.server.conn_errors.append(str(e))
|
|
|
|
if self.server.chatty:
|
|
|
|
handle_error("\n server: bad connection attempt from " + repr(self.addr) + ":\n")
|
2021-06-24 09:05:42 -03:00
|
|
|
|
|
|
|
# bpo-44229, bpo-43855, bpo-44237, and bpo-33450:
|
|
|
|
# Ignore spurious EPROTOTYPE returned by write() on macOS.
|
|
|
|
# See also http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
|
|
|
|
if e.errno != errno.EPROTOTYPE and sys.platform != "darwin":
|
|
|
|
self.running = False
|
|
|
|
self.close()
|
2017-09-07 13:56:24 -03:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self.server.shared_ciphers.append(self.sslconn.shared_ciphers())
|
|
|
|
if self.server.context.verify_mode == ssl.CERT_REQUIRED:
|
|
|
|
cert = self.sslconn.getpeercert()
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose and self.server.chatty:
|
2017-09-07 13:56:24 -03:00
|
|
|
sys.stdout.write(" client cert is " + pprint.pformat(cert) + "\n")
|
|
|
|
cert_binary = self.sslconn.getpeercert(True)
|
|
|
|
if support.verbose and self.server.chatty:
|
2021-04-24 04:17:54 -03:00
|
|
|
if cert_binary is None:
|
|
|
|
sys.stdout.write(" client did not provide a cert\n")
|
|
|
|
else:
|
|
|
|
sys.stdout.write(f" cert binary is {len(cert_binary)}b\n")
|
2017-09-07 13:56:24 -03:00
|
|
|
cipher = self.sslconn.cipher()
|
|
|
|
if support.verbose and self.server.chatty:
|
|
|
|
sys.stdout.write(" server: connection cipher is now " + str(cipher) + "\n")
|
|
|
|
return True
|
|
|
|
|
|
|
|
def read(self):
|
|
|
|
if self.sslconn:
|
|
|
|
return self.sslconn.read()
|
|
|
|
else:
|
|
|
|
return self.sock.recv(1024)
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def write(self, bytes):
|
|
|
|
if self.sslconn:
|
|
|
|
return self.sslconn.write(bytes)
|
|
|
|
else:
|
|
|
|
return self.sock.send(bytes)
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def close(self):
|
|
|
|
if self.sslconn:
|
|
|
|
self.sslconn.close()
|
|
|
|
else:
|
|
|
|
self.sock.close()
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def run(self):
|
|
|
|
self.running = True
|
|
|
|
if not self.server.starttls_server:
|
|
|
|
if not self.wrap_conn():
|
|
|
|
return
|
|
|
|
while self.running:
|
|
|
|
try:
|
|
|
|
msg = self.read()
|
|
|
|
stripped = msg.strip()
|
|
|
|
if not stripped:
|
|
|
|
# eof, so quit this handler
|
|
|
|
self.running = False
|
|
|
|
try:
|
2008-08-12 13:56:25 -03:00
|
|
|
self.sock = self.sslconn.unwrap()
|
2017-09-07 13:56:24 -03:00
|
|
|
except OSError:
|
|
|
|
# Many tests shut the TCP connection down
|
|
|
|
# without an SSL shutdown. This causes
|
|
|
|
# unwrap() to raise OSError with errno=0!
|
|
|
|
pass
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
else:
|
2017-09-07 13:56:24 -03:00
|
|
|
self.sslconn = None
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
self.close()
|
2017-09-07 13:56:24 -03:00
|
|
|
elif stripped == b'over':
|
|
|
|
if support.verbose and self.server.connectionchatty:
|
|
|
|
sys.stdout.write(" server: client closed connection\n")
|
|
|
|
self.close()
|
|
|
|
return
|
|
|
|
elif (self.server.starttls_server and
|
|
|
|
stripped == b'STARTTLS'):
|
|
|
|
if support.verbose and self.server.connectionchatty:
|
|
|
|
sys.stdout.write(" server: read STARTTLS from client, sending OK...\n")
|
|
|
|
self.write(b"OK\n")
|
|
|
|
if not self.wrap_conn():
|
|
|
|
return
|
|
|
|
elif (self.server.starttls_server and self.sslconn
|
|
|
|
and stripped == b'ENDTLS'):
|
|
|
|
if support.verbose and self.server.connectionchatty:
|
|
|
|
sys.stdout.write(" server: read ENDTLS from client, sending OK...\n")
|
|
|
|
self.write(b"OK\n")
|
|
|
|
self.sock = self.sslconn.unwrap()
|
|
|
|
self.sslconn = None
|
|
|
|
if support.verbose and self.server.connectionchatty:
|
|
|
|
sys.stdout.write(" server: connection is now unencrypted...\n")
|
|
|
|
elif stripped == b'CB tls-unique':
|
|
|
|
if support.verbose and self.server.connectionchatty:
|
|
|
|
sys.stdout.write(" server: read CB tls-unique from client, sending our CB data...\n")
|
|
|
|
data = self.sslconn.get_channel_binding("tls-unique")
|
|
|
|
self.write(repr(data).encode("us-ascii") + b"\n")
|
2018-09-23 03:32:31 -03:00
|
|
|
elif stripped == b'PHA':
|
|
|
|
if support.verbose and self.server.connectionchatty:
|
|
|
|
sys.stdout.write(" server: initiating post handshake auth\n")
|
|
|
|
try:
|
|
|
|
self.sslconn.verify_client_post_handshake()
|
|
|
|
except ssl.SSLError as e:
|
|
|
|
self.write(repr(e).encode("us-ascii") + b"\n")
|
|
|
|
else:
|
|
|
|
self.write(b"OK\n")
|
|
|
|
elif stripped == b'HASCERT':
|
|
|
|
if self.sslconn.getpeercert() is not None:
|
|
|
|
self.write(b'TRUE\n')
|
|
|
|
else:
|
|
|
|
self.write(b'FALSE\n')
|
|
|
|
elif stripped == b'GETCERT':
|
|
|
|
cert = self.sslconn.getpeercert()
|
|
|
|
self.write(repr(cert).encode("us-ascii") + b"\n")
|
2021-04-26 10:01:40 -03:00
|
|
|
elif stripped == b'VERIFIEDCHAIN':
|
|
|
|
certs = self.sslconn._sslobj.get_verified_chain()
|
|
|
|
self.write(len(certs).to_bytes(1, "big") + b"\n")
|
|
|
|
elif stripped == b'UNVERIFIEDCHAIN':
|
|
|
|
certs = self.sslconn._sslobj.get_unverified_chain()
|
|
|
|
self.write(len(certs).to_bytes(1, "big") + b"\n")
|
2017-09-07 13:56:24 -03:00
|
|
|
else:
|
|
|
|
if (support.verbose and
|
|
|
|
self.server.connectionchatty):
|
|
|
|
ctype = (self.sslconn and "encrypted") or "unencrypted"
|
|
|
|
sys.stdout.write(" server: read %r (%s), sending back %r (%s)...\n"
|
|
|
|
% (msg, ctype, msg.lower(), ctype))
|
|
|
|
self.write(msg.lower())
|
2021-04-24 04:17:54 -03:00
|
|
|
except OSError as e:
|
|
|
|
# handles SSLError and socket errors
|
2024-03-26 04:45:43 -03:00
|
|
|
if isinstance(e, ConnectionError):
|
|
|
|
# OpenSSL 1.1.1 sometimes raises
|
|
|
|
# ConnectionResetError when connection is not
|
|
|
|
# shut down gracefully.
|
|
|
|
if self.server.chatty and support.verbose:
|
|
|
|
print(f" Connection reset by peer: {self.addr}")
|
|
|
|
|
|
|
|
self.close()
|
|
|
|
self.running = False
|
|
|
|
return
|
2018-05-23 17:24:45 -03:00
|
|
|
if self.server.chatty and support.verbose:
|
2024-03-26 04:45:43 -03:00
|
|
|
handle_error("Test server failure:\n")
|
2021-04-24 04:17:54 -03:00
|
|
|
try:
|
|
|
|
self.write(b"ERROR\n")
|
|
|
|
except OSError:
|
|
|
|
pass
|
2017-09-07 13:56:24 -03:00
|
|
|
self.close()
|
|
|
|
self.running = False
|
2018-05-23 17:24:45 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __init__(self, certificate=None, ssl_version=None,
|
|
|
|
certreqs=None, cacerts=None,
|
|
|
|
chatty=True, connectionchatty=False, starttls_server=False,
|
2021-04-19 02:27:10 -03:00
|
|
|
alpn_protocols=None,
|
2017-09-07 13:56:24 -03:00
|
|
|
ciphers=None, context=None):
|
|
|
|
if context:
|
|
|
|
self.context = context
|
|
|
|
else:
|
|
|
|
self.context = ssl.SSLContext(ssl_version
|
|
|
|
if ssl_version is not None
|
2017-09-15 15:27:30 -03:00
|
|
|
else ssl.PROTOCOL_TLS_SERVER)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.context.verify_mode = (certreqs if certreqs is not None
|
|
|
|
else ssl.CERT_NONE)
|
|
|
|
if cacerts:
|
|
|
|
self.context.load_verify_locations(cacerts)
|
|
|
|
if certificate:
|
|
|
|
self.context.load_cert_chain(certificate)
|
|
|
|
if alpn_protocols:
|
|
|
|
self.context.set_alpn_protocols(alpn_protocols)
|
|
|
|
if ciphers:
|
|
|
|
self.context.set_ciphers(ciphers)
|
|
|
|
self.chatty = chatty
|
|
|
|
self.connectionchatty = connectionchatty
|
|
|
|
self.starttls_server = starttls_server
|
|
|
|
self.sock = socket.socket()
|
2020-04-25 04:06:29 -03:00
|
|
|
self.port = socket_helper.bind_port(self.sock)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.flag = None
|
|
|
|
self.active = False
|
|
|
|
self.selected_alpn_protocols = []
|
|
|
|
self.shared_ciphers = []
|
|
|
|
self.conn_errors = []
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.daemon = True
|
2024-11-07 06:07:02 -04:00
|
|
|
self._in_context = False
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def __enter__(self):
|
2024-11-07 06:07:02 -04:00
|
|
|
if self._in_context:
|
|
|
|
raise ValueError('Re-entering ThreadedEchoServer context')
|
|
|
|
self._in_context = True
|
2017-09-07 13:56:24 -03:00
|
|
|
self.start(threading.Event())
|
|
|
|
self.flag.wait()
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
2024-11-07 06:07:02 -04:00
|
|
|
assert self._in_context
|
|
|
|
self._in_context = False
|
2017-09-07 13:56:24 -03:00
|
|
|
self.stop()
|
|
|
|
self.join()
|
|
|
|
|
|
|
|
def start(self, flag=None):
|
2024-11-07 06:07:02 -04:00
|
|
|
if not self._in_context:
|
|
|
|
raise ValueError(
|
|
|
|
'ThreadedEchoServer must be used as a context manager')
|
2017-09-07 13:56:24 -03:00
|
|
|
self.flag = flag
|
|
|
|
threading.Thread.start(self)
|
|
|
|
|
|
|
|
def run(self):
|
2024-11-07 06:07:02 -04:00
|
|
|
if not self._in_context:
|
|
|
|
raise ValueError(
|
|
|
|
'ThreadedEchoServer must be used as a context manager')
|
2021-05-03 12:45:02 -03:00
|
|
|
self.sock.settimeout(1.0)
|
|
|
|
self.sock.listen(5)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.active = True
|
|
|
|
if self.flag:
|
|
|
|
# signal an event
|
|
|
|
self.flag.set()
|
|
|
|
while self.active:
|
|
|
|
try:
|
|
|
|
newconn, connaddr = self.sock.accept()
|
|
|
|
if support.verbose and self.chatty:
|
|
|
|
sys.stdout.write(' server: new connection from '
|
|
|
|
+ repr(connaddr) + '\n')
|
|
|
|
handler = self.ConnectionHandler(self, newconn, connaddr)
|
|
|
|
handler.start()
|
|
|
|
handler.join()
|
2021-05-03 12:45:02 -03:00
|
|
|
except TimeoutError as e:
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(f' connection timeout {e!r}\n')
|
2017-09-07 13:56:24 -03:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
self.stop()
|
2018-05-23 17:24:45 -03:00
|
|
|
except BaseException as e:
|
|
|
|
if support.verbose and self.chatty:
|
|
|
|
sys.stdout.write(
|
|
|
|
' connection handling failed: ' + repr(e) + '\n')
|
|
|
|
|
2021-05-03 12:45:02 -03:00
|
|
|
self.close()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
if self.sock is not None:
|
|
|
|
self.sock.close()
|
|
|
|
self.sock = None
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def stop(self):
|
|
|
|
self.active = False
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
class AsyncoreEchoServer(threading.Thread):
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# this one's based on asyncore.dispatcher
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
class EchoServer (asyncore.dispatcher):
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
class ConnectionHandler(asyncore.dispatcher_with_send):
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __init__(self, conn, certfile):
|
|
|
|
self.socket = test_wrap_socket(conn, server_side=True,
|
|
|
|
certfile=certfile,
|
|
|
|
do_handshake_on_connect=False)
|
|
|
|
asyncore.dispatcher_with_send.__init__(self, self.socket)
|
|
|
|
self._ssl_accepting = True
|
|
|
|
self._do_ssl_handshake()
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def readable(self):
|
|
|
|
if isinstance(self.socket, ssl.SSLSocket):
|
|
|
|
while self.socket.pending() > 0:
|
|
|
|
self.handle_read_event()
|
|
|
|
return True
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def _do_ssl_handshake(self):
|
|
|
|
try:
|
|
|
|
self.socket.do_handshake()
|
|
|
|
except (ssl.SSLWantReadError, ssl.SSLWantWriteError):
|
|
|
|
return
|
|
|
|
except ssl.SSLEOFError:
|
|
|
|
return self.handle_close()
|
|
|
|
except ssl.SSLError:
|
|
|
|
raise
|
|
|
|
except OSError as err:
|
|
|
|
if err.args[0] == errno.ECONNABORTED:
|
2011-10-27 18:56:55 -03:00
|
|
|
return self.handle_close()
|
2017-09-07 13:56:24 -03:00
|
|
|
else:
|
|
|
|
self._ssl_accepting = False
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def handle_read(self):
|
|
|
|
if self._ssl_accepting:
|
|
|
|
self._do_ssl_handshake()
|
|
|
|
else:
|
|
|
|
data = self.recv(1024)
|
2010-04-27 07:59:39 -03:00
|
|
|
if support.verbose:
|
2017-09-07 13:56:24 -03:00
|
|
|
sys.stdout.write(" server: read %s from client\n" % repr(data))
|
|
|
|
if not data:
|
|
|
|
self.close()
|
|
|
|
else:
|
|
|
|
self.send(data.lower())
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def handle_close(self):
|
|
|
|
self.close()
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
2017-09-07 13:56:24 -03:00
|
|
|
sys.stdout.write(" server: closed connection %s\n" % self.socket)
|
2007-12-14 18:08:56 -04:00
|
|
|
|
|
|
|
def handle_error(self):
|
|
|
|
raise
|
|
|
|
|
2008-04-10 17:54:35 -03:00
|
|
|
def __init__(self, certfile):
|
2017-09-07 13:56:24 -03:00
|
|
|
self.certfile = certfile
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
2020-04-25 04:06:29 -03:00
|
|
|
self.port = socket_helper.bind_port(sock, '')
|
2017-09-07 13:56:24 -03:00
|
|
|
asyncore.dispatcher.__init__(self, sock)
|
|
|
|
self.listen(5)
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def handle_accepted(self, sock_obj, addr):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" server: new connection from %s:%s\n" %addr)
|
|
|
|
self.ConnectionHandler(sock_obj, self.certfile)
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def handle_error(self):
|
|
|
|
raise
|
2011-12-21 11:52:40 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __init__(self, certfile):
|
|
|
|
self.flag = None
|
|
|
|
self.active = False
|
|
|
|
self.server = self.EchoServer(certfile)
|
|
|
|
self.port = self.server.port
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.daemon = True
|
2011-12-21 11:52:40 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __str__(self):
|
|
|
|
return "<%s %s>" % (self.__class__.__name__, self.server)
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __enter__(self):
|
|
|
|
self.start(threading.Event())
|
|
|
|
self.flag.wait()
|
|
|
|
return self
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def __exit__(self, *args):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" cleanup: stopping server.\n")
|
|
|
|
self.stop()
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" cleanup: joining server thread.\n")
|
|
|
|
self.join()
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" cleanup: successfully joined.\n")
|
|
|
|
# make sure that ConnectionHandler is removed from socket_map
|
|
|
|
asyncore.close_all(ignore_all=True)
|
|
|
|
|
|
|
|
def start (self, flag=None):
|
|
|
|
self.flag = flag
|
|
|
|
threading.Thread.start(self)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.active = True
|
|
|
|
if self.flag:
|
|
|
|
self.flag.set()
|
|
|
|
while self.active:
|
|
|
|
try:
|
|
|
|
asyncore.loop(1)
|
|
|
|
except:
|
|
|
|
pass
|
2007-12-14 18:08:56 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def stop(self):
|
|
|
|
self.active = False
|
|
|
|
self.server.close()
|
|
|
|
|
|
|
|
def server_params_test(client_context, server_context, indata=b"FOO\n",
|
|
|
|
chatty=True, connectionchatty=False, sni_name=None,
|
|
|
|
session=None):
|
|
|
|
"""
|
|
|
|
Launch a server, connect a client to it and try various reads
|
|
|
|
and writes.
|
|
|
|
"""
|
|
|
|
stats = {}
|
|
|
|
server = ThreadedEchoServer(context=server_context,
|
|
|
|
chatty=chatty,
|
|
|
|
connectionchatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=sni_name, session=session) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
for arg in [indata, bytearray(indata), memoryview(indata)]:
|
2009-11-25 14:55:32 -04:00
|
|
|
if connectionchatty:
|
|
|
|
if support.verbose:
|
2017-09-07 13:56:24 -03:00
|
|
|
sys.stdout.write(
|
|
|
|
" client: sending %r...\n" % indata)
|
|
|
|
s.write(arg)
|
|
|
|
outdata = s.read()
|
|
|
|
if connectionchatty:
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" client: read %r\n" % outdata)
|
|
|
|
if outdata != indata.lower():
|
|
|
|
raise AssertionError(
|
|
|
|
"bad data <<%r>> (%d) received; expected <<%r>> (%d)\n"
|
|
|
|
% (outdata[:20], len(outdata),
|
|
|
|
indata[:20].lower(), len(indata)))
|
|
|
|
s.write(b"over\n")
|
|
|
|
if connectionchatty:
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" client: closing connection.\n")
|
|
|
|
stats.update({
|
|
|
|
'compression': s.compression(),
|
|
|
|
'cipher': s.cipher(),
|
|
|
|
'peercert': s.getpeercert(),
|
|
|
|
'client_alpn_protocol': s.selected_alpn_protocol(),
|
|
|
|
'version': s.version(),
|
|
|
|
'session_reused': s.session_reused,
|
|
|
|
'session': s.session,
|
|
|
|
})
|
|
|
|
s.close()
|
|
|
|
stats['server_alpn_protocols'] = server.selected_alpn_protocols
|
|
|
|
stats['server_shared_ciphers'] = server.shared_ciphers
|
|
|
|
return stats
|
|
|
|
|
|
|
|
def try_protocol_combo(server_protocol, client_protocol, expect_success,
|
|
|
|
certsreqs=None, server_options=0, client_options=0):
|
|
|
|
"""
|
|
|
|
Try to SSL-connect using *client_protocol* to *server_protocol*.
|
|
|
|
If *expect_success* is true, assert that the connection succeeds,
|
|
|
|
if it's false, assert that the connection fails.
|
|
|
|
Also, if *expect_success* is a string, assert that it is the protocol
|
|
|
|
version actually used by the connection.
|
|
|
|
"""
|
|
|
|
if certsreqs is None:
|
|
|
|
certsreqs = ssl.CERT_NONE
|
|
|
|
certtype = {
|
|
|
|
ssl.CERT_NONE: "CERT_NONE",
|
|
|
|
ssl.CERT_OPTIONAL: "CERT_OPTIONAL",
|
|
|
|
ssl.CERT_REQUIRED: "CERT_REQUIRED",
|
|
|
|
}[certsreqs]
|
|
|
|
if support.verbose:
|
|
|
|
formatstr = (expect_success and " %s->%s %s\n") or " {%s->%s} %s\n"
|
|
|
|
sys.stdout.write(formatstr %
|
|
|
|
(ssl.get_protocol_name(client_protocol),
|
|
|
|
ssl.get_protocol_name(server_protocol),
|
|
|
|
certtype))
|
2021-04-19 02:27:10 -03:00
|
|
|
|
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
# ignore Deprecation warnings
|
|
|
|
client_context = ssl.SSLContext(client_protocol)
|
|
|
|
client_context.options |= client_options
|
|
|
|
server_context = ssl.SSLContext(server_protocol)
|
|
|
|
server_context.options |= server_options
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2019-02-19 13:06:03 -04:00
|
|
|
min_version = PROTOCOL_TO_TLS_VERSION.get(client_protocol, None)
|
|
|
|
if (min_version is not None
|
2021-04-19 02:27:10 -03:00
|
|
|
# SSLContext.minimum_version is only available on recent OpenSSL
|
|
|
|
# (setter added in OpenSSL 1.1.0, getter added in OpenSSL 1.1.1)
|
|
|
|
and hasattr(server_context, 'minimum_version')
|
|
|
|
and server_protocol == ssl.PROTOCOL_TLS
|
|
|
|
and server_context.minimum_version > min_version
|
|
|
|
):
|
2019-02-19 13:06:03 -04:00
|
|
|
# If OpenSSL configuration is strict and requires more recent TLS
|
|
|
|
# version, we have to change the minimum to test old TLS versions.
|
2021-04-19 02:27:10 -03:00
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
server_context.minimum_version = min_version
|
2019-02-19 13:06:03 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# NOTE: we must enable "ALL" ciphers on the client, otherwise an
|
|
|
|
# SSLv23 client will send an SSLv3 hello (rather than SSLv2)
|
|
|
|
# starting from OpenSSL 1.0.0 (see issue #8322).
|
2017-09-15 15:27:30 -03:00
|
|
|
if client_context.protocol == ssl.PROTOCOL_TLS:
|
2017-09-07 13:56:24 -03:00
|
|
|
client_context.set_ciphers("ALL")
|
|
|
|
|
2021-03-18 19:06:50 -03:00
|
|
|
seclevel_workaround(server_context, client_context)
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
for ctx in (client_context, server_context):
|
|
|
|
ctx.verify_mode = certsreqs
|
2018-01-20 10:16:30 -04:00
|
|
|
ctx.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
ctx.load_verify_locations(SIGNING_CA)
|
2017-09-07 13:56:24 -03:00
|
|
|
try:
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=False, connectionchatty=False)
|
|
|
|
# Protocol mismatch can result in either an SSLError, or a
|
|
|
|
# "Connection reset by peer" error.
|
|
|
|
except ssl.SSLError:
|
|
|
|
if expect_success:
|
|
|
|
raise
|
|
|
|
except OSError as e:
|
|
|
|
if expect_success or e.errno != errno.ECONNRESET:
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
if not expect_success:
|
|
|
|
raise AssertionError(
|
|
|
|
"Client protocol %s succeeded with server protocol %s!"
|
|
|
|
% (ssl.get_protocol_name(client_protocol),
|
|
|
|
ssl.get_protocol_name(server_protocol)))
|
|
|
|
elif (expect_success is not True
|
|
|
|
and expect_success != stats['version']):
|
|
|
|
raise AssertionError("version mismatch: expected %r, got %r"
|
|
|
|
% (expect_success, stats['version']))
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
class ThreadedTests(unittest.TestCase):
|
2016-09-11 19:01:11 -03:00
|
|
|
|
2023-09-05 11:56:30 -03:00
|
|
|
@support.requires_resource('walltime')
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_echo(self):
|
|
|
|
"""Basic test of an SSL client connecting to a server"""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
with self.subTest(client=ssl.PROTOCOL_TLS_CLIENT, server=ssl.PROTOCOL_TLS_SERVER):
|
|
|
|
server_params_test(client_context=client_context,
|
|
|
|
server_context=server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
2017-09-15 15:27:30 -03:00
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
client_context.check_hostname = False
|
|
|
|
with self.subTest(client=ssl.PROTOCOL_TLS_SERVER, server=ssl.PROTOCOL_TLS_CLIENT):
|
|
|
|
with self.assertRaises(ssl.SSLError) as e:
|
|
|
|
server_params_test(client_context=server_context,
|
|
|
|
server_context=client_context,
|
2016-09-11 19:01:11 -03:00
|
|
|
chatty=True, connectionchatty=True,
|
2017-09-15 15:27:30 -03:00
|
|
|
sni_name=hostname)
|
2021-06-11 04:15:48 -03:00
|
|
|
self.assertIn(
|
|
|
|
'Cannot create a client socket with a PROTOCOL_TLS_SERVER context',
|
|
|
|
str(e.exception)
|
|
|
|
)
|
2016-09-11 19:01:11 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
with self.subTest(client=ssl.PROTOCOL_TLS_SERVER, server=ssl.PROTOCOL_TLS_SERVER):
|
|
|
|
with self.assertRaises(ssl.SSLError) as e:
|
|
|
|
server_params_test(client_context=server_context,
|
|
|
|
server_context=server_context,
|
|
|
|
chatty=True, connectionchatty=True)
|
2021-06-11 04:15:48 -03:00
|
|
|
self.assertIn(
|
|
|
|
'Cannot create a client socket with a PROTOCOL_TLS_SERVER context',
|
|
|
|
str(e.exception)
|
|
|
|
)
|
2016-09-12 05:48:20 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
with self.subTest(client=ssl.PROTOCOL_TLS_CLIENT, server=ssl.PROTOCOL_TLS_CLIENT):
|
|
|
|
with self.assertRaises(ssl.SSLError) as e:
|
|
|
|
server_params_test(client_context=server_context,
|
|
|
|
server_context=client_context,
|
|
|
|
chatty=True, connectionchatty=True)
|
2021-06-11 04:15:48 -03:00
|
|
|
self.assertIn(
|
|
|
|
'Cannot create a client socket with a PROTOCOL_TLS_SERVER context',
|
|
|
|
str(e.exception))
|
2016-09-12 05:48:20 -03:00
|
|
|
|
2024-10-19 18:16:36 -03:00
|
|
|
@unittest.skipUnless(support.Py_GIL_DISABLED, "test is only useful if the GIL is disabled")
|
|
|
|
def test_ssl_in_multiple_threads(self):
|
|
|
|
# See GH-124984: OpenSSL is not thread safe.
|
|
|
|
threads = []
|
|
|
|
|
|
|
|
global USE_SAME_TEST_CONTEXT
|
|
|
|
USE_SAME_TEST_CONTEXT = True
|
|
|
|
try:
|
|
|
|
for func in (
|
|
|
|
self.test_echo,
|
|
|
|
self.test_alpn_protocols,
|
|
|
|
self.test_getpeercert,
|
|
|
|
self.test_crl_check,
|
|
|
|
self.test_check_hostname_idn,
|
|
|
|
self.test_wrong_cert_tls12,
|
|
|
|
self.test_wrong_cert_tls13,
|
|
|
|
):
|
|
|
|
# Be careful with the number of threads here.
|
|
|
|
# Too many can result in failing tests.
|
|
|
|
for num in range(5):
|
|
|
|
with self.subTest(func=func, num=num):
|
|
|
|
threads.append(Thread(target=func))
|
|
|
|
|
|
|
|
with threading_helper.catch_threading_exception() as cm:
|
|
|
|
for thread in threads:
|
|
|
|
with self.subTest(thread=thread):
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
for thread in threads:
|
|
|
|
with self.subTest(thread=thread):
|
|
|
|
thread.join()
|
|
|
|
if cm.exc_value is not None:
|
|
|
|
# Some threads can skip their test
|
|
|
|
if not isinstance(cm.exc_value, unittest.SkipTest):
|
|
|
|
raise cm.exc_value
|
|
|
|
finally:
|
|
|
|
USE_SAME_TEST_CONTEXT = False
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_getpeercert(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
2017-09-15 15:27:30 -03:00
|
|
|
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
2017-09-07 13:56:24 -03:00
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
do_handshake_on_connect=False,
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
# getpeercert() raise ValueError while the handshake isn't
|
|
|
|
# done.
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
s.getpeercert()
|
|
|
|
s.do_handshake()
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
|
|
|
cipher = s.cipher()
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(pprint.pformat(cert) + '\n')
|
|
|
|
sys.stdout.write("Connection cipher is " + str(cipher) + '.\n')
|
|
|
|
if 'subject' not in cert:
|
|
|
|
self.fail("No subject field in certificate: %s." %
|
|
|
|
pprint.pformat(cert))
|
|
|
|
if ((('organizationName', 'Python Software Foundation'),)
|
|
|
|
not in cert['subject']):
|
|
|
|
self.fail(
|
|
|
|
"Missing or invalid 'organizationName' field in certificate subject; "
|
|
|
|
"should be 'Python Software Foundation'.")
|
|
|
|
self.assertIn('notBefore', cert)
|
|
|
|
self.assertIn('notAfter', cert)
|
|
|
|
before = ssl.cert_time_to_seconds(cert['notBefore'])
|
|
|
|
after = ssl.cert_time_to_seconds(cert['notAfter'])
|
|
|
|
self.assertLess(before, after)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def test_crl_check(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
tf = getattr(ssl, "VERIFY_X509_TRUSTED_FIRST", 0)
|
2017-09-15 15:27:30 -03:00
|
|
|
self.assertEqual(client_context.verify_flags, ssl.VERIFY_DEFAULT | tf)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# VERIFY_DEFAULT should pass
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2010-04-27 07:59:39 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# VERIFY_CRL_CHECK_LEAF without a loaded CRL file fails
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context.verify_flags |= ssl.VERIFY_CRL_CHECK_LEAF
|
2013-11-21 18:56:13 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = re.compile(r"""(
|
|
|
|
certificate verify failed # OpenSSL
|
|
|
|
|
|
|
|
|
CERTIFICATE_VERIFY_FAILED # AWS-LC
|
|
|
|
)""", re.X)
|
2017-09-07 13:56:24 -03:00
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.SSLError, regex):
|
2013-11-21 18:56:13 -04:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# now load a CRL file. The CRL file is signed by the CA.
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context.load_verify_locations(CRLFILE)
|
2013-11-21 18:56:13 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
2013-11-21 18:56:13 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_check_hostname(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
2013-11-21 18:56:13 -04:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2013-12-01 21:41:19 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# correct hostname should verify
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
|
|
|
|
|
|
|
# incorrect hostname should raise an exception
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = re.compile(r"""(
|
|
|
|
certificate verify failed # OpenSSL
|
|
|
|
|
|
|
|
|
CERTIFICATE_VERIFY_FAILED # AWS-LC
|
|
|
|
)""", re.X)
|
2017-09-07 13:56:24 -03:00
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname="invalid") as s:
|
2024-03-21 16:16:36 -03:00
|
|
|
with self.assertRaisesRegex(ssl.CertificateError, regex):
|
2013-12-01 21:41:19 -04:00
|
|
|
s.connect((HOST, server.port))
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# missing server_hostname arg should cause an exception, too
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with socket.socket() as s:
|
|
|
|
with self.assertRaisesRegex(ValueError,
|
|
|
|
"check_hostname requires server_hostname"):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context.wrap_socket(s)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2021-04-17 05:07:19 -03:00
|
|
|
@unittest.skipUnless(
|
|
|
|
ssl.HAS_NEVER_CHECK_COMMON_NAME, "test requires hostname_checks_common_name"
|
|
|
|
)
|
|
|
|
def test_hostname_checks_common_name(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
assert client_context.hostname_checks_common_name
|
|
|
|
client_context.hostname_checks_common_name = False
|
|
|
|
|
|
|
|
# default cert has a SAN
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
|
|
|
client_context, server_context, hostname = testing_context(NOSANFILE)
|
|
|
|
client_context.hostname_checks_common_name = False
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
with self.assertRaises(ssl.SSLCertVerificationError):
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
2018-01-20 10:16:30 -04:00
|
|
|
def test_ecc_cert(self):
|
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
client_context.load_verify_locations(SIGNING_CA)
|
2018-05-22 17:50:12 -03:00
|
|
|
client_context.set_ciphers('ECDHE:ECDSA:!NULL:!aRSA')
|
2018-01-20 10:16:30 -04:00
|
|
|
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
# load ECC cert
|
|
|
|
server_context.load_cert_chain(SIGNED_CERTFILE_ECC)
|
|
|
|
|
|
|
|
# correct hostname should verify
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
|
|
|
cipher = s.cipher()[0].split('-')
|
|
|
|
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
|
|
|
|
|
2024-03-06 17:44:58 -04:00
|
|
|
@unittest.skipUnless(IS_OPENSSL_3_0_0,
|
|
|
|
"test requires RFC 5280 check added in OpenSSL 3.0+")
|
|
|
|
def test_verify_strict(self):
|
|
|
|
# verification fails by default, since the server cert is non-conforming
|
|
|
|
client_context = ssl.create_default_context()
|
|
|
|
client_context.load_verify_locations(LEAF_MISSING_AKI_CA)
|
|
|
|
hostname = LEAF_MISSING_AKI_CERTFILE_HOSTNAME
|
|
|
|
|
|
|
|
server_context = ssl.create_default_context(purpose=Purpose.CLIENT_AUTH)
|
|
|
|
server_context.load_cert_chain(LEAF_MISSING_AKI_CERTFILE)
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
with self.assertRaises(ssl.SSLError):
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
|
|
|
# explicitly disabling VERIFY_X509_STRICT allows it to succeed
|
|
|
|
client_context = ssl.create_default_context()
|
|
|
|
client_context.load_verify_locations(LEAF_MISSING_AKI_CA)
|
|
|
|
client_context.verify_flags &= ~ssl.VERIFY_X509_STRICT
|
|
|
|
|
|
|
|
server_context = ssl.create_default_context(purpose=Purpose.CLIENT_AUTH)
|
|
|
|
server_context.load_cert_chain(LEAF_MISSING_AKI_CERTFILE)
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
|
|
|
|
2018-01-20 10:16:30 -04:00
|
|
|
def test_dual_rsa_ecc(self):
|
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
client_context.load_verify_locations(SIGNING_CA)
|
2018-02-27 03:55:39 -04:00
|
|
|
# TODO: fix TLSv1.3 once SSLContext can restrict signature
|
|
|
|
# algorithms.
|
2021-06-13 08:46:07 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2018-01-20 10:16:30 -04:00
|
|
|
# only ECDSA certs
|
|
|
|
client_context.set_ciphers('ECDHE:ECDSA:!NULL:!aRSA')
|
|
|
|
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
# load ECC and RSA key/cert pairs
|
|
|
|
server_context.load_cert_chain(SIGNED_CERTFILE_ECC)
|
|
|
|
server_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
# correct hostname should verify
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
|
|
|
cipher = s.cipher()[0].split('-')
|
|
|
|
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
|
|
|
|
|
2018-01-29 09:25:13 -04:00
|
|
|
def test_check_hostname_idn(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
2018-02-23 21:35:08 -04:00
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2018-01-29 09:25:13 -04:00
|
|
|
server_context.load_cert_chain(IDNSANSFILE)
|
|
|
|
|
2018-02-23 21:35:08 -04:00
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2018-01-29 09:25:13 -04:00
|
|
|
context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
context.check_hostname = True
|
|
|
|
context.load_verify_locations(SIGNING_CA)
|
|
|
|
|
|
|
|
# correct hostname should verify, when specified in several
|
|
|
|
# different ways
|
|
|
|
idn_hostnames = [
|
|
|
|
('könig.idn.pythontest.net',
|
2018-02-23 21:35:08 -04:00
|
|
|
'xn--knig-5qa.idn.pythontest.net'),
|
2018-01-29 09:25:13 -04:00
|
|
|
('xn--knig-5qa.idn.pythontest.net',
|
|
|
|
'xn--knig-5qa.idn.pythontest.net'),
|
|
|
|
(b'xn--knig-5qa.idn.pythontest.net',
|
2018-02-23 21:35:08 -04:00
|
|
|
'xn--knig-5qa.idn.pythontest.net'),
|
2018-01-29 09:25:13 -04:00
|
|
|
|
|
|
|
('königsgäßchen.idna2003.pythontest.net',
|
2018-02-23 21:35:08 -04:00
|
|
|
'xn--knigsgsschen-lcb0w.idna2003.pythontest.net'),
|
2018-01-29 09:25:13 -04:00
|
|
|
('xn--knigsgsschen-lcb0w.idna2003.pythontest.net',
|
|
|
|
'xn--knigsgsschen-lcb0w.idna2003.pythontest.net'),
|
|
|
|
(b'xn--knigsgsschen-lcb0w.idna2003.pythontest.net',
|
2018-02-23 21:35:08 -04:00
|
|
|
'xn--knigsgsschen-lcb0w.idna2003.pythontest.net'),
|
|
|
|
|
|
|
|
# ('königsgäßchen.idna2008.pythontest.net',
|
|
|
|
# 'xn--knigsgchen-b4a3dun.idna2008.pythontest.net'),
|
|
|
|
('xn--knigsgchen-b4a3dun.idna2008.pythontest.net',
|
|
|
|
'xn--knigsgchen-b4a3dun.idna2008.pythontest.net'),
|
|
|
|
(b'xn--knigsgchen-b4a3dun.idna2008.pythontest.net',
|
|
|
|
'xn--knigsgchen-b4a3dun.idna2008.pythontest.net'),
|
|
|
|
|
2018-01-29 09:25:13 -04:00
|
|
|
]
|
|
|
|
for server_hostname, expected_hostname in idn_hostnames:
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=server_hostname) as s:
|
|
|
|
self.assertEqual(s.server_hostname, expected_hostname)
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
cert = s.getpeercert()
|
|
|
|
self.assertEqual(s.server_hostname, expected_hostname)
|
|
|
|
self.assertTrue(cert, "Can't get peer certificate.")
|
|
|
|
|
|
|
|
# incorrect hostname should raise an exception
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname="python.example.org") as s:
|
|
|
|
with self.assertRaises(ssl.CertificateError):
|
|
|
|
s.connect((HOST, server.port))
|
2024-02-04 11:28:07 -04:00
|
|
|
with ThreadedEchoServer(context=server_context, chatty=True) as server:
|
|
|
|
with warnings_helper.check_no_resource_warning(self):
|
|
|
|
with self.assertRaises(UnicodeError):
|
|
|
|
context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname='.pythontest.net')
|
|
|
|
with ThreadedEchoServer(context=server_context, chatty=True) as server:
|
|
|
|
with warnings_helper.check_no_resource_warning(self):
|
|
|
|
with self.assertRaises(UnicodeDecodeError):
|
|
|
|
context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=b'k\xf6nig.idn.pythontest.net')
|
2018-01-29 09:25:13 -04:00
|
|
|
|
2018-05-23 17:24:45 -03:00
|
|
|
def test_wrong_cert_tls12(self):
|
2017-09-07 13:56:24 -03:00
|
|
|
"""Connecting when the server rejects the client's certificate
|
|
|
|
|
|
|
|
Launch a server with CERT_REQUIRED, and check that trying to
|
|
|
|
connect to it with a wrong client certificate fails.
|
|
|
|
"""
|
2018-02-27 03:55:39 -04:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-08-14 07:54:19 -03:00
|
|
|
# load client cert that is not signed by trusted CA
|
|
|
|
client_context.load_cert_chain(CERTFILE)
|
2018-02-27 03:55:39 -04:00
|
|
|
# require TLS client authentication
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
2018-05-23 17:24:45 -03:00
|
|
|
# TLS 1.3 has different handshake
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2018-02-27 03:55:39 -04:00
|
|
|
|
|
|
|
server = ThreadedEchoServer(
|
|
|
|
context=server_context, chatty=True, connectionchatty=True,
|
|
|
|
)
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
with server, \
|
2018-02-27 03:55:39 -04:00
|
|
|
client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
try:
|
|
|
|
# Expect either an SSL error about the server rejecting
|
|
|
|
# the connection, or a low-level connection reset (which
|
|
|
|
# sometimes happens on Windows)
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
except ssl.SSLError as e:
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\nSSLError is %r\n" % e)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ECONNRESET:
|
|
|
|
raise
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\nsocket.error is %r\n" % e)
|
|
|
|
else:
|
|
|
|
self.fail("Use of invalid cert should have failed!")
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_3')
|
2018-05-23 17:24:45 -03:00
|
|
|
def test_wrong_cert_tls13(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-08-14 07:54:19 -03:00
|
|
|
# load client cert that is not signed by trusted CA
|
|
|
|
client_context.load_cert_chain(CERTFILE)
|
2018-05-23 17:24:45 -03:00
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
|
|
client_context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(
|
|
|
|
context=server_context, chatty=True, connectionchatty=True,
|
|
|
|
)
|
|
|
|
with server, \
|
|
|
|
client_context.wrap_socket(socket.socket(),
|
2021-06-03 13:04:25 -03:00
|
|
|
server_hostname=hostname,
|
|
|
|
suppress_ragged_eofs=False) as s:
|
2018-05-23 17:24:45 -03:00
|
|
|
s.connect((HOST, server.port))
|
2021-06-03 17:12:31 -03:00
|
|
|
with self.assertRaisesRegex(
|
2024-03-26 04:45:43 -03:00
|
|
|
OSError,
|
2024-04-03 09:29:02 -03:00
|
|
|
'alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA|'
|
|
|
|
'closed by the remote host|Connection reset by peer|'
|
|
|
|
'Broken pipe'
|
2021-06-03 17:12:31 -03:00
|
|
|
):
|
|
|
|
# TLS 1.3 perform client cert exchange after handshake
|
2018-05-23 17:24:45 -03:00
|
|
|
s.write(b'data')
|
2021-04-23 15:03:25 -03:00
|
|
|
s.read(1000)
|
|
|
|
s.write(b'should have failed already')
|
|
|
|
s.read(1000)
|
2018-05-23 17:24:45 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_rude_shutdown(self):
|
|
|
|
"""A brutal shutdown of an SSL server should raise an OSError
|
|
|
|
in the client when attempting handshake.
|
|
|
|
"""
|
|
|
|
listener_ready = threading.Event()
|
|
|
|
listener_gone = threading.Event()
|
|
|
|
|
|
|
|
s = socket.socket()
|
2020-04-25 04:06:29 -03:00
|
|
|
port = socket_helper.bind_port(s, HOST)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# `listener` runs in a thread. It sits in an accept() until
|
|
|
|
# the main thread connects. Then it rudely closes the socket,
|
|
|
|
# and sets Event `listener_gone` to let the main thread know
|
|
|
|
# the socket is gone.
|
|
|
|
def listener():
|
|
|
|
s.listen()
|
|
|
|
listener_ready.set()
|
|
|
|
newsock, addr = s.accept()
|
|
|
|
newsock.close()
|
|
|
|
s.close()
|
|
|
|
listener_gone.set()
|
|
|
|
|
|
|
|
def connector():
|
|
|
|
listener_ready.wait()
|
|
|
|
with socket.socket() as c:
|
|
|
|
c.connect((HOST, port))
|
|
|
|
listener_gone.wait()
|
2016-02-01 17:58:11 -04:00
|
|
|
try:
|
2017-09-07 13:56:24 -03:00
|
|
|
ssl_sock = test_wrap_socket(c)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2016-02-01 17:58:11 -04:00
|
|
|
else:
|
2017-09-07 13:56:24 -03:00
|
|
|
self.fail('connecting to closed SSL socket should have failed')
|
2010-04-28 18:37:09 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
t = threading.Thread(target=listener)
|
|
|
|
t.start()
|
|
|
|
try:
|
|
|
|
connector()
|
|
|
|
finally:
|
|
|
|
t.join()
|
2010-04-28 18:37:09 -03:00
|
|
|
|
2017-09-08 16:00:19 -03:00
|
|
|
def test_ssl_cert_verify_error(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
server_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with context.wrap_socket(socket.socket(),
|
2017-09-15 15:27:30 -03:00
|
|
|
server_hostname=SIGNED_CERTFILE_HOSTNAME) as s:
|
2017-09-08 16:00:19 -03:00
|
|
|
try:
|
|
|
|
s.connect((HOST, server.port))
|
2024-03-21 16:16:36 -03:00
|
|
|
self.fail("Expected connection failure")
|
2017-09-08 16:00:19 -03:00
|
|
|
except ssl.SSLError as e:
|
|
|
|
msg = 'unable to get local issuer certificate'
|
|
|
|
self.assertIsInstance(e, ssl.SSLCertVerificationError)
|
|
|
|
self.assertEqual(e.verify_code, 20)
|
|
|
|
self.assertEqual(e.verify_message, msg)
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = f"({msg}|CERTIFICATE_VERIFY_FAILED)"
|
|
|
|
self.assertRegex(repr(e), regex)
|
|
|
|
regex = re.compile(r"""(
|
|
|
|
certificate verify failed # OpenSSL
|
|
|
|
|
|
|
|
|
CERTIFICATE_VERIFY_FAILED # AWS-LC
|
|
|
|
)""", re.X)
|
|
|
|
self.assertRegex(repr(e), regex)
|
2017-09-08 16:00:19 -03:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
def test_PROTOCOL_TLS(self):
|
2017-09-07 13:56:24 -03:00
|
|
|
"""Connecting to an SSLv23 server with various client options"""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_SSLv3, False)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS, True)
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('TLSv1'):
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1, 'TLSv1')
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_SSLv3, False, ssl.CERT_OPTIONAL)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS, True, ssl.CERT_OPTIONAL)
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('TLSv1'):
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1, 'TLSv1', ssl.CERT_OPTIONAL)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_SSLv3, False, ssl.CERT_REQUIRED)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS, True, ssl.CERT_REQUIRED)
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('TLSv1'):
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1, 'TLSv1', ssl.CERT_REQUIRED)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# Server with specific SSL options
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_SSLv3, False,
|
2017-09-07 13:56:24 -03:00
|
|
|
server_options=ssl.OP_NO_SSLv3)
|
|
|
|
# Will choose TLSv1
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS, True,
|
2017-09-07 13:56:24 -03:00
|
|
|
server_options=ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3)
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('TLSv1'):
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1, False,
|
|
|
|
server_options=ssl.OP_NO_TLSv1)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('SSLv3')
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_protocol_sslv3(self):
|
|
|
|
"""Connecting to an SSLv3 server with various client options"""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, 'SSLv3')
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, 'SSLv3', ssl.CERT_OPTIONAL)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, 'SSLv3', ssl.CERT_REQUIRED)
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLS, False,
|
2017-09-07 13:56:24 -03:00
|
|
|
client_options=ssl.OP_NO_SSLv3)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLSv1, False)
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1')
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_protocol_tlsv1(self):
|
|
|
|
"""Connecting to a TLSv1 server with various client options"""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, 'TLSv1')
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, 'TLSv1', ssl.CERT_OPTIONAL)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, 'TLSv1', ssl.CERT_REQUIRED)
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-07 13:56:24 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv3, False)
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLS, False,
|
2017-09-07 13:56:24 -03:00
|
|
|
client_options=ssl.OP_NO_TLSv1)
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_1')
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_protocol_tlsv1_1(self):
|
|
|
|
"""Connecting to a TLSv1.1 server with various client options.
|
|
|
|
Testing against older TLS versions."""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_1, 'TLSv1.1')
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-07 13:56:24 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_SSLv3, False)
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLS, False,
|
2017-09-07 13:56:24 -03:00
|
|
|
client_options=ssl.OP_NO_TLSv1_1)
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1_1, 'TLSv1.1')
|
2019-09-26 12:02:59 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
|
2008-04-10 17:12:06 -03:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_2')
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_protocol_tlsv1_2(self):
|
|
|
|
"""Connecting to a TLSv1.2 server with various client options.
|
|
|
|
Testing against older TLS versions."""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_2, 'TLSv1.2',
|
|
|
|
server_options=ssl.OP_NO_SSLv3|ssl.OP_NO_SSLv2,
|
|
|
|
client_options=ssl.OP_NO_SSLv3|ssl.OP_NO_SSLv2,)
|
2019-09-26 12:02:59 -03:00
|
|
|
if has_tls_version('SSLv3'):
|
2017-09-07 13:56:24 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_SSLv3, False)
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLS, False,
|
2017-09-07 13:56:24 -03:00
|
|
|
client_options=ssl.OP_NO_TLSv1_2)
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1_2, 'TLSv1.2')
|
2022-06-28 04:33:06 -03:00
|
|
|
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
|
|
|
|
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
|
|
|
|
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def test_starttls(self):
|
|
|
|
"""Switching from clear text to encrypted and back again."""
|
|
|
|
msgs = (b"msg 1", b"MSG 2", b"STARTTLS", b"MSG 3", b"msg 4", b"ENDTLS", b"msg 5", b"msg 6")
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(CERTFILE,
|
|
|
|
starttls_server=True,
|
|
|
|
chatty=True,
|
|
|
|
connectionchatty=True)
|
|
|
|
wrapped = False
|
|
|
|
with server:
|
|
|
|
s = socket.socket()
|
2019-09-01 06:12:52 -03:00
|
|
|
s.setblocking(True)
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
sys.stdout.write("\n")
|
2017-09-07 13:56:24 -03:00
|
|
|
for indata in msgs:
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(
|
|
|
|
" client: sending %r...\n" % indata)
|
|
|
|
if wrapped:
|
|
|
|
conn.write(indata)
|
|
|
|
outdata = conn.read()
|
|
|
|
else:
|
|
|
|
s.send(indata)
|
|
|
|
outdata = s.recv(1024)
|
|
|
|
msg = outdata.strip().lower()
|
|
|
|
if indata == b"STARTTLS" and msg.startswith(b"ok"):
|
|
|
|
# STARTTLS ok, switch to secure mode
|
2011-05-08 19:42:58 -03:00
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(
|
2017-09-07 13:56:24 -03:00
|
|
|
" client: read %r from server, starting TLS...\n"
|
|
|
|
% msg)
|
2017-09-15 15:27:30 -03:00
|
|
|
conn = test_wrap_socket(s)
|
2017-09-07 13:56:24 -03:00
|
|
|
wrapped = True
|
|
|
|
elif indata == b"ENDTLS" and msg.startswith(b"ok"):
|
|
|
|
# ENDTLS ok, switch back to clear text
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
2010-04-27 07:59:39 -03:00
|
|
|
sys.stdout.write(
|
2017-09-07 13:56:24 -03:00
|
|
|
" client: read %r from server, ending TLS...\n"
|
|
|
|
% msg)
|
|
|
|
s = conn.unwrap()
|
|
|
|
wrapped = False
|
2010-04-27 07:59:39 -03:00
|
|
|
else:
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
sys.stdout.write(
|
2017-09-07 13:56:24 -03:00
|
|
|
" client: read %r from server\n" % msg)
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
2017-09-07 13:56:24 -03:00
|
|
|
sys.stdout.write(" client: closing connection.\n")
|
|
|
|
if wrapped:
|
|
|
|
conn.write(b"over\n")
|
|
|
|
else:
|
|
|
|
s.send(b"over\n")
|
|
|
|
if wrapped:
|
|
|
|
conn.close()
|
|
|
|
else:
|
|
|
|
s.close()
|
2008-04-10 17:12:06 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_socketserver(self):
|
|
|
|
"""Using socketserver to create and manage SSL connections."""
|
2018-01-20 10:16:30 -04:00
|
|
|
server = make_https_server(self, certfile=SIGNED_CERTFILE)
|
2017-09-07 13:56:24 -03:00
|
|
|
# try to connect
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write('\n')
|
2023-09-16 13:47:18 -03:00
|
|
|
# Get this test file itself:
|
|
|
|
with open(__file__, 'rb') as f:
|
2017-09-07 13:56:24 -03:00
|
|
|
d1 = f.read()
|
|
|
|
d2 = ''
|
|
|
|
# now fetch the same data from the HTTPS server
|
2023-09-16 13:47:18 -03:00
|
|
|
url = f'https://localhost:{server.port}/test_ssl.py'
|
2018-01-20 10:16:30 -04:00
|
|
|
context = ssl.create_default_context(cafile=SIGNING_CA)
|
2017-09-07 13:56:24 -03:00
|
|
|
f = urllib.request.urlopen(url, context=context)
|
|
|
|
try:
|
|
|
|
dlen = f.info().get("content-length")
|
|
|
|
if dlen and (int(dlen) > 0):
|
|
|
|
d2 = f.read(int(dlen))
|
2008-05-20 18:35:26 -03:00
|
|
|
if support.verbose:
|
2008-04-10 17:12:06 -03:00
|
|
|
sys.stdout.write(
|
2017-09-07 13:56:24 -03:00
|
|
|
" client: read %d bytes from remote server '%s'\n"
|
|
|
|
% (len(d2), server))
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
self.assertEqual(d1, d2)
|
2008-04-10 17:12:06 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_asyncore_server(self):
|
|
|
|
"""Check the example asyncore integration."""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
|
|
|
indata = b"FOO\n"
|
|
|
|
server = AsyncoreEchoServer(CERTFILE)
|
|
|
|
with server:
|
|
|
|
s = test_wrap_socket(socket.socket())
|
|
|
|
s.connect(('127.0.0.1', server.port))
|
2008-09-08 13:45:19 -03:00
|
|
|
if support.verbose:
|
2017-09-07 13:56:24 -03:00
|
|
|
sys.stdout.write(
|
|
|
|
" client: sending %r...\n" % indata)
|
|
|
|
s.write(indata)
|
|
|
|
outdata = s.read()
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" client: read %r\n" % outdata)
|
|
|
|
if outdata != indata.lower():
|
|
|
|
self.fail(
|
|
|
|
"bad data <<%r>> (%d) received; expected <<%r>> (%d)\n"
|
|
|
|
% (outdata[:20], len(outdata),
|
|
|
|
indata[:20].lower(), len(indata)))
|
|
|
|
s.write(b"over\n")
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" client: closing connection.\n")
|
|
|
|
s.close()
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" client: connection closed.\n")
|
2008-09-08 13:45:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_recv_send(self):
|
|
|
|
"""Test recv(), send() and friends."""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(CERTFILE,
|
|
|
|
certreqs=ssl.CERT_NONE,
|
2017-09-15 15:27:30 -03:00
|
|
|
ssl_version=ssl.PROTOCOL_TLS_SERVER,
|
2017-09-07 13:56:24 -03:00
|
|
|
cacerts=CERTFILE,
|
|
|
|
chatty=True,
|
|
|
|
connectionchatty=False)
|
|
|
|
with server:
|
|
|
|
s = test_wrap_socket(socket.socket(),
|
|
|
|
server_side=False,
|
|
|
|
certfile=CERTFILE,
|
|
|
|
ca_certs=CERTFILE,
|
2021-04-19 02:27:10 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE)
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
# helper methods for standardising recv* method signatures
|
|
|
|
def _recv_into():
|
|
|
|
b = bytearray(b"\0"*100)
|
|
|
|
count = s.recv_into(b)
|
|
|
|
return b[:count]
|
|
|
|
|
|
|
|
def _recvfrom_into():
|
|
|
|
b = bytearray(b"\0"*100)
|
|
|
|
count, addr = s.recvfrom_into(b)
|
|
|
|
return b[:count]
|
|
|
|
|
|
|
|
# (name, method, expect success?, *args, return value func)
|
|
|
|
send_methods = [
|
|
|
|
('send', s.send, True, [], len),
|
|
|
|
('sendto', s.sendto, False, ["some.address"], len),
|
|
|
|
('sendall', s.sendall, True, [], lambda x: None),
|
|
|
|
]
|
|
|
|
# (name, method, whether to expect success, *args)
|
|
|
|
recv_methods = [
|
|
|
|
('recv', s.recv, True, []),
|
|
|
|
('recvfrom', s.recvfrom, False, ["some.address"]),
|
|
|
|
('recv_into', _recv_into, True, []),
|
|
|
|
('recvfrom_into', _recvfrom_into, False, []),
|
|
|
|
]
|
|
|
|
data_prefix = "PREFIX_"
|
|
|
|
|
|
|
|
for (meth_name, send_meth, expect_success, args,
|
|
|
|
ret_val_meth) in send_methods:
|
|
|
|
indata = (data_prefix + meth_name).encode('ascii')
|
|
|
|
try:
|
|
|
|
ret = send_meth(indata, *args)
|
|
|
|
msg = "sending with {}".format(meth_name)
|
|
|
|
self.assertEqual(ret, ret_val_meth(indata), msg=msg)
|
|
|
|
outdata = s.read()
|
|
|
|
if outdata != indata.lower():
|
|
|
|
self.fail(
|
|
|
|
"While sending with <<{name:s}>> bad data "
|
|
|
|
"<<{outdata:r}>> ({nout:d}) received; "
|
|
|
|
"expected <<{indata:r}>> ({nin:d})\n".format(
|
|
|
|
name=meth_name, outdata=outdata[:20],
|
|
|
|
nout=len(outdata),
|
|
|
|
indata=indata[:20], nin=len(indata)
|
2008-09-08 13:45:19 -03:00
|
|
|
)
|
2017-09-07 13:56:24 -03:00
|
|
|
)
|
|
|
|
except ValueError as e:
|
|
|
|
if expect_success:
|
|
|
|
self.fail(
|
|
|
|
"Failed to send with method <<{name:s}>>; "
|
|
|
|
"expected to succeed.\n".format(name=meth_name)
|
|
|
|
)
|
|
|
|
if not str(e).startswith(meth_name):
|
|
|
|
self.fail(
|
|
|
|
"Method <<{name:s}>> failed with unexpected "
|
|
|
|
"exception message: {exp:s}\n".format(
|
|
|
|
name=meth_name, exp=e
|
2008-09-08 13:45:19 -03:00
|
|
|
)
|
2017-09-07 13:56:24 -03:00
|
|
|
)
|
2008-09-08 13:45:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
for meth_name, recv_meth, expect_success, args in recv_methods:
|
|
|
|
indata = (data_prefix + meth_name).encode('ascii')
|
|
|
|
try:
|
|
|
|
s.send(indata)
|
|
|
|
outdata = recv_meth(*args)
|
|
|
|
if outdata != indata.lower():
|
|
|
|
self.fail(
|
|
|
|
"While receiving with <<{name:s}>> bad data "
|
|
|
|
"<<{outdata:r}>> ({nout:d}) received; "
|
|
|
|
"expected <<{indata:r}>> ({nin:d})\n".format(
|
|
|
|
name=meth_name, outdata=outdata[:20],
|
|
|
|
nout=len(outdata),
|
|
|
|
indata=indata[:20], nin=len(indata)
|
2008-09-08 13:45:19 -03:00
|
|
|
)
|
2017-09-07 13:56:24 -03:00
|
|
|
)
|
|
|
|
except ValueError as e:
|
|
|
|
if expect_success:
|
|
|
|
self.fail(
|
|
|
|
"Failed to receive with method <<{name:s}>>; "
|
|
|
|
"expected to succeed.\n".format(name=meth_name)
|
|
|
|
)
|
|
|
|
if not str(e).startswith(meth_name):
|
|
|
|
self.fail(
|
|
|
|
"Method <<{name:s}>> failed with unexpected "
|
|
|
|
"exception message: {exp:s}\n".format(
|
|
|
|
name=meth_name, exp=e
|
2008-09-08 13:45:19 -03:00
|
|
|
)
|
2017-09-07 13:56:24 -03:00
|
|
|
)
|
|
|
|
# consume data
|
|
|
|
s.read()
|
2008-09-08 13:45:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# read(-1, buffer) is supported, even though read(-1) is not
|
|
|
|
data = b"data"
|
|
|
|
s.send(data)
|
|
|
|
buffer = bytearray(len(data))
|
|
|
|
self.assertEqual(s.read(-1, buffer), len(data))
|
|
|
|
self.assertEqual(buffer, data)
|
2016-03-27 02:35:19 -03:00
|
|
|
|
2017-09-07 18:18:21 -03:00
|
|
|
# sendall accepts bytes-like objects
|
|
|
|
if ctypes is not None:
|
|
|
|
ubyte = ctypes.c_ubyte * len(data)
|
|
|
|
byteslike = ubyte.from_buffer_copy(data)
|
|
|
|
s.sendall(byteslike)
|
|
|
|
self.assertEqual(s.read(), data)
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# Make sure sendmsg et al are disallowed to avoid
|
|
|
|
# inadvertent disclosure of data and/or corruption
|
|
|
|
# of the encrypted data stream
|
2018-12-06 16:36:55 -04:00
|
|
|
self.assertRaises(NotImplementedError, s.dup)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertRaises(NotImplementedError, s.sendmsg, [b"data"])
|
|
|
|
self.assertRaises(NotImplementedError, s.recvmsg, 100)
|
|
|
|
self.assertRaises(NotImplementedError,
|
2018-12-06 16:36:55 -04:00
|
|
|
s.recvmsg_into, [bytearray(100)])
|
2017-09-07 13:56:24 -03:00
|
|
|
s.write(b"over\n")
|
2016-03-27 02:35:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertRaises(ValueError, s.recv, -1)
|
|
|
|
self.assertRaises(ValueError, s.read, -1)
|
2016-03-27 02:35:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
s.close()
|
2008-09-08 13:45:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_recv_zero(self):
|
|
|
|
server = ThreadedEchoServer(CERTFILE)
|
2022-05-08 11:49:09 -03:00
|
|
|
self.enterContext(server)
|
2017-09-07 13:56:24 -03:00
|
|
|
s = socket.create_connection((HOST, server.port))
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
s = test_wrap_socket(s, suppress_ragged_eofs=False)
|
|
|
|
self.addCleanup(s.close)
|
2016-07-10 21:17:13 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# recv/read(0) should return no data
|
|
|
|
s.send(b"data")
|
|
|
|
self.assertEqual(s.recv(0), b"")
|
|
|
|
self.assertEqual(s.read(0), b"")
|
|
|
|
self.assertEqual(s.read(), b"data")
|
|
|
|
|
|
|
|
# Should not block if the other end sends no data
|
|
|
|
s.setblocking(False)
|
|
|
|
self.assertEqual(s.recv(0), b"")
|
|
|
|
self.assertEqual(s.recv_into(bytearray()), 0)
|
2016-07-10 21:17:13 -03:00
|
|
|
|
2023-11-27 13:15:39 -04:00
|
|
|
def test_recv_into_buffer_protocol_len(self):
|
|
|
|
server = ThreadedEchoServer(CERTFILE)
|
|
|
|
self.enterContext(server)
|
|
|
|
s = socket.create_connection((HOST, server.port))
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
s = test_wrap_socket(s, suppress_ragged_eofs=False)
|
|
|
|
self.addCleanup(s.close)
|
|
|
|
|
|
|
|
s.send(b"data")
|
|
|
|
buf = array.array('I', [0, 0])
|
|
|
|
self.assertEqual(s.recv_into(buf), 4)
|
|
|
|
self.assertEqual(bytes(buf)[:4], b"data")
|
|
|
|
|
|
|
|
class B(bytearray):
|
|
|
|
def __len__(self):
|
|
|
|
1/0
|
|
|
|
s.send(b"data")
|
|
|
|
buf = B(6)
|
|
|
|
self.assertEqual(s.recv_into(buf), 4)
|
|
|
|
self.assertEqual(bytes(buf), b"data\0\0")
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_nonblocking_send(self):
|
|
|
|
server = ThreadedEchoServer(CERTFILE,
|
|
|
|
certreqs=ssl.CERT_NONE,
|
2017-09-15 15:27:30 -03:00
|
|
|
ssl_version=ssl.PROTOCOL_TLS_SERVER,
|
2017-09-07 13:56:24 -03:00
|
|
|
cacerts=CERTFILE,
|
|
|
|
chatty=True,
|
|
|
|
connectionchatty=False)
|
|
|
|
with server:
|
|
|
|
s = test_wrap_socket(socket.socket(),
|
|
|
|
server_side=False,
|
|
|
|
certfile=CERTFILE,
|
|
|
|
ca_certs=CERTFILE,
|
2021-04-19 02:27:10 -03:00
|
|
|
cert_reqs=ssl.CERT_NONE)
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
2016-07-10 21:17:13 -03:00
|
|
|
s.setblocking(False)
|
2014-04-29 05:03:28 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
# If we keep sending data, at some point the buffers
|
|
|
|
# will be full and the call will block
|
|
|
|
buf = bytearray(8192)
|
|
|
|
def fill_buffer():
|
|
|
|
while True:
|
|
|
|
s.send(buf)
|
|
|
|
self.assertRaises((ssl.SSLWantWriteError,
|
|
|
|
ssl.SSLWantReadError), fill_buffer)
|
|
|
|
|
|
|
|
# Now read all the output and discard it
|
|
|
|
s.setblocking(True)
|
|
|
|
s.close()
|
|
|
|
|
|
|
|
def test_handshake_timeout(self):
|
|
|
|
# Issue #5103: SSL handshake must respect the socket timeout
|
|
|
|
server = socket.socket(socket.AF_INET)
|
|
|
|
host = "127.0.0.1"
|
2020-04-25 04:06:29 -03:00
|
|
|
port = socket_helper.bind_port(server)
|
2017-09-07 13:56:24 -03:00
|
|
|
started = threading.Event()
|
|
|
|
finish = False
|
|
|
|
|
|
|
|
def serve():
|
|
|
|
server.listen()
|
|
|
|
started.set()
|
|
|
|
conns = []
|
|
|
|
while not finish:
|
|
|
|
r, w, e = select.select([server], [], [], 0.1)
|
|
|
|
if server in r:
|
|
|
|
# Let the socket hang around rather than having
|
|
|
|
# it closed by garbage collection.
|
|
|
|
conns.append(server.accept()[0])
|
|
|
|
for sock in conns:
|
|
|
|
sock.close()
|
|
|
|
|
|
|
|
t = threading.Thread(target=serve)
|
|
|
|
t.start()
|
|
|
|
started.wait()
|
2010-04-24 18:26:44 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
try:
|
2010-04-24 18:26:44 -03:00
|
|
|
try:
|
2017-09-07 13:56:24 -03:00
|
|
|
c = socket.socket(socket.AF_INET)
|
|
|
|
c.settimeout(0.2)
|
|
|
|
c.connect((host, port))
|
|
|
|
# Will attempt handshake and time out
|
2020-11-20 04:26:07 -04:00
|
|
|
self.assertRaisesRegex(TimeoutError, "timed out",
|
2017-09-07 13:56:24 -03:00
|
|
|
test_wrap_socket, c)
|
2010-04-24 18:26:44 -03:00
|
|
|
finally:
|
2017-09-07 13:56:24 -03:00
|
|
|
c.close()
|
|
|
|
try:
|
|
|
|
c = socket.socket(socket.AF_INET)
|
|
|
|
c = test_wrap_socket(c)
|
|
|
|
c.settimeout(0.2)
|
|
|
|
# Will attempt handshake and time out
|
2020-11-20 04:26:07 -04:00
|
|
|
self.assertRaisesRegex(TimeoutError, "timed out",
|
2017-09-07 13:56:24 -03:00
|
|
|
c.connect, (host, port))
|
|
|
|
finally:
|
|
|
|
c.close()
|
|
|
|
finally:
|
|
|
|
finish = True
|
2012-11-10 20:25:36 -04:00
|
|
|
t.join()
|
2013-01-12 16:54:44 -04:00
|
|
|
server.close()
|
2014-09-04 16:00:10 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_server_accept(self):
|
|
|
|
# Issue #16357: accept() on a SSLSocket created through
|
|
|
|
# SSLContext.wrap_socket().
|
2021-04-19 02:27:10 -03:00
|
|
|
client_ctx, server_ctx, hostname = testing_context()
|
2017-09-07 13:56:24 -03:00
|
|
|
server = socket.socket(socket.AF_INET)
|
|
|
|
host = "127.0.0.1"
|
2020-04-25 04:06:29 -03:00
|
|
|
port = socket_helper.bind_port(server)
|
2021-04-19 02:27:10 -03:00
|
|
|
server = server_ctx.wrap_socket(server, server_side=True)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertTrue(server.server_side)
|
|
|
|
|
|
|
|
evt = threading.Event()
|
|
|
|
remote = None
|
|
|
|
peer = None
|
|
|
|
def serve():
|
|
|
|
nonlocal remote, peer
|
|
|
|
server.listen()
|
|
|
|
# Block on the accept and wait on the connection to close.
|
|
|
|
evt.set()
|
|
|
|
remote, peer = server.accept()
|
2018-05-23 17:24:45 -03:00
|
|
|
remote.send(remote.recv(4))
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
t = threading.Thread(target=serve)
|
|
|
|
t.start()
|
|
|
|
# Client wait until server setup and perform a connect.
|
|
|
|
evt.wait()
|
2021-04-19 02:27:10 -03:00
|
|
|
client = client_ctx.wrap_socket(
|
|
|
|
socket.socket(), server_hostname=hostname
|
|
|
|
)
|
|
|
|
client.connect((hostname, port))
|
2018-05-23 17:24:45 -03:00
|
|
|
client.send(b'data')
|
|
|
|
client.recv()
|
2017-09-07 13:56:24 -03:00
|
|
|
client_addr = client.getsockname()
|
|
|
|
client.close()
|
|
|
|
t.join()
|
|
|
|
remote.close()
|
|
|
|
server.close()
|
|
|
|
# Sanity checks.
|
|
|
|
self.assertIsInstance(remote, ssl.SSLSocket)
|
|
|
|
self.assertEqual(peer, client_addr)
|
|
|
|
|
|
|
|
def test_getpeercert_enotconn(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
context.check_hostname = False
|
2017-09-07 13:56:24 -03:00
|
|
|
with context.wrap_socket(socket.socket()) as sock:
|
|
|
|
with self.assertRaises(OSError) as cm:
|
|
|
|
sock.getpeercert()
|
|
|
|
self.assertEqual(cm.exception.errno, errno.ENOTCONN)
|
|
|
|
|
|
|
|
def test_do_handshake_enotconn(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
context.check_hostname = False
|
2017-09-07 13:56:24 -03:00
|
|
|
with context.wrap_socket(socket.socket()) as sock:
|
|
|
|
with self.assertRaises(OSError) as cm:
|
|
|
|
sock.do_handshake()
|
|
|
|
self.assertEqual(cm.exception.errno, errno.ENOTCONN)
|
|
|
|
|
2018-05-22 17:50:12 -03:00
|
|
|
def test_no_shared_ciphers(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
# OpenSSL enables all TLS 1.3 ciphers, enforce TLS 1.2 for test
|
2021-06-13 08:46:07 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2018-09-07 12:30:33 -03:00
|
|
|
# Force different suites on client and server
|
2018-05-22 17:50:12 -03:00
|
|
|
client_context.set_ciphers("AES128")
|
|
|
|
server_context.set_ciphers("AES256")
|
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
with self.assertRaises(OSError):
|
2014-03-22 14:13:50 -03:00
|
|
|
s.connect((HOST, server.port))
|
2024-03-21 16:16:36 -03:00
|
|
|
self.assertIn("NO_SHARED_CIPHER", server.conn_errors[0])
|
2014-03-22 14:13:50 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_version_basic(self):
|
|
|
|
"""
|
|
|
|
Basic tests for SSLSocket.version().
|
|
|
|
More tests are done in the test_protocol_*() methods.
|
|
|
|
"""
|
2017-09-15 15:27:30 -03:00
|
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
context.check_hostname = False
|
|
|
|
context.verify_mode = ssl.CERT_NONE
|
2017-09-07 13:56:24 -03:00
|
|
|
with ThreadedEchoServer(CERTFILE,
|
2017-09-15 15:27:30 -03:00
|
|
|
ssl_version=ssl.PROTOCOL_TLS_SERVER,
|
2017-09-07 13:56:24 -03:00
|
|
|
chatty=False) as server:
|
|
|
|
with context.wrap_socket(socket.socket()) as s:
|
|
|
|
self.assertIs(s.version(), None)
|
2018-02-24 16:10:57 -04:00
|
|
|
self.assertIs(s._sslobj, None)
|
2011-12-21 11:54:45 -04:00
|
|
|
s.connect((HOST, server.port))
|
2021-04-17 06:36:35 -03:00
|
|
|
self.assertEqual(s.version(), 'TLSv1.3')
|
2018-02-24 16:10:57 -04:00
|
|
|
self.assertIs(s._sslobj, None)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertIs(s.version(), None)
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_3')
|
2017-09-07 22:07:00 -03:00
|
|
|
def test_tls1_3(self):
|
2021-04-19 02:27:10 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 22:07:00 -03:00
|
|
|
s.connect((HOST, server.port))
|
2018-02-27 03:55:39 -04:00
|
|
|
self.assertIn(s.cipher()[0], {
|
2018-05-22 17:50:12 -03:00
|
|
|
'TLS_AES_256_GCM_SHA384',
|
|
|
|
'TLS_CHACHA20_POLY1305_SHA256',
|
|
|
|
'TLS_AES_128_GCM_SHA256',
|
2018-02-27 03:55:39 -04:00
|
|
|
})
|
|
|
|
self.assertEqual(s.version(), 'TLSv1.3')
|
2017-09-07 22:07:00 -03:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_2')
|
2021-04-19 02:27:10 -03:00
|
|
|
@requires_tls_version('TLSv1')
|
|
|
|
@ignore_deprecation
|
2019-09-26 12:02:59 -03:00
|
|
|
def test_min_max_version_tlsv1_2(self):
|
2018-02-27 06:54:43 -04:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
# client TLSv1.0 to 1.2
|
|
|
|
client_context.minimum_version = ssl.TLSVersion.TLSv1
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
# server only TLSv1.2
|
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
|
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertEqual(s.version(), 'TLSv1.2')
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_1')
|
2021-04-19 02:27:10 -03:00
|
|
|
@ignore_deprecation
|
2019-09-26 12:02:59 -03:00
|
|
|
def test_min_max_version_tlsv1_1(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-02-27 06:54:43 -04:00
|
|
|
# client 1.0 to 1.2, server 1.0 to 1.1
|
2019-09-26 12:02:59 -03:00
|
|
|
client_context.minimum_version = ssl.TLSVersion.TLSv1
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2018-02-27 06:54:43 -04:00
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1
|
|
|
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_1
|
2021-03-18 19:06:50 -03:00
|
|
|
seclevel_workaround(client_context, server_context)
|
2018-02-27 06:54:43 -04:00
|
|
|
|
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertEqual(s.version(), 'TLSv1.1')
|
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('TLSv1_2')
|
2020-11-18 08:10:53 -04:00
|
|
|
@requires_tls_version('TLSv1')
|
2021-04-19 02:27:10 -03:00
|
|
|
@ignore_deprecation
|
2019-09-26 12:02:59 -03:00
|
|
|
def test_min_max_version_mismatch(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-02-27 06:54:43 -04:00
|
|
|
# client 1.0, server 1.2 (mismatch)
|
|
|
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2019-09-11 14:24:47 -03:00
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
2019-06-03 15:40:15 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1
|
2019-09-11 14:48:58 -03:00
|
|
|
client_context.minimum_version = ssl.TLSVersion.TLSv1
|
2021-03-18 19:06:50 -03:00
|
|
|
seclevel_workaround(client_context, server_context)
|
|
|
|
|
2018-02-27 06:54:43 -04:00
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
with self.assertRaises(ssl.SSLError) as e:
|
|
|
|
s.connect((HOST, server.port))
|
2024-03-28 21:58:37 -03:00
|
|
|
self.assertRegex(str(e.exception), "(alert|ALERT)")
|
2018-02-27 06:54:43 -04:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@requires_tls_version('SSLv3')
|
2018-02-27 06:54:43 -04:00
|
|
|
def test_min_max_version_sslv3(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.minimum_version = ssl.TLSVersion.SSLv3
|
|
|
|
client_context.minimum_version = ssl.TLSVersion.SSLv3
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.SSLv3
|
2021-03-18 19:06:50 -03:00
|
|
|
seclevel_workaround(client_context, server_context)
|
|
|
|
|
2018-02-27 06:54:43 -04:00
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertEqual(s.version(), 'SSLv3')
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_default_ecdh_curve(self):
|
|
|
|
# Issue #21015: elliptic curve-based Diffie Hellman key exchange
|
|
|
|
# should be enabled by default on SSL contexts.
|
2021-04-19 02:27:10 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2017-09-07 22:07:00 -03:00
|
|
|
# TLSv1.3 defaults to PFS key agreement and no longer has KEA in
|
|
|
|
# cipher name.
|
2021-04-19 02:27:10 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2017-09-07 13:56:24 -03:00
|
|
|
# Prior to OpenSSL 1.0.0, ECDH ciphers have to be enabled
|
|
|
|
# explicitly using the 'ECCdraft' cipher alias. Otherwise,
|
|
|
|
# our default cipher list should prefer ECDH-based ciphers
|
|
|
|
# automatically.
|
2021-04-19 02:27:10 -03:00
|
|
|
with ThreadedEchoServer(context=server_context) as server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2011-07-20 20:11:30 -03:00
|
|
|
s.connect((HOST, server.port))
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertIn("ECDH", s.cipher()[0])
|
2008-09-08 13:45:19 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
@unittest.skipUnless("tls-unique" in ssl.CHANNEL_BINDING_TYPES,
|
|
|
|
"'tls-unique' channel binding not available")
|
|
|
|
def test_tls_unique_channel_binding(self):
|
|
|
|
"""Test tls-unique channel binding."""
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
2015-01-23 17:35:37 -04:00
|
|
|
|
2018-02-27 03:55:39 -04:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
|
2024-03-21 16:16:36 -03:00
|
|
|
# tls-unique is not defined for TLSv1.3
|
|
|
|
# https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
|
2018-02-27 03:55:39 -04:00
|
|
|
server = ThreadedEchoServer(context=server_context,
|
2017-09-07 13:56:24 -03:00
|
|
|
chatty=True,
|
|
|
|
connectionchatty=False)
|
2018-02-27 03:55:39 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
with server:
|
2018-02-27 03:55:39 -04:00
|
|
|
with client_context.wrap_socket(
|
|
|
|
socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
# get the data
|
|
|
|
cb_data = s.get_channel_binding("tls-unique")
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(
|
|
|
|
" got channel binding data: {0!r}\n".format(cb_data))
|
|
|
|
|
|
|
|
# check if it is sane
|
|
|
|
self.assertIsNotNone(cb_data)
|
2018-05-23 17:24:45 -03:00
|
|
|
if s.version() == 'TLSv1.3':
|
|
|
|
self.assertEqual(len(cb_data), 48)
|
|
|
|
else:
|
|
|
|
self.assertEqual(len(cb_data), 12) # True for TLSv1
|
2018-02-27 03:55:39 -04:00
|
|
|
|
|
|
|
# and compare with the peers version
|
|
|
|
s.write(b"CB tls-unique\n")
|
|
|
|
peer_data_repr = s.read().strip()
|
|
|
|
self.assertEqual(peer_data_repr,
|
|
|
|
repr(cb_data).encode("us-ascii"))
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# now, again
|
2018-02-27 03:55:39 -04:00
|
|
|
with client_context.wrap_socket(
|
|
|
|
socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
new_cb_data = s.get_channel_binding("tls-unique")
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(
|
|
|
|
"got another channel binding data: {0!r}\n".format(
|
|
|
|
new_cb_data)
|
|
|
|
)
|
|
|
|
# is it really unique
|
|
|
|
self.assertNotEqual(cb_data, new_cb_data)
|
|
|
|
self.assertIsNotNone(cb_data)
|
2018-05-23 17:24:45 -03:00
|
|
|
if s.version() == 'TLSv1.3':
|
|
|
|
self.assertEqual(len(cb_data), 48)
|
|
|
|
else:
|
|
|
|
self.assertEqual(len(cb_data), 12) # True for TLSv1
|
2018-02-27 03:55:39 -04:00
|
|
|
s.write(b"CB tls-unique\n")
|
|
|
|
peer_data_repr = s.read().strip()
|
|
|
|
self.assertEqual(peer_data_repr,
|
|
|
|
repr(new_cb_data).encode("us-ascii"))
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def test_compression(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write(" got compression: {!r}\n".format(stats['compression']))
|
|
|
|
self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' })
|
|
|
|
|
|
|
|
@unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'),
|
|
|
|
"ssl.OP_NO_COMPRESSION needed for this test")
|
|
|
|
def test_compression_disabled(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.options |= ssl.OP_NO_COMPRESSION
|
|
|
|
server_context.options |= ssl.OP_NO_COMPRESSION
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertIs(stats['compression'], None)
|
|
|
|
|
2022-12-20 03:10:30 -04:00
|
|
|
def test_legacy_server_connect(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.options |= ssl.OP_LEGACY_SERVER_CONNECT
|
|
|
|
server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
|
|
|
|
|
|
|
def test_no_legacy_server_connect(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.options &= ~ssl.OP_LEGACY_SERVER_CONNECT
|
|
|
|
server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
|
|
|
|
2019-06-19 17:09:54 -03:00
|
|
|
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_dh_params(self):
|
|
|
|
# Check we can get a connection with ephemeral Diffie-Hellman
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-02-27 03:55:39 -04:00
|
|
|
# test scenario needs TLS <= 1.2
|
2021-06-13 08:46:07 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2017-09-15 15:27:30 -03:00
|
|
|
server_context.load_dh_params(DHFILE)
|
|
|
|
server_context.set_ciphers("kEDH")
|
2021-06-13 08:46:07 -03:00
|
|
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2017-09-15 15:27:30 -03:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
cipher = stats["cipher"][0]
|
|
|
|
parts = cipher.split("-")
|
|
|
|
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
|
2024-03-21 16:16:36 -03:00
|
|
|
self.fail("Non-DH key exchange: " + cipher[0])
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2018-02-25 04:49:31 -04:00
|
|
|
def test_ecdh_curve(self):
|
|
|
|
# server secp384r1, client auto
|
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-02-27 03:55:39 -04:00
|
|
|
|
2018-02-25 04:49:31 -04:00
|
|
|
server_context.set_ecdh_curve("secp384r1")
|
|
|
|
server_context.set_ciphers("ECDHE:!eNULL:!aNULL")
|
2021-04-19 03:31:29 -03:00
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
2018-02-25 04:49:31 -04:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
|
|
|
|
|
|
|
# server auto, client secp384r1
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.set_ecdh_curve("secp384r1")
|
|
|
|
server_context.set_ciphers("ECDHE:!eNULL:!aNULL")
|
2021-04-19 03:31:29 -03:00
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
2018-02-25 04:49:31 -04:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
|
|
|
|
|
|
|
# server / client curve mismatch
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.set_ecdh_curve("prime256v1")
|
|
|
|
server_context.set_ecdh_curve("secp384r1")
|
|
|
|
server_context.set_ciphers("ECDHE:!eNULL:!aNULL")
|
2021-04-19 03:31:29 -03:00
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
with self.assertRaises(ssl.SSLError):
|
2021-04-17 06:36:35 -03:00
|
|
|
server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2018-02-25 04:49:31 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_selected_alpn_protocol(self):
|
|
|
|
# selected_alpn_protocol() is None unless ALPN is used.
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertIs(stats['client_alpn_protocol'], None)
|
|
|
|
|
|
|
|
def test_selected_alpn_protocol_if_server_uses_alpn(self):
|
|
|
|
# selected_alpn_protocol() is None unless ALPN is used by the client.
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2017-09-07 13:56:24 -03:00
|
|
|
server_context.set_alpn_protocols(['foo', 'bar'])
|
|
|
|
stats = server_params_test(client_context, server_context,
|
2017-09-15 15:27:30 -03:00
|
|
|
chatty=True, connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertIs(stats['client_alpn_protocol'], None)
|
|
|
|
|
|
|
|
def test_alpn_protocols(self):
|
|
|
|
server_protocols = ['foo', 'bar', 'milkshake']
|
|
|
|
protocol_tests = [
|
|
|
|
(['foo', 'bar'], 'foo'),
|
|
|
|
(['bar', 'foo'], 'foo'),
|
|
|
|
(['milkshake'], 'milkshake'),
|
|
|
|
(['http/3.0', 'http/4.0'], None)
|
|
|
|
]
|
|
|
|
for client_protocols, expected in protocol_tests:
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2017-09-07 13:56:24 -03:00
|
|
|
server_context.set_alpn_protocols(server_protocols)
|
|
|
|
client_context.set_alpn_protocols(client_protocols)
|
2015-01-23 17:35:37 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
try:
|
|
|
|
stats = server_params_test(client_context,
|
|
|
|
server_context,
|
|
|
|
chatty=True,
|
2017-09-15 15:27:30 -03:00
|
|
|
connectionchatty=True,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
except ssl.SSLError as e:
|
|
|
|
stats = e
|
2012-03-21 20:23:03 -03:00
|
|
|
|
2021-04-17 06:36:35 -03:00
|
|
|
msg = "failed trying %s (s) and %s (c).\n" \
|
|
|
|
"was expecting %s, but got %%s from the %%s" \
|
|
|
|
% (str(server_protocols), str(client_protocols),
|
|
|
|
str(expected))
|
|
|
|
client_result = stats['client_alpn_protocol']
|
|
|
|
self.assertEqual(client_result, expected,
|
|
|
|
msg % (client_result, "client"))
|
|
|
|
server_result = stats['server_alpn_protocols'][-1] \
|
|
|
|
if len(stats['server_alpn_protocols']) else 'nothing'
|
|
|
|
self.assertEqual(server_result, expected,
|
|
|
|
msg % (server_result, "server"))
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def test_npn_protocols(self):
|
2021-04-17 06:36:35 -03:00
|
|
|
assert not ssl.HAS_NPN
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def sni_contexts(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2017-09-07 13:56:24 -03:00
|
|
|
server_context.load_cert_chain(SIGNED_CERTFILE)
|
2017-09-15 15:27:30 -03:00
|
|
|
other_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
2017-09-07 13:56:24 -03:00
|
|
|
other_context.load_cert_chain(SIGNED_CERTFILE2)
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
2017-09-07 13:56:24 -03:00
|
|
|
client_context.load_verify_locations(SIGNING_CA)
|
|
|
|
return server_context, other_context, client_context
|
|
|
|
|
|
|
|
def check_common_name(self, stats, name):
|
|
|
|
cert = stats['peercert']
|
|
|
|
self.assertIn((('commonName', name),), cert['subject'])
|
|
|
|
|
|
|
|
def test_sni_callback(self):
|
|
|
|
calls = []
|
|
|
|
server_context, other_context, client_context = self.sni_contexts()
|
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context.check_hostname = False
|
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def servername_cb(ssl_sock, server_name, initial_context):
|
|
|
|
calls.append((server_name, initial_context))
|
|
|
|
if server_name is not None:
|
|
|
|
ssl_sock.context = other_context
|
|
|
|
server_context.set_servername_callback(servername_cb)
|
|
|
|
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True,
|
|
|
|
sni_name='supermessage')
|
|
|
|
# The hostname was fetched properly, and the certificate was
|
|
|
|
# changed for the connection.
|
|
|
|
self.assertEqual(calls, [("supermessage", server_context)])
|
|
|
|
# CERTFILE4 was selected
|
|
|
|
self.check_common_name(stats, 'fakehostname')
|
|
|
|
|
|
|
|
calls = []
|
|
|
|
# The callback is called with server_name=None
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True,
|
|
|
|
sni_name=None)
|
|
|
|
self.assertEqual(calls, [(None, server_context)])
|
2017-09-15 15:27:30 -03:00
|
|
|
self.check_common_name(stats, SIGNED_CERTFILE_HOSTNAME)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# Check disabling the callback
|
|
|
|
calls = []
|
|
|
|
server_context.set_servername_callback(None)
|
|
|
|
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=True,
|
|
|
|
sni_name='notfunny')
|
|
|
|
# Certificate didn't change
|
2017-09-15 15:27:30 -03:00
|
|
|
self.check_common_name(stats, SIGNED_CERTFILE_HOSTNAME)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertEqual(calls, [])
|
2013-01-05 16:20:29 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def test_sni_callback_alert(self):
|
|
|
|
# Returning a TLS alert is reflected to the connecting client
|
|
|
|
server_context, other_context, client_context = self.sni_contexts()
|
2013-01-05 16:20:29 -04:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def cb_returning_alert(ssl_sock, server_name, initial_context):
|
|
|
|
return ssl.ALERT_DESCRIPTION_ACCESS_DENIED
|
|
|
|
server_context.set_servername_callback(cb_returning_alert)
|
|
|
|
with self.assertRaises(ssl.SSLError) as cm:
|
2013-01-05 16:20:29 -04:00
|
|
|
stats = server_params_test(client_context, server_context,
|
2017-09-07 13:56:24 -03:00
|
|
|
chatty=False,
|
2013-01-05 16:20:29 -04:00
|
|
|
sni_name='supermessage')
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_ACCESS_DENIED')
|
|
|
|
|
|
|
|
def test_sni_callback_raising(self):
|
|
|
|
# Raising fails the connection with a TLS handshake failure alert.
|
|
|
|
server_context, other_context, client_context = self.sni_contexts()
|
|
|
|
|
|
|
|
def cb_raising(ssl_sock, server_name, initial_context):
|
|
|
|
1/0
|
|
|
|
server_context.set_servername_callback(cb_raising)
|
|
|
|
|
2019-06-02 22:51:43 -03:00
|
|
|
with support.catch_unraisable_exception() as catch:
|
|
|
|
with self.assertRaises(ssl.SSLError) as cm:
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=False,
|
|
|
|
sni_name='supermessage')
|
|
|
|
|
2024-03-21 16:16:36 -03:00
|
|
|
# Allow for flexible libssl error messages.
|
|
|
|
regex = "(SSLV3_ALERT_HANDSHAKE_FAILURE|NO_PRIVATE_VALUE)"
|
2024-03-28 21:58:37 -03:00
|
|
|
self.assertRegex(cm.exception.reason, regex)
|
2019-06-02 22:51:43 -03:00
|
|
|
self.assertEqual(catch.unraisable.exc_type, ZeroDivisionError)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def test_sni_callback_wrong_return_type(self):
|
|
|
|
# Returning the wrong return type terminates the TLS connection
|
|
|
|
# with an internal error alert.
|
|
|
|
server_context, other_context, client_context = self.sni_contexts()
|
2013-04-11 15:48:42 -03:00
|
|
|
|
2017-09-07 13:56:24 -03:00
|
|
|
def cb_wrong_return_type(ssl_sock, server_name, initial_context):
|
|
|
|
return "foo"
|
|
|
|
server_context.set_servername_callback(cb_wrong_return_type)
|
2013-01-05 16:20:29 -04:00
|
|
|
|
2019-06-02 22:51:43 -03:00
|
|
|
with support.catch_unraisable_exception() as catch:
|
|
|
|
with self.assertRaises(ssl.SSLError) as cm:
|
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
chatty=False,
|
|
|
|
sni_name='supermessage')
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR')
|
|
|
|
self.assertEqual(catch.unraisable.exc_type, TypeError)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
def test_shared_ciphers(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-05-22 17:50:12 -03:00
|
|
|
client_context.set_ciphers("AES128:AES256")
|
2023-03-22 11:08:41 -03:00
|
|
|
server_context.set_ciphers("AES256:eNULL")
|
2018-05-22 17:50:12 -03:00
|
|
|
expected_algs = [
|
|
|
|
"AES256", "AES-256",
|
|
|
|
# TLS 1.3 ciphers are always enabled
|
|
|
|
"TLS_CHACHA20", "TLS_AES",
|
|
|
|
]
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
ciphers = stats['server_shared_ciphers'][0]
|
|
|
|
self.assertGreater(len(ciphers), 0)
|
|
|
|
for name, tls_version, bits in ciphers:
|
2018-05-22 17:50:12 -03:00
|
|
|
if not any(alg in name for alg in expected_algs):
|
2017-09-07 13:56:24 -03:00
|
|
|
self.fail(name)
|
|
|
|
|
|
|
|
def test_read_write_after_close_raises_valuerror(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
s = client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.close()
|
|
|
|
|
|
|
|
self.assertRaises(ValueError, s.read, 1024)
|
|
|
|
self.assertRaises(ValueError, s.write, b'hello')
|
|
|
|
|
|
|
|
def test_sendfile(self):
|
|
|
|
TEST_DATA = b"x" * 512
|
2020-08-03 13:41:24 -03:00
|
|
|
with open(os_helper.TESTFN, 'wb') as f:
|
2017-09-07 13:56:24 -03:00
|
|
|
f.write(TEST_DATA)
|
2020-08-03 13:41:24 -03:00
|
|
|
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
2021-04-19 02:27:10 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
2017-09-07 13:56:24 -03:00
|
|
|
with server:
|
2021-04-19 02:27:10 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2013-07-20 14:35:16 -03:00
|
|
|
s.connect((HOST, server.port))
|
2020-08-03 13:41:24 -03:00
|
|
|
with open(os_helper.TESTFN, 'rb') as file:
|
2017-09-07 13:56:24 -03:00
|
|
|
s.sendfile(file)
|
|
|
|
self.assertEqual(s.recv(1024), TEST_DATA)
|
|
|
|
|
|
|
|
def test_session(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
2018-02-27 03:55:39 -04:00
|
|
|
# TODO: sessions aren't compatible with TLSv1.3 yet
|
2021-06-13 08:46:07 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2017-09-07 13:56:24 -03:00
|
|
|
|
|
|
|
# first connection without session
|
2017-09-15 15:27:30 -03:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
session = stats['session']
|
|
|
|
self.assertTrue(session.id)
|
|
|
|
self.assertGreater(session.time, 0)
|
|
|
|
self.assertGreater(session.timeout, 0)
|
|
|
|
self.assertTrue(session.has_ticket)
|
2021-04-17 06:36:35 -03:00
|
|
|
self.assertGreater(session.ticket_lifetime_hint, 0)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertFalse(stats['session_reused'])
|
|
|
|
sess_stat = server_context.session_stats()
|
|
|
|
self.assertEqual(sess_stat['accept'], 1)
|
|
|
|
self.assertEqual(sess_stat['hits'], 0)
|
|
|
|
|
|
|
|
# reuse session
|
2017-09-15 15:27:30 -03:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
session=session, sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
sess_stat = server_context.session_stats()
|
|
|
|
self.assertEqual(sess_stat['accept'], 2)
|
|
|
|
self.assertEqual(sess_stat['hits'], 1)
|
|
|
|
self.assertTrue(stats['session_reused'])
|
|
|
|
session2 = stats['session']
|
|
|
|
self.assertEqual(session2.id, session.id)
|
|
|
|
self.assertEqual(session2, session)
|
|
|
|
self.assertIsNot(session2, session)
|
|
|
|
self.assertGreaterEqual(session2.time, session.time)
|
|
|
|
self.assertGreaterEqual(session2.timeout, session.timeout)
|
|
|
|
|
|
|
|
# another one without session
|
2017-09-15 15:27:30 -03:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertFalse(stats['session_reused'])
|
|
|
|
session3 = stats['session']
|
|
|
|
self.assertNotEqual(session3.id, session.id)
|
|
|
|
self.assertNotEqual(session3, session)
|
|
|
|
sess_stat = server_context.session_stats()
|
|
|
|
self.assertEqual(sess_stat['accept'], 3)
|
|
|
|
self.assertEqual(sess_stat['hits'], 1)
|
|
|
|
|
|
|
|
# reuse session again
|
2017-09-15 15:27:30 -03:00
|
|
|
stats = server_params_test(client_context, server_context,
|
|
|
|
session=session, sni_name=hostname)
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertTrue(stats['session_reused'])
|
|
|
|
session4 = stats['session']
|
|
|
|
self.assertEqual(session4.id, session.id)
|
|
|
|
self.assertEqual(session4, session)
|
|
|
|
self.assertGreaterEqual(session4.time, session.time)
|
|
|
|
self.assertGreaterEqual(session4.timeout, session.timeout)
|
|
|
|
sess_stat = server_context.session_stats()
|
|
|
|
self.assertEqual(sess_stat['accept'], 4)
|
|
|
|
self.assertEqual(sess_stat['hits'], 2)
|
|
|
|
|
|
|
|
def test_session_handling(self):
|
2017-09-15 15:27:30 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context2, _, _ = testing_context()
|
2017-09-07 13:56:24 -03:00
|
|
|
|
2018-02-27 03:55:39 -04:00
|
|
|
# TODO: session reuse does not work with TLSv1.3
|
2021-06-13 08:46:07 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
client_context2.maximum_version = ssl.TLSVersion.TLSv1_2
|
2017-09-07 22:07:00 -03:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
2017-09-07 13:56:24 -03:00
|
|
|
with server:
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
# session is None before handshake
|
|
|
|
self.assertEqual(s.session, None)
|
|
|
|
self.assertEqual(s.session_reused, None)
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
session = s.session
|
|
|
|
self.assertTrue(session)
|
|
|
|
with self.assertRaises(TypeError) as e:
|
|
|
|
s.session = object
|
2018-06-11 21:26:28 -03:00
|
|
|
self.assertEqual(str(e.exception), 'Value is not a SSLSession.')
|
2013-07-20 14:35:16 -03:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
# cannot set session after handshake
|
|
|
|
with self.assertRaises(ValueError) as e:
|
|
|
|
s.session = session
|
|
|
|
self.assertEqual(str(e.exception),
|
|
|
|
'Cannot set session after handshake.')
|
2014-06-10 22:54:30 -03:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
# can set session before handshake and before the
|
|
|
|
# connection was established
|
|
|
|
s.session = session
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertEqual(s.session.id, session.id)
|
|
|
|
self.assertEqual(s.session, session)
|
|
|
|
self.assertEqual(s.session_reused, True)
|
2016-09-10 18:44:53 -03:00
|
|
|
|
2017-09-15 15:27:30 -03:00
|
|
|
with client_context2.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
2017-09-07 13:56:24 -03:00
|
|
|
# cannot re-use session with a different SSLContext
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2016-09-10 18:44:53 -03:00
|
|
|
s.session = session
|
|
|
|
s.connect((HOST, server.port))
|
2017-09-07 13:56:24 -03:00
|
|
|
self.assertEqual(str(e.exception),
|
|
|
|
'Session refers to a different SSLContext.')
|
2016-09-10 18:44:53 -03:00
|
|
|
|
2023-11-27 00:01:44 -04:00
|
|
|
@requires_tls_version('TLSv1_2')
|
2023-11-28 20:15:39 -04:00
|
|
|
@unittest.skipUnless(ssl.HAS_PSK, 'TLS-PSK disabled on this OpenSSL build')
|
2023-11-27 00:01:44 -04:00
|
|
|
def test_psk(self):
|
|
|
|
psk = bytes.fromhex('deadbeef')
|
|
|
|
|
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
client_context.check_hostname = False
|
|
|
|
client_context.verify_mode = ssl.CERT_NONE
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
client_context.set_ciphers('PSK')
|
|
|
|
client_context.set_psk_client_callback(lambda hint: (None, psk))
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
server_context.set_ciphers('PSK')
|
|
|
|
server_context.set_psk_server_callback(lambda identity: psk)
|
|
|
|
|
|
|
|
# correct PSK should connect
|
|
|
|
server = ThreadedEchoServer(context=server_context)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket()) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
|
|
|
# incorrect PSK should fail
|
|
|
|
incorrect_psk = bytes.fromhex('cafebabe')
|
|
|
|
client_context.set_psk_client_callback(lambda hint: (None, incorrect_psk))
|
|
|
|
server = ThreadedEchoServer(context=server_context)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket()) as s:
|
|
|
|
with self.assertRaises(ssl.SSLError):
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
|
|
|
# identity_hint and client_identity should be sent to the other side
|
|
|
|
identity_hint = 'identity-hint'
|
|
|
|
client_identity = 'client-identity'
|
|
|
|
|
|
|
|
def client_callback(hint):
|
|
|
|
self.assertEqual(hint, identity_hint)
|
|
|
|
return client_identity, psk
|
|
|
|
|
|
|
|
def server_callback(identity):
|
|
|
|
self.assertEqual(identity, client_identity)
|
|
|
|
return psk
|
|
|
|
|
|
|
|
client_context.set_psk_client_callback(client_callback)
|
|
|
|
server_context.set_psk_server_callback(server_callback, identity_hint)
|
|
|
|
server = ThreadedEchoServer(context=server_context)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket()) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
|
|
|
# adding client callback to server or vice versa raises an exception
|
|
|
|
with self.assertRaisesRegex(ssl.SSLError, 'Cannot add PSK server callback'):
|
|
|
|
client_context.set_psk_server_callback(server_callback, identity_hint)
|
|
|
|
with self.assertRaisesRegex(ssl.SSLError, 'Cannot add PSK client callback'):
|
|
|
|
server_context.set_psk_client_callback(client_callback)
|
|
|
|
|
|
|
|
# test with UTF-8 identities
|
|
|
|
identity_hint = '身份暗示' # Translation: "Identity hint"
|
|
|
|
client_identity = '客户身份' # Translation: "Customer identity"
|
|
|
|
|
|
|
|
client_context.set_psk_client_callback(client_callback)
|
|
|
|
server_context.set_psk_server_callback(server_callback, identity_hint)
|
|
|
|
server = ThreadedEchoServer(context=server_context)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket()) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
|
|
|
@requires_tls_version('TLSv1_3')
|
2023-11-28 20:15:39 -04:00
|
|
|
@unittest.skipUnless(ssl.HAS_PSK, 'TLS-PSK disabled on this OpenSSL build')
|
2023-11-27 00:01:44 -04:00
|
|
|
def test_psk_tls1_3(self):
|
|
|
|
psk = bytes.fromhex('deadbeef')
|
|
|
|
identity_hint = 'identity-hint'
|
|
|
|
client_identity = 'client-identity'
|
|
|
|
|
|
|
|
def client_callback(hint):
|
|
|
|
# identity_hint is not sent to the client in TLS 1.3
|
|
|
|
self.assertIsNone(hint)
|
|
|
|
return client_identity, psk
|
|
|
|
|
|
|
|
def server_callback(identity):
|
|
|
|
self.assertEqual(identity, client_identity)
|
|
|
|
return psk
|
|
|
|
|
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
client_context.check_hostname = False
|
|
|
|
client_context.verify_mode = ssl.CERT_NONE
|
|
|
|
client_context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
|
|
client_context.set_ciphers('PSK')
|
|
|
|
client_context.set_psk_client_callback(client_callback)
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
server_context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
|
|
server_context.set_ciphers('PSK')
|
|
|
|
server_context.set_psk_server_callback(server_callback, identity_hint)
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket()) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
2011-12-20 05:13:40 -04:00
|
|
|
|
2019-09-26 12:02:59 -03:00
|
|
|
@unittest.skipUnless(has_tls_version('TLSv1_3'), "Test needs TLS 1.3")
|
2018-09-23 03:32:31 -03:00
|
|
|
class TestPostHandshakeAuth(unittest.TestCase):
|
|
|
|
def test_pha_setter(self):
|
|
|
|
protocols = [
|
2021-04-19 02:27:10 -03:00
|
|
|
ssl.PROTOCOL_TLS_SERVER, ssl.PROTOCOL_TLS_CLIENT
|
2018-09-23 03:32:31 -03:00
|
|
|
]
|
|
|
|
for protocol in protocols:
|
|
|
|
ctx = ssl.SSLContext(protocol)
|
|
|
|
self.assertEqual(ctx.post_handshake_auth, False)
|
|
|
|
|
|
|
|
ctx.post_handshake_auth = True
|
|
|
|
self.assertEqual(ctx.post_handshake_auth, True)
|
|
|
|
|
|
|
|
ctx.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
self.assertEqual(ctx.post_handshake_auth, True)
|
|
|
|
|
|
|
|
ctx.post_handshake_auth = False
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
|
|
|
|
self.assertEqual(ctx.post_handshake_auth, False)
|
|
|
|
|
|
|
|
ctx.verify_mode = ssl.CERT_OPTIONAL
|
|
|
|
ctx.post_handshake_auth = True
|
|
|
|
self.assertEqual(ctx.verify_mode, ssl.CERT_OPTIONAL)
|
|
|
|
self.assertEqual(ctx.post_handshake_auth, True)
|
|
|
|
|
|
|
|
def test_pha_required(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.post_handshake_auth = True
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'FALSE\n')
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertEqual(s.recv(1024), b'OK\n')
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'TRUE\n')
|
|
|
|
# PHA method just returns true when cert is already available
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertEqual(s.recv(1024), b'OK\n')
|
|
|
|
s.write(b'GETCERT')
|
|
|
|
cert_text = s.recv(4096).decode('us-ascii')
|
|
|
|
self.assertIn('Python Software Foundation CA', cert_text)
|
|
|
|
|
|
|
|
def test_pha_required_nocert(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.post_handshake_auth = True
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
|
2021-04-24 04:17:54 -03:00
|
|
|
def msg_cb(conn, direction, version, content_type, msg_type, data):
|
|
|
|
if support.verbose and content_type == _TLSContentType.ALERT:
|
|
|
|
info = (conn, direction, version, content_type, msg_type, data)
|
|
|
|
sys.stdout.write(f"TLS: {info!r}\n")
|
|
|
|
|
|
|
|
server_context._msg_callback = msg_cb
|
|
|
|
client_context._msg_callback = msg_cb
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=True)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
2021-06-03 13:04:25 -03:00
|
|
|
server_hostname=hostname,
|
|
|
|
suppress_ragged_eofs=False) as s:
|
2021-04-24 04:17:54 -03:00
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'PHA')
|
2021-04-24 10:08:13 -03:00
|
|
|
# test sometimes fails with EOF error. Test passes as long as
|
|
|
|
# server aborts connection with an error.
|
2021-04-24 04:17:54 -03:00
|
|
|
with self.assertRaisesRegex(
|
2024-03-26 04:45:43 -03:00
|
|
|
OSError,
|
2024-04-12 15:41:16 -03:00
|
|
|
('certificate required'
|
|
|
|
'|EOF occurred'
|
|
|
|
'|closed by the remote host'
|
|
|
|
'|Connection reset by peer'
|
|
|
|
'|Broken pipe')
|
2021-04-24 04:17:54 -03:00
|
|
|
):
|
2019-07-09 09:33:49 -03:00
|
|
|
# receive CertificateRequest
|
2021-06-02 17:25:26 -03:00
|
|
|
data = s.recv(1024)
|
|
|
|
self.assertEqual(data, b'OK\n')
|
|
|
|
|
2019-07-09 09:33:49 -03:00
|
|
|
# send empty Certificate + Finish
|
|
|
|
s.write(b'HASCERT')
|
2021-06-02 17:25:26 -03:00
|
|
|
|
2019-07-09 09:33:49 -03:00
|
|
|
# receive alert
|
2021-06-03 13:04:25 -03:00
|
|
|
s.recv(1024)
|
2018-09-23 03:32:31 -03:00
|
|
|
|
|
|
|
def test_pha_optional(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.post_handshake_auth = True
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
# check CERT_OPTIONAL
|
|
|
|
server_context.verify_mode = ssl.CERT_OPTIONAL
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'FALSE\n')
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertEqual(s.recv(1024), b'OK\n')
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'TRUE\n')
|
|
|
|
|
|
|
|
def test_pha_optional_nocert(self):
|
|
|
|
if support.verbose:
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.post_handshake_auth = True
|
|
|
|
server_context.verify_mode = ssl.CERT_OPTIONAL
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'FALSE\n')
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertEqual(s.recv(1024), b'OK\n')
|
2019-05-06 15:57:17 -03:00
|
|
|
# optional doesn't fail when client does not have a cert
|
2018-09-23 03:32:31 -03:00
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'FALSE\n')
|
|
|
|
|
|
|
|
def test_pha_no_pha_client(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.post_handshake_auth = True
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
with self.assertRaisesRegex(ssl.SSLError, 'not server'):
|
|
|
|
s.verify_client_post_handshake()
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertIn(b'extension not received', s.recv(1024))
|
|
|
|
|
|
|
|
def test_pha_no_pha_server(self):
|
|
|
|
# server doesn't have PHA enabled, cert is requested in handshake
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'TRUE\n')
|
|
|
|
# PHA doesn't fail if there is already a cert
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertEqual(s.recv(1024), b'OK\n')
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'TRUE\n')
|
|
|
|
|
|
|
|
def test_pha_not_tls13(self):
|
|
|
|
# TLS 1.2
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
# PHA fails for TLS != 1.3
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertIn(b'WRONG_SSL_VERSION', s.recv(1024))
|
|
|
|
|
2019-07-01 03:29:17 -03:00
|
|
|
def test_bpo37428_pha_cert_none(self):
|
|
|
|
# verify that post_handshake_auth does not implicitly enable cert
|
|
|
|
# validation.
|
|
|
|
hostname = SIGNED_CERTFILE_HOSTNAME
|
|
|
|
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
client_context.post_handshake_auth = True
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
# no cert validation and CA on client side
|
|
|
|
client_context.check_hostname = False
|
|
|
|
client_context.verify_mode = ssl.CERT_NONE
|
|
|
|
|
|
|
|
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
server_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
server_context.load_verify_locations(SIGNING_CA)
|
|
|
|
server_context.post_handshake_auth = True
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'FALSE\n')
|
|
|
|
s.write(b'PHA')
|
|
|
|
self.assertEqual(s.recv(1024), b'OK\n')
|
|
|
|
s.write(b'HASCERT')
|
|
|
|
self.assertEqual(s.recv(1024), b'TRUE\n')
|
|
|
|
# server cert has not been validated
|
|
|
|
self.assertEqual(s.getpeercert(), {})
|
|
|
|
|
2021-04-26 10:01:40 -03:00
|
|
|
def test_internal_chain_client(self):
|
|
|
|
client_context, server_context, hostname = testing_context(
|
|
|
|
server_chain=False
|
|
|
|
)
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(
|
|
|
|
socket.socket(),
|
|
|
|
server_hostname=hostname
|
|
|
|
) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
vc = s._sslobj.get_verified_chain()
|
|
|
|
self.assertEqual(len(vc), 2)
|
|
|
|
ee, ca = vc
|
|
|
|
uvc = s._sslobj.get_unverified_chain()
|
|
|
|
self.assertEqual(len(uvc), 1)
|
|
|
|
|
|
|
|
self.assertEqual(ee, uvc[0])
|
|
|
|
self.assertEqual(hash(ee), hash(uvc[0]))
|
|
|
|
self.assertEqual(repr(ee), repr(uvc[0]))
|
|
|
|
|
|
|
|
self.assertNotEqual(ee, ca)
|
|
|
|
self.assertNotEqual(hash(ee), hash(ca))
|
|
|
|
self.assertNotEqual(repr(ee), repr(ca))
|
|
|
|
self.assertNotEqual(ee.get_info(), ca.get_info())
|
|
|
|
self.assertIn("CN=localhost", repr(ee))
|
|
|
|
self.assertIn("CN=our-ca-server", repr(ca))
|
|
|
|
|
|
|
|
pem = ee.public_bytes(_ssl.ENCODING_PEM)
|
|
|
|
der = ee.public_bytes(_ssl.ENCODING_DER)
|
|
|
|
self.assertIsInstance(pem, str)
|
|
|
|
self.assertIn("-----BEGIN CERTIFICATE-----", pem)
|
|
|
|
self.assertIsInstance(der, bytes)
|
|
|
|
self.assertEqual(
|
|
|
|
ssl.PEM_cert_to_DER_cert(pem), der
|
|
|
|
)
|
|
|
|
|
2024-08-16 17:27:44 -03:00
|
|
|
def test_certificate_chain(self):
|
|
|
|
client_context, server_context, hostname = testing_context(
|
|
|
|
server_chain=False
|
|
|
|
)
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
|
|
|
|
with open(SIGNING_CA) as f:
|
|
|
|
expected_ca_cert = ssl.PEM_cert_to_DER_cert(f.read())
|
|
|
|
|
|
|
|
with open(SINGED_CERTFILE_ONLY) as f:
|
|
|
|
expected_ee_cert = ssl.PEM_cert_to_DER_cert(f.read())
|
|
|
|
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(
|
|
|
|
socket.socket(),
|
|
|
|
server_hostname=hostname
|
|
|
|
) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
vc = s.get_verified_chain()
|
|
|
|
self.assertEqual(len(vc), 2)
|
|
|
|
|
|
|
|
ee, ca = vc
|
|
|
|
self.assertIsInstance(ee, bytes)
|
|
|
|
self.assertIsInstance(ca, bytes)
|
|
|
|
self.assertEqual(expected_ca_cert, ca)
|
|
|
|
self.assertEqual(expected_ee_cert, ee)
|
|
|
|
|
|
|
|
uvc = s.get_unverified_chain()
|
|
|
|
self.assertEqual(len(uvc), 1)
|
|
|
|
self.assertIsInstance(uvc[0], bytes)
|
|
|
|
|
|
|
|
self.assertEqual(ee, uvc[0])
|
|
|
|
self.assertNotEqual(ee, ca)
|
|
|
|
|
2021-04-26 10:01:40 -03:00
|
|
|
def test_internal_chain_server(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
client_context.load_cert_chain(SIGNED_CERTFILE)
|
|
|
|
server_context.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(
|
|
|
|
socket.socket(),
|
|
|
|
server_hostname=hostname
|
|
|
|
) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
s.write(b'VERIFIEDCHAIN\n')
|
|
|
|
res = s.recv(1024)
|
|
|
|
self.assertEqual(res, b'\x02\n')
|
|
|
|
s.write(b'UNVERIFIEDCHAIN\n')
|
|
|
|
res = s.recv(1024)
|
|
|
|
self.assertEqual(res, b'\x02\n')
|
|
|
|
|
2018-09-23 03:32:31 -03:00
|
|
|
|
2019-05-31 06:44:05 -03:00
|
|
|
HAS_KEYLOG = hasattr(ssl.SSLContext, 'keylog_filename')
|
|
|
|
requires_keylog = unittest.skipUnless(
|
|
|
|
HAS_KEYLOG, 'test requires OpenSSL 1.1.1 with keylog callback')
|
|
|
|
|
|
|
|
class TestSSLDebug(unittest.TestCase):
|
|
|
|
|
2020-08-03 13:41:24 -03:00
|
|
|
def keylog_lines(self, fname=os_helper.TESTFN):
|
2019-05-31 06:44:05 -03:00
|
|
|
with open(fname) as f:
|
|
|
|
return len(list(f))
|
|
|
|
|
|
|
|
@requires_keylog
|
2019-06-19 17:09:54 -03:00
|
|
|
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
|
2019-05-31 06:44:05 -03:00
|
|
|
def test_keylog_defaults(self):
|
2020-08-03 13:41:24 -03:00
|
|
|
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
2019-05-31 06:44:05 -03:00
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertEqual(ctx.keylog_filename, None)
|
|
|
|
|
2020-08-03 13:41:24 -03:00
|
|
|
self.assertFalse(os.path.isfile(os_helper.TESTFN))
|
|
|
|
ctx.keylog_filename = os_helper.TESTFN
|
|
|
|
self.assertEqual(ctx.keylog_filename, os_helper.TESTFN)
|
|
|
|
self.assertTrue(os.path.isfile(os_helper.TESTFN))
|
2019-05-31 06:44:05 -03:00
|
|
|
self.assertEqual(self.keylog_lines(), 1)
|
|
|
|
|
|
|
|
ctx.keylog_filename = None
|
|
|
|
self.assertEqual(ctx.keylog_filename, None)
|
|
|
|
|
|
|
|
with self.assertRaises((IsADirectoryError, PermissionError)):
|
|
|
|
# Windows raises PermissionError
|
|
|
|
ctx.keylog_filename = os.path.dirname(
|
2020-08-03 13:41:24 -03:00
|
|
|
os.path.abspath(os_helper.TESTFN))
|
2019-05-31 06:44:05 -03:00
|
|
|
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ctx.keylog_filename = 1
|
|
|
|
|
|
|
|
@requires_keylog
|
2019-06-19 17:09:54 -03:00
|
|
|
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
|
2019-05-31 06:44:05 -03:00
|
|
|
def test_keylog_filename(self):
|
2020-08-03 13:41:24 -03:00
|
|
|
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
2019-05-31 06:44:05 -03:00
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
|
2020-08-03 13:41:24 -03:00
|
|
|
client_context.keylog_filename = os_helper.TESTFN
|
2019-05-31 06:44:05 -03:00
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
# header, 5 lines for TLS 1.3
|
|
|
|
self.assertEqual(self.keylog_lines(), 6)
|
|
|
|
|
|
|
|
client_context.keylog_filename = None
|
2020-08-03 13:41:24 -03:00
|
|
|
server_context.keylog_filename = os_helper.TESTFN
|
2019-05-31 06:44:05 -03:00
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertGreaterEqual(self.keylog_lines(), 11)
|
|
|
|
|
2020-08-03 13:41:24 -03:00
|
|
|
client_context.keylog_filename = os_helper.TESTFN
|
|
|
|
server_context.keylog_filename = os_helper.TESTFN
|
2019-05-31 06:44:05 -03:00
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
self.assertGreaterEqual(self.keylog_lines(), 21)
|
|
|
|
|
|
|
|
client_context.keylog_filename = None
|
|
|
|
server_context.keylog_filename = None
|
|
|
|
|
|
|
|
@requires_keylog
|
|
|
|
@unittest.skipIf(sys.flags.ignore_environment,
|
|
|
|
"test is not compatible with ignore_environment")
|
2019-06-19 17:09:54 -03:00
|
|
|
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
|
2019-05-31 06:44:05 -03:00
|
|
|
def test_keylog_env(self):
|
2020-08-03 13:41:24 -03:00
|
|
|
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
2019-05-31 06:44:05 -03:00
|
|
|
with unittest.mock.patch.dict(os.environ):
|
2020-08-03 13:41:24 -03:00
|
|
|
os.environ['SSLKEYLOGFILE'] = os_helper.TESTFN
|
|
|
|
self.assertEqual(os.environ['SSLKEYLOGFILE'], os_helper.TESTFN)
|
2019-05-31 06:44:05 -03:00
|
|
|
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
|
self.assertEqual(ctx.keylog_filename, None)
|
|
|
|
|
|
|
|
ctx = ssl.create_default_context()
|
2020-08-03 13:41:24 -03:00
|
|
|
self.assertEqual(ctx.keylog_filename, os_helper.TESTFN)
|
2019-05-31 06:44:05 -03:00
|
|
|
|
|
|
|
ctx = ssl._create_stdlib_context()
|
2020-08-03 13:41:24 -03:00
|
|
|
self.assertEqual(ctx.keylog_filename, os_helper.TESTFN)
|
2019-05-31 06:44:05 -03:00
|
|
|
|
|
|
|
def test_msg_callback(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
|
|
|
|
def msg_cb(conn, direction, version, content_type, msg_type, data):
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.assertIs(client_context._msg_callback, None)
|
|
|
|
client_context._msg_callback = msg_cb
|
|
|
|
self.assertIs(client_context._msg_callback, msg_cb)
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
client_context._msg_callback = object()
|
|
|
|
|
|
|
|
def test_msg_callback_tls12(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
2021-06-13 08:46:07 -03:00
|
|
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
2019-05-31 06:44:05 -03:00
|
|
|
|
|
|
|
msg = []
|
|
|
|
|
|
|
|
def msg_cb(conn, direction, version, content_type, msg_type, data):
|
|
|
|
self.assertIsInstance(conn, ssl.SSLSocket)
|
|
|
|
self.assertIsInstance(data, bytes)
|
|
|
|
self.assertIn(direction, {'read', 'write'})
|
|
|
|
msg.append((direction, version, content_type, msg_type))
|
|
|
|
|
|
|
|
client_context._msg_callback = msg_cb
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
2019-06-03 15:40:15 -03:00
|
|
|
self.assertIn(
|
2019-05-31 06:44:05 -03:00
|
|
|
("read", TLSVersion.TLSv1_2, _TLSContentType.HANDSHAKE,
|
|
|
|
_TLSMessageType.SERVER_KEY_EXCHANGE),
|
2019-06-03 15:40:15 -03:00
|
|
|
msg
|
|
|
|
)
|
|
|
|
self.assertIn(
|
2019-05-31 06:44:05 -03:00
|
|
|
("write", TLSVersion.TLSv1_2, _TLSContentType.CHANGE_CIPHER_SPEC,
|
|
|
|
_TLSMessageType.CHANGE_CIPHER_SPEC),
|
2019-06-03 15:40:15 -03:00
|
|
|
msg
|
|
|
|
)
|
2019-05-31 06:44:05 -03:00
|
|
|
|
2021-03-21 12:13:09 -03:00
|
|
|
def test_msg_callback_deadlock_bpo43577(self):
|
|
|
|
client_context, server_context, hostname = testing_context()
|
|
|
|
server_context2 = testing_context()[1]
|
|
|
|
|
|
|
|
def msg_cb(conn, direction, version, content_type, msg_type, data):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def sni_cb(sock, servername, ctx):
|
|
|
|
sock.context = server_context2
|
|
|
|
|
|
|
|
server_context._msg_callback = msg_cb
|
|
|
|
server_context.sni_callback = sni_cb
|
|
|
|
|
|
|
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
|
|
|
with server:
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
with client_context.wrap_socket(socket.socket(),
|
|
|
|
server_hostname=hostname) as s:
|
|
|
|
s.connect((HOST, server.port))
|
|
|
|
|
2019-05-31 06:44:05 -03:00
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
def set_socket_so_linger_on_with_zero_timeout(sock):
|
|
|
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
|
|
|
|
|
|
|
|
|
|
|
|
class TestPreHandshakeClose(unittest.TestCase):
|
|
|
|
"""Verify behavior of close sockets with received data before to the handshake.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class SingleConnectionTestServerThread(threading.Thread):
|
|
|
|
|
2023-08-23 18:57:11 -03:00
|
|
|
def __init__(self, *, name, call_after_accept, timeout=None):
|
2023-08-22 14:53:15 -03:00
|
|
|
self.call_after_accept = call_after_accept
|
|
|
|
self.received_data = b'' # set by .run()
|
|
|
|
self.wrap_error = None # set by .run()
|
|
|
|
self.listener = None # set by .start()
|
|
|
|
self.port = None # set by .start()
|
2023-08-23 18:57:11 -03:00
|
|
|
if timeout is None:
|
|
|
|
self.timeout = support.SHORT_TIMEOUT
|
|
|
|
else:
|
|
|
|
self.timeout = timeout
|
2023-08-22 14:53:15 -03:00
|
|
|
super().__init__(name=name)
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.start()
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
try:
|
|
|
|
if self.listener:
|
|
|
|
self.listener.close()
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
self.join()
|
|
|
|
self.wrap_error = None # avoid dangling references
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
|
|
|
self.ssl_ctx.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
self.ssl_ctx.load_verify_locations(cafile=ONLYCERT)
|
|
|
|
self.ssl_ctx.load_cert_chain(certfile=ONLYCERT, keyfile=ONLYKEY)
|
|
|
|
self.listener = socket.socket()
|
|
|
|
self.port = socket_helper.bind_port(self.listener)
|
2023-08-23 18:57:11 -03:00
|
|
|
self.listener.settimeout(self.timeout)
|
2023-08-22 14:53:15 -03:00
|
|
|
self.listener.listen(1)
|
|
|
|
super().start()
|
|
|
|
|
|
|
|
def run(self):
|
2023-08-23 18:57:11 -03:00
|
|
|
try:
|
|
|
|
conn, address = self.listener.accept()
|
|
|
|
except TimeoutError:
|
|
|
|
# on timeout, just close the listener
|
|
|
|
return
|
|
|
|
finally:
|
|
|
|
self.listener.close()
|
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
with conn:
|
|
|
|
if self.call_after_accept(conn):
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
tls_socket = self.ssl_ctx.wrap_socket(conn, server_side=True)
|
|
|
|
except OSError as err: # ssl.SSLError inherits from OSError
|
|
|
|
self.wrap_error = err
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.received_data = tls_socket.recv(400)
|
|
|
|
except OSError:
|
|
|
|
pass # closed, protocol error, etc.
|
|
|
|
|
|
|
|
def non_linux_skip_if_other_okay_error(self, err):
|
2024-03-11 16:25:39 -03:00
|
|
|
if sys.platform in ("linux", "android"):
|
2023-08-22 14:53:15 -03:00
|
|
|
return # Expect the full test setup to always work on Linux.
|
|
|
|
if (isinstance(err, ConnectionResetError) or
|
|
|
|
(isinstance(err, OSError) and err.errno == errno.EINVAL) or
|
2024-11-07 06:06:27 -04:00
|
|
|
re.search('wrong.version.number', str(getattr(err, "reason", "")), re.I)):
|
2023-08-22 14:53:15 -03:00
|
|
|
# On Windows the TCP RST leads to a ConnectionResetError
|
|
|
|
# (ECONNRESET) which Linux doesn't appear to surface to userspace.
|
|
|
|
# If wrap_socket() winds up on the "if connected:" path and doing
|
|
|
|
# the actual wrapping... we get an SSLError from OpenSSL. Typically
|
|
|
|
# WRONG_VERSION_NUMBER. While appropriate, neither is the scenario
|
|
|
|
# we're specifically trying to test. The way this test is written
|
|
|
|
# is known to work on Linux. We'll skip it anywhere else that it
|
|
|
|
# does not present as doing so.
|
2023-08-23 18:57:11 -03:00
|
|
|
try:
|
|
|
|
self.skipTest(f"Could not recreate conditions on {sys.platform}:"
|
|
|
|
f" {err=}")
|
|
|
|
finally:
|
|
|
|
# gh-108342: Explicitly break the reference cycle
|
|
|
|
err = None
|
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
# If maintaining this conditional winds up being a problem.
|
|
|
|
# just turn this into an unconditional skip anything but Linux.
|
|
|
|
# The important thing is that our CI has the logic covered.
|
|
|
|
|
|
|
|
def test_preauth_data_to_tls_server(self):
|
|
|
|
server_accept_called = threading.Event()
|
|
|
|
ready_for_server_wrap_socket = threading.Event()
|
|
|
|
|
|
|
|
def call_after_accept(unused):
|
|
|
|
server_accept_called.set()
|
2023-08-23 18:57:11 -03:00
|
|
|
if not ready_for_server_wrap_socket.wait(support.SHORT_TIMEOUT):
|
2023-08-22 14:53:15 -03:00
|
|
|
raise RuntimeError("wrap_socket event never set, test may fail.")
|
|
|
|
return False # Tell the server thread to continue.
|
|
|
|
|
|
|
|
server = self.SingleConnectionTestServerThread(
|
|
|
|
call_after_accept=call_after_accept,
|
|
|
|
name="preauth_data_to_tls_server")
|
|
|
|
self.enterContext(server) # starts it & unittest.TestCase stops it.
|
|
|
|
|
|
|
|
with socket.socket() as client:
|
|
|
|
client.connect(server.listener.getsockname())
|
|
|
|
# This forces an immediate connection close via RST on .close().
|
|
|
|
set_socket_so_linger_on_with_zero_timeout(client)
|
|
|
|
client.setblocking(False)
|
|
|
|
|
|
|
|
server_accept_called.wait()
|
|
|
|
client.send(b"DELETE /data HTTP/1.0\r\n\r\n")
|
|
|
|
client.close() # RST
|
|
|
|
|
|
|
|
ready_for_server_wrap_socket.set()
|
|
|
|
server.join()
|
2023-08-23 18:57:11 -03:00
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
wrap_error = server.wrap_error
|
2023-08-23 18:57:11 -03:00
|
|
|
server.wrap_error = None
|
|
|
|
try:
|
|
|
|
self.assertEqual(b"", server.received_data)
|
|
|
|
self.assertIsInstance(wrap_error, OSError) # All platforms.
|
|
|
|
self.non_linux_skip_if_other_okay_error(wrap_error)
|
|
|
|
self.assertIsInstance(wrap_error, ssl.SSLError)
|
|
|
|
self.assertIn("before TLS handshake with data", wrap_error.args[1])
|
|
|
|
self.assertIn("before TLS handshake with data", wrap_error.reason)
|
|
|
|
self.assertNotEqual(0, wrap_error.args[0])
|
|
|
|
self.assertIsNone(wrap_error.library, msg="attr must exist")
|
|
|
|
finally:
|
|
|
|
# gh-108342: Explicitly break the reference cycle
|
|
|
|
wrap_error = None
|
|
|
|
server = None
|
2023-08-22 14:53:15 -03:00
|
|
|
|
|
|
|
def test_preauth_data_to_tls_client(self):
|
2023-08-23 18:57:11 -03:00
|
|
|
server_can_continue_with_wrap_socket = threading.Event()
|
2023-08-22 14:53:15 -03:00
|
|
|
client_can_continue_with_wrap_socket = threading.Event()
|
|
|
|
|
|
|
|
def call_after_accept(conn_to_client):
|
2023-08-23 18:57:11 -03:00
|
|
|
if not server_can_continue_with_wrap_socket.wait(support.SHORT_TIMEOUT):
|
|
|
|
print("ERROR: test client took too long")
|
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
# This forces an immediate connection close via RST on .close().
|
|
|
|
set_socket_so_linger_on_with_zero_timeout(conn_to_client)
|
|
|
|
conn_to_client.send(
|
|
|
|
b"HTTP/1.0 307 Temporary Redirect\r\n"
|
|
|
|
b"Location: https://example.com/someone-elses-server\r\n"
|
|
|
|
b"\r\n")
|
|
|
|
conn_to_client.close() # RST
|
|
|
|
client_can_continue_with_wrap_socket.set()
|
|
|
|
return True # Tell the server to stop.
|
|
|
|
|
|
|
|
server = self.SingleConnectionTestServerThread(
|
|
|
|
call_after_accept=call_after_accept,
|
|
|
|
name="preauth_data_to_tls_client")
|
|
|
|
self.enterContext(server) # starts it & unittest.TestCase stops it.
|
|
|
|
# Redundant; call_after_accept sets SO_LINGER on the accepted conn.
|
|
|
|
set_socket_so_linger_on_with_zero_timeout(server.listener)
|
|
|
|
|
|
|
|
with socket.socket() as client:
|
|
|
|
client.connect(server.listener.getsockname())
|
2023-08-23 18:57:11 -03:00
|
|
|
server_can_continue_with_wrap_socket.set()
|
|
|
|
|
|
|
|
if not client_can_continue_with_wrap_socket.wait(support.SHORT_TIMEOUT):
|
|
|
|
self.fail("test server took too long")
|
2023-08-22 14:53:15 -03:00
|
|
|
ssl_ctx = ssl.create_default_context()
|
|
|
|
try:
|
|
|
|
tls_client = ssl_ctx.wrap_socket(
|
|
|
|
client, server_hostname="localhost")
|
|
|
|
except OSError as err: # SSLError inherits from OSError
|
|
|
|
wrap_error = err
|
|
|
|
received_data = b""
|
|
|
|
else:
|
|
|
|
wrap_error = None
|
|
|
|
received_data = tls_client.recv(400)
|
|
|
|
tls_client.close()
|
|
|
|
|
|
|
|
server.join()
|
2023-08-23 18:57:11 -03:00
|
|
|
try:
|
|
|
|
self.assertEqual(b"", received_data)
|
|
|
|
self.assertIsInstance(wrap_error, OSError) # All platforms.
|
|
|
|
self.non_linux_skip_if_other_okay_error(wrap_error)
|
|
|
|
self.assertIsInstance(wrap_error, ssl.SSLError)
|
|
|
|
self.assertIn("before TLS handshake with data", wrap_error.args[1])
|
|
|
|
self.assertIn("before TLS handshake with data", wrap_error.reason)
|
|
|
|
self.assertNotEqual(0, wrap_error.args[0])
|
|
|
|
self.assertIsNone(wrap_error.library, msg="attr must exist")
|
|
|
|
finally:
|
|
|
|
# gh-108342: Explicitly break the reference cycle
|
2024-02-04 11:28:07 -04:00
|
|
|
with warnings_helper.check_no_resource_warning(self):
|
|
|
|
wrap_error = None
|
2023-08-23 18:57:11 -03:00
|
|
|
server = None
|
2023-08-22 14:53:15 -03:00
|
|
|
|
|
|
|
def test_https_client_non_tls_response_ignored(self):
|
|
|
|
server_responding = threading.Event()
|
|
|
|
|
|
|
|
class SynchronizedHTTPSConnection(http.client.HTTPSConnection):
|
|
|
|
def connect(self):
|
2023-08-23 18:57:11 -03:00
|
|
|
# Call clear text HTTP connect(), not the encrypted HTTPS (TLS)
|
|
|
|
# connect(): wrap_socket() is called manually below.
|
2023-08-22 14:53:15 -03:00
|
|
|
http.client.HTTPConnection.connect(self)
|
2023-08-23 18:57:11 -03:00
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
# Wait for our fault injection server to have done its thing.
|
2023-08-23 18:57:11 -03:00
|
|
|
if not server_responding.wait(support.SHORT_TIMEOUT) and support.verbose:
|
2023-08-22 14:53:15 -03:00
|
|
|
sys.stdout.write("server_responding event never set.")
|
|
|
|
self.sock = self._context.wrap_socket(
|
|
|
|
self.sock, server_hostname=self.host)
|
|
|
|
|
|
|
|
def call_after_accept(conn_to_client):
|
|
|
|
# This forces an immediate connection close via RST on .close().
|
|
|
|
set_socket_so_linger_on_with_zero_timeout(conn_to_client)
|
|
|
|
conn_to_client.send(
|
|
|
|
b"HTTP/1.0 402 Payment Required\r\n"
|
|
|
|
b"\r\n")
|
|
|
|
conn_to_client.close() # RST
|
|
|
|
server_responding.set()
|
|
|
|
return True # Tell the server to stop.
|
|
|
|
|
2023-08-23 18:57:11 -03:00
|
|
|
timeout = 2.0
|
2023-08-22 14:53:15 -03:00
|
|
|
server = self.SingleConnectionTestServerThread(
|
|
|
|
call_after_accept=call_after_accept,
|
2023-08-23 18:57:11 -03:00
|
|
|
name="non_tls_http_RST_responder",
|
|
|
|
timeout=timeout)
|
2023-08-22 14:53:15 -03:00
|
|
|
self.enterContext(server) # starts it & unittest.TestCase stops it.
|
|
|
|
# Redundant; call_after_accept sets SO_LINGER on the accepted conn.
|
|
|
|
set_socket_so_linger_on_with_zero_timeout(server.listener)
|
|
|
|
|
|
|
|
connection = SynchronizedHTTPSConnection(
|
2023-08-23 18:57:11 -03:00
|
|
|
server.listener.getsockname()[0],
|
2023-08-22 14:53:15 -03:00
|
|
|
port=server.port,
|
|
|
|
context=ssl.create_default_context(),
|
2023-08-23 18:57:11 -03:00
|
|
|
timeout=timeout,
|
2023-08-22 14:53:15 -03:00
|
|
|
)
|
2023-08-23 18:57:11 -03:00
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
# There are lots of reasons this raises as desired, long before this
|
|
|
|
# test was added. Sending the request requires a successful TLS wrapped
|
|
|
|
# socket; that fails if the connection is broken. It may seem pointless
|
|
|
|
# to test this. It serves as an illustration of something that we never
|
|
|
|
# want to happen... properly not happening.
|
2024-02-04 11:28:07 -04:00
|
|
|
with warnings_helper.check_no_resource_warning(self), \
|
|
|
|
self.assertRaises(OSError):
|
2023-08-22 14:53:15 -03:00
|
|
|
connection.request("HEAD", "/test", headers={"Host": "localhost"})
|
|
|
|
response = connection.getresponse()
|
|
|
|
|
2023-08-23 18:57:11 -03:00
|
|
|
server.join()
|
|
|
|
|
2023-08-22 14:53:15 -03:00
|
|
|
|
2021-04-21 14:20:44 -03:00
|
|
|
class TestEnumerations(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_tlsversion(self):
|
|
|
|
class CheckedTLSVersion(enum.IntEnum):
|
|
|
|
MINIMUM_SUPPORTED = _ssl.PROTO_MINIMUM_SUPPORTED
|
|
|
|
SSLv3 = _ssl.PROTO_SSLv3
|
|
|
|
TLSv1 = _ssl.PROTO_TLSv1
|
|
|
|
TLSv1_1 = _ssl.PROTO_TLSv1_1
|
|
|
|
TLSv1_2 = _ssl.PROTO_TLSv1_2
|
|
|
|
TLSv1_3 = _ssl.PROTO_TLSv1_3
|
|
|
|
MAXIMUM_SUPPORTED = _ssl.PROTO_MAXIMUM_SUPPORTED
|
|
|
|
enum._test_simple_enum(CheckedTLSVersion, TLSVersion)
|
|
|
|
|
|
|
|
def test_tlscontenttype(self):
|
|
|
|
class Checked_TLSContentType(enum.IntEnum):
|
|
|
|
"""Content types (record layer)
|
|
|
|
|
|
|
|
See RFC 8446, section B.1
|
|
|
|
"""
|
|
|
|
CHANGE_CIPHER_SPEC = 20
|
|
|
|
ALERT = 21
|
|
|
|
HANDSHAKE = 22
|
|
|
|
APPLICATION_DATA = 23
|
|
|
|
# pseudo content types
|
|
|
|
HEADER = 0x100
|
|
|
|
INNER_CONTENT_TYPE = 0x101
|
|
|
|
enum._test_simple_enum(Checked_TLSContentType, _TLSContentType)
|
|
|
|
|
|
|
|
def test_tlsalerttype(self):
|
|
|
|
class Checked_TLSAlertType(enum.IntEnum):
|
|
|
|
"""Alert types for TLSContentType.ALERT messages
|
|
|
|
|
|
|
|
See RFC 8466, section B.2
|
|
|
|
"""
|
|
|
|
CLOSE_NOTIFY = 0
|
|
|
|
UNEXPECTED_MESSAGE = 10
|
|
|
|
BAD_RECORD_MAC = 20
|
|
|
|
DECRYPTION_FAILED = 21
|
|
|
|
RECORD_OVERFLOW = 22
|
|
|
|
DECOMPRESSION_FAILURE = 30
|
|
|
|
HANDSHAKE_FAILURE = 40
|
|
|
|
NO_CERTIFICATE = 41
|
|
|
|
BAD_CERTIFICATE = 42
|
|
|
|
UNSUPPORTED_CERTIFICATE = 43
|
|
|
|
CERTIFICATE_REVOKED = 44
|
|
|
|
CERTIFICATE_EXPIRED = 45
|
|
|
|
CERTIFICATE_UNKNOWN = 46
|
|
|
|
ILLEGAL_PARAMETER = 47
|
|
|
|
UNKNOWN_CA = 48
|
|
|
|
ACCESS_DENIED = 49
|
|
|
|
DECODE_ERROR = 50
|
|
|
|
DECRYPT_ERROR = 51
|
|
|
|
EXPORT_RESTRICTION = 60
|
|
|
|
PROTOCOL_VERSION = 70
|
|
|
|
INSUFFICIENT_SECURITY = 71
|
|
|
|
INTERNAL_ERROR = 80
|
|
|
|
INAPPROPRIATE_FALLBACK = 86
|
|
|
|
USER_CANCELED = 90
|
|
|
|
NO_RENEGOTIATION = 100
|
|
|
|
MISSING_EXTENSION = 109
|
|
|
|
UNSUPPORTED_EXTENSION = 110
|
|
|
|
CERTIFICATE_UNOBTAINABLE = 111
|
|
|
|
UNRECOGNIZED_NAME = 112
|
|
|
|
BAD_CERTIFICATE_STATUS_RESPONSE = 113
|
|
|
|
BAD_CERTIFICATE_HASH_VALUE = 114
|
|
|
|
UNKNOWN_PSK_IDENTITY = 115
|
|
|
|
CERTIFICATE_REQUIRED = 116
|
|
|
|
NO_APPLICATION_PROTOCOL = 120
|
|
|
|
enum._test_simple_enum(Checked_TLSAlertType, _TLSAlertType)
|
|
|
|
|
|
|
|
def test_tlsmessagetype(self):
|
|
|
|
class Checked_TLSMessageType(enum.IntEnum):
|
|
|
|
"""Message types (handshake protocol)
|
|
|
|
|
|
|
|
See RFC 8446, section B.3
|
|
|
|
"""
|
|
|
|
HELLO_REQUEST = 0
|
|
|
|
CLIENT_HELLO = 1
|
|
|
|
SERVER_HELLO = 2
|
|
|
|
HELLO_VERIFY_REQUEST = 3
|
|
|
|
NEWSESSION_TICKET = 4
|
|
|
|
END_OF_EARLY_DATA = 5
|
|
|
|
HELLO_RETRY_REQUEST = 6
|
|
|
|
ENCRYPTED_EXTENSIONS = 8
|
|
|
|
CERTIFICATE = 11
|
|
|
|
SERVER_KEY_EXCHANGE = 12
|
|
|
|
CERTIFICATE_REQUEST = 13
|
|
|
|
SERVER_DONE = 14
|
|
|
|
CERTIFICATE_VERIFY = 15
|
|
|
|
CLIENT_KEY_EXCHANGE = 16
|
|
|
|
FINISHED = 20
|
|
|
|
CERTIFICATE_URL = 21
|
|
|
|
CERTIFICATE_STATUS = 22
|
|
|
|
SUPPLEMENTAL_DATA = 23
|
|
|
|
KEY_UPDATE = 24
|
|
|
|
NEXT_PROTO = 67
|
|
|
|
MESSAGE_HASH = 254
|
|
|
|
CHANGE_CIPHER_SPEC = 0x0101
|
|
|
|
enum._test_simple_enum(Checked_TLSMessageType, _TLSMessageType)
|
|
|
|
|
|
|
|
def test_sslmethod(self):
|
|
|
|
Checked_SSLMethod = enum._old_convert_(
|
|
|
|
enum.IntEnum, '_SSLMethod', 'ssl',
|
|
|
|
lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23',
|
|
|
|
source=ssl._ssl,
|
|
|
|
)
|
2021-09-15 13:57:03 -03:00
|
|
|
# This member is assigned dynamically in `ssl.py`:
|
|
|
|
Checked_SSLMethod.PROTOCOL_SSLv23 = Checked_SSLMethod.PROTOCOL_TLS
|
2021-04-21 14:20:44 -03:00
|
|
|
enum._test_simple_enum(Checked_SSLMethod, ssl._SSLMethod)
|
|
|
|
|
|
|
|
def test_options(self):
|
|
|
|
CheckedOptions = enum._old_convert_(
|
2021-09-15 13:57:03 -03:00
|
|
|
enum.IntFlag, 'Options', 'ssl',
|
2021-04-21 14:20:44 -03:00
|
|
|
lambda name: name.startswith('OP_'),
|
|
|
|
source=ssl._ssl,
|
|
|
|
)
|
|
|
|
enum._test_simple_enum(CheckedOptions, ssl.Options)
|
|
|
|
|
|
|
|
def test_alertdescription(self):
|
|
|
|
CheckedAlertDescription = enum._old_convert_(
|
|
|
|
enum.IntEnum, 'AlertDescription', 'ssl',
|
|
|
|
lambda name: name.startswith('ALERT_DESCRIPTION_'),
|
|
|
|
source=ssl._ssl,
|
|
|
|
)
|
|
|
|
enum._test_simple_enum(CheckedAlertDescription, ssl.AlertDescription)
|
|
|
|
|
|
|
|
def test_sslerrornumber(self):
|
2021-09-15 13:57:03 -03:00
|
|
|
Checked_SSLErrorNumber = enum._old_convert_(
|
|
|
|
enum.IntEnum, 'SSLErrorNumber', 'ssl',
|
|
|
|
lambda name: name.startswith('SSL_ERROR_'),
|
2021-04-21 14:20:44 -03:00
|
|
|
source=ssl._ssl,
|
|
|
|
)
|
2021-09-15 13:57:03 -03:00
|
|
|
enum._test_simple_enum(Checked_SSLErrorNumber, ssl.SSLErrorNumber)
|
2021-04-21 14:20:44 -03:00
|
|
|
|
|
|
|
def test_verifyflags(self):
|
|
|
|
CheckedVerifyFlags = enum._old_convert_(
|
2021-09-15 13:57:03 -03:00
|
|
|
enum.IntFlag, 'VerifyFlags', 'ssl',
|
2021-04-21 14:20:44 -03:00
|
|
|
lambda name: name.startswith('VERIFY_'),
|
|
|
|
source=ssl._ssl,
|
|
|
|
)
|
|
|
|
enum._test_simple_enum(CheckedVerifyFlags, ssl.VerifyFlags)
|
|
|
|
|
|
|
|
def test_verifymode(self):
|
|
|
|
CheckedVerifyMode = enum._old_convert_(
|
|
|
|
enum.IntEnum, 'VerifyMode', 'ssl',
|
|
|
|
lambda name: name.startswith('CERT_'),
|
|
|
|
source=ssl._ssl,
|
|
|
|
)
|
|
|
|
enum._test_simple_enum(CheckedVerifyMode, ssl.VerifyMode)
|
|
|
|
|
2021-09-15 13:57:03 -03:00
|
|
|
|
2021-09-19 09:27:33 -03:00
|
|
|
def setUpModule():
|
2010-08-04 13:45:21 -03:00
|
|
|
if support.verbose:
|
|
|
|
plats = {
|
|
|
|
'Mac': platform.mac_ver,
|
|
|
|
'Windows': platform.win32_ver,
|
|
|
|
}
|
2018-05-16 12:51:18 -03:00
|
|
|
for name, func in plats.items():
|
|
|
|
plat = func()
|
|
|
|
if plat and plat[0]:
|
|
|
|
plat = '%s %r' % (name, plat)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
plat = repr(platform.platform())
|
2010-08-04 13:45:21 -03:00
|
|
|
print("test_ssl: testing with %r %r" %
|
|
|
|
(ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO))
|
|
|
|
print(" under %s" % plat)
|
2010-10-22 15:19:07 -03:00
|
|
|
print(" HAS_SNI = %r" % ssl.HAS_SNI)
|
2013-03-29 14:09:06 -03:00
|
|
|
print(" OP_ALL = 0x%8x" % ssl.OP_ALL)
|
|
|
|
try:
|
|
|
|
print(" OP_NO_TLSv1_1 = 0x%8x" % ssl.OP_NO_TLSv1_1)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2010-08-04 13:45:21 -03:00
|
|
|
|
2010-05-16 15:19:27 -03:00
|
|
|
for filename in [
|
2016-03-26 22:53:46 -03:00
|
|
|
CERTFILE, BYTES_CERTFILE,
|
2010-05-16 15:19:27 -03:00
|
|
|
ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY,
|
2013-01-05 16:20:29 -04:00
|
|
|
SIGNED_CERTFILE, SIGNED_CERTFILE2, SIGNING_CA,
|
2010-05-16 15:19:27 -03:00
|
|
|
BADCERT, BADKEY, EMPTYCERT]:
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
raise support.TestFailed("Can't read certificate file %r" % filename)
|
2007-11-15 18:23:56 -04:00
|
|
|
|
2020-05-27 19:10:27 -03:00
|
|
|
thread_info = threading_helper.threading_setup()
|
2021-09-19 09:27:33 -03:00
|
|
|
unittest.addModuleCleanup(threading_helper.threading_cleanup, *thread_info)
|
|
|
|
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 18:37:11 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-09-19 09:27:33 -03:00
|
|
|
unittest.main()
|