Repository navigation
[DO NOT MERGE] [8.0.0 Cherry-pick] Connection encryption info – Slice B: negotiated mode and TLS protocol - #5102
Open
github-actions[bot] wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
priyankatiwari08
marked this pull request as ready for review
November 18, 2026 07:32
Contributor
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
#4831) * Capture negotiated encryption mode and TLS protocol for EncryptionInfo (Slice B) Records the final negotiated encryption mode and TLS protocol per physical login attempt, publishes an immutable snapshot to SqlConnection.EncryptionInfo on successful open, and attaches the terminal attempt's values to SqlException.EncryptionInfo when open fails. Part of #2353. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Discard negotiated encryption details on deferred TLS validation failure Native SNI (Schannel) defers server certificate verification, so EnableSsl succeeds and an untrusted certificate only surfaces as an SSL provider error on the LOGIN7 write. Discard the mode/protocol recorded for the in-progress login attempt when ProcessSNIError sees an SSL provider error, so SqlException.EncryptionInfo no longer reports a negotiated mode for a TLS session that was never established. Managed SNI is unaffected. Part of #2353. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Clear only negotiated mode/protocol on SSL provider login errors Preserve other capture state (certificate details from Slices C/D) when Native SNI's deferred certificate validation fails on the LOGIN7 write. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Clarify that the SSL-error reset covers only mode and protocol Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Keep observed mode/protocol on TLS validation failure (G2/D15) Replace ClearNegotiated with DiscardUnobservedNegotiation: on SSL-provider login errors the mode is dropped only when no protocol was observed. Failed EnableSsl attempts record the mode only when a protocol was observed. Certificate fields are untouched. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Add negotiated cipher suite capture plumbing (Slice B) EncryptionInfoCapture.RecordCipherSuite(int) is the single recording point for NegotiatedCipherSuite, used by Slice C (managed SslStream) and Slice D (native SNI). The value resets with the other fields per attempt, flows into SqlConnection and SqlException snapshots, and is kept on failure like the protocol; DiscardUnobservedNegotiation never clears or invents it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Align EncryptionInfo simulator tests with stricter TDS server fault reporting Main's #4891 makes the simulated server rethrow connection faults on Stop. Use Encryption=None for the pre-login rejection case (as ConnectionTests does) and mark the untrusted-certificate case as an expected TLS handshake failure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Adapt Slice B tests and design note to NegotiatedCipherSuiteId Assert the numeric cipher-suite ID through the public NegotiatedCipherSuiteId property and cover the .NET-only TlsCipherSuite surface under #if NET. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Replace removed certificate hash references with full certificate API (Slice B) Pass presentedServerCertificate: null from EncryptionInfoCapture and assert the certificate is unavailable through PresentedServerCertificateRawData and GetServerCertificate(). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Address #4831 review feedback - Sort EncryptionInfoCapture members; use auto-properties for capture/snapshot. - Replace SSL provider magic number with TdsEnums.SNI_SSL_PROVIDER. - Reset capture on instance-failure reconnect. - Restructure tests per testing instructions; split sync/async scenarios. - Untrusted-certificate failure asserts no inferred mode/protocol. - Clarify Strict/PRELOGIN failure semantics in design note. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Document EncryptionInfo failure scope: post-login enlistment keeps Empty Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Release encryption capture on non-pooled auto-enlist failure; clarify design note failure rules Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Add reconnect, enlistment and ManualTests coverage for encryption info - Simulated-server tests (sync and async): reconnect after a server drop publishes a new snapshot; non-pooled and pooled DTC enlistment failures leave SqlException.EncryptionInfo empty. - ManualTests against SQL Server: Optional, Mandatory, Strict and a login failure (sync and async), close keeps a held snapshot, pooled reuse. - Restore the UTF-8 BOM in SqlException.xml. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Run encryption info ManualTests in CI and harden enlistment teardown assert Add the Set=1 trait so the PR pipeline selects the ConnectionEncryptionInfo ManualTests, and assert on the base exception during simulated server teardown so both teardown orderings pass. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Adapt Slice B to the Slice A review follow-up (#5043) Convert the captured cipher suite to TlsCipherSuite? at the snapshot boundary on .NET, and use the shared EncryptionInfoTestData helpers in B's tests. The SqlException attach test is covered by SqlExceptionTests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Address Slice B review: accumulator, TdsParser rules, SqlException contract - Rename EncryptionInfoCapture to EncryptionInfoAccumulator (file, field, property, tests and docs). - Make the accumulator a plain holder (Mode, Protocol, CipherSuite, HasValues, Reset, ToSnapshot). Move the recording rules into TdsParser: RecordEncryption (SslProtocols.None maps to null), RecordModeIfProtocolObserved, DiscardUnobservedNegotiation and RecordCipherSuite. Rule tests move to Parser/TdsParserTests. - On .NET, store the cipher suite as TlsCipherSuite and record it with RecordCipherSuite(TlsCipherSuite); .NET Framework keeps the range-checked int. - Use target-typed new() where the type is obvious. - Add a dedicated SqlException catch in the login path that attaches the encryption info; AttachEncryptionInfo now takes SqlException. - A SqlException thrown while opening carries the encryption info whenever any is available, including transaction enlistment. Pooled checkout enlistment failures attach the physical connection's published snapshot. - Update the SqlException.EncryptionInfo docs and design note. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Clarify SqlException.EncryptionInfo scope in docs State that only exceptions thrown while opening a connection carry encryption information, that other operations return an empty snapshot, and that pooled-connection enlistment failures carry the values recorded at the physical connection's earlier login. Remove a duplicated sentence about deserialized exceptions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Address review: record mode when selected, normalize in accumulator setters - Protocol setter maps SslProtocols.None to null; netfx CipherSuite setter discards values outside the TLS cipher-suite range. - Remove RecordEncryption, RecordCipherSuite, RecordModeIfProtocolObserved, DiscardUnobservedNegotiation and the ProcessSNIError mode erasure; TdsParser assigns accumulator properties directly. - Record the encryption mode as soon as PRELOGIN selects it (or before the Strict TLS-first handshake), independent of the TLS outcome. - Keep the single-attach assert in AttachPublishedEncryptionInfo, drop the guard. - Move rule tests to accumulator setter tests; update docs and design note. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Address Paul's review: PRELOGIN encryption negotiation, Strict tests - Move the PRELOGIN ENCRYPT negotiation into NegotiateEncryptionOption, which returns the negotiated option; GetEncryptionMode maps it to the reported mode. - Add TLS-first (TDS 8) support to the simulated TDS server and Strict success/failure tests (sync and async). - Rewrite accumulator setter tests: all modes, all reported protocols via Enum.GetValues, other-properties-unaffected asserts, all property subsets. - Remove manual ConnectionEncryptionInfo tests now covered by simulated tests. - Run ResetSessionIsolationLevel inside the Activate attach try, with tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Correct Optional + ENCRYPT_ON row in the mode mapping table With Encrypt=Optional the client sends ENCRYPT_OFF, and a server reply of ENCRYPT_ON leaves the option OFF, so no TLS runs and the mode is None. Only ENCRYPT_REQ upgrades the session to Full. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 0a46e01)
priyankatiwari08
force-pushed
the
dev/automation/pr-4831-to-8.0.0
branch
from
November 18, 2026 07:46
011dd08 to
8fcb746
Compare
priyankatiwari08
changed the base branch from
release/8.0
to
dev/automation/pr-4830-to-8.0.0-v2
November 18, 2026 07:47
This branch has not been deployed
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
Important
DO NOT MERGE. The connection-encryption info feature (#2353) will land in release/8.0 as a whole, only after all slices have merged to
main(remaining: Slice C #4835 and Slice D #4836). An earlier Slice A cherry-pick (#5037) was merged and then reverted by #5090 for this reason. This PR is up for review now so the 8.0 port is ready when the feature is complete.8.0.0 cherry-pick of Slice B of the connection-encryption info feature: #4831 (main
0a46e011d), viagit cherry-pick -x 0a46e011don top of the Slice A port.Populates the negotiated encryption mode and TLS protocol: adds
EncryptionInfoAccumulator, wires it throughSqlConnectionInternal/TdsParser, and adds unit and simulated-server tests.Stack order (each PR is based on the previous one; merge bottom-up):
release/8.0dev/automation/pr-4830-to-8.0.0-v2A separate PR for the Slice A review follow-up (#5043) is not needed: #5037 already contained every #5043 change.
git cherry-pick -x 8d330f187on top of PR1 produced an empty commit, and all 15 files touched by #5043 are byte-identical betweenmain@8d330f187and this branch. (The earlier auto cherry-pick #5055 was closed unmerged.)Conflicts
None. The original auto cherry-pick onto bare
release/8.0conflicted because Slice A was not present (it had been reverted). Rebased onto the Slice A port, the cherry-pick applies cleanly with no adaptation. The simulated-server Strict tests useTdsServerArguments.TlsFirst/ExpectTlsHandshakeFailure, which release/8.0 already has, so #5051 is not needed.The branch was force-pushed (with lease against
011dd0813, the previous empty conflict-marker commit) and retargeted to the Slice A port branch.Issues
Ports #4831 to release/8.0. Feature: #2353.
Testing
Build (0 warnings, 0 errors each):
dotnet build build.proj -t:BuildSqlClient(driver, ref, NotSupported) — succeeded, 0 warnings, 0 errorsdotnet build src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj— succeeded, 0 warnings, 0 errorsdotnet build src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTests.csproj— succeeded, 0 warnings, 0 errorsFocused unit tests (
$f = 'FullyQualifiedName~EncryptionInfo|FullyQualifiedName~EncryptionInfoAccumulator|FullyQualifiedName~ConnectionEncryptionInfo|FullyQualifiedName~SqlConnectionTests|FullyQualifiedName~SqlExceptionTest'):dotnet test src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj --no-build -f passed: 127/127, 0 failed, 0 skipped.0 --filter $f— passed: 127/127, 0 failed, 0 skippeddotnet test src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj --no-build -f passed: 132/132, 0 failed, 0 skipped --filter $f --blame-hang-timeout 5m(with a clean Windows PowerShellPSModulePath) — passed: 132/132, 0 failed, 0 skippedGuidelines
Please review the contribution guidelines before submitting a pull request: