Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose connection encryption information to clients #2353

Open
shueybubbles opened this issue Feb 9, 2024 · 6 comments
Open

Expose connection encryption information to clients #2353

shueybubbles opened this issue Feb 9, 2024 · 6 comments
Labels
💡 Enhancement New feature request 🆕 Public API Use this label for new API additions to the driver.

Comments

@shueybubbles
Copy link

Is your feature request related to a problem? Please describe.

For SSMS we want to give the user full details about their connection security, including encryption status, certificate details, and TLS protocol version.
Such information is needed for both failed and successful connections. For failed connections we want to show the cert validation errors along with the public key cert information so the user can make an informed choice about whether to set Trust Server Certificate or Host Name In Certificate in their connection dialog.

Describe the solution you'd like

  • Provide a more detailed data structure in SqlException that contains the certificate information when cert validation fails
  • Expose TLS and cert information on SqlConnection objects that are in the Open state.
  • Consider exposing cert validation callbacks like you do for token acquisition so apps can have more fine grained control.

It'd be great if this functionality enables an app like SSMS to install the server cert locally to automate the client config steps documented at https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/special-cases-for-encrypting-connections-sql-server?view=sql-server-ver16

Describe alternatives you've considered

We could try to negotiate a TLS connection to the server out-of-band from the SQL connection to get the cert and do our own validation.

@JRahnama JRahnama added this to Needs triage in SqlClient Triage Board via automation Feb 9, 2024
@JRahnama JRahnama moved this from Needs triage to Ideas for Future in SqlClient Triage Board Feb 9, 2024
@JRahnama JRahnama moved this from Ideas for Future to Needs triage in SqlClient Triage Board Feb 9, 2024
@JRahnama JRahnama added 💡 Enhancement New feature request 🆕 Public API Use this label for new API additions to the driver. labels Feb 9, 2024
@JRahnama JRahnama moved this from Needs triage to Ideas for Future in SqlClient Triage Board Feb 13, 2024
@walterpg
Copy link

This would help all integrators who must implement interfaces requiring this information. Currently SQL Server looks bad (unsafe) when it is necessary to explain that connection security feedback is not available with a preferred API. Incomplete and/or inferred security info is not useful, and difficult to trust.

It would really be nice to push this out to DbConnection, but that is another story I suppose.

@cheenamalhotra
Copy link
Member

cheenamalhotra commented Mar 20, 2024

In the meantime, noting down an alternative:

If you have VIEW SERVER STATE or VIEW DATABASE STATE permissions, you could fetch this information from sys.dm_exec_connections [corrected] using the connection you want to get information for:

select session_id, encrypt_option, protocol_type, CONVERT(BINARY(4),protocol_version) as tds_version
from sys.dm_exec_connections
where session_id = @@SPID

@walterpg
Copy link

@cheenamalhotra :
The first DMV mentioned is an Analytics-only object, and neither it nor the query involves TLS information.

The info needed here are connection negotiation artifacts. Maybe SQL Server squirrels that away somewhere, but it seems more efficient to collect it on the client side, where it should already reside in a connected AuthenticatedStream, etc.

@cheenamalhotra
Copy link
Member

Oops, yes I meant sys.dm_exec_connections, and also yes, this should be ideally available via a driver API.

@shueybubbles
Copy link
Author

Having the information available during connection is a bit higher priority for administrative applications. Similar to how the web browser and remote desktop clients work, we need to be able to present the certificate information to the user to let them decide whether to install it/trust it etc.

@walterpg
Copy link

walterpg commented Apr 1, 2024

@shueybubbles:
Agreed. Those users might also prefer to discern other dubiously positive negotiated results, like in a web app. Even (or especially) after SqlClient app deployment. Platform or database config changes can inadvertently result in less secure connections:

  • TCP instead of pipes
  • TLS1.0
  • NTLM auth

Today those results are not available to a security-conscious client app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Enhancement New feature request 🆕 Public API Use this label for new API additions to the driver.
Projects
SqlClient Triage Board
  
Ideas for Future
Development

No branches or pull requests

4 participants