Skip to content

Commit 86d7e8e

Browse files
authored
Merge pull request #175 from rstudio/mm-md5-fips
md5 fallback for FIPS mode
2 parents b817710 + 45f2b38 commit 86d7e8e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Added
10+
- Support for generating md5 file upload checksums, even if Python's `hashlib`
11+
was configured for FIPS mode. The fallback uses the `usedforsecurity` option which is
12+
available in Python 3.9 and later.
13+
14+
715
## [1.5.2] - 2021-04-02
816

917
### Added

rsconnect/bundle.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,20 @@ def manifest_add_buffer(manifest, filename, buf):
7575
manifest["files"][filename] = {"checksum": buffer_checksum(buf)}
7676

7777

78+
def make_hasher():
79+
try:
80+
return hashlib.md5()
81+
except Exception:
82+
# md5 is not available in FIPS mode, see if the usedforsecurity option is available
83+
# (it was added in python 3.9). We set usedforsecurity=False since we are only
84+
# using this for a file upload integrity check.
85+
return hashlib.md5(usedforsecurity=False)
86+
87+
7888
def file_checksum(path):
7989
"""Calculate the md5 hex digest of the specified file"""
8090
with open(path, "rb") as f:
81-
m = hashlib.md5()
91+
m = make_hasher()
8292
chunk_size = 64 * 1024
8393

8494
chunk = f.read(chunk_size)
@@ -90,7 +100,7 @@ def file_checksum(path):
90100

91101
def buffer_checksum(buf):
92102
"""Calculate the md5 hex digest of a buffer (str or bytes)"""
93-
m = hashlib.md5()
103+
m = make_hasher()
94104
m.update(to_bytes(buf))
95105
return m.hexdigest()
96106

0 commit comments

Comments
 (0)