SQL Server 2012 ForceEncryption without SSL certificate? - sql-server

Using information from some consultants about 2 years ago we set up a SQL Server 2012 box to always have an encrypted connection (at least we thought so). A week ago the SSL certificate expired and everything continues to work fine which is puzzling.
We forced encryption by doing the following:
Obtain an SSL certificate and install it on the SQL Server via MMC. Explicit instructions for this step are here.
Open SQL Server Configuration Manger and expand the SQL Server Network Configuration node in the left pane.
Right click Protocols for MSSQLServer and choose properties.
Go to Certificate tab and choose the installed SSL cert from the drop down.
Go to the Flags tab and set force encryption to Yes.
Now, since the SSL cert expired, there is no longer any cert selected in the drop down when I visit step 3 above. However, I put WireShark on the DB server and use SSMS to request some data. The TDS (Tabular Data Stream) packets are still encrypted? When I put WireShark on a different DB Server I set ForceEncryption to NO, those TDS packets are not encrypted as expected.
So my questions are:
How are the TDS packets still encrypted if the cert is expired?
Even when the cert was valid, why didn't I have to select Options > Encrypt Connection to connect to my encrypted DB server? I thought setting ForceEncryption=Yes required ALL client connections to specify Encrypt in their connection string (or the SSMS checkbox)?
If Web APIs are the only method of accessing my DB, and they do so over SSL, is it even necessary to encrypt the SQL Protocol?

1)How are the TDS packets still encrypted if the cert is expired?
you don't need a valid certificate in order to encrypt, you can still encrypt using an expired certificate.
2)Even when the cert was valid, why didn't I have to select Options > Encrypt Connection to connect to my encrypted DB server? I thought setting ForceEncryption=Yes required ALL client connections to specify Encrypt in their connection string (or the SSMS checkbox)?
Do not enable the Force Protocol Encryption option on both the client and the server,
if you enabled force encryption on SQL server you don't need to do it on any client-side
3)If Web APIs are the only method of accessing my DB, and they do so over SSL, is it even necessary to encrypt the SQL Protocol?
To enable SSL you need the certificate to be installed on SQL server so in order to access the DBusing SSL you are doing the same job.
Thank you

Related

Client side changes to be done for configuring SQL Server connection encryption in-transit

SQL Server instance has force encryption flag enabled and SQL Server has valid certificate imported into SQL instance in SQL configuration manager,
I have seen in the documentation that if the client application doesn't support encryption then the connection will fail if the force encryption flag is enabled. What does this mean? Should the client application string have encrypt=true if the force encryption flag is enabled?
If the server has Force Network Encryption enabled, then it does not matter whether the connection string has encrypt=true set or not. The server will tell the client that it must use encryption to establish the connection.
If the client does not support encryption and the server requires it, no connection will be established.
Setting encrypt=true in the connection string is used when the server has a certificate set up which allows encryption to be used, but does not require it.

Connect to SQL Server using a pem file, username and password

I have a SQL Server (which is a Google cloud SQL Server). The connection with it needs to be ssl encrypted and authenticated with a username and password.
I can get the .pem file for the ssl certificate :
I also have the username, password, and ip of the server. In the SqlClient connection string syntax I was able to find the flags defining the username (uid), password (pwd) and ip (Data Source). But I can't find how to place the .pem file.
Does the .pem file not belong in the connection string? If so, how do I use it ?
Thanks,
nimrod
Edit: I tried opening the connection with trustServerCertificate=true, but still got error: 40 - Could not open a connection to SQL Server.
Solution:
The SSL wasn't the issue. Adding the TrustServerCertificate and Encrypt flags should have allowed SSL. With these flags the client just accepts any certificate from the sever, and proceeds with the SSL handshake.
My issue was that I didn't add the client network to the trusted networks list for the cloud SQL. This is apparently a requirement even though the cloud SQL is set to us a public IP. I added the 0.0.0.0/0 network as trusted, and the connection worked.
Does the .pem file not belong in the connection string?
No.
The client demands protocol encryption using the Encrypt connection string option. If the server's certificate is not trusted by the client, you either need to install the certificate on the client or opt to TrustServerCertificate in the connection string.

SSMS - connection security

This may well be a stupid question, but regardless...
If I use Sql Management Studio to connect to a remote database using a SQL user/password (outside of our network) - how secure is this connection? Is data encrypted when it is transferred?
This is a great question.
By default, there is no encryption between you and the server. However, you can configure the sql server to accept encrypted connections.
If you've ever set up IIS to use https with a local certificate, the process is very similar. Create a certificate on the server, export the cert to your machine and install. Click connect, select your server, click options and check encrypt connection.
Read more here:http://msdn.microsoft.com/en-us/library/ms191192.aspx

Secure communication between linked SQL Servers

