A public network scene sensor terminal trusted upgrading method and system

CN117336688BActive Publication Date: 2026-10-27GUILIN UNIV OF ELECTRONIC TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310581029.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-23
Publication Date
2026-10-27
Estimated Expiration
2043-05-23

AI Technical Summary

Technical Problem

由于其仅使用CRC校验保证数据完整性,通信数据明文传输,该申请只能保证当前发送的身份认证指令由合法的服务器发出,但并不能保证后续发送的开始帧、传输帧、结束帧的数据安全性

Benefits of technology

[0013]本发明的有益效果为:本发明在MODBUS协议基础上进行改进,运用传感器终端的唯一序列号作为传感器终端身份的唯一索引,并设置传感器本地身份校验码,灵活运用SHA256和RSA加密算法处理通信数据,保证通信数据在传输过程的真实性和保密性。本发明的方法在对数据加密的同时,也能确保服务器身份的合法性。当攻击者在不知道传感器身份校验码(管理员设定并保管)的前提下,任何修改数据的尝试都将被传感器终端识破,解决现有技术中存在的安全性问题。本发明的方法能有效验证发送者的身份,防止数据泄露,防篡改能力强,数据传输安全可靠,实现传感器终端的应用程序远程可信升级。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117336688B_ABST
    Figure CN117336688B_ABST
Patent Text Reader

Abstract

The application belongs to the field of wireless sensor network information security, and particularly relates to a sensor terminal trusted upgrade method and system in a public network scene. The application is improved on the basis of the MODBUS protocol, uses the unique serial number of the sensor terminal as the unique index of the sensor terminal identity, sets the sensor local identity check code, flexibly uses the SHA256 and RSA encryption algorithms to process the communication data, and ensures the authenticity and confidentiality of the communication data in the transmission process. The method of the application can encrypt the data and also ensure the legality of the server identity, and solves the security problem existing in the prior art. The method of the application can effectively verify the identity of the sender, prevent data leakage, has strong anti-tampering ability, and is safe and reliable in data transmission, so that the remote trusted upgrade of the application program of the sensor terminal is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of wireless sensor network information security, specifically relating to a trusted upgrade method and system for sensor terminals in public network scenarios. Background Technology

[0002] With the development of IoT applications in smart cities, smart transportation, smart homes, smart agriculture, and other fields, an increasing number of sensor terminals are being deployed. Faced with ever-increasing product demands, sensor terminal devices can only improve their service performance and meet user needs through application upgrades. The previous method of requiring manual on-site maintenance and upgrades for sensor terminals is gradually being replaced by remote upgrades. The MODBUS protocol, widely used in industrial IoT and IoT systems, is a request / response protocol that provides services defined by function codes, enabling client / server communication. However, directly using the MODBUS protocol as the file transfer protocol for terminal application upgrades cannot ensure the integrity and reliability of the upgrade files, requiring improvements based on the MODBUS protocol. Furthermore, the transmission network used for remote upgrades is not secure; upgrade file data may be maliciously eavesdropped on or tampered with during transmission, posing security risks.

[0003] Chinese invention publication CN115766444A discloses a method and system for upgrading sensor terminal nodes in a Modbus TCP network scenario. It authenticates the server's legitimacy by sending an authentication command containing a digital digest to the sensor, without considering security during the communication process. Because it only uses CRC checksum to ensure data integrity and transmits communication data in plaintext, this application can only guarantee that the currently sent authentication command is issued by a legitimate server, but cannot guarantee the security of subsequent start frames, transmission frames, and end frames. Plaintext transmission of start frames, transmission frames, and end frames exposes data to an insecure network environment, creating a security vulnerability. If an attacker maliciously eavesdrops on the communication between the server and the sensor terminal, and after successful server authentication, the attacker maliciously tampers with information such as file size, function code, and serial number, and misleads the sensor terminal by modifying the CRC checksum, the sensor terminal upgrade will fail. If the attacker maliciously tampers with the file data in the transmission frame and modifies the CRC checksum, the sensor terminal will receive an incorrect upgrade file and use it for "upgrade," resulting in an ineffective upgrade or even a system crash. Summary of the Invention

