Skip to content

test(net): build test certificates where the subject name comes back const - #1723

Merged
Coldwings merged 2 commits into
alibaba:mainfrom
lihuiba:fix-x509-const-subject-name
Nov 2, 2026
Merged

Coldwings merged 2 commits into
alibaba:mainfrom
lihuiba:fix-x509-const-subject-name

Conversation

@lihuiba

@lihuiba lihuiba commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

What

net/security-context/test/test_cert_utils.h hands the result of
X509_get_subject_name() to X509_NAME_add_entry_by_txt() and
X509_set_issuer_name(), which take a mutable X509_NAME*. The getter's return
qualifier depends on the OpenSSL headers in use: 1.1.1 returns X509_NAME*,
newer ones return const X509_NAME*. With the newer headers the five call sites
fail to compile:

test_cert_utils.h:35:5: error: no matching function for call to 'X509_NAME_add_entry_by_txt'
... candidate function not viable: 1st argument ('const X509_NAME *') would lose const qualifier

This is what broke the macOS arm CI image (whose homebrew OpenSSL is newer) while
the intel image, on 1.1.1, stayed green -- same source, two header versions.

How

One helper takes the writable view back, and the five sites use it:

inline X509_NAME* test_subject_name(X509* cert) {
    return const_cast<X509_NAME*>(X509_get_subject_name(cert));
}

No version macro: on the old signature const_cast removes no qualifier and is a
no-op, so the same text compiles against both. The cast is sound because these
certificates are built here and are writable.

Verification

  • -fsyntax-only on net/http/test/client_function_test.cpp with OpenSSL 3.6.3
    headers: clean.
  • The same helper text compiled against both getter signatures (mutable and
    const) in one TU: compiles in both directions.
  • CI: the macOS arm job is the witness for the const signature; Linux and the
    macOS intel job cover the mutable one.

The macOS arm image's X509_get_subject_name() returns a const X509_NAME*, while
X509_NAME_add_entry_by_txt() and X509_set_issuer_name() take a mutable one, so
client_function_test stopped compiling there -- the intel image's OpenSSL returns
the mutable pointer and was fine. The certificates are ours and writable, so the
five call sites go through one helper that takes the writable view back.
The getter's return qualifier follows whichever headers are installed, so the fix
must not key off a version: removing no qualifier is a no-op, which is what lets
the single helper compile unchanged against the mutable and the const signature.
@lihuiba lihuiba added the need-backport A PR that should be back-ported to prior release branches (release/*) label Nov 2, 2026
@Coldwings
Coldwings merged commit 28d396e into alibaba:main Nov 2, 2026
20 checks passed
Coldwings added a commit that referenced this pull request Nov 2, 2026
Drop the TestCertChain / generate_ca_signed_cert block that the cherry-pick
pulled in as conflict context: those helpers come from a main-only change and
nothing on release/0.9 uses them. What remains is the actual fix of #1723 --
test_subject_name() and its one call site in generate_different_self_signed_cert().
lihuiba added a commit that referenced this pull request Nov 2, 2026
…e subject name comes back const (#1723) (#1724)

* test(net): build test certificates where the subject name comes back const (#1723)

* test(net): take a writable subject name when building test certificates

The macOS arm image's X509_get_subject_name() returns a const X509_NAME*, while
X509_NAME_add_entry_by_txt() and X509_set_issuer_name() take a mutable one, so
client_function_test stopped compiling there -- the intel image's OpenSSL returns
the mutable pointer and was fine. The certificates are ours and writable, so the
five call sites go through one helper that takes the writable view back.

* test(net): say why one const_cast covers both OpenSSL signatures

The getter's return qualifier follows whichever headers are installed, so the fix
must not key off a version: removing no qualifier is a no-op, which is what lets
the single helper compile unchanged against the mutable and the const signature.

* test(net): resolve backport conflict in test_cert_utils.h

Drop the TestCertChain / generate_ca_signed_cert block that the cherry-pick
pulled in as conflict context: those helpers come from a main-only change and
nothing on release/0.9 uses them. What remains is the actual fix of #1723 --
test_subject_name() and its one call site in generate_different_self_signed_cert().

---------

Co-authored-by: Huiba Li <huiba.lhb@alibaba-inc.com>
Co-authored-by: Coldwings <coldwings@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-backport A PR that should be back-ported to prior release branches (release/*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants