Skip to content

Commit 2504f8f

Browse files
zmstoneRed-Asuka
authored andcommitted
Add example to enable mTlS for ssl listener in EMQX v5
1 parent 8fb49a0 commit 2504f8f

File tree

2 files changed

+72
-45
lines changed

2 files changed

+72
-45
lines changed

en/202007/enable-two-way-ssl-for-emqx.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
As a security protocol based on modern cryptographic public key algorithms, TLS/SSL can ensure the security of transmission in the computer communication network. EMQX has built-in support for TLS/SSL including one-way/two-ways authentication, the X.509 certificate, load balance SSL and many other security certifications. You can enable SSL/TLS for all protocols supported by EMQX, and can also configure HTTP API provided by EMQX to use TLS.
1+
As a security protocol based on modern cryptographic public key algorithms, TLS/SSL can ensure the security of transmission in the computer communication network. EMQX has built-in support for TLS/SSL including one-way/two-ways (mutual TLS, or mTLS) authentication, the X.509 certificate, load balance SSL and many other security certifications. You can enable SSL/TLS for all protocols supported by EMQX, and can also configure HTTP API provided by EMQX to use TLS.
22

33
In the previous article, we've introduced how to [enable SSL/TLS one-way security connection for the EMQX](https://www.emqx.com/en/blog/emqx-server-ssl-tls-secure-connection-configuration-guide). This article will introduce how to enable SSL/TLS two-way security connection for [MQTT](https://www.emqx.com/en/mqtt-guide) in EMQX.
44

@@ -22,7 +22,7 @@ The following picture describes the process of the TLS/SSL handshake protocol. F
2222

2323

2424

25-
## Why do we need SSL/TLS two-way certification
25+
## Why do we need SSL/TLS two-way (mTLS) certification
2626

2727
The two-way certification is that a certificate is required for service and client during the connection authentication. Both parties need to perform authentication for ensuring that both sides involved in communication are trusted. Both parties share their public certificates, and then perform verification and confirmation based on the certificate. For some application scenarios that required high security, we need to enable two-way SSL/TLS authentication.
2828

@@ -122,12 +122,35 @@ openssl x509 -req -days 3650 -in client.csr -CA ca.pem -CAkey ca.key -CAcreatese
122122
After preparing the server and client certificate, we can enable TLS/SSL two-way authentication in the EMQX.
123123

124124

125-
126125
## Enable and verify SSL/TLS two-way connection
127126

128-
**In the EMQX, the default listening port of `mqtt:ssl` is 8883.**
127+
### EMQX v5 configuration
129128

130-
### EMQX configuration
129+
```shell
130+
listeners.ssl.default {
131+
bind = "0.0.0.0:8883"
132+
ssl_options {
133+
# PEM file containing the trusted CA (certificate authority) certificates that the listener uses to verify the authenticity of the client certificates.
134+
# For one-way authentication, the file content can be empty.
135+
cacertfile = "etc/certs/ca.pem"
136+
# PEM file containing the SSL/TLS certificate chain for the listener.
137+
# If the certificate is not directly issued by a root CA, the intermediate CA certificates should be appended after the listener certificate to form a chain.
138+
certfile = "etc/certs/emqx.pem"
139+
# PEM file containing the private key corresponding to the SSL/TLS certificate.
140+
keyfile = "etc/certs/emqx.key"
141+
# Set `verify_peer` to verify the authenticity of the client certificates. Must be set to 'verify_peer' for two-way authentication (mTLS).
142+
# Set 'verify_none' to allow any client to connect, regardless of the client certificate.
143+
verify = verify_peer
144+
# If set to `true`, the handshake fails if the client does not have a certificate to send. Must be set to `true` for two-way authentication (mTLS).
145+
# If set to `false`, it fails only if the client sends an invalid certificate (an empty certificate is considered valid). i.e. one-way authentication.
146+
fail_if_no_peer_cert = true
147+
}
148+
}
149+
```
150+
151+
### EMQX v4 configuration
152+
153+
**In the EMQX, the default listening port of `mqtt:ssl` is 8883.**
131154

132155
Copy the file `emqx.pem`, `emqx.key` and `ca.pem` generated by OpenSSL tool into the directory `etc/certs/` of EMQX, and refer the following configuration to modify `emqx.conf`:
133156

@@ -136,32 +159,23 @@ Copy the file `emqx.pem`, `emqx.key` and `ca.pem` generated by OpenSSL tool into
136159
## Value: IP:Port | Port
137160
listener.ssl.external = 8883
138161

139-
## Path to the file containing the user's private PEM-encoded key.
140-
## Value: File
162+
# PEM file containing the private key corresponding to the SSL/TLS certificate.
141163
listener.ssl.external.keyfile = etc/certs/emqx.key
142164

143-
## NOTE: If emqx.pem is a certificate chain, please make sure the first certificate is the certificate for the server, but not a CA certificate.
144-
## Path to a file containing the user certificate.
145-
## Value: File
165+
# PEM file containing the SSL/TLS certificate chain for the listener.
166+
# If the certificate is not directly issued by a root CA, the intermediate CA certificates should be appended after the listener certificate to form a chain.
146167
listener.ssl.external.certfile = etc/certs/emqx.pem
147168

148-
## Note: ca.pem is to hold the server's intermediate and root CA certificates. Other trusted CAs can be appended for client certificate validation.
149-
## Path to the file containing PEM-encoded CA certificates. The CA certificates
150-
## Value: File
169+
# PEM file containing the trusted CA (certificate authority) certificates that the listener uses to verify the authenticity of the client certificates.
170+
# For one-way authentication, the file content can be empty.
151171
listener.ssl.external.cacertfile = etc/certs/ca.pem
152172

