Skip to content

bpo-31664: Add support of Blowfish in crypt.#3854

Merged
serhiy-storchaka merged 7 commits intopython:masterfrom
serhiy-storchaka:crypt-blowfish
Oct 24, 2017
Merged

bpo-31664: Add support of Blowfish in crypt.#3854
serhiy-storchaka merged 7 commits intopython:masterfrom
serhiy-storchaka:crypt-blowfish

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka commented Oct 2, 2017

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Oct 2, 2017
Comment thread Doc/library/crypt.rst Outdated
.. data:: METHOD_BLF

Another Modular Crypt Format method with 22 character salt and 31
character hash.
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.

Please add the "Blowfish" name, which is better known than "BLF".

Comment thread Doc/library/crypt.rst Outdated

A Modular Crypt Format method with 16 character salt and 86 character
hash. This is the strongest method.
hash based on the SSH-512 hash function. This is the strongest method.
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.

SSH-512?

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.

Oh, I often do this mistake. :)

Comment thread Doc/library/crypt.rst Outdated
The return value is a string suitable for passing as the *salt* argument
to :func:`crypt`.

*log_round* specifies the binary logarithm of the number of rounds
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.

You should mention log_rounds is ignored otherwise.

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'm going to rename this parameter to rounds, because SHA-* methods allow to specify the number of rounds.

Comment thread Doc/library/crypt.rst Outdated
.. versionadded:: 3.3

.. versionchanged:: 3.7
Added the *log_round* parameter.
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.

s/log_round/log_rounds/

Comment thread Lib/crypt.py
if not method.ident:
s = ''
elif method.ident[0] == '2':
s = f'${method.ident}${log_rounds:02d}$'
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.

What if log_rounds is more than 99?

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.

log_rounds should be between 4 and 31. crypt() will return None if it is invalid or out of range. Should we silently bound log_rounds into the range 4 to 31, or raise an error, or keep all as is and let crypt() detect an 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.

I prefer to have a thin wrapper to the C crypt() function. Maybe add unit tests for invalid round values? Negative, 0, 999, etc.?

Comment thread Lib/crypt.py
_add_method('SHA512', '6', 16, 106)
_add_method('SHA256', '5', 16, 63)

for _v in 'b', 'y', 'a', '':
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.

Can you please add a comment explaining this and the following line?

@serhiy-storchaka serhiy-storchaka requested review from pitrou, tiran and vstinner and removed request for pitrou and vstinner October 22, 2017 14:37
Comment thread Doc/library/crypt.rst

A Modular Crypt Format method with 16 character salt and 86 character
hash. This is the strongest method.
hash based on the SHA-512 hash function. This is the strongest method.
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.

Is it still the strongest now?

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 don't know what is stronger, SHA or Blowfish. But since SHA methods were added in glibc when the Blowfish method already was provided by the third-party library, I suppose that at least SHA-512 is not weaker (and likely is stronger) than Blowfish.

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.

You're right. Reference for the SHA2 methods is at https://www.akkadia.org/drepper/SHA-crypt.txt

Comment thread Doc/library/crypt.rst Outdated
character hash.
character hash based on the SHA-256 hash function.

.. data:: METHOD_BLF
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.

Why not METHOD_BLOWFISH?

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.

FreeBSD provides an API for getting a list of supported methods. Their names are: "md5", "blf", "nth", "sha256", "sha512" and "des".

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.

Do we care about the FreeBSD API? We don't expose it...

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 don't have any arguments for other names.

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.

Well, my point is that METHOD_BLOWFISH is obvious while METHOD_BLF is obscure (except perhaps for someone familiar with FreeBSD APIs :-)).

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.

Okay, I'll change the name. In any time we can add an alias if it is needed.

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 prefer METHOD_BLOWFISH. I agree with @pitrou, Python is not FreeBSD.

@serhiy-storchaka serhiy-storchaka deleted the crypt-blowfish branch October 24, 2017 16:36
@serhiy-storchaka
Copy link
Copy Markdown
Member Author

Thank you for your reviews @Haypo and @pitrou!

@tuxxy
Copy link
Copy Markdown

tuxxy commented Feb 6, 2018

This is really stupid.

Can we at least give a DeprecationWarning when importing this, at least? People should not use this and should know very well that using these algorithms result in insecure software.

This is not an enhancement of Python, this is a security risk for its users.

@gpshead
Copy link
Copy Markdown
Member

gpshead commented Feb 6, 2018

Ignoring your uncalled for rudeness...

As a programming language we err on the side of being useful for practical purposes, not to pass judgement on if the data users need to process and/or systems they are writing software to interact with are legacy or not.

At most, I suggest a PR noting APIs that should not be used in new system designs in the documentation (hyperlinking to supporting information for people to read).

@tuxxy
Copy link
Copy Markdown

tuxxy commented Feb 6, 2018

Hold on, how is a DeprecationWarning passing judgement on to users?

In what world is informing users that using deprecated algorithms leads to insecure code?

@tuxxy
Copy link
Copy Markdown

tuxxy commented Feb 6, 2018

Also, what problem is this solving by being in the standard library instead of letting the user use any of the well reviewed and well used libraries that implement these insecure algorithms?

Putting this in the standard library will lead to users using them when they shouldn't.

@gpshead
Copy link
Copy Markdown
Member

gpshead commented Feb 6, 2018

DeprecationWarning is only for things that are going to be removed.

Also, warnings are seen by users of programs more often than by developers. Any time a warning is raised, it spams the wrong people. Use warnings sparingly, only after great thought.

Also I strongly suspect you haven't bothered to read the diff of the commit for this issue. Look at the NEWS entry if nothing else.

locking the conversation as I feel like you are being rude.

@python python locked as too heated and limited conversation to collaborators Feb 6, 2018
@tiran
Copy link
Copy Markdown
Member

tiran commented Feb 7, 2018

Thanks @gpshead, I'm supporting your action.

@serhiy-storchaka serhiy-storchaka changed the title bpo-31664: Add support of Blowfish, extended DES and NT-Hash in crypt. bpo-31664: Add support of Blowfish in crypt. Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants