当前位置:网站首页>Using emqx cloud to realize one machine one secret verification of IOT devices
Using emqx cloud to realize one machine one secret verification of IOT devices
2022-07-02 21:55:00 【51CTO】
Data security is the top priority of Internet of things applications . Manufacturers often use symmetric encryption 、 Asymmetric encryption 、 digital signature 、 Digital certificate and other methods to authenticate the equipment , To prevent the access of illegal devices . In the use of certificates , One type and one density 、 Different schemes such as one machine and one secret , One machine one secret scheme sets a unique device certificate for each device end in advance , Two way verification can be carried out when the device communicates with the server , After the verification is passed , Only when the device end and the server end are in normal data transmission . Compared with other schemes , One machine and one secret can achieve independent verification and authorization for each device , With higher security .
As a safe and reliable full custody MQTT Message cloud service , EMQX Cloud Support multiple authentication methods , Including basic certification ( user name / password , client ID/ password ) And JWT、PSK and X.509 Certification , At the same time, the external database can be configured as the data source to verify the authentication information .
This article will use Redis Store the database as the authentication data source , Explain how to pass the Common Name To verify information , Connect to EMQX Cloud, Realize client-side one machine one secret authentication . If the client certificate does not contain the specified unique Common Name, You cannot pass the certification .
Through this paper , Readers can realize one machine and one secret for their IOT devices 、 The ability of bidirectional identity authentication between the device and the server and establishing a secure channel , Effectively prevent counterfeiting equipment 、 The device key is 、 Forge server instructions 、 Monitor or tamper with key information 、 Steal the key through the security vulnerability of the equipment production line .
Operation process
One 、 To configure TLS/SSL Two-way authentication
1、 preparation
Purchase server certificate , And resolve its domain name to the deployment connection address .
Purchase server certificate
Generate client root ca Self signed certificate , Use self signed root ca The certificate issuing client certificate needs to ensure Common Name only .
# CA Certificate generation client-ca.crt,subj Adjust according to actual use .
openssl req \
-new \
-newkey rsa:2048 \
-days 365 \
-nodes \
-x509 \
-subj "/C=Common Name/O=EMQ Technologies Co., Ltd/Common Name=EMQ CA" \
-keyout client-ca.key \
-out client-ca.crt
# Client secret key generation client.key
openssl genrsa -out client.key 2048
# Generate client certificate request file client.csr,Common Name Carry authentication information for the client
openssl req -new -key client.key -out client.csr -subj "/Common Name=346a004d-1dab-4016-bb38-03cca7094415"
# use CA The certificate signs the client certificate , Generate client.crt
openssl x509 -req -days 365 -sha256 -in client.csr -CA client-ca.crt -CAkey client-ca.key -CAcreateserial -out client.crt
# View the client certificate information
openssl x509 -noout -text -in client.crt
# Certificate of verification
openssl verify -CAfile client-ca.crt client.crt
2、 The configuration process
Sign in EMQX Cloud Console . Enter deployment details , Click on +TLS/SSL configure button , Configure certificate content , You can upload files or fill in the certificate directly TLS/SSL Authentication type :
① One way Authentication : Only the client verifies the server certificate .
② Two-way authentication : Client and server mutually verify certificates .
In this example document, we take two-way authentication as an example , Fill in the following in the deployment console :
① Public key certificate : Server certificate
② Certificate chain : Certificate chain , Usually, when the third-party organization issues the certificate, it will provide
③ Private key : Private key
④ client CA certificate : When selecting two-way authentication , You need to provide the client CA certificate
MQTT Cloud TLS SSL Two-way authentication
After completion , Click ok , Until the status is running , namely TLS/SSL Two way authentication configuration is complete .
Two 、 To configure Redis authentication / Access control
This article takes Redis authentication / Take access control as an example , Of course, you can also use other external authentication data sources , In the scenario described in this article , Recommended for comparison Redis authentication / Access control .
1、 establish VPC Peer to peer connection
stay EMQX Cloud Deployment details page , establish VPC Peer to peer connection , It is convenient for the professional version to deploy intranet access to you Redis Authentication database .
EMQX Cloud establish VPC Peer to peer connection
2、 To configure Redis authentication / Access control
redis To configure
In your ECS , Create a Redis service . For the convenience of demonstration , Use here Docker Quickly build .
docker run -itd --name redis -p 6379:6379 redis:latest
There are two ways to configure data in this example ( A choice ):
HMSET tls_domain:346a004d-1dab-4016-bb38-03cca7094415 password pubic
HMSET tls_subject:346a004d-1dab-4016-bb38-03cca7094415 password pubic
redis To configure
Redis authentication / Access control configuration
When authenticating ,EMQX Cloud The current client information will be used to populate and execute the user configured authentication query command , Find out that the client is in Redis Authentication data in .
Can be certified in SQL Use the following placeholders in , Execution time EMQX Cloud Will be automatically populated as client information ::
%u: user name
%c: client ID
%C:TLS Certificate common name ( Domain name or subdomain name of the certificate ), Only when the TLS Valid when connected
%d:TLS certificate subject, Only when the TLS Valid when connected
You can adjust the authentication query command according to your business needs , Use any Redis Supported commands (opens new window), However, in any case, the authentication query command needs to meet the following conditions :
① The first data in the query result must be password,EMQX Use this field to compare with the client password
② If the salt configuration is enabled , The second data in the query result must be salt Field ,EMQX Use this field as the salt( salt ) value
Click authentication in the deployment - External authentication authorization - Redis authentication / Access control , Click Configure authentication , You can create a new certification .
The authentication query command has the following two ways :
HMGET tls_domain:%C password
HMGET tls_subject:%d password
That is, the device needs to carry the client certificate 、 Client secret key and its Common Name 、password The way to authenticate .
Redis authentication
Test verification
We use MQTT X The simulation client carries the following information to connect to EMQX Cloud.
① Server side CA
② Common Name by 346a004d-1dab-4016-bb38-03cca7094415 Client certificate for 、 Client secret key
③ password:public
MQTT X
Click on Upper right corner connect, appear connected Indicates that the connection was successful . thus , With designation common name Your device has been successfully connected to EMQX Cloud, That is, one machine and one secret device are verified and connected to EMQX Cloud Have succeeded .
MQTT X1
Conclusion
So far we're done EMQX Cloud Client-side one machine one certificate verification process , Successfully connected to deployment . Compared with other schemes , One machine and one secret can achieve independent verification and authorization for each device , With higher security , If you also set up a unique access credential for each of your IOT devices , You can refer to this article for configuration .
边栏推荐
- Gbase8s database type
- Unity3D学习笔记4——创建Mesh高级接口
- Gee: (II) resampling the image
- sql service 截取字符串
- Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
- Research Report on market supply and demand and strategy of China's plastic pump industry
- [Yu Yue education] reference materials of analog electronic technology of Nanjing Institute of information technology
- Research Report on market supply and demand and strategy of China's Plastic Geogrid industry
- Plastic granule Industry Research Report - market status analysis and development prospect forecast
- Evolution of messaging and streaming systems under the native tide of open source cloud
猜你喜欢
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
Redis分布式锁故障,我忍不住想爆粗...
GEE:(二)对影像进行重采样
Baidu sued a company called "Ciba screen"
How to write a good program when a big book speaks every day?
MySQL learning record (3)
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
[shutter] shutter layout component (opacity component | clipprect component | padding component)
LandingSite eBand B1冒烟测试用例
Etcd raft protocol
随机推荐
pyqt图片解码 编码后加载图片
The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
使用 EMQX Cloud 实现物联网设备一机一密验证
*C language final course design * -- address book management system (complete project + source code + detailed notes)
MySQL installation failed -gpg verification failed
Pyqt picture decodes and encodes and loads pictures
Infrastructure is code: a change is coming
Official announcement! The golden decade of new programmers and developers was officially released
【剑指 Offer】56 - I. 数组中数字出现的次数
Record the functions of sharing web pages on wechat, QQ and Weibo
Une semaine de vie
读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
[sword finger offer] 56 - I. the number of numbers in the array
Research Report on market supply and demand and strategy of China's Plastic Geogrid industry
How to write a good program when a big book speaks every day?
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
China plastic bottle and container market trend report, technological innovation and market forecast
~91 rotation
The neo4j skill tree was officially released to help you easily master the neo4j map database