Commits

Jared Jennings  committed 7b0fd77

Import and use the SHA256 hash function if the MD5 doesn't work.

On a non-FIPS-configured machine, all tests pass before and after the patch.

On a FIPS-configured machine, some tests fail due to the ValueError thrown by the MD5 function before the patch, and a bunch of tests fail after the patch because sha256 is used instead of md5, which changes all of the hash values.

  • Participants
  • Parent commits 5122373

Comments (0)

Files changed (2)

+use-sha256-if-md5-fails
 # Placed by Bitbucket

File use-sha256-if-md5-fails

+# HG changeset patch
+# Parent 35ecbdd750ad125581f52c7754f49990f7e1e513
+diff -r 35ecbdd750ad -r 9f30b4548d1e weberror/util/serial_number_generator.py
+--- a/weberror/util/serial_number_generator.py	Tue Nov 09 14:27:51 2010 -0800
++++ b/weberror/util/serial_number_generator.py	Thu Oct 13 17:34:21 2011 -0500
+@@ -12,6 +12,12 @@
+     from hashlib import md5
+ except ImportError:
+     from md5 import md5
++try:
++    md5('test string')
++    _default_hasher = md5
++except ValueError:
++    from hashlib import sha256
++    _default_hasher = sha256
+ 
+ good_characters = "23456789abcdefghjkmnpqrtuvwxyz"
+ 
+@@ -37,7 +43,7 @@
+         number = number / base
+     return ''.join(result)
+ 
+-def hash_identifier(s, length, pad=True, hasher=md5, prefix='',
++def hash_identifier(s, length, pad=True, hasher=_default_hasher, prefix='',
+                     group=None, upper=False):
+     """
+     Hashes the string (with the given hashing module), then turns that