[0004] To address the aforementioned issues, this invention provides a trusted upgrade method and system for sensor terminals in public network scenarios. Based on the MODBUS protocol, it improves upon it by using the sensor terminal's unique serial number as a unique index for terminal identity and setting a local sensor identity verification code. It cleverly utilizes SHA256 and RSA encryption algorithms to process communication data, ensuring the authenticity and confidentiality of communication data during transmission. This invention effectively verifies the sender's identity, prevents data leakage, has strong anti-tampering capabilities, and ensures secure and reliable data transmission, enabling remote trusted upgrades of sensor terminals. The specific technical solution is as follows: A trusted upgrade method for sensor terminals in a public network scenario includes the following steps: Step S1: The server backend sends a serial number query command to the sensor terminal connected to the WEB management platform, parses the serial number information of the sensor terminal in the received response frame, and simultaneously obtains the IP address and communication port information of the current communication network connection. It then compares whether the serial number information of the sensor terminal is saved in the database. If the serial number information of the sensor terminal is saved, the IP address and communication port information of the communication network connection are compared and updated. If the serial number information of the sensor terminal is not saved, a new record is added. The record includes the serial number, IP address, and communication port information of the sensor terminal, thereby adding the sensor terminal to the server platform. The serial number of the sensor terminal is unique. Step S2: The sensor terminal introduces a sensor identity verification code. Before deployment and use, the sensor terminal is set with an identity verification code. At the same time, the identity verification code is saved to the database through the WEB management platform. Step S3: The user uploads the target upgrade file to be executed through the WEB management platform, or selects a suitable upgrade file from the upgrade file list provided by the WEB management platform as the target upgrade file, selects the sensor terminal to be upgraded according to the serial number of the sensor terminal, and clicks the relevant button to execute the upgrade operation; Step S4: The server backend sends an upgrade service request instruction frame to the sensor terminal and waits for a response frame from the sensor terminal. After receiving the response frame from the sensor terminal, it parses it to determine whether the sensor terminal agrees to the upgrade request from the server. If the sensor terminal does not agree to the upgrade service request, the server determines the reason for the error and sends it back to the user. If the sensor terminal agrees to the upgrade service request, the sensor terminal enters the waiting file transfer state and proceeds to step S5. Step S5: After the server backend converts the format of the data in the target upgrade file in step S3, it divides the converted data into N data blocks. The server backend sequentially frames, encrypts, and encapsulates the data blocks to obtain N transmission frames as required, and sends the transmission frames to the sensor terminal in the order of block division. The transmission process of the i-th transmission frame includes: the server backend sends the i-th transmission frame to the sensor terminal and waits for the response frame from the sensor terminal to obtain the transmission status of the i-th transmission frame. After receiving the i-th transmission frame, the sensor terminal first decrypts the i-th transmission frame to obtain the corresponding i-th data block, performs verification by combining it with the locally stored sensor terminal identity verification code, and then sends the verification result to the server backend in the form of a response frame; where i=1,2,...,N; In step S6, the server backend sends an encrypted end frame to the sensor terminal, notifying the sensor terminal that "the server has ended the transmission of the upgrade file," and waits for a response frame from the sensor terminal to obtain the transmission status of the end frame. After receiving the end frame, the sensor terminal performs authentication and decryption on the end frame to obtain the verification result, and sends the verification result to the server backend in the form of a response frame. If the verification passes, the sensor terminal further processes the N data blocks obtained by local decryption in step S5 to obtain the complete target upgrade file and then starts the firmware upgrade. Step S7: The server backend returns the execution result to the WEB management platform and prompts the user with the operation result.

[0005] Preferably, in step S1, the server backend continuously listens for connection requests from the sensor terminal by opening a Socket socket; The sensor terminal connects remotely to the WEB management platform via its public IP address and communication port. When the sensor terminal successfully connects to the WEB management platform, the server automatically sends a serial number query command to the sensor terminal to obtain the current serial number of the sensor terminal. At the same time, the server adds or updates the IP address and communication port number bound to the serial number in the database for the unique identification of the sensor terminal.

[0006] Preferably, step S4 specifically includes: the server backend queries the IP address and communication port of the current server backend and the target sensor terminal for network communication based on the unique serial number of the sensor terminal; The server backend sends an upgrade service request instruction frame to the sensor terminal through a specified IP address and communication port, and waits for a response frame from the target sensor terminal within an agreed time. Based on the function code and CRC code in the response frame, it determines whether the target sensor terminal agrees to the upgrade service request. If it agrees, it continues to step S5. If the target sensor terminal does not agree or the response times out, the upgrade service request is resent once. If the target sensor terminal still does not agree to the upgrade service or the response times out on the Mth time, the upgrade service is terminated, the cause of the error is determined, and an error result is returned.

[0007] Preferably, in step S5, a 4-byte absolute address offset is set to identify the position of the data block in the original data by the sensor terminal. The absolute address offset in the i-th transmission frame corresponding to the i-th data block is L*(i-1); where L is the length of the transmission frame packet corresponding to the first N-1 data blocks, and the length of the transmission frame packet corresponding to the N-th data block is less than or equal to L.

