MQTT mosquitto[2]---- SSL双向认证的配置文件的Configuration的配置方式

我们知道,MQTT mosquitto支持单项和双向的SSL认证,在上一节中,我们已经给大家分享了单向的SSL如何配置,在这一节中咱们来看一下双向的SSL认证的配置文件应该如何配置? 那么什么是双向的SSL认证呢?所谓的双向的SSL认证,打个通俗的比方就是,在进行SSL加密通信前,通信的双方(在咱们的例子中是mosquitto服务器端和MQTT客户端(消息的发送或者接收端))需要相互验证各自的证书是否合法。比如,是否是一个合法的CA颁发的等等。

在上一节提到,我们知道启动MQTT mosquitto的时候,可以通过下面的命令

mosquitto [-c config file] [ -d | --daemon ] [-p port number] [-v]

来指定启动的方式,其中,-c 后面跟的是启动mosquitto可以调整的参数,比如是否开启基本认证,端口是什么,SSL单向和双向的认证配置等等。

-d 表示MQTT mosquitto将在后台运行。

-p 代表当前的mosquitto服务实例启动以后,其监听端口号,这个配置的覆盖[-c config file] 指定的配置文件中的端口

-v 代码调试模式(verbose)可以输出更多的信息

假设我们自己已经通过OpenSSL生成了相关的CA证书,和服务器端自签名公钥和私钥,客户端的自签名公钥和私钥。其位置分布存储在:

(1) CA证书的位置

D:\mosquitto\certificates\ca.crt

(2) 服务器端的自签名的公钥的地址

D:\mosquitto\certificates\server.crt

(3) 服务器端的自签名的私钥的地址

 D:\mosquitto\certificates\server.key

则其单向的SSL的mosquitto服务器端的配置文件(Configuration)的配置方式如下:

假设下面的配置存储在一个名为D:\mosquitto\twowayssl.conf的文本文件中,

# See also the mosquitto-tls man page.

# At least one of cafile or capath must be defined. They both 
# define methods of accessing the PEM encoded Certificate 
# Authority certificates that have signed your server certificate 
# and that you wish to trust.
# cafile defines the path to a file containing the CA certificates.
# capath defines a directory that will be searched for files
# containing the CA certificates. For capath to work correctly, the
# certificate files must have ".crt" as the file ending and you must run
# "c_rehash <path to capath>" each time you add/remove a certificate.
cafile D:\mosquitto\certificates\ca.crt
#capath

# Path to the PEM encoded server certificate.
certfile D:\mosquitto\certificates\server.crt

# Path to the PEM encoded keyfile.
keyfile D:\mosquitto\certificates\server.key

# This option defines the version of the TLS protocol to use for this listener.
# The default value will always be the highest version that is available for
# the version of openssl that the broker was compiled against. For openssl >=
# 1.0.1 the valid values are tlsv1.2 tlsv1.1 and tlsv1. For openssl < 1.0.1 the
# valid values are tlsv1.
tls_version tlsv1

# By default a TLS enabled listener will operate in a similar fashion to a
# https enabled web server, in that the server has a certificate signed by a CA
# and the client will verify that it is a trusted certificate. The overall aim
# is encryption of the network traffic. By setting require_certificate to true,
# the client must provide a valid certificate in order for the network
# connection to proceed. This allows access to the broker to be controlled
# outside of the mechanisms provided by MQTT.
require_certificate true

# If require_certificate is true, you may set use_identity_as_username to true
# to use the CN value from the client certificate as a username. If this is
# true, the password_file option will not be used for this listener.
use_identity_as_username true

从上面可以看出,双向和单项认证的区别是,除了需要单向SSL认证需要的CA的证书,服务器端的公钥和私钥的证书之外,还需要开启下面的两个开关。

# By default a TLS enabled listener will operate in a similar fashion to a
# https enabled web server, in that the server has a certificate signed by a CA
# and the client will verify that it is a trusted certificate. The overall aim
# is encryption of the network traffic. By setting require_certificate to true,
# the client must provide a valid certificate in order for the network
# connection to proceed. This allows access to the broker to be controlled
# outside of the mechanisms provided by MQTT.
require_certificate true

# If require_certificate is true, you may set use_identity_as_username to true
# to use the CN value from the client certificate as a username. If this is
# true, the password_file option will not be used for this listener.
use_identity_as_username true

则可以通过下面的方式启动mosquitto服务器端的双向的SSL服务。

mosquitto D:\mosquitto\twowayssl.conf -p 1885 -v

时间: 2024-08-05 19:13:10

MQTT mosquitto[2]---- SSL双向认证的配置文件的Configuration的配置方式的相关文章

Nginx、SSL双向认证、PHP、SOAP、Webservice、https

