|
|
23b3e9 |
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
|
|
|
23b3e9 |
--- a/Lib/multiprocessing/connection.py
|
|
|
23b3e9 |
+++ b/Lib/multiprocessing/connection.py
|
|
|
23b3e9 |
@@ -41,6 +41,10 @@
|
|
|
23b3e9 |
# A very generous timeout when it comes to local connections...
|
|
|
23b3e9 |
CONNECTION_TIMEOUT = 20.
|
|
|
23b3e9 |
|
|
|
23b3e9 |
+# The hmac module implicitly defaults to using MD5.
|
|
|
23b3e9 |
+# Support using a stronger algorithm for the challenge/response code:
|
|
|
23b3e9 |
+HMAC_DIGEST_NAME='sha256'
|
|
|
23b3e9 |
+
|
|
|
23b3e9 |
_mmap_counter = itertools.count()
|
|
|
23b3e9 |
|
|
|
23b3e9 |
default_family = 'AF_INET'
|
|
|
23b3e9 |
@@ -700,12 +704,16 @@
|
|
|
23b3e9 |
WELCOME = b'#WELCOME#'
|
|
|
23b3e9 |
FAILURE = b'#FAILURE#'
|
|
|
23b3e9 |
|
|
|
23b3e9 |
+def get_digestmod_for_hmac():
|
|
|
23b3e9 |
+ import hashlib
|
|
|
23b3e9 |
+ return getattr(hashlib, HMAC_DIGEST_NAME)
|
|
|
23b3e9 |
+
|
|
|
23b3e9 |
def deliver_challenge(connection, authkey):
|
|
|
23b3e9 |
import hmac
|
|
|
23b3e9 |
assert isinstance(authkey, bytes)
|
|
|
23b3e9 |
message = os.urandom(MESSAGE_LENGTH)
|
|
|
23b3e9 |
connection.send_bytes(CHALLENGE + message)
|
|
|
23b3e9 |
- digest = hmac.new(authkey, message).digest()
|
|
|
23b3e9 |
+ digest = hmac.new(authkey, message, get_digestmod_for_hmac()).digest()
|
|
|
23b3e9 |
response = connection.recv_bytes(256) # reject large message
|
|
|
23b3e9 |
if response == digest:
|
|
|
23b3e9 |
connection.send_bytes(WELCOME)
|
|
|
23b3e9 |
@@ -719,7 +727,7 @@
|
|
|
23b3e9 |
message = connection.recv_bytes(256) # reject large message
|
|
|
23b3e9 |
assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' % message
|
|
|
23b3e9 |
message = message[len(CHALLENGE):]
|
|
|
23b3e9 |
- digest = hmac.new(authkey, message).digest()
|
|
|
23b3e9 |
+ digest = hmac.new(authkey, message, get_digestmod_for_hmac()).digest()
|
|
|
23b3e9 |
connection.send_bytes(digest)
|
|
|
23b3e9 |
response = connection.recv_bytes(256) # reject large message
|
|
|
23b3e9 |
if response != WELCOME:
|