[0008] Preferably, the encryption process of the server for the i-th transmission frame in step S5 includes: By combining the sensor identity verification code, function code, transmission frame packet length, absolute address offset, and the i-th data block, a SHA256 operation is performed to obtain digital digest I; The ciphertext is obtained by encrypting the function code, transmission frame packet length, absolute address offset, and i-th data block using the RSA public key; The obtained digital digest I and the ciphertext are encapsulated into the i-th transmission frame.

[0009] Preferably, in step S5, the sensor terminal performs decryption and verification after receiving the i-th transmission frame, specifically including: Use the RSA private key to decrypt the ciphertext sent by the server to obtain the function code, transmission frame packet length, absolute address offset, and the i-th data block; By combining the locally stored sensor terminal's identity verification code with the decrypted function code, transmission frame packet length, absolute address offset, and the i-th data block, a SHA256 operation is performed to obtain Digital Digest II; Verify that digital digest II is the same as digital digest I. If they match, it means that the data in the i-th transmission frame has not been tampered with, the server is legitimate, and the data is trustworthy. If they do not match, it means that the server is illegitimate or the data is untrustworthy. The sensor terminal responds accordingly based on the verification result: if the data is reliable, it sends a normal response frame to the server and prepares to receive the next frame of data; if the data is unreliable, it sends an abnormal response frame to the server, discards the unreliable frame, and waits for the i-th transmission frame to be retransmitted.

[0010] Preferably, the improved MODBUS protocol is used for data transmission in step S5 or step S6; the application data unit of the improved MODBUS protocol includes a MODBUS application protocol header and a protocol data unit. The MODBUS application protocol header includes a transaction meta identifier, a protocol identifier, a length identifier, and a unit identifier; The protocol data unit includes a function code, transmission frame packet length, absolute address offset, digital digest, and ciphertext.

[0011] Preferably, in step S5 or S6, after the server backend receives the response frame sent by the sensor terminal, it verifies the frame content and monitors whether the data transmission process is normal, specifically including the following: First, verify that the function code in the response frame is correct; Then, check in turn whether the transaction element identifier, protocol identifier, and unit identifier in the response frame are consistent with the transmission frame or end frame sent by the server backend to the sensor terminal. Finally, verify that the response code is normal. If any of the following occurs: sensor terminal response timeout, verification content does not meet requirements, or response code is abnormal, the server will resend the transmission frame or termination frame to the sensor terminal. If the Mth verification still fails, the server terminates the file transfer service, determines the type of abnormal response based on the error code and exception code in the response frame returned by the sensor terminal, and returns the abnormal result.

[0012] A trusted upgrade system for sensor terminals in a public network scenario, used to implement the upgrade method, includes a web management platform, a server, and several sensor terminals; the server is connected to the web management platform and several sensor terminals respectively. The WEB management platform provides a web-based system for visually managing sensor terminal information, uploading and downloading upgrade files, and user operations related to terminal upgrade services. The server backend is used for actual data parsing and business execution. The sensor terminal has a BootLoader program and an APP program. The BootLoader program is used to receive upgrade data and run upgrade files, and the APP program is used to send relevant responses to requests to the server backend. The sensor terminal supports SHA256 operation and RSA encryption operation.

[0013] The beneficial effects of this invention are as follows: Based on the MODBUS protocol, this invention improves upon it by using the sensor terminal's unique serial number as a unique index for the sensor terminal's identity and setting a local sensor identity verification code. It flexibly utilizes SHA256 and RSA encryption algorithms to process communication data, ensuring the authenticity and confidentiality of the communication data during transmission. This invention's method, while encrypting data, also ensures the legitimacy of the server's identity. When an attacker does not know the sensor identity verification code (set and stored by the administrator), any attempt to modify the data will be detected by the sensor terminal, solving the security problems existing in the prior art. This invention's method effectively verifies the sender's identity, prevents data leakage, has strong anti-tampering capabilities, ensures secure and reliable data transmission, and enables remote and reliable upgrades of the sensor terminal's application. Attached Figure Description

[0014] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn to scale.

[0015] Figure 1 This is a schematic diagram of the method flow of Embodiment 1 of the present invention; Figure 2 This is a diagram of the instruction structure / response frame structure for obtaining the serial number according to the present invention; Figure 3 This is a structural diagram of the MODBUS Application Protocol Header (MBAP) in an embodiment of the present invention; Figure 4 This is a structural diagram of the Protocol Data Unit (PDU) of the present invention; Figure 5 This is a flowchart illustrating the server data encryption process of the present invention. Figure 6 This is a flowchart of the sensor terminal data decryption and verification process of the present invention; Figure 7 This is a diagram of the correct response frame structure of the present invention; Figure 8 This is a diagram of the error response frame structure of the present invention; Figure 9 This is a system schematic diagram of Embodiment 2 of the present invention. Detailed Implementation

