Repository navigation
Connection encryption info – Slice C: Managed SNI certificate capture - #4835
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
TLS transport changes still lack effective same-attempt isolation coverage and require the listed real-server validation.
4 open findings
What changed in this PR
Adds Slice C of connection encryption diagnostics, capturing Managed SNI server certificate details for successful and failed connections.
Changes:
- Captures certificate hashes, validation verdicts, and chain status.
- Propagates captured data through TDS and MARS layers.
- Adds unit coverage and design documentation.
| File | Description |
|---|---|
ManagedSniCertificateCaptureTests.cs |
Adds simulated TLS integration tests. |
ConnectionEncryptionInfoTests.cs |
Updates managed-SNI hash expectations. |
SniCommonServerCertificateCaptureTest.cs |
Tests validation and capture logic. |
TdsParserStateObjectManaged.netcore.cs |
Exposes managed transport capture. |
TdsParserStateObject.cs |
Defines the transport capture hook. |
TdsParser.cs |
Records capture after TLS negotiation. |
SniTcpHandle.netcore.cs |
Captures TCP TLS certificate details. |
SniNpHandle.netcore.cs |
Captures Named Pipes TLS certificate details. |
SniMarsHandle.netcore.cs |
Forwards capture through MARS handles. |
SniMarsConnection.netcore.cs |
Exposes the physical MARS capture. |
SniHandle.netcore.cs |
Adds the capture property contract. |
SniCommon.netcore.cs |
Produces validation verdicts, hashes, and chain flags. |
ServerCertificateCapture.cs |
Defines the immutable transport capture. |
EncryptionInfoCapture.cs |
Publishes certificate fields in snapshots. |
2353-connection-encryption-info.md |
Documents Managed SNI capture semantics. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev/automation/encryption-info-slice-b-mode-protocol #4835 +/- ##
=======================================================================================
Coverage ? 72.45%
=======================================================================================
Files ? 316
Lines ? 71329
Branches ? 0
=======================================================================================
Hits ? 51678
Misses ? 19651
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7d60501 to
549fd10
Compare
549fd10 to
502f3f3
Compare
e4e6869 to
e9fbf4b
Compare
e9fbf4b to
78f101e
Compare
88d2d83 to
73c72c2
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Simulator coverage does not establish TLS diagnostic correctness across real SQL Server transport paths, leaving Windows/Linux validation of certificate handling, Strict/TDS 8, named-pipe TLS, and MARS outstanding.
No open issues 🎉
Review effort: Balanced
73c72c2 to
928f40a
Compare
928f40a to
8a0b3a3
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
TLS-state capture still needs real SQL Server validation across Windows/Linux, Strict/TDS 8, named pipes, and MARS, which the limited simulator coverage and pending build/test pipeline do not establish.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Platform-sensitive TLS capture still requires real SQL Server validation on Windows/Linux, including Strict/TDS 8, named-pipe TLS, and MARS, which simulated-server tests cannot establish.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Real SQL Server validation is still outstanding for platform-sensitive TLS diagnostics on Windows/Linux, Strict/TDS 8, named pipes, and actual MARS; simulator tests do not establish certificate/cipher capture or failure behavior on these paths.
No open issues 🎉
Review effort: Balanced
benrr101
left a comment
There was a problem hiding this comment.
Overall it's probably fine. A few stylistic changes requested, but they're not going to be blockers.
…tails (Slice C) Capture SHA-256 of the presented leaf certificate, the effective SqlClient validation verdict, and the original callback chain status flags in Managed SNI, and flow them into the per-attempt encryption info capture so both SqlConnection.EncryptionInfo and SqlException.EncryptionInfo report them. No trust decisions, messages, or tracing are changed. Part of #2353 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Named pipes validate against the target '.', which X509Certificate2.MatchesHostname rejects with ArgumentException before the final verdict is recorded. Record the errors already established (e.g. ChainError and callback chain status) before the host name check so the capture survives. The exception is not caught or changed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Record (int)SslStream.NegotiatedCipherSuite after the handshake (authoritative) and inside the certificate validation callback (adopt-if-none), so failed certificate validation keeps the observed suite. TCP and named-pipe handles; MARS passes through. Reads are exception-safe; 0 is treated as unavailable. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… failures Main's #4891 makes the TDS simulator rethrow connection faults on Stop. The untrusted, host-name-mismatch and pin-mismatch capture tests now set ExpectTlsHandshakeFailure so the server treats the client's rejection as expected. Test-only change. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Assert the public CLS-compliant NegotiatedCipherSuiteId property in the Managed SNI simulator tests and describe the two-property shape in the Managed capture section. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… SNI) Managed SNI now captures a copy of the presented leaf certificate's DER encoding (GetRawCertData) instead of its SHA-256 hash, and passes it to the snapshot so SqlConnectionEncryptionInfo.GetServerCertificate() can return it. Certificates over 64 KiB are not captured, and the first certificate presented in an attempt is kept. Capture still happens in the validation callback's finally block, so it is present on TrustServerCertificate bypass and on validation failure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Reset the attempt's encryption info capture when Connect retries after an instance-resolution failure, so only the retried attempt's values publish. - Document that an observed protocol is kept after a failure. - Compare capture outcomes against an independent restatement of the validation rules instead of the legacy overload. - Add routed single-login tests proving only the terminal attempt's certificate is published, including a terminal attempt that fails before TLS. - Add XML summaries and Arrange/Act/Assert structure to the capture tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace the bool-async theories with separate Open_ and OpenAsync_ tests that call each API directly, sharing setup and scenario assertion helpers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Slice B's reconnect tests asserted that certificate fields are null. Managed SNI now records the presented certificate under TrustServerCertificate, so use the bypass assertion. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the shared EncryptionInfoTestData.AssertEmpty helper and value-returning Assert.NotNull instead of ad-hoc IsEmpty checks and null-forgiving operators. Test-only; no product change. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move C's certificate-field tests into EncryptionInfoAccumulatorTests using the accumulator's settable properties, drop the RecordServerCertificate-based tests, remove the inherited AssertCertificateFieldsNull use from the enlistment test (Managed SNI now records the presented certificate), and update the remaining EncryptionInfoCapture references in docs and comments. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Platform-sensitive TLS callback capture lacks real-server validation on Windows/Linux, Strict/TDS 8, named pipes, and MARS, leaving key behaviors unverified by the supplied TLS 1.2 TCP simulator coverage.
No open issues 🎉
Review effort: Balanced



