Modify the correct variable when setting available hashing algorithms (#52994)

* Revert "use list instead of tuple and remove md5 on ValueError (#51357)" c459f040da.
* Modify the correct variable when determining available hashing algorithms
pull/53117/head
Sam Doran 6 years ago committed by GitHub
parent 644362d0be
commit 23a6b88dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +0,0 @@
---
bugfixes:
- ansible.module_utils.basic - fix handling of md5 in algorithms tuple for FIPS compatibility (https://github.com/ansible/ansible/issues/51355)

@ -0,0 +1,2 @@
bugfixes:
- basic - modify the correct variable when determining available hashing algorithms to avoid errors when md5 is not available (https://github.com/ansible/ansible/issues/51355)

@ -129,12 +129,10 @@ try:
for attribute in ('available_algorithms', 'algorithms'):
algorithms = getattr(hashlib, attribute, None)
if algorithms:
# convert algorithms to list instead of immutable tuple so md5 can be removed if not available
algorithms = list(algorithms)
break
if algorithms is None:
# python 2.5+
algorithms = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']
algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
for algorithm in algorithms:
AVAILABLE_HASH_ALGORITHMS[algorithm] = getattr(hashlib, algorithm)
@ -142,7 +140,7 @@ try:
try:
hashlib.md5()
except ValueError:
algorithms.remove('md5')
AVAILABLE_HASH_ALGORITHMS.pop('md5', None)
except Exception:
import sha
AVAILABLE_HASH_ALGORITHMS = {'sha1': sha.sha}

Loading…
Cancel
Save