Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove md5 usage to prevent issues on FIPS enabled systems (closes #29603)#29608

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 2 commits intomatplotlib:mainfrommartinky24:bugfix/29603/md5-fips
Feb 12, 2025

Conversation

martinky24
Copy link
Contributor

@martinky24martinky24 commentedFeb 12, 2025
edited
Loading

PR summary

If you use a FIPS (Federal Information Processing Standards) compliant Python install, then you cannot usepyplot.show to display a plot withplt.rcParams['text.usetex'] = True due to ahashlib.md5 call intexmanager.py.

Instead of just fixing the one instance I ran into, I changed the other usages ofhashlib.md5 in the codebase to nip those in the bud.

Perhttps://docs.python.org/3/library/hashlib.html#hash-algorithms, note thatsha256 is inhashlib.algorithms_guaranteed (whilemd5 might not be), so it seems like a reasonable drop-in-place replacement.

Constructors for hash algorithms that are always present in this module aresha1(),sha224(),sha256(),sha384(),sha512(),sha3_224(),sha3_256(),sha3_384(),sha3_512(),shake_128(),shake_256(),blake2b(), andblake2s().md5() is normally available as well, though it may be missing or blocked if you are using a rare “FIPS compliant” build of Python. These correspond toalgorithms_guaranteed.

I think that these changes should be entirely transparent to end-users (unless they're on FIPS-enabled systems) and are merely implementation details, and thus do not require documentation changes. Correct me if this understanding is incorrect.

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@tacaswelltacaswell added this to thev3.10.1 milestoneFeb 12, 2025
@jklymak
Copy link
Member

I'm not at all an expert but would these have passed FIPS ifusedforsecurity was set to False, regardless of the algorithm?https://docs.python.org/3/library/hashlib.html

@martinky24
Copy link
ContributorAuthor

martinky24 commentedFeb 12, 2025
edited
Loading

I'm not at all an expert but would these have passed FIPS ifusedforsecurity was set to False, regardless of the algorithm?https://docs.python.org/3/library/hashlib.html

Great question. I primarily went this route following the precedent from#18193. If it worked there, I figure it should work here.

It was a few years ago, but I did run across a static compliance scanner that wasn't smart enough to respect (or perhaps intentionally didn't respect?) theusedforsecurity flag. I don't recall any specific details, it was a few years ago.

The other aspect is that I don't think that any of the instances I changed usedmd5 for any reason other than blind convenience. As such, unless there is a performance concern, I'd say that in these use casessha256 is just as convenient. Correct me if I am wrong here, perhapsmd5 may have been chosen intentionally over other algorithms in one of these use cases?

In any event I am happy to discuss or look into this further if there's a desire.

@jklymak
Copy link
Member

I'm sure it was indeed chosen for convenience. But the point of labelling as not for security is to prevent whack a mole with security checkers for something that is just being done to create a convenient label.

martinky24 reacted with thumbs up emoji

…ations are not used for security-based purposes
@martinky24
Copy link
ContributorAuthor

martinky24 commentedFeb 12, 2025
edited
Loading

That's reasonable. Regardless of the algorithm used it can be added, which is helpful in-code documentation. I have added a follow-up commit.

@martinky24
Copy link
ContributorAuthor

I am not an expert in Github / Azure CI pipelining, but I do not think any of the failures are legitimate issues with my changes?

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe@anntzer had a minute for a second review as I think he has some expertise on these parts of the code. But this seems fine to me.

Did you test if FIPS is happy with the flag even with md5 ?

@tacaswell
Copy link
Member

I'm happy to merge this as is. A quick search suggests that getting a GHA running in FIPS mode is not trivial.

The conventional wisdom is "md5 is insecure but fast" does not seem to hold up:

In [6]: %timeit hashlib.md5(data, usedforsecurity=False).hexdigest()46.9 μs ± 69.9 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)In [7]: %timeit hashlib.sha256(data, usedforsecurity=False).hexdigest()20.3 μs ± 19 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

wheredata is len 48407 (a small jpeg) and

In [12]: %timeit hashlib.sha256(b'some short text', usedforsecurity=False).hexdigest()246 ns ± 1.09 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)In [13]: %timeit hashlib.md5(b'some short text', usedforsecurity=False).hexdigest()259 ns ± 0.872 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

so I see no reason to not always prefer sha256

martinky24 and timhoffm reacted with thumbs up emoji

@tacaswelltacaswell merged commit2d5e503 intomatplotlib:mainFeb 12, 2025
41 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestFeb 12, 2025
@lumberbot-appLumberbot (App)
Copy link

Something went wrong ... Please have a look at my logs.

@martinky24
Copy link
ContributorAuthor

For the sake of posterity:

Did you test if FIPS is happy with the flag even with md5 ?

In a quick test in my FIPS environment, FIPS is happy with justusedforsecurity=False

Although I agree with the decision to change the algorithm anyway.

Thanks all!

jklymak reacted with thumbs up emoji

@tacaswell
Copy link
Member

Congratulations on your first merged Maptlotlib PR@martinky24 🎉 Thank you for reporting and fixing this issue and I hope we hear from you again!

martinky24 reacted with thumbs up emoji

@jklymak
Copy link
Member

In a quick test in my FIPS environment, FIPS is happy with justusedforsecurity=False

Thats great - so we have somewhat future proofed ourselves against future changes to what is considered "secure"

martinky24 reacted with thumbs up emoji

@ksundenksunden mentioned this pull requestMar 3, 2025
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@tacaswelltacaswelltacaswell approved these changes

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.10.1
Development

Successfully merging this pull request may close these issues.

[Bug]: Settingtext.usetex=True inpyplot.rcParams Raises FIPS Compliance Errors
3 participants
@martinky24@jklymak@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp