In this blog post, we’ll determine a MySQL connection using SSL… or not.
Since MySQL 5.7.5 the server generates SSL certificates (see auto_generate_certs) by default if compiled with SSL, or uses mysql_ssl_rsa_setup if compiled with YaSSL.
But how can we check to see if our MySQL client connection uses SSL?
When using an interactive client, it’s easy! You have two options:
1. Check the status(s):
|
1 |
mysql> s<br>--------------<br>mysql Ver 14.14 Distrib 5.7.11, for Linux (x86_64) using EditLine wrapper<br><br>Connection id: 7<br>Current database: <br>Current user: root@localhost<br>SSL: Cipher in use is DHE-RSA-AES256-SHA<br>Current pager: stdout<br>Using outfile: ''<br>Using delimiter: ;<br>Server version: 5.7.11-log MySQL Community Server (GPL)<br>Protocol version: 10<br>Connection: Localhost via UNIX socket<br>Server characterset: latin1<br>Db characterset: latin1<br>Client characterset: utf8<br>Conn. characterset: utf8<br>UNIX socket: /var/lib/mysql/mysql.sock<br>Uptime: 36 min 33 sec<br> |
As you can see, for that connection, we are indeed using SSL: SSL: Cipher in use is DHE-RSA-AES256-SHA
2. Use the status variables Ssl_version and Ssl_cipher:
|
1 |
mysql> show status like 'Ssl_version';<br>+---------------+---------+<br>| Variable_name | Value |<br>+---------------+---------+<br>| Ssl_version | TLSv1.1 |<br>+---------------+---------+<br>mysql> show status like 'Ssl_cipher';<br>+---------------+--------------------+<br>| Variable_name | Value |<br>+---------------+--------------------+<br>| Ssl_cipher | DHE-RSA-AES256-SHA |<br>+---------------+--------------------+<br> |
But is there a way to verify this on all the connections? For example, if we have some applications connected to our database server, how do we verify which connections are using SSL and which are not?
Yes, there is a solution: Performance_Schema!
This is how:
|
1 |
mysql> SELECT sbt.variable_value AS tls_version, t2.variable_value AS cipher, <br> processlist_user AS user, processlist_host AS host <br> FROM performance_schema.status_by_thread AS sbt <br> JOIN performance_schema.threads AS t ON t.thread_id = sbt.thread_id <br> JOIN performance_schema.status_by_thread AS t2 ON t2.thread_id = t.thread_id <br> WHERE sbt.variable_name = 'Ssl_version' and t2.variable_name = 'Ssl_cipher' ORDER BY tls_version;<br>+-------------+--------------------+------+-----------+<br>| tls_version | cipher | user | host |<br>+-------------+--------------------+------+-----------+<br>| | | root | localhost |<br>| TLSv1 | DHE-RSA-AES256-SHA | root | localhost |<br>| TLSv1.1 | DHE-RSA-AES256-SHA | root | localhost |<br>+-------------+--------------------+------+-----------+<br> |
That’s it. Isn’t that easy? 😉