Skip to content

gh-61460: Switch multiprocessing socket auth to hmac-sha256 #99425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,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)
digest = hmac.new(authkey, message, 'md5').digest()
digest = hmac.new(authkey, message, 'sha256').digest()
response = connection.recv_bytes(256) # reject large message
if response == digest:
connection.send_bytes(WELCOME)
Expand All @@ -819,7 +819,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):]
digest = hmac.new(authkey, message, 'md5').digest()
digest = hmac.new(authkey, message, 'sha256').digest()
connection.send_bytes(digest)
response = connection.recv_bytes(256) # reject large message
if response != WELCOME:
Expand Down
14 changes: 7 additions & 7 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3042,7 +3042,7 @@ def test_remote(self):
del queue


@hashlib_helper.requires_hashdigest('md5')
@hashlib_helper.requires_hashdigest('sha256')
class _TestManagerRestart(BaseTestCase):

@classmethod
Expand Down Expand Up @@ -3531,7 +3531,7 @@ def test_dont_merge(self):
#

@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
@hashlib_helper.requires_hashdigest('md5')
@hashlib_helper.requires_hashdigest('sha256')
class _TestPicklingConnections(BaseTestCase):

ALLOWED_TYPES = ('processes',)
Expand Down Expand Up @@ -3834,7 +3834,7 @@ def test_copy(self):


@unittest.skipUnless(HAS_SHMEM, "requires multiprocessing.shared_memory")
@hashlib_helper.requires_hashdigest('md5')
@hashlib_helper.requires_hashdigest('sha256')
class _TestSharedMemory(BaseTestCase):

ALLOWED_TYPES = ('processes',)
Expand Down Expand Up @@ -4636,7 +4636,7 @@ def test_invalid_handles(self):



@hashlib_helper.requires_hashdigest('md5')
@hashlib_helper.requires_hashdigest('sha256')
class OtherTest(unittest.TestCase):
# TODO: add more tests for deliver/answer challenge.
def test_deliver_challenge_auth_failure(self):
Expand Down Expand Up @@ -4673,7 +4673,7 @@ def send_bytes(self, data):
def initializer(ns):
ns.test += 1

@hashlib_helper.requires_hashdigest('md5')
@hashlib_helper.requires_hashdigest('sha256')
class TestInitializers(unittest.TestCase):
def setUp(self):
self.mgr = multiprocessing.Manager()
Expand Down Expand Up @@ -5537,7 +5537,7 @@ def is_alive(self):
any(process.is_alive() for process in forked_processes))


@hashlib_helper.requires_hashdigest('md5')
@hashlib_helper.requires_hashdigest('sha256')
class TestSyncManagerTypes(unittest.TestCase):
"""Test all the types which can be shared between a parent and a
child process by using a manager which acts as an intermediary
Expand Down Expand Up @@ -5969,7 +5969,7 @@ def install_tests_in_module_dict(remote_globs, start_method):
class Temp(base, Mixin, unittest.TestCase):
pass
if type_ == 'manager':
Temp = hashlib_helper.requires_hashdigest('md5')(Temp)
Temp = hashlib_helper.requires_hashdigest('sha256')(Temp)
Temp.__name__ = Temp.__qualname__ = newname
Temp.__module__ = __module__
remote_globs[newname] = Temp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The socket authentication shared secret confirmation handshake used
internally by multiprocessing has been changed from hmac-md5 to hmac-sha256.