From b52b741de580bbf24c79d5db28f4c9a2fbe346b7 Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Fri, 8 Apr 2022 12:50:38 -0400 Subject: [PATCH] pass usedforsecurity=False to md5 --- rsconnect_jupyter/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rsconnect_jupyter/__init__.py b/rsconnect_jupyter/__init__.py index 907b79fe..94853a0f 100644 --- a/rsconnect_jupyter/__init__.py +++ b/rsconnect_jupyter/__init__.py @@ -58,7 +58,14 @@ def md5(s): if hasattr(s, "encode"): s = s.encode("utf-8") - h = hashlib.md5() + try: + h = hashlib.md5() + except Exception: + # md5 is not available in FIPS mode, see if the usedforsecurity option is available + # (it was added in python 3.9). We set usedforsecurity=False since we are only + # using this for a file upload integrity check. + h = hashlib.md5(usedforsecurity=False) + h.update(s) return h.hexdigest()