Skip to content

tls: replace deprecated X509_NAME_get_text_by_NID API - #15227

Merged
hristostaykov-del merged 5 commits into
redis:unstablefrom
arpitjaswal:fix-openssl4-deprecation
Sep 30, 2026
Merged

hristostaykov-del merged 5 commits into
redis:unstablefrom
arpitjaswal:fix-openssl4-deprecation

Conversation

@arpitjaswal

@arpitjaswal arpitjaswal commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

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.

🤖 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 getCertFieldByName in src/tls.c so peer certificate subject fields (e.g. CN for TLS client auth) no longer call X509_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 via ASN1_STRING_to_UTF8 into a binary-safe sds (still using the returned length for embedded NULs). The UTF-8 buffer is freed with OPENSSL_free after copy. OpenSSL accessor calls are chained instead of storing X509_get_subject_name in a local, avoiding const qualifier 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.

@CLAassistant

CLAassistant commented May 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jit-ci

jit-ci Bot commented May 18, 2026

Copy link
Copy Markdown

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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 7a3dc52. Configure here.

Comment thread src/tls.c Resolved
@sundb sundb added this to Redis 8.10 May 19, 2026
@sundb sundb moved this from Todo to In Review in Redis 8.10 Jul 17, 2026
@sundb sundb removed this from Redis 8.10 Aug 4, 2026
@sundb sundb added this to Redis 8.12 Aug 4, 2026
@bkuhls

bkuhls commented Sep 9, 2026

Copy link
Copy Markdown

This patch needs an update due to commit 84c7553

@hristostaykov-del

Copy link
Copy Markdown
Collaborator

Please re-base on top of latest unstable

Comment thread src/tls.c Resolved
@lerman25

Copy link
Copy Markdown
Contributor

Adding a data point on urgency. Since 2026-09-28, Homebrew's openssl points to openssl@4, and openssl@3 is keg-only. A default macOS build with BUILD_TLS=yes now picks up OpenSSL 4 through OPENSSL_PREFIX?=/opt/homebrew/opt/openssl, and fails:

tls.c:713:15: error: 'X509_NAME_get_text_by_NID' is deprecated [-Werror,-Wdeprecated-declarations]

We hit this in RediSearch CI on unstable, 8.10.2, 8.8.3 and 8.6.7, in every macOS job that builds Redis with TLS. For now we build against openssl@3 (RediSearch/RediSearch#11620), but that only works while Homebrew still ships openssl@3.

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.39%. Comparing base (e336bde) to head (18e0338).
⚠️ Report is 2 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/tls.c 100.00% <ø> (ø)

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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]>

@hristostaykov-del hristostaykov-del left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@hristostaykov-del
hristostaykov-del merged commit 8bc1c4e into redis:unstable Sep 30, 2026
2 checks passed
bkuhls added a commit to bkuhls/buildroot that referenced this pull request Oct 6, 2026
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]>
aradalvand pushed a commit to aradalvand/RediSearch that referenced this pull request Oct 21, 2026
* [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]>
sundb pushed a commit to sundb/redis that referenced this pull request Oct 22, 2026
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.
sundb pushed a commit to sundb/redis that referenced this pull request Oct 22, 2026
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.
sundb pushed a commit to sundb/redis that referenced this pull request Oct 22, 2026
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.
sundb pushed a commit that referenced this pull request Oct 26, 2026
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.
sundb pushed a commit that referenced this pull request Oct 26, 2026
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.
sundb pushed a commit that referenced this pull request Oct 26, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] compile with openssl 4.0.0

6 participants