|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
From ecc5137120f471c22ff6dcb1bd128561c31e023c Mon Sep 17 00:00:00 2001
|
|
|
|
|
From 4345f8ea8a56a58ef8a48439c0e201702d1012a2 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
|
Date: Thu, 12 Dec 2019 16:58:31 +0100
|
|
|
|
|
Subject: [PATCH 1/7] Expose blake2b and blake2s hashes from OpenSSL
|
|
|
|
@ -205,10 +205,10 @@ index 5d84f4a..011026a 100644
|
|
|
|
|
-/*[clinic end generated code: output=69f2374071bff707 input=a9049054013a1b77]*/
|
|
|
|
|
+/*[clinic end generated code: output=c6a9af5563972eda input=a9049054013a1b77]*/
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 0198d467525e79cb4be4418708719af3eaee7a40 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From 1f79be1a11ad6811913c239da980c5bab0f1c538 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
|
Date: Thu, 1 Aug 2019 17:57:05 +0200
|
|
|
|
|
Subject: [PATCH 2/7] Use a stronger hash in multiprocessing handshake
|
|
|
|
@ -220,7 +220,7 @@ https://bugs.python.org/issue17258
|
|
|
|
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
|
|
|
|
|
|
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
|
|
|
|
|
index 8b81f99..69c0b7e 100644
|
|
|
|
|
index 59c61d2..7fc594e 100644
|
|
|
|
|
--- a/Lib/multiprocessing/connection.py
|
|
|
|
|
+++ b/Lib/multiprocessing/connection.py
|
|
|
|
|
@@ -43,6 +43,10 @@ BUFSIZE = 8192
|
|
|
|
@ -234,7 +234,7 @@ index 8b81f99..69c0b7e 100644
|
|
|
|
|
_mmap_counter = itertools.count()
|
|
|
|
|
|
|
|
|
|
default_family = 'AF_INET'
|
|
|
|
|
@@ -752,7 +756,7 @@ def deliver_challenge(connection, authkey):
|
|
|
|
|
@@ -753,7 +757,7 @@ def deliver_challenge(connection, authkey):
|
|
|
|
|
"Authkey must be bytes, not {0!s}".format(type(authkey)))
|
|
|
|
|
message = os.urandom(MESSAGE_LENGTH)
|
|
|
|
|
connection.send_bytes(CHALLENGE + message)
|
|
|
|
@ -243,7 +243,7 @@ index 8b81f99..69c0b7e 100644
|
|
|
|
|
response = connection.recv_bytes(256) # reject large message
|
|
|
|
|
if response == digest:
|
|
|
|
|
connection.send_bytes(WELCOME)
|
|
|
|
|
@@ -768,7 +772,7 @@ def answer_challenge(connection, authkey):
|
|
|
|
|
@@ -769,7 +773,7 @@ def answer_challenge(connection, authkey):
|
|
|
|
|
message = connection.recv_bytes(256) # reject large message
|
|
|
|
|
assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' % message
|
|
|
|
|
message = message[len(CHALLENGE):]
|
|
|
|
@ -253,10 +253,10 @@ index 8b81f99..69c0b7e 100644
|
|
|
|
|
response = connection.recv_bytes(256) # reject large message
|
|
|
|
|
if response != WELCOME:
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From a7822e2e1f21529e9730885bd8c9c6ab7c704d5b Mon Sep 17 00:00:00 2001
|
|
|
|
|
From e069ed2dcd0edf0de489eb387267fb35a92ed506 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
|
Date: Thu, 25 Jul 2019 17:19:06 +0200
|
|
|
|
|
Subject: [PATCH 3/7] Disable Python's hash implementations in FIPS mode,
|
|
|
|
@ -446,10 +446,10 @@ index 56ae7a5..45fb403 100644
|
|
|
|
|
+ if (_Py_hashlib_fips_error(exc, name)) return NULL; \
|
|
|
|
|
+} while (0)
|
|
|
|
|
diff --git a/configure.ac b/configure.ac
|
|
|
|
|
index 52d5c1f..56aff78 100644
|
|
|
|
|
index 7b4000f..8e2f0ad 100644
|
|
|
|
|
--- a/configure.ac
|
|
|
|
|
+++ b/configure.ac
|
|
|
|
|
@@ -7069,7 +7069,8 @@ PY_STDLIB_MOD([_sha512], [test "$with_builtin_sha512" = yes])
|
|
|
|
|
@@ -7070,7 +7070,8 @@ PY_STDLIB_MOD([_sha512], [test "$with_builtin_sha512" = yes])
|
|
|
|
|
PY_STDLIB_MOD([_sha3], [test "$with_builtin_sha3" = yes])
|
|
|
|
|
PY_STDLIB_MOD([_blake2],
|
|
|
|
|
[test "$with_builtin_blake2" = yes], [],
|
|
|
|
@ -460,10 +460,10 @@ index 52d5c1f..56aff78 100644
|
|
|
|
|
PY_STDLIB_MOD([_crypt],
|
|
|
|
|
[], [test "$ac_cv_crypt_crypt" = yes],
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From e9ce6d33544559172dbebbe0c0dfba2757c62331 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From 2e0c5086f4a52803595e19795111278c3c80ee2f Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
|
Date: Fri, 29 Jan 2021 14:16:21 +0100
|
|
|
|
|
Subject: [PATCH 4/7] Use python's fall back crypto implementations only if we
|
|
|
|
@ -623,10 +623,10 @@ index 01d12f5..a7cdb07 100644
|
|
|
|
|
def test_pbkdf2_hmac_py(self):
|
|
|
|
|
with warnings_helper.check_warnings():
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 641c617775b6973ed84711a2602ba190fe064474 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From 0e1d2a67ef66cccc9afa4a515dc34ce587946f22 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
|
Date: Wed, 31 Jul 2019 15:43:43 +0200
|
|
|
|
|
Subject: [PATCH 5/7] Test equivalence of hashes for the various digests with
|
|
|
|
@ -783,21 +783,21 @@ index a7cdb07..c071f28 100644
|
|
|
|
|
class KDFTests(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From a706c8342f0f9307d44c43c203702e1476fe73b4 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From f1c9ecbb2e2f08d792fb0557058824eed23abb7b Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
|
Date: Mon, 26 Aug 2019 19:39:48 +0200
|
|
|
|
|
Subject: [PATCH 6/7] Guard against Python HMAC in FIPS mode
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
Lib/hmac.py | 13 +++++++++----
|
|
|
|
|
Lib/hmac.py | 12 +++++++++---
|
|
|
|
|
Lib/test/test_hmac.py | 10 ++++++++++
|
|
|
|
|
2 files changed, 19 insertions(+), 4 deletions(-)
|
|
|
|
|
2 files changed, 19 insertions(+), 3 deletions(-)
|
|
|
|
|
|
|
|
|
|
diff --git a/Lib/hmac.py b/Lib/hmac.py
|
|
|
|
|
index 8b4f920..20ef96c 100644
|
|
|
|
|
index 8b4eb2f..8930bda 100644
|
|
|
|
|
--- a/Lib/hmac.py
|
|
|
|
|
+++ b/Lib/hmac.py
|
|
|
|
|
@@ -16,8 +16,9 @@ else:
|
|
|
|
@ -812,16 +812,9 @@ index 8b4f920..20ef96c 100644
|
|
|
|
|
|
|
|
|
|
# The size of the digests returned by HMAC depends on the underlying
|
|
|
|
|
# hashing module used. Use digest_size from the instance of HMAC instead.
|
|
|
|
|
@@ -48,17 +49,18 @@ class HMAC:
|
|
|
|
|
msg argument. Passing it as a keyword argument is
|
|
|
|
|
recommended, though not required for legacy API reasons.
|
|
|
|
|
"""
|
|
|
|
|
-
|
|
|
|
|
if not isinstance(key, (bytes, bytearray)):
|
|
|
|
|
raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__)
|
|
|
|
|
|
|
|
|
|
@@ -55,10 +56,12 @@ class HMAC:
|
|
|
|
|
if not digestmod:
|
|
|
|
|
raise TypeError("Missing required parameter 'digestmod'.")
|
|
|
|
|
raise TypeError("Missing required argument 'digestmod'.")
|
|
|
|
|
|
|
|
|
|
- if _hashopenssl and isinstance(digestmod, (str, _functype)):
|
|
|
|
|
+ if _hashopenssl.get_fips_mode() or (_hashopenssl and isinstance(digestmod, (str, _functype))):
|
|
|
|
@ -833,7 +826,7 @@ index 8b4f920..20ef96c 100644
|
|
|
|
|
self._init_old(key, msg, digestmod)
|
|
|
|
|
else:
|
|
|
|
|
self._init_old(key, msg, digestmod)
|
|
|
|
|
@@ -69,6 +71,9 @@ class HMAC:
|
|
|
|
|
@@ -69,6 +72,9 @@ class HMAC:
|
|
|
|
|
self.block_size = self._hmac.block_size
|
|
|
|
|
|
|
|
|
|
def _init_old(self, key, msg, digestmod):
|
|
|
|
@ -844,7 +837,7 @@ index 8b4f920..20ef96c 100644
|
|
|
|
|
digest_cons = digestmod
|
|
|
|
|
elif isinstance(digestmod, str):
|
|
|
|
|
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
|
|
|
|
|
index a39a2c4..0742a1c 100644
|
|
|
|
|
index 1502fba..e40ca4b 100644
|
|
|
|
|
--- a/Lib/test/test_hmac.py
|
|
|
|
|
+++ b/Lib/test/test_hmac.py
|
|
|
|
|
@@ -5,6 +5,7 @@ import hashlib
|
|
|
|
@ -883,7 +876,7 @@ index a39a2c4..0742a1c 100644
|
|
|
|
|
@unittest.skipUnless(sha256_module is not None, 'need _sha256')
|
|
|
|
|
def test_with_sha256_module(self):
|
|
|
|
|
h = hmac.HMAC(b"key", b"hash this!", digestmod=sha256_module.sha256)
|
|
|
|
|
@@ -481,6 +489,7 @@ class SanityTestCase(unittest.TestCase):
|
|
|
|
|
@@ -489,6 +497,7 @@ class UpdateTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
class CopyTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
@ -891,7 +884,7 @@ index a39a2c4..0742a1c 100644
|
|
|
|
|
@hashlib_helper.requires_hashdigest('sha256')
|
|
|
|
|
def test_attributes_old(self):
|
|
|
|
|
# Testing if attributes are of same type.
|
|
|
|
|
@@ -492,6 +501,7 @@ class CopyTestCase(unittest.TestCase):
|
|
|
|
|
@@ -500,6 +509,7 @@ class CopyTestCase(unittest.TestCase):
|
|
|
|
|
self.assertEqual(type(h1._outer), type(h2._outer),
|
|
|
|
|
"Types of outer don't match.")
|
|
|
|
|
|
|
|
|
@ -900,290 +893,43 @@ index a39a2c4..0742a1c 100644
|
|
|
|
|
def test_realcopy_old(self):
|
|
|
|
|
# Testing if the copy method created a real copy.
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
From 03f1dedfe5d29af20fb3686d76b045384d41d8dd Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Petr Viktorin <encukou@gmail.com>
|
|
|
|
|
Date: Wed, 25 Aug 2021 16:44:43 +0200
|
|
|
|
|
Subject: [PATCH 7/7] Disable hash-based PYCs in FIPS mode
|
|
|
|
|
|
|
|
|
|
If FIPS mode is on, we can't use siphash-based HMAC
|
|
|
|
|
(_Py_KeyedHash), so:
|
|
|
|
|
From a0c3f9ac5a4e60ab22418a3196ae46ba34e9477b Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Nikita Sobolev <mail@sobolevn.me>
|
|
|
|
|
Date: Thu, 24 Nov 2022 01:47:31 +0300
|
|
|
|
|
Subject: [PATCH 7/7] closes gh-99508: fix `TypeError` in
|
|
|
|
|
`Lib/importlib/_bootstrap_external.py` (GH-99635)
|
|
|
|
|
|
|
|
|
|
- Unchecked hash PYCs can be imported, but not created
|
|
|
|
|
- Checked hash PYCs can not be imported nor created
|
|
|
|
|
- The default mode is timestamp-based PYCs, even if
|
|
|
|
|
SOURCE_DATE_EPOCH is set.
|
|
|
|
|
|
|
|
|
|
If FIPS mode is off, there are no changes in behavior.
|
|
|
|
|
|
|
|
|
|
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1835169
|
|
|
|
|
---
|
|
|
|
|
Lib/py_compile.py | 2 ++
|
|
|
|
|
Lib/test/support/__init__.py | 14 +++++++++++++
|
|
|
|
|
Lib/test/test_cmd_line_script.py | 2 ++
|
|
|
|
|
Lib/test/test_compileall.py | 11 +++++++++-
|
|
|
|
|
Lib/test/test_imp.py | 2 ++
|
|
|
|
|
.../test_importlib/source/test_file_loader.py | 6 ++++++
|
|
|
|
|
Lib/test/test_py_compile.py | 11 ++++++++--
|
|
|
|
|
Lib/test/test_zipimport.py | 2 ++
|
|
|
|
|
Python/import.c | 20 +++++++++++++++++++
|
|
|
|
|
9 files changed, 67 insertions(+), 3 deletions(-)
|
|
|
|
|
Lib/importlib/_bootstrap_external.py | 3 ++-
|
|
|
|
|
.../next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst | 2 ++
|
|
|
|
|
2 files changed, 4 insertions(+), 1 deletion(-)
|
|
|
|
|
create mode 100644 Misc/NEWS.d/next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst
|
|
|
|
|
|
|
|
|
|
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
|
|
|
|
|
index db52725..5fca65e 100644
|
|
|
|
|
--- a/Lib/py_compile.py
|
|
|
|
|
+++ b/Lib/py_compile.py
|
|
|
|
|
@@ -70,7 +70,9 @@ class PycInvalidationMode(enum.Enum):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_default_invalidation_mode():
|
|
|
|
|
+ import _hashlib
|
|
|
|
|
if (os.environ.get('SOURCE_DATE_EPOCH') and not
|
|
|
|
|
+ _hashlib.get_fips_mode() and not
|
|
|
|
|
os.environ.get('RPM_BUILD_ROOT')):
|
|
|
|
|
return PycInvalidationMode.CHECKED_HASH
|
|
|
|
|
else:
|
|
|
|
|
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
|
|
|
|
|
index dc7a6e6..646b328 100644
|
|
|
|
|
--- a/Lib/test/support/__init__.py
|
|
|
|
|
+++ b/Lib/test/support/__init__.py
|
|
|
|
|
@@ -2203,6 +2203,20 @@ def sleeping_retry(timeout, err_msg=None, /,
|
|
|
|
|
delay = min(delay * 2, max_delay)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def fails_in_fips_mode(expected_error):
|
|
|
|
|
+ import _hashlib
|
|
|
|
|
+ if _hashlib.get_fips_mode():
|
|
|
|
|
+ def _decorator(func):
|
|
|
|
|
+ def _wrapper(self, *args, **kwargs):
|
|
|
|
|
+ with self.assertRaises(expected_error):
|
|
|
|
|
+ func(self, *args, **kwargs)
|
|
|
|
|
+ return _wrapper
|
|
|
|
|
+ else:
|
|
|
|
|
+ def _decorator(func):
|
|
|
|
|
+ return func
|
|
|
|
|
+ return _decorator
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
def adjust_int_max_str_digits(max_digits):
|
|
|
|
|
"""Temporarily change the integer string conversion length limit."""
|
|
|
|
|
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
|
|
|
|
|
index 7fcd563..476b557 100644
|
|
|
|
|
--- a/Lib/test/test_cmd_line_script.py
|
|
|
|
|
+++ b/Lib/test/test_cmd_line_script.py
|
|
|
|
|
@@ -286,6 +286,7 @@ class CmdLineTest(unittest.TestCase):
|
|
|
|
|
self._check_script(zip_name, run_name, zip_name, zip_name, '',
|
|
|
|
|
zipimport.zipimporter)
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_zipfile_compiled_checked_hash(self):
|
|
|
|
|
with os_helper.temp_dir() as script_dir:
|
|
|
|
|
script_name = _make_test_script(script_dir, '__main__')
|
|
|
|
|
@@ -296,6 +297,7 @@ class CmdLineTest(unittest.TestCase):
|
|
|
|
|
self._check_script(zip_name, run_name, zip_name, zip_name, '',
|
|
|
|
|
zipimport.zipimporter)
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_zipfile_compiled_unchecked_hash(self):
|
|
|
|
|
with os_helper.temp_dir() as script_dir:
|
|
|
|
|
script_name = _make_test_script(script_dir, '__main__')
|
|
|
|
|
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
|
|
|
|
|
index 9cd92ad..4ec29a1 100644
|
|
|
|
|
--- a/Lib/test/test_compileall.py
|
|
|
|
|
+++ b/Lib/test/test_compileall.py
|
|
|
|
|
@@ -806,14 +806,23 @@ class CommandLineTestsBase:
|
|
|
|
|
out = self.assertRunOK('badfilename')
|
|
|
|
|
self.assertRegex(out, b"Can't list 'badfilename'")
|
|
|
|
|
|
|
|
|
|
- def test_pyc_invalidation_mode(self):
|
|
|
|
|
+ @support.fails_in_fips_mode(AssertionError)
|
|
|
|
|
+ def test_pyc_invalidation_mode_checked(self):
|
|
|
|
|
script_helper.make_script(self.pkgdir, 'f1', '')
|
|
|
|
|
pyc = importlib.util.cache_from_source(
|
|
|
|
|
os.path.join(self.pkgdir, 'f1.py'))
|
|
|
|
|
+
|
|
|
|
|
self.assertRunOK('--invalidation-mode=checked-hash', self.pkgdir)
|
|
|
|
|
with open(pyc, 'rb') as fp:
|
|
|
|
|
data = fp.read()
|
|
|
|
|
self.assertEqual(int.from_bytes(data[4:8], 'little'), 0b11)
|
|
|
|
|
+
|
|
|
|
|
+ @support.fails_in_fips_mode(AssertionError)
|
|
|
|
|
+ def test_pyc_invalidation_mode_unchecked(self):
|
|
|
|
|
+ script_helper.make_script(self.pkgdir, 'f1', '')
|
|
|
|
|
+ pyc = importlib.util.cache_from_source(
|
|
|
|
|
+ os.path.join(self.pkgdir, 'f1.py'))
|
|
|
|
|
+
|
|
|
|
|
self.assertRunOK('--invalidation-mode=unchecked-hash', self.pkgdir)
|
|
|
|
|
with open(pyc, 'rb') as fp:
|
|
|
|
|
data = fp.read()
|
|
|
|
|
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
|
|
|
|
|
index 4062afd..6bc276d 100644
|
|
|
|
|
--- a/Lib/test/test_imp.py
|
|
|
|
|
+++ b/Lib/test/test_imp.py
|
|
|
|
|
@@ -352,6 +352,7 @@ class ImportTests(unittest.TestCase):
|
|
|
|
|
import _frozen_importlib
|
|
|
|
|
self.assertEqual(_frozen_importlib.__spec__.origin, "frozen")
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_source_hash(self):
|
|
|
|
|
self.assertEqual(_imp.source_hash(42, b'hi'), b'\xfb\xd9G\x05\xaf$\x9b~')
|
|
|
|
|
self.assertEqual(_imp.source_hash(43, b'hi'), b'\xd0/\x87C\xccC\xff\xe2')
|
|
|
|
|
@@ -371,6 +372,7 @@ class ImportTests(unittest.TestCase):
|
|
|
|
|
res = script_helper.assert_python_ok(*args)
|
|
|
|
|
self.assertEqual(res.out.strip().decode('utf-8'), expected)
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_find_and_load_checked_pyc(self):
|
|
|
|
|
# issue 34056
|
|
|
|
|
with os_helper.temp_cwd():
|
|
|
|
|
diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py
|
|
|
|
|
index 378dcbe..7b223a1 100644
|
|
|
|
|
--- a/Lib/test/test_importlib/source/test_file_loader.py
|
|
|
|
|
+++ b/Lib/test/test_importlib/source/test_file_loader.py
|
|
|
|
|
@@ -16,6 +16,7 @@ import types
|
|
|
|
|
import unittest
|
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
|
|
+from test import support
|
|
|
|
|
from test.support.import_helper import make_legacy_pyc, unload
|
|
|
|
|
|
|
|
|
|
from test.test_py_compile import without_source_date_epoch
|
|
|
|
|
@@ -238,6 +239,7 @@ class SimpleTest(abc.LoaderTests):
|
|
|
|
|
loader.load_module('bad name')
|
|
|
|
|
|
|
|
|
|
@util.writes_bytecode_files
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_checked_hash_based_pyc(self):
|
|
|
|
|
with util.create_modules('_temp') as mapping:
|
|
|
|
|
source = mapping['_temp']
|
|
|
|
|
@@ -269,6 +271,7 @@ class SimpleTest(abc.LoaderTests):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@util.writes_bytecode_files
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_overridden_checked_hash_based_pyc(self):
|
|
|
|
|
with util.create_modules('_temp') as mapping, \
|
|
|
|
|
unittest.mock.patch('_imp.check_hash_based_pycs', 'never'):
|
|
|
|
|
@@ -294,6 +297,7 @@ class SimpleTest(abc.LoaderTests):
|
|
|
|
|
self.assertEqual(mod.state, 'old')
|
|
|
|
|
|
|
|
|
|
@util.writes_bytecode_files
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_unchecked_hash_based_pyc(self):
|
|
|
|
|
with util.create_modules('_temp') as mapping:
|
|
|
|
|
source = mapping['_temp']
|
|
|
|
|
@@ -324,6 +328,7 @@ class SimpleTest(abc.LoaderTests):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@util.writes_bytecode_files
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def test_overridden_unchecked_hash_based_pyc(self):
|
|
|
|
|
with util.create_modules('_temp') as mapping, \
|
|
|
|
|
unittest.mock.patch('_imp.check_hash_based_pycs', 'always'):
|
|
|
|
|
@@ -433,6 +438,7 @@ class BadBytecodeTest:
|
|
|
|
|
del_source=del_source)
|
|
|
|
|
test('_temp', mapping, bc_path)
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def _test_partial_hash(self, test, *, del_source=False):
|
|
|
|
|
with util.create_modules('_temp') as mapping:
|
|
|
|
|
bc_path = self.manipulate_bytecode(
|
|
|
|
|
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
|
|
|
|
|
index 9b420d2..dd6460a 100644
|
|
|
|
|
--- a/Lib/test/test_py_compile.py
|
|
|
|
|
+++ b/Lib/test/test_py_compile.py
|
|
|
|
|
@@ -143,13 +143,16 @@ class PyCompileTestsBase:
|
|
|
|
|
importlib.util.cache_from_source(bad_coding)))
|
|
|
|
|
|
|
|
|
|
def test_source_date_epoch(self):
|
|
|
|
|
+ import _hashlib
|
|
|
|
|
py_compile.compile(self.source_path, self.pyc_path)
|
|
|
|
|
self.assertTrue(os.path.exists(self.pyc_path))
|
|
|
|
|
self.assertFalse(os.path.exists(self.cache_path))
|
|
|
|
|
with open(self.pyc_path, 'rb') as fp:
|
|
|
|
|
flags = importlib._bootstrap_external._classify_pyc(
|
|
|
|
|
fp.read(), 'test', {})
|
|
|
|
|
- if os.environ.get('SOURCE_DATE_EPOCH'):
|
|
|
|
|
+ if _hashlib.get_fips_mode():
|
|
|
|
|
+ expected_flags = 0b00
|
|
|
|
|
+ elif os.environ.get('SOURCE_DATE_EPOCH'):
|
|
|
|
|
expected_flags = 0b11
|
|
|
|
|
else:
|
|
|
|
|
expected_flags = 0b00
|
|
|
|
|
@@ -180,7 +183,8 @@ class PyCompileTestsBase:
|
|
|
|
|
# Specifying optimized bytecode should lead to a path reflecting that.
|
|
|
|
|
self.assertIn('opt-2', py_compile.compile(self.source_path, optimize=2))
|
|
|
|
|
|
|
|
|
|
- def test_invalidation_mode(self):
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
+ def test_invalidation_mode_checked(self):
|
|
|
|
|
py_compile.compile(
|
|
|
|
|
self.source_path,
|
|
|
|
|
invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH,
|
|
|
|
|
@@ -189,6 +193,9 @@ class PyCompileTestsBase:
|
|
|
|
|
flags = importlib._bootstrap_external._classify_pyc(
|
|
|
|
|
fp.read(), 'test', {})
|
|
|
|
|
self.assertEqual(flags, 0b11)
|
|
|
|
|
+
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
+ def test_invalidation_mode_unchecked(self):
|
|
|
|
|
py_compile.compile(
|
|
|
|
|
self.source_path,
|
|
|
|
|
invalidation_mode=py_compile.PycInvalidationMode.UNCHECKED_HASH,
|
|
|
|
|
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
|
|
|
|
|
index 59a5200..81fadb3 100644
|
|
|
|
|
--- a/Lib/test/test_zipimport.py
|
|
|
|
|
+++ b/Lib/test/test_zipimport.py
|
|
|
|
|
@@ -190,6 +190,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|
|
|
|
TESTMOD + pyc_ext: (NOW, test_pyc)}
|
|
|
|
|
self.doTest(pyc_ext, files, TESTMOD)
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
def testUncheckedHashBasedPyc(self):
|
|
|
|
|
source = b"state = 'old'"
|
|
|
|
|
source_hash = importlib.util.source_hash(source)
|
|
|
|
|
@@ -204,6 +205,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|
|
|
|
self.assertEqual(mod.state, 'old')
|
|
|
|
|
self.doTest(None, files, TESTMOD, call=check)
|
|
|
|
|
|
|
|
|
|
+ @support.fails_in_fips_mode(ImportError)
|
|
|
|
|
@unittest.mock.patch('_imp.check_hash_based_pycs', 'always')
|
|
|
|
|
def test_checked_hash_based_change_pyc(self):
|
|
|
|
|
source = b"state = 'old'"
|
|
|
|
|
diff --git a/Python/import.c b/Python/import.c
|
|
|
|
|
index 39144d3..b439059 100644
|
|
|
|
|
--- a/Python/import.c
|
|
|
|
|
+++ b/Python/import.c
|
|
|
|
|
@@ -2449,6 +2449,26 @@ static PyObject *
|
|
|
|
|
_imp_source_hash_impl(PyObject *module, long key, Py_buffer *source)
|
|
|
|
|
/*[clinic end generated code: output=edb292448cf399ea input=9aaad1e590089789]*/
|
|
|
|
|
{
|
|
|
|
|
+ PyObject *_hashlib = PyImport_ImportModule("_hashlib");
|
|
|
|
|
+ if (_hashlib == NULL) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ PyObject *fips_mode_obj = PyObject_CallMethod(_hashlib, "get_fips_mode", NULL);
|
|
|
|
|
+ Py_DECREF(_hashlib);
|
|
|
|
|
+ if (fips_mode_obj == NULL) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ int fips_mode = PyObject_IsTrue(fips_mode_obj);
|
|
|
|
|
+ Py_DECREF(fips_mode_obj);
|
|
|
|
|
+ if (fips_mode < 0) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fips_mode) {
|
|
|
|
|
+ PyErr_SetString(
|
|
|
|
|
+ PyExc_ImportError,
|
|
|
|
|
+ "hash-based PYC validation (siphash24) not available in FIPS mode");
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ };
|
|
|
|
|
union {
|
|
|
|
|
uint64_t x;
|
|
|
|
|
char data[sizeof(uint64_t)];
|
|
|
|
|
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
|
|
|
|
|
index e53f6ac..bdc491e 100644
|
|
|
|
|
--- a/Lib/importlib/_bootstrap_external.py
|
|
|
|
|
+++ b/Lib/importlib/_bootstrap_external.py
|
|
|
|
|
@@ -1077,7 +1077,8 @@ class SourceLoader(_LoaderBasics):
|
|
|
|
|
source_mtime is not None):
|
|
|
|
|
if hash_based:
|
|
|
|
|
if source_hash is None:
|
|
|
|
|
- source_hash = _imp.source_hash(source_bytes)
|
|
|
|
|
+ source_hash = _imp.source_hash(_RAW_MAGIC_NUMBER,
|
|
|
|
|
+ source_bytes)
|
|
|
|
|
data = _code_to_hash_pyc(code_object, source_hash, check_source)
|
|
|
|
|
else:
|
|
|
|
|
data = _code_to_timestamp_pyc(code_object, source_mtime,
|
|
|
|
|
diff --git a/Misc/NEWS.d/next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst b/Misc/NEWS.d/next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst
|
|
|
|
|
new file mode 100644
|
|
|
|
|
index 0000000..82720d1
|
|
|
|
|
--- /dev/null
|
|
|
|
|
+++ b/Misc/NEWS.d/next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst
|
|
|
|
|
@@ -0,0 +1,2 @@
|
|
|
|
|
+Fix ``TypeError`` in ``Lib/importlib/_bootstrap_external.py`` while calling
|
|
|
|
|
+``_imp.source_hash()``.
|
|
|
|
|
--
|
|
|
|
|
2.43.0
|
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|