Overview
Message Queue for MQTT supports Chinese commercial cryptographic algorithms (SM2, SM3, and SM4) and complies with the GB/T 38636-2020 Transport Layer Cryptography Protocol (TLCP) for dual-certificate SM communication and RFC 8998 for single-certificate SM mode with TLS 1.3. To enable the SM feature, upload SM certificates through the custom certificate feature.
Prerequisites
Install the Tongsuo SM implementation library.
Notes
-
To use the SM feature, submit a ticket to request activation.
-
The SM feature is supported only for Platinum Edition and Professional Edition instances of Message Queue for MQTT.
-
The SM feature is available in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Shenzhen), China (Ulanqab), China (Zhangjiakou), China (Guangzhou), Singapore, and Germany (Frankfurt).
Procedure
-
The SM feature follows the same mutual authentication process as custom X.509 certificates, but uses different commands and algorithms to generate certificates. For detailed instructions, see the certificate usage guide in the official Tongsuo documentation.
-
Generate certificates.
-
This example assumes that Tongsuo is installed at
/home/admin/tongsuo:
$ll /home/admin/tongsuo total 16 drwxrwxr-x 2 admin admin 4096 Dec 16 14:28 bin drwxrwxr-x 3 admin admin 4096 Dec 16 14:28 include drwxrwxr-x 5 admin admin 4096 Dec 16 14:28 lib64 drwxrwxr-x 5 admin admin 4096 Dec 16 14:28 ssl-
For the certificate creation script and configurations, see
mkcert.sh,ca.conf, andsubca.confin the Tongsuo official documentation for certificates. Inmkcert.sh, update the Tongsuo installation directory and set the following environment variables before you run the script:
export LD_LIBRARY_PATH=/home/admin/tongsuo/lib64:$LD_LIBRARY_PATH export PATH=/home/admin/tongsuo/bin:$PATH-
Running the script generates the following certificates:
$ll /home/admin/sm2-tlcp total 104 -rw-rw-r-- 1 admin admin 3328 Jan 16 10:36 ca.cnf -rw-rw-r-- 1 admin admin 709 Jan 16 10:45 ca.crt -rw-rw-r-- 1 admin admin 513 Jan 16 10:45 ca.csr -rw------- 1 admin admin 241 Jan 16 10:45 ca.key -rw-rw-r-- 1 admin admin 1422 Jan 16 10:45 chain-ca.crt -rw-rw-r-- 1 admin admin 1409 Jan 16 13:55 client_enc.crt -rw-rw-r-- 1 admin admin 513 Jan 16 10:45 client_enc.csr -rw------- 1 admin admin 241 Jan 16 10:45 client_enc.key -rw-rw-r-- 1 admin admin 1413 Jan 16 13:55 client_sign.crt -rw-rw-r-- 1 admin admin 517 Jan 16 10:45 client_sign.csr -rw------- 1 admin admin 241 Jan 16 10:45 client_sign.key drwxrwxr-x 2 admin admin 4096 Jan 16 10:45 crl drwxrwxr-x 2 admin admin 4096 Jan 16 10:45 db -rw-rw-r-- 1 admin admin 2393 Jan 16 10:45 mkcert.sh drwxrwxr-x 2 admin admin 4096 Jan 16 10:45 newcerts drwxrwxr-x 2 admin admin 4096 Jan 16 10:45 private -rw-rw-r-- 1 admin admin 700 Jan 16 10:45 server_enc.crt -rw-rw-r-- 1 admin admin 513 Jan 16 10:45 server_enc.csr -rw------- 1 admin admin 241 Jan 16 10:45 server_enc.key -rw-rw-r-- 1 admin admin 700 Jan 16 10:45 server_sign.crt -rw-rw-r-- 1 admin admin 517 Jan 16 10:45 server_sign.csr -rw------- 1 admin admin 241 Jan 16 10:45 server_sign.key -rw-rw-r-- 1 admin admin 4047 Jan 16 10:37 subca.cnf -rw-rw-r-- 1 admin admin 713 Jan 16 10:45 subca.crt -rw-rw-r-- 1 admin admin 509 Jan 16 10:45 subca.csr -rw------- 1 admin admin 241 Jan 16 10:45 subca.key
-
-
Upload the issued server-side signing and encryption dual certificates to the Alibaba Cloud Certificate Management Service console.
-
In the left-side navigation pane, choose Certificate Management > SSL Certificate Management V2.0. On the Uploaded Certificates tab, click Upload Certificate.
-
For Certificate Algorithm, select SM2 Algorithm.
-
Enter a custom Certificate Name.
-
For Certificate File, upload the
server_sign.crtfile. -
For Certificate Key, upload the
server_sign.keyfile. -
For Encryption Certificate, upload the
server_enc.crtfile. -
For Encryption Private Key, upload the
server_enc.keyfile.
-
-
Upload the CA certificate (
ca.crt) in the Message Queue for MQTT console.-
In the left-side navigation pane, choose Certificate Management > CA Certificate. Click Register Certificate.
-
Upload the Verification Certificate.
-
Upload the CA Certificate.
-
-
For client certificate configuration, see the code demo. Key settings:
MQTTAsync_SSLOptions ssl =MQTTAsync_SSLOptions_initializer; // Specify the CA certificate and the client's signing and encryption certificates and keys. ssl.trustStore = "/home/admin/sm2-tlcp/chain-ca.crt"; ssl.enable_ntls = 1; ssl.sign_cert_file = "/home/admin/sm2-tlcp/client_sign.crt"; ssl.sign_key_file = "/home/admin/sm2-tlcp/client_sign.key"; ssl.enc_cert_file = "/home/admin/sm2-tlcp/client_enc.crt"; ssl.enc_key_file = "/home/admin/sm2-tlcp/client_enc.key";