Skip to content

[8.0.0 Cherry-pick] Connection encryption info – Slice A: public API surface - #5037

Merged
paulmedynski merged 4 commits into
release/8.0from
dev/automation/pr-4830-to-8.0.0
Nov 12, 2026
Merged

paulmedynski merged 4 commits into
release/8.0from
dev/automation/pr-4830-to-8.0.0

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Cherry-pick of #4830 (d8a60de) into release/8.0.


Update: This PR now also includes b457732, 93d5fd3 and b65fa83, cherry-picks of 4114d5c, b172dc5 and ce8508d from #5043 (Slice A review follow-up on main), which addresses the review feedback on this PR.

* Add connection encryption info public API surface (Slice A)

Adds SqlConnectionEncryptionInfo, SqlConnectionEncryptionMode, and
SqlServerCertificateValidationErrors, plus SqlConnection.EncryptionInfo and
SqlException.EncryptionInfo getters. In this slice both getters always return
an empty snapshot; no TdsParser/SNI plumbing yet.

Related to #2353.

Co-authored-by: Copilot App <[email protected]>

* Use SHA-256 certificate hash in SqlConnectionEncryptionInfo; add design note

Replace PresentedServerCertificateThumbprint (string?) with
PresentedServerCertificateHash256 (ReadOnlyMemory<byte>?), per the API
agreed with the SSMS team. The internal constructor validates the hash is
32 bytes and keeps a private copy. Add doc/design-notes/2353 for reviewers.

Co-authored-by: Copilot App <[email protected]>

* Fix doc include path and slice plan in design note

Co-authored-by: Copilot App <[email protected]>

* Add NegotiatedCipherSuite to SqlConnectionEncryptionInfo

Adds int? NegotiatedCipherSuite (IANA TLS cipher suite identifier selected by the server) to the public snapshot, ref assembly, XML docs, design note and unit tests. Proposal pending API review.

Co-authored-by: Copilot App <[email protected]>

* Cipher suite: NegotiatedCipherSuiteId (int?) on all TFMs; TlsCipherSuite? on .NET (review feedback)

- Add NegotiatedCipherSuiteId (int?, CLS-compliant) on every target framework.
  It returns the IANA identifier unchanged, including unnamed/GREASE values.
- On .NET only, NegotiatedCipherSuite exposes the same value as
  System.Net.Security.TlsCipherSuite? and is marked [CLSCompliant(false)].
- No NegotiatedCipherSuite member on net462/netstandard2.0, so the only shared
  member has an identical signature across the netstandard2.0 ref and the
  net10.0 implementation.
- The internal constructor still takes int? (0..0xFFFF). The internal
  NegotiatedCipherSuiteValue is removed.
- Update ref, XML docs, design note and unit tests.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34
Co-authored-by: Copilot App <[email protected]>

* Encryption info: replace certificate hash with GetServerCertificate() (threat model review)

Remove PresentedServerCertificateHash256 and expose the server-presented leaf
certificate via X509Certificate2? GetServerCertificate(). Each call returns a
new caller-owned instance parsed from a private DER copy, or null when no
certificate was captured or the bytes cannot be parsed. The internal ctor now
takes byte[]? presentedServerCertificate, and PresentedServerCertificateRawData
exposes the captured bytes internally. Update ref, XML docs, design note and
unit tests.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34
Co-authored-by: Copilot App <[email protected]>

* Encryption info tests: register SqlErrorCollection known types for DataContract round trip

Since #4622, SqlException.GetObjectData writes the error collection, so
DataContractSerializer needs SqlErrorCollection, SqlError and List<object> as
known types.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34
Co-authored-by: Copilot App <[email protected]>

* Encryption info: address Slice A review feedback

- Sort SqlConnectionEncryptionInfo public members alphabetically in the
  implementation, reference assembly, XML doc snippets and design note.
- Document how each SqlConnectionEncryptionMode value is negotiated and
  how much of the connection TLS covers.
- Clarify that the internal PresentedServerCertificateRawData wraps the
  snapshot's private copy and must not be mutated.
- Add XML docs to the test constants and helpers.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34
Co-authored-by: Copilot App <[email protected]>

* Docs: make SqlConnectionEncryptionInfo type remarks release-neutral

Remove the statement that the driver never populates the snapshot; it becomes inaccurate once capture lands in later slices. Point to the getter remarks for when values are captured.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34

Co-authored-by: Copilot App <[email protected]>

* Docs: clarify negotiated protocol availability on failure

Describe null as unavailable, not proof that no TLS handshake completed, and document that a protocol observed before a later handshake or connection failure is retained.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34

Co-authored-by: Copilot App <[email protected]>

* Docs: mark encryption info API approved

Update the design note to show the approved API and remove outdated review caveats. Replace Slice A-only empty-snapshot wording in the getter remarks with the stable connection and exception snapshot contracts.

Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c47d6846-090b-4240-9f75-efa50beb8e34
@github-actions
github-actions Bot requested a review from a team as a code owner November 11, 2026 13:32
@github-actions github-actions Bot added this to the 8.0.0 milestone Nov 11, 2026
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Nov 11, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@paulmedynski
paulmedynski force-pushed the dev/automation/pr-4830-to-8.0.0 branch from b7ed861 to ecfb453 Compare November 11, 2026 15:28
@github-project-automation github-project-automation Bot moved this from To triage to Waiting for customer in SqlClient Board Nov 11, 2026
@paulmedynski

