Fix stale key_method pointer after private key switch in CERT#3085
Merged
Fix stale key_method pointer after private key switch in CERT#3085
key_method pointer after private key switch in CERT#3085Conversation
key_method pointer after private key switch in CERT
samuel40791765
approved these changes
Mar 10, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3085 +/- ##
==========================================
- Coverage 78.36% 78.18% -0.19%
==========================================
Files 689 689
Lines 121743 121814 +71
Branches 16997 16995 -2
==========================================
- Hits 95402 95238 -164
- Misses 25452 25692 +240
+ Partials 889 884 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nebeid
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes:
key_methodand per-slotprivatekeyonCERTare mutually exclusive —key_methodwins when non-NULL. But several paths didn't clear the other when setting one, so stale
values could silently take effect after switching between a real key and a callback.
Adds
SetKeyMethodandSetSlotPrivateKeyonCERTthat enforce the invariant, androutes all mutation paths through them.
Call-outs:
dc_key_method/dc_privatekeyhave the same issue — left for a follow-up.SSL_set_private_key_method/SSL_CTX_set_private_key_methodstayvoidfor APIcompat; failures go to the error stack.
Testing:
Added
SSLTest.KeyMethodPrivateKeyMutualExclusivity— 6 sub-cases covering invariantchecks across all mutation paths and functional handshake checks after key switches in
both directions.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.