Is the data transferred between two SQL Servers protected (encrypted) by default? If not, is there a way to accomplish this?
I have two SQL Server 2005 databases running on separate servers, separate machines, separate networks. How can I ensure that data transmitted from one server to another is secure? I have tried researching the subject but am unable to find anything.
Many thanks,
Sebastian
Encrypt Via SQL Server
Provision a certificate on both machines.
Configure any non-server clients to trust the certificate's root signing authority. See How to enable SSL encryption for an instance of SQL Server by using Microsoft Management Console.
Configure the server(s) to force all incoming connections to use SSL so that any clients that do not support this will fail to connect. In SQL Server Configuration Manager, set the ForceEncryption parameter to "Yes" in the Protocols section.
OR, instead of the prior step, you can add Encrypted=yes to the provider/connection string for the connection/linked server. If, for example, you register the linked server using sp_addlinkedserver it might look something like this:
EXEC master.dbo.sp_addlinkedserver
#server = N'LinkedServerName',
#srvproduct = N'',
#provider = N'SQLNCLI',
#datasrc = N'Server\InstanceName',
#provstr = N'Encrypt=yes;',
#catalog = 'DatabaseName'
;
I do NOT recommend that you use the option TrustServerCertificate=True because this will disable the client from validating the identity of the server it is connected to.
Also, if using ODBC, the encryption property can be specified in a DSN.
Note that while servers don't require certificates to be installed since you can configure them to automatically create and sign their own certificates, it is best to manually install them, because you can run into problems with the self-created certificates since they change on each restart.
The best security is when the client specifically requests channel encryption, because this not only encrypts the data but the client also attempts to validate the identity of the server via the certificate, helping to mitigate a man-in-the-middle attack.
Encrypt Via The Network
Another option is to set up a secure tunnel (such as a VPN) between the two servers' networks, and ensure that the routing for traffic between them is entirely through said tunnel. This is 100% secure as well, as long as you are sure the traffic goes over the right route.
I realize this is a very old thread, but there's something in here that I just found out is potentially misleading.
"3. Configure the server(s) to force all incoming connections to use SSL so that any clients that do not support this will fail to connect. In SQL Server Configuration Manager, set the ForceEncryption parameter to "Yes" in the Protocols section."
The ForceEncryption parameter on the SQL server side does not fail clients that do not have Encrypt = True set on the client end. Importantly, you can create insecure connections to the SQL server instance even when ForceEncryption is set to "Yes" on the server.
You can validate this by setting ForceEncryption = Yes on the server side, then by connecting to that SQL server using SSMS and choosing not to encrypt the connection on the client side.
You can check the encryption state of the client connection by visiting the Properties of the server in Object Explorer, then clicking on View Connection Properties (right click on the servername in Object Explorer, then click Properties).
You can then see that the value for the Encypted property is set to No.
You can then do a select or other SQL statement to confirm that you are able to access data from the server side, without encryption. I believe that in order to have full end-to-end encryption, you must set encryption on both the client and the server side.
Here is a Microsoft link explaining this issue.
And a screenshot in case that link doesn't work.
And another Microsoft link saying the same thing.
And another screenshot in case that link doesn't work.

How to validate SQL Server traffic is encrypted?

I need to prove that the encryption settings we have in our app's connection string are working.
What would be the simplest way to validate that traffic from our web site to the SQL Server is in fact encrypted?
You could use something like Wireshark to view the packets at they're transmitted over the network
You check the encrypt_option column of the sys.dm_exec_connections DMV. This way you can no only prove that is encrypted, but you can also validate in your application at start up time. To enforce the encryption you follow the methods described in this MSDN How To: Enable Encrypted Connections to the Database Engine. If either the client or the server forces encryption and a certificate is provided and the client accepts the server certificate, the connection will be encrypted. To validate that the traffic is encrypted you can use the built-in netmon.exe tool (must be installed from ad/remove system components), download the improved Microsoft Network Monitor 3.2 or other third party tools.
As an alternative the deployment site can enforce IPSec encryption.
I would set the Force Protocol Encryption to true and Trust Server Certificate to true in the db connection string. The server should fail to establish a connection if it cannot provide you with an encrypted connection as requested. There is an article that covers encryption with sql server 2005 and later.
Simple test is to try a connection with and without encryption and fail when it hands out the undesired type of connection. then its up to the DBA, IT or you to configure the server to match your requirements.
There is another much underrated tool from Microsoft itself: 'Microsoft Network Monitor'. Basically this is very similar to wireshark with the exception that some specific MS protocols have better parser and visualisation support than wireshark itself and obviously it would only run under windows ;-).
The tool is quite old and looks abandoned (havn't seen a newer release so far) but still does an good job and the grammar for defining new protocols is quite neat/interesting - so this still possess a lot of power for the future.
Analysis Example - Recording is filtered for TDS - so the other packets are discared mostly:
This is also true for sql server connections. The MNM can even visualize the resultsets going over the wire - quite neat. Nonetheless wireshark as mentioned above would be sufficient to validate encryption and applied certificates on the wire itself. Means it can understand the TDS-Protocoll fully.
Handling TLS
Also with an extension (so called experts) 'NmDecrypt' and the right certificates (including private keys) - it is possible to decrypt protocolls - quite nice for TDS which uses TLS INSIDE of TDS - no wonder - no one has really implemented that yet as a fully supported protocoll for wireshark ;)
Links for the tools:
Microsoft Network Monitor: http://www.microsoft.com/en-us/download/details.aspx?id=4865
NMDecrypt: http://nmdecrypt.codeplex.com/releases/view/85581
To guarantee that encryption is being used, you need to enable the force encryption option on the server.
Client side encryption is not mandatory. Server side is mandatory.
When the SQL Server service starts, it will stop if it can not read the certificate or there are other obstacles. It will not accept unencrypted connections.
To answer, I used a packet sniffer the first I used encryption to check, then I just relied on the fact that server side encryption is mandatory and SQL won't start.
For SQL 2000, KB 276553
Keep in mind that there is a current
SQL Server limitation if you enable
encryption on the server. Encryption
will be for all incoming connections.
If you enable encryption on the client
computer, all outgoing connections
from that client try to make an
encrypted connection to any SQL
Server.
A KB search for SQL 2005
Late edit:
Use an older version of the MS JDBC client: it can't handle server side encryption...

Resources