To ensure secure communication, message production and consumption must support Transport Layer Security (TLS) encryption. TLS is a widely recognized method for securing communications, which is critical for financial systems. SOFAMQ provides easy-to-use TLS encryption capabilities. This topic describes how to use TLS to encrypt messages.
The certificate authority (CA) for the NameServer, broker, and client certificates must be the same.
Configure the NameServer
Prepare the environment.
Confirm that OpenSSL is installed on the NameServer. If it is not installed, you must install it. You can run the
openssl versioncommand to check the installation.Generate certificates.
The following steps describe how to generate certificates using OpenSSL:
NoteEnter a password when prompted by the following commands. This example uses 123456 for all passwords.
This topic describes two methods for installing a CA certificate:
Request a certificate from a dedicated CA. This is the recommended method.
Generate a self-signed root certificate.
You can name the file
ca.crt. The steps are as follows:Generate a CA key.
openssl genrsa -des3 -out ca.key 2048Generate a certificate signing request (CSR).
openssl req -new -out ca.csr -key ca.key -keyform PEM -subj "/C=CN/ST=Province/L=City/O=Organization/OU=Department/CN=domain_name_or_ip"Generate the self-signed root certificate.
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt -CAcreateserial
Generate a public-private key pair for the application. The following example shows the command.
openssl genrsa -des3 -out server.pem 2048You can name the file
server.pem.Generate a CSR. The following example shows the command.
openssl req -new -key server.pem -out server.csr -subj "/C=CN/ST=Province/L=City/O=Organization/OU=Department/CN=domain_name_or_ip"You can name the file
server.csr.Use the CA to sign and generate the application certificate. The following example shows the command.
openssl x509 -req -in server.csr -out server.crt -signkey server.pem -CA ca.crt -CAkey ca.key -days 365 -CAcreateserialYou can name the file
server.crt.
Configure the
tls.propertiesconfiguration file. The parameters are described as follows:Configuration item
Description
Example value
Recommended value
tls.test.mode.enableSpecifies whether to use test mode.
false
false
tls.server.need.client.authSpecifies whether the server-side requests a client certificate.
optional
optional
tls.server.keyPathThe path of the server-side private key file.
/home/admin/store/ca/server.pem-
tls.server.keyPasswordThe access password for the server-side private key file.
123456
-
tls.server.certPathThe path of the server-side application certificate.
/home/admin/store/ca/server.crt-
tls.server.authClientSpecifies whether the server-side authenticates the client.
true
true
tls.server.trustCertPathThe path of the server-side authentication certificate.
/home/admin/store/ca/ca.crt-
ImportantPlace the certificates in the
/home/admin/storefolder. This folder is not typically cleared.Set environment variables. The parameters are described as follows:
Configuration item
Description
Default value
tls.server.modeThe enumeration values are as follows:
Disable: Encryption is not supported.
Permissive: Compatible mode.
Enforcing: Forced encryption.
Permissive
tls.config.fileThe path of the tls.properties file.
/etc/rocketmq/tls.propertiesNoteIf you use Yunyou for deployment, the path for the tls.properties file is fixed to
/home/admin/store/ca/tls.properties.Restart the NameServer.
Configure the broker
Prepare the environment.
Confirm that OpenSSL is installed on the broker. If it is not installed, you must install it. You can run the
openssl versioncommand to check the installation.Generate certificates.
The following steps describe how to generate certificates using OpenSSL:
NoteEnter a password when prompted by the following commands. This example uses 123456 for all passwords.
You can install the CA certificate using one of the following two methods:
Request a certificate from a dedicated CA. This is the recommended method.
Generate a self-signed root certificate.
You can name the file
ca.crt. For information about the command to generate a root certificate, see NameServer self-signed root certificate.
Generate a server-side application public-private key pair. The following example shows the command.
openssl genrsa -des3 -out server.pem 2048You can name the file
server.pem.Generate a server-side CSR. The following example shows the command.
openssl req -new -key server.pem -out server.csr -subj "/C=CN/ST=Province/L=City/O=Organization/OU=Department/CN=domain_name_or_ip"You can name the file
server.csr.Use the CA to sign and generate the server-side application certificate. The following example shows the command.
openssl x509 -req -in server.csr -out server.crt -signkey server.pem -CA ca.crt -CAkey ca.key -days 365 -CAcreateserialYou can name the file
server.crt.Generate a client application public-private key pair. The following example shows the command.
openssl genrsa -des3 -out client.pem 2048You can name the file
client.pem.Generate a client CSR. The following example shows the command.
openssl req -new -key client.pem -out client.csr -subj "/C=CN/ST=Province/L=City/O=Organization/OU=Department/CN=domain_name_or_ip"You can name the file
client.csr.Use the CA to sign and generate the client application certificate. The following example shows the command.
openssl x509 -req -in client.csr -out client.crt -signkey client.pem -CA ca.crt -CAkey ca.key -days 365 -CAcreateserialYou can name the file
client.crt.
Configure the
tls.propertiesconfiguration file. The parameters are described as follows:Configuration item
Description
Example value
Recommended value
tls.test.mode.enableSpecifies whether to use test mode.
false
false
tls.server.need.client.authSpecifies whether the server-side requests a client certificate.
optional
optional
tls.server.keyPathThe path of the server-side private key file.
/home/admin/store/ca/server.pem-
tls.server.keyPasswordThe access password for the server-side private key file.
123456
-
tls.server.certPathThe path of the server-side application certificate.
/home/admin/store/ca/server.crt-
tls.server.authClientSpecifies whether the server-side authenticates the client.
true
true
tls.server.trustCertPathThe path of the server-side authentication certificate.
/home/admin/store/ca/ca.crt-
tls.client.keyPathThe path of the client private key file.
/home/admin/store/ca/client.pem-
tls.client.keyPasswordThe access password for the client private key file.
Abc123456
-
tls.client.certPathThe path of the client application certificate.
/home/admin/store/ca/client.crt-
tls.client.authServerSpecifies whether the client authenticates the server-side.
true
true
tls.client.trustCertPathThe path of the client authentication certificate.
/home/admin/store/ca/ca.crt-
ImportantPlace the certificates in the
/home/admin/storefolder. This folder is not typically cleared.Set environment variables. The parameters are described as follows:
Configuration item
Description
Default value
tls.server.modeThe enumeration values are as follows:
Disable: Encryption is not supported.
Permissive: Compatible mode.
Enforcing: Forced encryption.
Permissive
tls.config.fileThe path of the tls.properties file.
/etc/rocketmq/tls.propertiesNoteIf you use Yunyou for deployment, the path for the tls.properties file is fixed to
/home/admin/store/ca/tls.properties.Restart the broker.
Configure the client
Prepare the environment.
On the client, check the version of the sofamq-client JAR package to confirm that it is 3.1.6.1 or later.
Generate certificates.
The following steps describe how to generate certificates using OpenSSL:
NoteEnter a password when prompted by the following commands. This example uses 123456 for all passwords.
This topic describes two methods for installing the CA certificate:
Request a certificate from a dedicated CA. This is the recommended method.
Generate a self-signed root certificate.
You can name the file
ca.crt. For information about the command to generate a root certificate, see NameServer self-signed root certificate.
Generate an application public-private key pair. The following example shows the command.
openssl genrsa -des3 -out client.pem 2048You can name the file
client.pem.Generate a CSR. The following example shows the command.
openssl req -new -key client.pem -out client.csr -subj "/C=CN/ST=Province/L=City/O=Organization/OU=Department/CN=domain_name_or_ip"You can name the file
client.csr.Use the CA to sign and generate the application certificate. The following example shows the command.
openssl x509 -req -in client.csr -out client.crt -signkey client.pem -CA ca.crt -CAkey ca.key -days 365 -CAcreateserialYou can name the file
client.crt.
Configure the
tls.propertiesconfiguration file. The parameters are described as follows:Configuration item
Description
Example value
Recommended value
tls.test.mode.enableSpecifies whether to use test mode.
false
false
tls.client.keyPathThe path of the client private key file.
/home/admin/store/ca/client.pem-
tls.client.keyPasswordThe access password for the client private key file.
123456
-
tls.client.certPathThe path of the client application certificate.
/home/admin/store/ca/client.crt-
tls.client.authServerSpecifies whether the client authenticates the server-side.
true
true
tls.client.trustCertPathThe path of the client authentication certificate.
/home/admin/store/ca/ca.crt-
Set environment variables. The parameters are described as follows:
Configuration item
Description
Default value
tls.config.fileThe path of the tls.properties file.
/etc/rocketmq/tls.propertiestls.enableSpecifies whether to enable encryption on the client.
false
Restart the client.
Before you enable TLS on the client, confirm that TLS is enabled on the broker and NameServer.
Specify whether to use encryption when you create a producer or consumer instance. This step is optional.
The
tls.enableenvironment variable specifies the default encryption setting. However, the API setting has a higher priority.The following code provides an API example:
Properties properties = new Properties(); properties.setProperty(PropertyKeyConst.GROUP_ID, "GID_LFQ"); properties.setProperty(PropertyKeyConst.USE_TLS, "true"); // Enable encryption Producer producer = AccessPoint.getAccessPoint().createProducer(properties); producer.start();