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

Run in FIPS enabled environment with python3.10+ #292

Open
markesha opened this issue Oct 30, 2024 · 3 comments
Open

Run in FIPS enabled environment with python3.10+ #292

markesha opened this issue Oct 30, 2024 · 3 comments

Comments

@markesha
Copy link

Python 3.10 and later versions rely on OpenSSL 1.1.1 or newer, which includes FIPS-compliance checks.

MD5 is not an approved algorithm in FIPS mode, so attempting to instantiate hashlib.md5() in get_migration_hash will fail when the system is running in FIPS mode.

Since MD5 is used in a non-security context, the usedforsecurity flag should be added.

    @staticmethod
    def get_migration_hash(app_label: str, migration_name: str) -> str:
        hash_md5 = hashlib.md5(usedforsecurity=False)
        with open(get_migration_abspath(app_label, migration_name), "rb") as f:
            for chunk in iter(lambda: f.read(4096), b""):
                hash_md5.update(chunk)
        return hash_md5.hexdigest()

The same issue in Django django/django@d10c7bf

Traceback (most recent call last):
12:57:05    File "/src/backend/manage.py", line 12, in <module>
12:57:05      execute_from_command_line(sys.argv)
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
12:57:05      utility.execute()
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
12:57:05      self.fetch_command(subcommand).run_from_argv(self.argv)
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 412, in run_from_argv
12:57:05      self.execute(*args, **cmd_options)
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 458, in execute
12:57:05      output = self.handle(*args, **options)
12:57:05               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django_migration_linter/management/commands/lintmigrations.py", line 180, in handle
12:57:05      linter.lint_all_migrations(
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django_migration_linter/migration_linter.py", line 151, in lint_all_migrations
12:57:05      self.lint_migration(m)
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django_migration_linter/migration_linter.py", line 162, in lint_migration
12:57:05      md5hash = self.get_migration_hash(app_label, migration_name)
12:57:05                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12:57:05    File "/src/.venv/lib/python3.12/site-packages/django_migration_linter/migration_linter.py", line 234, in get_migration_hash
12:57:05      hash_md5 = hashlib.md5()
12:57:05                 ^^^^^^^^^^^^^
12:57:05  ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
@David-Wobrock
Copy link
Collaborator

Thanks @markesha for opening an issue.

That would make sense indeed to use something else than MD5.
Feel free to suggest a PR :)

Else, I'll try to look into it, but I can't commit on any time frame :)

markesha pushed a commit to markesha/django-migration-linter that referenced this issue Nov 15, 2024
Python 3.10 and later versions rely on OpenSSL 1.1.1 or newer, which includes FIPS-compliance checks.

MD5 is not an approved algorithm in FIPS mode, so attempting to instantiate hashlib.md5() will fail when the system is running in FIPS mode.
Since MD5 is used in a non-security context, the change adds the [_usedforsecurity_](https://docs.python.org/3/library/hashlib.html) flag.

The same issue in Django django/django@d10c7bf
@markesha
Copy link
Author

@David-Wobrock here you go #293

@markesha
Copy link
Author

markesha commented Jan 3, 2025

@David-Wobrock what do you think?

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

No branches or pull requests

2 participants