I think my question is similar to C#: how to check if a MySqlConnection is using SSL or not?, but unfortunately it doesn't have good answers because it is unclear maybe. So here's my take:
I have created a new connection:
var connection = new MySqlConnection("Data Source=example.com;Port=3306;Database=Foo;User Id=root;Password=foo;SSL Mode=Required");
How do I verify it uses SSL, is there something like connection.IsOverSSL
?
Edit:
I tried using SHOW SESSION STATUS LIKE 'Ssl_cipher'
, but this gives me Ssl_cipher
even if SSL Mode=Required
:
The code I use is:
var connection = new MySqlConnection(ConfigurationManager.AppSettings["Test"]);
connection.Open();
var command = new MySqlCommand("SHOW SESSION STATUS LIKE \'Ssl_cipher\'", connection);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString(0));
}
According to https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html, it should give me Ssl_cipher | DHE-RSA-AES128-GCM-SHA256
You can look at the connection string for the word "SSL". This would allow you to know if your IDbConnection is using ssl in this case. For a list of the connection strings that you could use with MySql, please visit ConnectionStrings.com. Let me know if this solves your problem.
I would try looking at the connection string. Here is a solution to demonstrate this.
Turns out I wasn't printing the second column of the query, this now works:
It prints
Ssl_cipher: AES256-SHA
forSSL Mode=Required
, andSsl_cipher:
forSSL Mode=None
. On the other hand, I getSsl_cipher: AES256-SHA
even ifSSL Mode
is missing altogether so maybe it's on by default.