|
|
@ -1,4 +1,4 @@
|
|
|
|
From ccb2659fa0ec259d4161ed84345553bf3f216531 Mon Sep 17 00:00:00 2001
|
|
|
|
From 4cef6c756055a15dc33a475c1f405676fa69410c Mon Sep 17 00:00:00 2001
|
|
|
|
From: Petr Viktorin <encukou@gmail.com>
|
|
|
|
From: Petr Viktorin <encukou@gmail.com>
|
|
|
|
Date: Wed, 11 Aug 2021 16:51:03 +0200
|
|
|
|
Date: Wed, 11 Aug 2021 16:51:03 +0200
|
|
|
|
Subject: [PATCH 01/10] Backport PyModule_AddObjectRef as
|
|
|
|
Subject: [PATCH 01/10] Backport PyModule_AddObjectRef as
|
|
|
@ -71,10 +71,10 @@ index 13482c6..fca1083 100644
|
|
|
|
PyModule_AddIntConstant(PyObject *m, const char *name, long value)
|
|
|
|
PyModule_AddIntConstant(PyObject *m, const char *name, long value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 794c37495d91823bd820b96382b999d84dcad58d Mon Sep 17 00:00:00 2001
|
|
|
|
From a115773e979f968edaed8a3419f3ccc34eef8320 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Petr Viktorin <encukou@gmail.com>
|
|
|
|
From: Petr Viktorin <encukou@gmail.com>
|
|
|
|
Date: Fri, 13 Aug 2021 13:16:43 +0200
|
|
|
|
Date: Fri, 13 Aug 2021 13:16:43 +0200
|
|
|
|
Subject: [PATCH 02/10] _hashopenssl: Uncomment and use initialization function
|
|
|
|
Subject: [PATCH 02/10] _hashopenssl: Uncomment and use initialization function
|
|
|
@ -144,10 +144,10 @@ index 4db058c..56dfff9 100644
|
|
|
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
return m;
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 94b56c82b459474c3e0f9e5421fa7becbf5a1c70 Mon Sep 17 00:00:00 2001
|
|
|
|
From 28506af69b2b005bb7a8931624f97273269458a1 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Christian Heimes <christian@python.org>
|
|
|
|
From: Christian Heimes <christian@python.org>
|
|
|
|
Date: Sat, 27 Mar 2021 14:55:03 +0100
|
|
|
|
Date: Sat, 27 Mar 2021 14:55:03 +0100
|
|
|
|
Subject: [PATCH 03/10] bpo-40645: use C implementation of HMAC (GH-24920,
|
|
|
|
Subject: [PATCH 03/10] bpo-40645: use C implementation of HMAC (GH-24920,
|
|
|
@ -927,10 +927,10 @@ index 68aa765..4466ec4 100644
|
|
|
|
-/*[clinic end generated code: output=b6b280e46bf0b139 input=a9049054013a1b77]*/
|
|
|
|
-/*[clinic end generated code: output=b6b280e46bf0b139 input=a9049054013a1b77]*/
|
|
|
|
+/*[clinic end generated code: output=7ff9aad0bd53e7ce input=a9049054013a1b77]*/
|
|
|
|
+/*[clinic end generated code: output=7ff9aad0bd53e7ce input=a9049054013a1b77]*/
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From b63e3fbd7c0506b5a6c00c1bb0d255054e38bbe8 Mon Sep 17 00:00:00 2001
|
|
|
|
From 1f5f7d3892febb68cf96ef151beab06eae1792ce Mon Sep 17 00:00:00 2001
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
Date: Thu, 12 Dec 2019 16:58:31 +0100
|
|
|
|
Date: Thu, 12 Dec 2019 16:58:31 +0100
|
|
|
|
Subject: [PATCH 04/10] Expose blake2b and blake2s hashes from OpenSSL
|
|
|
|
Subject: [PATCH 04/10] Expose blake2b and blake2s hashes from OpenSSL
|
|
|
@ -944,7 +944,7 @@ used under FIPS.
|
|
|
|
3 files changed, 148 insertions(+), 1 deletion(-)
|
|
|
|
3 files changed, 148 insertions(+), 1 deletion(-)
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
index f845c7a..7aaeb76 100644
|
|
|
|
index bc11a8d..9a07499 100644
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
@@ -363,6 +363,12 @@ class HashLibTestCase(unittest.TestCase):
|
|
|
|
@@ -363,6 +363,12 @@ class HashLibTestCase(unittest.TestCase):
|
|
|
@ -1137,10 +1137,10 @@ index 4466ec4..54c22b2 100644
|
|
|
|
-/*[clinic end generated code: output=7ff9aad0bd53e7ce input=a9049054013a1b77]*/
|
|
|
|
-/*[clinic end generated code: output=7ff9aad0bd53e7ce input=a9049054013a1b77]*/
|
|
|
|
+/*[clinic end generated code: output=fab05055e982f112 input=a9049054013a1b77]*/
|
|
|
|
+/*[clinic end generated code: output=fab05055e982f112 input=a9049054013a1b77]*/
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From dc8ad7b98d6d9bf14cae439acb3a99fa8f4f5020 Mon Sep 17 00:00:00 2001
|
|
|
|
From 842bd1c8c8a62c342fed848e5a5f0f1d97daeaba Mon Sep 17 00:00:00 2001
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
Date: Thu, 1 Aug 2019 17:57:05 +0200
|
|
|
|
Date: Thu, 1 Aug 2019 17:57:05 +0200
|
|
|
|
Subject: [PATCH 05/10] Use a stronger hash in multiprocessing handshake
|
|
|
|
Subject: [PATCH 05/10] Use a stronger hash in multiprocessing handshake
|
|
|
@ -1152,7 +1152,7 @@ https://bugs.python.org/issue17258
|
|
|
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
|
|
|
|
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
|
|
|
|
index 510e4b5..b68f2fb 100644
|
|
|
|
index 8e2facf..bb4acb6 100644
|
|
|
|
--- a/Lib/multiprocessing/connection.py
|
|
|
|
--- a/Lib/multiprocessing/connection.py
|
|
|
|
+++ b/Lib/multiprocessing/connection.py
|
|
|
|
+++ b/Lib/multiprocessing/connection.py
|
|
|
|
@@ -42,6 +42,10 @@ BUFSIZE = 8192
|
|
|
|
@@ -42,6 +42,10 @@ BUFSIZE = 8192
|
|
|
@ -1166,7 +1166,7 @@ index 510e4b5..b68f2fb 100644
|
|
|
|
_mmap_counter = itertools.count()
|
|
|
|
_mmap_counter = itertools.count()
|
|
|
|
|
|
|
|
|
|
|
|
default_family = 'AF_INET'
|
|
|
|
default_family = 'AF_INET'
|
|
|
|
@@ -741,7 +745,7 @@ def deliver_challenge(connection, authkey):
|
|
|
|
@@ -736,7 +740,7 @@ def deliver_challenge(connection, authkey):
|
|
|
|
"Authkey must be bytes, not {0!s}".format(type(authkey)))
|
|
|
|
"Authkey must be bytes, not {0!s}".format(type(authkey)))
|
|
|
|
message = os.urandom(MESSAGE_LENGTH)
|
|
|
|
message = os.urandom(MESSAGE_LENGTH)
|
|
|
|
connection.send_bytes(CHALLENGE + message)
|
|
|
|
connection.send_bytes(CHALLENGE + message)
|
|
|
@ -1175,7 +1175,7 @@ index 510e4b5..b68f2fb 100644
|
|
|
|
response = connection.recv_bytes(256) # reject large message
|
|
|
|
response = connection.recv_bytes(256) # reject large message
|
|
|
|
if response == digest:
|
|
|
|
if response == digest:
|
|
|
|
connection.send_bytes(WELCOME)
|
|
|
|
connection.send_bytes(WELCOME)
|
|
|
|
@@ -757,7 +761,7 @@ def answer_challenge(connection, authkey):
|
|
|
|
@@ -752,7 +756,7 @@ def answer_challenge(connection, authkey):
|
|
|
|
message = connection.recv_bytes(256) # reject large message
|
|
|
|
message = connection.recv_bytes(256) # reject large message
|
|
|
|
assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' % message
|
|
|
|
assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' % message
|
|
|
|
message = message[len(CHALLENGE):]
|
|
|
|
message = message[len(CHALLENGE):]
|
|
|
@ -1185,10 +1185,10 @@ index 510e4b5..b68f2fb 100644
|
|
|
|
response = connection.recv_bytes(256) # reject large message
|
|
|
|
response = connection.recv_bytes(256) # reject large message
|
|
|
|
if response != WELCOME:
|
|
|
|
if response != WELCOME:
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From af0c88c9d5bc4f9c127e49ed80d14e25d18813f2 Mon Sep 17 00:00:00 2001
|
|
|
|
From 0390f1ea33f8a604467829733541791a29cee4da Mon Sep 17 00:00:00 2001
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
Date: Thu, 25 Jul 2019 17:19:06 +0200
|
|
|
|
Date: Thu, 25 Jul 2019 17:19:06 +0200
|
|
|
|
Subject: [PATCH 06/10] Disable Python's hash implementations in FIPS mode,
|
|
|
|
Subject: [PATCH 06/10] Disable Python's hash implementations in FIPS mode,
|
|
|
@ -1231,7 +1231,7 @@ index ffa3be0..3e3f4dd 100644
|
|
|
|
def __get_builtin_constructor(name):
|
|
|
|
def __get_builtin_constructor(name):
|
|
|
|
cache = __builtin_constructor_cache
|
|
|
|
cache = __builtin_constructor_cache
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
index 7aaeb76..fa4a8d7 100644
|
|
|
|
index 9a07499..56dfbaa 100644
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
@@ -35,14 +35,15 @@ else:
|
|
|
|
@@ -35,14 +35,15 @@ else:
|
|
|
@ -1446,10 +1446,10 @@ index 0bec170..479f4b5 100644
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 9bc3d493a3508fb82df7d24cc62315c072d9eca8 Mon Sep 17 00:00:00 2001
|
|
|
|
From 667781e01425308ae95f062f8596866a5af76f77 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
Date: Fri, 29 Jan 2021 14:16:21 +0100
|
|
|
|
Date: Fri, 29 Jan 2021 14:16:21 +0100
|
|
|
|
Subject: [PATCH 07/10] Use python's fall back crypto implementations only if
|
|
|
|
Subject: [PATCH 07/10] Use python's fall back crypto implementations only if
|
|
|
@ -1565,7 +1565,7 @@ index 3e3f4dd..b842f5f 100644
|
|
|
|
|
|
|
|
|
|
|
|
for __func_name in __always_supported:
|
|
|
|
for __func_name in __always_supported:
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
index fa4a8d7..ec6c883 100644
|
|
|
|
index 56dfbaa..05f4a54 100644
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
@@ -171,7 +171,13 @@ class HashLibTestCase(unittest.TestCase):
|
|
|
|
@@ -171,7 +171,13 @@ class HashLibTestCase(unittest.TestCase):
|
|
|
@ -1604,7 +1604,7 @@ index fa4a8d7..ec6c883 100644
|
|
|
|
def test_get_builtin_constructor(self):
|
|
|
|
def test_get_builtin_constructor(self):
|
|
|
|
get_builtin_constructor = getattr(hashlib,
|
|
|
|
get_builtin_constructor = getattr(hashlib,
|
|
|
|
'__get_builtin_constructor')
|
|
|
|
'__get_builtin_constructor')
|
|
|
|
@@ -1061,6 +1081,7 @@ class KDFTests(unittest.TestCase):
|
|
|
|
@@ -1070,6 +1090,7 @@ class KDFTests(unittest.TestCase):
|
|
|
|
iterations=1, dklen=None)
|
|
|
|
iterations=1, dklen=None)
|
|
|
|
self.assertEqual(out, self.pbkdf2_results['sha1'][0][0])
|
|
|
|
self.assertEqual(out, self.pbkdf2_results['sha1'][0][0])
|
|
|
|
|
|
|
|
|
|
|
@ -1613,10 +1613,10 @@ index fa4a8d7..ec6c883 100644
|
|
|
|
def test_pbkdf2_hmac_py(self):
|
|
|
|
def test_pbkdf2_hmac_py(self):
|
|
|
|
self._test_pbkdf2_hmac(builtin_hashlib.pbkdf2_hmac, builtin_hashes)
|
|
|
|
self._test_pbkdf2_hmac(builtin_hashlib.pbkdf2_hmac, builtin_hashes)
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 331c0d39cbc9c4df266c375bae8c1a0d27dd78d9 Mon Sep 17 00:00:00 2001
|
|
|
|
From e36df0297eca09ca1826163f39a812b45558f690 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
From: Charalampos Stratakis <cstratak@redhat.com>
|
|
|
|
Date: Wed, 31 Jul 2019 15:43:43 +0200
|
|
|
|
Date: Wed, 31 Jul 2019 15:43:43 +0200
|
|
|
|
Subject: [PATCH 08/10] Test equivalence of hashes for the various digests with
|
|
|
|
Subject: [PATCH 08/10] Test equivalence of hashes for the various digests with
|
|
|
@ -1659,7 +1659,7 @@ index 0000000..1f99dd7
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+ unittest.main()
|
|
|
|
+ unittest.main()
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
|
|
|
|
index ec6c883..0fd036f 100644
|
|
|
|
index 05f4a54..980c773 100644
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
--- a/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
+++ b/Lib/test/test_hashlib.py
|
|
|
|
@@ -20,6 +20,7 @@ import warnings
|
|
|
|
@@ -20,6 +20,7 @@ import warnings
|
|
|
@ -1755,7 +1755,7 @@ index ec6c883..0fd036f 100644
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
m = hash_object_constructor(data, **kwargs)
|
|
|
|
m = hash_object_constructor(data, **kwargs)
|
|
|
|
@@ -974,6 +989,15 @@ class HashLibTestCase(unittest.TestCase):
|
|
|
|
@@ -983,6 +998,15 @@ class HashLibTestCase(unittest.TestCase):
|
|
|
|
):
|
|
|
|
):
|
|
|
|
HASHXOF()
|
|
|
|
HASHXOF()
|
|
|
|
|
|
|
|
|
|
|
@ -1772,10 +1772,10 @@ index ec6c883..0fd036f 100644
|
|
|
|
class KDFTests(unittest.TestCase):
|
|
|
|
class KDFTests(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From 1a3df28f95710925bc80018bcf22b7f37bbb1e17 Mon Sep 17 00:00:00 2001
|
|
|
|
From 8fc0216da1d6e148bf086c8c137ddc19a33ab642 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
|
Date: Mon, 26 Aug 2019 19:39:48 +0200
|
|
|
|
Date: Mon, 26 Aug 2019 19:39:48 +0200
|
|
|
|
Subject: [PATCH 09/10] Guard against Python HMAC in FIPS mode
|
|
|
|
Subject: [PATCH 09/10] Guard against Python HMAC in FIPS mode
|
|
|
@ -1889,290 +1889,43 @@ index adf52ad..41e6a14 100644
|
|
|
|
def test_realcopy_old(self):
|
|
|
|
def test_realcopy_old(self):
|
|
|
|
# Testing if the copy method created a real copy.
|
|
|
|
# Testing if the copy method created a real copy.
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From dded0e09dd3e51998a2aa54d2ae8464d73987e51 Mon Sep 17 00:00:00 2001
|
|
|
|
From 4271e404c9aa918368d397654d60e4e845dfc844 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Petr Viktorin <encukou@gmail.com>
|
|
|
|
From: Nikita Sobolev <mail@sobolevn.me>
|
|
|
|
Date: Wed, 25 Aug 2021 16:44:43 +0200
|
|
|
|
Date: Thu, 24 Nov 2022 01:47:31 +0300
|
|
|
|
Subject: [PATCH 10/10] Disable hash-based PYCs in FIPS mode
|
|
|
|
Subject: [PATCH 10/10] closes gh-99508: fix `TypeError` in
|
|
|
|
|
|
|
|
`Lib/importlib/_bootstrap_external.py` (GH-99635)
|
|
|
|
If FIPS mode is on, we can't use siphash-based HMAC
|
|
|
|
|
|
|
|
(_Py_KeyedHash), so:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- 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/importlib/_bootstrap_external.py | 3 ++-
|
|
|
|
Lib/test/support/__init__.py | 14 +++++++++++++
|
|
|
|
.../next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst | 2 ++
|
|
|
|
Lib/test/test_cmd_line_script.py | 2 ++
|
|
|
|
2 files changed, 4 insertions(+), 1 deletion(-)
|
|
|
|
Lib/test/test_compileall.py | 11 +++++++++-
|
|
|
|
create mode 100644 Misc/NEWS.d/next/Library/2022-11-21-10-45-54.gh-issue-99508.QqVbby.rst
|
|
|
|
Lib/test/test_imp.py | 2 ++
|
|
|
|
|
|
|
|
.../test_importlib/source/test_file_loader.py | 6 ++++++
|
|
|
|
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
|
|
|
|
Lib/test/test_py_compile.py | 11 ++++++++--
|
|
|
|
index f0c9f8e..cccf6b2 100644
|
|
|
|
Lib/test/test_zipimport.py | 2 ++
|
|
|
|
--- a/Lib/importlib/_bootstrap_external.py
|
|
|
|
Python/import.c | 20 +++++++++++++++++++
|
|
|
|
+++ b/Lib/importlib/_bootstrap_external.py
|
|
|
|
9 files changed, 67 insertions(+), 3 deletions(-)
|
|
|
|
@@ -986,7 +986,8 @@ class SourceLoader(_LoaderBasics):
|
|
|
|
|
|
|
|
source_mtime is not None):
|
|
|
|
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
|
|
|
|
if hash_based:
|
|
|
|
index bba3642..02db901 100644
|
|
|
|
if source_hash is None:
|
|
|
|
--- a/Lib/py_compile.py
|
|
|
|
- source_hash = _imp.source_hash(source_bytes)
|
|
|
|
+++ b/Lib/py_compile.py
|
|
|
|
+ source_hash = _imp.source_hash(_RAW_MAGIC_NUMBER,
|
|
|
|
@@ -70,7 +70,9 @@ class PycInvalidationMode(enum.Enum):
|
|
|
|
+ source_bytes)
|
|
|
|
|
|
|
|
data = _code_to_hash_pyc(code_object, source_hash, check_source)
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
else:
|
|
|
|
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
|
|
|
|
data = _code_to_timestamp_pyc(code_object, source_mtime,
|
|
|
|
index 6dc0813..b9d5f9a 100644
|
|
|
|
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
|
|
|
|
--- a/Lib/test/support/__init__.py
|
|
|
|
new file mode 100644
|
|
|
|
+++ b/Lib/test/support/__init__.py
|
|
|
|
index 0000000..82720d1
|
|
|
|
@@ -3296,6 +3296,20 @@ def clear_ignored_deprecations(*tokens: object) -> None:
|
|
|
|
--- /dev/null
|
|
|
|
warnings._filters_mutated()
|
|
|
|
+++ 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
|
|
|
|
+def fails_in_fips_mode(expected_error):
|
|
|
|
+``_imp.source_hash()``.
|
|
|
|
+ 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 7cb1370..61df232 100644
|
|
|
|
|
|
|
|
--- a/Lib/test/test_cmd_line_script.py
|
|
|
|
|
|
|
|
+++ b/Lib/test/test_cmd_line_script.py
|
|
|
|
|
|
|
|
@@ -282,6 +282,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 support.temp_dir() as script_dir:
|
|
|
|
|
|
|
|
script_name = _make_test_script(script_dir, '__main__')
|
|
|
|
|
|
|
|
@@ -292,6 +293,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 support.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 ab647d6..7d50f07 100644
|
|
|
|
|
|
|
|
--- a/Lib/test/test_compileall.py
|
|
|
|
|
|
|
|
+++ b/Lib/test/test_compileall.py
|
|
|
|
|
|
|
|
@@ -758,14 +758,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 fe394dc..802f0e8 100644
|
|
|
|
|
|
|
|
--- a/Lib/test/test_imp.py
|
|
|
|
|
|
|
|
+++ b/Lib/test/test_imp.py
|
|
|
|
|
|
|
|
@@ -343,6 +343,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'\xc6\xe7Z\r\x03:}\xab')
|
|
|
|
|
|
|
|
self.assertEqual(_imp.source_hash(43, b'hi'), b'\x85\x9765\xf8\x9a\x8b9')
|
|
|
|
|
|
|
|
@@ -362,6 +363,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 support.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 ab44722..480cc81 100644
|
|
|
|
|
|
|
|
--- a/Lib/test/test_importlib/source/test_file_loader.py
|
|
|
|
|
|
|
|
+++ b/Lib/test/test_importlib/source/test_file_loader.py
|
|
|
|
|
|
|
|
@@ -17,6 +17,7 @@ import types
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+from test import support
|
|
|
|
|
|
|
|
from test.support import make_legacy_pyc, unload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from test.test_py_compile import without_source_date_epoch
|
|
|
|
|
|
|
|
@@ -239,6 +240,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']
|
|
|
|
|
|
|
|
@@ -270,6 +272,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'):
|
|
|
|
|
|
|
|
@@ -295,6 +298,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']
|
|
|
|
|
|
|
|
@@ -325,6 +329,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'):
|
|
|
|
|
|
|
|
@@ -434,6 +439,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 b2d3dcf..7e4b0c5 100644
|
|
|
|
|
|
|
|
--- a/Lib/test/test_py_compile.py
|
|
|
|
|
|
|
|
+++ b/Lib/test/test_py_compile.py
|
|
|
|
|
|
|
|
@@ -141,13 +141,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
|
|
|
|
|
|
|
|
@@ -178,7 +181,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,
|
|
|
|
|
|
|
|
@@ -187,6 +191,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 b7347a3..09ea990 100644
|
|
|
|
|
|
|
|
--- a/Lib/test/test_zipimport.py
|
|
|
|
|
|
|
|
+++ b/Lib/test/test_zipimport.py
|
|
|
|
|
|
|
|
@@ -186,6 +186,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)
|
|
|
|
|
|
|
|
@@ -200,6 +201,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 8358d70..1b7fb85 100644
|
|
|
|
|
|
|
|
--- a/Python/import.c
|
|
|
|
|
|
|
|
+++ b/Python/import.c
|
|
|
|
|
|
|
|
@@ -2354,6 +2354,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)];
|
|
|
|
|
|
|
|
--
|
|
|
|
--
|
|
|
|
2.37.2
|
|
|
|
2.45.0
|
|
|
|
|
|
|
|
|
|
|
|