本文是1:1模式,N:1模式请参见新的一篇博客<SSL双向认证(高清版)> ----------------------------------------------------- 我是分割线 --------------------------------------------------------- 标题太长了不知道该怎么起,索性就把keyword列出来吧~ WebService的WS-*搞了一天没搞定,看样子PHP应该是彻底抛弃SOAP协议了,google翻烂了也没找到什么靠谱的解

SSL双向认证(高清版)

介绍了SSL双向认证的一些基本问题,以及使用Nginx+PHP基于它搭建https的Webservice. 之前的方式只是实现1:1的模式,昨天同事继续实现了n:1的模式,这里我再整理记录下. 由于nginx的ssl_client_certificate参数只能指定一个客户端公钥,如果增加一个客户端进行通信就要重新配一个server. n:1的模式是通过CA的级联证书模式实现的,首先自己生成一套CA根级证书,再借助其生成二级证书作为client证书. 此时client私钥签名不仅可以通过对应的c

tomcat配置SSL双向认证

一.SSL简单介绍 SSL(Secure Sockets Layer 安全套接层)就是一种协议(规范),用于保障客户端和服务器端通信的安全,以免通信时传输的信息被窃取或者修改. 怎样保障数据传输安全?  客户端和服务器端在进行握手(客户端和服务器建立连接和交换参数的过程称之为握手)时会产生一个“对话密钥”(session key),用来加密接下来的数据传输,解密时也是用的这个“对话密钥”,而这个“对话密钥”只有客户端和服务器端知道.也就是说只要这个“对话密钥”不被破解,就能保证安全. 2. 客户

SSL双向认证和SSL单向认证的流程和区别

refs: SSL双向认证和SSL单向认证的区别https://www.jianshu.com/p/fb5fe0165ef2 图解 https 单向认证和双向认证!https://cloud.tencent.com/developer/news/233610 SSL/TLS 双向认证(一) -- SSL/TLS工作原理https://blog.csdn.net/wuliganggang/article/details/78428866 双向认证 SSL 协议要求服务器和用户双方都有证书.单向认证

SSL双向认证

之前的方式只是实现1:1的模式,昨天同事继续实现了n:1的模式,这里我再整理记录下. 由于nginx的ssl_client_certificate参数只能指定一个客户端公钥,如果增加一个客户端进行通信就要重新配一个server. n:1的模式是通过CA的级联证书模式实现的,首先自己生成一套CA根级证书,再借助其生成二级证书作为client证书. 此时client私钥签名不仅可以通过对应的client公钥验证,还可通过根证书的公钥进行验证. 看到这里应该豁然开朗了吧,下面简单介绍下具体怎么操作:

【密码学】ssl双向认证和单向认证原理

有朋友在搞一个项目,周末有聊到一些安全性的东西,很自然会想起https,但https究竟如何实施,其原理又是什么? 基于ssl,一般的应用都是单向认证,如果应用场景要求对客户来源做验证也可以实现成双向认证. 网上google一下: 为了便于更好的认识和理解 SSL 协议,这里着重介绍 SSL 协议的握手协议.SSL 协议既用到了公钥加密技术又用到了对称加密技术,对称加密技术虽然比公钥加密技术的速度快,可是公钥加密技术提供了更好的身份认证技术.SSL 的握手协议非常有效的让客户和服务器之间完成相互

NGINX 配置 SSL 双向认证

对于 NGINX 的 HTTPS 配置,通常情况下我们只需要实现服务端认证就行,因为浏览器内置了一些受信任的证书颁发机构(CA),服务器端只需要拿到这些机构颁发的证书并配置好,浏览器会自己校验证书的可用性并通过 SSL 进行通讯加密. 但特殊情况下我们也需要对客户端进行验证,只有受信任的客户端才能使用服务接口,此时我们就需要启用双向认证来达到这个目的,只有 当客户端请求带了可用的证书才能调通服务端接口 . CA 与自签名 CA 是权威机构才能做的,并且如果该机构达不到安全标准就会被浏览器厂商“封

webservice ssl双向认证配置

1.在tomcat中安装axis2插件 2.生成证书,用jdk自带的keytool 服务端 keytool -genkey -alias Server -dname "CN=192.168.10.100, OU=JH, O=JH, L=HangZhou, S=ZheJiang, C=CN" -keystore server.keystore -keyalg RSA keytool -export -alias Server -file server.cer -storepass 123

(备忘)Nginx配置客户端SSL双向认证

对于 NGINX 的 HTTPS 配置,通常情况下我们只需要实现服务端认证就行,因为浏览器内置了一些受信任的证书颁发机构(CA),服务器端只需要拿到这些机构颁发的证书并配置好,浏览器会自己校验证书的可用性并通过 SSL 进行通讯加密. 但特殊情况下我们也需要对客户端进行验证,只有受信任的客户端才能使用服务接口,此时我们就需要启用双向认证来达到这个目的,只有 当客户端请求带了可用的证书才能调通服务端接口 . CA 与自签名 CA 是权威机构才能做的,并且如果该机构达不到安全标准就会被浏览器厂商"封