Time synchronization method, device, electronic device and storage medium
By receiving and decrypting encrypted messages to determine timestamp information, correcting local time, and ensuring data integrity using data ciphertext and authentication tags, it solves the problem of vulnerability to clock synchronization between domain controllers and improves automotive electronics and electrical Architecture security.
Patent Information
- Application Number
- CN202211058995.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2042-08-31
AI Technical Summary
In the automotive electronic and electrical architecture, clock synchronization between domain controllers is vulnerable to attacks, resulting in failure of time synchronization and security risks.
By receiving encrypted and decrypted messages sent by the master device, the timestamp information is determined to correct the local time, and the data ciphertext and authentication tags are used during the transmission process to ensure the confidentiality and integrity of the data.
Improve the security of time synchronization between vehicle equipment, prevent attackers from tampering with time information, and ensure the stability and security of the system.
Smart Images

Figure CN115484078B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of time synchronization technology, and in particular to a time synchronization method, device, electronic device and storage medium. Background Art
[0002] In the current automotive electronic and electrical architecture, domain controllers are generally divided into power domain, chassis domain, cockpit domain, autonomous driving domain and body domain, and each domain controller is interconnected through Ethernet. The clock is the "pulse" of the entire vehicle system. To ensure that the entire vehicle system works effectively, stably and with high quality, it is necessary to ensure that the various domain controllers as network node devices are "in step", that is, it is necessary to ensure the clock synchronization function between the various domain controllers.
[0003] However, during the time synchronization process of each node device, the related messages transmitted are vulnerable to attacks, such as Denial of service (Dos), Delay Attack (DA) or Man-in-the-Middle Attack (MITM), etc. The time information carried by them can be easily intercepted and maliciously tampered with, resulting in the inability of the node device to perform accurate time synchronization, and then causing the node device to fail in function. In addition, attackers can even obtain and control the real-time clock of the node device to achieve the purpose of manipulating the node device, bringing unpredictable security risks to the entire vehicle system. Summary of the invention
[0004] The embodiments of the present application provide a time synchronization method, apparatus, electronic device and storage medium for ensuring the confidentiality and integrity of message data during the time synchronization process of the vehicle, thereby improving the security of time synchronization between various device nodes of the vehicle.
[0005] On the one hand, an embodiment of the present application provides a time synchronization method, the method comprising:
[0006] Receive a first encrypted message and a second encrypted message sent by a master device; the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message; the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message;
[0007] Determine the second timestamp information according to the reception time of the first encrypted message;
[0008] Decrypting the second encrypted message to obtain the second message and the first timestamp information carried by the second message;
[0009] The time of the local device is corrected according to the first timestamp information and the second timestamp information.
[0010] Further, the second encrypted message includes the data ciphertext and the authentication tag;
[0011] Decrypting the second encrypted message to obtain the second message and the first timestamp information carried by the second message includes:
[0012] Determine the tag to be authenticated based on the preset second decryption strategy and the data ciphertext;
[0013] When the authentication tag matches the tag to be authenticated, the data ciphertext is decrypted based on a preset first decryption strategy and a preset key to obtain a second message and first timestamp information carried by the second message;
[0014] Decrypting the first encrypted message to obtain the first message includes:
[0015] Based on the preset second decryption strategy, the first encrypted message is decrypted to obtain the first message.
[0016] Further, according to the first timestamp information and the second timestamp information, the time of the local device is corrected, including:
[0017] Determine clock deviation information according to the first timestamp information and the second timestamp information;
[0018] According to the clock deviation information, the time of the local device is corrected.
[0019] Further, after correcting the time of the local device according to the first timestamp information and the second timestamp information, the method further includes:
[0020] Sending a third encrypted message to the master device so that the master device decrypts the third encrypted message and determines fourth timestamp information according to a time when the third encrypted message is received; the third encrypted message is obtained by encrypting the third message;
[0021] receiving a fourth encrypted message and a fifth encrypted message sent by the master device; the fourth encrypted message is obtained by the master device encrypting the fourth message, and the fifth encrypted message is obtained by the master device encrypting the fifth message; the fourth message carries fourth timestamp information, and the fifth message carries fifth timestamp information; the fifth timestamp information represents the sending time of the fourth encrypted message;
[0022] Decrypting the fourth encrypted message to obtain the fourth message and fourth timestamp information carried by the fourth message, and determining sixth timestamp information according to the reception time of the fourth encrypted message;
[0023] Decrypting the fifth encrypted message to obtain a fifth message and fifth timestamp information carried by the fifth message;
[0024] The time of the local device is corrected according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
[0025] Furthermore, before sending the third encrypted message to the master device, the method further includes:
[0026] generating a third message;
[0027] The third message is encrypted to obtain a third encrypted message, and when the encryption of the third message is completed, the clock information of the local device is obtained, and the third timestamp information is determined based on the clock information.
[0028] Further, according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information, the time of the local device is corrected, including:
[0029] Determining transmission delay information according to the third timestamp information, the fourth timestamp information, the fifth timestamp information, and the sixth timestamp information;
[0030] The time of the local device is corrected according to the first timestamp information, the second timestamp information and the transmission delay information.
[0031] In another aspect, a time synchronization method is provided, the method comprising:
[0032] A first encrypted message and a second encrypted message are sent to a slave device, wherein the first encrypted message is obtained by encrypting the first message, and the second encrypted message is obtained by encrypting the second message, and the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message, so that the slave device decrypts the first encrypted message to obtain the first message, and determines the second timestamp information according to the receiving time of the first encrypted message, and decrypts the second encrypted message from the slave device to obtain the second message and the first timestamp information carried by the second message, and the slave device corrects the time of the local device according to the first timestamp information and the second timestamp information.
[0033] Furthermore, the process of generating the first encrypted message and the second encrypted message includes:
[0034] Generate a first message and a second message;
[0035] Encrypt the first message to obtain a first encrypted message, and when the encryption of the first message is completed, obtain clock information of the local device, and determine first timestamp information based on the clock information;
[0036] The second message is encrypted to obtain a second encrypted message.
[0037] Further, the first timestamp information is a data field preset in the second message;
[0038] The second message is encrypted to obtain a second encrypted message, including:
[0039] Encrypting the data field based on a preset first encryption strategy and a preset key to obtain a data ciphertext;
[0040] Encrypt the data ciphertext based on a preset second encryption strategy to obtain an authentication tag;
[0041] Generate a second encrypted message according to the data ciphertext and the authentication tag;
[0042] Encrypting the first message to obtain a first encrypted message includes:
[0043] The first message is encrypted based on a preset second encryption strategy to obtain a first encrypted message.
[0044] Further, after sending the first encrypted message and the second encrypted message to the slave device, the method further includes:
[0045] receiving a third encrypted message sent by the slave device, where the third encrypted message is obtained by encrypting the third message by the slave device;
[0046] Decrypting the third encrypted message to obtain a third message, and determining fourth timestamp information according to a time when the third encrypted message is received;
[0047] A fourth encrypted message and a fifth encrypted message are sent to the slave device, the fourth encrypted message is obtained by encrypting the fourth message, the fifth encrypted message is obtained by encrypting the fifth message, the fourth message carries fourth timestamp information, the fifth message carries fifth timestamp information, and the fifth timestamp information represents the sending time of the fourth encrypted message, so that the slave device decrypts the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determines the sixth timestamp information according to the receiving time of the fourth encrypted message; and so that the slave device decrypts the fifth encrypted message to obtain the fifth message and the fifth timestamp information carried by the fifth message, and so that the slave device corrects the time of the local device according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
[0048] Furthermore, the generation process of the fourth encrypted message and the fifth encrypted message includes:
[0049] generating a fourth message and a fifth message;
[0050] Encrypting the fourth message to obtain a fourth encrypted message, and when the encryption of the fourth message is completed, obtaining clock information of the local device, and determining fifth timestamp information based on the clock information;
[0051] The fifth message is encrypted to obtain a fifth encrypted message.
[0052] On the other hand, a time synchronization device is provided, the device comprising:
[0053] A receiving module, used to receive a first encrypted message and a second encrypted message sent by a master device; the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message; the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message;
[0054] A decryption module, used to determine the second timestamp information according to the reception time of the first encrypted message; decrypt the first encrypted message to obtain the first message, and decrypt the second encrypted message to obtain the second message and the first timestamp information carried by the second message;
[0055] The synchronization module is used to correct the time of the local device according to the first timestamp information and the second timestamp information.
[0056] On the other hand, a time synchronization device is provided, the device comprising:
[0057] A sending module is used to send a first encrypted message and a second encrypted message to a slave device, wherein the first encrypted message is obtained by encrypting the first message, and the second encrypted message is obtained by encrypting the second message. The second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message, so that the slave device decrypts the first encrypted message to obtain the first message, and determines the second timestamp information according to the receiving time of the first encrypted message, and decrypts the second encrypted message from the slave device to obtain the second message and the first timestamp information carried by the second message, and the slave device corrects the time of the local device according to the first timestamp information and the second timestamp information.
[0058] On the other hand, an electronic device is provided, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by the processor to implement any of the time synchronization methods mentioned above.
[0059] On the other hand, a computer-readable storage medium is provided, in which at least one instruction, at least one program, code set or instruction set is stored, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement any of the time synchronization methods described above.
[0060] The time synchronization method, device, equipment and storage medium provided in the embodiments of the present application have the following technical effects:
[0061] Receive the first encrypted message and the second encrypted message sent by the main device, the first encrypted message is obtained by the main device encrypting the first message, the second encrypted message is obtained by the main device encrypting the second message, the second message carries the first timestamp information, the first timestamp information represents the sending time of the first encrypted message, the second timestamp information is determined according to the receiving time of the first encrypted message, the second encrypted message is decrypted to obtain the first timestamp information carried by the second message, and the time of the local device is corrected according to the first timestamp information and the second timestamp information. This application determines the second timestamp information and obtains the first timestamp information by decrypting the first encrypted message and the second encrypted message sent by the main device, and thereby corrects the time of the local device, thereby improving the safety of the vehicle when performing time synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0063] Figure 1 It is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0064] Figure 2 This is a schematic diagram of a time synchronization structure provided by an embodiment of the present application;
[0065] Figure 3 It is a flowchart of a time synchronization method provided in an embodiment of the present application;
[0066] Figure 4 It is a flowchart of a method for generating a first encrypted message and a second encrypted message provided in an embodiment of the present application;
[0067] Figure 5 It is a flowchart of a method for encrypting a second message provided in an embodiment of the present application;
[0068] Figure 6It is a schematic diagram of an encryption method for a message data field provided by the present application;
[0069] Figure 7 It is a flowchart of a decryption method of a second encrypted message provided in an embodiment of the present application;
[0070] Figure 8 It is a flowchart of a local time correction method provided in an embodiment of the present application;
[0071] Fig. 9 It is a structural diagram of a local time correction method provided in an embodiment of the present application;
[0072] Fig.10 It is a flowchart of a time synchronization method provided in an embodiment of the present application;
[0073] Fig.11 It is a flowchart of a method for encrypting a third message provided in an embodiment of the present application;
[0074] Fig.12 It is a flowchart of a method for correcting local time provided in an embodiment of the present application;
[0075] Fig.13 It is a flowchart of another time synchronization method provided in an embodiment of the present application;
[0076] Fig.14 It is a flowchart of another time synchronization method provided in an embodiment of the present application;
[0077] Fig.15 It is a flowchart of an encryption method for a fourth message and a fifth message provided in an embodiment of the present application;
[0078] Fig.16 It is a structural diagram of a time synchronization device provided in an embodiment of the present application;
[0079] Fig.17 It is a structural diagram of a time synchronization device provided in an embodiment of the present application;
[0080] Fig.18 It is a hardware structure block diagram of the server of the time synchronization method provided in the embodiment of the present application. DETAILED DESCRIPTION
[0081] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0082] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0083] See also Figure 1 , Figure 1 It is a schematic diagram of an application scenario provided by an embodiment of the present application, which includes a vehicle, which can be an unmanned vehicle, that is, an automatic driving vehicle, or a semi-automatic driving vehicle. The time synchronization method provided by an embodiment of the present application is applied to a scene composed of a master device and a slave device in the vehicle, and the scene can include multiple slave devices; wherein the master device is the central network node device in the scene, and the local time of the master device is used as the standard time for time synchronization between the master device and the slave device.
[0084] In one implementation, the time synchronization method provided in an embodiment of the present application is based on the generalized Precision Time Protocol (gPTP) for transmission at the data link layer or a sublayer of the data link layer, which sublayer may be a media access control layer (MAC Layer), and is connected to an Ethernet link (Ethernet) through a physical layer (Physical Layer, PHY).
[0085] See also Figure 2 , Figure 2 is a schematic diagram of a time synchronization structure provided by an embodiment of the present application, such as Figure 2As shown, the time synchronization structure may include a hardware circuit module, an event port, a common port, a timestamp printing module, an authentication module and a message sending and receiving management module; the message sending and receiving management module may receive and send encrypted messages; the authentication module may decrypt received encrypted messages, and may also encrypt generated unencrypted messages; the event port and the common port may generate messages, the hardware circuit module may control the timestamp printing module to accurately record the timestamp information of the event port when sending encrypted messages or receiving encrypted messages, and the messages generated by the common port may be used to carry the timestamp information recorded by the timestamp printing module.
[0086] In one embodiment, the master device or the slave device may send or receive encrypted messages through a physical network card.
[0087] The time synchronization structure may also include a clock state machine and a preset best master clock algorithm and a local clock algorithm; the clock state machine may determine whether the local clock is the master clock based on the preset best master clock algorithm. When the vehicle system is powered on, all network node devices in the system may participate in the election for the master clock. Based on the best master clock algorithm, it may be determined whether the local clock of the network node device is the master clock. If it is determined that the local clock of the network node device is the master clock, the network node device is the master device and other network node devices are slave devices. For slave devices, the clock state machine may also correct the local time based on the local clock algorithm.
[0088] The time synchronization structure may also include a data set management module for storing and managing received message data.
[0089] The following describes a specific embodiment of a time synchronization method of the present application. Figure 3 It is a flowchart of a time synchronization method provided by an embodiment of the present application. This specification provides method operation steps such as the embodiment or flowchart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one execution method among many step execution sequences and does not represent the only execution sequence. When the actual system or server product is executed, it can be executed in the order shown in the embodiment or in parallel (for example, in a parallel processor or multi-threaded processing environment). Specifically, Figure 3 As shown, the time synchronization method is executed based on a slave device, and the time synchronization method may include:
[0090] S301: Receive a first encrypted message and a second encrypted message sent by a master device, where the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message, and the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message.
[0091] Figure 4 : is a flow chart of a method for generating a first encrypted message and a second encrypted message provided in an embodiment of the present application. The generation method is executed based on a master device and may specifically include:
[0092] S401: Generate a first message and a second message.
[0093] Optionally, the first message and the second message are a group of messages used to measure clock deviation information between the slave device and the master device. The group of messages can be generated by the master device at a predetermined period.
[0094] Specifically, the first message can be generated through the event port of the master device. As an example, the first message may not carry timestamp information, but is used to trigger the timestamp printing module of the master device or the slave device to record the local time of the master device or the slave device. As an example, the master device can obtain the first encrypted message after encrypting the first message, and trigger the timestamp printing module to record the local time of the master device when sending the first encrypted message. As an example, the slave device can trigger the timestamp printing module to record the local time of the slave device at the moment of receiving the first encrypted message. Specifically, the second message can be generated through the universal port, the second message can carry the time information triggered when the master device sends the first encrypted message, and is sent to the slave device after encrypting the second message.
[0095] S402: Encrypt the first message to obtain a first encrypted message, obtain clock information of the local device when sending the first encrypted message, and determine first timestamp information based on the clock information.
[0096] Optionally, the local device at this time is a master device, and the clock information of the master device refers to time information indicated by a master clock in the master device.
[0097] Specifically, encrypting the first message may be that the master device encrypts the first message based on a second encryption strategy preset by the master device to obtain a first encrypted message.
[0098] Exemplarily, the second encryption strategy preset in the main device may be the national secret SM3 algorithm, that is, the SM3 cryptographic hash algorithm whose relevant standard recognized by the State Cryptography Administration of China is GM / T 0004-2012. The first message is encrypted based on the preset SM3 algorithm to obtain the first encrypted message.
[0099] S403: Encrypt the second message to obtain a second encrypted message.
[0100] Optionally, when sending, the data field carrying the timestamp information in the message can be encrypted based on a preset encryption strategy and a preset key to obtain a data ciphertext, and then the authentication tag is determined based on the preset key and the obtained data ciphertext, so that when receiving, it is only necessary to determine the tag to be authenticated based on the received data ciphertext and the preset key, and compare the tag to be authenticated with the received authentication tag. If they match, the received data ciphertext is decrypted based on the preset encryption strategy and the preset key to obtain the data field carrying the timestamp information.
[0101] Optionally, the first timestamp information is a preset data field in the second message, or the second message may carry the first timestamp information through a preset data field. Specifically, the second message may include a message header part (Header) and a message data part (TypeLengthValue, TLV), the data field is the TLV part in the second message, and the first timestamp information may be the TLV part in the second message.
[0102] For details, please refer to Figure 5 , Figure 5 It is a flowchart of a second message encryption method provided in an embodiment of the present application, which may specifically include:
[0103] S501: Encrypt the data field based on a preset first encryption strategy and a preset key to obtain data ciphertext.
[0104] Optionally, see Figure 6 , Figure 6 It is a schematic diagram of an encryption method for a message data field provided by the implementation of the present application. The preset first encryption strategy can be the national secret SM4 algorithm, that is, the SM4 block cipher algorithm with the relevant standard GM / T0002-2012 recognized by the State Cryptography Administration of China. Based on the preset first encryption strategy SM4 algorithm and the preset key Key2, the data field in the second message can be encrypted, thereby converting the data field into data ciphertext.
[0105] In an optional implementation, the preset key may also be obtained by encrypting the initial key preset in the main device based on the second encryption strategy. As an example, the key Key2 may be obtained by encrypting the preset initial key Key1 by the main device based on the preset second encryption strategy SM3.
[0106] In the embodiment of the present application, the key used to encrypt the data field carrying timestamp information is obtained after encryption based on a preset initial key, thereby improving the confidentiality of the data field.
[0107] S502: Encrypt the data ciphertext based on a preset second encryption strategy to obtain an authentication tag.
[0108] As an example, the data ciphertext can be processed based on the preset second encryption strategy SM3 and the preset key Key2 to obtain an authentication tag, so that when the data ciphertext is subsequently decrypted, it is possible to determine whether the received data ciphertext is damaged by verifying the received authentication tag. If the received authentication tag is damaged, then the timestamp information carried by the received data ciphertext is at risk of leakage, and further decryption is not required. Through the authentication tag, the decryption process can be optimized, meaningless decryption processes can be reduced, and the confidentiality of the data ciphertext can also be improved.
[0109] S503: Generate a second encrypted message according to the data ciphertext and the authentication tag.
[0110] Specifically, generating the second encrypted message according to the data ciphertext and the authentication tag may be adding the authentication tag to the data ciphertext, thereby obtaining the second encrypted message including the data ciphertext and the authentication tag.
[0111] In the embodiment of the present application, the data ciphertext is first obtained by encrypting the second message, and then the authentication tag is determined based on the data ciphertext, so that when the second encrypted message is received, it is only necessary to determine the tag to be authenticated based on the received data ciphertext, compare the tag to be authenticated with the received authentication tag, and decrypt the data ciphertext when the authentication tag matches the tag to be authenticated. The embodiment of the present application optimizes the decryption process through the above scheme; in addition, for an attacker, unless the preset key and the preset first and second encryption strategies can be cracked, the data ciphertext and the authentication tag cannot be decrypted at the same time, making it more difficult for the attacker to send malicious data, thereby improving the security and confidentiality of message transmission.
[0112] S303: Decrypt the first encrypted message to obtain the first message, and determine the second timestamp information according to the receiving time of the first encrypted message.
[0113] Optionally, decrypting the first encrypted message to obtain the first message may include:
[0114] Based on a preset second decryption strategy corresponding to the second encryption strategy, the first encrypted message is decrypted to obtain a first message.
[0115] Specifically, the second decryption strategy may be a decryption strategy corresponding to the second encryption strategy, or in other words, executing the second decryption strategy is the inverse process of executing the second encryption strategy.
[0116] S305: Decrypt the second encrypted message to obtain the second message and the first timestamp information carried by the second message.
[0117] Optionally, the second encrypted message includes a data ciphertext and an authentication tag, see Figure 7 , Figure 7 It is a flowchart of a decryption method of a second encrypted message provided in an embodiment of the present application, which may specifically include:
[0118] S701: Determine a tag to be authenticated based on a preset second decryption strategy and data ciphertext.
[0119] Specifically, the data ciphertext in the second encrypted message may be decrypted according to the second decryption strategy corresponding to the second encryption strategy SM3, thereby obtaining the tag to be authenticated.
[0120] When generating an authentication tag or a tag to be authenticated, the embodiment of the present application directly calculates the data ciphertext based on a preset second encryption strategy or a second decryption strategy, without the need for additional key processing, thereby simplifying the encryption and decryption process of the message and improving the speed of encryption and decryption.
[0121] S702: When the authentication tag of the second encrypted message matches the tag to be authenticated, the data ciphertext is decrypted based on a preset first decryption strategy and a preset key to obtain the second message and the first timestamp information carried by the second message.
[0122] The embodiment of the present application calculates the tag to be authenticated and compares the tag to be authenticated with the authentication tag in the second encrypted message to determine whether the data ciphertext in the second encrypted message is damaged. If the tag to be authenticated matches the authentication tag in the second encrypted message, it indicates that the data ciphertext in the second encrypted message is not damaged, and the data ciphertext in the second encrypted message continues to be decrypted. If the authentication tag of the second encrypted message does not match the tag to be authenticated, it indicates that the data ciphertext in the second encrypted message is damaged, and there is no need to decrypt the data ciphertext in the second encrypted message, thereby simplifying the decryption process.
[0123] S307: Correct the local time according to the first timestamp information and the second timestamp information.
[0124] Figure 8 : is a flowchart of a local time correction method provided by an embodiment of the present application, which may specifically include:
[0125] S801: Determine clock deviation information according to the first timestamp information and the second timestamp information.
[0126] For details, please refer to Fig. 9 , Fig. 9This is a structural diagram of a local time correction method provided by an embodiment of the present application. According to the first timestamp information and the second timestamp information, the clock deviation information between the slave device and the master device can be determined. As an example, the first timestamp information is t1, and the second timestamp information is t2, then the clock deviation information between the slave device and the master device can be determined to be t2-t1.
[0127] S802: Correct the local time according to the clock deviation information.
[0128] Specifically, after the clock deviation information is determined, the slave device can correct the local time based on the clock deviation information.
[0129] In this way, the embodiment of the present application decrypts the first encrypted message and the second encrypted message sent by the main device, determines the second timestamp information and obtains the first timestamp information, and corrects the local time accordingly, thereby ensuring the confidentiality and integrity of the message data during the vehicle's time synchronization process, thereby improving the security of time synchronization between the vehicle's various device nodes.
[0130] In one embodiment, there is a transmission delay in the network transmission between the master device and the slave device. In order to more accurately synchronize the time between the master and the slave devices, it is necessary to determine the transmission delay information between the master and the slave devices, and further determine the clock deviation information based on the transmission delay information, so as to correct the local time of the slave device.
[0131] Specifically, Fig.10 As shown, Fig.10 is a flow chart of a time synchronization method provided by an embodiment of the present application. After the slave device corrects the local time according to the first timestamp information and the second timestamp information in step S307, the time synchronization method may further include:
[0132] S1001: Send a third encrypted message to a master device, so that the master device decrypts the third encrypted message and determines fourth timestamp information according to a receiving time of the third encrypted message; the third encrypted message is obtained by encrypting the third message.
[0133] As an example, the process of decrypting the third encrypted message to obtain the third message may be that the main device may decrypt the third encrypted message based on a preset second decryption strategy to obtain the third message, and determine the fourth timestamp information according to the reception time of the third encrypted message, wherein executing the second decryption strategy may be the inverse process of executing the second encryption strategy.
[0134] Fig.11 It is a flowchart of a method for encrypting a third message provided in an embodiment of the present application, which may specifically include:
[0135] S1101: Generate a third message.
[0136] Specifically, the third message may be generated through the event port of the slave device. As an example, the third message may not carry timestamp information, but is used to trigger the timestamp printing module of the slave device or the master device to record the local time of the slave device or the master device. As an example, the slave device may obtain the third encrypted message after encrypting the third message, and trigger the timestamp printing module to record the local time of the slave device when sending the third encrypted message. As an example, the master device may trigger the timestamp printing module to record the local time of the master device at the moment of receiving the third encrypted message.
[0137] S1102: Encrypt the third message to obtain a third encrypted message, obtain clock information of the local device when sending the third encrypted message, and determine third timestamp information based on the clock information.
[0138] The third timestamp information represents the sending time of the third encrypted message; the local device at this time refers to the slave device, and the clock information of the slave device refers to the time information indicated by the slave clock in the slave device.
[0139] As an example, encrypting the third message may be that the slave device encrypts the third message based on a second encryption policy preset by the slave device to obtain a third encrypted message.
[0140] Exemplarily, the second encryption strategy preset in the slave device may be the national encryption SM3 algorithm, and the third message may be encrypted based on the SM3 algorithm to obtain a third encrypted message.
[0141] S1003: Receive a fourth encrypted message and a fifth encrypted message sent by the master device, the fourth encrypted message is obtained by the master device encrypting the fourth message, the fifth encrypted message is obtained by the master device encrypting the fifth message, the fourth message carries fourth timestamp information, the fifth message carries fifth timestamp information, and the fifth timestamp information represents the sending time of the fourth encrypted message.
[0142] Specifically, the fourth message can be generated through the event port of the master device. As an example, the fourth message can carry fourth timestamp information. As an example, the master device can obtain a fourth encrypted message after encrypting the fourth message, and trigger the timestamp printing module to record the local time of the master device when sending the fourth encrypted message, that is, the fifth timestamp information. As an example, the slave device can trigger the timestamp printing module to record the local time of the slave device at the moment of receiving the fourth encrypted message, that is, the sixth timestamp information.
[0143] Specifically, the fifth message can be generated through the universal port of the master device. As an example, the fifth message can carry fifth timestamp information triggered when the master device sends the fourth encrypted message, and send it to the slave device after encrypting the fifth message.
[0144] S1005: Decrypt the fourth encrypted message to obtain the fourth message and fourth timestamp information carried by the fourth message, and determine sixth timestamp information according to the receiving time of the fourth encrypted message.
[0145] As an example, the label to be authenticated can be determined based on a second decryption strategy preset in the device and the data ciphertext of the fourth encrypted message; when the authentication tag of the second encrypted message matches the label to be authenticated, the data ciphertext of the fourth encrypted message is decrypted based on the preset first decryption strategy and the preset key to obtain the fourth message and the fourth timestamp information carried by the fourth message.
[0146] S1007: Decrypt the fifth encrypted message to obtain a fifth message and fifth timestamp information carried by the fifth message;
[0147] Optionally, the decryption of the fifth encrypted message and the decryption of the fourth encrypted message may adopt the same decryption method as the second encrypted message, which will not be described in detail here.
[0148] S1009: Correct the local time according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information.
[0149] Exemplarily, the transmission delay information between the slave device and the master device can be determined based on the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information, and the local time of the slave device can be corrected according to the transmission delay information and the first and second timestamp information.
[0150] The embodiment of the present application can complete a transmission delay measurement through the above steps S1001-S1009, and the transmission time △t1 of the third encrypted message can be determined as t4-t3 through the third timestamp information t3 and the fourth timestamp information t4, and the transmission time △t2 of the fourth encrypted message can be determined as t6-t5 through the fifth timestamp information t5 and the sixth timestamp information t6. Under the assumption that the transmission path is symmetrical, that is, the transmission path of the message from the master device to the slave device and the transmission path of the message from the slave device to the master device are different only in the transmission direction, the transmission delay information between the master device and the slave device can be further determined through the transmission time △t1 of the third encrypted message and the transmission time △t2 of the fourth encrypted message. As an example, (△t1+△t2) / 2 can be used as a single transmission delay information between the master device and the slave device.
[0151] For details, please refer to Fig.12 , Fig.12 This is a flow chart of correcting the local time according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information provided by an embodiment of the present application, which may specifically include:
[0152] S1201: Determine transmission delay information according to third timestamp information, fourth timestamp information, fifth timestamp information and sixth timestamp information.
[0153] Specifically, the transmission delay information between the slave device and the master device can be determined based on the third, fourth, fifth, and sixth timestamp information. As an example, the third, fourth, fifth, and sixth timestamp information are t3, t4, t5, and t6, respectively. Then, it can be determined that the transmission time △t1 of the third encrypted message is t4-t3, and the transmission time △t2 of the fourth encrypted message is t6-t5. Then, it can be determined that the single transmission delay information between the slave device and the master device is ((t4-t3)+(t6-t5)) / 2.
[0154] S1202: Correct the local time according to the first timestamp information, the second timestamp information and the transmission delay information.
[0155] As an example, after determining the first timestamp information t1, the second timestamp information t2 and the transmission delay information ((t4-t3)+(t6-t5)) / 2, it can be further determined that the clock deviation information between the slave device and the master device is (t2-t1)-[(t4-t3)+(t6-t5)] / 2.
[0156] S802: Correct the local time according to the clock deviation information.
[0157] Specifically, after the clock deviation information is determined, the slave device can correct the local time based on the clock deviation information determined in step S1202.
[0158] In this way, the embodiment of the present application ensures the confidentiality and integrity of message data transmission during the vehicle's time synchronization process, thereby improving the security of time synchronization between various device nodes in the vehicle.
[0159] In this way, the slave device in the embodiment of the present application determines the third and sixth timestamp information and obtains the fourth and fifth timestamp information by sending the third encrypted message to the master device and decrypting the fourth and fifth encrypted messages sent by the master device, and thereby continues to correct the local time of the slave device, thereby improving the security of time synchronization between various device nodes in the vehicle.
[0160] The following describes another specific embodiment of the time synchronization method of the present application. Fig.13 is a flow chart of another time synchronization method provided by an embodiment of the present application, and the specific example is as follows Fig.13 As shown, the time synchronization method is executed based on a master device, and the master device can provide time reference information and send it to a slave device, so that the slave device can keep synchronization with the time reference information of the master device according to the received time reference information. The time synchronization method may include:
[0161] S1301: Send a first encrypted message and a second encrypted message to a slave device, where the first encrypted message is obtained by encrypting the first message, and the second encrypted message is obtained by encrypting the second message, and the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message, so that the slave device decrypts the first encrypted message and determines the second timestamp information according to the receiving time of the first encrypted message, and so that the slave device decrypts the second encrypted message to obtain the first timestamp information, and so that the slave device corrects the local time according to the first timestamp information and the second timestamp information.
[0162] In one embodiment, Fig.14 As shown, Fig.14 1 is a flow chart of another time synchronization method provided in an embodiment of the present application. After the master device sends the first encrypted message and the second encrypted message to the slave device in step S1301, the time synchronization method may further include:
[0163] S1401: Receive a third encrypted message sent by a slave device, where the third encrypted message is obtained by encrypting a third message from the slave device.
[0164] S1403: Decrypt the third encrypted message to obtain a third message, and determine fourth timestamp information according to a receiving time of the third encrypted message.
[0165] As an example, decrypting the third encrypted message to obtain the third message may be that the main device decrypts the third encrypted message based on a preset second decryption strategy to obtain the third message, and the main device may determine the fourth timestamp information based on the reception time of the third encrypted message, wherein executing the second decryption strategy may be the inverse process of executing the second encryption strategy.
[0166] S1405: Send a fourth encrypted message and a fifth encrypted message to the slave device, the fourth encrypted message is obtained by encrypting the fourth message, the fifth encrypted message is obtained by encrypting the fifth message, the fourth message carries fourth timestamp information, the fifth message carries fifth timestamp information, the fifth timestamp information represents the sending time of the fourth encrypted message, so that the slave device decrypts the fourth encrypted message to obtain the fourth timestamp information, and determines the sixth timestamp information according to the receiving time of the fourth encrypted message, and enables the slave device to decrypt the fifth encrypted message to obtain the fifth timestamp information, and enables the slave device to correct the local time according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
[0167] Fig.15 It is a flowchart of an encryption method for a fourth message and a fifth message provided in an embodiment of the present application, which may specifically include:
[0168] S1501: Generate a fourth message and a fifth message.
[0169] Exemplarily, the fourth message and the fifth message are a group of messages, which can be generated after the main device decrypts the third encrypted message to obtain the third message, and determines the fourth timestamp information based on the reception time of the third encrypted message. Specifically, the fourth message can be generated through the event port of the main device, and the fifth message can be generated through the general port of the main device. The fourth message can trigger the timestamp printing module to record the local time of the main device when it is subsequently encrypted.
[0170] S1502: Encrypt the fourth message to obtain a fourth encrypted message, and when the encryption of the fourth message is completed, obtain clock information of the local device, and determine fifth timestamp information based on the clock information.
[0171] Optionally, the fourth timestamp information is a preset data field in the fourth message, or the fourth message can carry the fourth timestamp information through a preset data field. Specifically, the fourth message may include a message header part (Header) and a message data part (TypeLengthValue, TLV), and the data field is the TLV part in the second message.
[0172] As an example, the fourth message is encrypted to obtain a fourth encrypted message, which can be specifically: based on a preset first encryption strategy and a preset key, the data field is encrypted to obtain data ciphertext, wherein the preset first encryption strategy can be the national secret SM4 algorithm, and based on the preset first encryption strategy SM4 algorithm and the preset key Key2, the data field in the fourth message can be encrypted, thereby converting the data field into data ciphertext; based on the preset second encryption strategy SM3, the data ciphertext is encrypted to obtain an authentication tag; and the fourth encrypted message is generated according to the data ciphertext and the authentication tag.
[0173] As an example, generating the fourth encrypted message according to the data ciphertext and the authentication tag may be adding the authentication tag to the data ciphertext, thereby obtaining the fourth encrypted message including the data ciphertext and the authentication tag.
[0174] S1503: Encrypt the fifth message to obtain a fifth encrypted message.
[0175] Optionally, the fifth message may be encrypted using the method for encrypting the fourth message, which is not described in detail here.
[0176] See also Fig. 9 , the following describes the interactive process of time synchronization between the slave device and the master device:
[0177] The master device generates a first message and a second message;
[0178] The master device encrypts the second message to obtain a second encrypted message; specifically, the first timestamp information is a data field preset in the second message, the master device can encrypt the data field based on a preset first encryption strategy and a preset key to obtain a data ciphertext, encrypt the data ciphertext based on a preset second encryption strategy to obtain an authentication tag, and generate a second encrypted message according to the data ciphertext and the authentication tag.
[0179] The master device encrypts the first message to obtain a first encrypted message, and when the encryption of the first message is completed, the master device obtains the clock information of the master device, and determines the first timestamp information based on the clock information of the master device. Specifically, the master device can encrypt the first message based on a preset second encryption strategy to obtain the first encrypted message;
[0180] The slave device receives a first encrypted message and a second encrypted message sent by the master device; the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message; the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message;
[0181] The slave device decrypts the first encrypted message to obtain the first message, and determines the second timestamp information according to the reception time of the first encrypted message; specifically, the slave device may decrypt the first encrypted message based on the second decryption strategy corresponding to the second encryption strategy to obtain the first message;
[0182] Decrypting the second encrypted message from the device to obtain the second message and the first timestamp information carried by the second message; specifically, it may include: determining the tag to be authenticated based on the second decryption strategy corresponding to the second encryption strategy and the data ciphertext in the second encrypted message; when the authentication tag in the second encrypted message matches the tag to be authenticated, decrypting the data ciphertext based on the first decryption strategy and key corresponding to the first encryption strategy to obtain the second message and the first timestamp information carried by the second message.
[0183] The slave device corrects the local time of the slave device according to the first timestamp information and the second timestamp information; specifically, the slave device can determine the clock deviation information between the slave device and the master device according to the first timestamp information and the second timestamp information; and corrects the local time of the slave device according to the clock deviation information and the second timestamp information;
[0184] The slave device generates a third message;
[0185] The slave device encrypts the third message to obtain a third encrypted message, and when encrypting the third message, the slave device obtains clock information of the slave device, and determines third timestamp information based on the clock information of the slave device;
[0186] The slave device sends a third encrypted message to the master device;
[0187] The master device decrypts the third encrypted message to obtain the third message, and determines fourth timestamp information according to the reception time of the third encrypted message;
[0188] The master device generates a fourth message and a fifth message;
[0189] The master device processes the fifth message to obtain a fifth encrypted message;
[0190] The master device encrypts the fourth message to obtain a fourth encrypted message, and when the encryption of the fourth message is completed, the master device obtains the clock information of the master device, and determines the fifth timestamp information based on the clock information of the master device;
[0191] The master device sends a fourth encrypted message and a fifth encrypted message to the slave device; the fourth encrypted message is obtained by the master device encrypting the fourth message, and the fifth encrypted message is obtained by the master device encrypting the fifth message; the fourth message carries fourth timestamp information, and the fifth message carries fifth timestamp information; the fifth timestamp information represents the sending time of the fourth encrypted message;
[0192] The slave device decrypts the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determines the sixth timestamp information according to the reception time of the fourth encrypted message;
[0193] The slave device decrypts the fifth encrypted message to obtain the fifth message and fifth timestamp information carried by the fifth message;
[0194] The slave device corrects the local time of the slave device according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message. Specifically, the transmission delay information between the slave device and the master device can be determined according to the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the local time of the slave device is corrected according to the first timestamp information, the second timestamp information and the transmission delay information.
[0195] The present application also provides an embodiment of a time synchronization device, Fig.16 is a schematic diagram of the structure of a time synchronization device provided in an embodiment of the present application, such as Fig.16 As shown, the time synchronization device may include:
[0196] The first receiving module 1601 is used to receive a first encrypted message and a second encrypted message sent by a master device; the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message; the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message;
[0197] The first decryption module 1603 is used to decrypt the first encrypted message to obtain the first message, and determine the second timestamp information according to the reception time of the first encrypted message; decrypt the second encrypted message to obtain the second message and the first timestamp information carried by the second message;
[0198] The synchronization module 1605 is used to correct the local time according to the first timestamp information and the second timestamp information.
[0199] In one implementation, the first decryption module 1603 may include:
[0200] A first decryption unit is used to determine the tag to be authenticated based on a preset second decryption strategy and the data ciphertext in the second encrypted message; when the authentication tag in the second encrypted message matches the tag to be authenticated, decrypt the data ciphertext in the second encrypted message based on the preset first decryption strategy and the preset key to obtain the second message and the first timestamp information carried by the second message;
[0201] The second decryption unit is used to decrypt the first encrypted message based on a preset second decryption strategy to obtain the first message.
[0202] In one implementation, the synchronization module 1605 may include:
[0203] A first correction unit, configured to determine clock deviation information according to the first timestamp information and the second timestamp information;
[0204] The second correction unit is used to correct the local time according to the clock deviation information and the second timestamp information.
[0205] In one implementation, the time synchronization device may further include:
[0206] The first sending module 1607 is used to send a third encrypted message to the master device, so that the master device decrypts the third encrypted message and determines fourth timestamp information according to a receiving time of the third encrypted message; the third encrypted message is obtained by encrypting the third message.
[0207] In one implementation, the first receiving module 1601 can also be used to: receive a fourth encrypted message and a fifth encrypted message sent by a master device; the fourth encrypted message is obtained by the master device encrypting the fourth message, and the fifth encrypted message is obtained by the master device encrypting the fifth message; the fourth message carries fourth timestamp information, and the fifth message carries fifth timestamp information; the fifth timestamp information represents the sending time of the fourth encrypted message.
[0208] In one implementation, the first decryption module 1603 may further include:
[0209] a third decryption unit, configured to decrypt the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determine the sixth timestamp information according to the reception time of the fourth encrypted message;
[0210] The fourth decryption unit is used to decrypt the fifth encrypted message to obtain a fifth message and fifth timestamp information carried by the fifth message.
[0211] In one implementation, the synchronization module 1605 is further used to correct the local time according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
[0212] Specifically, the synchronization module may further include:
[0213] a third correction unit, configured to determine transmission delay information according to the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information;
[0214] The fourth correction unit is used to correct the local time according to the first timestamp information, the second timestamp information and the transmission delay information.
[0215] In one implementation, the time synchronization device may further include:
[0216] The first encryption module is used to generate a third message; encrypt the third message to obtain a third encrypted message, and when the encryption of the third message is completed, obtain the clock information of the local device, and determine the third timestamp information based on the clock information.
[0217] The present application also provides another embodiment of a time synchronization device, Fig.17 is a schematic diagram of the structure of a time synchronization device provided in an embodiment of the present application, such as Fig.17 As shown, the time synchronization device may include:
[0218] The second sending module 1701 is used to send a first encrypted message and a second encrypted message to a slave device, where the first encrypted message is obtained by encrypting the first message, and the second encrypted message is obtained by encrypting the second message. The second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message, so that the slave device can decrypt the first encrypted message and determine the second timestamp information according to the receiving time of the first encrypted message, and the slave device can decrypt the second encrypted message to obtain the first timestamp information, and the slave device can correct the local time according to the first timestamp information and the second timestamp information.
[0219] In one implementation, the time synchronization device may further include:
[0220] The second encryption module 1703 is used to generate a first message and a second message; encrypt the first message to obtain a first encrypted message, and when the encryption of the first message is completed, obtain the clock information of the local device, and determine the first timestamp information based on the clock information; encrypt the second message to obtain a second encrypted message.
[0221] In one implementation, the second encryption module 1703 may include:
[0222] A third encryption unit, used to encrypt the first message based on a preset second encryption strategy to obtain a first encrypted message;
[0223] The fourth encryption unit is used to: encrypt the data field based on a preset first encryption strategy and a preset key to obtain a data ciphertext, wherein the first timestamp information is a preset data field in the second message; encrypt the data ciphertext based on a preset second encryption strategy to obtain an authentication tag; and generate a second encrypted message based on the data ciphertext and the authentication tag.
[0224] In one implementation, the time synchronization device may further include:
[0225] The second receiving module 1705 is used to receive a third encrypted message sent by the slave device, where the third encrypted message is obtained by encrypting the third message from the slave device;
[0226] The second decryption module 1707 is used to decrypt the third encrypted message to obtain the third message, and determine the fourth timestamp information according to the receiving time of the third encrypted message;
[0227] In one implementation, the second sending module 1701 is further used for:
[0228] A fourth encrypted message and a fifth encrypted message are sent to the slave device, the fourth encrypted message is obtained by encrypting the fourth message, the fifth encrypted message is obtained by encrypting the fifth message, the fourth message carries fourth timestamp information, the fifth message carries fifth timestamp information, the fifth timestamp information represents the sending time of the fourth encrypted message, so that the slave device decrypts the fourth encrypted message to obtain the fourth timestamp information, and determines the sixth timestamp information according to the receiving time of the fourth encrypted message, and so that the slave device decrypts the fifth encrypted message to obtain the fifth timestamp information, and so that the slave device corrects the local time according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
[0229] In one implementation, the second encryption module 1703 is further used to: generate a fourth message and a fifth message; encrypt the fourth message to obtain a fourth encrypted message, and when the encryption of the fourth message is completed, obtain the clock information of the local device, and determine the fifth timestamp information based on the clock information.
[0230] The device and method embodiments in the embodiments of this application are based on the same application concept.
[0231] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal, a server or a similar computing device. Taking running on a server as an example, Fig.18 : is a hardware structure block diagram of a server of the time synchronization method provided in the embodiment of the present application. Fig.18As shown, the server 1800 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1810 (the central processing unit 1810 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 1830 for storing data, and one or more storage media 1820 (such as one or more mass storage devices) for storing application programs 1823 or data 1822. Among them, the memory 1830 and the storage medium 1820 can be short-term storage or permanent storage. The program stored in the storage medium 1820 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 1810 can be configured to communicate with the storage medium 1820 and execute a series of instruction operations in the storage medium 1820 on the server 1800. The server 1800 may also include one or more power supplies 1860, one or more wired or wireless network interfaces 1850, one or more input and output interfaces 1840, and / or one or more operating systems 1621, such as Windows ServerTM, Mac OS XTM, UnixTM, Linux, FreeBSD, etc.
[0232] The input / output interface 1840 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 1800. In one example, the input / output interface 1840 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices via a base station so as to communicate with the Internet. In one example, the input / output interface 1840 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0233] It can be understood by those skilled in the art that Fig.18 The structure shown is for illustration only and does not limit the structure of the above electronic device. Fig.18 More or fewer components as shown, or with Fig.18 Different configurations are shown.
[0234] An embodiment of the present application also provides a storage medium, which can be set in a server to store at least one instruction, at least one program, code set or instruction set related to the time synchronization method in the method embodiment. The at least one instruction, the at least one program, the code set or instruction set is loaded and executed by the processor to implement any of the above-mentioned time synchronization methods.
[0235] Optionally, in the embodiment of the present application, the above-mentioned storage medium may be located in at least one network server among multiple network servers of the computer network. Optionally, in the present embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0236] It can be seen from the time synchronization method, device, electronic device or storage medium provided by the above-mentioned embodiment of the present application that in the embodiment of the present application, the first encrypted message and the second encrypted message sent by the main device are received; the first encrypted message is obtained by the main device encrypting the first message, and the second encrypted message is obtained by the main device encrypting the second message; the second message carries the first timestamp information, and the first timestamp information represents the sending time of the first encrypted message; the first encrypted message is decrypted to obtain the first message, and the second timestamp information is determined according to the receiving time of the first encrypted message; the second encrypted message is decrypted to obtain the second message and the first timestamp information carried by the second message; the local time is corrected according to the first timestamp information and the second timestamp information. In this way, the embodiment of the present application determines the second timestamp information and obtains the first timestamp information by decrypting the first encrypted message and the second encrypted message sent by the main device, and thereby corrects the local time, thereby ensuring the confidentiality and integrity of the message data during the time synchronization process of the vehicle, thereby improving the security of time synchronization between various device nodes of the vehicle.
[0237] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of this specification are described. Other embodiments are within the scope of the attached claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0238] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0239] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0240] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A time synchronization method, characterized in that: The method comprises: Receive a first encrypted message and a second encrypted message sent by a master device; the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message; Determine second timestamp information according to the reception time of the first encrypted message; Decrypting the second encrypted message to obtain the second message and first timestamp information carried by the second message; the first timestamp information represents the sending time of the first encrypted message; Correcting the time of the local device according to the first timestamp information and the second timestamp information; Sending a third encrypted message to the master device, so that the master device decrypts the third encrypted message and determines fourth timestamp information according to a time when the third encrypted message is received; The third encrypted message is obtained by encrypting the third message; receiving a fourth encrypted message and a fifth encrypted message sent by the master device; the fourth encrypted message is obtained by the master device encrypting the fourth message, and the fifth encrypted message is obtained by the master device encrypting the fifth message; the fourth message carries the fourth timestamp information, and the fifth message carries the fifth timestamp information; the fifth timestamp information represents the sending time of the fourth encrypted message; decrypting the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determining sixth timestamp information according to a time when the fourth encrypted message is received; Decrypting the fifth encrypted message to obtain the fifth message and the fifth timestamp information carried by the fifth message; The time of the local device is corrected according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
2. The method according to claim 1, characterized in that The second encrypted message includes a data ciphertext and an authentication tag; The decrypting the second encrypted message to obtain the second message and the first timestamp information carried by the second message includes: Determining a tag to be authenticated based on a preset second decryption strategy and the data ciphertext; In a case where the authentication tag matches the tag to be authenticated, decrypting the data ciphertext based on a preset first decryption strategy and a preset key to obtain the second message and the first timestamp information carried by the second message; The decrypting the first encrypted message to obtain the first message includes: Based on a preset second decryption strategy, the first encrypted message is decrypted to obtain the first message.
3. The method according to claim 1, characterized in that The correcting the time of the local device according to the first timestamp information and the second timestamp information includes: Determine clock deviation information according to the first timestamp information and the second timestamp information; The time of the local device is corrected according to the clock deviation information.
4. The method according to claim 1, characterized in that: Before sending the third encrypted message to the master device, the method further includes: generating the third message; The third message is encrypted to obtain the third encrypted message, and when the encryption of the third message is completed, the clock information of the local device is obtained, and the third timestamp information is determined based on the clock information.
5. The method according to claim 1, characterized in that: The correcting the time of the local device according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information includes: Determine transmission delay information according to the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; The time of the local device is corrected according to the first timestamp information, the second timestamp information and the transmission delay information.
6. A time synchronization method, characterized in that: The method comprises: Sending a first encrypted message and a second encrypted message to a slave device, wherein the first encrypted message is obtained by encrypting the first message, the second encrypted message is obtained by encrypting the second message, and the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message, so that the slave device decrypts the first encrypted message to obtain the first message, and determines the second timestamp information according to the receiving time of the first encrypted message, and the slave device decrypts the second encrypted message to obtain the second message and the first timestamp information carried by the second message, and the slave device corrects the time of the local device according to the first timestamp information and the second timestamp information; receiving a third encrypted message sent by the slave device, where the third encrypted message is obtained by the slave device encrypting the third message; Decrypting the third encrypted message to obtain the third message, and determining fourth timestamp information according to a time when the third encrypted message is received; A fourth encrypted message and a fifth encrypted message are sent to the slave device, wherein the fourth encrypted message is obtained by encrypting the fourth message, and the fifth encrypted message is obtained by encrypting the fifth message, the fourth message carries the fourth timestamp information, and the fifth message carries the fifth timestamp information, and the fifth timestamp information represents the sending time of the fourth encrypted message, so that the slave device decrypts the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determines the sixth timestamp information according to the receiving time of the fourth encrypted message; and so that the slave device decrypts the fifth encrypted message to obtain the fifth message and the fifth timestamp information carried by the fifth message, and so that the slave device corrects the time of the local device according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
7. The method according to claim 6, characterized in that The generation process of the first encrypted message and the second encrypted message includes: Generate the first message and the second message; Encrypting the first message to obtain the first encrypted message, and when the encryption of the first message is completed, acquiring clock information of the local device, and determining first timestamp information based on the clock information; The second message is encrypted to obtain the second encrypted message.
8. The method according to claim 7, characterized in that The first timestamp information is a data field preset in the second message; The encrypting the second message to obtain the second encrypted message includes: Encrypting the data field based on a preset first encryption strategy and a preset key to obtain a data ciphertext; Encrypting the data ciphertext based on a preset second encryption strategy to obtain an authentication tag; Generate the second encrypted message according to the data ciphertext and the authentication tag; The encrypting the first message to obtain the first encrypted message includes: The first message is encrypted based on a preset second encryption strategy to obtain the first encrypted message.
9. A time synchronization device, characterized in that: The device comprises: A receiving module, configured to receive a first encrypted message and a second encrypted message sent by a master device; the first encrypted message is obtained by the master device encrypting the first message, and the second encrypted message is obtained by the master device encrypting the second message; the second message carries first timestamp information, and the first timestamp information represents the sending time of the first encrypted message; a decryption module, configured to determine second timestamp information according to a time of receiving the first encrypted message; and decrypt the second encrypted message to obtain the second message and the first timestamp information carried by the second message; a synchronization module, configured to correct the time of the local device according to the first timestamp information and the second timestamp information; and further configured to send a third encrypted message to the master device so that the master device decrypts the third encrypted message and determines a fourth timestamp information according to a time of receiving the third encrypted message; Also used for the third encrypted message to be obtained by encrypting the third message; Also used for receiving a fourth encrypted message and a fifth encrypted message sent by the master device; the fourth encrypted message is obtained by the master device encrypting the fourth message, and the fifth encrypted message is obtained by the master device encrypting the fifth message; the fourth message carries the fourth timestamp information, and the fifth message carries the fifth timestamp information; the fifth timestamp information represents the sending time of the fourth encrypted message; It is also used to decrypt the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determine the sixth timestamp information according to the receiving time of the fourth encrypted message; Also used for decrypting the fifth encrypted message to obtain the fifth message and the fifth timestamp information carried by the fifth message; It is also used to correct the time of the local device according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
10. A time synchronization device, characterized in that: The device comprises: a sending module, configured to send a first encrypted message and a second encrypted message to a slave device, wherein the first encrypted message is obtained by encrypting the first message, the second encrypted message is obtained by encrypting the second message, the second message carries first timestamp information, and the first timestamp information represents a sending time of the first encrypted message, so that the slave device decrypts the first encrypted message to obtain the first message, and determines the second timestamp information according to a receiving time of the first encrypted message, and the slave device decrypts the second encrypted message to obtain the second message and the first timestamp information carried by the second message, and the slave device corrects the time of a local device according to the first timestamp information and the second timestamp information; Also used for receiving a third encrypted message sent by the slave device, wherein the third encrypted message is obtained by the slave device encrypting the third message; It is also used to decrypt the third encrypted message to obtain the third message, and determine fourth timestamp information according to the reception time of the third encrypted message; It is also used to send a fourth encrypted message and a fifth encrypted message to the slave device, the fourth encrypted message is obtained by encrypting the fourth message, the fifth encrypted message is obtained by encrypting the fifth message, the fourth message carries the fourth timestamp information, the fifth message carries the fifth timestamp information, and the fifth timestamp information represents the sending time of the fourth encrypted message, so that the slave device decrypts the fourth encrypted message to obtain the fourth message and the fourth timestamp information carried by the fourth message, and determines the sixth timestamp information according to the receiving time of the fourth encrypted message; and so that the slave device decrypts the fifth encrypted message to obtain the fifth message and the fifth timestamp information carried by the fifth message, and so that the slave device corrects the time of the local device according to the first timestamp information, the second timestamp information, the third timestamp information, the fourth timestamp information, the fifth timestamp information and the sixth timestamp information; the third timestamp information represents the sending time of the third encrypted message.
11. An electronic device, characterized in that: The device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the time synchronization method as described in any one of claims 1 to 8.
12. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the time synchronization method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Synchronized method and device of encrypted messages between each other
CN103118029A
Network node, packet transmission method and network
CN108781162A
Clock synchronization method and device in encrypted communication process and multi-device system
CN112398567A
Networking verification method and device and computer readable storage medium
CN112866987A
System and information writing method
JP2018110355A
