[release/8.0-staging] macOS: Set certificate as a dependency of private key handles #96993
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.
Backport of #95924 and #96685 to release/8.0-staging
/cc @bartonjs
Customer Impact
Reported by multiple customers in #94959 and #95924 (comment). Customers that upgrade to .NET 8 from previous versions of .NET may receive an exception when attempting to use a private key from a certificate where the certificate has been disposed on macOS. The behavior contract of the key and certificate is that they have independent lifetimes and developers are not expected to keep the certificate alive for the duration of the private key.
Workarounds for the issue range from intrusive to not possible if the issue arises in a 3rd party library. This issue is impeding upgrades from .NET 6/7 to .NET 8.
Regression
Yes. #82205 made changes to reference lifetimes and commit 28f958d introduced the regression. We did not have unit tests asserting the independent lifetimes of the private key and the certificate.
Testing
New unit tests were introduced to prevent the fix from regressing; existing unit tests ensure existing scenarios continue to work.
Risk
Low and mitigated. This is a targeted change for macOS and the options for addressing the regression were discussed before making this fix.