Skip to content

Commit 5e6476a

Browse files
authored
drop support for openssl < 1.1.1d (#8449)
This removes the OS random engine, which contained the only CPython PSF licensed code in the repository. Accordingly, that license has now been removed.
1 parent 4c24dd0 commit 5e6476a

File tree

20 files changed

+20
-1194
lines changed

20 files changed

+20
-1194
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ jobs:
136136
- {IMAGE: "bullseye", TOXENV: "py39", RUNNER: "ubuntu-latest"}
137137
- {IMAGE: "bookworm", TOXENV: "py311", RUNNER: "ubuntu-latest"}
138138
- {IMAGE: "sid", TOXENV: "py311", RUNNER: "ubuntu-latest"}
139-
- {IMAGE: "ubuntu-bionic", TOXENV: "py36", RUNNER: "ubuntu-latest"}
140139
- {IMAGE: "ubuntu-focal", TOXENV: "py38", RUNNER: "ubuntu-latest"}
141140
- {IMAGE: "ubuntu-jammy", TOXENV: "py310", RUNNER: "ubuntu-latest"}
142141
- {IMAGE: "ubuntu-rolling", TOXENV: "py310", RUNNER: "ubuntu-latest"}
@@ -182,7 +181,6 @@ jobs:
182181
run: mkdir -p "${HOME}/.cache/pip"
183182
- run: |
184183
echo "OPENSSL_FORCE_FIPS_MODE=1" >> $GITHUB_ENV
185-
echo "CFLAGS=-DUSE_OSRANDOM_RNG_FOR_TESTING" >> $GITHUB_ENV
186184
if: matrix.IMAGE.FIPS
187185
- run: /venv/bin/python -m pip install -c ci-constraints-requirements.txt 'tox>3' coverage
188186
- run: '/venv/bin/tox -vvv --notest'
@@ -373,11 +371,11 @@ jobs:
373371
- {OS: 'macos-12', ARCH: 'x86_64'}
374372
- {OS: [self-hosted, macos, ARM64, tart], ARCH: 'arm64'}
375373
PYTHON:
376-
- {VERSION: "3.6", TOXENV: "py36-nocoverage", EXTRA_CFLAGS: ""}
377-
- {VERSION: "3.11", TOXENV: "py311", EXTRA_CFLAGS: "-DUSE_OSRANDOM_RNG_FOR_TESTING"}
374+
- {VERSION: "3.6", TOXENV: "py36-nocoverage"}
375+
- {VERSION: "3.11", TOXENV: "py311"}
378376
exclude:
379377
# We only test latest Python on arm64. The py36 won't work since there's no universal2 binary
380-
- PYTHON: {VERSION: "3.6", TOXENV: "py36-nocoverage", EXTRA_CFLAGS: ""}
378+
- PYTHON: {VERSION: "3.6", TOXENV: "py36-nocoverage"}
381379
RUNNER: {OS: [self-hosted, macos, ARM64, tart], ARCH: 'arm64'}
382380
name: "${{ matrix.PYTHON.TOXENV }} on macOS ${{ matrix.RUNNER.ARCH }}"
383381
timeout-minutes: 15
@@ -420,11 +418,10 @@ jobs:
420418
run: |
421419
OPENSSL_DIR=$(readlink -f ../openssl-macos-universal2/) \
422420
OPENSSL_STATIC=1 \
423-
CFLAGS="-Werror -Wno-error=deprecated-declarations -Wno-error=incompatible-pointer-types-discards-qualifiers -Wno-error=unused-function -mmacosx-version-min=10.12 $EXTRA_CFLAGS" \
421+
CFLAGS="-Werror -Wno-error=deprecated-declarations -Wno-error=incompatible-pointer-types-discards-qualifiers -Wno-error=unused-function -mmacosx-version-min=10.12" \
424422
tox -vvv --notest
425423
env:
426424
TOXENV: ${{ matrix.PYTHON.TOXENV }}
427-
EXTRA_CFLAGS: ${{ matrix.PYTHON.EXTRA_CFLAGS }}
428425
CARGO_TARGET_DIR: ${{ format('{0}/src/rust/target/', github.workspace) }}
429426
- name: Tests
430427
run: tox --skip-pkg-install -- --color=yes --wycheproof-root=wycheproof
@@ -443,8 +440,8 @@ jobs:
443440
- {ARCH: 'x86', WINDOWS: 'win32'}
444441
- {ARCH: 'x64', WINDOWS: 'win64'}
445442
PYTHON:
446-
- {VERSION: "3.6", TOXENV: "py36-nocoverage", CL_FLAGS: ""}
447-
- {VERSION: "3.11", TOXENV: "py311", CL_FLAGS: "/D USE_OSRANDOM_RNG_FOR_TESTING"}
443+
- {VERSION: "3.6", TOXENV: "py36-nocoverage"}
444+
- {VERSION: "3.11", TOXENV: "py311"}
448445
JOB_NUMBER: [0, 1]
449446
name: "${{ matrix.PYTHON.TOXENV }} on ${{ matrix.WINDOWS.WINDOWS }} (part ${{ matrix.JOB_NUMBER }})"
450447
timeout-minutes: 15
@@ -481,7 +478,6 @@ jobs:
481478
- name: Configure
482479
run: |
483480
echo "OPENSSL_DIR=C:/openssl-${{ matrix.WINDOWS.WINDOWS }}" >> $GITHUB_ENV
484-
echo "CL=${{ matrix.PYTHON.CL_FLAGS }}" >> $GITHUB_ENV
485481
shell: bash
486482

487483
- name: Clone wycheproof

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Changelog
88

99
.. note:: This version is not yet released and is under active development.
1010

11+
* **BACKWARDS INCOMPATIBLE:** Support for OpenSSL less than 1.1.1d has been
12+
removed. Users on older version of OpenSSL will need to upgrade.
13+
1114
.. _v40-0-0:
1215

1316
40.0.0 - 2023-03-24

LICENSE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
This software is made available under the terms of *either* of the licenses
22
found in LICENSE.APACHE or LICENSE.BSD. Contributions to cryptography are made
33
under the terms of *both* these licenses.
4-
5-
The code used in the OS random engine is derived from CPython, and is licensed
6-
under the terms of the PSF License Agreement.

LICENSE.PSF

Lines changed: 0 additions & 41 deletions
This file was deleted.

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ include CONTRIBUTING.rst
33
include LICENSE
44
include LICENSE.APACHE
55
include LICENSE.BSD
6-
include LICENSE.PSF
76
include README.rst
87
include tox.ini
98

docs/openssl.rst

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ A list of supported versions can be found in our :doc:`/installation`
1010
documentation.
1111

1212
In general the backend should be considered an internal implementation detail
13-
of the project, but there are some public methods available for more advanced
14-
control.
13+
of the project, but there are some public methods available for debugging
14+
purposes.
1515

1616
.. data:: cryptography.hazmat.backends.openssl.backend
1717

@@ -29,21 +29,6 @@ control.
2929
typically shown in hexadecimal (e.g. ``0x1010003f``). This is
3030
not necessarily the same version as it was compiled against.
3131

32-
.. method:: activate_osrandom_engine()
33-
34-
Activates the OS random engine. This will effectively disable OpenSSL's
35-
default CSPRNG.
36-
37-
.. method:: osrandom_engine_implementation()
38-
39-
.. versionadded:: 1.7
40-
41-
Returns the implementation of OS random engine.
42-
43-
.. method:: activate_builtin_random()
44-
45-
This will activate the default OpenSSL CSPRNG.
46-
4732
.. _legacy-provider:
4833

4934
Legacy provider in OpenSSL 3.x
@@ -56,68 +41,5 @@ disable the legacy provider in OpenSSL 3.x. This will disable legacy
5641
cryptographic algorithms, including ``Blowfish``, ``CAST5``, ``SEED``,
5742
``ARC4``, and ``RC2`` (which is used by some encrypted serialization formats).
5843

59-
OS random engine
60-
----------------
61-
62-
.. note::
63-
64-
As of OpenSSL 1.1.1d its CSPRNG is fork-safe by default.
65-
``cryptography`` does not compile or load the custom engine on
66-
>= 1.1.1d.
67-
68-
By default OpenSSL uses a user-space CSPRNG that is seeded from system random (
69-
``/dev/urandom`` or ``CryptGenRandom``). This CSPRNG is not reseeded
70-
automatically when a process calls ``fork()``. This can result in situations
71-
where two different processes can return similar or identical keys and
72-
compromise the security of the system.
73-
74-
The approach this project has chosen to mitigate this vulnerability is to
75-
include an engine that replaces the OpenSSL default CSPRNG with one that
76-
sources its entropy from ``/dev/urandom`` on UNIX-like operating systems and
77-
uses ``CryptGenRandom`` on Windows. This method of pulling from the system pool
78-
allows us to avoid potential issues with `initializing the RNG`_ as well as
79-
protecting us from the ``fork()`` weakness.
80-
81-
This engine is **active** by default when importing the OpenSSL backend. When
82-
active this engine will be used to generate all the random data OpenSSL
83-
requests.
84-
85-
When importing only the binding it is added to the engine list but
86-
**not activated**.
87-
88-
89-
OS random sources
90-
-----------------
91-
92-
On macOS and FreeBSD ``/dev/urandom`` is an alias for ``/dev/random``. The
93-
implementation on macOS uses the `Yarrow`_ algorithm. FreeBSD uses the
94-
`Fortuna`_ algorithm.
95-
96-
On Windows the implementation of ``CryptGenRandom`` depends on which version of
97-
the operation system you are using. See the `Microsoft documentation`_ for more
98-
details.
99-
100-
Linux uses its own PRNG design. ``/dev/urandom`` is a non-blocking source
101-
seeded from the same pool as ``/dev/random``.
102-
103-
+------------------------------------------+------------------------------+
104-
| Windows | ``CryptGenRandom()`` |
105-
+------------------------------------------+------------------------------+
106-
| Linux >= 3.17 with working | ``getrandom()`` |
107-
| ``SYS_getrandom`` syscall | |
108-
+------------------------------------------+------------------------------+
109-
| OpenBSD >= 5.6 | ``getentropy()`` |
110-
+------------------------------------------+------------------------------+
111-
| BSD family (including macOS 10.12+) with | ``getentropy()`` |
112-
| ``SYS_getentropy`` in ``sys/syscall.h`` | |
113-
+------------------------------------------+------------------------------+
114-
| fallback | ``/dev/urandom`` with |
115-
| | cached file descriptor |
116-
+------------------------------------------+------------------------------+
117-
11844

11945
.. _`OpenSSL`: https://www.openssl.org/
120-
.. _`initializing the RNG`: https://en.wikipedia.org/wiki/OpenSSL#Predictable_private_keys_.28Debian-specific.29
121-
.. _`Fortuna`: https://en.wikipedia.org/wiki/Fortuna_(PRNG)
122-
.. _`Yarrow`: https://en.wikipedia.org/wiki/Yarrow_algorithm
123-
.. _`Microsoft documentation`: https://docs.microsoft.com/en-us/windows/desktop/api/wincrypt/nf-wincrypt-cryptgenrandom

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = attr: cryptography.__version__
44
description = cryptography is a package which provides cryptographic recipes and primitives to Python developers.
55
long_description = file: README.rst
66
long_description_content_type = text/x-rst
7-
license = (Apache-2.0 OR BSD-3-Clause) AND PSF-2.0
7+
license = Apache-2.0 OR BSD-3-Clause
88
url = https://github.com/pyca/cryptography
99
author = The Python Cryptographic Authority and individual contributors
1010
author_email = [email protected]

src/_cffi_src/build_openssl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def _extra_compile_args(platform):
100100
"nid",
101101
"objects",
102102
"opensslv",
103-
"osrandom_engine",
104103
"pem",
105104
"pkcs12",
106105
"rand",

src/_cffi_src/openssl/cryptography.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,25 @@
5252
#define CRYPTOGRAPHY_LIBRESSL_LESS_THAN_370 (0)
5353
#endif
5454
55-
#if OPENSSL_VERSION_NUMBER < 0x10101000
56-
#error "pyca/cryptography MUST be linked with Openssl 1.1.1 or later"
55+
#if OPENSSL_VERSION_NUMBER < 0x10101040
56+
#error "pyca/cryptography MUST be linked with Openssl 1.1.1d or later"
5757
#endif
5858
59-
#define CRYPTOGRAPHY_OPENSSL_111D_OR_GREATER \
60-
(OPENSSL_VERSION_NUMBER >= 0x10101040 && !CRYPTOGRAPHY_IS_LIBRESSL)
6159
#define CRYPTOGRAPHY_OPENSSL_300_OR_GREATER \
6260
(OPENSSL_VERSION_NUMBER >= 0x30000000 && !CRYPTOGRAPHY_IS_LIBRESSL)
6361
64-
#define CRYPTOGRAPHY_OPENSSL_LESS_THAN_111B \
65-
(OPENSSL_VERSION_NUMBER < 0x10101020 || CRYPTOGRAPHY_IS_LIBRESSL)
66-
#define CRYPTOGRAPHY_OPENSSL_LESS_THAN_111D \
67-
(OPENSSL_VERSION_NUMBER < 0x10101040 || CRYPTOGRAPHY_IS_LIBRESSL)
6862
#define CRYPTOGRAPHY_OPENSSL_LESS_THAN_111E \
6963
(OPENSSL_VERSION_NUMBER < 0x10101050 || CRYPTOGRAPHY_IS_LIBRESSL)
70-
#if (CRYPTOGRAPHY_OPENSSL_LESS_THAN_111D && !CRYPTOGRAPHY_IS_LIBRESSL && \
71-
!defined(OPENSSL_NO_ENGINE)) || defined(USE_OSRANDOM_RNG_FOR_TESTING)
72-
#define CRYPTOGRAPHY_NEEDS_OSRANDOM_ENGINE 1
73-
#else
74-
#define CRYPTOGRAPHY_NEEDS_OSRANDOM_ENGINE 0
75-
#endif
76-
/* Ed25519 support is available from OpenSSL 1.1.1b and LibreSSL 3.7.0. */
64+
/* Ed25519 support is in all supported OpenSSLs as well as LibreSSL 3.7.0. */
7765
#define CRYPTOGRAPHY_HAS_WORKING_ED25519 \
78-
(!CRYPTOGRAPHY_OPENSSL_LESS_THAN_111B || \
66+
(!CRYPTOGRAPHY_IS_LIBRESSL || \
7967
(CRYPTOGRAPHY_IS_LIBRESSL && !CRYPTOGRAPHY_LIBRESSL_LESS_THAN_370))
8068
"""
8169

8270
TYPES = """
83-
static const int CRYPTOGRAPHY_OPENSSL_111D_OR_GREATER;
8471
static const int CRYPTOGRAPHY_OPENSSL_300_OR_GREATER;
8572
86-
static const int CRYPTOGRAPHY_OPENSSL_LESS_THAN_111B;
8773
static const int CRYPTOGRAPHY_OPENSSL_LESS_THAN_111E;
88-
static const int CRYPTOGRAPHY_NEEDS_OSRANDOM_ENGINE;
8974
static const int CRYPTOGRAPHY_HAS_WORKING_ED25519;
9075
9176
static const int CRYPTOGRAPHY_LIBRESSL_LESS_THAN_370;

src/_cffi_src/openssl/err.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#define ERR_LIB_PROV 0
5050
#endif
5151
52-
#if !CRYPTOGRAPHY_OPENSSL_111D_OR_GREATER || CRYPTOGRAPHY_IS_BORINGSSL
52+
#ifndef EVP_R_XTS_DUPLICATED_KEYS
5353
static const int EVP_R_XTS_DUPLICATED_KEYS = 0;
5454
#endif
5555

src/_cffi_src/openssl/osrandom_engine.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)