Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIPS Compliance #361

Closed
jtrinh27 opened this issue Mar 28, 2024 · 7 comments
Closed

FIPS Compliance #361

jtrinh27 opened this issue Mar 28, 2024 · 7 comments
Assignees

Comments

@jtrinh27
Copy link

jtrinh27 commented Mar 28, 2024

Leveraging this Library in a FIPS Enforced environment causes the application using this library to be halted. Although the use of md5 here is valid, it is caught by the FIPS Enforced environment.

hash_method: _t.Any = md5,

@davidism
Copy link
Member

Need to somehow make this lazy, the issue is that hashlib.md5 doesn't exist in FIPS mode, so it raises an exception on attribute access before it's possible to change the default in user code.

@northernSage northernSage self-assigned this Apr 1, 2024
@northernSage
Copy link
Member

how about moving to sha256? That should be a compliant alternative 🤔

@aenglander
Copy link

aenglander commented Apr 1, 2024

Changing the default would be a breaking change. I suggest passing a hash method like the FileSystemCache and lazy loading the default. There's no guarantee that any internal function will be FIPS-compliant. Passing the hash function would allow using an external FIPS-compliant hashing function if necessary.

@davidism
Copy link
Member

davidism commented Apr 1, 2024

I have a lazy loading fix for flask/itsdangerous, I'll ping here once I get that in there.

@northernSage
Copy link
Member

northernSage commented Apr 7, 2024

I'll get the ball rolling, maybe something simple like:

class FileSystemCache(BaseCache):
    # ...
    def __init__(
        ...
        hash_method: _t.Any = None,
    ):
        # ...
        self._hash_method = hash_method

        if hash_method is None:
            try:
                from hashlib import md5
            except ImportError as err:
                raise RuntimeError(
                    "could not import hashlib.md5 "
                    "alternative hashing methods may be used by passing 'hash_method' initialization parameter "
                ) from err
            else:
                self._hash_method = md5

@davidism
Copy link
Member

davidism commented Apr 7, 2024

I just did this in Flask, and will add it to itsdangerous as well: https://github.com/pallets/flask/pull/5460/files Basically write a wrapper that accesses hashlib.md5 internally, so it's not accessed at import time. Then you can continue to use MD5 here and allow people to override it.

def _lazy_md5(string: bytes = b"") -> t.Any:
    return hashlib.md5(string)

hash_method=_lazy_md5

@northernSage
Copy link
Member

cool, will use this to set the default. Thanks all for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants