Skip to content

Fips distutils fix #2

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 2 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
11 changes: 1 addition & 10 deletions Lib/distutils/command/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def upload_file(self, command, pyversion, filename):
'content': (os.path.basename(filename),content),
'filetype': command,
'pyversion': pyversion,
'sha256_digest': hashlib.sha256(content).hexdigest(),

# additional meta-data
'metadata_version': '1.0',
Expand All @@ -120,16 +121,6 @@ def upload_file(self, command, pyversion, filename):
'requires': meta.get_requires(),
'obsoletes': meta.get_obsoletes(),
}
try:
digest = hashlib.md5(content).hexdigest()
except ValueError as e:
msg = 'calculating md5 checksum failed: %s' % e
self.announce(msg, log.ERROR)
if not hashlib.get_fips_mode():
# this really shouldn't fail
raise
else:
data['md5_digest'] = digest
comment = ''
if command == 'bdist_rpm':
dist, version, id = platform.dist()
Expand Down
13 changes: 2 additions & 11 deletions Lib/distutils/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import unittest
import unittest.mock as mock
from urllib.request import HTTPError
import hashlib

from test.support import run_unittest

Expand Down Expand Up @@ -131,11 +130,7 @@ def test_upload(self):

# what did we send ?
headers = dict(self.last_open.req.headers)
if hashlib.get_fips_mode():
# md5 hash is omitted
self.assertEqual(headers['Content-length'], '2020')
else:
self.assertEqual(headers['Content-length'], '2162')
self.assertEqual(headers['Content-length'], '2197')
content_type = headers['Content-type']
self.assertTrue(content_type.startswith('multipart/form-data'))
self.assertEqual(self.last_open.req.get_method(), 'POST')
Expand Down Expand Up @@ -171,11 +166,7 @@ def test_upload_correct_cr(self):
cmd.run()

headers = dict(self.last_open.req.headers)
if hashlib.get_fips_mode():
# md5 hash is omitted
self.assertEqual(headers['Content-length'], '2030')
else:
self.assertEqual(headers['Content-length'], '2172')
self.assertEqual(headers['Content-length'], '2207')
self.assertIn(b'long description\r', self.last_open.req.data)

def test_upload_fails(self):
Expand Down