feat: add handshake Exception on ITlsHandshakeFeature#65807
Open
DeagleGross wants to merge 7 commits intodotnet:mainfrom
Open
feat: add handshake Exception on ITlsHandshakeFeature#65807DeagleGross wants to merge 7 commits intodotnet:mainfrom
Exception on ITlsHandshakeFeature#65807DeagleGross wants to merge 7 commits intodotnet:mainfrom
Conversation
1 task
HandshakeException on ITlsHandshakeFeatureException on ITlsHandshakeFeature
Exception on ITlsHandshakeFeatureException on ITlsHandshakeFeature
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new Exception property to ITlsHandshakeFeature so middleware can inspect TLS handshake failures, and updates Kestrel’s HttpsConnectionMiddleware to populate it (including snapshotting SslStream-backed properties before disposal).
Changes:
- Add
ITlsHandshakeFeature.Exception(default interface member) as a new approved API surface. - Populate the handshake exception in
HttpsConnectionMiddlewareon handshake failures and snapshot TLS-related properties beforeSslStreamdisposal. - Add functional tests validating
Exceptionis set on handshake failure/timeout and remains null on success; update sample to demonstrate usage.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs | Adds coverage for handshake exception + post-failure feature access patterns (with some flakiness risks). |
| src/Servers/Kestrel/samples/SampleApp/Startup.cs | Demonstrates reading ITlsHandshakeFeature.Exception after handshake completion. |
| src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs | Sets feature.Exception on handshake failure and snapshots properties before disposal. |
| src/Servers/Kestrel/Core/src/Internal/TlsConnectionFeature.cs | Adds snapshotting/cached backing fields and an Exception property implementation. |
| src/Servers/Connections.Abstractions/src/PublicAPI/net11.0/PublicAPI.Unshipped.txt | Declares the new public API entry for net11.0. |
| src/Servers/Connections.Abstractions/src/Features/ITlsHandshakeFeature.cs | Introduces the new Exception property (NETCOREAPP) with a default implementation. |
src/Servers/Connections.Abstractions/src/PublicAPI/net11.0/PublicAPI.Unshipped.txt
Show resolved
Hide resolved
src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs
Outdated
Show resolved
Hide resolved
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.
Adding handshake exception on the
ITlsHandshakeFeatureIn order to allow users to get the exception happened during tls handshake, adding new approved API on
ITlsHandshakeFeatureand populating it in theHttpsConnectionMiddleware.Since we now assume
ITlsHandshakeFeaturecan be used after tls handshake failed, and underlyingsslStreammay be disposed (should be actually), I added a way to snapshot all the fields fromsslStreamtoTlsConnectionFeaturebackup-fields, which will be used if set.Note: changed to
NET11_0_OR_GREATERinstead of NETCOREAPP to not make an unintended change in net10Fixes #65758