153-
## A server only does x509-path validation in mode verify_peer,
154-
## as it then sends a certificate request to the client (this
155-
## message is not sent if the verify option is verify_none).
156-
##
157-
## Value: verify_peer | verify_none
173+
# Set `verify_peer` to verify the authenticity of the client certificates.
174+
# Set `verify_none` to allow any client to connect, regardless of the client certificate.
158175
listener.ssl.external.verify = verify_peer
159176

160-
## Used together with {verify, verify_peer} by an SSL server. If set to true,
161-
## the server fails if the client does not have a certificate to send, that is,
162-
## sends an empty certificate.
163-
##
164-
## Value: true | false
177+
# If set to `true`, the handshake fails if the client does not have a certificate to send. Must be set to `true` for two-way authentication (mTLS).
178+
# If set to `false`, it fails only if the client sends an invalid certificate (an empty certificate is considered valid). i.e. one-way authentication.
165179
listener.ssl.external.fail_if_no_peer_cert = true
166180
```
167181

zh/202007/enable-two-way-ssl-for-emqx.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,43 +130,56 @@ openssl x509 -req -days 3650 -in client.csr -CA ca.pem -CAkey ca.key -CAcreatese
130130

131131
## SSL/TLS 双向连接的启用及验证
132132

133-
**在 EMQX 中 `mqtt:ssl` 的默认监听端口为 8883。**
133+
### EMQX v5 配置
134+
135+
```shell
136+
listeners.ssl.default {
137+
bind = "0.0.0.0:8883"
138+
ssl_options {
139+
# PEM 格式的文件,用于保存一个或多个用于签发客户端证书的根证书。TLS 握手阶段 EMQX 会使用这些证书来验证客户端证书。
140+
# 如果不想要对客户端证书进行验证 (即:单向认证),则该文件内容可以为空。
141+
cacertfile = "etc/certs/ca.pem"
142+
# PEM 格式的服务端证书链文件。
143+
# 如果证书链中包含中间 CA 证书,需要将中间 CA 证书附加到服务端证书后以形成证书链。
144+
certfile = "etc/certs/emqx.pem"
145+
# PEM 格式的服务端私钥文件。
146+
keyfile = "etc/certs/emqx.key"
147+
# 设置 `verify_peer` 以验证客户端证书。
148+
# 设置 `verify_none` 允许任何客户端连接,无论客户端证书如何。
149+
verify = verify_peer
150+
# 如果设置为 `true`,则客户端未发送证书时,连接将失败,双向认证必选。
151+
# 如果设置为 `false`,则仅在客户端发送无效证书时失败(空证书被视为有效),即:单向认证。
152+
fail_if_no_peer_cert = true
153+
}
154+
}
155+
156+
157+
### EMQX v4 配置
134158

135-
### EMQX 配置
159+
** EMQX `mqtt:ssl` 的默认监听端口为 8883。**
136160

137161
将前文中通过 OpenSSL 工具生成的 `emqx.pem``emqx.key``ca.pem` 文件拷贝到 EMQX 的 `etc/certs/` 目录下,并参考如下配置修改 `emqx.conf`
138162

139163
```shell
140-
## listener.ssl.$name is the IP address and port that the MQTT/SSL
141-
## Value: IP:Port | Port
142164
listener.ssl.external = 8883
143165
144-
## Path to the file containing the user's private PEM-encoded key.
145-
## Value: File
166+
# PEM 格式的服务端私钥文件。
146167
listener.ssl.external.keyfile = etc/certs/emqx.key
147168
148-
## 注意:如果 emqx.pem 是证书链,请确保第一个证书是服务器的证书,而不是 CA 证书。
149-
## Path to a file containing the user certificate.
150-
## Value: File
169+
# PEM 格式的服务端证书链文件。
170+
# 如果证书链中包含中间 CA 证书,需要将中间 CA 证书附加到服务端证书后以形成证书链。
151171
listener.ssl.external.certfile = etc/certs/emqx.pem
152172
153-
## 注意:ca.pem 用于保存服务器的中间 CA 证书和根 CA 证书。可以附加其他受信任的 CA,用来进行客户端证书验证。
154-
## Path to the file containing PEM-encoded CA certificates. The CA certificates
155-
## Value: File
173+
# PEM 格式的文件,用于保存一个或多个用于签发客户端证书的根证书。TLS 握手阶段 EMQX 会使用这些证书来验证客户端证书。
174+
# 如果不想要对客户端证书进行验证 (即:单向认证),则该文件内容可以为空。
156175
listener.ssl.external.cacertfile = etc/certs/ca.pem
157176
158-
## A server only does x509-path validation in mode verify_peer,
159-
## as it then sends a certificate request to the client (this
160-
## message is not sent if the verify option is verify_none).
161-
##
162-
## Value: verify_peer | verify_none
177+
# 设置 `verify_peer` 以验证客户端证书。
178+
# 设置 `verify_none` 允许任何客户端连接,无论客户端证书如何。
163179
listener.ssl.external.verify = verify_peer
164180
165-
## Used together with {verify, verify_peer} by an SSL server. If set to true,
166-
## the server fails if the client does not have a certificate to send, that is,
167-
## sends an empty certificate.
168-
##
169-
## Value: true | false
181+
# 如果设置为 `true`,则客户端未发送证书时,连接将失败,双向认证必选。
182+
# 如果设置为 `false`,则仅在客户端发送无效证书时失败(空证书被视为有效),即:单向认证。
170183
listener.ssl.external.fail_if_no_peer_cert = true
171184
```
172185

0 commit comments

Comments
 (0)