Smart agriculture smart contract authentication method and system based on blockchain
Through the blockchain smart contract authentication method, the problems of equipment authentication and data transmission security in the smart agricultural system are solved, efficient authentication and key negotiation between devices are realized, and the security and reliability of data transmission are ensured.
Patent Information
- Application Number
- CN202310425446.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-17
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2043-04-17
AI Technical Summary
In smart agricultural systems based on blockchain, the wide distribution and uncontrollability of equipment make it difficult to guarantee the security and reliability of data during transmission and recording, especially in device-to-device and device-to-gateway authentication and keys. During the negotiation process.
Adopting a blockchain-based smart agriculture smart contract authentication method, through system parameter creation, IoT device registration, gateway node and edge server registration, authentication and key negotiation between devices, dynamic device addition, and block creation and smart contracts Consensus mechanism ensures secure authentication and data transmission between devices. Specific steps include using Galois field elliptic curves and SHA-256 hash functions for key management and certificate generation, achieving mutual authentication and key negotiation between devices, and verifying and adding blocks through smart contract mechanisms.
It achieves efficient authentication and key negotiation from device to device and device to gateway, ensures the security and reliability of data transmission, enhances the transparency and traceability of the blockchain system, and solves the security problem in the process of device authentication and data transmission. Sexual issues.
Smart Images