[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0017] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0018] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0019] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0020] Example 1: like Figure 1 As shown, a specific embodiment of the present invention provides a trusted upgrade method for sensor terminals in a public network scenario, including the following steps: Step S1: The server backend sends a serial number query command to the sensor terminal connected to the WEB management platform, parses the serial number information of the sensor terminal in the received response frame, and simultaneously obtains the IP address and communication port information of the current communication network connection. It then compares the database to see if the sensor terminal's serial number information is saved. If a record of the sensor terminal's serial number information is saved, the server compares and updates the IP address and communication port information of the communication network connection. If the sensor terminal's serial number information is not saved, a new record is added. The record includes the sensor terminal's serial number, IP address, and communication port information, thus adding the sensor terminal to the server platform. The serial number of the sensor terminal is unique. During normal operation of the server backend, it continuously listens for connection requests from sensor terminals by opening a Socket socket, providing device connection services for the sensor terminals. The sensor terminal connects remotely to the WEB management platform via its public IP address and communication port. When the sensor terminal successfully connects to the WEB management platform, the server automatically sends a serial number query command to the sensor terminal to obtain the current serial number of the sensor terminal. If the serial number of the sensor terminal cannot be found in the database, the serial number and current communication information of the sensor terminal are saved. That is, the information to be saved is: serial number, IP address, and communication port. If the database can find the serial number of the sensor terminal, the server adds or updates the IP address and communication port number bound to the serial number in the database for the unique identification of the sensor terminal.

[0021] The application protocol header and function code of the serial number acquisition command sent by the server and the serial number response frame sent by the sensor terminal are the same, with the function code being 0x02. The sensor terminal sends the serial number information to the server in the data field, and the frame format is as follows: Figure 2 As shown.

[0022] Step S2: The sensor terminal introduces a sensor identity verification code. Before deployment and use, the sensor terminal is set with an identity verification code. At the same time, the identity verification code is saved to the database through the WEB management platform. Step S3: The user uploads the target upgrade file to be executed through the WEB management platform, or selects a suitable upgrade file from the upgrade file list provided by the WEB management platform as the target upgrade file, selects the sensor terminal to be upgraded according to the serial number of the sensor terminal, and clicks the relevant button to execute the upgrade operation.

[0023] Step S4: The server backend sends an upgrade service request instruction frame to the sensor terminal and waits for a response frame from the sensor terminal. After receiving the response frame from the sensor terminal, it parses it to determine whether the sensor terminal agrees to the upgrade request from the server. If the sensor terminal does not agree to the upgrade service request, the server determines the reason for the error and sends it back to the user. If the sensor terminal agrees to the upgrade service request, the sensor terminal enters the waiting file transfer state and proceeds to step S5.

[0024] The server backend queries the IP address and communication port of the current server backend and the target sensor terminal for network communication based on the unique serial number of the sensor terminal; The server backend sends an upgrade service request instruction frame to the sensor terminal through a specified IP address and communication port. The function code is 0x03. At the same time, it waits for a response frame from the target sensor terminal within an agreed time. Based on the function code and CRC code in the response frame, it determines whether the target sensor terminal agrees to the upgrade service request. If it agrees, it continues to step S5. If the target sensor terminal does not agree or the response times out, the upgrade service request is resent once. If the target sensor terminal still does not agree to the upgrade service or the response times out on the Mth (M is configurable)th time, the upgrade service is terminated, the cause of the error is determined, and the error result is returned.

[0025] In step S5, the server backend converts the data in the target upgrade file from step S3 into a new format and then divides the converted data into N data blocks.

[0026] This embodiment uses the improved MODBUS protocol for data transmission; the improved MODBUS protocol application data unit (ADU) includes the MODBUS application protocol header (MBAP) and protocol data unit (PDU). like Figure 3 As shown, the MODBUS Application Protocol Header (MBAP) includes a transaction meta identifier, a protocol identifier, a length identifier, and a unit identifier; wherein the transaction meta identifier, the protocol identifier, and the length identifier are each 2 bytes, and the unit identifier is 1 byte.

[0027] like Figure 4 As shown, the Protocol Data Unit (PDU) includes a function code, a transmission frame packet length, an absolute address offset, a digital digest, and ciphertext. The function code, transmission frame packet length, absolute address offset, digital digest, and ciphertext are 1 byte, 1 byte, 4 bytes, 32 bytes, and 128 bytes, respectively.

