This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: OpenSSL 1.1.1 still implements some disable-flags for Blake2, Scrypt
Type: Stage: resolved
Components: Build, Extension Modules, SSL Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: Alexandru Ardelean, christian.heimes
Priority: normal Keywords: patch

Created on 2021-10-27 13:16 by Alexandru Ardelean, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29237 closed Alexandru Ardelean, 2021-10-27 13:24
Messages (7)
msg405093 - (view) Author: Alexandru Ardelean (Alexandru Ardelean) * Date: 2021-10-27 13:16
This follows update https://bugs.python.org/issue43669

Which is present in Python 3.10

Some OpenSSL 1.1.1 can be built without Blake2 support or Scrypt.

SHA3 and SHAKE do not seem to have any enable/disable flags.

This results in compiler errors where EVP_blake2b512, EVP_blake2s256, EVP_PBE_scrypt and PKCS5_v2_scrypt_keyivgen can be un-defined.

This is unfortunate behavior on the part of OpenSSL 1.1.1.

So, for BLAKE2 and SCRYPT, we should still check that the OPENSSL_NO_SCRYPT and OPENSSL_NO_BLAKE2 defines are not-define.
msg405094 - (view) Author: Alexandru Ardelean (Alexandru Ardelean) * Date: 2021-10-27 13:23
Note: PKCS5_v2_scrypt_keyivgen() will not cause an error, but EVP_PBE_scrypt() will
msg405098 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-10-27 13:51
Python 3.10 and newer require OpenSSL 1.1.1+ with blake2, sha3, scrypt, and similar features enabled. The required feature set is specified in PEP 644, https://www.python.org/dev/peps/pep-0644/#compatibility . Python requires the features, because I want to keep our test matrix small and guarantee the presence of a minimal feature set.

Why do you want to build OpenSSL without blake2 or scrypt?
msg405150 - (view) Author: Alexandru Ardelean (Alexandru Ardelean) * Date: 2021-10-28 07:24
Apologies for the slow reply.

It was the end of work-day when I submitted the bug & patch.
I know, not a good method, but I do what I can :)

So, OpenWrt's OpenSSL does not build BLAKE2 by default.
See: https://github.com/openwrt/openwrt/blob/master/package/libs/openssl/Makefile#L190

Scrypt is on by default. In the sense that there is no disable flag.

I only care about BLAKE2, but I was trying not to half-ass the implementation, given that Scrypt is also disable-able.

Now there are 2 options that I feel could be reasonable (anyone is free to disagree with me here):
1. this is patch upstream as I'm trying here
2. keep this patch downstream (i.e. just in our tree for OpenWrt's Python) until OpenSSL (or OpenWrt) enables BLAKE2 by default

There are several options that feel a bit more difficult (to me):
3. Enable OpenSSL BLAKE2 on by default in OpenWrt core; this may also work, but requires some discussion with the OpenWrt core-team that handles OpenSSL; though usually OpenWrt tries to be minimal, so I'm feeling there would be some resistance 
4. Not build hashlib (in Python) if BLAKE2 is not enabled in OpenSSL ; this is doable, but maybe a bit too complicated (for what is worth); it can cause support issues (in OpenWrt) like "hey, where did hashlib go?"

I may have missed a few possible options. But these are the more obvious ones.

Moving forward, I am fine with either of the first 2 options.
I am feeling that option 2 is closer to what is desired by upstream Python (which I am fine to do).

Thank you :)
Alex
msg405159 - (view) Author: Alexandru Ardelean (Alexandru Ardelean) * Date: 2021-10-28 08:14
So, I've read through:

https://www.python.org/dev/peps/pep-0644/#compatibility


I also stumbled over:
https://lwn.net/Articles/841664/

Which also led to:
https://www.python.org/dev/peps/pep-0644/#libressl-support

The answer is loud and clear now: will keep this downstream.

