Configuration on MariaDB
Wireshark capture while connecting to MariaDB


Step 1 : Protect MariaDB/MySQL
Set a strong password for the root user.
Remove access to the user Anonymous.
We allow only the connection to the root user from localhost.
We delete the database 'test' to which all users could access.
Finally, we reload the table of privileges.
Step 2 : Configuration SSL/TLS
Create CA certificate CA

Indeed, we have 2 files:
/etc/mysql/ssl/ca-cert.pem - Certificate file for the certification authority (CA).
/etc/mysql/ssl/ca-key.pem - Key file for the certification authority (CA).
Create the server's SSL/TLS certificate
We have 2 additional files:
/etc/mysql/ssl/server-cert.pem - MariaDB server certificate file.
/etc/mysql/ssl/server-key.pem - File of key of the MariaDB server.
Create the SSL/TLS certificate for the MySQL client
Verification of certificates
Apply SSL/TLS to MariaDB
Modify the MariaDB configuration file and add :

Configure the MariaDB client to use SSL (add in the client configuration file /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf) :

Copy /etc/mysql/ssl/ca-cert.pem, /etc/mysql/ssl/client-cert.pem, and /etc/mysql/ssl/client-key.pem to all clients. Here, we only have one user so it's not useful.
Verification
SSL configuration worked well on MariaDB :


4. Two-Way TLS
Logging in as root, we remove the old privileges of the user foo :

New ones are created, allowing the client to verify the server certificate and the server to verify the client certificate:
Check by logging in as a foo user:

5. Perform a flow capture with Wireshark of a mutual-auth TLS encrypted connection to the database, identify the key exchanges

1 : The first TLS packet is "Client Hello". The client lists the SSL/TLS versions and cipher suites it is able to use (here 31 suites) :

2 : Then a "Server Hello" packet arrives. The server consults the list of SSL/TLS versions and cipher suites and chooses the most recent one it can use. Then the server sends a message to the client containing the SSL/TLS version and the cipher suite it has chosen :

3 : Exchange of keys Once the server and the client have agreed on the SSL/TLS version and the number sequence, the server sends two elements. The first is its SSL/TLS certificate to the client. The client (web browser) validates the server's certificate. Web browsers store a list of Root CAs within them. These root CAs are third parties that web browsers trust. The server's certificate is issued by a Root CA or an Immediate CA. The immediate CA is a CA that the root CA trusts.
On the Wireshark capture, we do not see any Server Key Exchange or Client Key Exchange packets. However the encryption is in place and we receive the Change Cipher Spec packet.
Change Cipher Spec
The Change Cipher Spec message is sent by the client and server to notify the receiving party that the following records will be protected by the cipher specification and keys that were just negotiated.

Appendices
Last updated
Was this helpful?