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

Appearance settings

bpo-9216: Expose OpenSSL FIPS_mode() as _hashlib.get_fips_mode()#19703

Merged
miss-islington merged 3 commits into
python:masterpython/cpython:masterfrom
vstinner:hashlib_get_fips_modeCopy head branch name to clipboard
Apr 29, 2020
Merged

bpo-9216: Expose OpenSSL FIPS_mode() as _hashlib.get_fips_mode()#19703
miss-islington merged 3 commits into
python:masterpython/cpython:masterfrom
vstinner:hashlib_get_fips_modeCopy head branch name to clipboard

Conversation

@vstinner

@vstinner vstinner commented Apr 24, 2020

Copy link
Copy Markdown
Member

test.pythoninfo logs OpenSSL FIPS_mode() and Linux
/proc/sys/crypto/fips_enabled in a new "fips" section.

Co-Authored-By: Petr Viktorin encukou@gmail.com

https://bugs.python.org/issue9216

Automerge-Triggered-By: @tiran

@vstinner

Copy link
Copy Markdown
Member Author

cc @tiran @pitrou

@vstinner

Copy link
Copy Markdown
Member Author

Original patch: stratakis@5fa9620

@encukou

encukou commented Apr 24, 2020

Copy link
Copy Markdown
Member

This should stay private, in _hashlib. It's an OpenSSL detail.

@vstinner

Copy link
Copy Markdown
Member Author

Original patch: stratakis/cpython@5fa9620

RHEL has two more patches:

  • stratakis@fa3ce51 "Skip error checking in _hashlib.get_fips_mode" which seems to be specific to RHEL OpenSSL
  • stratakis@63426a2 "Don't re-export get_fips_mode from hashlib" Well, I propose to expose it as hashlib.get_fips_mode() on purpose.

@vstinner

Copy link
Copy Markdown
Member Author

I modified my PR to return a boolean rather directly returning FIPS_mode() integer value.

@vstinner

Copy link
Copy Markdown
Member Author

It may be interesting to log /proc/sys/crypto/fips_enabled in test.pythoninfo.

test.pythoninfo logs OpenSSL FIPS_mode() and Linux
/proc/sys/crypto/fips_enabled in a new "fips" section.

Co-Authored-By: Petr Viktorin <encukou@gmail.com>
@vstinner vstinner changed the title bpo-9216: Expose OpenSSL FIPS_mode() as hashlib.get_fips_mode() bpo-9216: Expose OpenSSL FIPS_mode() as _hashlib.get_fips_mode() Apr 24, 2020
@vstinner

Copy link
Copy Markdown
Member Author

This PR contains no documentation nor NEWS entry on purpose: _hashlib.get_fips_mode() must be private.

Comment thread Modules/_hashopenssl.c
@bedevere-bot

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment thread Modules/_hashopenssl.c
// then the function will return 0 with an error code of
// CRYPTO_R_FIPS_MODE_NOT_SUPPORTED (0x0f06d065)."
// But 0 is also a valid result value.
unsigned long errcode = ERR_peek_last_error();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will fail with other libraries that don't clean the OpenSSL last_error after themselves.
(Apparently that is normal in the OpenSSL world.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a call to ERR_clear_error() at the function entry point: does it solve the issue that you described?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know :(
Christian might.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this will ensure that there is no error left on the error stack and the function only fails when FIPS_mode() puts an error on the error stack.

@vstinner

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@tiran: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from tiran April 24, 2020 14:55
@vstinner

Copy link
Copy Markdown
Member Author

I added ERR_clear_error() call: @tiran, @encukou, @stratakis: Would you mind to review my updated PR? It only adds a private _hashlib.get_fips_mode() method with no documentation.

@encukou

encukou commented Apr 28, 2020

Copy link
Copy Markdown
Member

The patch looks OK: all the issues I had with the original implementation are addressed. But I don't feel qualified to review this – I could just point out what security experts pointed out to me before.

Comment thread Modules/_hashopenssl.c
// then the function will return 0 with an error code of
// CRYPTO_R_FIPS_MODE_NOT_SUPPORTED (0x0f06d065)."
// But 0 is also a valid result value.
unsigned long errcode = ERR_peek_last_error();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this will ensure that there is no error left on the error stack and the function only fails when FIPS_mode() puts an error on the error stack.

@miss-islington miss-islington merged commit e3dfb9b into python:master Apr 29, 2020
@vstinner vstinner deleted the hashlib_get_fips_mode branch April 29, 2020 16:11
@vstinner

Copy link
Copy Markdown
Member Author

Thanks for the reviews @tiran and @encukou!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.