diff options
author | Christian Heimes <christian@python.org> | 2022-01-13 08:46:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 08:46:38 (GMT) |
commit | 443b308fee088e21bbf472c376c5c9e3648f916c (patch) | |
tree | d9a0955f1967f9febb6d17806eb7d0d18b55d2ba /Lib/test | |
parent | a6ca8eee2254762422f90cf94fbaac34f85db780 (diff) | |
download | cpython-443b308fee088e21bbf472c376c5c9e3648f916c.zip cpython-443b308fee088e21bbf472c376c5c9e3648f916c.tar.gz cpython-443b308fee088e21bbf472c376c5c9e3648f916c.tar.bz2 |
bpo-40479: Fix hashlib's usedforsecurity for OpenSSL 3.0.0 (GH-30455)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_hashlib.py | 13 | ||||
-rw-r--r-- | Lib/test/test_imaplib.py | 6 | ||||
-rw-r--r-- | Lib/test/test_poplib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_smtplib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_tools/test_md5sum.py | 2 | ||||
-rw-r--r-- | Lib/test/test_urllib2_localnet.py | 2 |
6 files changed, 16 insertions, 15 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 1623bf3..110eb48 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -48,12 +48,15 @@ else: builtin_hashlib = None try: - from _hashlib import HASH, HASHXOF, openssl_md_meth_names + from _hashlib import HASH, HASHXOF, openssl_md_meth_names, get_fips_mode except ImportError: HASH = None HASHXOF = None openssl_md_meth_names = frozenset() + def get_fips_mode(): + return 0 + try: import _blake2 except ImportError: @@ -192,10 +195,7 @@ class HashLibTestCase(unittest.TestCase): @property def is_fips_mode(self): - if hasattr(self._hashlib, "get_fips_mode"): - return self._hashlib.get_fips_mode() - else: - return None + return get_fips_mode() def test_hash_array(self): a = array.array("b", range(10)) @@ -1017,7 +1017,7 @@ class KDFTests(unittest.TestCase): self.assertEqual(out, expected, (digest_name, password, salt, rounds)) - with self.assertRaisesRegex(ValueError, 'unsupported hash type'): + with self.assertRaisesRegex(ValueError, '.*unsupported.*'): pbkdf2('unknown', b'pass', b'salt', 1) if 'sha1' in supported: @@ -1057,6 +1057,7 @@ class KDFTests(unittest.TestCase): @unittest.skipUnless(hasattr(hashlib, 'scrypt'), ' test requires OpenSSL > 1.1') + @unittest.skipIf(get_fips_mode(), reason="scrypt is blocked in FIPS mode") def test_scrypt(self): for password, salt, n, r, p, expected in self.scrypt_test_vectors: result = hashlib.scrypt(password, salt=salt, n=n, r=r, p=p) diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index c2b935f..30b5537 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -387,7 +387,7 @@ class NewIMAPTestsMixin(): self.assertEqual(code, 'OK') self.assertEqual(server.response, b'ZmFrZQ==\r\n') # b64 encoded 'fake' - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def test_login_cram_md5_bytes(self): class AuthHandler(SimpleIMAPHandler): capabilities = 'LOGINDISABLED AUTH=CRAM-MD5' @@ -405,7 +405,7 @@ class NewIMAPTestsMixin(): ret, _ = client.login_cram_md5("tim", b"tanstaaftanstaaf") self.assertEqual(ret, "OK") - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def test_login_cram_md5_plain_text(self): class AuthHandler(SimpleIMAPHandler): capabilities = 'LOGINDISABLED AUTH=CRAM-MD5' @@ -851,7 +851,7 @@ class ThreadedNetworkedTests(unittest.TestCase): b'ZmFrZQ==\r\n') # b64 encoded 'fake' @threading_helper.reap_threads - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def test_login_cram_md5(self): class AuthHandler(SimpleIMAPHandler): diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py index 44cf523..1220ca3 100644 --- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -318,11 +318,11 @@ class TestPOP3Class(TestCase): def test_rpop(self): self.assertOK(self.client.rpop('foo')) - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def test_apop_normal(self): self.assertOK(self.client.apop('foo', 'dummypassword')) - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def test_apop_REDOS(self): # Replace welcome with very long evil welcome. # NB The upper bound on welcome length is currently 2048. diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 9761a37..1a60fef 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -1171,7 +1171,7 @@ class SMTPSimTests(unittest.TestCase): finally: smtp.close() - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def testAUTH_CRAM_MD5(self): self.serv.add_feature("AUTH CRAM-MD5") smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', @@ -1180,7 +1180,7 @@ class SMTPSimTests(unittest.TestCase): self.assertEqual(resp, (235, b'Authentication Succeeded')) smtp.close() - @hashlib_helper.requires_hashdigest('md5') + @hashlib_helper.requires_hashdigest('md5', openssl=True) def testAUTH_multiple(self): # Test that multiple authentication methods are tried. self.serv.add_feature("AUTH BOGUS PLAIN LOGIN CRAM-MD5") diff --git a/Lib/test/test_tools/test_md5sum.py b/Lib/test/test_tools/test_md5sum.py index 92315f1..c5a230e 100644 --- a/Lib/test/test_tools/test_md5sum.py +++ b/Lib/test/test_tools/test_md5sum.py @@ -11,7 +11,7 @@ from test.test_tools import scriptsdir, skip_if_missing skip_if_missing() -@hashlib_helper.requires_hashdigest('md5') +@hashlib_helper.requires_hashdigest('md5', openssl=True) class MD5SumTests(unittest.TestCase): @classmethod def setUpClass(cls): diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index 36fb05d..0b2d07c 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -317,7 +317,7 @@ class BasicAuthTests(unittest.TestCase): self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, self.server_url) -@hashlib_helper.requires_hashdigest("md5") +@hashlib_helper.requires_hashdigest("md5", openssl=True) class ProxyAuthTests(unittest.TestCase): URL = "http://localhost" |