A method for obtaining system time and terminal equipment
By running system clock services in the TEE of the terminal device, using NTP servers, satellites and base stations to obtain absolute time and generate system time, the problem of system clocks being easily tampered with is solved, and the security and accuracy of system time are improved.
Patent Information
- Application Number
- CN202011105785.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-15
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2040-10-15
AI Technical Summary
The system clock service in the terminal device is easily tampered with, resulting in system time errors and affecting the normal operation of the device.
Run the system clock service in the TEE of the terminal device, obtain the absolute time by sending requests to the NTP server, satellite and base station, and generate the system time based on the received response, ensuring the security and accuracy of the system time.
It effectively prevents system time from being tampered with, improves the security and accuracy of system time of terminal equipment, and ensures the normal operation of the equipment.
Smart Images

Figure CN114374460B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal control technology, and in particular to a method for acquiring system time and a terminal device. Background Art
[0002] Currently, applications in terminal devices (such as camera services, payment services, and system clock services) can run in rich execution environments (REE) or trusted execution environments (TEE) according to different security levels. For example, camera services have relatively low security requirements and can run in REE. Payment services have relatively high security requirements and can run in TEE.
[0003] Among them, REE is a less secure execution environment, and applications running in REE are easily tampered with. Generally speaking, the above-mentioned system clock service also runs in REE. Therefore, the system clock service is easily tampered with, and the wrong system time is output, resulting in the terminal device being unable to provide services to users normally. Summary of the invention
[0004] The present application provides a method for obtaining system time and a terminal device, which can ensure the security and accuracy of the system time of the terminal device, and further use the correct system time to ensure the normal operation of the terminal device.
[0005] In order to achieve the above technical objectives, this application adopts the following technical solutions:
[0006] In the first aspect, the present application provides a method for obtaining system time, which is applied to a terminal device, and the terminal device includes a TEE. The method includes: the terminal device runs a system clock service in the TEE, and sends a first request to the network time protocol NTP server, the satellite, and the base station; the terminal device receives at least one of the following: a first response from the satellite, a first response from the base station, and a first response from the NTP server, and the terminal device generates the system time of the terminal device through the system clock service according to the preset security level and the absolute time in the received first response. Among them, the first request is used to obtain absolute time; the preset security level includes the security level of the absolute time of the satellite, the base station, and the NTP server.
[0007] Using the method provided by the present application, on the one hand, the terminal device can run the system clock service in the TEE and send a first request to the NTP server, satellite and base station, and the first request is used to obtain the absolute time. Therefore, after receiving the first request, the NTP server, satellite and base station can return a first response including the absolute time to the terminal device. The terminal device can then receive the first response; then generate the system time of the terminal device according to the absolute time in the first response.
[0008] Among them, since the system clock service is located in the TEE of the terminal device, and TEE is a highly secure execution environment, the information in the TEE can only be accessed or modified by the trusted application (TA) authorized by the TEE. Therefore, it is difficult for third-party tools outside the TEE to tamper with the information in the TEE, and the system time generated by the system clock service in the TEE will not be tampered with, ensuring the security and accuracy of the system time of the terminal device. In addition, using the correct system time can ensure the normal operation of the terminal device.
[0009] On the other hand, the terminal device sends a first request to the NTP server, the satellite and the base station, that is, requests the NTP server, the satellite and the base station to obtain the absolute time. Then, at least one of the first response from the NTP server, the first response from the satellite and the first response from the base station can be received; and the system time of the terminal device is generated by using at least one first response, thereby avoiding the problem that the system time of the terminal device cannot be generated when the first response from the NTP server cannot be received due to the NTP server stopping working, or the problem that the system time of the terminal device cannot be generated when the first response from the satellite or the base station cannot be received due to the communication failure with the satellite or the base station, thereby improving the reliability of obtaining the system time of the terminal device.
[0010] In a possible implementation, the received first response is a first response from a first object, and the first object belongs to a satellite, a base station, and an NTP server. The method also includes: if the first object does not include the highest priority among the satellite, the base station, and the NTP server, the terminal device resends the first request to the second object through the system clock service. The security level of the absolute time of the second object is higher than the security level of the absolute time of the first object, and the second object belongs to the satellite, the base station, and the NTP server.
[0011] In this design, when the terminal device receives a first response from the first object, and the first object does not include the satellite, base station, and NTP server with the highest absolute time security level, the terminal device re-sends a first request to the second object with a higher absolute time security level than the first object, so as to re-request the absolute time from the satellite, base station, and NTP server with a higher absolute time security level. Then, the system time of the terminal device can be generated using the absolute time with a higher security level. Since the possibility of tampering with the absolute time with a higher security level is lower, the system time of the terminal device is generated using the absolute time with a higher security level, which improves the security and accuracy of the system time of the terminal device.
[0012] In another possible implementation, the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and the security level of the absolute time of the base station is higher than the security level of the absolute time of the satellite. The terminal device generates the system time of the terminal device through the system clock service according to the preset security level and the absolute time in the received first response, including: if the received first response includes a first response from the satellite and / or the base station, and a first response from the NTP server, the terminal device generates the system time of the terminal device through the system clock service according to the first absolute time in the first response from the NTP server.
[0013] It is understandable that the terminal device may receive a first response from a satellite and / or a base station, and a first response from an NTP server. Among them, the absolute time in the first response from an NTP server, a satellite or a base station can be used to generate the system time of the terminal device. However, compared with the absolute time in the first response from a satellite or a base station, the first absolute time in the first response from an NTP server has a higher security level. Therefore, if the terminal device receives a first response from a satellite and / or a base station, and a first response from an NTP server at the same time, the terminal device can generate the system time of the terminal device according to the first absolute time in the first response from the NTP server through the system clock service. Since the security level of the first absolute time in the first response from the NTP server is higher, the possibility of the first absolute time being tampered with is lower. Therefore, generating the system time of the terminal device according to the first absolute time in the first response from the NTP server can further improve the security and accuracy of the system time of the terminal device.
[0014] In another possible implementation, the terminal device generates the system time of the terminal device through a system clock service according to a preset security level and the absolute time in the first response received, including: if the received first response is a first response from a satellite and / or a base station, the terminal device generates the system time of the terminal device through a system clock service according to the preset security level, and the second absolute time in the first response from the satellite and / or the second absolute time in the first response from the base station.
[0015] In this design, the terminal device sends a first request to the NTP server, satellite and base station, that is, requests the NTP server, satellite and base station to obtain the absolute time. Furthermore, if the first response from the NTP server is not received, but the first response from the satellite and / or base station is received, the system time of the terminal device can be generated by the system clock service using the second absolute time in the first response from the satellite and / or the second absolute time in the first response from the base station. This avoids the problem of being unable to generate the system time of the terminal device when the first response from the NTP server cannot be received due to the NTP server stopping working, and improves the reliability of obtaining the system time of the terminal device.
[0016] Secondly, since it is difficult for third-party tools outside of TEE to tamper with the information in TEE, the system time generated by the system clock service in TEE will not be tampered with, ensuring the security and accuracy of the system time of the terminal device. Using the correct system time of the terminal device can ensure the normal operation of the terminal device.
[0017] In another possible implementation, the method further includes: if the terminal device receives a first response from the NTP server within a preset time period starting from the time when the terminal device generates the system time according to the preset security level and the second absolute time, the terminal device generates the system time of the terminal device according to the first absolute time in the first response from the NTP server through the system clock service.
[0018] In this design, after the terminal device generates the system time using the second absolute time in the first response from the base station or satellite, if the terminal device receives the first response from the NTP server, the terminal device's system time is generated using the first absolute time in the first response from the NTP server. Since the security level of the first absolute time from the NTP server is greater than the security level of the second absolute time from the base station or satellite, the security of the system time generated using the first absolute time is higher than the security of the system time generated using the second absolute time. Further, the system time generated using the first absolute time is replaced by the system time generated using the second absolute time, which can improve the security of the terminal device's system time.
[0019] In another possible implementation, the method further includes: if the terminal device does not receive a first response from the NTP server within a preset time period starting from the time the terminal device generates the system time according to a preset security level and a second absolute time, the terminal device resends the first request to the NTP server through the system clock service.
[0020] In this design, after the terminal device generates the system time using the second absolute time in the first response from the base station or satellite, if the first response from the NTP server is not received, the first request is resent to the NTP server, the satellite and the base station. Since the security level of the first absolute time from the NTP server is greater than the security level of the second absolute time from the base station or the satellite. Therefore, if the first response from the NTP server is not received, the first request can continue to be sent to the NTP server, the satellite and the base station to request to obtain the absolute time, so as to request to obtain the first absolute time from the NTP server with a higher security level. This can improve the security and accuracy of the system time of the terminal device.
[0021] In another possible implementation, the terminal device runs a system clock service in TEE and sends a first request to the timing server NTP server, satellite and base station, including: when the terminal device is turned on, the system clock service is run in TEE and the first request is sent to the NTP server, satellite and base station.
[0022] In this design method, an implementation method is described in which a terminal device sends a first request to an NTP server, a satellite, and a base station through a system clock service.
[0023] In another possible implementation, the terminal device runs a system clock service in TEE and sends a first request to the timing server NTP server, satellite and base station, including: after the terminal device is turned on, it periodically runs a system clock service in TEE and sends a first request to the NTP server, satellite and base station.
[0024] In this design method, another implementation method is described in which the terminal device sends a first request to the NTP server, satellite and base station through the system clock service.
[0025] In another possible implementation, the method further includes: when the terminal device generates the system time through the system clock service, the first real-time relative time is obtained from the TEE, and the system time and the first real-time relative time are saved; when the terminal device receives a time synchronization request from any application in the terminal device, the second real-time relative time is obtained from the TEE through the system clock service, and the real-time system time of the terminal device is calculated according to the system time, the first real-time relative time and the second real-time relative time; the terminal device outputs the real-time system time to the application through the system clock service. Among them, the first real-time relative time is the time from the terminal device being turned on to the generation of the system time; the second real-time relative time is the time from the terminal device being turned on to the receipt of the time synchronization request.
[0026] In this design, since the system time of the terminal device changes in real time, and the system time generated by the terminal device is the system time at a certain moment. Therefore, while generating the system time, the first real-time relative time can be recorded, that is, the duration from the terminal device being turned on to the generation of the system time. Furthermore, if a time synchronization request of any application is received, the second real-time relative time when the time synchronization request is received is obtained, that is, the duration from the terminal device being turned on to the reception of the time synchronization request. According to the first real-time relative time and the second real-time relative time, the duration from the generation of the system time to the reception of the time synchronization request can be obtained. Furthermore, using the system time and the duration from the generation of the system time to the reception of the time synchronization request, the system time when the time synchronization request is received, that is, the real-time system time of the terminal device, can be calculated. Then, the real-time system time is output to the application.
[0027] In another possible implementation, the method further includes: when the terminal device generates the system time through the system clock service, the terminal device obtains the first real-time relative time from the TEE, and saves the system time and the first real-time relative time; when the terminal device receives the shutdown command, the terminal device obtains the third real-time relative time from the TEE through the system clock service; the terminal device calculates the shutdown time of the terminal device according to the system time, the first real-time relative time and the third real-time relative time through the system clock service, and saves the shutdown time. Among them, the first real-time relative time is the length of time from the terminal device being turned on to the generation of the system time; the third real-time relative time is the length of time from the terminal device being turned on to the receipt of the shutdown command.
[0028] In this design, since the system time of the terminal device changes in real time, and the system time generated by the terminal device is the system time at a certain moment. Therefore, when the system time is generated, the first real-time relative time can be recorded, that is, the time from the terminal device being turned on to the generation of the system time. Furthermore, if a shutdown command is received, the third real-time relative time when the shutdown command is received is obtained, that is, the time from the terminal device being turned on to the reception of the shutdown command. According to the first real-time relative time and the third real-time relative time, the time from the generation of the system time to the reception of the shutdown command can be obtained. Furthermore, using the system time and the time from the generation of the system time to the reception of the shutdown command, the system time when the shutdown command is received, that is, the shutdown time, can be calculated.
[0029] In another possible implementation, before the above-mentioned terminal device runs the system clock service in the TEE and sends a first request to the Network Time Protocol NTP server, satellite and base station, the method also includes: the terminal device establishes a secure channel for data transmission between the system clock service and the NTP server; wherein the terminal device sends the first request to the NTP server through the secure channel, and the terminal device receives a first response from the NTP server through the secure channel.
[0030] In this design, the terminal device establishes a secure channel for data transmission between the system clock service and the NTP server, so as to send a first request to the NTP server through the secure channel and receive a first response from the NTP server through the secure channel. This prevents third-party tools outside the TEE from tampering with the first response being sent, and ensures the security of the first absolute time in the first response from the NTP server. This improves the security and accuracy of the system time generated using the first absolute time in the first response from the NTP server.
[0031] In another possible implementation, the terminal device includes REE. The terminal device establishes a secure channel for data transmission between the system clock service and the NTP server, including: the terminal device establishes a secure channel for data transmission between the system clock service and the NTP server through REE; wherein the secure channel passes through REE.
[0032] In this design method, an implementation method for a terminal device to establish a secure channel for data transmission between a system clock service and an NTP server is described.
[0033] In another possible implementation, the terminal device includes a satellite positioning chip and a modem. The terminal device sends a first request to the satellite via the satellite positioning chip through a system clock service, and the terminal device receives a first response from the satellite from the satellite positioning chip through the system clock service. The terminal device sends a first request to the base station via the modem through the system clock service, and the terminal device receives a first response from the base station from the modem through the system clock service.
[0034] In this design, the terminal device receives the first response from the satellite directly from the satellite positioning chip through the system clock service, that is, directly receives the absolute time in the first response from the satellite from the satellite positioning chip. This avoids the possibility of tampering with the absolute time in the first response from the satellite during the process of transmitting the absolute time in the first response from the satellite through other modules in the terminal device except the satellite positioning chip. Similarly, the terminal device receives the first response from the base station directly from the modem through the system clock service, that is, directly receives the absolute time in the first response from the base station from the modem. This avoids the possibility of tampering with the absolute time in the first response from the base station during the process of transmitting the absolute time in the first response from the base station through other modules except the modem. Further, the possibility of tampering with the absolute time in the first response from the base station by a third-party tool is avoided, thus ensuring the security and accuracy of the absolute time in the first response from the satellite and the base station.
[0035] In the second aspect, the present application provides a method for obtaining system time, which is applied to a terminal device, wherein the terminal device includes a TEE, and the method includes: the terminal device runs a system clock service in the TEE, and sends a first request to a network time protocol NTP server; the terminal device receives a first response from the NTP server; wherein the first response includes a first absolute time; the terminal device generates the system time of the terminal device according to the first absolute time through the system clock service. wherein the first request is used to obtain the first absolute time from the NTP server.
[0036] In a possible implementation, the method further includes: when the terminal device generates the system time through the system clock service, the first real-time relative time is obtained from the TEE, and the system time and the first real-time relative time are saved; when the terminal device receives a time synchronization request from any application in the terminal device, the second real-time relative time is obtained from the TEE through the system clock service, and the real-time system time of the terminal device is calculated according to the system time, the first real-time relative time and the second real-time relative time; the terminal device outputs the real-time system time to the application through the system clock service. Among them, the first real-time relative time is the time from the terminal device being turned on to the generation of the system time; the second real-time relative time is the time from the terminal device being turned on to the receipt of the time synchronization request.
[0037] In another possible implementation, the terminal device runs a system clock service in TEE and sends a first request to the timing server NTP server, including: after the terminal device is turned on, the system clock service is periodically run in TEE and the first request is sent to the NTP server; or, when the terminal device is turned on, the system clock service is run in TEE and the first request is sent to the NTP server.
[0038] In another possible implementation, before the terminal device runs the system clock service in the TEE and sends the first request to the network time protocol NTP server, the method further includes: the terminal device establishes a secure channel for data transmission between the system clock service and the NTP server. The terminal device sends the first request to the NTP server through the secure channel, and the terminal device receives the first response from the NTP server through the secure channel.
[0039] In another possible implementation, the terminal device includes a rich execution environment (REE). The terminal device establishes a secure channel for data transmission between the system clock service and the NTP server, including: the terminal device establishes a secure channel for data transmission between the system clock service and the NTP server through the REE; wherein the secure channel passes through the REE.
[0040] In the third aspect, the present application also provides a method for obtaining system time, which is applied to a terminal device, wherein the terminal device includes a TEE, and the method includes: the terminal device runs a system clock service in the TEE and sends a first request to a satellite or a base station; the terminal device receives a first response from the satellite or the base station; the terminal device generates the system time of the terminal device according to the second absolute time through the system clock service. The first request is used to obtain the second absolute time from the satellite; and the first response includes the second absolute time.
[0041] In a possible implementation, the method further includes: when the terminal device generates the system time through the system clock service, the first real-time relative time is obtained from the TEE, and the system time and the first real-time relative time are saved; when the terminal device receives a time synchronization request from any application in the terminal device, the second real-time relative time is obtained from the TEE through the system clock service, and the real-time system time of the terminal device is calculated according to the system time, the first real-time relative time and the second real-time relative time; the terminal device outputs the real-time system time to the application through the system clock service. Among them, the first real-time relative time is the time from the terminal device being turned on to the generation of the system time; the second real-time relative time is the time from the terminal device being turned on to the receipt of the time synchronization request.
[0042] In another possible implementation, the terminal device runs a system clock service in the TEE and sends a first request to the satellite or base station, including: after the terminal device is powered on, the system clock service is periodically run in the TEE and the first request is sent to the satellite or base station; or, when the terminal device is powered on, the system clock service is run in the TEE and the first request is sent to the satellite or base station.
[0043] In a fourth aspect, the present application also provides a terminal device, comprising: a processor and a memory; wherein the memory is used to store computer program code, and the computer program code includes computer instructions; the processor is used to run the computer instructions so that the terminal device executes a method for obtaining system time as described in the first aspect, the second aspect, the third aspect and any possible implementation manner thereof.
[0044] In a fifth aspect, the present application further provides a chip system, which is applied to a mobile terminal, such as the mobile terminal described in the fourth aspect. The chip system includes one or more interface circuits and one or more processors. The interface circuit and the processor are interconnected by a line. The interface circuit is used to receive a signal from the memory of the mobile terminal and send the received signal to the processor. The signal may include a computer instruction stored in the memory. When the above-mentioned processor executes the computer instruction, the above-mentioned mobile terminal can execute the method for obtaining the system time as described in the first aspect, the second aspect, the third aspect and any possible implementation method thereof.
[0045] In the sixth aspect, the present application also provides a computer-readable storage medium, on which computer instructions are stored. When the computer instructions are executed on a terminal device, the terminal device executes a method for obtaining system time such as the first aspect, the second aspect, the third aspect and any possible implementation methods thereof.
[0046] In the seventh aspect, the present application also provides a computer program product, comprising one or more instructions, which can be run on a terminal device, so that the terminal device executes a method for obtaining system time such as the first aspect, the second aspect, the third aspect and any possible implementation method thereof.
[0047] The technical effects brought about by the second aspect of this application and any possible design thereof, as well as the third, fourth, fifth, sixth and seventh aspects can refer to the technical effects brought about by the different design methods in the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 A schematic diagram of the composition of a terminal device provided in conventional technology Figure 1 ;
[0049] Figure 2 A schematic diagram of the composition of a terminal device provided in conventional technology Figure 2 ;
[0050] Figure 3 A schematic diagram of a conventional technique for controlling a mobile phone communication function according to a system time;
[0051] Figure 4 A schematic diagram of an implementation environment involved in a method for obtaining system time provided in an embodiment of the present application;
[0052] Figure 5 A hardware structure diagram of a terminal device provided in an embodiment of the present application;
[0053] Figure 6 A schematic diagram of the composition of a terminal device provided in an embodiment of the present application Figure 1 ;
[0054] Figure 7 A method for obtaining system time provided in the embodiment of the present application Figure 1 ;
[0055] Figure 8 A method for obtaining system time provided in the embodiment of the present application Figure 2 ;
[0056] Fig. 9 A method for obtaining system time provided in the embodiment of the present application Figure 3 ;
[0057] Fig.10 A method for obtaining system time provided in the embodiment of the present application Figure 4 ;
[0058] Fig.11A method for obtaining system time provided in the embodiment of the present application Figure 5 ;
[0059] Fig.12 A schematic diagram of the composition of a terminal device provided in an embodiment of the present application Figure 2 ;
[0060] Fig.13 A schematic diagram of the composition of a terminal device provided in an embodiment of the present application Figure 3 ;
[0061] Fig.14 A schematic diagram of the composition of a terminal device provided in an embodiment of the present application Figure 4 ;
[0062] Fig.15 A method for obtaining system time provided in the embodiment of the present application Figure 6 ;
[0063] Fig.16 A schematic diagram of the composition of a terminal device provided in an embodiment of the present application Figure 5 ;
[0064] Fig.17 A method for obtaining system time provided in the embodiment of the present application Figure 7 ;
[0065] Fig.18 A schematic diagram of the composition of a terminal device provided in an embodiment of the present application Figure 6 ;
[0066] Fig.19 A method for obtaining system time provided in the embodiment of the present application Figure 8 ;
[0067] Fig. 20 A schematic diagram of the structure of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0068] In the following, the terms "first", "second", "third", etc. are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", "third", etc. may explicitly or implicitly include one or more of the features.
[0069] At present, considering that different applications have different security requirements, for example, applications involving some private information have very high security requirements for the execution environment, while other applications that do not involve private information have lower security requirements for the execution environment. In order to meet the security requirements of different applications, the terminal device is divided into three areas, and the security of these three parts from low to high are REE, TEE and independent chip.
[0070] See also Figure 1 The terminal device 100 includes an application processor (AP) chip 101 and an independent chip 102. The AP chip 101 is used to process all applications (APP) of the terminal device. The independent chip 102 refers to a chip with some specific functions that cannot be changed externally, such as Figure 1 As shown, the independent chip 102 may include a secure element (SE) having an encryption / decryption logic circuit, a modem for communicating with a base station, and an integrated chip providing certain specific functions.
[0071] REE and TEE are located in two mutually isolated areas in the AP chip 101. Moreover, REE and TEE are not only mutually isolated in hardware, but also run their own operating systems. Applications running in REE have relatively low security requirements, such as Figure 1 As shown in Figure 1, applications running in REE are called Common Applications (CA). The operating system (OS) of REE can be Linux, Android, or iOS. Applications running in TEE have high security requirements, such as Figure 1 As shown in the figure, the application running in TEE is called a trusted application TA. TEE stores sensitive information such as user identity, keys, and certificates in a secure area. This sensitive information can only be accessed or modified by the trusted application TA authorized by TEE, and TEE provides encryption and integrity protection mechanisms for the operation and processing of this sensitive information. At the same time, the keys stored in TEE can be used to encrypt user information in a normal execution environment, such as address books, text messages, and other sensitive information, to ensure the security of sensitive information stored in REE.
[0072] In conventional technology, terminal devices mainly communicate with other external devices through REE to achieve data interaction functions. For example, terminal devices communicate with NTP servers through REE to obtain system time through NTP servers. Figure 2As shown in the schematic diagram of the composition of the terminal device, the terminal device 210 includes a TEE and a REE. Among them, the REE includes a system physical clock. The process of the terminal device 210 obtaining the system time through the REE may include: the terminal device 210 runs the system clock service in the REE, and sends a request for obtaining the time to the NTP server 220. The NTP server 220 receives and responds to the request, and returns the cloud time by the original route. The terminal device 210 receives the cloud time through the system clock service in the REE, and sends the cloud time to the system physical clock. The system physical clock updates the system time of the terminal device 210 in real time according to the cloud time.
[0073] Among them, the NTP server 220 can provide accurate time, and the source of time obtained by the NTP server 220 can be an atomic clock, an observatory, a satellite, or can be obtained from the Internet. The time output by the NTP server 200 to an external device (such as the terminal device 100) is called cloud time.
[0074] like Figure 2 As shown, the general application CA running in REE can modify the system time through the interface provided by the system clock service. Users can also operate on the application provided by the REE operating system (which can be referred to as the system application) to modify the system time through the interface provided by the system clock service. In addition, due to the low security of REE, hackers may use hacking tools to obtain the highest authority (such as root authority) of the REE operating system; then, use the highest authority to hijack the REE operating system, that is, any file (including system files) in the REE operating system can be operated, including modifying the system time through the interface provided by the system clock service.
[0075] In summary, general application CA, users and hackers may tamper with the system time through the system clock service running in REE. Although there is a real-time relative time in TEE that will not be tampered with; however, the real-time relative time is a relative time and cannot be used alone as the basis for obtaining the system time of the terminal device. If a physical clock is added to TEE to generate the system time, the hardware cost will increase. Therefore, it can be seen that the system time of the terminal device obtained by using the above conventional technology without increasing the hardware cost is at risk of being tampered with.
[0076] If the system time of a terminal device is tampered with, the terminal device will output the wrong system time, which will cause the terminal device to be unable to provide services to users normally. The following describes the impact of system time tampering on the normal operation of terminal devices in combination with various scenarios.
[0077] Scenario 1: Some applications with high security requirements often need to connect to the Internet regularly to update data; and they can only continue to provide services to users if the data is updated on time, otherwise they will stop providing services to users.
[0078] For example, an application that uses the central bank's digital currency (DCEP) for payment needs to regularly update the "central bank wallet authentication sub-private key". If the system time is wrong and the application fails to regularly update the "central bank wallet authentication sub-private key" from the backend server, the backend server will stop providing payment services to users through the application.
[0079] For another example, an application that provides offline electronic contracts generates an electronic contract that includes a timestamp for recording the time when the electronic contract was generated. The time recorded in the timestamp is generated by the application based on the system time. If the system time is wrong, the time recorded in the timestamp is wrong. If the time recorded in the timestamp is wrong, the effective time of the electronic contract is wrong, and the user cannot use the electronic contract.
[0080] Scenario 2: For mobile phones purchased by users through installment payments from operators that provide network services, the operators will control whether to provide network services for the mobile phones based on whether the users pay on time, in order to reduce the losses caused by users' failure to pay as agreed. Figure 3 As shown in the flowchart of controlling the communication function of the mobile phone, if a user fails to pay on time after purchasing a mobile phone 330, the operator operates the server 310 managing network services so that the server 310 managing network services sends a lock command for the mobile phone 330 to the server 320 managing the modem. The server 320 managing the modem then sends the lock command to the APP managing the modem running in the REE of the mobile phone 330. The lock command is sent to the TA managing the modem running in the TEE of the mobile phone 330 through the APP managing the modem. The lock command is sent to the modem TA managing the modem running in the TEE of the mobile phone 330 through the TA managing the modem to the modem 331, and then the modem 331 stops working, and the mobile phone 330 cannot use network services (such as making calls, sending text messages, and surfing the Internet).
[0081] However, in order to use the network service of mobile phone 330 without paying, the user may take illegal means to set the APP managing the modem running in REE so that it cannot communicate with the server 320 managing the modem, so that the server 320 managing the modem cannot issue a lock command. In view of this situation, the APP managing the modem can be pre-set to automatically generate a lock command when it has not communicated with the server 320 managing the modem for a long time, so as to control modem 331 to stop working. However, if the user also takes illegal means to tamper with the system time through the system clock service running in REE, and the system time is wrong, the APP managing the modem cannot determine that it has not communicated with the server 320 managing the modem for a long time, and cannot automatically generate a lock command. In this way, modem 331 continues to work, resulting in the user still being able to use the communication service of mobile phone 330 without paying on time, causing losses to the operator.
[0082] In order to avoid the above problems caused by inaccurate system time of terminal devices, an embodiment of the present application provides a method for obtaining system time. Through this method, the security and accuracy of the system time of the terminal device can be improved without increasing hardware costs, thereby ensuring the normal operation of the terminal device.
[0083] Please refer to Figure 4 , which shows a schematic diagram of the implementation environment involved in a method for obtaining system time provided in an embodiment of the present application. Figure 4 As shown, the implementation environment may include an NTP server 410 and a terminal device 420. The NTP server 410 is used to obtain cloud time from an atomic clock, an observatory, a satellite, or the Internet; and is also used to send the cloud time to the terminal device 420 in response to a request for obtaining time sent by the terminal device 420. The terminal device 420 is used to receive the cloud time sent by the NTP server 410; and the cloud time can be used to generate the system time.
[0084] Optionally, the implementation environment may also include one or more satellites, such as satellite 431 and satellite 432. Each satellite (including satellite 431 and satellite 432) is used to provide high-precision, high-reliability positioning, navigation, and timing services for various users around the clock. The terminal device 420 has a satellite positioning chip for communicating with one or more satellites to obtain information such as position, speed, and satellite time from one or more satellites. Furthermore, the terminal device 420 can also use satellite time to generate system time. Among them, the satellite positioning chip in the terminal device 420 can receive satellite data sent by each satellite, and then extract satellite time from the satellite data. Multiple satellites may include: BeiDou Navigation Satellite System (BDS), Global Positioning System (GPS), GLONASS, Galileo satellite navigation system and other satellite systems.
[0085] Optionally, the implementation environment may further include one or more base stations, such as base station 441 and base station 442. Each base station is used to provide wireless communication functions for the terminal device. The terminal device 420 has a modem for communicating with one or more base stations to implement communication services such as making calls, sending text messages, and surfing the Internet. The modem is also used to receive base station data sent by each base station, and then extract the base station time from the base station data. Furthermore, the terminal device 420 can also use the base station time to generate the system time.
[0086] Among them, base stations can be roughly divided into the following types according to the wireless access technology used in the system: 2G base stations in the second generation mobile phone communication technology specification (2-Generation wireless telephone technology, 2G) network, 3G base stations in the third generation mobile communication technology (3G) network, 4G base stations in the fourth generation mobile communication technology (4G) network, and 5G base stations in the fifth generation mobile communication technology (5G) network. Secondly, in systems using different wireless access technologies, the names of base stations may be different. For example, in the LTE system, it is called an evolved NodeB (eNB or eNodeB); in the third generation mobile communication technology (3G) system, it is called a base station (Node B).
[0087] It should be noted that the above cloud time, satellite time and base station time are all absolute time. Absolute time refers to time that is independent of any particular reference system and can also be called standard time. Absolute time can include year, month, day, hour, minute and second, for example, 18:09:52 on August 26, 2020. Different countries set their own absolute time according to their own longitude and latitude.
[0088] It should be noted that the terminal device in the embodiment of the present application can be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, etc. The embodiment of the present application does not impose any special restrictions on the specific form of the terminal device. As an example, Figure 4 As shown, the implementation environment of the embodiment of the present application includes a terminal device 420, which is shown by taking a mobile phone as an example.
[0089] The following continues to take the terminal device 420 as a mobile phone as an example to introduce the hardware structure of the terminal device. Figure 5As shown, the terminal device 420 may include: a processor 510, an external memory interface 520, an internal memory 521, a universal serial bus (USB) interface 530, a charging management module 540, a power management module 541, a battery 542, an antenna 1, an antenna 2, a mobile communication module 550, a wireless communication module 560, an audio module 570, a speaker 570A, a receiver 570B, a microphone 570C, an earphone interface 570D, a sensor module 580, a button 590, a motor 591, an indicator 592, a camera 593 (which may include cameras 1-N), a display screen 594 (such as a touch screen), and a subscriber identification module (SIM) card interface 595 (which may include SIM card interfaces 1-N), etc.
[0090] Among them, the above-mentioned sensor module 580 may include sensors such as pressure sensor, gyroscope sensor, air pressure sensor, magnetic sensor, acceleration sensor, distance sensor, proximity light sensor, fingerprint sensor, temperature sensor, touch sensor, ambient light sensor and bone conduction sensor.
[0091] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the terminal device 420. In other embodiments, the terminal device 420 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0092] The processor 510 may include one or more processing units, for example, the processor 510 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0093] The controller may be the nerve center and command center of the terminal device 420. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0094] The processor 510 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 510 is a cache memory. The memory may store instructions or data that the processor 510 has just used or cyclically used. If the processor 510 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 510, and thus improves the efficiency of the system.
[0095] In some embodiments, the processor 510 may include one or more interfaces. It is understood that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation on the terminal device 420. In other embodiments, the terminal device 420 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0096] The charging management module 540 is used to receive charging input from a charger (charging input of a wired charger and / or wireless charging input) to charge the battery 542. The charger can be a wireless charger or a wired charger. While the charging management module 540 is charging the battery 542, it can also power the terminal device through the power management module 541.
[0097] The power management module 541 is used to connect the battery 542, the charging management module 540 and the processor 510. The power management module 541 receives input from the battery 542 and / or the charging management module 540, and supplies power to the processor 510, the internal memory 521, the external memory, the display screen 594, the camera 593, and the wireless communication module 560. In some embodiments, the power management module 541 may also be disposed in the processor 510. In other embodiments, the power management module 541 and the charging management module 540 may also be disposed in the same device.
[0098] The wireless communication function of the terminal device 420 can be implemented by antenna 1, antenna 2, mobile communication module 550, wireless communication module 560, modem processor and baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. In some embodiments, the antenna 1 of the terminal device 420 is coupled with the mobile communication module 550, and the antenna 2 is coupled with the wireless communication module 560, so that the terminal device 420 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global navigation satellite system (GNSS), wireless local area network (WLAN) (such as Wi-Fi network) technology, etc. The GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS) and / or satellite based augmentation system (SBAS), etc. Exemplarily, the terminal device 420 may obtain the real-time location information of the terminal device 420 through positioning technologies such as GPS, BDS or SBAS.
[0099] The mobile communication module 550 can provide wireless communication solutions including 2G / 3G / 4G / 5G etc. applied on the terminal device 420. For example, the terminal device 420 can send an email to a server through the mobile communication module 550.
[0100] The wireless communication module 560 can provide wireless communication solutions including WLAN (such as Wi-Fi network), Bluetooth (BT), GNSS, Near Field Communication (NFC), Infrared (IR), and frequency modulation (FM) for application on the terminal device 420. For example, the terminal device 420 can obtain the real-time location information of the terminal device 420 through GNSS positioning technology.
[0101] The terminal device 420 implements the display function through the GPU, the display screen 594, and the application processor. The terminal device 420 can implement the shooting function through the ISP, the camera 593, the video codec, the GPU, the display screen 594, and the application processor. The external memory interface 520 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device 420. The internal memory 521 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 510 executes various functional applications and data processing of the terminal device 420 by running the instructions stored in the internal memory 521. The terminal device 420 can implement the audio function through the audio module 570, the speaker 570A, the receiver 570B, the microphone 570C, the headphone interface 570D, and the application processor.
[0102] It should be noted that the methods in the following embodiments can all be implemented in the terminal device 420 having the above hardware structure.
[0103] In the embodiment of the present application, it is considered that the TEE in the terminal device will store sensitive information such as the user's identity, keys, and certificates in a secure area, and these sensitive information can only be accessed or modified by the trusted application TA authorized by the TEE; then the general application CA and users, hackers, etc. cannot tamper with the sensitive information in the TEE. Therefore, the terminal device can add a system clock service in the TEE. The system time generated by running the system clock service in the TEE will not be tampered with, and running the system clock service in the TEE will not increase the hardware cost. In this way, the security and accuracy of the system time of the terminal device are guaranteed without increasing the hardware cost, and the correct system time can ensure the normal operation of the terminal device.
[0104] Please refer to Figure 6 , is a schematic diagram of the composition of a terminal device provided in an embodiment of the present application. The terminal device 420 is divided into multiple areas according to different functions, which may specifically include TEE, REE, modem611 and satellite positioning chip 612. Among them, a system clock service, one or more TAs, and a first clock for recording the above-mentioned real-time relative time RT are running in the TEE. One or more CAs are running in the REE. TEE can be connected to modem611 and satellite positioning chip 612 respectively. Modem611 is used to communicate with a base station through a wireless network and obtain base station time from base station 620. Satellite positioning chip 612 is used to communicate with satellite 630 through a wireless network and obtain satellite time from satellite 630. The terminal device runs a system clock service in TEE and executes a method for obtaining system time. Obtain at least one of satellite time, base station time and cloud time from an NTP server to generate the system time of the terminal device.
[0105] It should be noted that the methods in the following embodiments can all be implemented in the above-mentioned terminal device 420.
[0106] Please refer to Figure 7 , is a flow chart of a method for obtaining system time provided in an embodiment of the present application. Figure 7 As shown, the method may include S701-S703.
[0107] S701. The terminal device runs a system clock service in TEE and sends a first request to an NTP server, a satellite, and a base station; wherein the first request is used to obtain absolute time.
[0108] The system clock service is pre-set in the TEE of the terminal device. The terminal device can run the system clock service in the TEE to send a first request to the NTP server, satellite and base station through the communication module in the terminal device. If the NTP server, satellite and base station receive the first request respectively, they can respond to the first request and return a first response including the absolute time to the terminal device.
[0109] S702. The terminal device receives at least one of the following: a first response from a satellite, a first response from a base station, and a first response from an NTP server.
[0110] In the embodiment of the present application, the terminal device may receive the first response returned by at least one of the NTP server, satellite and base station, or may not receive the first response returned by any of the NTP server, satellite and base station due to the following factors: the NTP server stops working, the terminal device cannot access all satellites due to the environment, and the terminal device is not located within the coverage of any base station. In addition, the terminal device may also receive the first responses from the NTP server, satellite and base station at the same time, or may receive the absolute time from the NTP server, satellite and base station at different times.
[0111] Furthermore, if the terminal device does not receive the first response from the satellite, the first response from the base station, and the first response from the NTP server, the terminal device runs the system clock service in the TEE and resends the first request to the NTP server, the satellite, and the base station.
[0112] S703. The terminal device generates the system time of the terminal device through the system clock service according to the preset security level and the absolute time in the received first response; wherein the preset security level includes the security level of the absolute time of the satellite, base station and NTP server respectively.
[0113] Among them, the absolute time in the first response from the NTP server is the cloud time; the absolute time in the first response from the base station is the base station time; the absolute time in the first response from the satellite is the satellite time.
[0114] In an embodiment of the present application, the terminal device may pre-store the preset security level in the TEE. If the first response received by the terminal device is the first response from the NTP server, satellite or base station, the terminal device may generate the system time ET of the terminal device according to the absolute time in the received first response through the system clock service, and save the system time ET of the terminal device in the TEE. If the first response received by the terminal device is multiple first responses, the terminal device may select the first response with the highest security level of the corresponding absolute time from the received first responses through the system clock service according to the preset security level; then generate the system time ET of the terminal device according to the absolute time in the first response with the highest security level of the corresponding absolute time, and save the system time ET of the terminal device in the TEE.
[0115] The multiple first responses include at least two of the following: a first response from an NTP server, a first response from a satellite, and a first response from a base station.
[0116] In the embodiment of the present application, the security level of the absolute time of the satellite, base station and NTP server can be set according to the possibility of tampering of the absolute time. The smaller the possibility of tampering of any absolute time, the higher the security level of the absolute time.
[0117] In an embodiment of the present application, the terminal device determines the first response with the highest security level of the corresponding absolute time from the received first response according to the preset security level through the system clock service. The first response with the highest security level of the corresponding absolute time may be the first response from the NTP server, or the first response from the satellite, or the first response from the base station. Furthermore, the terminal device may generate the system time of the terminal device according to the absolute time in the first response from the NTP server, the satellite, or the base station through the system clock service. Among them, the second absolute time in the first response from the satellite may include one or more satellite times; the second absolute time in the first response from the satellite may include one or more satellite times.
[0118] Furthermore, the terminal device may pre-store a first fault-tolerant strategy and a second fault-tolerant strategy in the TEE. The first fault-tolerant strategy is used to indicate the deletion of the base station time of the 2G base station. The second fault-tolerant strategy is used to indicate the deletion of multiple different satellite times, and may also be used to indicate the deletion of multiple different base station times. If the terminal device determines that the first response with the highest security level corresponding to the absolute time is the first response from the NTP server, the first absolute time in the first response from the NTP server is directly used as the system time of the terminal device through the system clock service. If the terminal device determines that the first response with the highest security level corresponding to the absolute time is the first response from the satellite or base station, the system clock service may generate the system time of the terminal device according to the second absolute time in the first response from the satellite or base station in accordance with the first fault-tolerant strategy and / or the second fault-tolerant strategy.
[0119] The absolute time in the first response from the NTP server is referred to as the first absolute time. The absolute time in the first response from the base station and the absolute time in the first response from the satellite are both referred to as the second absolute time.
[0120] The sameness of multiple satellite times may mean that the deviation between any two satellite times among the multiple satellite times is less than the first duration (e.g., 0.5s, 0.1s), rather than that the multiple satellite times are completely equal. Similarly, the sameness of multiple base station times may mean that the deviation between any two base station times among the multiple base station times is less than the second duration (e.g., 0.5s, 0.1s), rather than that the multiple base station times are completely equal. The first duration may be equal to or not equal to the second duration.
[0121] Exemplarily, taking satellite time as an example, if it is determined that the first response with the highest security level of the corresponding absolute time is the first response from the satellite, and the second absolute time in the first response from the satellite is a plurality of different satellite times, then the second absolute time in the first response from the satellite is deleted according to the second fault-tolerant strategy through the system clock service, and the system time of the terminal device is not generated. If it is determined that the first response with the highest security level of the corresponding absolute time is the first response from the satellite, and the second absolute time in the first response from the satellite is a plurality of completely identical satellite times, then any satellite time in the first response from the satellite is used as the system time of the terminal device through the system clock service. If it is determined that the first response with the highest security level of the corresponding absolute time is the first response from the satellite, and the second absolute time in the first response from the satellite is a satellite time, then the satellite time in the first response from the satellite is used as the system time of the terminal device through the system clock service.
[0122] Exemplarily, taking the base station time as an example, if the first response with the highest security level of the corresponding absolute time is determined to be the first response from the base station, and the second absolute time in the first response from the base station is the base station time of multiple non-2G base stations that are not the same, then the second absolute time in the first response from the base station is deleted according to the second fault-tolerant strategy through the system clock service, and the system time of the terminal device is not generated. If the first response with the highest security level of the corresponding absolute time is determined to be the first response from the base station, and the second absolute time in the first response from the base station is the base station time of multiple non-2G base stations that are the same, then the base station time of any non-2G base station is used as the system time of the terminal device through the system clock service. If the first response with the highest security level of the corresponding absolute time is determined to be the first response from the base station, and the second absolute time in the first response from the base station is a base station time, then the base station time in the first response from the base station is used as the system time of the terminal device through the system clock service. If the first response with the highest security level of the corresponding absolute time is determined to be the first response from the base station, and the second absolute time in the first response from the base station is the base station time of a 2G base station, then the second absolute time in the first response from the satellite is deleted according to the first fault-tolerant strategy, and the system time of the terminal device is not generated. Among them, the base station time of the non-2G base station is the base station time that does not come from the 2G base station.
[0123] It is understandable that the terminal device pre-stores a first fault-tolerant strategy and a second fault-tolerant strategy. Among them, the first fault-tolerant strategy is used to delete the base station time of a 2G base station with a greater possibility of forgery, avoid the possibility of tampering with the system time of the terminal device using the forged base station time of the 2G base station, and improve the security of the system time of the terminal device. The second fault-tolerant strategy is used to delete multiple different satellite times. Since multiple different satellite times indicate that there is an erroneous satellite time, deleting multiple different satellite times can avoid using the erroneous satellite time to generate the system time of the terminal device, thereby improving the accuracy of the system time of the terminal device. Similarly, the second fault-tolerant strategy can also be used to delete the base station time of multiple different non-2G base stations. Since the base station time of multiple different non-2G base stations indicates that there is an erroneous base station time, deleting the base station time of multiple different non-2G base stations can avoid using the erroneous base station time to generate the system time of the terminal device, thereby improving the accuracy of the system time of the terminal device.
[0124] In an embodiment of the present application, if the terminal device fails to generate the system time of the terminal device through the system clock service according to the preset security level and the absolute time in the first response received, the terminal device runs the system clock service in the TEE and resends the first request to the NTP server, satellite and base station.
[0125] It is understandable that, on the one hand, the terminal device can run the system clock service in the TEE, and send a first request to the NTP server, satellite and base station, and the first request is used to obtain the absolute time. Therefore, after receiving the first request, the NTP server, satellite and base station can return a first response including the absolute time to the terminal device. The terminal device can then receive the first response. Then the system time of the terminal device is generated according to the absolute time in the first response. Among them, since the system clock service is located in the TEE of the terminal device, and TEE is a highly secure execution environment, the information in the TEE can only be accessed or modified by a trusted application (TA) authorized by the TEE. Therefore, it is difficult for third-party tools outside the TEE to tamper with the information in the TEE, and the system time generated by the system clock service in the TEE will not be tampered with, ensuring the security and accuracy of the system time of the terminal device. Then, by using the correct system time, the normal operation of the terminal device can be guaranteed.
[0126] On the other hand, the terminal device sends a first request to the NTP server, the satellite and the base station, that is, requests the NTP server, the satellite and the base station to obtain the absolute time. Then, at least one of the first response from the NTP server, the first response from the satellite and the first response from the base station can be received; and the system time of the terminal device is generated by using at least one first response, thereby avoiding the problem that the system time of the terminal device cannot be generated when the first response from the NTP server cannot be received due to the NTP server stopping working, or the problem that the system time of the terminal device cannot be generated when the first response from the satellite or the base station cannot be received due to the communication failure with the satellite or the base station, thereby improving the reliability of obtaining the system time of the terminal device.
[0127] In an embodiment of the present application, the first response received is a first response from a first object, and the first object belongs to a satellite, a base station, and an NTP server. If the first object does not include the satellite, the base station, and the NTP server with the highest security level of absolute time, the terminal device resends the first request to the second object through the system clock service. Among them, the security level of the absolute time of the second object is higher than the security level of the absolute time of the first object, and the second object belongs to a satellite, a base station, and an NTP server.
[0128] It is understandable that when the terminal device receives the first response from the first object, and the first object does not include the satellite, base station, and NTP server with the highest absolute time security level, the first request is re-sent to the second object with an absolute time security level greater than the first object, so as to re-request the absolute time from the satellite, base station, and NTP server with an absolute time security level higher. Then, the system time of the terminal device can be generated using the absolute time with a higher security level. Since the absolute time with a higher security level is less likely to be tampered with, the system time of the terminal device is generated using the absolute time with a higher security level, thereby improving the security and accuracy of the system time of the terminal device.
[0129] In the embodiment of the present application, it is taken as an example that the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and the security level of the absolute time of the base station is higher than the security level of the absolute time of the satellite. If the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and also higher than the security level of the absolute time of the satellite, it can be seen that the first absolute time in the first response from the NTP server (i.e., the time on the cloud) is least likely to be tampered with. Therefore, when the first response received by the terminal device includes the first response from the NTP server, the first absolute time in the first response from the NTP server is preferentially used to generate the system time of the terminal device. For details, please refer to Figure 8 , S703 may include S801.
[0130] S801. If the received first response includes a first response from a satellite and / or a base station, and a first response from an NTP server, the terminal device generates a system time of the terminal device according to a first absolute time in the first response from the NTP server through a system clock service.
[0131] The system clock service in the terminal device simultaneously receives the first response from the satellite and / or base station and the first response from the NTP server. The system clock service selects the first response from the NTP server with the highest absolute time security level from the received first responses according to the preset security level; and then uses the first absolute time in the first response from the NTP server as the system time ET of the terminal device.
[0132] It should be noted that in the embodiments of the present application, there is no restriction on the high-low relationship among the security level of the absolute time of the NTP server, the security level of the absolute time of the satellite, and the security level of the absolute time of the base station. The high-low relationship can be that the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and the security level of the absolute time of the base station is higher than the security level of the absolute time of the satellite; it can also be that the security level of the absolute time of the satellite is higher than the security level of the absolute time of the NTP server, and the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station; it can also be other high-low relationships.
[0133] Secondly, for the specific process of executing the method for obtaining the system time for any high-low relationship, please refer to the specific process of executing the method for obtaining the system time when the security level of the absolute time of the above-mentioned NTP server is higher than the security level of the absolute time of the base station, and the security level of the absolute time of the base station is higher than the security level of the absolute time of the satellite. Taking the security level of the absolute time of the satellite being higher than the security level of the absolute time of the NTP server, and the security level of the absolute time of the NTP server being higher than the security level of the absolute time of the base station as an example, if the received first response includes a first response from the NTP server and / or the base station, and a first response from the satellite, the terminal device generates the system time of the terminal device according to the absolute time in the first response from the satellite through the system clock service.
[0134] It is understandable that, since the security level of the first absolute time in the first response from the NTP server is higher, the possibility of the first absolute time being tampered with is lower. Therefore, generating the system time of the terminal device according to the first absolute time in the first response from the NTP server can further improve the security of the system time of the terminal device.
[0135] In an embodiment of the present application, taking the example that the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and the security level of the absolute time of the base station is higher than the security level of the absolute time of the satellite, if the security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and also higher than the security level of the absolute time of the satellite, it can be known that the first absolute time in the first response from the NTP server (i.e., the time on the cloud) is least likely to be tampered with, and the system time generated according to the first absolute time in the first response from the NTP server has the highest accuracy. Then, if the system clock service in the terminal device obtains the system time of the terminal device according to the second absolute time in the first response from the satellite or base station. The system clock service in the terminal device can also continue to send a first request to the NTP server until the first response from the NTP server is received, so as to obtain the system time of the terminal device according to the first absolute time in the first response of the NTP server. The system time obtained according to the first absolute time is more accurate than the system time obtained according to the first absolute time. Specifically, please refer to Fig. 9 , S703 can also include S901-S903.
[0136] S901. If the received first response is the first response from the satellite and / or the base station, the terminal device generates the system time of the terminal device through the system clock service according to the preset security level and the second absolute time in the first response from the satellite and / or the second absolute time in the first response from the base station.
[0137] After the terminal device sends a first request to the NTP server, satellite and base station, if the terminal device receives a first response from the satellite and / or base station before receiving the first response from the NTP server, the terminal device generates the system time ET of the terminal device through the system clock service according to the preset security level and the second absolute time in the first response from the satellite and / or base station, and saves the system time ET of the terminal device in the TEE.
[0138] For example, taking the case where the security level of the absolute time of the base station is greater than the security level of the absolute time of the satellite, the system clock service in the terminal device simultaneously receives a first response from the satellite and a first response from the base station. The system clock service then selects the first response from the base station with the highest absolute time security level from the received first responses according to the preset security level. The system time ET of the terminal device is then generated according to the second absolute time in the first response from the base station.
[0139] It should be noted that the security level of the satellite's absolute time may also be greater than the security level of the base station's absolute time. In the embodiments of the present application, there is no restriction on the security level of the satellite's absolute time being greater than or less than the security level of the base station's absolute time. If the security level of the satellite's absolute time is greater than the security level of the base station's absolute time, and the system clock service in the terminal device receives the first response from the satellite and the first response from the base station at the same time, the system clock service selects the first response from the satellite with the highest absolute time security level from the received first responses according to the preset security level; and then generates the system time ET of the terminal device according to the second absolute time in the first response from the satellite.
[0140] Exemplarily, when the system clock service in the terminal device receives the first response from the satellite, the system clock service directly generates the system time ET of the terminal device according to the second absolute time in the first response from the satellite.
[0141] S902. If the terminal device receives a first response from the NTP server within a preset period of time starting from when the terminal device generates the system time according to the preset security level and the second absolute time, the terminal device generates the system time of the terminal device according to the first absolute time in the first response from the NTP server through the system clock service.
[0142] While the terminal device generates the system time according to the preset security level and the second absolute time, it starts timing and determines whether the timing duration is equal to or greater than the preset duration. If the timing duration is less than the preset duration, and the system clock service in the terminal device receives the first response from the NTP server, the system clock service uses the first absolute time in the first response from the NTP server as the system time of the terminal device, that is, the system time of the terminal device generated according to the first absolute time is used to replace the system time ET of the terminal device generated according to the second absolute time.
[0143] S903. If the terminal device does not receive a first response from the NTP server within a preset time period starting from when the terminal device generates the system time according to the preset security level and the second absolute time, the terminal device resends the first request to the NTP server through the system clock service.
[0144] If the system clock service in the terminal device does not receive the first response from the NTP server when the timing duration is equal to or greater than the preset duration, the system clock service can resend the first request to the NTP server; or, resend the first request to the NTP server, the satellite and the base station (i.e., restart execution of S701).
[0145] It is understandable that after the terminal device generates the system time using the second absolute time in the first response from the base station or satellite, if the terminal device receives the first response from the NTP server, the terminal device generates the system time using the first absolute time in the first response from the NTP server. Since the security level of the first absolute time from the NTP server is higher than the security level of the second absolute time from the base station or satellite, the security of the system time generated using the first absolute time is higher than the security of the system time generated using the second absolute time. Furthermore, the security of the system time of the terminal device can be improved by replacing the system time of the terminal device generated according to the second absolute time with the system time of the terminal device generated according to the first absolute time.
[0146] Secondly, after the terminal device generates the system time using the second absolute time in the first response from the base station or satellite, if the first response from the NTP server is not received, the first request is resent to the NTP server. Since the security level of the first absolute time from the NTP server is higher than the security level of the second absolute time from the base station or satellite; therefore, if the first response from the NTP server is not received, the first request can continue to be sent to the NTP server to request the absolute time. In this way, the first absolute time from the NTP server with higher security can be obtained, thereby improving the security of the system time of the terminal device.
[0147] In an embodiment of the present application, after sending a first request to an NTP server, a satellite, and a base station, if the terminal device does not receive a first response from the NTP server but receives a first response from a satellite or a base station, the terminal device may generate a system time based on a first absolute time in the first response from the satellite or the base station and save the system time. Then, the terminal device continues to wait for receiving a first response from the NTP server through the system clock service. If a first response is received from the NTP server, the system time of the terminal device is generated based on the first absolute time in the first response from the NTP server. If the first response is not received from the NTP server, the first request is no longer sent to the NTP server. Please refer to Fig.10 , after S901, S703 may also include S904, but not including S902-S903.
[0148] S904: If the terminal device receives a first response from the NTP server, the terminal device generates a system time of the terminal device according to a first absolute time in the first response from the NTP server through a system clock service.
[0149] It is understandable that after the terminal device generates the system time according to the preset security level and the second absolute time, if the terminal device receives the first response from the NTP server, the first absolute time in the first response from the NTP server is used as the system time of the terminal device, that is, the system time generated by using the first absolute time is used to replace the system time generated by using the second absolute time. If the first response from the NTP server is not received, the first request is not resent.
[0150] In the embodiment of the present application, the terminal device can run the system clock service in the TEE when it is turned on, and send a first request to the NTP server, the satellite, and the base station. That is, the terminal device executes S701 when it is turned on. Furthermore, after the terminal device executes S701 at startup through the system clock service, it can execute S702-S703.
[0151] It should be noted that, in addition to executing S701 when the terminal device is turned on, it can also execute S701 in the above S903 if the terminal device does not receive the first response from the NTP server within the preset time starting from the terminal device generating the system time according to the preset security level and the second absolute time.
[0152] In the embodiment of the present application, after the terminal device is turned on, the system clock service is periodically run in the TEE to send a first request to the NTP server, the satellite and the base station. Specifically, the terminal device can periodically execute S701-S702, S801, S901 and S904 through the system clock service.
[0153] In the embodiment of the present application, since the absolute time changes in real time, the system time of the terminal device used to record the absolute time should also change in real time. Therefore, when generating a system time, the duration from the generation of the system time to the current time can also be recorded. In this way, the real-time system time of the terminal device can be determined based on the duration and the system time, which is recorded as ST. Please refer to Fig.11 The terminal device uses the system clock service to generate the system time of the terminal device while executing S703 and can also execute S1101; then, execute S1102-S1103.
[0154] S1101. When the terminal device generates system time through the system clock service, it obtains the first real-time relative time from the TEE and saves the system time and the first real-time relative time.
[0155] Through the system clock service, the terminal can obtain the real-time relative time RT1 of the current moment in the TEE while generating the system time of the terminal device, and use RT1 as the first real-time relative time; save the system time and the first real-time relative time in the TEE. Among them, the real-time relative time RT in the TEE is used to record the length of time from the start of the terminal device to the current moment, and the real-time relative time RT in the TEE changes in real time. The real-time relative time RT in the TEE is cleared when the terminal device is shut down. The first real-time relative time is the length of time from the start of the terminal device to the generation of the system time of the terminal device.
[0156] Among them, the TEE may only record the relative time ERT when the ET is generated. The system time of the terminal device and the first real-time relative time are saved in the TEE, that is, ET is set equal to the system time, and ERT is set equal to the first real-time relative time.
[0157] S1102. When the terminal device receives a time synchronization request from any application in the terminal device, it obtains the second real-time relative time from the TEE through the system clock service, and calculates the real-time system time of the terminal device based on the system time, the first real-time relative time and the second real-time relative time.
[0158] When the terminal device receives the time synchronization request through the system clock service, it obtains the real-time relative time RT2 of the current moment in the TEE in response to the time synchronization request, and uses RT2 as the second real-time relative time. Then, the difference between the second real-time relative time and the first real-time relative time can be calculated through the system clock service. The difference represents the duration from the generation of the system time of the terminal device to the current moment. Finally, the sum of the system time and the difference is calculated through the system clock service; the sum is equal to the real-time system time of the terminal device. Among them, the second real-time relative time is the duration from the power-on of the terminal device to the receipt of the time synchronization request.
[0159] Among them, any application in the terminal device can be any TA in TEE, or any CA in REE. The real-time system time is the real-time system time ST of the terminal device, ST = ET + RT2 - ERT.
[0160] S1103. The terminal device outputs the real-time system time to the application through the system clock service.
[0161] The terminal device outputs the real-time system time to any application through the system clock service.
[0162] Furthermore, after S1102, the terminal device can use the real-time system time as the system time of the terminal device (e.g., setting ET equal to the real-time system time) and replace the first real-time relative time with the second real-time relative time (e.g., setting ERT equal to the second real-time relative time) through the system clock service. Furthermore, if a time synchronization request is received from any application in the terminal device again, a new second real-time relative time is obtained from TEE, and the real-time system time ST of the terminal device is calculated based on ET, ERT and the new second real-time relative time.
[0163] It is understandable that, since the system time of the terminal device changes in real time, the system time generated by the terminal device is the system time at a certain moment. Therefore, while generating the system time, the first real-time relative time can be recorded, that is, the duration from the terminal device turning on to generating the system time. Furthermore, if a time synchronization request of any application is received, the second real-time relative time when the time synchronization request is received is obtained, that is, the duration from the terminal device turning on to receiving the time synchronization request. According to the first real-time relative time and the second real-time relative time, the duration from generating the system time to receiving the time synchronization request can be obtained. Furthermore, using the system time and the duration from generating the system time to receiving the time synchronization request, the system time when the time synchronization request is received, that is, the real-time system time of the terminal device, can be calculated. Then, the real-time system time is output to the application. In this way, the terminal device communicates with the NTP server, satellite and base station and only obtains the system time once, and can also provide real-time system time, saving traffic.
[0164] In an embodiment of the present application, after S1101, in addition to receiving a time synchronization request from any application in the terminal device, the terminal device may also receive a shutdown command. If the terminal device receives a shutdown command, it obtains the third real-time relative time from the TEE through the system clock service, and calculates the shutdown time of the terminal device based on the system time of the terminal device, the first real-time relative time, and the third real-time relative time. Among them, the shutdown time is equal to the difference between the system time of the terminal device plus the third real-time relative time and the first real-time relative time. Among them, the third real-time relative time is the length of time from the terminal device being turned on to receiving the shutdown command.
[0165] It is understandable that, since the system time of the terminal device changes in real time, and the system time generated by the terminal device is the system time at a certain moment. Therefore, while generating the system time, the first real-time relative time can be recorded, that is, the time from the terminal device being turned on to the generation of the system time. Furthermore, if a shutdown command is received, the third real-time relative time when the shutdown command is received is obtained, that is, the time from the terminal device being turned on to the reception of the shutdown command. According to the first real-time relative time and the third real-time relative time, the time from the generation of the system time to the reception of the shutdown command can be obtained. Furthermore, using the system time and the time from the generation of the system time to the reception of the shutdown command, the system time when the shutdown command is received, that is, the shutdown time, can be calculated.
[0166] In the embodiment of the present application, when the terminal device is turned on, the saved shutdown time of the terminal device can be used as ET. Then, if a time synchronization request is received from any application in the terminal device, and there is no system time of the terminal device, the ET (i.e., the saved shutdown time of the terminal device) can be output to the application through the system clock service.
[0167] In the embodiment of the present application, the terminal device may output the most recently saved shutdown time to the application through the system clock service while outputting the real-time system time to the application, or output the most recently saved shutdown time and its corresponding identifier indicating the shutdown time, and the identifier indicating the system time corresponding to the real-time system time to the application. For example, the identifier indicating the shutdown time is 0, and the identifier indicating the system time is 1.
[0168] It is understandable that, in addition to outputting the real-time system time to the application, the terminal device can also output the most recently saved shutdown time to any application. Since the real-time system time represents the real-time system time of the terminal device, and the shutdown time is the system time when the shutdown instruction was last received, the real-time system time should be later than the shutdown time. In this way, the application can determine whether the real-time system time is later than the shutdown time to determine whether the real-time system time is accurate. In other words, outputting the shutdown time to the application helps the application determine the security of the system time.
[0169] In an embodiment of the present application, before S701, the terminal device can establish a secure channel for data transmission between the system clock service and the NTP server; wherein the terminal device can send a first request to the NTP server through the secure channel, and the terminal device receives a first response from the NTP server through the secure channel.
[0170] The terminal device runs the system clock service in TEE, first establishes a secure channel for data transmission between the system clock service and the NTP server; then, sends a first request to the Network Time Protocol NTP server, satellite and base station through the secure channel.
[0171] In the embodiment of the present application, the terminal device includes REE in addition to TEE. The terminal device can establish a secure channel for data transmission between the system clock service and the NTP server through REE, wherein the secure channel passes through REE.
[0172] Among them, the terminal device can also add a first application APP in REE, and the first APP is used to transmit data between the NTP server and the system clock service in TEE. The terminal device runs the system clock service in TEE and can send a secure channel request to the NTP server through the first application. The NTP server receives the secure channel request and establishes a secure channel for data transmission with the system clock service.
[0173] For example, Fig.12 As shown in the schematic diagram of the composition of the terminal device, the terminal device 420 may also include a sensor aggregator 613; the REE in the terminal device 420 may also run a first APP. One end of the sensor aggregator 613 is respectively connected to the modem and the satellite positioning chip, and the other end is connected to the TEE; the sensor aggregator 613 is used to transmit information between the TEE and the modem and the satellite positioning chip. The first APP is used to transmit data between the NTP server 640 and the system clock service in the TEE. The terminal device 420 runs the system clock service in the TEE, and obtaining the system time of the terminal device may include steps A1-A6.
[0174] A1. The terminal device runs the system clock service in the TEE, sends a first request to the NTP server through the first APP, and also sends a first request to the modem and the satellite positioning chip respectively through the sensor aggregator.
[0175] A2. The NTP server responds to the first request and obtains the cloud time; then uses the cloud time as the first absolute time and generates a first response including the first absolute time; and then returns the first response to the system clock service through the first APP.
[0176] A3. The modem receives and responds to the first request, receives base station data from the base station, generates a first response including the second absolute time according to the base station data, and then returns the first response to the system clock service through the sensor aggregator.
[0177] The base station data received by the modem may be one or more base station data, and the one or more base station data corresponds to one or more base stations. The modem may process each base station data to obtain a base station time, and then obtain one or more base station times; and then generate a first response according to the one or more base station times.
[0178] In the embodiment of the present application, after the modem obtains one or more base station times, it can directly use all base station times as the second absolute time and generate a first response including the second absolute time. Alternatively, after the modem obtains one or more base station times, it generates a base station time according to all base station times according to the first fault tolerance strategy and / or the second fault tolerance strategy; then uses the base station time as the second absolute time and generates a first response including the second absolute time.
[0179] Further, if the modem fails to generate a base station time according to all base station times according to the first fault tolerance strategy and / or the second fault tolerance strategy after obtaining one or more base station times, the first response is not returned to the system clock service.
[0180] It should be noted that the detailed process of the modem generating a base station time according to the first fault-tolerant strategy and / or the second fault-tolerant strategy based on all base station times can be referred to the specific process of the terminal device generating the system time of the terminal device according to the first fault-tolerant strategy and the second fault-tolerant strategy through the system clock service according to the second absolute time in the first response from the base station, which will not be repeated here in the embodiment of the present application. In addition, if the modem generates a base station time according to all base station times according to the first fault-tolerant strategy and / or the second fault-tolerant strategy, after determining through the system clock service that the first response with the highest security level of the corresponding absolute time is the first response from the base station, the second absolute time in the first response from the base station can be directly used as the system time of the terminal device.
[0181] A4. The satellite positioning chip receives and responds to the first request, receives satellite data from the satellite, generates a first response including the second absolute time according to the satellite data, and then returns the first response to the system clock service through the sensor aggregator.
[0182] The satellite data received by the satellite positioning chip may be one or more satellite data, and the one or more satellite data correspond to one or more satellites. The satellite positioning chip may process each satellite data to obtain satellite time, and then obtain one or more satellite times; then, generate a first response according to the one or more satellite times.
[0183] In the embodiment of the present application, after obtaining one or more satellite times, the satellite positioning chip can directly use all satellite times as the second absolute time and generate a first response including the second absolute time. Alternatively, after obtaining one or more satellite times, the satellite positioning chip generates a satellite time according to all satellite times according to the second fault-tolerant strategy; then uses this satellite time as the second absolute time and generates a first response including the second absolute time.
[0184] Furthermore, if the satellite positioning chip fails to generate a satellite time based on all satellite times according to the second fault-tolerant strategy after receiving the satellite time from the satellite, the first response is not returned to the system clock service.
[0185] It should be noted that the detailed process of the satellite positioning chip generating a satellite time according to all satellite times according to the second fault-tolerant strategy can be referred to the specific process of the terminal device generating the system time of the terminal device according to the second absolute time in the first response from the satellite through the system clock service according to the second fault-tolerant strategy, which will not be repeated here in the embodiment of the present application. In addition, if the satellite positioning chip generates a satellite time according to all satellite times according to the second fault-tolerant strategy, then after determining through the system clock service that the first response with the highest security level of the corresponding absolute time is the first response from the satellite, the second absolute time in the first response from the satellite can be directly used as the system time of the terminal device.
[0186] A5. The terminal device obtains a system time ET through the system clock service according to the first response from the NTP server, the first response from the base station and the first response from the satellite, and obtains the real-time relative time of the current moment from the first clock, and uses the obtained real-time relative time of the current moment as ERT.
[0187] It should be noted that the specific process for the terminal device to obtain a system time ET based on the first response from the NTP server, the first response from the base station and the first response from the satellite can be found in the detailed description of S703 above, and will not be elaborated here in the embodiment of the present application.
[0188] A6. The terminal device can generate the real-time system clock ST of the terminal device according to ET and ERT through the system clock service, and output ST to one or more TAs in TEE and one or more CAs in REE.
[0189] It should be noted that Fig.12 The terminal device 420 may not include the sensor aggregator 613, and directly interacts with the modem 611 and the satellite positioning chip 612 through the system clock service, which is not limited in the embodiment of the present application.
[0190] For example, Fig.13 As shown in the schematic diagram of the terminal device, the terminal device 420 may also include the sensor aggregator 613; the REE in the terminal device 420 may also run the first APP. Specifically, the terminal device 420 runs the system clock service in the TEE, and obtaining the system time of the terminal device may include steps B1-B14.
[0191] B1. When the terminal device is turned on, the system clock service runs in the TEE and sends a secure channel request to the NTP server through the first APP.
[0192] When the terminal device is turned on, the system clock service is automatically run through TEE, or the system clock service in TEE is started through the first APP in REE.
[0193] B2. The NTP server receives and responds to the secure channel request, and establishes a secure channel for data transmission with the system clock service.
[0194] B3. The terminal device sends a first request to the NTP server via the secure channel through the system clock service.
[0195] B4. The NTP server receives and responds to the first request, obtains the cloud time; uses the cloud time as the first absolute time, and generates a first response including the first absolute time; and then sends the first response to the system clock service in the TEE via the secure channel.
[0196] B5. The terminal device sends a first request to the sensor aggregator through the system clock service.
[0197] It should be noted that step B1 may be executed first and then step B5, or step B5 may be executed first and then step B1, or step B1 and step B5 may be executed simultaneously. The embodiment of the present application does not limit the order of executing step B1 and step B5.
[0198] B6. The sensor aggregator receives the first request and sends the first request to the modem and the satellite positioning chip respectively.
[0199] B7. The modem receives and responds to the first request, receives the base station time from the base station; generates a second absolute time according to the received base station time according to the first fault-tolerant strategy, and generates a first response including the second absolute time; and then returns the first response to the system clock service through the sensor aggregator.
[0200] B8. The satellite positioning chip receives and responds to the first request, receives the satellite time from the satellite; generates a second absolute time according to the received satellite time according to the second fault-tolerant strategy, and generates a first response including the second absolute time; and then returns the first response to the system clock service through the sensor aggregator.
[0201] B9. The terminal device receives at least one of a first response from the NTP server, a first response from the satellite, and a first response from the base station through the system clock service.
[0202] B10. The terminal device generates a system time ET according to the received first response through the system clock service, obtains the real-time relative time of the current moment from the first clock, and uses the obtained real-time relative time of the current moment as ERT.
[0203] It should be noted that the specific process of the terminal device generating a system time ET based on the received first response can be found in the detailed description of S703 above, and will not be elaborated here in the embodiment of the present application.
[0204] B11. When the system clock service in the terminal device receives a time synchronization request from any CA from the first APP, or directly receives a time synchronization request from any TA, it obtains the real-time relative time of the current moment from the first clock, and uses the obtained real-time relative time of the current moment as the second real-time relative time.
[0205] B12. The system clock service in the terminal device calculates ST according to ET, ERT and the second real-time relative time, and outputs ST to any CA through the first APP, or outputs ST to any TA.
[0206] B13. If the terminal device receives a shutdown instruction, it obtains the current real-time relative time from the first clock, and uses the obtained current real-time relative time as the third real-time relative time.
[0207] B14. The system clock service in the terminal device calculates ST according to ET, ERT and the third real-time relative time, and uses ST as the shutdown time of the terminal device.
[0208] It should be noted that steps B11-B12 may be executed first and then steps B13-B14, or steps B13-B14 may be executed first and then steps B11-B12, or steps B11-B12 and steps B13-B14 may be executed at the same time. The embodiment of the present application does not limit the order of executing steps B11-B12 and steps B13-B14.
[0209] In the present application embodiment, Fig.14As shown in the schematic diagram of the composition of the terminal device, the terminal device 420 may include REE and TEE, but does not include modem 611, satellite positioning chip 612 and sensor aggregator 613. Among them, TEE includes a system clock service, and REE includes the above-mentioned first APP. The terminal device can establish a secure channel for data transmission between the system clock service and the NTP server through the first APP in REE. In this way, the terminal device runs the system clock service in TEE, and can safely obtain the cloud time from the NTP server through the secure channel. Then, the system time of the terminal device is generated by using the cloud time through the system clock service in TEE. Since it is difficult for the outside to tamper with the information in TEE, the system time will not be tampered with, thereby ensuring the security and accuracy of the system time. For details, please refer to Fig.15 , is a flow chart of a method for obtaining system time from an NTP server provided in an embodiment of the present application. Fig.15 As shown, the method for acquiring system time from an NTP server may include S1501-S1503.
[0210] S1501. The terminal device runs a system clock service in TEE and sends a first request to an NTP server; wherein the first request is used to obtain a first absolute time from the NTP server.
[0211] It should be noted that the detailed process of the terminal device in S1501 sending the first request to the NTP server when the TEE runs the system clock service can be found in the detailed description of sending the first request to the NTP server in S701, which will not be repeated here in the embodiment of the present application.
[0212] S1502. The terminal device receives a first response from the NTP server; wherein the first response includes a first absolute time.
[0213] It should be noted that the details of the first response from the NTP server in S1502 can be found in the detailed description of the first response from the NTP server in S703, which will not be described in detail in this embodiment of the present application.
[0214] S1503: The terminal device generates the system time of the terminal device according to the first absolute time through the system clock service.
[0215] The terminal device directly uses the first absolute time in the first response from the NTP server as the system time of the terminal device through the system clock service.
[0216] In the present application embodiment, Fig.16As shown in the schematic diagram of the terminal device composition, the terminal device 420 may include REE, TEE and modem 611, but does not include a satellite positioning chip 612 and a sensor aggregator 613. Among them, TEE includes a system clock service. The terminal device runs the system clock service in TEE and can directly obtain the base station time from the base station 620 through modem 611. Then, the system time of the terminal device is generated using the base station time through the system clock service in TEE. Since it is difficult for the outside to tamper with the information in TEE, the system time will not be tampered with, thereby ensuring the security and accuracy of the system time. For details, please refer to Fig.17 , is a flow chart of a method for obtaining system time from a base station provided in an embodiment of the present application. Fig.17 As shown, the method for acquiring system time from a base station may include S1701-S1703.
[0217] S1701. The terminal device runs a system clock service in the TEE and sends a first request to the base station; wherein the first request is used to obtain a second absolute time from the base station.
[0218] It should be noted that the detailed process of the terminal device in S1701 sending the first request to the base station when the TEE runs the system clock service can be found in the detailed description of sending the first request to the base station in S701, which will not be repeated here in the embodiment of the present application.
[0219] S1702. The terminal device receives a first response from the base station; wherein the first response includes a second absolute time.
[0220] It should be noted that, for details of the first response from the base station in S1702, reference may be made to the detailed description of the first response from the base station in S703, which will not be described in detail in this embodiment of the present application.
[0221] S1703: The terminal device generates the system time of the terminal device according to the second absolute time through the system clock service.
[0222] It should be noted that the detailed process of S1703 can be found in the detailed description of generating the system time of the terminal device according to the second absolute time in the first response from the base station in the above S703, which will not be elaborated here in the embodiment of the present application.
[0223] In the present application embodiment, Fig.18As shown in the schematic diagram of the terminal device composition, the terminal device 420 may include REE, TEE and satellite positioning chip 612, but does not include modem 611 and sensor aggregator 613. Among them, TEE includes a system clock service. The terminal device runs the system clock service in TEE and can directly obtain the satellite time from the satellite 630 through the satellite positioning chip 612. Then, the system time of the terminal device is generated using the satellite time through the system clock service in TEE. Since it is difficult for the outside to tamper with the information in TEE, the system time will not be tampered with, thereby ensuring the security and accuracy of the system time. For details, please refer to Fig.19 , is a flow chart of a method for obtaining system time from a satellite provided in an embodiment of the present application. Fig.19 As shown, the method for acquiring system time from a satellite may include S1901-S1903.
[0224] S1901. The terminal device runs a system clock service in the TEE and sends a first request to the satellite; wherein the first request is used to obtain a second absolute time from the satellite.
[0225] It should be noted that the detailed process of the terminal device in S1901 sending the first request to the satellite when the TEE runs the system clock service can be found in the detailed description of sending the first request to the satellite in S701, which will not be repeated here in the embodiment of the present application.
[0226] S1902. The terminal device receives a first response from the satellite; wherein the first response includes a second absolute time.
[0227] It should be noted that for details of the first response from the satellite in S1902, reference may be made to the detailed description of the first response from the satellite in S703, which will not be described in detail in this embodiment of the present application.
[0228] S1903. The terminal device generates the system time of the terminal device according to the second absolute time through the system clock service.
[0229] It should be noted that the detailed process of S1903 can be found in the detailed description of generating the system time of the terminal device according to the second absolute time in the first response from the satellite in the above S703, which will not be elaborated here in the embodiment of the present application.
[0230] It is understandable that the above method can be implemented by a system time acquisition device. In order to realize the above functions, the system time acquisition device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present application.
[0231] Another embodiment of the present application provides a terminal device (such as Figure 5 , Figure 6 , Figure 12-14 , Fig.16 ,or Fig.18 The mobile terminal 420 shown in the figure). The terminal device may include: one or more processors, a memory, a wireless communication module and a mobile communication module. The memory, the wireless communication module and the mobile communication module are coupled to the processor. The memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the mobile terminal can execute the various functions or steps executed by the mobile terminal 420 in the above method embodiment.
[0232] Another embodiment of the present application provides a chip system, such as Fig. 20 As shown, the chip system 2000 includes at least one processor 2001 and at least one interface circuit 2002. The processor 2001 and the interface circuit 2002 can be interconnected through a line. For example, the interface circuit 2002 can be used to receive signals from other devices (for example, a memory of a mobile terminal, a satellite positioning chip, a modem). For another example, the interface circuit 2002 can be used to send signals to other devices (for example, the processor 2001).
[0233] For example, the chip system can be applied to the mobile terminal (such as Figure 5 , Figure 6 , Figure 12-14 , Fig.16 ,or Fig.18 The interface circuit 2002 can read the instructions stored in the memory of the mobile terminal and send the instructions to the processor 2001. When the instructions are executed by the processor 2001, the mobile terminal can execute the various steps in the above embodiments.
[0234] Of course, the above chip system may also include other discrete devices, which is not specifically limited in the embodiments of the present application.
[0235] Another embodiment of the present application provides a computer-readable storage medium, on which computer instructions are stored. When the computer instructions are transmitted to a terminal device (such as Figure 5 , Figure 6 , Figure 12-14 , Fig.16 ,or Fig.18 When the computer readable storage medium is executed on the mobile terminal 420 shown in the figure, the terminal device executes each function or step executed by the mobile terminal 420 in the above method embodiment. For example, the computer readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0236] Another embodiment of the present application provides a computer program product, including one or more instructions, which can be executed on a terminal device (such as Figure 5 , Figure 6 , Figure 12-14 , Fig.16 ,or Fig.18 The mobile terminal 420 shown in the figure) is executed so that the terminal device executes each function or step executed by the mobile terminal 420 in the above method embodiment.
[0237] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0238] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0239] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0240] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0241] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, magnetic disks or optical disks.
[0242] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A method for obtaining system time, characterized in that: Applied in a terminal device, the terminal device includes a trusted execution environment TEE, and the method includes: The terminal device runs a system clock service in the TEE and sends a first request to a network time protocol NTP server, a satellite and a base station; wherein the first request is used to obtain absolute time; The terminal device receives at least one of the following: a first response from the satellite, a first response from the base station, and a first response from the NTP server; The terminal device generates the system time of the terminal device through the system clock service according to a preset security level and the absolute time in the first response received; wherein the preset security level includes the security level of the absolute time of the satellite, the base station and the NTP server respectively.
2. The method according to claim 1, characterized in that The received first response is a first response from a first object, the first object belongs to the satellite, the base station and the NTP server; the method further includes: If the first object does not include the absolute time with the highest security level among the satellite, the base station and the NTP server, the terminal device resends the first request to the second object through the system clock service; The security level of the absolute time of the second object is higher than the security level of the absolute time of the first object, and the second object belongs to the satellite, the base station and the NTP server.
3. The method according to claim 1 or 2, characterized in that: The security level of the absolute time of the NTP server is higher than the security level of the absolute time of the base station, and the security level of the absolute time of the base station is higher than the security level of the absolute time of the satellite; The terminal device generates the system time of the terminal device through the system clock service according to the preset security level and the absolute time in the received first response, including: If the received first response includes a first response from the satellite and / or the base station, and a first response from the NTP server, the terminal device generates the system time of the terminal device according to the first absolute time in the first response from the NTP server through the system clock service.
4. The method according to claim 3, characterized in that The terminal device generates the system time of the terminal device through the system clock service according to the preset security level and the absolute time in the received first response, including: If the received first response is a first response from the satellite and / or the base station, the terminal device generates the system time of the terminal device through the system clock service according to the preset security level, the second absolute time in the first response from the satellite and / or the second absolute time in the first response from the base station.
5. The method according to claim 4, characterized in that The method further comprises: If the terminal device receives a first response from the NTP server within a preset period of time starting from the time when the terminal device generates the system time according to the preset security level and the second absolute time, the terminal device generates the system time of the terminal device according to the first absolute time in the first response from the NTP server through the system clock service.
6. The method according to claim 4 or 5, characterized in that: The method further comprises: If the terminal device does not receive a first response from the NTP server within a preset period of time starting from the time when the terminal device generates the system time according to the preset security level and the second absolute time, the terminal device resends the first request to the NTP server through the system clock service.
7. The method according to claim 1 or 2, characterized in that: The terminal device runs a system clock service in the TEE and sends a first request to a timing server NTP server, a satellite and a base station, including: When the terminal device is turned on, the system clock service is run in the TEE, and the first request is sent to the NTP server, the satellite and the base station.
8. The method according to claim 1 or 2, characterized in that: The terminal device runs a system clock service in the TEE and sends a first request to a timing server NTP server, a satellite and a base station, including: After the terminal device is turned on, the system clock service is periodically run in the TEE to send the first request to the NTP server, the satellite and the base station.
9. The method according to claim 1 or 2, characterized in that: The method further comprises: When the terminal device generates the system time through the system clock service, the terminal device obtains the first real-time relative time from the TEE, and saves the system time and the first real-time relative time; the first real-time relative time is the duration from the power-on of the terminal device to the generation of the system time; When the terminal device receives a time synchronization request from any application in the terminal device, the terminal device obtains a second real-time relative time from the TEE through the system clock service, and calculates the real-time system time of the terminal device according to the system time, the first real-time relative time and the second real-time relative time; the second real-time relative time is the duration from when the terminal device is turned on to when the time synchronization request is received; The terminal device outputs the real-time system time to the application through the system clock service.
10. The method according to claim 1 or 2, characterized in that: Before the terminal device runs the system clock service in the TEE and sends a first request to the network time protocol NTP server, the satellite and the base station, the method further includes: The terminal device establishes a secure channel for data transmission between the system clock service and the NTP server; The terminal device sends the first request to the NTP server through the secure channel, and the terminal device receives the first response from the NTP server through the secure channel.
11. The method according to claim 10, characterized in that The terminal device includes a rich execution environment REE; The terminal device establishes a secure channel for data transmission between the system clock service and the NTP server, including: The terminal device establishes the secure channel for data transmission between the system clock service and the NTP server through the REE; wherein the secure channel passes through the REE.
12. The method according to claim 1 or 2, characterized in that: The terminal device includes a satellite positioning chip and a modem; The terminal device sends the first request to the satellite via the satellite positioning chip through the system clock service, and the terminal device receives the first response from the satellite from the satellite positioning chip through the system clock service; The terminal device sends the first request to the base station via the modem through the system clock service, and the terminal device receives the first response from the base station from the modem through the system clock service.
13. A method for obtaining system time, characterized in that: Applied in a terminal device, the terminal device includes a trusted execution environment TEE, and the method includes: The terminal device runs a system clock service in the TEE and sends a first request to a network time protocol NTP server; wherein the first request is used to obtain a first absolute time from the NTP server; The terminal device receives a first response from the NTP server; wherein the first response includes the first absolute time; The terminal device generates the system time of the terminal device according to the first absolute time through the system clock service.
14. The method according to claim 13, characterized in that The method further comprises: When the terminal device generates the system time through the system clock service, the terminal device obtains the first real-time relative time from the TEE, and saves the system time and the first real-time relative time; the first real-time relative time is the duration from the power-on of the terminal device to the generation of the system time; When the terminal device receives a time synchronization request from any application in the terminal device, the terminal device obtains a second real-time relative time from the TEE through the system clock service, and calculates the real-time system time of the terminal device according to the system time, the first real-time relative time and the second real-time relative time; the second real-time relative time is the duration from when the terminal device is turned on to when the time synchronization request is received; The terminal device outputs the real-time system time to the application through the system clock service.
15. The method according to claim 13 or 14, characterized in that The terminal device runs a system clock service in the TEE and sends a first request to the timing server NTP server, including: After the terminal device is turned on, the system clock service is periodically run in the TEE to send the first request to the NTP server; or When the terminal device is turned on, the system clock service runs in the TEE and sends the first request to the NTP server.
16. The method according to claim 13 or 14, characterized in that Before the terminal device runs the system clock service in the TEE and sends a first request to the network time protocol NTP server, the method further includes: The terminal device establishes a secure channel for data transmission between the system clock service and the NTP server; The terminal device sends the first request to the NTP server through the secure channel, and the terminal device receives the first response from the NTP server through the secure channel.
17. The method according to claim 16, characterized in that The terminal device includes a rich execution environment REE; The terminal device establishes a secure channel for data transmission between the system clock service and the NTP server, including: The terminal device establishes the secure channel for data transmission between the system clock service and the NTP server through the REE; wherein the secure channel passes through the REE.
18. A terminal device, characterized in that: The terminal device comprises: a processor and a memory; wherein the memory is used to store computer program code, and the computer program code comprises computer instructions; the processor is used to execute the computer instructions, so that the terminal device executes the method as described in any one of claims 1-12.
19. A terminal device, characterized in that: The terminal device includes: a processor and a memory; The memory is used to store computer program code, and the computer program code includes computer instructions; the processor is used to execute the computer instructions so that the terminal device executes the method as described in any one of claims 13-17.
20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a terminal device, the terminal device executes the method according to any one of claims 1 to 12.
21. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a terminal device, the terminal device executes the method according to any one of claims 13 to 17.
