Disclosure of Invention
The invention provides a TrustZone-based file encryption and decryption method, a TrustZone-based file encryption and decryption device and a terminal device, which can improve the security of file encryption.
Additional features and advantages of the invention will be set forth in the detailed description which follows, or may be learned by practice of the invention.
According to an aspect of the present invention, there is provided a TrustZone-based file encryption method, including: receiving a metadata encryption request for a file, the metadata encryption request comprising: metadata and class key identification of the file, wherein the metadata comprises: a file key for encrypting the file; searching a class key corresponding to the stored class key identification; sending a data encryption request to a trusted application in the trusted execution environment through a client interface between the normal execution environment and the trusted execution environment, the data encryption request including: class keys and metadata; the trusted application program decrypts the class key according to the master key pre-stored in the trusted execution environment; the trusted application program encrypts the metadata according to the decrypted class key; and the trusted application program returns the encrypted metadata to the common execution environment for storage through the client interface.
According to an embodiment of the present invention, the class key identifier corresponds to an application scenario; the application scene comprises the following steps: the terminal equipment can be accessed after being successfully started, the terminal equipment can be accessed after being successfully started and legally logged in and the user interface is unlocked, and the terminal equipment can be only written in when being successfully started and legally logged in and the user interface is locked.
According to an embodiment of the present invention, the method further includes: encrypting the file in the trusted execution environment according to the file key; receiving encrypted metadata; and merging the encrypted metadata and the encrypted file into one file for storage.
According to an embodiment of the present invention, encrypting a file in a trusted execution environment according to a file key includes: dividing a file into a plurality of data blocks; and independently encrypting the plurality of data blocks.
According to an embodiment of the present invention, the size of the data block is equal to the size of the operating system kernel memory page multiplied by the power of 2 to the nth power, where N is a positive integer greater than or equal to 2.
According to another aspect of the present invention, there is provided a TrustZone-based file decryption method suitable for use in any one of the above encryption methods, comprising: receiving a metadata decryption request for a file, the metadata decryption request comprising: metadata and a class key identifier of the file to be decrypted, wherein the metadata comprises: a file key for encrypting the file; searching a class key corresponding to the stored class key identification; sending a data decryption request to a trusted application program in the trusted execution environment through a client interface between the normal execution environment and the trusted execution environment, wherein the data decryption request comprises: class keys and metadata to be decrypted; the trusted application program decrypts the class key according to the master key pre-stored in the trusted execution environment; the trusted application program decrypts the metadata according to the decrypted class key; and the trusted application program returns the decrypted metadata to the common execution environment through the client interface.
According to an embodiment of the present invention, the method further includes: receiving an operation request for a file sent by a client application program in a common execution environment; and sending a metadata decryption request of the file according to the operation request.
According to an embodiment of the present invention, the method further includes: decrypting the file in the trusted execution environment according to the file key in the decrypted metadata; and
the decrypted file is returned to the client application.
According to an embodiment of the present invention, decrypting the file in the trusted execution environment according to the file key in the decrypted metadata includes: a plurality of encrypted data blocks divided from a file are independently decrypted.
According to still another aspect of the present invention, there is provided a TrustZone-based file encryption apparatus, including: an encryption request receiving module, configured to receive a metadata encryption request for a file, where the metadata encryption request includes: metadata and class key identification of the file, wherein the metadata comprises: a file key for encrypting the file; the first type key acquisition module is used for searching a class key corresponding to the stored class key identifier; an encryption request module, configured to send a data encryption request to a trusted application in a trusted execution environment through a client interface between a normal execution environment and the trusted execution environment, where the data encryption request includes: class keys and metadata; the first type key decryption module is used for decrypting the type key according to a master key which is stored in a trusted execution environment in advance through a trusted application program; the encryption execution module is used for encrypting the metadata according to the decrypted class key through the trusted application program; and the encrypted data returning module is used for returning the encrypted metadata to the common execution environment for storage through the client interface by the trusted application program.
According to an embodiment of the present invention, the class key identifier corresponds to an application scenario; the application scene comprises the following steps: the terminal equipment can be accessed after being successfully started, the terminal equipment can be accessed after being successfully started and legally logged in and the user interface is unlocked, and the terminal equipment can be only written in when being successfully started and legally logged in and the user interface is locked.
According to an embodiment of the present invention, the apparatus further includes: the file encryption module is used for encrypting the file in the trusted execution environment according to the file key; the metadata receiving module is used for receiving the encrypted metadata; and the merging storage module is used for merging the encrypted metadata and the encrypted file into one file for storage.
According to an embodiment of the present invention, a file encryption module includes: the data block dividing submodule is used for dividing the file into a plurality of data blocks; and the database encryption submodule is used for independently encrypting the data blocks.
According to an embodiment of the present invention, the size of the data block is equal to the size of the operating system kernel memory page multiplied by the power of 2 to the nth power, where N is a positive integer greater than or equal to 2.
According to still another aspect of the present invention, there is provided a TrustZone-based file decrypting apparatus adapted to the encrypting apparatus according to any one of the above, comprising: a decryption request receiving module, configured to receive a metadata decryption request for a file, where the metadata decryption request includes: metadata and a class key identifier of the file to be decrypted, wherein the metadata comprises: a file key for encrypting the file; the second type key obtaining module is used for searching a class key corresponding to the stored class key identification; a decryption request module, configured to send a data decryption request to a trusted application in a trusted execution environment through a client interface between a common execution environment and the trusted execution environment, where the data decryption request includes: class keys and metadata to be decrypted; the second type key decryption module is used for decrypting the type key according to the main key which is stored in the trusted execution environment in advance through the trusted application program; the decryption execution module is used for decrypting the metadata according to the decrypted class key through the trusted application program; and the decrypted data returning module is used for returning the decrypted metadata to the common execution environment through the client interface by the trusted application program.
According to an embodiment of the present invention, the apparatus further includes: an operation request receiving module, configured to receive an operation request for a file sent by a client application in a common execution environment; and the decryption request sending module is used for sending the metadata decryption request of the file according to the operation request.
According to an embodiment of the present invention, the apparatus further includes: the file decryption module is used for decrypting the file in the trusted execution environment according to the file key in the decrypted metadata; and a decrypted file returning module for returning the decrypted file to the client application program.
According to an embodiment of the present invention, the file decryption module includes: and the data block decryption submodule is used for independently decrypting a plurality of encrypted data blocks divided according to the file.
According to still another aspect of the present invention, there is provided a terminal device including: a processor; and a memory for storing executable instructions for the processor; wherein the processor is configured to perform the method of any one of the above via execution of the executable instructions.
According to still another aspect of the present invention, there is provided a terminal device including: a processor; and a memory for storing executable instructions for the processor; wherein the processor is configured to perform the method of any one of the above via execution of the executable instructions.
According to the TrustZone-based file encryption method, the metadata containing the file key is encrypted in the trusted execution environment, and the ciphertext of the file key is stored in the common execution environment, so that the safe storage and use of the file key for encrypting the file are ensured.
In addition, according to some embodiments, the TrustZone-based file encryption method according to the embodiments of the present invention further enhances the security of file encryption by encrypting the file key in the trusted execution environment. In addition, the security of the file is further enhanced by carrying out encryption operation in a trusted execution environment by taking a single file as a logic encryption unit.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The drawings are merely schematic illustrations of the invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to provide a thorough understanding of embodiments of the invention. One skilled in the relevant art will recognize, however, that the invention may be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known structures, methods, devices, implementations, materials, or operations are not shown or described in detail to avoid obscuring aspects of the invention.
TrustZone technology is a Trusted Execution Environment (TEE) standard on the ARM platform that provides the ability to execute portions of code securely in a Trusted execution environment through access isolation of hardware and cooperation of secure kernel software. The trusted Execution Environment constructed based on the TrustZone hardware isolation technology divides the application programs related to sensitive data into a Client application program (Client APP) and a trusted application program (trusted APP, TA), the Client application program is executed in a normal Execution Environment (REE) for processing most of non-sensitive services, i.e. a normal operating System (Rich OS) of the mobile terminal device, and the trusted application program is executed in the trusted Execution Environment for processing sensitive services. The normal execution environment and the trusted execution environment are isolated from each other, and a Client application program running in the normal execution environment accesses (access) the trusted application program running in the trusted execution environment through a Client interface (TrustZone Client API), or exchanges data with the trusted application program through the Client interface.
Fig. 1 is an architectural diagram illustrating a generic execution environment and trusted execution in a terminal device according to an example. Fig. 2 is a flowchart illustrating a TrustZone-based file encryption method according to an exemplary embodiment. With reference to fig. 1 and 2, the method 10 shown in fig. 2 includes:
in step S102, a metadata encryption request for a file is received.
The metadata encryption request includes: metadata of the file and a class key Identification (ID). The metadata includes: a file key for encrypting the file.
For example, a file key encryption request sent by the file encryption implementation service is received by the encryption/decryption storage service in fig. 1. The file encryption implementation service sends the file key encryption request to the encryption and decryption storage service, and the request encryption and decryption storage service encrypts the metadata containing the file key used for encrypting the data file in fig. 1.
The encryption and decryption storage service and the file encryption implementation service can be implemented as a code set consisting of at least one function, and each function comprises: function name, function call information, and some or all of the function implementations. When there are multiple functions, a function implementation may also include calling other defined functions, etc.
The file key encryption request is sent, for example, by Inter-Process Communication (IPC), such as Dbus, a folder Inter-Process Communication mechanism, or the like.
The file key encryption request carries the metadata and the class key identifier in a parameter form.
In step S104, the stored class key is searched for to identify the corresponding class key.
For example, the stored class key is looked up by the encryption and decryption storage service to identify the corresponding class key. In the encryption and decryption storage service, class keys corresponding to various key identifications are stored, wherein the various keys are ciphertexts encrypted by using a master key in a trusted execution environment.
In some embodiments, the class key identification corresponds to an application scenario of an application program that invokes the database file. Application scenarios include, for example:
1) after the terminal equipment is successfully started, the following access can be carried out: this scenario is typically used for the requirements of system-resident services for encryption;
2) after the terminal equipment is successfully started and legally logged in, the terminal equipment can access: this scenario is typically used for the encryption requirements of system services and system applications;
3) the terminal equipment is successfully started, legally logs in and can access after the user interface is unlocked: this scenario is typically used for the encryption requirements of common client applications; alternatively, the first and second electrodes may be,
4) the terminal equipment can only write in when successfully started and legally logged in and the user interface is locked: this scenario is generally used for the encryption requirements of resident applications, such as short messages, emails, Instant Messaging (IM), and the like, and data needs to be written to the system securely with the user interface locked.
Because the security policies of the application program under different application scenarios are different, the application scenario selects the application scenario to determine the corresponding class key at each time, and the differentiated application scenario can improve the security of the application data. For example, if the policy of an encrypted item is set to that the terminal device successfully starts and legally logs in and the user interface can access after being unlocked, access requests at other times are rejected, and the corresponding class key is also cleared from the memory, so that the encryption security is further improved.
The key is a main attack point of the black box encryption algorithm, so that the security of the key in storage and use needs to be guaranteed. The storage security mainly refers to that an attacker cannot perform read-write access on the key, and the used security mainly refers to the possibility that the key is subjected to dynamic attack in the memory. In the method, in order to enhance the security of the key, the class key stored in the common execution environment is stored in a ciphertext form.
In some embodiments, the encryption and decryption storage service also needs to confirm to the trusted application through the client interface whether the master key is available during initialization.
In some embodiments, the method 10 may further include the following step before step S104:
in step 1, the encryption and decryption storage service sends a class key corresponding to each application scenario to the trusted application program through the client interface.
In step 2, the trusted application encrypts the class key of each application scenario according to the master key in the TrustZone context.
In step 3, the trusted application program returns the class key corresponding to each encrypted application scenario to the encryption and decryption storage service in the common execution environment for storage through the client interface.
In step S106, a data encryption request is sent to the trusted application in the trusted execution environment through the client interface between the normal execution environment and the trusted execution environment.
The data encryption request includes: class keys and metadata.
For example, a data encryption request is sent by the cryptographic storage service to a trusted application in the trusted execution environment, the data encryption request including: the class key and metadata found in step S102.
As shown in fig. 1, in a specific implementation, the encryption/decryption storage service may implement, through a TrustZone client interface, a call between the encryption storage service and a trusted application that is specifically served for key encryption/decryption, that is, a communication service between the encryption storage service and the trusted application, by using communication mechanisms in a common execution environment and a trusted execution environment in a kernel space. It should be noted that the communication mechanisms in the normal execution environment and the trusted execution environment in the kernel space are known to those skilled in the art and will not be described herein.
In some embodiments, the client interface employs a Mandatory Access Control (MAC) rights management mechanism, such as a SELinux access control mechanism.
SELinux is a suite of Label-based security systems. In the SELinux strategy, the subject controls the object by setting the tag. The subject may be each process running in the terminal device, and the object is all resources in the system, including: file system, directory, file start indicator, port, message interface, network interface, and the like. Each process has its own tag, and each object has its own tag. The process tag is controlled to access the object tag through the written SELinux strategy, such as file access, read-write, SOCKET operation and the like. For example, through policy configuration, the process labeled a is allowed to call the client interface labeled B, thereby ensuring that the interface of the encrypted storage service is not abused arbitrarily.
In step S108, the trusted application decrypts the class key according to the master key pre-stored in the trusted execution environment.
The master key is owned independently by each terminal device and is loaded into the image file of the TrustZone, i.e. into the context of the TrustZone's trusted execution environment, during the initialization of the executable environment. Since the master key is pre-buried in the trusted execution environment and cannot appear in the ordinary execution environment, the class key cannot be decrypted in the ordinary execution environment because the master key cannot be acquired, so that the security of the application data encrypted by the class key is enhanced.
In step S110, the trusted application encrypts the metadata according to the decrypted class key.
The trusted application may use a symmetric Encryption algorithm such as AES (Advanced Encryption Standard) or DES (Data Encryption Standard), for example, to encrypt the metadata according to the decrypted class key, which is not limited in the present invention. Available encryption modes include: CBC (Cipher blocking chaining), OFB (Output Feedback), CFB (Cipher Feedback).
As shown in fig. 1, the trusted application may perform the above-described data encryption operation by calling a hardware encryption engine that is commonly used in the trusted execution environment.
In step S112, the trusted application returns the encrypted metadata to the normal execution environment through the client interface for storage.
And after the trusted application program completes encryption, returning the encrypted metadata to the common execution environment through the client interface.
According to the TrustZone-based file encryption method, the metadata containing the file key is encrypted in the trusted execution environment, and the ciphertext of the file key is stored in the common execution environment, so that the safe storage and use of the file key for encrypting the file are ensured.
It should be clearly understood that the present disclosure describes how to make and use particular examples, but the principles of the present disclosure are not limited to any details of these examples. Rather, these principles can be applied to many other embodiments based on the teachings of the present disclosure.
Fig. 3 is a flowchart illustrating another TrustZone-based file encryption method according to an exemplary embodiment. The method 20 shown in fig. 3 includes:
in step S202, the file is encrypted in the trusted execution environment according to the file key.
For example, as shown in FIG. 1, a file encryption implementation service may implement encryption of a file by a trusted application in a trusted execution environment.
The access interface of the file encryption implementation service to the data file is designed to be as close as possible to a general high-level file access interface (different from the underlying file interface of a Linux or Windows system), and basically the details of encryption are transparent to the user except for the specified file password or the parameters of the encryption class.
The file encryption implementation service sends the file to be encrypted to the trusted application program, and the trusted application program encrypts the file. In specific implementation, the file encryption implementation service may implement the call between the file encryption implementation service and the trusted application program, that is, the communication service between the file encryption implementation service and the trusted application program, through the TrustZone client interface and by using a communication mechanism in the common execution environment and the trusted execution environment in the kernel space. It should be noted that the communication mechanisms in the normal execution environment and the trusted execution environment in the kernel space are known to those skilled in the art and will not be described herein.
The trusted application program encrypts the file by taking a single file as a logic encryption unit to perform overall encryption, instead of encrypting a general universal data block and a data stream in any type, the encryption is not common file encryption based on a file system or a block device.
The trusted application may use a symmetric Encryption algorithm such as AES (Advanced Encryption Standard) or DES (Data Encryption Standard), for example, to encrypt the file according to the file key, which is not limited in the present invention.
As shown in fig. 1, the trusted application may perform the above-described data encryption operation by calling a hardware encryption engine that is commonly used in the trusted execution environment.
In some embodiments, to balance system performance and security, the trusted application may divide the file into multiple data blocks and encrypt the multiple data blocks independently. There is no correlation between the data blocks, so the trusted application can implement parallel encryption operation on a plurality of data blocks. The size of the data block can be adjusted as required, for example, the size of the kernel memory page of the operating system of the mobile terminal device can be multiplied by the power of N of 2, where N is a positive integer greater than or equal to 2. For example, for a 32-bit operating system, the memory page size is 4KB, then the data block size may be 16KB, 64KB, 256KB, etc.; for a 64-bit operating system, the memory page size is 64KB, and the data block size can be 128KB, 256KB, 1024KB, etc. The data block size depends on the choice of platform resources, configuration and encryption algorithm. Generally speaking, the larger the block, the faster the serial access speed, such as a copy file operation; the smaller the partitions, the better the random access performance, e.g., random read and write operations.
Fig. 4 is an architecture diagram illustrating a general execution environment and trusted execution in another terminal device according to an example. In some embodiments, as shown in FIG. 4, the file encryption implementation service may also encrypt the file through a second trusted application in the trusted execution environment. The file encryption implementation service sends the file to be encrypted and the plaintext of the file key to the second trusted application program, and the second trusted application program encrypts the file. In specific implementation, the file encryption implementation service may implement the call between the file encryption implementation service and the second trusted application program, that is, the communication service between the file encryption implementation service and the second trusted application program, through the TrustZone client interface and by using a communication mechanism in the common execution environment and the trusted execution environment in the kernel space. Whereas the first trusted application in figure 4 is used to implement the encryption operation on the metadata in method 10. It should be noted that the communication mechanisms in the normal execution environment and the trusted execution environment in the kernel space are known to those skilled in the art and will not be described herein. Furthermore, to strike a balance between system performance and security, the second trusted application may divide the file into a plurality of data blocks and encrypt the plurality of data blocks independently. The specific data block division description is the same as above, and is not described herein again.
Fig. 9 is an architecture diagram illustrating a generic execution environment and trusted execution in yet another terminal device according to an example. In some embodiments, as shown in FIG. 9, the encryption implementation service encrypts the file through a generic hardware encryption engine in the trusted execution environment. The file encryption implementation service sends the file to be encrypted and the plaintext of the file key to a hardware encryption engine in the trusted execution environment, and the hardware encryption engine encrypts the file. In specific implementation, the file encryption implementation service may implement the call between the file encryption implementation service and the hardware encryption engine through the TrustZone client interface and by using a communication mechanism in the common execution environment and the trusted execution environment in the kernel space, that is, the communication service between the file encryption implementation service and the hardware encryption engine. It should be noted that the communication mechanisms in the normal execution environment and the trusted execution environment in the kernel space are known to those skilled in the art and will not be described herein. In addition, to strike a balance between system performance and security, the file encryption implementation service may divide the file into a plurality of data blocks and request the hardware encryption engine to independently encrypt the plurality of data blocks. The specific data block division description is the same as above, and is not described herein again.
In step S204, the encrypted metadata is received.
For example, the metadata encrypted by method 10 is received by the file encryption implementation service in fig. 1.
In step S206, the encrypted metadata and the encrypted file are merged into one file for storage.
The encrypted metadata is integrated with the encrypted file, so that the encrypted file can be freely copied and moved.
According to the TrustZone-based file encryption method, the file key is encrypted in the trusted execution environment, so that the security of file encryption is further enhanced. In addition, the security of the file is further enhanced by carrying out encryption operation in a trusted execution environment by taking a single file as a logic encryption unit.
Fig. 5 is a flowchart illustrating a TrustZone-based file decryption method according to an exemplary embodiment. The decryption method is applicable to the file encryption methods 10 and 20 described above. Referring to fig. 1, the method 30 shown in fig. 5 includes:
in step S302, a metadata decryption request for a file is received.
For example, a metadata decryption request sent by the file encryption implementation service is received by the encryption/decryption storage service shown in fig. 1.
The metadata decryption request is, for example, a password creation call sent through interprocess communication, such as Dbus, a binary interprocess communication mechanism, or the like.
The metadata decryption request carries metadata to be decrypted and a class key identifier of the file in a parameter form, for example, and the metadata includes: a file key for encrypting the file.
In step S304, the stored class key is searched for a class key corresponding to the class key identifier.
For example, the stored class key is looked up by the encryption and decryption storage service to identify the corresponding class key. In the encryption and decryption storage service, class keys corresponding to various key identifications are stored, wherein the various keys are ciphertexts encrypted by using a master key in a trusted execution environment.
In some embodiments, the class key identification corresponds to an application scenario of an application program that invokes the database file. The types of the application scenarios are the same as above, and are not described herein again.
The key is a main attack point of the black box encryption algorithm, so that the security of the key in storage and use needs to be guaranteed. The storage security mainly refers to that an attacker cannot perform read-write access on the key, and the used security mainly refers to the possibility that the key is subjected to dynamic attack in the memory. In the method, in order to enhance the security of the key, the class key stored in the common execution environment is stored in a ciphertext form.
In step S306, a data decryption request is sent to the trusted application in the trusted execution environment through the client interface between the normal execution environment and the trusted execution environment.
For example, a data encryption request is sent by the cryptographic storage service to a trusted application in the trusted execution environment, the data encryption request including: the class key found in step S304 and the metadata to be decrypted.
As shown in fig. 1, in a specific implementation, the encryption/decryption storage service may implement a call between the encryption storage service and a trusted application exclusively serving for encryption/decryption, that is, a communication service between the encryption storage service and a trusted application exclusively serving for encryption/decryption, through a TrustZone client interface and by using communication mechanisms in a common execution environment and a trusted execution environment in a kernel space. It should be noted that the communication mechanisms in the normal execution environment and the trusted execution environment in the kernel space are known to those skilled in the art and will not be described herein.
In step S308, the trusted application decrypts the class key according to the master key pre-stored in the trusted execution environment.
The master key is owned independently by each terminal device and is loaded into the image file of the TrustZone, i.e. into the context of the TrustZone's trusted execution environment, during the initialization of the executable environment. Since the master key is pre-buried in the trusted execution environment and cannot appear in the ordinary execution environment, the class key cannot be decrypted in the ordinary execution environment because the master key cannot be acquired, so that the security of the application data encrypted by the class key is enhanced.
In step S310, the trusted application decrypts the metadata to be decrypted according to the decrypted class key.
And carrying out decryption operation on the data to be decrypted corresponding to the encryption algorithm used in the encryption process.
In step S312, the trusted application returns the decrypted metadata to the encryption/decryption storage service through the client interface.
And after the trusted application program finishes decryption, the decrypted metadata is returned to the common execution environment through the client interface.
Fig. 6 is a flowchart illustrating another TrustZone-based file decryption method according to an exemplary embodiment. As shown in fig. 6, the method 40 includes:
in step S402, an operation request for a file sent by a client application in the normal execution environment is received.
For example, as shown in FIG. 1, when a client application needs to open the file, the operation request is sent to a file encryption implementation service.
It should be noted that, in the implementation, the file encryption implementation service may be implemented inside each application, i.e., each call to the service. Or may be an independent service, and each application realizes the call to the service through mechanisms such as interprocess communication.
In step S404, a metadata decryption request for the file is transmitted according to the operation request.
Thereby performing the decryption operation on the metadata in method 30.
In some embodiments, the method 40 further comprises:
in step S406, the file is decrypted in the trusted execution environment according to the file key in the decrypted metadata.
For example, as shown in FIG. 1, a file encryption implementation service may implement decryption of a file by a trusted application in a trusted execution environment.
The file encryption implementation service sends the file to be decrypted to the trusted application program, and the trusted application program decrypts the file. In specific implementation, the file encryption implementation service may implement the call between the file encryption implementation service and the trusted application program, that is, the communication service between the file encryption implementation service and the trusted application program, through the TrustZone client interface and by using a communication mechanism in the common execution environment and the trusted execution environment in the kernel space.
As shown in fig. 1, the trusted application may perform the above-described data decryption operation by calling a hardware encryption engine that is commonly used in the trusted execution environment.
In some embodiments, when the file to be decrypted is composed of a plurality of encrypted data blocks, the first trusted application independently decrypts the plurality of encrypted data blocks in accordance with the file key.
In some embodiments, as shown in FIG. 4, the file encryption implementation service may also decrypt the file through a second trusted application in the trusted execution environment. The file encryption implementation service sends the file to be decrypted and the plaintext of the file key to the second trusted application program, and the second trusted application program encrypts the file. In specific implementation, the file encryption implementation service may implement the call between the file encryption implementation service and the second trusted application program, that is, the communication service between the file encryption implementation service and the second trusted application program, through the TrustZone client interface and by using a communication mechanism in the common execution environment and the trusted execution environment in the kernel space.
In some embodiments, as shown in FIG. 9, the encryption implementation service decrypts files through a generic hardware encryption engine in the trusted execution environment. The file encryption implementation service sends the file to be decrypted and the plaintext of the file key to a hardware encryption engine in the trusted execution environment, and the hardware encryption engine encrypts the file. In specific implementation, the file encryption implementation service may implement the call between the file encryption implementation service and the hardware encryption engine through the TrustZone client interface and by using a communication mechanism in the common execution environment and the trusted execution environment in the kernel space, that is, the communication service between the file encryption implementation service and the hardware encryption engine.
In step S408, the decrypted file is returned to the client application.
Those skilled in the art will appreciate that all or part of the steps implementing the above embodiments are implemented as computer programs executed by a CPU. The computer program, when executed by the CPU, performs the functions defined by the method provided by the present invention. The program may be stored in a computer readable storage medium, which may be a read-only memory, a magnetic or optical disk, or the like.
Furthermore, it should be noted that the above-mentioned figures are only schematic illustrations of the processes involved in the method according to exemplary embodiments of the invention, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
The following are embodiments of the apparatus of the present invention that may be used to perform embodiments of the method of the present invention. For details which are not disclosed in the embodiments of the apparatus of the present invention, reference is made to the embodiments of the method of the present invention.
Fig. 7 is a block diagram illustrating a TrustZone-based file encryption apparatus according to an exemplary embodiment. As shown in fig. 7, the apparatus 50 includes: an encryption request receiving module 502, a first-type key obtaining module 504, an encryption request module 506, a first-type key decryption module 508, an encryption execution module 510, and an encrypted data returning module 512.
The encryption request receiving module 502 is configured to receive a metadata encryption request of a file, where the metadata encryption request includes: metadata and class key identification of the file, wherein the metadata comprises: a file key for encrypting the file.
The first class key obtaining module 504 is configured to search for a class key corresponding to the stored class key identifier.
In some embodiments, the class key identification corresponds to an application scenario; the application scene comprises the following steps: the terminal equipment can be accessed after being successfully started, the terminal equipment can be accessed after being successfully started and legally logged in and the user interface is unlocked, and the terminal equipment can be only written in when being successfully started and legally logged in and the user interface is locked.
The encryption request module 506 is configured to send a data encryption request to a trusted application in the trusted execution environment through a client interface between the normal execution environment and the trusted execution environment, where the data encryption request includes: class keys and metadata.
The first type key decryption module 508 is configured to decrypt, by the trusted application, the type key according to a master key pre-stored in the trusted execution environment.
The encryption execution module 510 is configured to encrypt the metadata according to the decrypted class key by the trusted application.
The encrypted data returning module 512 is configured to return the encrypted metadata to the normal execution environment through the client interface by the trusted application.
In some embodiments, the apparatus 50 further comprises: a file encryption module 514, a metadata receiving module 516, and a merge storage module 518. The file encryption module 514 is configured to encrypt a file in the trusted execution environment according to the file key. The metadata receiving module 516 is used for receiving the encrypted metadata. The merge storage module 518 is configured to merge the encrypted metadata and the encrypted file into one file for storage.
In some embodiments, the file encryption module 514 includes: a data block dividing sub-module 5142 and a database encryption sub-module 5144. The data block dividing sub-module 5142 is configured to divide the file into a plurality of data blocks. The database encryption sub-module 5144 is used to independently encrypt a plurality of data blocks.
According to the TrustZone-based file encryption method, the metadata containing the file key is encrypted in the trusted execution environment, and the ciphertext of the file key is stored in the common execution environment, so that the safe storage and use of the file key for encrypting the file are ensured.
Fig. 8 is a block diagram illustrating a TrustZone-based file decryption apparatus according to an exemplary embodiment. The decryption means is adapted to the encryption means 50 described above. As shown in fig. 8, the decryption apparatus 60 includes: a decryption request receiving module 602, a second-type key obtaining module 604, a decryption request module 606, a second-type key decryption module 608, a decryption execution module 610 and a decrypted data returning module 612.
The decryption request receiving module 602 is configured to receive a metadata decryption request of a file, where the metadata decryption request includes: metadata and a class key identifier of the file to be decrypted, wherein the metadata comprises: a file key for encrypting the file.
The second-class key obtaining module 604 is configured to search for a class key corresponding to the stored class key identifier.
The decryption request module 606 is configured to send a data decryption request to a trusted application in the trusted execution environment through a client interface between the normal execution environment and the trusted execution environment, where the data decryption request includes: class keys and metadata to be decrypted.
The second type key decryption module 608 is configured to decrypt the type key according to the master key pre-stored in the trusted execution environment by the trusted application.
The decryption execution module 610 is configured to decrypt, by the trusted application, the metadata according to the decrypted class key.
The decrypted data returning module 612 is configured to return the decrypted metadata to the normal execution environment through the client interface by using the trusted application.
In some embodiments, the apparatus 60 further comprises: an operation request receiving module 614 and a decryption request sending module 616. The operation request receiving module 614 is configured to receive an operation request for a file sent by a client application in the normal execution environment. The decryption request sending module 616 is configured to send a metadata decryption request of the file according to the operation request.
In some embodiments, the apparatus 60 further comprises: a file decryption module 618 and a decrypted file return module 620. The file decryption module 618 is configured to decrypt the file in the trusted execution environment according to the file key in the decrypted metadata. Decrypted file return module 620 is used to return the decrypted file to the client application.
In some embodiments, the file decryption module 618 includes: the data block decryption submodule 6182 is configured to decrypt the plurality of encrypted data blocks partitioned according to the file independently.
It is noted that the block diagrams shown in the above figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiment of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to make a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) execute the method according to the embodiment of the present invention.
Exemplary embodiments of the present invention are specifically illustrated and described above. It is to be understood that the invention is not limited to the precise construction, arrangements, or instrumentalities described herein; on the contrary, the invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.