Repository navigation
tls: replace deprecated X509_NAME_get_text_by_NID API - #15227
Conversation
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 7a3dc52. Configure here.
|
This patch needs an update due to commit 84c7553 |
|
Please re-base on top of latest |
|
Adding a data point on urgency. Since 2026-09-28, Homebrew's We hit this in RediSearch CI on |
Co-authored-by: hristostaykov-del <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #15227 +/- ##
============================================
- Coverage 77.64% 77.39% -0.25%
============================================
Files 146 146
Lines 88012 88016 +4
============================================
- Hits 68335 68122 -213
- Misses 19677 19894 +217
🚀 New features to boost your workflow:
|
OpenSSL 4.0 ("Constify X509_NAME", b0f2107b44) makes
X509_get_subject_name(), X509_NAME_get_entry() and
X509_NAME_ENTRY_get_data() return const pointers, so initializing the
non-const subject/entry/data locals discards a qualifier:
tls.c:709: error: initialization discards 'const' qualifier from
pointer target type [-Werror=discarded-qualifiers]
tls.c:718: (same)
tls.c:719: (same)
OpenSSL 1.0.2 and 1.1.1, on the other hand, declare
X509_NAME_get_index_by_NID() with a non-const X509_NAME parameter
(1.0.2 also X509_NAME_get_entry() and X509_NAME_ENTRY_get_data()), so
const locals discard a qualifier there instead. No single declaration
is clean on both ends of the range we build against.
Chain the calls instead of holding the intermediate objects in typed
locals: within any one OpenSSL version each accessor's return type
matches the next accessor's parameter type, so this is warning-free
everywhere. Keep an explicit NULL check on the subject; the field is
mandatory in a parsed certificate and X509_NAME_get_index_by_NID()
handles NULL anyway, but the check is free and self-explanatory.
X509_get_subject_name() only returns cert_info.subject and this runs
once per accepted connection, so calling it three times is negligible.
This matters for CI, not just for local builds: build-macos-latest
compiles with -Werror and BUILD_TLS=yes, and Homebrew's `openssl`
formula points at openssl@4 since 2026-09-28. The current runner image
(20260907) still ships OpenSSL 3.6.4, so the job is green today and
will turn red at the next image refresh.
Verified by compiling the complete tls.c with the Makefile flags plus
-Werror against real headers of OpenSSL 1.0.2u, 1.1.1w, 3.0.13, 3.6.5
and 4.0.4: unstable and the previous revision fail on 4.0.4, this
compiles clean on all of them (the only diagnostic on 1.1.1w is a
pre-existing one at SSL_CTX_set_ecdh_auto(), identical on unstable).
Also checked against LibreSSL's exact prototypes. ./runtest --tls
--single unit/tls passes (28/28), including the embedded-NUL CN test.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
tls.c:676:5: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 [-Werror=deprecated-declarations]
676 | int len = X509_NAME_get_text_by_NID(subject, nid, buf, sizeof(buf));
| ^~~
In file included from ../../../per-package/redis/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/openssl/ssl.h:34,
from tls.c:22:
../../../per-package/redis/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/openssl/x509.h:1041:27: note: declared here
1041 | OSSL_DEPRECATEDIN_4_0 int X509_NAME_get_text_by_NID(const X509_NAME *name,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Upstream PR exists to fix the build problem:
redis/redis#15227
Added buildroot-specific patch to remove -Werror=deprecated-declarations
from CFLAGS to not block the bump of OpenSSL to 4.0.3.
Signed-off-by: Bernd Kuhls <[email protected]>
Cc: Daniel Price <[email protected]>
Cc: Titouan Christophe <[email protected]>
* [MOD-19641] Build macOS against OpenSSL 4 The Homebrew Redis package now ships Redis core against openssl@4 (as homebrew-core does), so the module must link the same major version. - macOS setup installs openssl@4; CMake prefers it over openssl@3. - CI builds Redis against openssl@4. Bump the pinned Redis ref to redis/redis#15227, which replaces the tls.c API OpenSSL 4 deprecates (it broke Redis's -Werror build, the reason for the openssl@3 pin). - Drop the hard-coded /usr/local/opt/openssl from hiredis.cmake: it could pick a different OpenSSL than OPENSSL_ROOT_DIR. - New CI check fails the macOS build if redisearch.so links any libssl/libcrypto outside openssl@4. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [MOD-19641] Waive cluster-bus protected mode whenever Redis has it The pinned Redis ref now includes redis/redis#15722, which refuses to start a cluster node with a non-TLS bus unless cluster-bus-port-protected-mode is waived. CI waived it only for the literal `unstable` ref, so every coordinator flow test failed on the new pin. runtests.sh now adds the waiver for cluster runs whenever the redis-server binary knows the option. That covers CI and local runs, and any future pin, without matching ref names. Also move the macOS OpenSSL linkage check from task-build.yml, which only runs on Linux, to task-test.yml, which builds the macOS test jobs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [MOD-19641] Require OpenSSL 4 for macOS builds Drop the unversioned Homebrew `opt/openssl` fallbacks and fail CMake configure when the OpenSSL found is not major version 4. A host without openssl@4 used to fall back silently to whatever `opt/openssl` pointed at, producing a module that fails to load in the Homebrew Redis package. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [MOD-19641] Waive cluster-bus protected mode for ENV_ONLY clusters too `make run REDIS_STANDALONE=0` sets ENV_ONLY=1, which starts the cluster through run_env and exits before the test path's waiver, so its nodes refused to start on a Redis that has cluster-bus-port-protected-mode. Probe the option in one helper and apply it on both paths. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes redis#15221 OpenSSL 4.0 deprecates `X509_NAME_get_text_by_NID()`. With our `-Werror=deprecated-declarations`, a `BUILD_TLS=yes` build against OpenSSL 4 headers fails: tls.c:713: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 Homebrew's `openssl` formula points at `openssl@4` since 2026-09-28, so this is now the default macOS build. ## Fix Extract the certificate subject field with `X509_NAME_get_index_by_NID()`, `X509_NAME_get_entry()`, `X509_NAME_ENTRY_get_data()` and `ASN1_STRING_to_UTF8()` instead. * The value is still built with `sdstrynewlen()` from the returned length, so the embedded-NUL CN fix (d22066d) is preserved and empty fields are still rejected. * BMPString/UniversalString names are now decoded to UTF-8 instead of copied as raw bytes, and the fixed 256-byte buffer that silently truncated longer names is gone. * The intermediate OpenSSL objects (subject, entry, value) are not held in typed locals: OpenSSL 1.0.2/1.1.1 take non-const `X509_NAME` parameters, while OpenSSL 4.0 returns const pointers from `X509_get_subject_name()`, `X509_NAME_get_entry()` and `X509_NAME_ENTRY_get_data()`. No single declaration is warning-free on both ends, so the calls are chained; within any one version each return type matches the next parameter type.
Fixes redis#15221 OpenSSL 4.0 deprecates `X509_NAME_get_text_by_NID()`. With our `-Werror=deprecated-declarations`, a `BUILD_TLS=yes` build against OpenSSL 4 headers fails: tls.c:713: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 Homebrew's `openssl` formula points at `openssl@4` since 2026-09-28, so this is now the default macOS build. ## Fix Extract the certificate subject field with `X509_NAME_get_index_by_NID()`, `X509_NAME_get_entry()`, `X509_NAME_ENTRY_get_data()` and `ASN1_STRING_to_UTF8()` instead. * The value is still built with `sdstrynewlen()` from the returned length, so the embedded-NUL CN fix (d22066d) is preserved and empty fields are still rejected. * BMPString/UniversalString names are now decoded to UTF-8 instead of copied as raw bytes, and the fixed 256-byte buffer that silently truncated longer names is gone. * The intermediate OpenSSL objects (subject, entry, value) are not held in typed locals: OpenSSL 1.0.2/1.1.1 take non-const `X509_NAME` parameters, while OpenSSL 4.0 returns const pointers from `X509_get_subject_name()`, `X509_NAME_get_entry()` and `X509_NAME_ENTRY_get_data()`. No single declaration is warning-free on both ends, so the calls are chained; within any one version each return type matches the next parameter type.
Fixes redis#15221 OpenSSL 4.0 deprecates `X509_NAME_get_text_by_NID()`. With our `-Werror=deprecated-declarations`, a `BUILD_TLS=yes` build against OpenSSL 4 headers fails: tls.c:713: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 Homebrew's `openssl` formula points at `openssl@4` since 2026-09-28, so this is now the default macOS build. ## Fix Extract the certificate subject field with `X509_NAME_get_index_by_NID()`, `X509_NAME_get_entry()`, `X509_NAME_ENTRY_get_data()` and `ASN1_STRING_to_UTF8()` instead. * The value is still built with `sdstrynewlen()` from the returned length, so the embedded-NUL CN fix (d22066d) is preserved and empty fields are still rejected. * BMPString/UniversalString names are now decoded to UTF-8 instead of copied as raw bytes, and the fixed 256-byte buffer that silently truncated longer names is gone. * The intermediate OpenSSL objects (subject, entry, value) are not held in typed locals: OpenSSL 1.0.2/1.1.1 take non-const `X509_NAME` parameters, while OpenSSL 4.0 returns const pointers from `X509_get_subject_name()`, `X509_NAME_get_entry()` and `X509_NAME_ENTRY_get_data()`. No single declaration is warning-free on both ends, so the calls are chained; within any one version each return type matches the next parameter type.
Fixes #15221 OpenSSL 4.0 deprecates `X509_NAME_get_text_by_NID()`. With our `-Werror=deprecated-declarations`, a `BUILD_TLS=yes` build against OpenSSL 4 headers fails: tls.c:713: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 Homebrew's `openssl` formula points at `openssl@4` since 2026-09-28, so this is now the default macOS build. ## Fix Extract the certificate subject field with `X509_NAME_get_index_by_NID()`, `X509_NAME_get_entry()`, `X509_NAME_ENTRY_get_data()` and `ASN1_STRING_to_UTF8()` instead. * The value is still built with `sdstrynewlen()` from the returned length, so the embedded-NUL CN fix (d22066d) is preserved and empty fields are still rejected. * BMPString/UniversalString names are now decoded to UTF-8 instead of copied as raw bytes, and the fixed 256-byte buffer that silently truncated longer names is gone. * The intermediate OpenSSL objects (subject, entry, value) are not held in typed locals: OpenSSL 1.0.2/1.1.1 take non-const `X509_NAME` parameters, while OpenSSL 4.0 returns const pointers from `X509_get_subject_name()`, `X509_NAME_get_entry()` and `X509_NAME_ENTRY_get_data()`. No single declaration is warning-free on both ends, so the calls are chained; within any one version each return type matches the next parameter type.
Fixes #15221 OpenSSL 4.0 deprecates `X509_NAME_get_text_by_NID()`. With our `-Werror=deprecated-declarations`, a `BUILD_TLS=yes` build against OpenSSL 4 headers fails: tls.c:713: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 Homebrew's `openssl` formula points at `openssl@4` since 2026-09-28, so this is now the default macOS build. ## Fix Extract the certificate subject field with `X509_NAME_get_index_by_NID()`, `X509_NAME_get_entry()`, `X509_NAME_ENTRY_get_data()` and `ASN1_STRING_to_UTF8()` instead. * The value is still built with `sdstrynewlen()` from the returned length, so the embedded-NUL CN fix (d22066d) is preserved and empty fields are still rejected. * BMPString/UniversalString names are now decoded to UTF-8 instead of copied as raw bytes, and the fixed 256-byte buffer that silently truncated longer names is gone. * The intermediate OpenSSL objects (subject, entry, value) are not held in typed locals: OpenSSL 1.0.2/1.1.1 take non-const `X509_NAME` parameters, while OpenSSL 4.0 returns const pointers from `X509_get_subject_name()`, `X509_NAME_get_entry()` and `X509_NAME_ENTRY_get_data()`. No single declaration is warning-free on both ends, so the calls are chained; within any one version each return type matches the next parameter type.
Fixes #15221 OpenSSL 4.0 deprecates `X509_NAME_get_text_by_NID()`. With our `-Werror=deprecated-declarations`, a `BUILD_TLS=yes` build against OpenSSL 4 headers fails: tls.c:713: error: 'X509_NAME_get_text_by_NID' is deprecated: Since OpenSSL 4.0 Homebrew's `openssl` formula points at `openssl@4` since 2026-09-28, so this is now the default macOS build. ## Fix Extract the certificate subject field with `X509_NAME_get_index_by_NID()`, `X509_NAME_get_entry()`, `X509_NAME_ENTRY_get_data()` and `ASN1_STRING_to_UTF8()` instead. * The value is still built with `sdstrynewlen()` from the returned length, so the embedded-NUL CN fix (d22066d) is preserved and empty fields are still rejected. * BMPString/UniversalString names are now decoded to UTF-8 instead of copied as raw bytes, and the fixed 256-byte buffer that silently truncated longer names is gone. * The intermediate OpenSSL objects (subject, entry, value) are not held in typed locals: OpenSSL 1.0.2/1.1.1 take non-const `X509_NAME` parameters, while OpenSSL 4.0 returns const pointers from `X509_get_subject_name()`, `X509_NAME_get_entry()` and `X509_NAME_ENTRY_get_data()`. No single declaration is warning-free on both ends, so the calls are chained; within any one version each return type matches the next parameter type.

Fixes #15221
OpenSSL 4.0 deprecates
X509_NAME_get_text_by_NID(). With our-Werror=deprecated-declarations, aBUILD_TLS=yesbuild against OpenSSL 4headers fails:
Homebrew's
opensslformula points atopenssl@4since 2026-09-28, so this isnow the default macOS build.
Fix
Extract the certificate subject field with
X509_NAME_get_index_by_NID(),X509_NAME_get_entry(),X509_NAME_ENTRY_get_data()andASN1_STRING_to_UTF8()instead.sdstrynewlen()from the returned length, sothe embedded-NUL CN fix (d22066d) is preserved and empty fields are still
rejected.
as raw bytes, and the fixed 256-byte buffer that silently truncated longer
names is gone.
typed locals: OpenSSL 1.0.2/1.1.1 take non-const
X509_NAMEparameters,while OpenSSL 4.0 returns const pointers from
X509_get_subject_name(),X509_NAME_get_entry()andX509_NAME_ENTRY_get_data(). No singledeclaration is warning-free on both ends, so the calls are chained; within
any one version each return type matches the next parameter type.
🤖 Generated with Claude Code
Note
Medium Risk
Touches TLS client-identity extraction used by
tlsGetPeerUsername; behavior should match but encoding/decoding path changed, so wrong CN mapping could affect auth on upgrade builds.Overview
Updates
getCertFieldByNameinsrc/tls.cso peer certificate subject fields (e.g. CN for TLS client auth) no longer callX509_NAME_get_text_by_NID, which OpenSSL 4 deprecates.Extraction now locates the subject entry with
X509_NAME_get_index_by_NID, reads the ASN.1 value, and decodes it viaASN1_STRING_to_UTF8into a binary-safesds(still using the returned length for embedded NULs). The UTF-8 buffer is freed withOPENSSL_freeafter copy. OpenSSL accessor calls are chained instead of storingX509_get_subject_namein a local, avoidingconstqualifier warnings across OpenSSL 1.0.2, 3.x, and 4.0.Reviewed by Cursor Bugbot for commit 1293a3c. Bugbot is set up for automated code reviews on this repo. Configure here.