[0028] Setting the absolute address offset ensures that the sensor terminal correctly splices several data blocks into complete upgrade file data after receiving them; setting the transmission frame packet length ensures that the sensor terminal correctly identifies the size of the data packets in the transmission frame.

[0029] A 4-byte absolute address offset is set to identify the position of the data block in the original data by the sensor terminal. The absolute address offset in the i-th transmission frame corresponding to the i-th data block is L*(i-1); where L is the length of the transmission frame packet corresponding to the first N-1 data blocks, and the length of the transmission frame packet corresponding to the N-th data block is less than or equal to L.

[0030] In this embodiment, the function code of the i-th transmission frame is 0x04, the length of the transmission frame packet encapsulated for the first N-1 data blocks is 0x6E, the length of the transmission frame packet encapsulated for the N-th data block is the actual byte length (in hexadecimal), and the absolute address offset in the transmission frame encapsulated for the i-th data block is 0x6E*(i-1) (in hexadecimal).

[0031] The server backend sequentially frames, encrypts, and encapsulates the data blocks to obtain N transmission frames as required, and sends the transmission frames to the sensor terminal in the order of block division. The transmission process of the i-th transmission frame includes: the server backend sends the i-th transmission frame to the sensor terminal and waits for the response frame from the sensor terminal to obtain the transmission status of the i-th transmission frame.

[0032] like Figure 5 As shown, the encryption process of the server for the i-th transmitted frame includes: By combining the sensor identity verification code, function code, transmission frame packet length, absolute address offset, and the i-th data block, a SHA256 operation is performed to obtain a 32-byte digital digest I; Using the RSA public key to encrypt the function code, transmission frame packet length, absolute address offset, and the i-th data block, we obtain 128 bytes of ciphertext; The obtained digital digest I and the ciphertext are encapsulated into the i-th transmission frame.

[0033] After receiving the i-th transmission frame, the sensor terminal first decrypts the i-th transmission frame to obtain the corresponding i-th data block, performs verification by combining it with the locally stored sensor terminal identity verification code, and then sends the verification result to the server backend in the form of a response frame; where i=1,2,...,N.

[0034] like Figure 6 As shown, after receiving the i-th transmission frame, the sensor terminal performs decryption and verification, specifically including: Use the RSA private key to decrypt the ciphertext sent by the server to obtain the function code, transmission frame packet length, absolute address offset, and the i-th data block; By combining the locally stored sensor terminal's identity verification code with the decrypted function code, transmission frame packet length, absolute address offset, and the i-th data block, a SHA256 operation is performed to obtain Digital Digest II; Verify that digital digest II is the same as digital digest I. If they match, it means that the data in the i-th transmission frame has not been tampered with, the server is legitimate, and the data is trustworthy. If they do not match, it means that the server is illegitimate or the data is untrustworthy. The sensor terminal responds accordingly based on the verification result: if the data is reliable, it sends a normal response frame to the server and prepares to receive the next frame of data; if the data is unreliable, it sends an abnormal response frame to the server, discards the unreliable frame, and waits for the i-th transmission frame to be retransmitted.

[0035] In step S6, the server backend sends an encrypted end frame to the sensor terminal, notifying the sensor terminal that "the server has ended the transmission of the upgrade file," and waits for a response frame from the sensor terminal to obtain the transmission status of the end frame. After receiving the end frame, the sensor terminal performs identity authentication and decryption on the end frame to obtain the verification result, and sends the verification result to the server backend in the form of a response frame. If the verification passes, the sensor terminal further processes the N data blocks obtained by local decryption in step S5 to obtain the complete target upgrade file and then starts the firmware upgrade.

[0036] The end frame function code is 0x05, the packet length is 0x00, the absolute address offset is 0x00000000, and the data block area is padded with 110 bytes of zero characters.

[0037] The server's encryption process for the end frame is similar to that for the transmission frame, referring to the encryption process for the i-th transmission frame in step S5. After encryption, the resulting digital digest and ciphertext are encapsulated into the end frame.

[0038] After receiving the end frame, the sensor terminal decrypts and verifies it to obtain the verification result, referring to the decryption and verification process of the sensor terminal for the i-th transmission frame in step S5.

[0039] The sensor terminal responds accordingly based on the verification results: if the end frame is reliable, it sends a normal response frame to the server, indicating that the upgrade file has been successfully transmitted. At the same time, the sensor terminal concatenates the data blocks in sequence with the transmission frame packet length and absolute address offset obtained locally in step 5 to obtain the complete upgrade file data and perform firmware upgrade; if the end frame data is unreliable, it sends an abnormal response command to the server, discards the end frame, and waits for the end frame to be retransmitted.

