如何检查MySQL连接是否经过SSL加密? [英] How to check whether a MySQL connection is SSL encrypted?
问题描述
我正在使用MySQL官方网站上的MySQL .NET连接器.我正在尝试从C#程序到Mysql数据库建立安全的SSL连接. Mysql服务器允许使用SSL连接.将have_ssl
变量设置为yes
并指定ca-cert
,server-cert
和server-key
.
I'm using MySQL .NET connector from MySQL official site. I'm trying to make a safe SSL connection from my C# program to a Mysql db. Mysql server allows to connect with SSL. have_ssl
variable is set to yes
and ca-cert
, server-cert
and server-key
are specified.
该用户的权限是:
'GRANT USAGE ON *.* TO \'logowanie\'@\'%\' IDENTIFIED BY PASSWORD \'*...\' REQUIRE SSL'
'GRANT SELECT ON `db`.`table1` TO \'logowanie\'@\'%\''
因此,我认为该用户如果没有SSL便无法登录?我说的对吗?
So I assume, that this user cannot login without SSL? Am I right?
我在C#程序中的连接字符串如下所示:
My connection string in C# program looks like that:
"server=127.0.0.1;uid=logowanie;pwd=log1;database=ewidencja;SslMode=Required";
请注意,此连接字符串没有证书文件的任何路径!它仅具有"SSLMode =必需"选项.是否可以在没有其他SSL选项的情况下进行SSL加密连接?
See that this connection string doesn't have any paths to certificate files! It only has "SSLMode=Required" option. Is it possible to make SSL encrypted connection without any other SSL options?
用户可以登录并在table1
上执行一些选择命令.因此,我假设此连接是SSL加密的?
如何检查此连接是否经过SSL加密以确保100%安全?
And the user is able to login and make some select command on table1
. So I assume this connection is SSL encrypted?
How can I check whether this connection is SSL encrypted to be 100% sure?
推荐答案
从 https://stackoverflow.com/a发布我的答案/46609559/492336 :
您可以从MySqlConnection内部执行此SQL语句:SHOW SESSION STATUS LIKE 'Ssl_cipher'
,它将显示连接是否已加密.
You can execute this SQL statement from inside the MySqlConnection: SHOW SESSION STATUS LIKE 'Ssl_cipher'
, and it will show you whether the connection is encrypted.
示例代码:
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)}: {reader.GetString(1)}");
}
这篇关于如何检查MySQL连接是否经过SSL加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!