Catch ValueError for FIPS 140-2 mode

In FIPS 140-2 mode, the underlying operating system will
prevent the loading of certian algorithms for hasing and
encryption. Python hashlib returns a ValueError exception
when the type cannot be instantiated.

This change catches the error and returns a relatively
user understandable reason as to why a failure has occured.

Change-Id: Id1a144b906303caa92ce88793fba8d1b14def738
Story: 2007306
Task: 38788
This commit is contained in:
Julia Kreger 2020-02-18 10:45:23 -08:00
parent e9bcc81536
commit ab00904e27

@ -269,7 +269,16 @@ class ImageDownload(object):
self._hash_algo = hashlib.new(algo)
self._expected_hash_value = image_info.get('os_hash_value')
elif image_info.get('checksum'):
self._hash_algo = hashlib.md5()
try:
self._hash_algo = hashlib.md5()
except ValueError as e:
message = ('Unable to proceed with image {} as the legacy '
'checksum indicator has been used, which makes use '
'the MD5 algorithm. This algorithm failed to load '
'due to the underlying operating system. Error: '
'{}').format(image_info['id'], str(e))
LOG.error(message)
raise errors.RESTError(details=message)
self._expected_hash_value = image_info['checksum']
else:
message = ('Unable to verify image {} with available checksums. '