Cooper
unread,Mar 5, 2024, 2:24:13 PMMar 5Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to reportlab-users
Thank you reportlab contributers, for all the work you do.
The hashing algorithm is MD5 which is not FIPS compliant. I had to monkey patch the hashlib to send all MD5 hashes to SHA256.
c = canvas.Canvas(packet, pagesize=page_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/reportlab/pdfgen/canvas.py", line 305, in __init__
self._doc = pdfdoc.PDFDocument(compression=pageCompression,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/reportlab/pdfbase/pdfdoc.py", line 137, in __init__
sig = self.signature = md5()
^^^^^
_hashlib.UnsupportedDigestmodError: [digital envelope routines] unsupported
#Fixed by mokey patch (before report lab import)
# Define a wrapper function that calls hashlib.sha256 instead of hashlib.md5
def sha256_as_md5(*args, **kwargs):
print("Warning: MD5 hash requested; using SHA256 as a FIPS-compliant replacement.")
return hashlib.sha256(*args, **kwargs)
original_md5 = hashlib.md5
# Replace the hashlib.md5 with your wrapper function
hashlib.md5 = sha256_as_md5