Figure CN118300806B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of agricultural blockchain technology, and in particular to a blockchain-based smart agriculture smart contract authentication method and system. Background Art
[0002] Blockchain is an open distributed database. With it, we can share information between untrusted third parties without worrying about privacy leaks. At the same time, due to the decentralized nature of blockchain, we can share and verify data between untrusted third parties. This provides a new way to solve the trust problem in traditional industries. For smart agriculture, the most important role of blockchain technology is to solve the information asymmetry problem in the agricultural product supply chain. There are many information islands in the supply chain, and traditional agriculture still has many problems.
[0003] Smart farming technology based on blockchain can provide farmers with agricultural data instantly on an integrated platform. Blockchain allows the integrity of data to be thoroughly checked using various encryption techniques, and the data is stored after consensus is reached on its content, and no tampering of the data after storage is allowed. This persistence and auditability of stored data provides confidence that the correct data is used when needed later, and increases transparency, anonymity and traceability. The use of blockchain in agriculture can reduce uncertainty in yields by increasing the predictability of yields, increase the profits obtained, and also reduce the waste of resources. In the agricultural context, some data in the production process may be private data of specific stakeholders, while certain other data must be made available to some or all stakeholders to maintain transparency. Data such as transaction details between farmers and agricultural companies must be kept confidential from farmers and companies.
[0004] The best way to apply blockchain technology in the field of smart agriculture is to combine it with the Internet of Things technology. The Internet of Things can monitor the agricultural production environment in real time, collect data and store it in blocks in the blockchain. The persistence and auditability of the data provide confidence in using the correct data when needed in the future, while increasing transparency, anonymity and traceability. Based on the data input from all parties, the smart contract in the blockchain automatically executes the program. However, due to the wide distribution of equipment and the uncontrollability of equipment, smart agriculture based on blockchain urgently needs an efficient equipment authentication mechanism to ensure the security and reliability of data during transmission and recording. Summary of the invention
[0005] In view of the above-mentioned defects of the prior art, the present invention proposes a blockchain-based smart agricultural smart contract authentication method and system. The device-to-device authentication stage and the device-to-gateway authentication stage support mutual authentication and key negotiation between two IoT devices and between IoT devices and gateway nodes, respectively. The edge server creates a data block on the IoT device authentication data received from the GWN and sends the data block to the cloud server. The consensus mechanism based on the smart contract allows the P2P network to verify and add the formed blocks.
[0006] To achieve the above purpose, the present invention adopts the following technical solution: a blockchain-based smart agricultural smart contract authentication method, comprising the following steps:
[0007] Step 1: Create system parameters;
[0008] Step 2: Register IoT devices;
[0009] Step 3: Register the gateway node, edge server and cloud server;
[0010] Step 4: Authentication and key negotiation between IoT devices and between IoT devices and gateways;
[0011] Step 5: Add dynamic IoT devices;
[0012] Step 6: Create blocks, conduct block authentication and consensus based on smart contracts to realize blockchain creation.
[0013] Furthermore, the system parameters created in step 1 are specifically:
[0014] Step 1.1: The smart agriculture management center selects a Galois field GF q Non-singular elliptic curve E on q (a,b)=y 2 =x 3 +ax+b(mod q)∪{O}, where O is a point at infinity, a and b are integer fields Z of order p q Two random numbers on , and satisfy 4a 3 +27b 2 ≠0(mod q), under the above parameter settings, the smart agriculture management center selects the elliptic curve E q A generator of (a,b);
[0015] Step 1.2: Define H(·) as the SHA-256 hash function, which is used by the smart agriculture management center when using H(·) as the processing consensus mechanism of the cloud server;
[0016] Step 1.3: The Smart Agriculture Management Center selects a random number mk RA ∈Z pAs the master key, and broadcast the system public parameters {E q (A, b), G, H(·)}.
[0017] Furthermore, the IoT device registration in step 2 is specifically as follows:
[0018] Step 2.1: When the ID S After the IoT device initiates a registration request to the Smart Agriculture Management Center, the Smart Agriculture Management Center assigns it a temporary identifier TID S , select a random secret value s1∈Z q , and calculate its pseudo-random identifier RID S =H(ID S ||s1||mk RA );
[0019] Step 2.2: The Smart Agriculture Management Center selects a random number pr for the IoT device s ∈Z q As the private key, and calculate the corresponding public key as Pub s =pr s G and temporary digital certificate TC S =H(RID S ||pr s ||mk RA ||T S ), where T S The timestamp when the registration action occurs;
[0020] Step 2.3: The smart agriculture management center preloads the registration tuple {(RID S ,TID S ,TC S ),E q (a,b),G,H(·),(pr s ,Pub S )} and publish its public key S Public release.
[0021] Furthermore, the gateway node, edge server and cloud server registration in step 3 are specifically as follows:
[0022] Step 3.1: Identify as ID G ,ID E ,ID C The gateway node, edge server and cloud server initiate registration requests to the smart agriculture management center respectively, and the smart agriculture management center assigns them temporary identifiers TID respectively G ,TID E ,TID C; Then, the smart agriculture management center selects random numbers g1,e1,c1∈Z q , and calculate the pseudo-random identifier RID respectively G =H(ID G ||g1||mk RA ||T G ), RID E =H(ID E ||g1||mk RA ||T E ), RID C =H(ID C ||g1||mk RA ||T C ), where T G , T E , T C These are the timestamps when the registration behavior of the gateway node, edge server, and cloud server occurs respectively;
[0023] Step 3.2: The smart agriculture management center preloads data registration tuples to the gateway node
[0024] {(RID G ,TID G ),(RID S ,TID S ,TC S ),E q (a, b), G, H(·)};
[0025] Then, the gateway node selects a random number pr G ∈Z q as the private key, and calculate the associated public key as Pub G =r G ·; Next, the gateway node stores the following registration tuple in the secure database and publishes its public key Pub G ;
[0026] {(RID G ,TID G ),(RID S ,TID S ,TC S ),(pr s ,Pub S ),E q (a, b), G, H(·)};
[0027] Step 3.3: The Smart Agriculture Management Center sends the following digital certificates to the edge server through a secure channel
[0028] {(RID E ,TIDE ),{(RID G )},H(·),E q (a,b),G};
[0029] The edge server selects a random number pr E ∈Z q as the private key, and calculate the associated public key as Pub E =pr E G, then the edge server stores the following registration tuple in the secure database and publishes its public key Pub E
[0030] {(RID E ,TID E ),{(RID G )},(pr E ,Pub E ),E q (a, b), G, H(·)};
[0031] Step 3.4: The Smart Agriculture Management Center sends the following digital certificates to the cloud server through a secure channel
[0032] {(RID C ,TID C ),{(RID E )},H(·),E q (a,b),G};
[0033] The cloud server selects a random number pr C ∈Z q as the private key, and calculate the associated public key as Pub C =pr C G, then the edge server stores the following registration tuple in the secure database and publishes its public key Pub C
[0034] {(RID C ,c),{(RID E )},(pr C ,Pub C ),E q (a, b), G, H(·)}.
[0035] Furthermore, the authentication and key negotiation between IoT devices and between IoT devices and gateways in step 4 is specifically as follows:
[0036] Step 4.1: IoT device 1 selects a random number r S1 ∈Z q , and combined with the current timestamp T S1 To calculate the generated about rS1 Signature S1 :c=H(c||TC s1 ||pr S1 ||T S1 ||r S1 ),c=x S1 ·G, Sig S1 =x S1 +H(TID S1 ||Pub S1 ||T S1 )*pr S1 (mod q); IoT device 1 sends the authentication request information Msg according to the above calculation. D1D2 ={TID S1 ,X S1 ,Sig S1 ,Pub S1 ,T S1}Sent to IoT device 2 via the public network;
[0037] Step 4.2: Assume that IoT device 2 receives the authentication request message Msg D1D2 The time is It first compares the inequality To check whether the request information has passed the validity period △T; if the inequality is established, the IoT device 2 compares the equation Sig S1 G = X S1 +H(TID S1 ||Pub S1 ||T S1 )·Pub S1 Is it true? If true, then sign Sig S1 Valid, otherwise invalid, IoT device 2 selects a random number r S2 ∈Z q , and combined with the current timestamp T S2 To calculate the public and private key pair y of IoT device 2 S2 =H(TID S2 ||RID S2 ||TC s2 ||r s2 ||pr s2 ||T s2 ), y S2 =y S2 G;
[0038] Step 4.3: Assume that IoT device 1 receives the authentication response message Msg D2D1 The time is It first compares the inequality To check whether the response information has passed the validity period △T; if the inequality holds, the IoT device 1 calculates the session key SK S1S2 =x S1 ·Y S2 ; IoT device 1 compares the equation Sig S2 G = Y S2 +H(TID S2 ||TID S1 ||Pub S2 ||SK S1S2 ||T S2 )·Pub S2 , and then use the current timestamp T S′ , calculate the session key verification parameter SKV S1S2 =H(SK S1S2 ||T S′ ), and send the authentication feedback information Msg D1D2′ ={SKV S1S2 ,T S′}Sent to IoT device 2 via a secure channel;
[0039] Step 4.4: Assume that IoT device 2 receives authentication feedback information Msg D1D2′ The time is It first compares the inequality To check whether the feedback information has passed the validity period △T; if the inequality holds, IoT device 2 calculates the session key verification parameter SKV S2S1 =H(SK S2S1 ||T S′ ) and determine SKV S1S2 =SKV S2S1 Is it true? If so, the session key negotiation between IoT device 1 and IoT device 2 is successful, and they can communicate with each other through the key SKV S1S2 =SKV S2S1 Realize the transmission of encrypted data;
[0040] Step 4.5: IoT device selects a random number p S ∈Z q , and combined with the current timestamp T S To calculate p S Signature S : A S =H(TID S ||p S ||T S )·G, Sig S =H(TID S ||pS |T S )+H(x S ||TID S ||A S ||T S ||TC S )·pr S (mod q); Finally, the IoT device sends the authentication request information Msg D2G ={TIG S ,A S ,x S ,Sig S ,T S}Sent to the gateway node through a secure channel;
[0041] Step 4.6: Assume that the gateway node receives the authentication request message Msg D2G The time is It first compares the inequality To check whether the request information has passed the validity period △T; if the inequality holds, the gateway node compares the equation Sig S G=A S +H(x s ||TID S ||A s ||TC s ||T s )·Pub S Is it true? If true, then sign Sig S Valid (otherwise invalid), gateway node calculation In addition, the gateway node selects a random number q G ∈Z q , and combined with the current timestamp T G To calculate the authentication feedback information component B G =H(TID G ||q G ||RID S ||T G )·G,DK GS =H(TID G ||q G ||RID S ||T G )·A S ,
[0042] Step 4.7: Assume that the IoT device receives the authentication response message Msg G2D The time is It first compares the inequality To check whether the request information has passed the validity period △T; if the inequality holds, the IoT device calculates DK SG =H(TID S ||p S ||T S )·B G , The session key between it and the gateway node is then calculated as SK SG =H(DK SG ||H(pr S ||p S ||RID S ||T S )||z G ); Then, the IoT device verifies the signature Sig G Validity: Sig G G=B G +H(TID S ||TID G ||TC S ||y G ||Pub G ||T G )·Pub G ; If this equation holds true, it means that the signature Sig G Valid or invalid, IoT device computing Use with Replace the stored TID S ; In addition, the IoT device calculates the session key verification parameter And send the authentication feedback information Msg through the public channel D2G′ ={SKV SG ,T V}Send to the gateway node;
[0043] Step 4.8: Assume that the gateway node receives the authentication feedback message Msg D2G′ The time is It first compares the inequality To check whether the feedback information has exceeded the validity period △T; if the inequality holds, the gateway node calculates the session key verification parameter And judge SKV SG =SKV GS Is it true? If so, the session key negotiation between the IoT device and the gateway node is successful, and they can communicate with each other through the key SKV SG =SKV GS Realize the transmission of encrypted data.
[0044] Furthermore, the dynamic IoT device addition in step 5 is specifically as follows:
[0045] Step 5.1: The Smart Agriculture Management Center confirms the identification of the newly added IoT device Temporary identification Then a random secret value is picked and a pseudo-random identifier In addition, the Smart Agriculture Management Center selects random numbers And calculate its corresponding public key And combined with the current timestamp Calculate a temporary certificate for the newly added IoT device
[0046] Step 5.2: The Smart Agriculture Management Center will register the tuple Preload the newly registered IoT device; finally, the Smart Agriculture Management Center publicly releases the public key of the newly registered IoT device
[0047] Furthermore, the step 6 performs block creation, block authentication and consensus based on smart contracts, wherein:
[0048] The steps to create a block are:
[0049] Step 6.1: When the gateway node receives the data collected by IoT device i The gateway node uses the ECDSA signature algorithm, and the private key pr G and the current timestamp T G For transactions To sign: Where Z i is the number of the agricultural area where the IoT device i is located, Sig(·) is the signature algorithm of ECDSA;
[0050] The gateway node then sends the transaction information sent to a nearby edge server; if This means that the user id has not been added to the revocation list, so the revocation list is updated R′=R∪{id}; Similarly, if the transaction involves sensitive information that needs to be encrypted, the gateway node generates the signature Before, the transaction is encrypted. And generate encrypted transaction information Send to a nearby edge server;
[0051] Step 6.2: The edge server calls the ECDSA verification algorithm and the gateway node's public key Pub G To verify transaction information or Is the signature in the valid? If valid, the edge server will t TX i or crypto transactions Combined into a partial block PBlock i ; Each partial block contains the partial block version Block_Ver, edge server label, and block generation timestamp T ES , the root node of the Merkle tree is MTR TX , edge server tag, public key Pub for transaction verification G , ECDSA signature Sig ParBlock , and use the edge server's private key Pr E The generated partial block header; then the edge server sends the generated partial block to the cloud server;
[0052] The edge server will then generate some blocks Sent to the cloud server, where Sig ParBlock It uses the ECDSA signature algorithm and the edge server's private key Pr E The generated signature for this part of the block;
[0053] Step 6.3: The cloud server first uses the edge server's public key Pub E To verify the signature Sig ParBlock ; If the verification is successful, the cloud server calculates the hash value Cur_Block_Hash of the current block and adds the previous block hash value Pre_Block_Hash to it, thereby PBlocking some blocks. i Integrate into a complete block i ;
[0054] Block authentication and consensus based on smart contracts are as follows:
[0055] Step 6.4: Define N as the total number of cloud servers in the blockchain network, set the magic number Magic_Number = 2·(N-1) / 3+1, and define an empty set CMP i ;
[0056] Step 6.5: The cloud server as the head node broadcasts the newly added block to all cloud servers as replica nodes in the blockchain network. Each replica node sets the voting information Consen_Vote j =No, and calculate the hash value of the newly added block Block_Hash=H(Block i ); If Block_Hash = Cur_Block_Hash, and the public key Pub of the edge server is used EThe signature Sig is verified correctly ParBlock , then generate the n t TX i The root node of the Merkle tree is MTR′ TX ; If MTR′ TX =MTR TX , then set the voting information Consen_Vote j =YES; then the voting information Consen_Vote j Join the collection CMP i middle;
[0057] Step 6.6: Define the number of available nodes and their initial value as App Count = 0, for the set CMP i All voting information in Consen_Vote j =YES, then App Count =App Count +1; finally, if App Count ≥Magic_Number, then Block i Join the blockchain and broadcast the block status YES to the blockchain network.
[0058] Furthermore, the session key with IoT device 1 in step 4.2 is calculated as SK S2S1 =y S2 ·X S1 , IoT device 2 is the session key SK S2S1 Generate signature Sig S2 =y S2 +H(tID S2 ||TID S1 ||Pub S2 ||SK S2S1 ||T S2 )*pr S2 (mod q); Finally, IoT device 2 sends the following authentication feedback information to IoT device 1 through the public network: Msg D2D1 ={TID S2 ,Y S1 ,Sig S2 ,Pub S2 ,t S2}.
[0059] Furthermore, in step 4.6, the session key with the IoT device is calculated as SK GS =H(DK GS ||y S ||H(pr G ||TIDG ||RID G ||TC S ||T G )), the gateway node generates a new temporary identifier for the IoT device and encrypt it as Then, the gateway node calculates the G Signature G =H(TID G ||q G ||RID S ||T S )+H(TID S ||TID G ||TC S ||y G ||Pub G ||T S )·pr G (mod q), and send the authentication feedback information Return to the IoT device.
[0060] A system for implementing the above-mentioned blockchain smart agricultural smart contract authentication method includes: a smart city management center and an Internet of Things device, a gateway node, an edge server, and a cloud server connected to the smart city management center, wherein the Internet of Things device and the gateway node are connected, the gateway node and the edge server are connected, and the edge server and the cloud server are connected, wherein:
[0061] The smart city management center is used to create system parameters and receive registration requests from IoT devices, gateway nodes, edge servers, and cloud servers and issue certificates;
[0062] The IoT device and the gateway node are used for authentication and key negotiation between two IoT devices, and authentication and key negotiation between an IoT device and a gateway node;
[0063] The gateway nodes, edge servers, and cloud servers are used to implement sequential data transmission, perform block creation, and block authentication and consensus based on smart contracts to realize blockchain construction.
[0064] The present invention has the following technical effects: the device-to-device authentication stage and the device-to-gateway authentication stage of the present invention support mutual authentication and key negotiation between two IoT devices and between an IoT device and a gateway node, respectively. The edge server creates a data block on the IoT device authentication data received from the GWN and sends the data block to the cloud server. The consensus mechanism based on smart contracts allows the P2P network to verify and add the formed blocks. The present invention proposes an efficient device authentication mechanism for blockchain-based smart agriculture to ensure the security and reliability of data during transmission and recording. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] Figure 1 It is a specific algorithm flow chart of the present invention.
[0066] Figure 2 It is a specific structural topology diagram of the present invention. DETAILED DESCRIPTION
[0067] The following describes the preferred embodiments of the present invention with reference to the accompanying drawings to make the technical content clearer and easier to understand. The present invention can be embodied in many different forms of embodiments, and the protection scope of the present invention is not limited to the embodiments mentioned in the text.
[0068] Example 1
[0069] like Figure 1 As shown, the present invention proposes a blockchain-based smart agriculture smart contract authentication method, comprising the following steps:
[0070] Step 1: Create system parameters;
[0071] Step 2: Register IoT devices;
[0072] Step 3: Register the gateway node, edge server and cloud server;
[0073] Step 4: Authentication and key negotiation between IoT devices and between IoT devices and gateways;
[0074] Step 5: Add dynamic IoT devices;
[0075] Step 6: Create blocks, conduct block authentication and consensus based on smart contracts to realize blockchain creation.
[0076] 1. System initialization algorithm
[0077] In this phase of the algorithm, the Smart Agriculture Management Center creates the system and generates system public parameters according to the following steps:
[0078] Step 1.1: The smart agriculture management center selects a Galois field GF q Non-singular elliptic curve E onq (a,b)=y 2 =x 3 +ax+b(mod q)∪{O}, where O is a point at infinity, a and b are integer fields Z of order p q Two random numbers on , and satisfy 4a 3 +27b 2 ≠0(mod q), under the above parameter settings, the smart agriculture management center selects the elliptic curve E q A generator of (a,b).
[0079] Step 1.2: Define H(·) as the SHA-256 hash function. The smart agriculture management center uses H(·) as the processing consensus mechanism of the cloud server.
[0080] Step 1.3: The Smart Agriculture Management Center selects a random number mk RA ∈Z p As the master key, and broadcast the system public parameters {E q (a, b), G, H(·)}.
[0081] 2. IoT device registration algorithm
[0082] This algorithm mainly describes the registration method of various types of equipment in smart agriculture to join the system. The process is performed offline by the smart agriculture management center and is mainly divided into the following three steps:
[0083] Step 2.1: When the ID S After the IoT device initiates a registration request to the Smart Agriculture Management Center, the Smart Agriculture Management Center assigns it a temporary identifier TID S , select a random secret value s1∈Z q , and calculate its pseudo-random identifier RID S =H(ID S ||s1||mk RA ).
[0084] Step 2.2: The Smart Agriculture Management Center selects a random number pr for the IoT device s ∈Z q As the private key, and calculate the corresponding public key as Pub s =pr s G and temporary digital certificate TC S =H(RID S ||pr s ||mk RA ||T S ), where T S The timestamp when the registration action occurs.
[0085] Step 2.3: The Smart Agriculture Management Center preloads registration tuples to IoT devices
[0086] {(RID S ,TID S ,TC S ),E q (a,b),G,H(·),(pr s ,Pub S )} and publish its public key S Public release.
[0087] 3. Registration Algorithm for Gateway Nodes, Edge Servers, and Cloud Servers
[0088] The algorithm is executed offline by the Smart Agriculture Management Center to distinguish and determine the association between IoT devices and gateway nodes, edge servers and gateway nodes, and cloud servers and edge servers. This allows gateway nodes to collect data only from their associated smart devices, edge servers to receive data only from their associated gateway nodes, and cloud servers to receive data only from their associated edge servers. Specifically, this stage consists of the following steps:
[0089] Step 3.1: Identify as ID G ,ID E ,ID C The gateway node, edge server and cloud server initiate registration requests to the smart agriculture management center respectively, and the smart agriculture management center assigns them temporary identifiers TID respectively G ,TID E ,TID C Then, the Smart Agriculture Management Center selects random numbers g1,e1,c1∈Z q , and calculate the pseudo-random identifier RID respectively G =H(ID G ||g1||mk RA ||T G ), RID E =H(ID E ||g1||mk RA ||T E ), RID C =H(ID C ||g1||mk RA ||T C ), where T G , T E , T C They are the timestamps when the registration behavior of the gateway node, edge server and cloud server occurs respectively.
[0090] Step 3.2: The smart agriculture management center preloads data registration tuples to the gateway node
[0091] {(RID G ,TID G ),(RID S ,TID S ,TC S ),E q (a, b), G, H(·)}.
[0092] Then, the gateway node selects a random number pr G ∈Z q as the private key, and calculate the associated public key as Pub G =pr G G. Next, the gateway node stores the following registration tuple in the secure database and publishes its public key Pub G
[0093] {(RID G ,TID G ),(RID S ,TID S ,TC S ),(pr s ,Pub S ),E q (a, b), G, H(·)}.
[0094] Step 3.3: The Smart Agriculture Management Center sends the following digital certificates to the edge server through a secure channel
[0095] {(RID E ,TID E ),{(RID G )},H(·),E q (a,b),G}.
[0096] The edge server selects a random number pr E ∈Z q as the private key, and calculate the associated public key as Pub E =pr E G, then the edge server stores the following registration tuple in the secure database and publishes its public key Pub E
[0097] {(RID E ,TID E ),{(RID G )},(pr E ,Pub E ),E q (a, b), G, H(·)}.
[0098] Step 3.4: The Smart Agriculture Management Center sends the following digital certificates to the cloud server through a secure channel
[0099] {(RID C ,TID C ),{(RID E )},H(·),E q (,b),G}.
[0100] The cloud server selects a random number pr C ∈Z q as the private key, and calculate the associated public key as Pub C =pr C G, then the edge server stores the following registration tuple in the secure database and publishes its public key Pub C
[0101] {(RID C ,c),{(RID E )},(pr C ,Pub C ),E q (a, b), G, H(·)}.
[0102] 4. Device Authentication and Key Agreement Algorithm
[0103] The algorithm is divided into two parts, which respectively describe the authentication and key negotiation between two IoT devices and the authentication and key negotiation process between an IoT device and a gateway node. First, for the first part, assume that IoT device 1 needs to securely send its sensed data to another IoT device 2. Since both IoT devices are registered by the smart agriculture management center, the information available in their memory and the session key between them are used during the authentication process to achieve secure data transmission:
[0104] Step 4.1: IoT device 1 selects a random number r S1 ∈Z q , and combined with the current timestamp T S1 To calculate the generated about r S1 Signature S1 :c=H(c||TC S1 ||pr S1 ||T S1 ||r S1 ),c=x S1 ·G, Sig S1 =x S1 +H(TID S1 ||Pub S1 ||TS1 )*pr S1 (mod q). IoT device 1 sends the authentication request information Msg D1D2 ={TID S1 ,X S1 ,Sig S1 ,Pub S1 ,T S1}Sent to IoT device 2 via the public network.
[0105] Step 4.2: Assume that IoT device 2 receives the authentication request message Msg D1D2 The time is It first compares the inequality To check whether the request information has passed the validity period △T. If the inequality is established, the IoT device 2 compares the equation Sig S1 G = X S1 +H(TID S1 ||Pub S1 ||T S1 )·Pub S1 Is it true? If true, then sign Sig S1 Valid (otherwise invalid), IoT device 2 selects a random number r S2 ∈Z q , and combined with the current timestamp T S2 To calculate the private key y S2 =H(TID S2 ||RID S2 ||TC S2 ||r S2 ||pr S2 || S2 ) and public key Y S2 =y S2 G. Based on this, the session key with IoT device 1 is calculated as SK S2S1 =y S2 ·X S1 In addition, IoT device 2 is the session key SK S2s1 Generate signature Sig s2 =y s2 +H(TID S2 ||TID S1 ||Pub S2 ||SK S2S1 ||T S2 )*pr S2 (mod q). Finally, IoT device 2 sends the following authentication feedback information to IoT device 1 through the public network: Msg D2D1 ={TID S2 ,YS1 ,Sig S2 ,Pub s2 ,T S2}.
[0106] Step 4.3: Assume that IoT device 1 receives the authentication response message Msg D2D1 The time is It first compares the inequality To check whether the response message has passed the validity period △T. If the inequality holds, IoT device 1 calculates the session key SK S1S2 =x S1 ·Y S2 IoT device 1 compares the equation Sig S2 G = Y S2 +H(TID S2 ||TID S1 ||Pub S2 ||SK S1S2 ||T S2 )·Pub S2 , and then use the current timestamp T S′ , calculate the session key verification parameter SKV S1S2 =H(SK S1S2 ||T S′ ), and send the authentication feedback information Msg D1D2′ ={SKV S1S2 ,T S′}Sent to IoT device 2 through a secure channel.
[0107] Step 4.4: Assume that IoT device 2 receives authentication feedback information Msg D1D2′ The time is It first compares the inequality To check whether the feedback information has passed the validity period △T. If the inequality holds, IoT device 2 calculates the session key verification parameter SKV S2S1 =H(SK S2S1 ||T S′ ) and determine SKV S1S2 =SKV S2S1 If true, the session key negotiation between IoT device 1 and IoT device 2 is successful, and they can communicate with each other through the session key SK S1S2 =K S2S1 Realize the transmission of encrypted data.
[0108] For the second part, assume that the IoT device needs to securely send its sensing data to a gateway node. A secure key negotiation method is also required between them. The specific steps are as follows:
[0109] Step 4-5: IoT device selects random number p S ∈Z q , and combined with the current timestamp T S To calculate p S Signature S : A S =H(TID S ||p S ||T S )·G, Sig S =H(TID S ||p S ||T S )+H(x S ||TID S ||A S ||T S ||TC S )·pr S (mod q). Finally, the IoT device sends the authentication request message Msg D2G ={TID S ,A S ,x S ,Sig S ,T S}Sent to the gateway node through a secure channel.
[0110] Step 4-6: Assume that the gateway node receives the authentication request message Msg D2G The time is It first compares the inequality To check whether the request information has passed the validity period △T. If the inequality holds, the gateway node compares the equation Sig S G=A S +H(x S ||TID S ||A S ||TC S ||T S )·Pub S Is it true? If true, then sign Sig S Valid (otherwise invalid), gateway node calculation In addition, the gateway node selects a random number q G ∈Z q , and combined with the current timestamp T G To calculate the authentication feedback information component B G =H(TID G ||q G ||RID S ||TG )·G, And the session key middleware DK GS =H(TID G ||q G ||RID S ||T G )·A S On this basis, the session key with the IoT device is calculated as SK GS =H(DK GS ||y S ||H(pr G ||TID G ||RID G ||TC S ||T G )), In addition, the gateway node generates a new temporary identifier for the IoT device and encrypt it as Then, the gateway node calculates the signature Sig G =H(TID G ||q G ||RID S ||T S )+H(TID S ||TID G ||TC S ||y G ||Pub G ||T S )·pr G (mod q), and send the authentication feedback information Return to the IoT device.
[0111] Step 4-7: Assume that the IoT device receives the authentication response message Msg G2D The time is It first compares the inequality To check whether the request information has passed the validity period △T. If the inequality holds, the IoT device calculates the session key middleware DK SG =H(TID S ||p S ||T S )·B G , The session key between it and the gateway node is then calculated as SK SG =H(DK SG ||H(pr S ||p S ||RID S ||T S)||z G ). Subsequently, the IoT device verifies the signature Sig through the following formula G Validity: Sig G G=B G +H(TID S ||TID G ||TC S ||y G ||Pub G ||T G )·Pub G If this equation holds true, then the signature Sig G Effective (otherwise ineffective), IoT device computing H(SK GS ||T G ), and use Replace the stored TID S In addition, the IoT device calculates the session key verification parameter And send the authentication feedback information Msg through the public channel D2G′ ={SKV SG ,T V}Sent to the gateway node.
[0112] Step 4.8: Assume that the gateway node receives the authentication feedback message Msg D2G′ The time is It first compares the inequality To check whether the feedback information has exceeded the validity period △T. If the inequality holds, the gateway node calculates the session key verification parameter And judge SKV SG =SKV GS If true, the session key negotiation between the IoT device and the gateway node is successful, and they can communicate with each other through the session key SK SG =SK GS Realize the transmission of encrypted data.
[0113] 5. Dynamic IoT device addition algorithm
[0114] This phase is performed by the Smart Agriculture Management Center when existing IoT devices need to be replaced due to failure or suspected unsafe conditions. Specifically, the algorithm is divided into the following two steps:
[0115] Step 5.1: The Smart Agriculture Management Center confirms the identification of the newly added IoT device Temporary identification Then a random secret value is picked and a pseudo-random identifier In addition, the Smart Agriculture Management Center selects random numbers And calculate its corresponding public key And combined with the current timestamp Calculate a temporary certificate for the newly added IoT device
[0116] Step 5.2: The Smart Agriculture Management Center will register the tuple Preload the newly registered IoT device. Finally, the Smart Agriculture Management Center publicly releases the public key of the newly registered IoT device.
[0117] 6. Blockchain construction algorithm
[0118] This algorithm describes the processes related to block creation, smart contract-based block verification, and voting-based block addition consensus. The algorithm is divided into two modules: block creation, smart contract-based block authentication and consensus.
[0119] Block creation module: This module describes the process of creating blocks by the gateway node, which is divided into the following three steps:
[0120] Step 6.1: When the gateway node receives the data collected by IoT device i The gateway node uses the ECDSA signature algorithm, and the private key pr G and the current timestamp T G For transactions To sign: Where Z i is the number of the agricultural area where the IoT device i is located, and Sig(·) is the signature algorithm of ECDSA. The gateway node then sends the transaction information Send to a nearby edge server. If This means that the user id has not been added to the revocation list, so the revocation list is updated R′=R∪{id}. Similarly, if the transaction involves sensitive information that needs to be encrypted, the gateway node generates the signature. Before, the transaction is encrypted. And generate encrypted transaction information Send to a nearby edge server.
[0121] Step 6.2: The edge server calls the ECDSA verification algorithm and the gateway node's public key Pub G To verify transaction information or Is the signature in the valid? If valid, the edge server will t TX i or crypto transactions Combined into a partial block PBlock i ; Each partial block contains the partial block version Block_Ver, the timestamp T of the block generation ES , the root node of the Merkle tree is MTR TX , edge server tag, public key Pub for transaction verification G , ECDSA signature Sig ParBlock , and use the edge server's private key Pr E The edge server will then generate some of the block headers. Sent to the cloud server, where Sig ParBlock It uses the ECDSA signature algorithm and the edge server's private key Pr E The generated signature for this part of the block.
[0122] Step 6.3: The cloud server first uses the edge server's public key Pub E To verify the signature Sig ParBlock If the verification is successful, the cloud server calculates the hash value Cur_Block_Hash of the current block and adds the previous block hash value Pre_Block_Hash to it, thereby PBlocking the part of the block. i Integrate into a complete block i .
[0123] Block certification and consensus module based on smart contracts: This module describes how to add a block to the blockchain. In smart contracts, the technology enforces rules and stipulates what people can and cannot do. Smart contracts are applications or code snippets that are automatically executed in a deterministic manner on the blockchain. Smart contracts are immutable, so once a smart contract is deployed, it cannot be modified. In addition, smart contracts are decentralized, and no single entity controls the state or execution of smart contracts. The cloud servers in the blockchain network use a voting-based consensus algorithm to achieve consensus on a given block: one node acts as the head node, and the other nodes are called replica nodes. The head node is responsible for initiating a proposal to add a block to the blockchain, and the head node role is transferred in a polling manner. Consensus is declared when a positive response from 2 / 3 nodes is received, and up to 1 / 3 of the nodes in the system are allowed to fail or go offline.
[0124] Specifically, this module is divided into the following steps:
[0125] Step 6.4: Define N as the total number of cloud servers in the blockchain network, set the magic number Magic_Number = 2·(N-1) / 3+1, and define an empty set CMP i .
[0126] Step 6.5: The head node (cloud server) broadcasts the newly added block to all replica nodes (cloud servers) in the blockchain network, and each replica node sets the voting information Consen_Vote j =No, and calculate the hash value of the newly added block Block_Hash=H(Block i ). If Block_Hash = Cur_Block_Hash, and the public key Pub of the edge server is used E The signature Sig is verified correctly ParBlock , then generate the n t TX i The root node of the Merkle tree MtR′ TX If MTR′ Tx =MTR TX , then set the voting information Consen_Vote j =YES. Then the voting information Consen_Vote j Join the collection CMP i middle.
[0127] Step 6.6: Define the number of available nodes and their initial value as App Count = 0, for the set CMP i All voting information in Consen_Vote j =YES, then App Count =App Count +1. Finally, if App Count ≥Magic_Number, then Block i Join the blockchain and broadcast the block status YES to the blockchain network.
[0128] The blockchain-based smart agricultural smart contract authentication method proposed in this invention works as follows:
[0129] Assume that there are multiple agricultural areas, each of which can be divided into multiple farms, and IoT smart devices are placed in each agricultural area to collect nearby environmental data. The data is then assigned to a gateway node, which collects data from smart devices in all its areas. The data from smart devices can be forwarded to the gateway node in a hop-by-hop forwarding manner. The gateway node has the collected sensor data (transactions) as well as other data (transactions), such as transaction details between farmers and agricultural companies, chemicals used to preserve agricultural products, the quantity and quality of fertilizers used in growing crops, and the economic benefits of agricultural products. The gateway node then forwards these transactions to the edge server to perform initial processing and create partial blocks. Before this, it is necessary to determine which transactions in the received block should be encrypted and which transactions do not need to be encrypted to form a hybrid blockchain. The processed data is then sent to the blockchain cloud center in the form of partial blocks, which consists of multiple cloud servers with smart contract functions. The smart contract is first used by the cloud server to verify the received partial block. Once it is verified, the cloud server creates the full block, executes the consensus algorithm with other cloud servers, and then executes to add the full block to the blockchain.
[0130] Example 2
[0131] like Figure 2 As shown, the present invention provides a system for implementing the smart agricultural smart contract authentication method of the above-mentioned blockchain, including: a smart city management center and an Internet of Things device, a gateway node, an edge server, and a cloud server connected to the smart city management center, the Internet of Things device and the gateway node are connected, the gateway node and the edge server are connected, and the edge server and the cloud server are connected, wherein:
[0132] Smart city management center, used to create system parameters and receive registration requests from IoT devices, gateway nodes, edge servers, and cloud servers and issue certificates;
[0133] IoT devices and gateway nodes are used for authentication and key negotiation between two IoT devices, and between an IoT device and a gateway node;
[0134] Gateway nodes, edge servers, and cloud servers are used to implement sequential data transmission, block creation, block authentication and consensus based on smart contracts, and realize blockchain construction.
[0135] The above system of the present invention implements device-to-device (D2D) authentication and device-to-gateway (D2G) authentication. The authentication stage supports mutual authentication and key negotiation between two IoT devices and between an IoT device and a gateway node (GWN). The edge server (ES) creates a data block on the IoT device authentication data received from the GWN and sends the data block to the cloud server (CS). The consensus mechanism based on smart contracts allows the P2P network to verify and add to the formed blocks.
[0136] The preferred specific embodiments of the present invention are described in detail above. It should be understood that ordinary technicians in the field can make many modifications and changes based on the concept of the present invention without creative work. Therefore, all technical solutions that can be obtained by technicians in the technical field based on the concept of the present invention through logical analysis, reasoning or limited experiments on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. Smart agricultural smart contract authentication method based on blockchain, It is characterized in that The following steps are involved: Step 1: Create system parameters; Step 2: Register IoT devices; Step 3: Register the gateway node, edge server and cloud server; Step 4: Authentication and key negotiation between IoT devices and between IoT devices and gateways; Step 5: Add dynamic IoT devices; Step 6: Create blocks, conduct block authentication and consensus based on smart contracts, and realize blockchain creation; The specific system parameters created in step 1 are: Step 1.1: The Smart Agriculture Management Center selects a Galois field Non-singular elliptic curves on ,in is a point at infinity, for p Integer field Two random numbers on , and satisfy , under the above parameter settings, the smart agriculture management center selects the elliptic curve A generator of ; Step 1.2: Definition It is the SHA-256 hash function used by the Smart Agriculture Management Center Used as a consensus mechanism for cloud servers; Step 1.3: Smart Agriculture Management Center selects random numbers As the master key, and broadcast the system public parameters ; The specific registration of IoT device in step 2 is as follows: Step 2.1: When the marker is After the IoT device initiates a registration request to the Smart Agriculture Management Center, the Smart Agriculture Management Center assigns it a temporary identifier. , pick a random secret value , and calculate its pseudo-random identifier ; Step 2.2: The Smart Agriculture Management Center selects a random number for the IoT device As the private key, and calculate the corresponding public key as And temporary digital certificates ,in The timestamp when the registration action occurs; Step 2.3: The Smart Agriculture Management Center preloads registration tuples to IoT devices , and its public key Public release; The gateway node, edge server and cloud server registration in step 3 are specifically as follows: Step 3.1: The labels are , , The gateway node, edge server and cloud server initiate registration requests to the smart agriculture management center respectively, and the smart agriculture management center assigns temporary identifiers to them respectively. , T , ; Then, the Smart Agriculture Management Center selects a random number , and calculate the pseudo-random identifier , , ,in , , These are the timestamps when the registration behavior of the gateway node, edge server, and cloud server occurs respectively; Step 3.2: The smart agriculture management center preloads data registration tuples to the gateway node ; Then, the gateway node selects a random number as the private key, and calculate the associated public key as ; Next, the gateway node stores the following registration tuple in the secure database and publishes its public key ; ; Step 3.3: The Smart Agriculture Management Center sends the following digital certificates to the edge server through a secure channel ; Edge server selects random number as the private key, and calculate the associated public key as , then the edge server stores the following registration tuple in the secure database and publishes its public key ; Step 3.4: The Smart Agriculture Management Center sends the following digital certificates to the cloud server through a secure channel ; Cloud server selects random number as the private key, and calculate the associated public key as , then the edge server stores the following registration tuple in the secure database and publishes its public key ; The authentication and key negotiation between IoT devices and between IoT devices and gateways in step 4 are as follows: Step 4.1: IoT device 1 selects a random number , and combined with the current timestamp To calculate the generated Signature : , = , IoT device 1 sends the authentication request information based on the above calculations Send to IoT device 2 via a public network; Step 4.2: Assume that IoT device 2 receives the authentication request message The time is , which first compares the inequality To check whether the request information has expired ; If the inequality holds, IoT device 2 compares the equation Is it true? If so, sign it. Valid, otherwise invalid, IoT device 2 selects a random number , and combined with the current timestamp To calculate , ; Step 4.3: Assume that IoT device 1 receives the authentication response message The time is , which first compares the inequality To check whether the response information has expired ; If this inequality holds, IoT device 1 calculates the session key ; IoT device 1 compares the equation , and then use the current timestamp , calculate the session key verification parameters , and provide certification feedback information Send to IoT device 2 via a secure channel; Step 4.4: Assume that IoT device 2 receives authentication feedback information The time is , which first compares the inequality To check whether the feedback information has expired ; If the inequality holds, IoT device 2 calculates the session key verification parameter , and judge Is it true? If so, the session key negotiation between IoT device 1 and IoT device 2 is successful, and they can communicate through the key Realize the transmission of encrypted data; Step 4.5: IoT device selects random number , and combined with the current timestamp To calculate Signature : , , ;Finally, the IoT device will authenticate the request information Send to the gateway node through a secure channel; Step 4.6: Assume that the gateway node receives the authentication request information The time is , which first compares the inequality To check whether the request information has expired ; If the inequality holds, the gateway node compares Is it true? If so, sign it. Valid (otherwise invalid), gateway node calculation ; In addition, the gateway node selects a random number , and combined with the current timestamp To calculate , , ; Step 4.7: Assume the IoT device receives the authentication response message The time is , which first compares the inequality To check whether the request information has expired ; If this inequality holds, then the IoT device calculates , , then the session key between it and the gateway node is calculated as ; The IoT device then verifies the signature Effectiveness: ; If this equation holds, the signature Valid or invalid, IoT device computing , and use Replace the stored ; In addition, the IoT device calculates the session key verification parameter , and send authentication feedback information through public channels Send to the gateway node; Step 4.8: Assume the gateway node receives authentication feedback information The time is , which first compares the inequality To check whether the feedback information has expired ; If the inequality holds, the gateway node calculates the session key verification parameter , and judge Is it true? If so, the session key negotiation between the IoT device and the gateway node is successful, and they can communicate through the key Realize the transmission of encrypted data; The dynamic IoT device addition in step 5 is specifically as follows: Step 5.1: The Smart Agriculture Management Center confirms the identification of the newly added IoT device , and its temporary identification , and then pick a random secret value , and a pseudo-random identifier ; In addition, the Smart Agriculture Management Center selects random numbers , and calculate its corresponding public key , and combined with the current timestamp , calculate a temporary certificate for the newly added IoT device ; Step 5.2: The Smart Agriculture Management Center will register the tuple Preload the newly registered IoT device; finally, the Smart Agriculture Management Center publicly releases the public key of the newly registered IoT device ; The step 6 performs block creation, block authentication and consensus based on smart contracts, where: The steps to create a block are: Step 6.1: When the gateway node receives the IoT device Data collected , the gateway node uses the ECDSA signature algorithm, the private key and the current timestamp For transactions To sign: ,in It is an IoT device The number of the agricultural zone in which you are located, It is the signature algorithm of ECDSA; The gateway node then sends the transaction information sent to a nearby edge server; if , it means that the user Has not been added to the revocation list, so update the revocation list Similarly, if the transaction involves sensitive information that needs to be encrypted, the gateway node generates the signature Before, the transaction is encrypted. , and generate encrypted transaction information ( , ) is sent to a nearby edge server; Step 6.2: The edge server calls the ECDSA verification algorithm and the public key of the gateway node To verify transaction information or( , ) is valid; if valid, the edge server will Transactions or crypto transactions Combined into a partial block ; Each partial block contains information including partial block version , the timestamp of block generation , the root node of the Merkle tree , the owner of some blocks (labels of edge servers), public keys for transaction verification , ECDSA signature , and use the edge server's private key Some of the generated block headers; The edge server will then generate some blocks Sent to the cloud server, where It uses the ECDSA signature algorithm and the private key of the edge server The generated signature for this part of the block; Step 6.3: The cloud server first uses the public key of the edge server To verify the signature ; If the verification is successful, the cloud server calculates the hash value of the current block , and add the previous block hash value , so that some blocks Integrate into one complete block ; Block authentication and consensus based on smart contracts are as follows: Step 6.4: Definition Set a magic number for the total number of cloud servers in the blockchain network , and define an empty collection ; Step 6.5: The cloud server as the head node broadcasts the newly added block to all cloud servers as replica nodes in the blockchain network. Each replica node Set voting information , and calculate the hash value of the newly added block ;if , and use the public key of the edge server The signature was verified correctly , then generate the relevant Transactions The root node of the Merkle tree ;like , then set the voting information ; Then the voting information Add to collection middle; Step 6.6: Define the number of available nodes and their initial value , for the set If all voting information in ,but +1; finally, if , then the block Add to the blockchain and update the status of the block Broadcast to the blockchain network.
2. According to the blockchain-based smart agricultural smart contract authentication method of claim 1, It is characterized in that The session key with IoT device 1 in step 4.2 is calculated as , IoT device 2 is the session key Generate signature ; Finally, IoT device 2 sends the following authentication feedback information to IoT device 1 through the public network: .
3. According to the blockchain-based smart agricultural smart contract authentication method of claim 1, It is characterized in that In step 4.6, the session key with the IoT device is calculated as , the gateway node generates a new temporary identifier for the IoT device , and encrypt it as ; Then, the gateway node calculates the Signature , and provide certification feedback information Return to the IoT device.
4. A system for implementing the smart agricultural smart contract authentication method of the blockchain described in any one of claims 1-3, It is characterized in that include: A smart city management center and an Internet of Things device, a gateway node, an edge server, and a cloud server connected to the smart city management center, wherein the Internet of Things device and the gateway node are connected, the gateway node and the edge server are connected, and the edge server and the cloud server are connected, wherein: The smart city management center is used to create system parameters and receive registration requests from IoT devices, gateway nodes, edge servers, and cloud servers and issue certificates; The IoT device and the gateway node are used for authentication and key negotiation between two IoT devices, and authentication and key negotiation between an IoT device and a gateway node; The gateway nodes, edge servers, and cloud servers are used to implement sequential data transmission, perform block creation, and block authentication and consensus based on smart contracts to realize blockchain construction.