Copy link
Copy Markdown
Contributor

My review here will be addressed by @priyankatiwari08 on main and any resulting commit will be cherry-picked into this PR.

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

Further comments related to the tests.

priyankatiwari08 added a commit that referenced this pull request Nov 12, 2026
Follow-up to #4830 addressing review feedback on the release/8.0
cherry-pick (#5037).

- Carry TlsCipherSuite end-to-end on .NET: the internal constructor takes
  TlsCipherSuite? and NegotiatedCipherSuite is an auto-property; .NET
  Framework keeps the range-checked int? identifier.
- Make SqlConnectionEncryptionMode byte-backed.
- Catch only CryptographicException in GetServerCertificate.
- Annotate GetServerCertificate as returning X509Certificate2? in the ref.
- Clarify null semantics and validation/decoding behavior in the docs and
  drop implementation details.
- Move SqlConnection and SqlException tests into SqlConnectionTests and
  SqlExceptionTests, share helpers via EncryptionInfoTestData, and tighten
  assertions.

Co-authored-by: Copilot App <[email protected]>
priyankatiwari08 and others added 3 commits November 12, 2026 12:44
Follow-up to #4830 addressing review feedback on the release/8.0
cherry-pick (#5037).

- Carry TlsCipherSuite end-to-end on .NET: the internal constructor takes
  TlsCipherSuite? and NegotiatedCipherSuite is an auto-property; .NET
  Framework keeps the range-checked int? identifier.
- Make SqlConnectionEncryptionMode byte-backed.
- Catch only CryptographicException in GetServerCertificate.
- Annotate GetServerCertificate as returning X509Certificate2? in the ref.
- Clarify null semantics and validation/decoding behavior in the docs and
  drop implementation details.
- Move SqlConnection and SqlException tests into SqlConnectionTests and
  SqlExceptionTests, share helpers via EncryptionInfoTestData, and tighten
  assertions.

Co-authored-by: Copilot App <[email protected]>
(cherry picked from commit 4114d5c)
GenAPI reproduces the '?' on SqlConnectionEncryptionInfo.GetServerCertificate()
but emitted no '#nullable' context into the auto-generated source (CS8669) and
copied the compiler-reserved NullableContextAttribute on net10.0 (CS8335).

Pass a header file that adds '#nullable enable annotations', matching the ref
assembly, and exclude the Nullable/NullableContext attributes from the output.

Co-authored-by: Copilot App <[email protected]>
(cherry picked from commit b172dc5)
- Take ushort in the cipher suite identifier theories so InlineData cannot
  exceed 16 bits.
- Document why the BinaryFormatter SqlException tests are .NET Framework only.

Co-authored-by: Copilot App <[email protected]>
(cherry picked from commit ce8508d)
@paulmedynski paulmedynski moved this from Waiting for customer to In review in SqlClient Board Nov 12, 2026
@paulmedynski
paulmedynski merged commit b99cd83 into release/8.0 Nov 12, 2026
9 checks passed
@paulmedynski
paulmedynski deleted the dev/automation/pr-4830-to-8.0.0 branch November 12, 2026 16:53
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Nov 12, 2026
paulmedynski pushed a commit that referenced this pull request Nov 12, 2026
* Address Slice A review feedback for connection encryption info

Follow-up to #4830 addressing review feedback on the release/8.0
cherry-pick (#5037).

- Carry TlsCipherSuite end-to-end on .NET: the internal constructor takes
  TlsCipherSuite? and NegotiatedCipherSuite is an auto-property; .NET
  Framework keeps the range-checked int? identifier.
- Make SqlConnectionEncryptionMode byte-backed.
- Catch only CryptographicException in GetServerCertificate.
- Annotate GetServerCertificate as returning X509Certificate2? in the ref.
- Clarify null semantics and validation/decoding behavior in the docs and
  drop implementation details.
- Move SqlConnection and SqlException tests into SqlConnectionTests and
  SqlExceptionTests, share helpers via EncryptionInfoTestData, and tighten
  assertions.

Co-authored-by: Copilot App <[email protected]>

* Fix notsupported build for nullable-annotated ref members

GenAPI reproduces the '?' on SqlConnectionEncryptionInfo.GetServerCertificate()
but emitted no '#nullable' context into the auto-generated source (CS8669) and
copied the compiler-reserved NullableContextAttribute on net10.0 (CS8335).

Pass a header file that adds '#nullable enable annotations', matching the ref
assembly, and exclude the Nullable/NullableContext attributes from the output.

Co-authored-by: Copilot App <[email protected]>

* Address second-round review feedback on Slice A follow-up

- Take ushort in the cipher suite identifier theories so InlineData cannot
  exceed 16 bits.
- Document why the BinaryFormatter SqlException tests are .NET Framework only.

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: Copilot App <[email protected]>
@mdaigle mdaigle mentioned this pull request Nov 16, 2026
3 of 4 tasks
saurabh500 added a commit that referenced this pull request Nov 17, 2026
…lic API surface (#5037)" (#5090)

This reverts commit b99cd83.

Co-authored-by: Saurabh Singh (SQL Drivers) <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants