Sql-server – How to configure encrypted SQL Server connections to prevent MITM attacks

encryptionSecuritysql serversql-server-2016

It has come to my surprise that SQL Server by default does nothing to prevent man-in-the-middle attacks when configuring your SQL Server to enforce connection encryption.

Forcing encryption on your connections is dead-simple. You go to Sql Server Configuration Manager, expand SQL Server Network Configuration, Protocols for [your instance], right-click TCP/IP, change Force Encryption to 'Yes', restart SQL Server and you're done.
Force Encryption set to Yes

Per Microsoft TechNet (https://technet.microsoft.com/en-us/library/ms189067(v=sql.105).aspx), this will generate a Self-Signed Certificate. Fine, no problem, But I expect my clients to complain that the certificate is not trusted. However, they do not. They happily connect to it. I then realize that 'Trust server certificate' is checked by default in SQL Management Studio. Fine, but the most shocking realization is: even if you uncheck "Trust server certificate", SSMS does not complain, warn, or reject the connection.

Trust server certificate is unchecked

So by default SQL Server is completely susceptible to MITM attacks because clients do nothing to verify the certificate from SQL Server. The certificate shouldn't have to be signed by a CA: the certificate should have to be configured as a trusted certificate on the client. If that's not true, what is the "Trust server certificate" checkbox for?

Best Answer

See Using Encryption Without Validation. Aside from the connection setting 'Trust Server Certificate', there is another setting, the client setting 'Trust Server Certificate', which is configured from the Configuration Manager. If any of the two is set, a self-signed certificate will succeed (actually is a bit more complex as the client setting No will override the connection setting... see the link).