Skip to content

ocsp: add single-cert stapling fast path and certinfo RAII - #13229

Merged
cmcfarlen merged 2 commits into
apache:masterfrom
c-taylor:ocsp-stapling-map-lifecycle
Jun 9, 2026
Merged

ocsp: add single-cert stapling fast path and certinfo RAII#13229
cmcfarlen merged 2 commits into
apache:masterfrom
c-taylor:ocsp-stapling-map-lifecycle

Conversation

@c-taylor

@c-taylor c-taylor commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Skip the SSL_get_certificate() lookup and X509_cmp() DER re-parse in the stapling callback when an SSL_CTX has a single certificate. The shortcut is gated to non-dual-cert builds; under HAVE_NATIVE_DUAL_CERT_SUPPORT a CTX can hold multiple certs where only one has OCSP info, so map size alone cannot identify the negotiated cert.

Give certinfo a constructor/destructor so its resources are managed by RAII, and allocate it with make_unique. This consolidates the cleanup that was duplicated across certinfo_map_free and the init error path, and fixes two pre-existing leaks (cid and the BoringSSL cert ref) plus an error path that could delete a certinfo_map still owned by the SSL_CTX.

Skip the SSL_get_certificate() lookup and X509_cmp() DER re-parse in the
stapling callback when an SSL_CTX has a single certificate. The shortcut
is gated to non-dual-cert builds; under HAVE_NATIVE_DUAL_CERT_SUPPORT a
CTX can hold multiple certs where only one has OCSP info, so map size
alone cannot identify the negotiated cert.

Give certinfo a constructor/destructor so its resources are managed by
RAII, and allocate it with make_unique. This consolidates the cleanup
that was duplicated across certinfo_map_free and the init error path,
and fixes two pre-existing leaks (cid and the BoringSSL cert ref) plus
an error path that could delete a certinfo_map still owned by the
SSL_CTX.
Comment thread src/iocore/net/OCSPStapling.cc Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Switch the per-SSL_CTX certinfo map to store std::unique_ptr<certinfo>
so ownership is explicit and the value cleanup is handled by RAII. This
removes the manual delete in certinfo_map_free and closes a leak window
at the insert site: the old release()-then-insert dropped the pointer if
the key already existed or the insert threw, whereas emplace with a move
only transfers ownership once insertion succeeds.
@c-taylor
c-taylor requested a review from bneradt June 8, 2026 17:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@bryancall

Copy link
Copy Markdown
Contributor

@c-taylor Do you want us to merge this in to master?

@c-taylor
c-taylor marked this pull request as ready for review June 8, 2026 23:00
@c-taylor

c-taylor commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Local validations were in progress since my last commit for @bneradt - Good here!

@c-taylor

c-taylor commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

All my validations are complete; Good to Merge.

@cmcfarlen
cmcfarlen merged commit 30d8fca into apache:master Jun 9, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Jun 9, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.0 in ATS v10.2.x Jun 16, 2026
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.0 Jun 16, 2026
@cmcfarlen

Copy link
Copy Markdown
Contributor

Cherry-picked to 10.2.x

cmcfarlen pushed a commit that referenced this pull request Jun 16, 2026
* ocsp: add single-cert stapling fast path and certinfo RAII

Skip the SSL_get_certificate() lookup and X509_cmp() DER re-parse in the
stapling callback when an SSL_CTX has a single certificate. The shortcut
is gated to non-dual-cert builds; under HAVE_NATIVE_DUAL_CERT_SUPPORT a
CTX can hold multiple certs where only one has OCSP info, so map size
alone cannot identify the negotiated cert.

Give certinfo a constructor/destructor so its resources are managed by
RAII, and allocate it with make_unique. This consolidates the cleanup
that was duplicated across certinfo_map_free and the init error path,
and fixes two pre-existing leaks (cid and the BoringSSL cert ref) plus
an error path that could delete a certinfo_map still owned by the
SSL_CTX.

* ocsp: make certinfo map own values via unique_ptr

Switch the per-SSL_CTX certinfo map to store std::unique_ptr<certinfo>
so ownership is explicit and the value cleanup is handled by RAII. This
removes the manual delete in certinfo_map_free and closes a leak window
at the insert site: the old release()-then-insert dropped the pointer if
the key already existed or the insert threw, whereas emplace with a move
only transfers ownership once insertion succeeds.

(cherry picked from commit 30d8fca)
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jul 29, 2026
)

* ocsp: add single-cert stapling fast path and certinfo RAII

Skip the SSL_get_certificate() lookup and X509_cmp() DER re-parse in the
stapling callback when an SSL_CTX has a single certificate. The shortcut
is gated to non-dual-cert builds; under HAVE_NATIVE_DUAL_CERT_SUPPORT a
CTX can hold multiple certs where only one has OCSP info, so map size
alone cannot identify the negotiated cert.

Give certinfo a constructor/destructor so its resources are managed by
RAII, and allocate it with make_unique. This consolidates the cleanup
that was duplicated across certinfo_map_free and the init error path,
and fixes two pre-existing leaks (cid and the BoringSSL cert ref) plus
an error path that could delete a certinfo_map still owned by the
SSL_CTX.

* ocsp: make certinfo map own values via unique_ptr

Switch the per-SSL_CTX certinfo map to store std::unique_ptr<certinfo>
so ownership is explicit and the value cleanup is handled by RAII. This
removes the manual delete in certinfo_map_free and closes a leak window
at the insert site: the old release()-then-insert dropped the pointer if
the key already existed or the insert threw, whereas emplace with a move
only transfers ownership once insertion succeeds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Picked v10.2.0

Development

Successfully merging this pull request may close these issues.

5 participants