[0040] In step S5 or S6, after receiving the response frame sent by the sensor terminal, the server backend verifies the frame content and monitors whether the data transmission process is normal to ensure the normal progress of the upgrade process. The response frame structure is as follows: Figure 7 As shown. The server verification process specifically includes: First, verify that the function code in the response frame is correct; Then, check in turn whether the transaction element identifier, protocol identifier, and unit identifier in the response frame are consistent with the transmission frame or end frame sent by the server backend to the sensor terminal. Finally, verify that the response code is normal. If any of the following occurs: sensor terminal response timeout, transaction identifier or other verification content does not meet the requirements, or response code is abnormal, the server will resend the transmission frame or end frame to the sensor terminal. If the Mth (configurable) verification still fails, the server terminates the file transfer service, determines the abnormal response type based on the error code and exception code in the response frame returned by the sensor terminal, and returns the abnormal result. The response type correspondence table is shown in Table 1 below.

[0041] Table 1 Response Type Correspondence Table like Figure 7 and Figure 8 As shown, Figure 7 This is a diagram of the correct response frame structure of the present invention; Figure 8 This is a diagram of the error response frame structure of the present invention.

[0042] Step S7: The server backend returns the execution result to the WEB management platform and prompts the user with the operation result.

[0043] CN115766444A provides a method and system for upgrading sensor terminal nodes in a Modbus TCP network scenario. The authentication server's legitimacy is achieved by sending an authentication command containing a digital digest to the sensor. Once the server obtains the sensor terminal's authentication, it begins the upgrade process. During the upgrade, the server does not encrypt the start frame, transmission frame, or end frame; it only uses CRC checksums to ensure data integrity. Because the communication data is transmitted in plaintext, the data remains exposed to an insecure network environment. When an attacker maliciously listens to the data of the communication between the server and the sensor terminal, and launches an attack on the start frame, transmission frame and end frame after the server's identity authentication is passed, it will greatly interfere with the entire upgrade process and increase maintenance costs: (1) If the attacker maliciously tampers with the function code and corrects the CRC check, the sensor terminal will not be able to detect the abnormality after receiving the wrong function code and will perform the wrong operation, which will cause the sensor terminal upgrade to fail; (2) If the attacker maliciously tampers with the file size in the start frame and corrects the CRC check, the sensor terminal will not be able to detect the abnormality and will process the data according to the wrong file size, which will ultimately cause the sensor terminal upgrade to fail; (3) If the attacker maliciously tampers with the file data in the transmission frame and corrects the CRC check, the sensor terminal will receive the wrong upgrade file and use the wrong upgrade file to "upgrade", which will result in the inability to achieve an effective upgrade, or even cause the sensor terminal to crash.

[0044] To address the aforementioned potential security issues, this invention improves upon the MODBUS protocol by using the sensor terminal's unique serial number as a unique index for terminal identity and setting a local sensor identity verification code. It flexibly employs SHA256 and RSA encryption algorithms to process communication data, ensuring the authenticity and confidentiality of the data during transmission. The server combines the sensor identity verification code, function code, packet length, absolute address offset, and data blocks to perform SHA256 calculations, obtaining a 32-byte digital digest. It then uses the RSA public key to encrypt the function code, packet length, absolute address offset, and data blocks, obtaining 128 bytes of ciphertext. The digital digest and ciphertext are then encapsulated into a protocol frame. The sensor identity verification code is set and stored by the administrator. Because SHA256 is irreversible, third parties cannot crack the sensor's identity verification code. The RSA encryption algorithm has a high security level; even if it is unfortunately cracked and the data is tampered with, the sensor terminal can still determine the data's trustworthiness through decryption and identity authentication. The sensor terminal uses an RSA private key to decrypt the ciphertext, obtaining the function code, packet length, absolute address offset, and data blocks. It then performs a SHA256 operation on the locally stored sensor identity verification code, the decrypted function code, packet length, absolute address offset, and data blocks to generate a new digital digest. The digital digest extracted from the frame is compared with the recalculated digital digest from the sensor terminal. If they match, the data has not been tampered with, the server's identity is legitimate, and the data is trustworthy. If they do not match, the server's identity is illegitimate or the data is untrustworthy. According to this method, any attempt by a third party to modify data without knowing the sensor identity verification code (set and stored by the administrator) will be detected by the sensor terminal, preventing data tampering and leakage, and truly achieving remote and trusted upgrades of the sensor terminal.

[0045] Example 2: like Figure 9 As shown in the figure, a specific embodiment of the present invention provides a trusted upgrade system for sensor terminals in a public network scenario, used to implement the upgrade method, including a WEB management platform, a server, and a number of sensor terminals; the server is connected to the WEB management platform and the number of sensor terminals respectively. The WEB management platform provides a web-based system for visually managing sensor terminal information, uploading and downloading upgrade files, and user operations related to terminal upgrade services. The server backend is used for actual data parsing and business execution. The sensor terminal has a BootLoader program and an APP program. The BootLoader program is used to receive upgrade data and run upgrade files, and the APP program is used to send relevant responses to requests to the server backend. The sensor terminal supports SHA256 operation and RSA encryption operation.

[0046] Those skilled in the art will recognize that the units of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of the invention.

[0047] In the embodiments provided in this application, it should be understood that the division of units is only a logical functional division. In actual implementation, there may be other division methods, such as multiple units can be combined into one unit, one unit can be split into multiple units, or some features can be ignored.

[0048] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be covered within the scope of the claims and specification of the present invention.

Claims

1. A method for trusted upgrade of sensor terminals in a public network scenario, characterized in that, Includes the following steps: Step S1: The server backend sends a serial number query command to the sensor terminal connected to the WEB management platform, parses the serial number information of the sensor terminal in the received response frame, and simultaneously obtains the IP address and communication port information of the current communication network connection. It then compares whether the serial number information of the sensor terminal is saved in the database. If the serial number information of the sensor terminal is saved, the IP address and communication port information of the communication network connection are compared and updated. If the serial number information of the sensor terminal is not saved, a new record is added. The record includes the serial number, IP address, and communication port information of the sensor terminal, thereby adding the sensor terminal to the server platform. The serial number of the sensor terminal is unique. Step S2: The sensor terminal introduces a sensor identity verification code. Before deployment and use, the sensor terminal is set with an identity verification code. At the same time, the identity verification code is saved to the database through the WEB management platform. Step S3: The user uploads the target upgrade file to be executed through the WEB management platform, or selects a suitable upgrade file from the upgrade file list provided by the WEB management platform as the target upgrade file, selects the sensor terminal to be upgraded according to the serial number of the sensor terminal, and clicks the relevant button to execute the upgrade operation; Step S4: The server backend sends an upgrade service request instruction frame to the sensor terminal and waits for a response frame from the sensor terminal. After receiving a response frame from the sensor terminal, it is parsed to determine whether the sensor terminal agrees to the upgrade request from the server. If the sensor terminal does not agree to the service upgrade request, the reason for the abnormality will be determined and fed back to the user. If the sensor terminal agrees to the upgrade service request, the sensor terminal enters the waiting file transfer state and proceeds to step S5. Step S5: After the server backend converts the format of the data in the target upgrade file in step S3, it divides the converted data into N data blocks. The server backend sequentially frames, encrypts, and encapsulates the data blocks to obtain N transmission frames, and sends the transmission frames to the sensor terminal in the order of block division. The transmission process of the i-th transmission frame includes: the server backend sends the i-th transmission frame to the sensor terminal and waits for the response frame from the sensor terminal to obtain the transmission status of the i-th transmission frame. After receiving the i-th transmission frame, the sensor terminal first decrypts the i-th transmission frame to obtain the corresponding i-th data block, verifies it using the locally stored sensor terminal identity verification code, and then sends the verification result to the server backend in the form of a response frame; where i = 1, 2, ..., N; the server's encryption process for the i-th transmission frame includes: By combining the sensor identity verification code, function code, transmission frame packet length, absolute address offset, and the i-th data block, a SHA256 operation is performed to obtain digital digest I; The ciphertext is obtained by encrypting the function code, transmission frame packet length, absolute address offset, and i-th data block using the RSA public key; The obtained digital digest I and the ciphertext are encapsulated into the i-th transmission frame; In step S6, the server backend sends an encrypted end frame to the sensor terminal, notifying the sensor terminal that "the server has ended the transmission of the upgrade file," and waits for a response frame from the sensor terminal to obtain the transmission status of the end frame. After receiving the end frame, the sensor terminal performs authentication processing and decryption on the end frame to obtain the verification result, and sends the verification result to the server backend in the form of a response frame. If the verification passes, the sensor terminal further processes the N data blocks obtained by local decryption in step S5 to obtain the complete target upgrade file and then starts the firmware upgrade. Step S7: The server backend returns the execution result to the WEB management platform and prompts the user with the operation result.

2. The trusted upgrade method for sensor terminals in a public network scenario according to claim 1, characterized in that, In step S1, the server backend continuously listens for connection requests from the sensor terminal by opening a Socket socket. The sensor terminal connects remotely to the WEB management platform via its public IP address and communication port. When the sensor terminal successfully connects to the WEB management platform, the server automatically sends a serial number query command to the sensor terminal to obtain the current serial number of the sensor terminal. At the same time, the server adds or updates the IP address and communication port number bound to the serial number in the database for the unique identification of the sensor terminal.

