【发布时间】:2017-10-06 09:10:05
【问题描述】:
我认为我的问题类似于C#: how to check if a MySqlConnection is using SSL or not?,但不幸的是它没有很好的答案,因为可能不清楚。所以这是我的看法:
我创建了一个新连接:
var connection = new MySqlConnection("Data Source=example.com;Port=3306;Database=Foo;User Id=root;Password=foo;SSL Mode=Required");
如何验证它是否使用 SSL,是否有类似 connection.IsOverSSL 的内容?
编辑:
我尝试使用SHOW SESSION STATUS LIKE 'Ssl_cipher',但这给了我Ssl_cipher,即使SSL Mode=Required:
我使用的代码是:
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));
}
根据https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html,应该给我Ssl_cipher | DHE-RSA-AES128-GCM-SHA256
【问题讨论】:
-
我认为没有提供特定属性来检查
MySqlConnection是否使用 SSL。最接近的方法是使用这些类似问题中给出的外部工具捕获网络流量:stackoverflow.com/questions/42703027/… & stackoverflow.com/questions/14389921/…。