Skip to content
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

Avoid md5 codepaths in FIPS mode #367

Merged
merged 1 commit into from
May 18, 2018
Merged
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
15 changes: 12 additions & 3 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,24 @@ def __init__(self, filename, comment, metadata, python_version, filetype):
# either use the methods or lambdas to do nothing.
blake_update = getattr(blake2_256_hash, 'update', lambda *args: None)
blake_hexdigest = getattr(blake2_256_hash, 'hexdigest', lambda: None)
md5_hash = hashlib.md5()

# NOTE: MD5 is not available on FIPS-enabled systems
md5_hash = None
try:
md5_hash = hashlib.md5()
except ValueError:
md5_hash = None
md5_update = getattr(md5_hash, 'update', lambda *args: None)
md5_hexdigest = getattr(md5_hash, 'hexdigest', lambda: None)

sha2_hash = hashlib.sha256()
with open(filename, "rb") as fp:
for content in iter(lambda: fp.read(io.DEFAULT_BUFFER_SIZE), b''):
md5_hash.update(content)
md5_update(content)
sha2_hash.update(content)
blake_update(content)

self.md5_digest = md5_hash.hexdigest()
self.md5_digest = md5_hexdigest()
self.sha2_digest = sha2_hash.hexdigest()
self.blake2_256_digest = blake_hexdigest()

Expand Down