Thank you and apologies for the noise.
msg405162 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-10-28 08:46
Ah, OpenWRT. :)

Thanks for you detailed explanation. I kinda agree that it makes sense for small, embedded systems like OpenWRT to reduce the size of binaries. After all storage and memory are precious on these systems.

PEP 644 favors usability over flexibility. 3rd party library developers can now rely on the presence of hashlib features. Before 3.10 they could not be sure that a Python build had certain features.

A downstream patch in OpenWRT makes sense.

By the way, you might be interested in --with-builtin-hashlib-hashes configure flag. It lets you disable builtin modules like _md5 and _sha3. The shared libraries are large. If you disable the builtin blake2 module, then certain features like MAC and tree hashing are not working.
msg405164 - (view) Author: Alexandru Ardelean (Alexandru Ardelean) * Date: 2021-10-28 09:02
> Thanks for you detailed explanation. I kinda agree that it makes sense for small, embedded systems like OpenWRT to reduce the size of binaries. After all storage and memory are precious on these systems.

So, OpenWrt is not as tiny as it used to be.
A large part is due to the Linux kernel increasing in default size.
But other libs do a small increase as well (with each new revision).
I think a new micro-OpenWrt (or similar project) would be required in some future to support the devices with less than 4 MB of flash and less than 32 MB of RAM.
OpenWrt last supported the 4/32 combination in 2018 (with the 18.06 release).
(But that's another topic I for when I retire maybe :p )

I think where users still install Python is where they have at least 64/128 MB of persistent storage/flash memory.

I am still surprised about the desire of users to install Python on such devices (even after doing this for ~7 years of [co-]maintaining it it on OpenWrt).
The Turris devices/routers (are one example that) use a lot of CPython for some userspace stuff.

> PEP 644 favors usability over flexibility. 3rd party library developers can now rely on the presence of hashlib features. Before 3.10 they could not be sure that a Python build had certain features.

Ack.

> A downstream patch in OpenWRT makes sense.

I've started down that path.
But guess what... I hit LibreSSL (on the host build) :P
Now I have a bigger job (than I thought) to update to 3.10
But that's fine.
These events are rare, and I do enjoy to fix them (when I can).

> By the way, you might be interested in --with-builtin-hashlib-hashes configure flag. It lets you disable builtin modules like _md5 and _sha3. The shared libraries are large. If you disable the builtin blake2 module, then certain features like MAC and tree hashing are not working.

I would not add too many flags in the Python build (on our side).
For now we have some ways to "modularize" a Python installation.
It's basically a hack-job of splitting Core-Python libraries into separate packages.
That's when someone really wants to do a minimal installation of Python, and add only 2-3 libraries on top.
Essentially, we build Python with all defaults possible, then some libs (.so & .py files) get packaged together (like ssl.py and _ssl.so from python).
The more immediate benefits (in this example) are that you can avoid installing OpenSSL libs on your device, but have some Python.

I know... crazy stuff, but people seem to do it.

I do admit some Python fans and developers would cringe at this but ¯\_(ツ)_/¯
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89790
2021-11-08 16:18:21christian.heimeslinkissue45749 superseder
2021-10-28 09:02:25Alexandru Ardeleansetmessages: + msg405164
2021-10-28 08:46:34christian.heimessetmessages: + msg405162
2021-10-28 08:14:23Alexandru Ardeleansetstatus: open -> closed
resolution: wont fix
messages: + msg405159

stage: patch review -> resolved
2021-10-28 07:24:09Alexandru Ardeleansetmessages: + msg405150
2021-10-27 13:51:00christian.heimessetmessages: + msg405098
2021-10-27 13:24:27Alexandru Ardeleansetkeywords: + patch
stage: patch review
pull_requests: + pull_request27500
2021-10-27 13:23:02Alexandru Ardeleansetmessages: + msg405094
2021-10-27 13:16:46Alexandru Ardeleancreate