3. The trusted upgrade method for sensor terminals in a public network scenario according to claim 1, characterized in that, Step S4 specifically includes: the server backend queries the IP address and communication port of the current server backend and the target sensor terminal for network communication based on the unique serial number of the sensor terminal; The server backend sends an upgrade service request instruction frame to the sensor terminal through a specified IP address and communication port, and waits for a response frame from the target sensor terminal within an agreed time. Based on the function code and CRC code in the response frame, it determines whether the target sensor terminal agrees to the upgrade service request. If it agrees, it continues to step S5. If the target sensor terminal does not agree or the response times out, the upgrade service request is resent once. If the target sensor terminal still does not agree to the upgrade service or the response times out on the Mth time, the upgrade service is terminated, the cause of the error is determined, and an error result is returned.

4. The trusted upgrade method for sensor terminals in a public network scenario according to claim 1, characterized in that, In step S5, a 4-byte absolute address offset is set to identify the position of the data block in the original data by the sensor terminal. The absolute address offset in the i-th transmission frame corresponding to the i-th data block is L*(i-1); where L is the length of the transmission frame packet corresponding to the first N-1 data blocks, and the length of the transmission frame packet corresponding to the N-th data block is less than or equal to L.

5. The trusted upgrade method for sensor terminals in a public network scenario according to claim 4, characterized in that, In step S5, after receiving the i-th transmission frame, the sensor terminal performs decryption and verification, specifically including: Use the RSA private key to decrypt the ciphertext sent by the server to obtain the function code, transmission frame packet length, absolute address offset, and the i-th data block; By combining the locally stored sensor terminal's identity verification code with the decrypted function code, transmission frame packet length, absolute address offset, and the i-th data block, a SHA256 operation is performed to obtain Digital Digest II; Verify that digital digest II is the same as digital digest I. If they match, it means that the data in the i-th transmission frame has not been tampered with, the server is legitimate, and the data is trustworthy. If they do not match, it means that the server is illegitimate or the data is untrustworthy. The sensor terminal responds accordingly based on the verification result: if the data is reliable, it sends a normal response frame to the server and prepares to receive the next frame of data; if the data is unreliable, it sends an abnormal response frame to the server, discards the unreliable frame, and waits for the i-th transmission frame to be retransmitted.

6. The trusted upgrade method for sensor terminals in a public network scenario according to claim 4, characterized in that, In step S5 or step S6, the improved MODBUS protocol is used for data transmission; the application data unit of the improved MODBUS protocol includes a MODBUS application protocol header and a protocol data unit. The MODBUS application protocol header includes a transaction meta identifier, a protocol identifier, a length identifier, and a unit identifier; The protocol data unit includes a function code, transmission frame packet length, absolute address offset, digital digest, and ciphertext.

7. The trusted upgrade method for sensor terminals in a public network scenario according to claim 6, characterized in that, In step S5 or S6, after the server receives the response frame sent by the sensor terminal, it verifies the frame content and monitors whether the data transmission process is normal. Specifically, this includes... the following: First, verify that the function code in the response frame is correct; Then, check in turn whether the transaction element identifier, protocol identifier, and unit identifier in the response frame are consistent with the transmission frame or end frame sent by the server backend to the sensor terminal. Finally, verify that the response code is normal. If any of the following occurs: sensor terminal response timeout, verification content does not meet requirements, or response code is abnormal, the server will resend the transmission frame or termination frame to the sensor terminal. If the Mth verification still fails, the server terminates the file transfer service, determines the type of abnormal response based on the error code and exception code in the response frame returned by the sensor terminal, and returns the abnormal result.

8. A trusted upgrade system for sensor terminals in a public network scenario, characterized in that, The method for implementing the upgrade method according to any one of claims 1 to 7 includes a web management platform, a server, and a plurality of sensor terminals; the server is connected to the web management platform and the plurality of sensor terminals respectively. The WEB management platform provides a web-based system for visually managing sensor terminal information, uploading and downloading upgrade files, and user operations related to terminal upgrade services. The server backend is used for actual data parsing and business execution. The sensor terminal has a BootLoader program and an APP program. The BootLoader program is used to receive upgrade data and run upgrade files, and the APP program is used to send relevant responses to requests to the server backend. The sensor terminal supports SHA256 operation and RSA encryption operation.

Citation Information

Patent Citations

  • Sensor terminal node upgrading method and system in Modbus TCP network scene

    CN115766444A

  • Intelligent display terminal firmware updating method

    CN104166565A

  • Method and device for designing secure interaction protocol in energy internet scene

    CN115118756A