IoT cross-chain method and system based on MQTT protocol
By establishing blockchain accounts and smart contracts on MQTT Broker, trusted connections and staggered connections between Brokers are achieved, the problem of IoT devices is solved, cross-chain technology and data protocol conversion is realized, and data reliability is ensured. Sex and safety.
Patent Information
- Application Number
- CN202210675741.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-15
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2042-06-15
AI Technical Summary
Due to insufficient hardware computing and storage capabilities, IoT devices are difficult to directly hold the blockchain's public and private key pair, which makes it difficult to open the chain.
By establishing MQTT Broker's blockchain account and smart contract, trusted connections and stalling between Brokers are realized, cross-chain network is formed, and blockchain smart contracts are used to map MQTT Topic to realize the conversion of off-chain data and on-chain data .
It solves the problem of IoT devices being linked, realizes trusted data interaction and cross-chain technology between Brokers, ensures data reliability and security, and avoids the limitations that the device itself needs to be changed.
Smart Images

Figure CN114978511B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of MQTT protocol, and in particular to an IoT cross-chain method based on MQTT protocol. Background Art
[0002] MQTT is the most widely used low-power, low-latency communication protocol in the IoT system, including the middle role MQTT broker Broker and MQTT client Client.
[0003] Blockchain is a decentralized distributed ledger database. Blockchain has two core characteristics: one is that the data is difficult to tamper with, and the other is decentralization. Based on these two characteristics, the information recorded in the blockchain is more reliable and can help people solve the problem of mutual distrust.
[0004] Due to the lack of hardware computing and storage capabilities and security issues, it is difficult for IoT devices to directly hold the public and private key pairs of the blockchain, and therefore it is difficult to perform on-chain operations. Therefore, on-chain operations based on IoT IoT devices are a difficult problem. Summary of the invention
[0005] In view of the defects in the prior art, the purpose of the present invention is to provide an IoT cross-chain method and system based on the MQTT protocol.
[0006] According to the present invention, an IoT cross-chain method based on the MQTT protocol includes the following steps:
[0007] Step S1: Create a blockchain account for MQTT Broker;
[0008] Step S2: Establish a trusted connection between the MQTT Broker and other Brokers on the blockchain;
[0009] Step S3: Establish a cross-chain network formed by multiple MQTT Brokers.
[0010] Preferably, the step S1 includes the following sub-steps:
[0011] Step S1.1: Establish an independent blockchain account role and public-private key pair for MQTT Broker; establish the registered identity of MQTT Broker in the smart contract MQTTBrokerManager on the blockchain, establish a connection with the blockchain node, and listen to messages on the smart contract MQTTBrokerManager;
[0012] Step S1.2: Define the mapping agent between MQTT Topic and blockchain smart contract;
[0013] Step S1.3: Establish the MQTT Broker cascade identity; access the MQTT Client account and Client CA certificate of other Brokers, establish a bridge with other MQTT Brokers, and form a cascade between multiple Brokers.
[0014] Preferably, the step S1.2 comprises:
[0015] Mapping Topic definition structure 1: blockchain abbreviation symbol / blockchain network number / smart contract address;
[0016] Mapping Topic definition structure 2: blockchain abbreviation symbol / blockchain network number / smart contract alias;
[0017] The structure of MQTT Message supports the direct use of the structure of Web3 JSON-RPC;
[0018] Supports user-configured conversion scripts for Topic Message and Web3 JSON-RPC.
[0019] Preferably, step S2 includes the following sub-steps:
[0020] Step S2.1: Initiate a connection request through the first MQTT Broker to the second MQTT Broker on the same blockchain, so that the first MQTT Broker sends encrypted data to the on-chain contract and indicates the address of the second MQTT Broker; the encrypted data is: the first MQTT Broker's Client, CA certificate, IP address port and the second MQTT Broker's public key information are packaged as a whole, and asymmetrically encrypted using the first MQTT Broker's private key;
[0021] Step S2.2: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the first MQTTBroker, has been legally registered. If legal, notify the second MQTT Broker through a smart contract message, which contains the requested req-id;
[0022] Step S2.3: The second MQTT Broker calls the smart contract method to obtain the data packet corresponding to the request req-id, verifies the signature of the data packet, and determines whether it is the first MQTT Broker;
[0023] Step S2.4: asymmetrically decrypt the encrypted data packet using the private key of the second MQTT Broker to obtain the information of the first MQTT Broker;
[0024] Step S2.5: When the second MQTT Broker refuses the connection, the method of the smart contract MQTTBrokerManager is called to notify the rejection of the request of the first MQTT Broker; when the second MQTT Broker agrees to the connection, the Client and CA certificate contents of the first MQTT Broker are added to the local whitelist, and the access password of the Client of the first MQTT Broker is generated and packaged together, and asymmetric encryption is performed through the private key of the second MQTT Broker, and the authorization connection method of the smart contract MQTTBrokerManager is called to notify the approval of Alice's connection request;
[0025] Step S2.6: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the second MQTTBroker, has been legally registered. If legal, notify the first MQTT Broker through a smart contract message that it has been authorized, and the notification contains the req-id of this request;
[0026] Step S2.7: The first MQTT Broker calls the smart contract method to obtain the data packet for requesting req-id authorization from the second MQTT Broker, verifies the signature of the data packet, and uses the private key of the first MQTT Broker for asymmetric decryption to obtain the access password for authorizing access to the Client;
[0027] Step S2.8: Use the Client access password through the first MQTT Broker to establish an MQTT secure connection with the second MQTT Broker.
[0028] Preferably, step S3 includes the following sub-steps:
[0029] Step S3.1: Contract mapping is performed between the first MQTT Broker and the first blockchain BC1 and the second blockchain BC2 at the same time;
[0030] Step S3.2: When the message sent by the first MQTT Broker to the Topic is directed to the first blockchain BC1 where it is located, the BC1 account of the first MQTT Broker is used to convert the message body into a Web3 JSON-RPC structure, and call the corresponding smart contract method of the blockchain BC1; when the message sent by the first MQTT Broker to the Topic is directed to the second blockchain BC2, the message is signed with a private key and sent to the third MQTT Broker located on the second blockchain BC2 through the cascade message between the MQTT Brokers, wherein the first MQTT Broker and the third MQTT Broker establish a connection through a non-blockchain method;
[0031] Step S3.3: Through the Topic mapping agent of the third MQTT Broker, the message body is signed and then converted into a Web3 JSON-RPC structure, and the corresponding smart contract method of blockchain BC2 is called.
[0032] According to the present invention, an IoT cross-chain system based on the MQTT protocol includes the following steps:
[0033] Module M1: Establishing the blockchain account of MQTT Broker;
[0034] Module M2: Establish a trusted connection between MQTT Broker and other Brokers on the blockchain;
[0035] Module M3: Establish a cross-chain network formed by multiple MQTT Brokers.
[0036] Preferably, the module M1 includes the following submodules:
[0037] Module M1.1: Establish an independent blockchain account role and public-private key pair for MQTT Broker; establish the registered identity of MQTT Broker in the smart contract MQTTBrokerManager on the blockchain, establish a connection with the blockchain node, and monitor messages on the smart contract MQTTBrokerManager;
[0038] Module M1.2: Define the mapping agent between MQTT Topic and blockchain smart contract;
[0039] Module M1.3: Establish MQTT Broker cascade identity; access the MQTT Client account and Client CA certificate of other Brokers, establish bridges with other MQTT Brokers, and form cascades between multiple Brokers.
[0040] Preferably, the module M1.2 comprises:
[0041] Mapping Topic definition structure 1: blockchain abbreviation symbol / blockchain network number / smart contract address;
[0042] Mapping Topic definition structure 2: blockchain abbreviation symbol / blockchain network number / smart contract alias;
[0043] The structure of MQTT Message supports the direct use of the structure of Web3 JSON-RPC;
[0044] Supports user-configured conversion scripts for Topic Message and Web3 JSON-RPC.
[0045] Preferably, the module M2 includes the following submodules:
[0046] Module M2.1: Initiate a connection request through the first MQTT Broker to the second MQTT Broker on the same blockchain, so that the first MQTT Broker sends encrypted data to the on-chain contract and indicates the address of the second MQTT Broker; the encrypted data is: the first MQTT Broker's Client, CA certificate, IP address port and the second MQTT Broker's public key information are packaged as a whole and asymmetrically encrypted using the first MQTT Broker's private key;
[0047] Module M2.2: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the first MQTTBroker, has been legally registered. If legal, notify the second MQTT Broker through a smart contract message, which contains the requested req-id;
[0048] Module M2.3: Call the smart contract method through the second MQTT Broker to obtain the data packet corresponding to the request req-id, verify the signature of the data packet, and determine whether it is the first MQTT Broker;
[0049] Module M2.4: Asymmetrically decrypt the encrypted data packet using the private key of the second MQTT Broker to obtain the information of the first MQTT Broker;
[0050] Module M2.5: When the second MQTT Broker refuses the connection, the method of the smart contract MQTTBrokerManager is called to notify the rejection of the request of the first MQTT Broker; when the second MQTT Broker agrees to the connection, the Client and CA certificate contents of the first MQTT Broker are added to the local whitelist, and the access password of the Client of the first MQTT Broker is generated and packaged together, and asymmetric encryption is performed through the private key of the second MQTT Broker, and the authorization connection method of the smart contract MQTTBrokerManager is called to notify the approval of Alice's connection request;
[0051] Module M2.6: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the second MQTTBroker, the contract caller, has been legally registered. If legal, the first MQTT Broker is notified through a smart contract message that the authorization has been granted, and the notification contains the req-id of this request;
[0052] Module M2.7: The first MQTT Broker calls the smart contract method to obtain the data packet of the second MQTT Broker requesting req-id authorization, verifies the signature of the data packet, uses the private key of the first MQTT Broker for asymmetric decryption, and obtains the access password for authorizing access to the Client;
[0053] Module M2.8: Use the Client access password of the first MQTT Broker to establish an MQTT secure connection with the second MQTT Broker.
[0054] Preferably, the module M3 includes the following submodules:
[0055] Module M3.1: Contract mapping of the first MQTT Broker with the first blockchain BC1 and the second blockchain BC2;
[0056] Module M3.2: When the message sent by the first MQTT Broker to the Topic is directed to the first blockchain BC1 where it is located, the BC1 account of the first MQTT Broker is used to convert the message body into a Web3 JSON-RPC structure, and call the corresponding smart contract method of the blockchain BC1; when the message sent by the first MQTT Broker to the Topic is directed to the second blockchain BC2, the message is signed with a private key and sent to the third MQTT Broker located on the second blockchain BC2 through the cascade message between the MQTT Brokers, where the first MQTT Broker and the third MQTT Broker establish a connection through a non-blockchain method;
[0057] Module M3.3: Through the Topic mapping agent of the third MQTT Broker, the message body is signed and then converted into a Web3 JSON-RPC structure, calling the corresponding smart contract method of blockchain BC2.
[0058] Compared with the prior art, the present invention has the following beneficial effects:
[0059] 1. The present invention realizes the proxy chaining of loT devices through MQTT Broker, which solves the problem that the IoT devices are difficult to chain due to insufficient hardware computing and storage capabilities and security issues.
[0060] 2. The Brokers in the present invention realize on-chain identity based on the trust mechanism of blockchain, conduct trusted data interaction between Brokers, further confirm the ownership and account of the interactive data on blockchain, and the cascading between Brokers realizes the cross-chain technology of the Internet of Things.
[0061] 3. The present invention defines the mapping between MQTT Topic and blockchain smart contract at the protocol level, which solves the problem that the IoT device side does not need to be modified, and the conversion between the off-chain data protocol and the on-chain data protocol can be realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0063] Figure 1 This is a flow chart of establishing a connection with an MQTT Broker in an embodiment of the present invention;
[0064] Figure 2 This is a flow chart of cross-chain operations supported by multiple MQTT Brokers in an embodiment of the present invention;
[0065] Figure 3 This is a schematic diagram of the cross-chain operation of multiple MQTT Brokers in an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0067] The present invention discloses an IoT cross-chain method based on the MQTT protocol. MQTT is a low-power, low-latency communication protocol with the widest application range in the IoT system, including an MQTT broker and an MQTT client.
[0068] Blockchain is a distributed ledger for building trust. It associates MQTT agents and clients with blockchain, has on-chain identities, authenticates and establishes trust through blockchain, maps smart contracts on blockchain with MQTT protocols, and implements a method of associating Layer 1 and Layer 2. At the same time, through the cascading function between Brokers, a network is established with multiple Brokers connected to different blockchains, forming a cross-chain network between IoT devices, and realizing a means of transferring off-chain IoT device data to on-chain IoT oracle (oracle), as well as a cross-chain solution for IoT oracle data.
[0069] The MQTT version of this technical solution needs to be v5.0, which specifically includes the following steps:
[0070] Step S1: Create a blockchain account for MQTT Broker, including:
[0071] Step S1.1: Establish independent blockchain account roles and public and private key pairs. In the following description, Alice is the blockchain identity of Broker, and Bob is similar;
[0072] The registered identity in the smart contract MQTTBrokerManager on the blockchain;
[0073] Establish a connection with the blockchain node and listen to messages on the smart contract MQTTBrokerManager.
[0074] Step S1.2: Define the mapping agent between MQTT Topic and blockchain smart contract:
[0075] Mapping Topic definition structure 1: blockchain abbreviation symbol / blockchain network number / smart contract address;
[0076] Mapping Topic definition structure 2: blockchain abbreviation symbol / blockchain network number / smart contract alias;
[0077] The structure of MQTT Message supports the direct use of the structure of Web3 JSON-RPC;
[0078] Supports user-configured conversion scripts for Topic Message and Web3 JSON-RPC.
[0079] Step S1.3: Establish the MQTT Broker cascade identity; access the MQTT Client account and Client CA certificate of other Brokers, establish a bridge with other MQTT Brokers, and form a cascade between multiple Brokers.
[0080] Step S2: Establish a trusted connection between the MQTT Broker and other Brokers on the blockchain, such as Figure 1 As shown;
[0081] The multiple MQTT Broker roles connected through the same blockchain are as follows:
[0082] A. MQTT Broker that initiates the connection request: Alice
[0083] B. The MQTT Broker that Alice wants to connect to: Bob
[0084] C. All MQTT Brokers maintain a connection with the blockchain and listen to messages on the smart contract MQTTBrokerManager
[0085] Step S2.1: Initiate a connection request through the first MQTT Broker (Alice) to the second MQTT Broker (Bob) on the same blockchain, so that the first MQTT Broker (Alice) sends encrypted data to the on-chain contract and indicates the address of the second MQTT Broker (Bob); the encrypted data is: the first MQTT Broker (Alice) Client, CA certificate, IP address port and the public key information of the second MQTT Broker (Bob) are packaged as a whole, and asymmetrically encrypted using the private key of the first MQTT Broker (Alice);
[0086] Step S2.2: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the first MQTTBroker (Alice), has been legally registered. If legal, notify the second MQTTBroker (Bob) through a smart contract message, which contains the requested req-id;
[0087] Step S2.3: The second MQTT Broker (Bob) calls the smart contract method to obtain the data packet corresponding to the request req-id, verifies the signature of the data packet, and determines whether it is the first MQTT Broker (Alice);
[0088] Step S2.4: Asymmetrically decrypt the encrypted data packet using the private key of the second MQTT Broker (Bob) to obtain the information of the first MQTT Broker (Alice);
[0089] Step S2.5: When the second MQTT Broker (Bob) refuses the connection, the method of the smart contract MQTTBrokerManager is called to notify the rejection of the request of the first MQTT Broker (Alice); when the second MQTT Broker (Bob) agrees to the connection, the Client and CA certificate content of the first MQTT Broker (Alice) are added to the local whitelist, and the access password of the Client of the first MQTT Broker (Alice) is generated and packaged together, and asymmetric encryption is performed through the private key of the second MQTT Broker (Bob), and the authorization connection method of the smart contract MQTTBrokerManager is called to notify the approval of Alice's connection request;
[0090] Step S2.6: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the second MQTTBroker (Bob), has been legally registered. If legal, notify the first MQTTBroker (Alice) through a smart contract message that it has been authorized, and the notification contains the req-id of this request;
[0091] Step S2.7: The first MQTT Broker (Alice) calls the smart contract method to obtain the data packet of the second MQTT Broker requesting req-id authorization, verifies the signature of the data packet, uses the private key of the first MQTT Broker (Alice) to perform asymmetric decryption, and obtains the access password authorized to access the Client;
[0092] Step S2.8: The first MQTT Broker (Alice) uses the Client access password to establish an MQTT secure connection with the second MQTT Broker (Bob).
[0093] Step S3: Establish a cross-chain network formed by multiple MQTT Brokers, such as Figure 2 and Figure 3 shown.
[0094] The accounts and permissions of multiple MQTT Brokers are as follows:
[0095] MQTT Broker: Alice has the public and private keys of the blockchain BC1 account. The smart contract MQTTBrokerManager on BC1 has been registered and authorized.
[0096] MQTT Broker: Bob has the public and private keys of the blockchain BC2 account. The smart contract MQTTBrokerManager on BC2 has been registered and authorized.
[0097] Alice and Bob have already established an MQTT connection directly through non-blockchain methods, that is, Alice's Client CA is in Bob's whitelist and has access to Bob's MQTT Client password. Similarly, Bob's Client CA is in Alice's whitelist and has access to Alice's MQTT Client password.
[0098] Step S3.1: Contract mapping is performed between the first MQTT Broker (Alice) and the first blockchain BC1 and the second blockchain BC2 at the same time;
[0099] Step S3.2: When the message sent by the first MQTT Broker (Alice) to the Topic is directed to the first blockchain BC1 where it is located, the BC1 account of the first MQTT Broker (Alice) is used to convert the message body into a Web3JSON-RPC structure, and the corresponding smart contract method of the blockchain BC1 is called; when the message sent by the first MQTT Broker (Alice) to the Topic is directed to the second blockchain BC2, the message is signed with a private key and sent to the third MQTT Broker (Bob) located on the second blockchain BC2 through the cascade message between the MQTT Brokers;
[0100] Step S3.3: Through the Topic mapping proxy of the third MQTT Broker (Bob), the message body is signed and then converted into a Web3 JSON-RPC structure to call the corresponding smart contract method of blockchain BC2. The notification of blockchain messages is also the same topic mapping proxy method.
[0101] Due to the lack of hardware computing and storage capabilities and security issues, it is difficult for IoT devices to directly hold the public and private key pairs of the blockchain. Through the capabilities of MQTT Broker, the proxy of IoT devices can be put on the chain. At the same time, Brokers can realize the on-chain identity based on the trust mechanism of blockchain, and conduct trusted data interaction between Brokers. Further, the blockchain can be used to confirm the ownership and account of the interactive data, and the cascade between Brokers can realize the cross-chain technology of the Internet of Things. The mapping between MQTT Topic and blockchain smart contracts is defined at the protocol level, which solves the problem that the off-chain data protocol and the on-chain data protocol can be converted without any changes on the IoT device side.
[0102] The present invention also provides an IoT cross-chain system based on the MQTT protocol, comprising the following modules:
[0103] Module M1: Establishing the blockchain account of MQTT Broker;
[0104] Module M1 includes the following submodules:
[0105] Module M1.1: Establish an independent blockchain account role and public-private key pair for MQTT Broker; establish the registered identity of MQTT Broker in the smart contract MQTTBrokerManager on the blockchain, establish a connection with the blockchain node, and monitor messages on the smart contract MQTTBrokerManager;
[0106] Module M1.2: Define the mapping agent between MQTT Topic and blockchain smart contract;
[0107] Module M1.2 includes:
[0108] Mapping Topic definition structure 1: blockchain abbreviation symbol / blockchain network number / smart contract address;
[0109] Mapping Topic definition structure 2: blockchain abbreviation symbol / blockchain network number / smart contract alias;
[0110] The structure of MQTT Message supports the direct use of the structure of Web3 JSON-RPC;
[0111] Supports user-configured conversion scripts for Topic Message and Web3 JSON-RPC.
[0112] Module M1.3: Establish MQTT Broker cascade identity; access the MQTT Client account and Client CA certificate of other Brokers, establish bridges with other MQTT Brokers, and form cascades between multiple Brokers.
[0113] Module M2: Establish a trusted connection between MQTT Broker and other Brokers on the blockchain;
[0114] Module M2 includes the following submodules:
[0115] Module M2.1: Initiate a connection request through the first MQTT Broker to the second MQTT Broker on the same blockchain, so that the first MQTT Broker sends encrypted data to the on-chain contract and indicates the address of the second MQTT Broker; the encrypted data is: the first MQTT Broker's Client, CA certificate, IP address port and the second MQTT Broker's public key information are packaged as a whole and asymmetrically encrypted using the first MQTT Broker's private key;
[0116] Module M2.2: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the first MQTTBroker, has been legally registered. If legal, notify the second MQTT Broker through a smart contract message, which contains the requested req-id;
[0117] Module M2.3: Call the smart contract method through the second MQTT Broker to obtain the data packet corresponding to the request req-id, verify the signature of the data packet, and determine whether it is the first MQTT Broker;
[0118] Module M2.4: Asymmetrically decrypt the encrypted data packet using the private key of the second MQTT Broker to obtain the information of the first MQTT Broker;
[0119] Module M2.5: When the second MQTT Broker refuses the connection, the method of the smart contract MQTTBrokerManager is called to notify the rejection of the request of the first MQTT Broker; when the second MQTT Broker agrees to the connection, the Client and CA certificate contents of the first MQTT Broker are added to the local whitelist, and the access password of the Client of the first MQTT Broker is generated and packaged together, and asymmetric encryption is performed through the private key of the second MQTT Broker, and the authorization connection method of the smart contract MQTTBrokerManager is called to notify the approval of Alice's connection request;
[0120] Module M2.6: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the second MQTTBroker, the contract caller, has been legally registered. If legal, the first MQTT Broker is notified through a smart contract message that the authorization has been granted, and the notification contains the req-id of this request;
[0121] Module M2.7: The first MQTT Broker calls the smart contract method to obtain the data packet of the second MQTT Broker requesting req-id authorization, verifies the signature of the data packet, uses the private key of the first MQTT Broker for asymmetric decryption, and obtains the access password for authorizing access to the Client;
[0122] Module M2.8: Use the Client access password of the first MQTT Broker to establish an MQTT secure connection with the second MQTT Broker.
[0123] Module M3: Establish a cross-chain network formed by multiple MQTT Brokers.
[0124] Module M3 includes the following submodules:
[0125] Module M3.1: Contract mapping of the first MQTT Broker with the first blockchain BC1 and the second blockchain BC2;
[0126] Module M3.2: When the message sent by the first MQTT Broker to the Topic is directed to the first blockchain BC1 where it is located, the BC1 account of the first MQTT Broker is used to convert the message body into a Web3 JSON-RPC structure and call the corresponding smart contract method of the blockchain BC1; when the message sent by the first MQTT Broker to the Topic is directed to the second blockchain BC2, the message is signed with a private key and sent to the third MQTT Broker located on the second blockchain BC2 through the cascade message between MQTT Brokers;
[0127] Module M3.3: Through the Topic mapping agent of the third MQTT Broker, the message body is signed and then converted into a Web3 JSON-RPC structure, calling the corresponding smart contract method of blockchain BC2.
[0128] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.
[0129] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. An IoT cross-chain method based on the MQTT protocol, characterized in that: The following steps are involved: Step S1: Create a blockchain account for MQTT Broker; Step S2: Establish a trusted connection between the MQTT Broker and other Brokers on the blockchain; Step S3: Establish a cross-chain network formed by multiple MQTT Brokers; The step S1 comprises the following sub-steps: Step S1.1: Establish an independent blockchain account role and public-private key pair for MQTT Broker; establish the registered identity of MQTT Broker in the smart contract MQTTBrokerManager on the blockchain, establish a connection with the blockchain node, and listen to messages on the smart contract MQTTBrokerManager; Step S1.2: Define the mapping agent between MQTT Topic and blockchain smart contract; Step S1.3: Establish MQTT Broker cascade identity; access the MQTT Client account and ClientCA certificate of other Brokers, establish bridges with other MQTT Brokers, and form cascades between multiple Brokers; The step S2 comprises the following sub-steps: Step S2.1: Initiate a connection request through the first MQTT Broker to the second MQTT Broker on the same blockchain, so that the first MQTT Broker sends encrypted data to the on-chain contract and indicates the address of the second MQTT Broker; the encrypted data is: the first MQTT Broker's Client, CA certificate, IP address port and the second MQTT Broker's public key information are packaged as a whole, and asymmetrically encrypted using the first MQTT Broker's private key; Step S2.2: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the first MQTT Broker, has been legally registered. If legal, notify the second MQTT Broker through a smart contract message, which contains the requested req-id; Step S2.3: The second MQTT Broker calls the smart contract method to obtain the data packet corresponding to the request req-id, verifies the signature of the data packet, and determines whether it is the first MQTT Broker; Step S2.4: Asymmetrically decrypt the encrypted data packet using the private key of the second MQTT Broker to obtain the information of the first MQTT Broker; Step S2.5: When the second MQTT Broker refuses the connection, the method of the smart contract MQTTBrokerManager is called to notify the rejection of the request of the first MQTT Broker; when the second MQTT Broker agrees to the connection, the Client and CA certificate contents of the first MQTT Broker are added to the local whitelist, and the access password of the Client of the first MQTT Broker is generated and packaged together, and asymmetric encryption is performed through the private key of the second MQTT Broker, and the authorization connection method of the smart contract MQTTBrokerManager is called to notify the approval of Alice's connection request; Step S2.6: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the second MQTT Broker, has been legally registered. If legal, notify the first MQTT Broker through a smart contract message that it has been authorized, and the notification contains the req-id of this request; Step S2.7: The first MQTT Broker calls the smart contract method to obtain the data packet for requesting req-id authorization from the second MQTT Broker, verifies the signature of the data packet, and uses the private key of the first MQTT Broker for asymmetric decryption to obtain the access password for authorizing access to the Client; Step S2.8: Establish an MQTT secure connection with the second MQTT Broker using the Client access password through the first MQTT Broker; The step S3 comprises the following sub-steps: Step S3.1: Contract mapping is performed between the first MQTT Broker and the first blockchain BC1 and the second blockchain BC2 at the same time; Step S3.2: When the message sent by the first MQTT Broker to the Topic is directed to the first blockchain BC1 where it is located, the BC1 account of the first MQTT Broker is used to convert the message body into a Web3 JSON-RPC structure and call the corresponding smart contract method of the blockchain BC1; When the message sent by the first MQTT Broker to the Topic is directed to the second blockchain BC2, the message is signed with a private key and sent to the third MQTT Broker located on the second blockchain BC2 through the cascade message between the MQTT Brokers, wherein the first MQTT Broker and the third MQTT Broker establish a connection through a non-blockchain method; Step S3.3: Through the Topic mapping agent of the third MQTT Broker, the message body is signed and then converted into a Web3JSON-RPC structure, and the corresponding smart contract method of blockchain BC2 is called.
2. The IoT cross-chain method based on the MQTT protocol according to claim 1 is characterized in that: The step S1.2 comprises: Mapping Topic definition structure 1: blockchain abbreviation symbol / blockchain network number / smart contract address; Mapping Topic definition structure 2: blockchain abbreviation symbol / blockchain network number / smart contract alias; The structure of MQTT Message supports the direct use of the structure of Web3 JSON-RPC; Supports user-configured conversion scripts for Topic Message and Web3 JSON-RPC.
3. An IoT cross-chain system based on the MQTT protocol, characterized in that: Includes the following modules: Module M1: Establishing the blockchain account of MQTT Broker; Module M2: Establish a trusted connection between MQTT Broker and other Brokers on the blockchain; Module M3: Establish a cross-chain network formed by multiple MQTT Brokers; The module M1 includes the following submodules: Module M1.1: Establish an independent blockchain account role and public-private key pair for MQTT Broker; establish the registered identity of MQTT Broker in the smart contract MQTTBrokerManager on the blockchain, establish a connection with the blockchain node, and monitor messages on the smart contract MQTTBrokerManager; Module M1.2: Define the mapping agent between MQTT Topic and blockchain smart contract; Module M1.3: Establish MQTT Broker cascade identity; access the MQTT Client account and ClientCA certificate of other Brokers, establish bridges with other MQTT Brokers, and form cascades between multiple Brokers; The module M2 Includes the following submodules: Module M2.1: Initiate a connection request through the first MQTT Broker to the second MQTT Broker on the same blockchain, so that the first MQTT Broker sends encrypted data to the on-chain contract and indicates the address of the second MQTT Broker; the encrypted data is: the first MQTT Broker's Client, CA certificate, IP address port and the second MQTT Broker's public key information are packaged as a whole and asymmetrically encrypted using the first MQTT Broker's private key; Module M2.2: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the contract caller, the first MQTT Broker, has been legally registered. If legal, notify the second MQTT Broker through a smart contract message, which contains the requested req-id; Module M2.3: Call the smart contract method through the second MQTT Broker to obtain the data packet corresponding to the request req-id, verify the signature of the data packet, and determine whether it is the first MQTT Broker; Module M2.4: Asymmetrically decrypt the encrypted data packet using the private key of the second MQTT Broker to obtain the information of the first MQTT Broker; Module M2.5: When the second MQTT Broker refuses the connection, the method of the smart contract MQTTBrokerManager is called to notify the rejection of the request of the first MQTT Broker; when the second MQTT Broker agrees to the connection, the Client and CA certificate contents of the first MQTT Broker are added to the local whitelist, and the access password of the Client of the first MQTT Broker is generated and packaged together, and asymmetric encryption is performed through the private key of the second MQTT Broker, and the authorization connection method of the smart contract MQTTBrokerManager is called to notify the approval of Alice's connection request; Module M2.6: Use the blockchain smart contract MQTTBrokerManager to identify whether the identity of the second MQTT Broker of the contract caller has been legally registered. If legal, notify the first MQTT Broker through a smart contract message that it has been authorized, and the notification contains the req-id of this request; Module M2.7: The first MQTT Broker calls the smart contract method to obtain the data packet of the second MQTT Broker requesting req-id authorization, verifies the signature of the data packet, uses the private key of the first MQTT Broker for asymmetric decryption, and obtains the access password for authorizing access to the Client; Module M2.8: Use the Client access password of the first MQTT Broker to establish an MQTT secure connection with the second MQTT Broker; The module M3 includes the following submodules: Module M3.1: Contract mapping of the first MQTT Broker with the first blockchain BC1 and the second blockchain BC2; Module M3.2: When the message sent by the first MQTT Broker to the Topic is directed to the first blockchain BC1 where it is located, the BC1 account of the first MQTT Broker is used to convert the message body into a Web3 JSON-RPC structure and call the corresponding smart contract method of the blockchain BC1; When the message sent by the first MQTT Broker to the Topic is directed to the second blockchain BC2, the message is signed with a private key and sent to the third MQTT Broker located on the second blockchain BC2 through the cascade message between the MQTT Brokers, wherein the first MQTT Broker and the third MQTT Broker establish a connection through a non-blockchain method; Module M3.3: Through the Topic mapping agent of the third MQTT Broker, the message body is signed and then converted into a Web3JSON-RPC structure, calling the corresponding smart contract method of blockchain BC2.
4. The IoT cross-chain system based on the MQTT protocol according to claim 3 is characterized in that: The module M1.2 includes: Mapping Topic definition structure 1: blockchain abbreviation symbol / blockchain network number / smart contract address; Mapping Topic definition structure 2: blockchain abbreviation symbol / blockchain network number / smart contract alias; The structure of MQTT Message supports the direct use of the structure of Web3 JSON-RPC; Supports user-configured conversion scripts for Topic Message and Web3 JSON-RPC.
