Skip to content

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

Open
priyankatiwari08 wants to merge 19 commits into
mainfrom
dev/automation/encryption-info-slice-d-native-sni
Open

priyankatiwari08 wants to merge 19 commits into
mainfrom
dev/automation/encryption-info-slice-d-native-sni

Conversation

@priyankatiwari08

@priyankatiwari08 priyankatiwari08 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Based on main (Slices A, B and C are merged). Depends at runtime on native SNI PR 8573; until an SNI package with those exports ships, Native SNI reports no certificate details.

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 (#nullable enable): Record(handle, accumulator) queries the exports and writes directly into the attempt's EncryptionInfoAccumulator (Slice C's accumulator pattern; no intermediate record and no state on the handle). A usable report replaces all five values (certificate, validation errors, chain status, protocol, cipher suite), with null for any value whose availability flag isn't set; an error code, missing export or malformed struct leaves the accumulator unchanged. The certificate is read into an ArrayPool buffer and copied by the accumulator. A null handle is rejected before reaching native code. Native calls go through an internal delegate seam so tests can inject structs and certificate bytes.
  • TdsParserStateObjectNative records in EnableSsl when adding the SSL provider fails, and in WaitForSSLHandShakeToComplete after the wait (success or failure), so async native handshakes are covered. WaitForSSLHandShakeToComplete gains an EncryptionInfoAccumulator parameter; Managed SNI ignores it because its validation callback already recorded the handshake. When nothing reported a protocol, TdsParser.EnableSsl records the protocol from the completed handshake (existing fallback).
  • The hash-only export and fallback are removed.
  • Design note: "Native SNI certificate capture" section describes the direct accumulator writes.

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, or an EntryPointNotFoundException (cached), gives a null certificate; the other fields are still reported. Other exceptions propagate.

Mapping

Field Native source (dwAvailable flag) Mapping
Presented server certificate SNIGetServerCertificateWrapper (CERTIFICATE 0x4) Raw DER bytes copied into the accumulator's ServerCertificateDerBytes (1..MaxServerCertificateDerBytesSize = 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). When unavailable, the handshake wait's protocol is used after a successful handshake.
NegotiatedCipherSuiteId (all targets) / NegotiatedCipherSuite (TlsCipherSuite?, .NET only) dwCipherSuite (CIPHER_SUITE 0x80) 0 and values above 0xFFFF map to null. Mapped by MapCipherSuite to TlsCipherSuite? on .NET (no int cast) and int? on netfx; the record is the only source; kept on a deferred-validation failure.

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: not swallowed and not cached; it propagates (no catch (Exception) blocks).
  • 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

  • Head 0bab0c633, rebased onto main (after Slice C merged as ce73774d1). The last commit replaces the TlsHandshakeInfo record with direct accumulator writes.
  • UnitTests (builds driver) for net10.0 and net462: 0 warnings, 0 errors.
  • SniNativeCertificateCapture|EncryptionInfoAccumulator|ServerCertificateCapture filter with main's SNI 8.0.0-preview1.26309.4 (no exports): net10.0 412/412, net462 413/413.
  • SniNativeCertificateCaptureTests cover: 32-byte struct layout; all 256 availability-flag combinations; certificate size limits (0, 1, 64 KiB, 64 KiB + 1), size query then read, read failures and short reads; missing exports (cached, no fallback); every validation-error bit and chain flag plus unknown bits; protocol mapping including TLS 1.3; cipher suite range; malformed and newer struct versions; return codes 87, 122, 1168 and others; propagating exceptions; null handle with the real binding; null accumulator; a later report replacing earlier values (including with null); and an unusable report leaving earlier values unchanged.
  • NativeSniEncryptionInfoTests (simulated server, Open and OpenAsync, Native SNI, untrusted self-signed certificate) assert the presented DER, ChainError and UntrustedRoot when the exports exist, and null otherwise.
  • Locally on net462, the simulated-server ConnectionEncryptionInfoTests fixture fails to create its certificate (Cannot find drive 'Cert' in the PowerShell host); this is environmental and unrelated to this change.
  • Export-present paths can't be exercised in CI until an SNI 8.0.x package with PR 8573 ships. An earlier head was validated live against 7.1.0-preview3.26303.1.

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)
  • 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 75.51020% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.89%. Comparing base (17bef7b) to head (4383fc9).
⚠️ Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
...Client/src/Interop/Windows/Sni/SniNativeWrapper.cs 51.21% 20 Missing ⚠️
...soft/Data/SqlClient/SniNativeCertificateCapture.cs 91.46% 7 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 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4836      +/-   ##
==========================================
+ Coverage   68.99%   72.89%   +3.90%     
==========================================
  Files         314      316       +2     
  Lines       45857    71576   +25719     
==========================================
+ Hits        31638    52174   +20536     
- Misses      14219    19402    +5183     
Flag Coverage Δ
CI-SqlClient ?
sqlclient-pr 72.89% <75.51%> (?)

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

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

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 test bypasses the connection factory’s access-token injection, causing both cases to fail at login for supported credential-free Azure SQL configurations before reaching the certificate assertions.

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 test directly constructs SqlConnection, bypassing managed-identity token assignment and causing both theory cases to fail authentication before certificate assertions for credential-free Azure SQL configurations accepted by its guard.

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.

🟡 Changes recommended

The default handshake-info delegate still invokes native code for a null handle, causing uncaught loading or marshalling exceptions that fail the new test instead of returning null.

2 open issues

Review effort: Balanced

priyankatiwari08 and others added 18 commits November 21, 2026 01:09
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 <[email protected]>
…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 <[email protected]>
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 <[email protected]>
…4810)

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

Co-authored-by: Copilot App <[email protected]>
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 <[email protected]>
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 <[email protected]>
- 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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Native SNI now produces C's TlsHandshakeInfo record through the
GetTlsHandshakeInfo override; the record is the single source of the
protocol, cipher suite and certificate details. Remove the separate
cipher-suite path and the swallowed exceptions (only missing-export
EntryPointNotFoundException is cached), map cipher suites to
TlsCipherSuite? on .NET, fall back to the handshake protocol when the
record reports none, and drop the NativeSniServerCertificateTest manual
test.

Co-authored-by: Copilot App <[email protected]>
Adopt the Slice C accumulator pattern for native SNI: the native handle writes
the certificate, validation errors, chain status, protocol and cipher suite
straight into the attempt's EncryptionInfoAccumulator when EnableSsl fails and
after WaitForSSLHandShakeToComplete, replacing the intermediate TlsHandshakeInfo
record and GetTlsHandshakeInfo. The certificate is read into a pooled buffer
and copied by the accumulator. A null handle is rejected before native code.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 5b0df491-21cd-4da0-b776-7cd9a8af085e

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 null-handle test incorrectly assumes a process-wide flag is false, causing order-dependent failures; it should capture the initial value and assert that the calls leave it unchanged.

2 open issues
1 resolved since last review

Review effort: Balanced

@paulmedynski paulmedynski 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.

I'll look at the tests after we address my code feedback.

/// <summary>
/// Copies the DER encoding of the server certificate presented during the most recent client
/// TLS handshake on <paramref name="pConn"/> into <paramref name="certificate"/>. Pass an empty
/// buffer to query the size, which is returned in <paramref name="certificateSize"/>.

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.

If SqlClient asks for the size, and then never asks for the cert, does that leave a cert allocated on the SNI side, and if yes, for how long, and how large can it be?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, native SNI keeps a copy. During the handshake, SNI_Conn::m_CertCapture stores a heap copy of the leaf certificate DER, whether or not SqlClient ever asks for it.

  • It is capped at 64 KB (SNI_CERT_MAX_CAPTURED_SIZE). A larger certificate is not captured and reported as unavailable; the connection is unaffected.
  • It is replaced on a re-handshake and freed on reset or when the SNI_Conn is released.
  • The size query does not allocate.

So the worst case is one leaf certificate (at most 64 KB) per open native connection, for that connection's lifetime.

Auto-replied by the GitHub Copilot app

…ive capture

- SNI_CERT_VALIDATION_INFO is a fixed 24-byte layout with no cbSize/dwVersion header.
- SniNativeWrapper detects a missing export once per process and returns ERROR_PROC_NOT_FOUND.
- Each native state object owns its SniNativeCertificateCapture; Default and flags removed.
- Single certificate size check in Record; Apply is private; docs and flow comments added.
- EncryptionInfoAccumulator parameters are nullable-annotated; tests and design note updated.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 5b0df491-21cd-4da0-b776-7cd9a8af085e

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 native interop layout omits required header fields, causing queries to fail against the supported native build and leaving certificate, validation, and cipher diagnostics unavailable.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment on lines +24 to +27
internal struct SniCertValidationInfo
{
/// <summary>Out: <see cref="SniCertInfoAvailability"/> flags.</summary>
public uint dwAvailable;

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: Waiting for customer

Development

Successfully merging this pull request may close these issues.

Feature | Expose connection encryption information to clients

6 participants