Skip to content

Connection encryption info – Slice D: Native SNI interop - #4836

Draft
priyankatiwari08 wants to merge 15 commits into
dev/automation/encryption-info-slice-c-managed-snifrom
dev/automation/encryption-info-slice-d-native-sni
Draft

priyankatiwari08 wants to merge 15 commits into
dev/automation/encryption-info-slice-c-managed-snifrom
dev/automation/encryption-info-slice-d-native-sni

Conversation

@priyankatiwari08

@priyankatiwari08 priyankatiwari08 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PR: stacked on #4835 (Slice C, dev/automation/encryption-info-slice-c-managed-sni), which is stacked on #4831 (B) and #4830 (A). Review only the Slice D commits.

Summary

Native SNI (Windows) now populates the per-attempt connection encryption info with the full presented server certificate (raw DER), validation errors, chain status, and (as a fallback) the server-selected TLS protocol observed by Schannel, which can be present even when the handshake did not complete, and the negotiated cipher suite. The values come from two new sni.dll exports. This brings Native SNI to parity with Managed SNI (Slice C).

Following the Threat Model Review outcome, the SHA-256 hash of the certificate is no longer captured or exposed; the driver exposes the presented certificate instead.

Part of #2353

Native dependency

  • The exports SNIGetCertValidationInfoWrapper and SNIGetServerCertificateWrapper are added by native SNI PR 8573 (Microsoft.Data.SqlClient.sni), which hasn't shipped yet. The behavior also relies on SNI deferred validation (commit b9d842c) and the host-name verdict fix (commit 55d318d) on ADO dev/automation/encryption-info-cert-exports.
  • This PR no longer changes SniVersion. Main moved to 8.0.0-preview1.26309.4 (Update SNI dependencies to 8.0.0-preview1.26309.4 #5011), and D keeps main's version rather than downgrading it. That package does not contain these exports, so with the default build Native SNI reports no certificate details (graceful degradation). The exports are in 7.1.0-preview3.26303.1 (Microsoft.Data.SqlClient.SNI and .SNI.runtime; SNI pipeline 2312, run 187399, native commit d77d9e15e; signed DLL SHA-256: x64 FFC43EB7…725E, x86 2941FD98…5937, arm64 4E89C37D…A9B0). An 8.0.x SNI build containing native PR 8573 is needed before this PR can deliver native certificate details by default.
  • CI restore no longer depends on 7.1.0-preview3.26303.1.
  • With an older sni.dll that lacks these exports, Native SNI reports no certificate details, and connections still work (see degradation below).
  • The only native build with these exports validated so far is 7.1.0-preview3.26303.1 (run 187399, commit d77d9e15e), used locally with -p:SniVersion=7.1.0-preview3.26303.1. Superseded private test builds are not supported; if one is loaded, it rejects the 32-byte request with 87 and every field stays null.

Changes

  • SniCertValidationInfo: blittable 32-byte v1 struct (cbSize, dwVersion, dwAvailable, dwValidationMode, dwProtocol, dwValidationErrors, dwChainStatus, dwCipherSuite), plus the availability flag and validation mode enums. The certificate flag is 0x4. SqlClient sends cbSize = 32.
  • P/Invoke declarations (Cdecl) for SNIGetCertValidationInfoWrapper and SNIGetServerCertificateWrapper(pConn, pb, cb, pcb) for net10.0 and for the net462 x64/x86/ARM64 dlls. The NotSupported stub throws.
  • SniNativeWrapper: SniGetServerCertificate; protocol mapping in ToSslProtocols, shared by the handshake and capture paths.
  • SniNativeCertificateCapture: queries and maps the values, and handles degradation. Native calls go through an internal seam (delegates) so tests can inject structs and certificate bytes.
  • TdsParserStateObjectNative.GetServerCertificateCapture() and GetNegotiatedCipherSuite() overrides (the latter reads only the validation info, without copying the certificate). TdsParser.EnableSsl assigns the EncryptionInfoAccumulator properties (ServerCertificateRawData, ValidationErrors, ChainStatus, Protocol ??=, CipherSuite if unset) directly, after EnableSsl and again right after WaitForSSLHandShakeToComplete, before its error check (covers async handshakes on success and failure). A protocol of None from the SSL wait no longer overwrites an observed protocol.
  • The certificate bytes are passed to the SqlConnectionEncryptionInfo constructor (byte[]? presentedServerCertificate) through Slice C's ServerCertificateCapture.
  • The hash-only export and fallback are removed.
  • Design note: "Native SNI certificate capture" section rewritten for the full certificate.

Certificate read

When dwAvailable has 0x4, SqlClient calls SNIGetServerCertificateWrapper twice:

  1. Size query with an empty buffer: must return 122 (INSUFFICIENT_BUFFER) with a size of 1..65,536 bytes. A size of 0 or over 64 KiB is rejected.
  2. Read into a buffer of that size: must return 0 with written == size.

Any other result, an EntryPointNotFoundException, or any exception gives a null certificate; the other fields are still reported.

Mapping

Field Native source (dwAvailable flag) Mapping
Presented server certificate SNIGetServerCertificateWrapper (CERTIFICATE 0x4) Raw DER bytes copied (1..64 KiB)
ServerCertificateValidationErrors dwValidationErrors (VALIDATION_ERRORS 0x8) Same bit values; unknown bits preserved
ServerCertificateChainStatus dwChainStatus (CHAIN_STATUS 0x10) Raw CERT_TRUST_* value read as X509ChainStatusFlags; unknown bits preserved
NegotiatedProtocol dwProtocol (PROTOCOL 0x2) SP_PROT_* client bits mapped like the handshake result (TLS 1.3 is 0x3000 on net462). Used only if no protocol was already recorded.
NegotiatedCipherSuiteId (all targets) / NegotiatedCipherSuite (TlsCipherSuite?, .NET only) dwCipherSuite (CIPHER_SUITE 0x80) 0 and values above 0xFFFF ignored. Read through GetNegotiatedCipherSuite(), else adopted from the capture when no suite was recorded for the attempt; kept on a deferred-validation failure. Cast to TlsCipherSuite on .NET.

The struct is ignored when cbSize < 32 or dwVersion < 1. Newer versions are accepted and their trailing data is ignored. Any field whose flag isn't set stays null.

Degradation behavior

  • Older sni.dll (missing exports): an EntryPointNotFoundException is cached once per export. A missing validation-info export leaves all fields null; a missing certificate export leaves only the certificate null. There is no hash fallback.
  • Superseded private builds: reject the 32-byte request with 87; all fields stay null.
  • Non-zero return codes (87, 122 on read, 1168, any other value): the affected fields stay null.
  • Any other exception: swallowed and not cached. The trace records only the exception type name, never certificate bytes or flags. The connection outcome and the thrown exception don't change.
  • Trust behavior and exception messages are unchanged.

Native deferred validation (always on)

Native SNI always defers server certificate validation until Schannel has the presented certificate; there is no opt-in or opt-out switch (decision by Paul Medynski; going to security review). With the matching SNI build, the certificate, validation errors and chain status are reported in every validation mode, including SchannelAutomatic failures, and a wrong HostNameInCertificate with an untrusted chain reports HostNameMismatch | ChainError, the same as Managed SNI. Accept/reject results and error codes are unchanged. Fields are never derived from HRESULTs or error messages.

Open questions

  1. Protocol on failure. SNI reads dwProtocol from the Schannel connection info after the server hello, so it is the version the server selected, not the client's offered set. This PR records it when no protocol was already recorded (G2/D15: observed mode/protocol kept on validation failure).
  2. CHAIN_STATUS_LEAF_TIME_ONLY (0x40). Set only for pinned-certificate expiry, where SNI checks the leaf validity period and builds no chain. Chain status is reported as null in that case, matching Managed SNI in pinned modes.
  3. dwValidationMode. Read but not used in the mapping.

Test results

  • Driver and ref build: 0 warnings, 0 errors (net462 and net10.0).
  • SniNativeCertificateCaptureTests cover:
    • 32-byte struct layout and offsets; Certificate = 0x4, CipherSuite = 0x80
    • all 256 availability-flag combinations
    • certificate size limits (0, 1, 64 KiB, 64 KiB + 1), size query then read, read failures, short reads
    • missing certificate export (no fallback, cached) and missing validation-info export
    • every validation-error bit and every X509ChainStatusFlags value, plus unknown bits
    • protocol mapping, including TLS 1.3
    • cipher suite with/without 0x80 and out-of-range values
    • malformed headers and newer struct versions
    • return codes 87, 122, 1168 and others; exceptions swallowed for both exports
    • TryGetCipherSuite: available/unavailable/out-of-range, error codes, missing export cached for all queries, exceptions swallowed without disabling, no usable handle
  • Head 121d8c07d (stacked on C f771fb427, after Paul's B review: EncryptionInfoCapture renamed to EncryptionInfoAccumulator, Record* helpers removed, mode kept on TLS/certificate failure). Rebased from C 1aed09457; conflicts: commit 1 (EncryptionInfoCapture.cs deleted upstream, D's logic re-expressed via accumulator properties), commit 11 (AssertUntrustedCertificateFailure now expects mode Full always; Tls12 + cipher only when managed or the native export is present), commit 12 (design note: took C's failure-path text, rewrote D's Native bullet). Range-diff: the other 11 commits =; new commit 15 adapts to the accumulator. Driver, ref, NotSupported, UnitTests and ManualTests build with 0 warnings. Focused filter with main's SNI 8.0.0-preview1.26309.4 (no exports): net10.0 1200/1200 (exit 0); net462 1178/1178, then the known teardown hang (exit 1). Export-present branches remain untestable until the feature-enabled SNI 8.0.x package ships. Earlier: head a09ba74c7 (stacked on C 1aed09457, on B 99db5b52d, on main with the merged Slice A review follow-up Connection encryption info – Slice A review follow-up #5043 8d330f187). Rebasing from C 7f962e900 produced no conflicts. The range-diff shows all 14 D commits as =, and D's cumulative patch is identical to e529d5166 when index and hunk-header lines are ignored. No product change was needed. The driver, ref, NotSupported and UnitTests build with 0 warnings. The focused EncryptionInfo|SniNativeCertificateCapture|SimulatedServerTests|InternalsVisibleTo|SqlExceptionTest|SqlConnectionTests filter ran with main's SNI 8.0.0-preview1.26309.4 (x64 3AADEA37). On net10.0, 1206/1206 passed (exit 0). On net462, 1178/1178 passed, followed by the known teardown hang (exit 1). Earlier: e529d5166 on C 7f962e900 adopted Connection encryption info – Slice A review follow-up #5043's test conventions with no product change (net10.0 1206/1206, net462 1178/1178). Earlier: 6b86e9c9b on C 8a0b3a36b (net10.0 1208/1208, before C's test consolidation). Earlier history: at 030c293b4, the head was stacked on C 928f40a85, B 7149c8753, A 1e1dc8628, main e16417f71. Product code is unchanged since f515c1e9b. 030c293b4 changes only one simulated-server assertion: with Native SNI, the certificate is required only when the separate SNIGetServerCertificateWrapper export is available, so a cipher suite no longer implies a certificate. D does not modify Directory.Packages.props. Focused filter with main's SNI 8.0.0-preview1.26309.4 (x64 3AADEA37): 513/513 on net10.0 and 509/509 on net462, both with exit 0. Build of the driver, ref and UnitTests: 0 warnings on both TFMs.
    • Main's default SNI 8.0.0-preview1.26309.4 (deployed x64 3AADEA37…, no exports): focused filter plus SimulatedServerTests and ConnectionPool tests passed 1666/1666 on net10.0. On net462, 1471/1471 passed, but the host then hit the known net462 teardown hang (blame named TdsTokenBoundsTests.BatchResponse_PromoteTransaction_OversizedLength_ThrowsParsingError; TdsTokenBoundsTests passes 12/12 when run alone).
    • Export-bearing -p:SniVersion=7.1.0-preview3.26303.1 (deployed x64 FFC43EB7…725E on both TFMs): focused filter EncryptionInfo|SniNativeCertificateCapture|InternalsVisibleTo|SqlExceptionTest passed 513/513 on net10.0 and 509/509 on net462, both with exit 0. On Native SNI with these exports, an untrusted-certificate failure reports Full, Tls12 and a cipher suite; with an older sni.dll only the mode (Full/Strict, recorded at PRELOGIN) is reported and protocol/cipher are null. net462 runs used a clean Windows PowerShell PSModulePath.
  • New simulated-server tests NativeSniEncryptionInfoTests (Open and OpenAsync, Native SNI, self-signed certificate, TrustServerCertificate=false) assert that SqlException.EncryptionInfo carries the presented DER, ChainError and UntrustedRoot. With an sni.dll lacking the exports they assert null instead. Both ran and passed on net10.0 and net462.
  • New live ManualTest NativeSniServerCertificateTest (Open and OpenAsync, Native SNI, Encrypt=Mandatory, TrustServerCertificate=true) asserts that GetServerCertificate() returns non-null DER with no private key, and that each call returns a distinct instance. If the loaded sni.dll lacks the export, it asserts null instead. Result against local SQL Server 2022: 2/2 on net10.0, 2/2 on net462. A temporary strict run that required the export also passed 2/2 on each TFM.
    • Nothing listens on localhost:1433 (the default instance is stopped and was left stopped), so the run used named instance MSSQLSERVER_02 at tcp:localhost,50904. No server config was changed.

Further manual tests

Run on Native SNI for net462 and net10.0, on x64, x86 and ARM64, with both sync and async Open:

  • TLS 1.2 and TLS 1.3 (Strict) with a valid certificate: certificate (matches the server's leaf DER), None/NoError, protocol and cipher suite populated
  • Untrusted root (covered by the simulated-server tests above) and expired certificate: ChainError plus the correct chain flags on SqlException.EncryptionInfo
  • Hostname mismatch with HostNameInCertificate: HostNameMismatch (HostNameMismatch | ChainError with an untrusted chain)
  • ServerCertificate pin mismatch: PinnedCertificateMismatch, with ChainStatus null
  • TrustServerCertificate=true: certificate present, validation fields null
  • SchannelAutomatic failure: certificate, ChainError and chain status reported
  • Integrated auth and the async handshake path
  • Old sni.dll (current package): connections succeed and certificate fields are null
  • Retry and failover: values reflect the terminal attempt only

Checklist

  • Tests added or updated
  • No public API changes in this slice
  • Verified against a native SNI build with the full-certificate export (7.1.0-preview3.26303.1 via -p:SniVersion, live Open/OpenAsync on an earlier head with identical D content)
  • No breaking changes

Copilot AI balanced review requested due to automatic review settings October 13, 2026 05:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Failed handshakes can expose an attempted protocol as negotiated, and the new tests omit required XML summaries.

2 open findings
What changed in this PR

Adds Native SNI certificate and TLS diagnostics to connection encryption snapshots, with graceful fallback for older native libraries.

Changes:

  • Adds native certificate-validation interop and mapping.
  • Captures certificate details after native TLS handshakes.
  • Adds documentation and extensive unit coverage.
File Description
doc/​design-notes/​2353-connection-encryption-info.md Documents Native SNI capture.
Connection/​EncryptionInfoCapture.cs Records transport-reported protocol.
Connection/​ServerCertificateCapture.cs Carries optional TLS protocol.
SniNativeCertificateCapture.cs Queries and maps native details.
TdsParser.cs Captures details after handshake waits.
TdsParserStateObjectNative.cs Exposes native certificate capture.
ISniNativeMethods.cs Extends the native interface.
SniCertValidationInfo.cs Defines the native interop structure.
SniNativeMethodsArm64.netfx.cs Adds ARM64 declarations.
SniNativeMethodsNotSupported.netfx.cs Adds unsupported-platform stubs.
SniNativeMethodsX64.netfx.cs Adds x64 declarations.
SniNativeMethodsX86.netfx.cs Adds x86 declarations.
SniNativeMethods.netcore.cs Adds modern .NET declarations.
SniNativeWrapper.cs Wraps exports and protocol mapping.
SniNativeCertificateCaptureTests.cs Tests mapping and degradation behavior.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 09:53
@priyankatiwari08
priyankatiwari08 force-pushed the dev/automation/encryption-info-slice-d-native-sni branch from 5c61fc2 to 5e5fd50 Compare October 13, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Existing unresolved feedback identifies a protocol-contract violation and missing required test documentation.

2 open findings

🧠 Review effort: Balanced

@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.80000% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.59%. Comparing base (1aed094) to head (a09ba74).

Files with missing lines Patch % Lines
...Client/src/Interop/Windows/Sni/SniNativeWrapper.cs 27.27% 8 Missing ⚠️
...Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs 0.00% 2 Missing ⚠️
.../Windows/Sni/SniNativeMethodsNotSupported.netfx.cs 0.00% 2 Missing ⚠️
...c/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs 0.00% 2 Missing ⚠️
...rc/Interop/Windows/Sni/SniNativeMethods.netcore.cs 50.00% 1 Missing ⚠️
...c/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs 50.00% 1 Missing ⚠️
...t/src/Microsoft/Data/SqlClient/Parser/TdsParser.cs 0.00% 1 Missing ⚠️
...ata/SqlClient/Parser/TdsParserStateObjectNative.cs 0.00% 1 Missing ⚠️
...soft/Data/SqlClient/SniNativeCertificateCapture.cs 98.96% 1 Missing ⚠️
Additional details and impacted files
@@                                  Coverage Diff                                   @@
##           dev/automation/encryption-info-slice-c-managed-sni    #4836      +/-   ##
======================================================================================
- Coverage                                               72.01%   69.59%   -2.42%     
======================================================================================
  Files                                                     316      318       +2     
  Lines                                                   71326    70135    -1191     
======================================================================================
- Hits                                                    51365    48813    -2552     
- Misses                                                  19961    21322    +1361     
Flag Coverage Δ
sqlclient-pr 69.59% <84.80%> (-2.42%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI balanced review requested due to automatic review settings October 15, 2026 09:39
@priyankatiwari08
priyankatiwari08 force-pushed the dev/automation/encryption-info-slice-d-native-sni branch from 5e5fd50 to f1a8e10 Compare October 15, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Native binary compatibility and real synchronous/asynchronous TLS behavior remain unverified against the unshipped SNI dependency.

3 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 09:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Native binary compatibility and real synchronous/asynchronous handshake behavior remain unverified against the unreleased SNI exports.

3 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 09:38
@priyankatiwari08
priyankatiwari08 force-pushed the dev/automation/encryption-info-slice-d-native-sni branch from db0de4e to 0d5e476 Compare October 19, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The native exports have not shipped, leaving binary compatibility and real Windows handshake behavior unverified.

3 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 13:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The previously identified chain-status contract concern remains unresolved in the supplied mapping and tests.

3 open issues

Review effort: Balanced

@priyankatiwari08 priyankatiwari08 added this to the 8.0.0-preview1 milestone Oct 19, 2026
@priyankatiwari08 priyankatiwari08 changed the title [Draft] Connection encryption info – Slice D: Native SNI interop [DO NOT MERGE] [Draft] Connection encryption info – Slice D: Native SNI interop Oct 19, 2026
@mdaigle mdaigle linked an issue Oct 20, 2026 that may be closed by this pull request
@cheenamalhotra cheenamalhotra removed this from the 8.0.0-preview1 milestone Oct 21, 2026
@priyankatiwari08 priyankatiwari08 added this to the 8.0.0 milestone Nov 10, 2026
@priyankatiwari08
priyankatiwari08 marked this pull request as ready for review November 10, 2026 18:35
@priyankatiwari08
priyankatiwari08 requested a review from a team as a code owner November 10, 2026 18:35
@priyankatiwari08
priyankatiwari08 force-pushed the dev/automation/encryption-info-slice-d-native-sni branch from 1965a79 to f515c1e Compare November 10, 2026 18:36
Copilot AI balanced review requested due to automatic review settings November 10, 2026 18:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests incorrectly require a non-null certificate when Native SNI can report a cipher suite without one if SNIGetServerCertificateWrapper is unavailable, causing failures in a supported degradation case.

2 open issues

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The native ABI and deferred certificate-validation contracts depend on unshipped SNI exports, leaving native/security-owner review and key TLS and architecture verification outstanding.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unshipped SNI exports and deferred-validation ABI changes require coordinated native/security review and validation with a matching Windows native build, especially for x86, ARM64, and Strict/TLS 1.3 paths.

1 open issue

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Native ABI and deferred certificate-validation behavior require native/security-owner verification with the matching feature-enabled 8.0.x SNI build, while x86/ARM64, Strict/TLS 1.3, and failure-path validation remain incomplete.

1 open issue

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The native ABI and deferred-validation changes require review against the unavailable matching SNI implementation, with x86/ARM64, Strict/TLS 1.3, and security validation still outstanding.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests bypass access-token setup for credential-free Azure SQL connection strings, causing login failures before the certificate assertions are reached.

1 open issue

Review effort: Balanced

Pooling = false,
};

using SqlConnection connection = new(builder.ConnectionString);
priyankatiwari08 and others added 15 commits November 17, 2026 13:05
Query the new sni.dll exports SNIGetCertValidationInfoWrapper and
SNIGetServerCertificateHashWrapper after the TLS handshake (success or
failure, before handle close) and populate the per-attempt capture:
hash (HASH flag), validation errors (VALIDATION_ERRORS), chain status
(CHAIN_STATUS, unknown bits preserved), and protocol fallback (PROTOCOL)
when not already recorded.

Missing exports in older sni.dll are detected once and cached; fields
stay null. Capture never throws or alters connection outcome. No SNI
package bump: the native exports are not shipped yet (SNI PR 8573).

Part of #2353

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…er ClearNegotiated

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…tive gaps

Native SNI now defers certificate validation unconditionally (SNI b9d842c)
and reports HostNameMismatch|ChainError (SNI 55d318d), so the SchannelAutomatic
and single-error gaps no longer apply. Older sni.dll still leaves fields null.
Add a mapping test for the full deferred-validation verdict.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Request version 2 of SNI_CERT_VALIDATION_INFO (cbSize = 68) and map
dwCipherSuite into the capture when dwVersion >= 2, cbSize >= 68 and the
CIPHER_SUITE (0x80) availability flag is set. Version 1 responses from
older sni.dll builds and missing exports leave the cipher suite null.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…4810)

SNIHandle moved to Microsoft.Data.SqlClient.NativeSni and TdsParserStateObjectNative to Microsoft.Data.SqlClient.Parser.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the CLS-compliant NegotiatedCipherSuiteId in native capture tests and keep the .NET-only TlsCipherSuite enum assertion. Update the native SNI mapping row.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ts hash

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The native SNI package on main (8.0.0-preview1.26309.4) does not yet provide
SNIGetServerCertificateWrapper/SNIGetCertValidationInfoWrapper, so the test
checks for the export and expects a null certificate without it.

Part of #2353

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Leave native chain status null for leaf-time-only (pinned) results, matching Managed SNI.
- Document that the native protocol is the server-selected version.
- Add Native SNI simulator tests for untrusted certificates on Open and OpenAsync.
- Use spy assertions instead of a throwing certificate query, and add test summaries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Native SNI with the validation info export reports the protocol, cipher suite
and mode on an untrusted-certificate failure, and the presented certificate
when TrustServerCertificate=true; an older sni.dll reports none of them.

Part of #2353

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
With an sni.dll that provides the validation info export, native SNI reports
mode Full, the server-selected protocol and the cipher suite on an
untrusted-certificate failure; an older sni.dll reports none of them.
Observing the protocol does not imply a completed handshake.

Part of #2353

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The cipher suite comes from SNIGetCertValidationInfoWrapper while the presented certificate comes from the separate SNIGetServerCertificateWrapper export, so require the certificate only when that export is available.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Assign accumulator properties directly from the native capture, add the
GetNegotiatedCipherSuite override backed by SNIGetCertValidationInfoWrapper,
and keep an observed protocol when the SSL wait reports none.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Directly constructing SqlConnection bypasses the shared factory’s access-token handling for supported credential-free Azure SQL configurations, causing both theory cases to fail authentication before reaching certificate assertions.

1 open issue

Review effort: Balanced

This branch has not been deployed

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

Labels

Hotfix 8.0.0 PRs that must be backported to release/8.0

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

Feature | Expose connection encryption information to clients

5 participants