MySQL Protocol SSL Encryption Guide

Updated at:

This topic describes how to use SSL/TLS encrypted links on port 33060 of the MySQL protocol for the Lindorm Wide Table Engine.

Version requirements

  • Wide Table Engine >= 2.8.6.14 and SQL version >= 2.9.7.16

Scope

This topic describes how to use SSL/TLS encrypted links on port 33060 of the MySQL protocol for the Lindorm Wide Table Engine. The following scenarios are covered:

  • The client requires only link encryption: use sslMode=REQUIRED.

  • The client requires verification of the server certificate chain against a CA certificate: use sslMode=VERIFY_CA and configure the CA certificate downloaded from the console. When a JDBC client requires strict CA-based verification, import the CA certificate into a truststore before connecting.

Enable the SSL encryption service in the console

Prerequisites

The Lindorm Wide Table Engine is activated.

Procedure

  1. Log on to the Lindorm console.

  2. In the upper-left corner of the page, select the region where the instance is deployed.

  3. On the Instances page, click the ID of the target instance or click View Instance Details in the Actions column for the instance.

  4. In the left-side navigation pane of the instance details page, click Wide Table Engine > Data Security.

  5. In the Data Link SSL section, enable the service in the Current Status: area.

  6. Wait for the SSL encryption service to be enabled. When the page displays the following information, the SSL encryption service is enabled:

    • Current Status:: Enabled

    • SSL Certificate Validity Period:: The certificate expiration time displayed on the page, for example, 2036-06-13 18:02:25

    • SSL Certificate Validity:: Valid

    • A Download CA Certificate button is provided.

Note

If the client needs to use VERIFY_CA for strict verification, click Download CA Certificate to obtain the CA certificate file.

Client connection modes

Encryption link only

If you only need to secure the link between the client and the server with encryption, use sslMode=REQUIRED. This mode enables TLS encryption without requiring the client to configure an additional CA root certificate.

Strict certificate chain verification

If the client needs to confirm that the server certificate is issued by a trusted CA, use sslMode=VERIFY_CA and specify the CA certificate downloaded from the console with --ssl-ca.

mysql --ssl-mode=VERIFY_CA \
  --ssl-ca=/path/to/Lindorm-CA.crt \
  -h <host> \
  -P 33060 \
  -u <user> \
  -p \
  -D <database> \
  --get-server-public-key

Example query:

mysql --ssl-mode=VERIFY_CA \
  --ssl-ca=/path/to/Lindorm-CA.crt \
  -h <host> -P 33060 -u <user> -p -D <database> \
  --get-server-public-key \
  -e "SELECT 1 AS ok"
Note

Replace /path/to/Lindorm-CA.crt in the example with the actual absolute path of the Lindorm-CA.crt file in your local environment.

If ok = 1 is returned, the client has completed the SSL handshake and query based on the CA certificate.

VERIFY_IDENTITY mode description

VERIFY_IDENTITY builds on VERIFY_CA by additionally verifying that the connection host name matches the SAN/CN declared in the server certificate. Therefore, to use this mode, the host that the client connects to must exactly match a domain name or IP address declared in the certificate.

JDBC strict CA verification

The common practice for MySQL Connector/J is to first import the CA certificate downloaded from the console into a Java truststore, and then configure the truststore in the JDBC URL.

Generate a truststore

keytool -importcert \
  -alias lindorm-ca \
  -file /path/to/Lindorm-CA.crt \
  -keystore /path/to/lindorm-ca.p12 \
  -storetype PKCS12 \
  -storepass changeit \
  -noprompt
Note
  • Replace /path/to/Lindorm-CA.crt in the example with the actual absolute path of the certificate file in your local environment.

  • Replace /path/to/lindorm-ca.p12 in the example with the actual absolute path where you plan to save the file in your local environment.

JDBC URL

String url = "jdbc:mysql://<host>:33060/<database>"
    + "?sslMode=VERIFY_CA"
    + "&allowPublicKeyRetrieval=true"
    + "&trustCertificateKeyStoreUrl=file:/path/to/lindorm-ca.p12"
    + "&trustCertificateKeyStorePassword=changeit"
    + "&trustCertificateKeyStoreType=PKCS12";
Connection connection = DriverManager.getConnection(url, user, password);

Note: trustCertificateKeyStoreUrl takes the file path of the truststore, not the path of the server certificate. Import the CA certificate downloaded from the console into a PKCS12 or JKS truststore before passing it to JDBC.

FAQs

  • Q: Does SSL encryption take effect as soon as it is enabled in the console?

    A: Whether SSL encryption is used is negotiated between the server and the client. You need to configure sslMode on the client for the negotiation.

  • Q: Does SSL encryption cause performance overhead?

    A: Enabling SSL encryption causes performance overhead. For performance-sensitive scenarios, we recommend that you disable SSL encryption by setting sslMode=DISABLED in the connection string.

  • Q: Does specifying only the certificate path automatically enable SSL?

    A: No. The MySQL protocol SSL link is enabled only after the corresponding SSL switch is turned on the server side.

  • Q: What is the difference between REQUIRED and VERIFY_CA?

    A: REQUIRED only requires that a TLS encrypted link be established. It does not require the client to verify the server certificate chain.

    VERIFY_CA not only establishes a TLS encrypted link but also requires the client to trust the CA root certificate that issues the server certificate.

  • Q: Which certificate should be specified for --ssl-ca?

    A: Specify the CA root certificate that you download by clicking Download CA Certificate in the console. Do not use the server certificate server.cert directly as --ssl-ca.

  • Q: Can JDBC use the crt file directly?

    A: Support for PEM certificate parameters varies across MySQL Connector/J versions. The common practice is to import the CA certificate downloaded from the console into a PKCS12 or JKS truststore, and then pass it to JDBC through trustCertificateKeyStoreUrl, trustCertificateKeyStorePassword, and trustCertificateKeyStoreType.