Skip to content

Handle missing Network.framework peer certificate chain#127451

Merged
liveans merged 1 commit intodotnet:mainfrom
liveans:fix-networkframework-null-peer-chain
Apr 27, 2026
Merged

Handle missing Network.framework peer certificate chain#127451
liveans merged 1 commit intodotnet:mainfrom
liveans:fix-networkframework-null-peer-chain

Conversation

@liveans
Copy link
Copy Markdown
Member

@liveans liveans commented Apr 27, 2026

Fixes crash in #123395

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in Apple Network Framework TLS/WebSockets scenarios by safely handling cases where the peer certificate chain handle is missing/invalid, avoiding a NullReferenceException during remote certificate extraction.

Changes:

  • Make the Network.framework peer chain handle nullable when retrieving the remote certificate.
  • Early-return null when the chain handle is missing or invalid, preventing calls into AppleCrypto with a null handle.
  • Ensure the copied certificate chain handle is disposed when it was created via SslCopyCertChain (SafeDeleteSslContext path), even on the early-return path.

@liveans liveans merged commit ea83ba3 into dotnet:main Apr 27, 2026
92 of 97 checks passed
@rzikm
Copy link
Copy Markdown
Member

rzikm commented Apr 27, 2026

I wonder how do we get to the situation that the remote certificate chain handle is missing or invalid. Since NW is used only for client scenario, there should always be remote (=server) certificate by the time we call the callback. Or am I missing something? The only possibility that occurs to me at the moment is TLS resumption and NW not storing remote cert alongside the TLS session ticket for future inspection.

@wfurt
Copy link
Copy Markdown
Member

wfurt commented Apr 27, 2026

I wonder how do we get to the situation that the remote certificate chain handle is missing or invalid. Since NW is used only for client scenario, there should always be remote (=server) certificate by the time we call the callback. Or am I missing something? The only possibility that occurs to me at the moment is TLS resumption and NW not storing remote cert alongside the TLS session ticket for future inspection.

my suspicion is TLS resume but since we do not have repro it is hard to know. The other option could be error states - like the TLS state machine got TLS alert but it did not bubble up yet and fail in the handshake validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants