mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
use list instead of tuple and remove md5 on ValueError (#51357)
* use list instead of tuple and remove md5 on ValueError Signed-off-by: michael.sgarbossa <msgarbossa@cvs.com> * convert algorithms to list and add comment Signed-off-by: michael.sgarbossa <msgarbossa@cvs.com> * only convert to list if algorithms is not None Signed-off-by: michael.sgarbossa <msgarbossa@cvs.com> * new fragment for PR 51357 Signed-off-by: michael.sgarbossa <msgarbossa@cvs.com> * fix lint: remove blank line
This commit is contained in:
committed by
Sam Doran
parent
d40f0313e2
commit
c459f040da
3
changelogs/fragments/51357-module_utils-basic.yml
Normal file
3
changelogs/fragments/51357-module_utils-basic.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- ansible.module_utils.basic - fix handling of md5 in algorithms tuple for FIPS compatibility (https://github.com/ansible/ansible/issues/51355)
|
||||||
@@ -128,10 +128,12 @@ try:
|
|||||||
for attribute in ('available_algorithms', 'algorithms'):
|
for attribute in ('available_algorithms', 'algorithms'):
|
||||||
algorithms = getattr(hashlib, attribute, None)
|
algorithms = getattr(hashlib, attribute, None)
|
||||||
if algorithms:
|
if algorithms:
|
||||||
|
# convert algorithms to list instead of immutable tuple so md5 can be removed if not available
|
||||||
|
algorithms = list(algorithms)
|
||||||
break
|
break
|
||||||
if algorithms is None:
|
if algorithms is None:
|
||||||
# python 2.5+
|
# python 2.5+
|
||||||
algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
|
algorithms = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']
|
||||||
for algorithm in algorithms:
|
for algorithm in algorithms:
|
||||||
AVAILABLE_HASH_ALGORITHMS[algorithm] = getattr(hashlib, algorithm)
|
AVAILABLE_HASH_ALGORITHMS[algorithm] = getattr(hashlib, algorithm)
|
||||||
|
|
||||||
@@ -139,7 +141,7 @@ try:
|
|||||||
try:
|
try:
|
||||||
hashlib.md5()
|
hashlib.md5()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
algorithms.pop('md5', None)
|
algorithms.remove('md5')
|
||||||
except Exception:
|
except Exception:
|
||||||
import sha
|
import sha
|
||||||
AVAILABLE_HASH_ALGORITHMS = {'sha1': sha.sha}
|
AVAILABLE_HASH_ALGORITHMS = {'sha1': sha.sha}
|
||||||
|
|||||||
Reference in New Issue
Block a user