SSL Setup Guide
Author: Eitan Blumin
Madeira Data Solutions
Import the CA Certificate on the SQL Server machine 3
Enable the SSL Setting in SQL Server 3
Restart the SQL Server service 3
Configuring the SQL Server clients to use encrypted connections 3
Check if connections are encrypted 4
Try to connect using the Fully Qualified Domain Name 4
Check the connection string of your application 4
SSL encryption for failover clustering in SQL Server 4
Rollback: Disabling the SSL Setting in SQL Server 5
The first step to secure the connections is to obtain a security certificate. These certificates need to be generated by IT, or by a trusted CA. There are several requirements which should be fulfilled by the certificate:
- It must be valid thus the current system date and time should be between the Valid From and Valid To properties of the certificate.
- The Common Name (CN) in the Subject property of the certificate must be the same as the fully qualified domain name (FQDN) of the server computer(s).
- It must be issued for server authentication so the Extended Key Usage property of the certificate should include 'Server Authentication (1.3.6.1.5.5.7.3.1)' (see below).
- It must be created by using the KeySpec option of 'AT_KEYEXCHANGE'.
It is possible to use self-signed certificates, but this should be done for test purposes only, and must be avoided in production environments.
To import a certificate, follow these steps on each relevant machine:
- Run certlm.msc (Certificates – Local Machine) as Administrator
- Right-click on the Personal folder, point to All Tasks , and then click Request New Certificate...
- Click Next in the Certificate Request Wizard dialog box. Select certificate type 'Computer'.
- You can enter a friendly name in text box if you want or leave it blank, then complete the wizard.
- Now you should see the certificate in the folder with the fully qualified computer domain name.
You can configure SSL using the SQL Server Configuration Manager. First, you should run SQL Server Configuration Manager under the SQL Server service account. The only exception is if the service is running as LocalSystem, NetworkService, or LocalService, in this case you can use an administrative account.
- Expand SQL Server Network Configuration and right-click on Protocols for <YourMSSQLServer> , then click Properties.
- On the Certificate tab, select the certificate you would like to use.
- On the Flags tab, select No in the ForceEncryption box, then click OK.
Restarting the SQL Server service in production environment obviously must be done very carefully and thoughtfully.
You should export the certificate from your SQL Server and install it on the client computer to establish the encryption.
- Open the MMC Certificates Snap-in as described above.
- Right-click the Certificate , point to All Tasks , and then click Export.
- Complete the Certificate Export Wizard , storing the certificate file in a selected location.
- Copy the certificate to the client computer.
- Use the MMC Certificates Snap-in on the client computer to install the exported certificate file: Right-click the Trusted Root Certification Authorities folder, point to All Tasks , and then click Import and follow the steps.
- In the SQL Server Configuration Manager right-click SQL Server Native Client Configuration , and then click Properties.
- On the Flags tab, select Yes in the ForceEncryption box, then click OK.
The client machine should trust the certificate so there are two options:
- The SQL Server's certificate should be installed on the client machine to establish a direct trust.
- The certificate of the root certificate authority and the intermediate/chain certificates should all be trusted. This way you can take advantage of the chain of trust, the core principle of SSL certificate hierarchy.
You can also encrypt the connection from SQL Server Management Studio (mainly for testing purposes):
- Click Options in the Connect to Server dialog.
- On the Connection Properties tab, tick the Encrypt connection checkbox.
You can query the sys.dm_exec_connections dynamic management view (DMV) to see if the connections to your SQL Server are encrypted or not. If the value of encrypt_option is "TRUE" then your connection is encrypted.
SELECT session_id, encrypt_option FROM sys.dm_exec_connections
It can cause an issue if you use only the computer name in the connection string. It is better to use the Fully Qualified Domain Name (FQDN) e.g. YourSQLServer.YourCompany.int\YourSQLServerInstance
Pay attention to the following properties of the connection string:
- encrypt
- trustServerCertificate
The value of the encrypt property should be 'true' to enable SSL encryption. If trustServerCertificate=true then it is possible to connect to the SQL Server using a self-signed certificate, but this scenario is recommended only in test environments.
If you would like to use encrypted connections in a clustered environment (including AlwaysOn) then you should have a certificate issued to the fully qualified DNS name of the failover clustered instance (i.e. the AlwaysOn listener) and this certificate should be installed on all of the nodes in the failover cluster. Additionally, you will have to edit the thumbprint of the certificate in the registry because it is set to Null in clustered environment.
The following steps should be performed on all of the nodes in the cluster:
- Navigate to the certificate in the MMC Certificates Snap-in and double click to open the certificate.
- Copy the hex value from the Thumbprint property on the Details tab to Notepad and remove the spaces.
- Start Regedit and copy the hex value to this key: HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\<YourSQLServerInstance>\MSSQLServer\SuperSocketNetLib\Certificate
- You will have to reboot your node, so it is recommended to failover to another node first.
Note: Encryption of the direct communication between AlwaysOn replicas is enabled by default, and therefore additional SSL encryption is not required.
You can configure SSL using the SQL Server Configuration Manager. First, you should run SQL Server Configuration Manager under the SQL Server service account. The only exception is if the service is running as LocalSystem, NetworkService, or LocalService, in this case you can use an administrative account.
- Expand SQL Server Network Configuration and right-click on Protocols for <YourMSSQLServer> , then click Properties.
- On the Certificate tab, select None instead of the certificate that was previously selected, then click OK.
- The SQL Server service will need to be restarted again to take effect.
To undo the SSL setting in client machines:
- Use the MMC Certificates Snap-in on the client computer to install the exported certificate file.
- In the SQL Server Configuration Manager right-click SQL Server Native Client Configuration , and then click Properties.
- On the Flags tab, select No in the ForceEncryption box, then click OK.
After you successfully install the certificate, the certificate does not appear in the ** Certificate** list on the ** Certificate** tab.
**Note: ** The ** Certificate ** tab is in the ** Protocols for <InstanceName> Properties ** dialog box that is opened from SQL Server Configuration Manager.
This issue occurs because you may have installed an invalid certificate. If the certificate is invalid, it will not be listed on the ** Certificate ** tab. To determine whether the certificate that you installed is valid, follow these steps:
- Open the Certificates snap-in. To do this, see step 1 in the "How to Configure the MMC Snap-in" section.
- In the Certificates snap-in, expand ** Personal** , and then expand Certificates.
- In the right pane, locate the certificate that you installed.
- Determine whether the certificate meets the following requirements: - In the right pane, the value in the ** Intended Purpose ** column for this certificate must be Server Authentication. - In the right pane, the value in the **Issued To ** column must be the server name.
- Double-click the certificate, and then determine whether the certificate meets the following requirements: - On the General ** tab, you receive the following message: You have a private key that corresponds to this certificate. - On the ** Details ** tab, the value for the ** Subject ** field must be server name. - The value for the ** Enhanced Key Usage field must be Server Authentication (<number>). - On the **Certification Path ** tab, the server name must appear under Certification path.
If any one of these requirements is not met, the certificate is invalid.
- https://support.microsoft.com/en-us/help/316898/how-to-enable-ssl-encryption-for-an-instance-of-sql-server-by-using-mi
- https://docs.microsoft.com/en-us/sql/database-engine/database-mirroring/transport-security-database-mirroring-always-on-availability?view=sql-server-2017
- https://www.mssqltips.com/sqlservertip/3299/how-to-configure-ssl-encryption-in-sql-server/
- https://www.mssqltips.com/sqlservertip/3408/how-to-troubleshoot-ssl-encryption-issues-in-sql-server/
__________________________________________________________________________________
info@madeiradata.com I www.madeiradata.com I +972-9-7400101