Description
Slice C of the connection encryption info feature. Managed SNI now captures the server certificate details from
RemoteCertificateValidationCallbackduring the TLS handshake. It flows them throughTdsParserStateObjectinto Slice B's per-attemptEncryptionInfoAccumulator, so both snapshots include them:SqlConnection.EncryptionInfoon successSqlException.EncryptionInfoon failureNative SNI does not return certificate data yet; that is Slice D.
Scope and guarantees
Message,ToString()or EventSource output.finallyblock, and they are read afterAuthenticateAsClientreturns insideEnableSsl.Capture points
nullwhenGetServerCertificate()/ internalPresentedServerCertificateRawDataGetRawCertData()), taken in the callback'sfinally. The first certificate in the attempt is kept. Captured even underTrustServerCertificatebypass and on validation failure.ServerCertificateValidationErrorsServerCertificateMissing(null certificate orRemoteCertificateNotAvailable),ChainError,HostNameMismatch(afterHostNameInCertificate),PinnedCertificateMismatch.Nonewhen validation passed.TrustServerCertificate), or theServerCertificatefile couldn't be read.ServerCertificateChainStatusX509Chain.ChainStatusflags (no rebuild).NoErrorwhen the chain was clean.ServerCertificatepin mode (chain not consulted, even on match); no certificate; null chain; orRemoteCertificateChainErrorswith no flags.NegotiatedEncryptionProtocol(Managed contribution)SslStream.SslProtocol, read inside the callback (guarded). Used only if the attempt has no protocol yet.SslStream, the read throws, or the value isNone.NegotiatedCipherSuiteId(Managed contribution)(int)SslStream.NegotiatedCipherSuite. Recorded after the handshake (authoritative) and inside the callback (adopted only if none was recorded). TCP and named pipes; MARS passes through.SslStream, the read throws, or the value is0.NegotiatedEncryptionModeThe protocol and cipher suite contributions are .NET only, because Managed SNI isn't compiled for .NET Framework.
Notable behavior
Full, the observed protocol (for exampleTls12) and cipher suite, together with the certificate,ServerCertificateValidationErrorsandServerCertificateChainStatus. Slice B keeps these values because a protocol was observed. Native SNI still reports none of them.., andX509Certificate2.MatchesHostname(".")throwsArgumentException, as it already does on main.ValidateSslServerCertificaterecords the errors it already knows (for exampleChainErrorand the chain status) before the host name check, so the capture survives the throw. The exception is not caught or changed. If no error is known before the check, the fields staynullrather than reportingNone.ServerCertificateCapture.RawCertificateandEncryptionInfoAccumulator.ServerCertificateRawData.Documentation
doc/design-notes/2353-connection-encryption-info.mdgains a "Managed SNI certificate capture" section. Its failure-path notes now distinguish Managed SNI (mode, protocol and certificate reported) from native SNI (none reported).Issues
Part of #2353. Stacked on #4831 (Slice B), which is stacked on #4830 (Slice A).
Testing
Automated tests
SniCommonServerCertificateCaptureTest(unit, .NET):SslPolicyErrorscombination,HostNameInCertificateoverride and mismatch, pin match, mismatch, missing and unreadable.X509ChainStatusFlagsvalue, and the full set, is preserved. An unbuilt chain is not rebuilt.CertificateRequestself-signed certificate and are a copy. A certificate over 64 KiB is not captured. The first certificate wins.GetServerCertificate().RawDataround-trips.null(unavailable) and zero values stay distinct. Nothing leaks intoMessageorToString().SslStream, a null or unauthenticatedSslStream(null, no throw), and adopt-if-none.ValidateSslServerCertificate_NamedPipeDotTarget_CapturesKnownErrorsAndKeepsException. Without the fix it fails with ExpectedChainError, Actualnull.ManagedSniCertificateCaptureTests(simulated TDS server over TLS, Managed SNI forced on Windows). Each scenario has separateOpenandOpenAsynctests:TrustServerCertificatebypass (certificate only), and a matching pin.ChainError, chain flags, certificate), host name mismatch,HostNameInCertificateoverride and mismatch, and pin mismatch. Failure cases also assert modeFulland protocolTls12.Reset().SslStream.NegotiatedCipherSuiteon success. On failure it equals the suite a trusted handshake with the same server negotiates.ConnectionEncryptionInfoTests(Slice B tests, adapted):TrustServerCertificatebypass and reconnect on Managed SNI report the certificate. An untrusted failure on Managed SNI reports mode, protocol and cipher suite.Results on head
f771fb427Base: #4831 @
dca9d2681(Slice B's accumulator design from the review rounds). Filter:ManagedSni|SniCommon|SimulatedServerTests|SqlException|SqlConnection|EncryptionInfo.PSModulePath,--blame-hang-timeout 10m)Changes from the previous head (
1aed09457), on top of the rebase:EncryptionInfoAccumulator.TdsParser.EnableSslassigns them directly from the transport'sServerCertificateCapture, along with the callback's protocol and cipher suite when none was already determined.Full), plus the protocol and cipher suite that Managed SNI observed.EncryptionInfoAccumulatorTests.Manual tests still needed
Encrypt=Strict. The simulated server only supports PRELOGIN TLS.Guidelines
Please review the contribution guidelines before submitting a pull request: