Implementation method and system for quickly packaging third-party library interface based on security domain
By generating client Proxy and server Stub codes in the TEE environment, remote interface calls in the security domain are realized, which solves the complexity problem of hardware suppliers adapting to different SOC chip manufacturers' solutions, improves development efficiency and system flexibility, and simplifies development process.
Patent Information
- Application Number
- CN202410759890.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-06
AI Technical Summary
In a more secure TEE environment, hardware suppliers need to adapt to solutions provided by different SOC chip manufacturers, resulting in heavy development workload, increased complexity, and delayed development cycles.
A tool that generates client Proxy and server Stub code by parsing hsm.h to realize remote interface calling tRPC based on the security domain. The REE side client Proxy serializes the parameters and sends them to the TEE side through IChannelBuffer. The TEE side server Stub responds Serialize and receive through IChannelBuffer to realize message passing between REE and TEE, simplifying interface calling.
It greatly improves production efficiency, reduces the development workload, shortens the development period, and ensures the flexibility and adaptability of the system. When the underlying TEE communication changes, only the Channel module needs to be modified to adapt to different communication methods, and other modules do not need to change.
Smart Images

Figure CN118606931A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of automotive electronic safety domains, and in particular to a method and system for implementing rapid encapsulation of a third-party library interface based on a safety domain. Background Art
[0002] With the development of Internet of Vehicles technology, users have higher and higher requirements for information security. In order to improve the level of information security, the software architecture has gradually changed from the original solution of external hardware security module (HSM) in rich execution environment (REE) such as Android or Linux to the solution of external HSM in trusted execution environment (TEE).
[0003] This brings challenges to the hardware suppliers of vehicle systems. With the change of architecture, hardware suppliers need to undertake a lot of adaptation work. In the original plan, HSM chip suppliers usually provide the source code of the HSM chip communication library for the Linux system, communicate with the HSM chip through the standard I2C or SPI interface, and provide a unified device node to the upper layer. Hardware suppliers usually only need to do simple adaptation and cross-compile the source code of the HSM library to use it.
[0004] like Figure 1 As shown in the figure, Normal World is also called REE, which usually refers to Android or Linux systems under the Arm architecture. Secure World is also called TEE. Usually different system on chip (hereinafter referred to as SOC) chip manufacturers provide different solutions, such as Qualcomm platform QSEE (Qualcomm Secure Execution Environment), open source OP-TEE (Open Source Project Trusted Execution Environment), etc.
[0005] There are usually two designs for user APP. One is that 101 user APP1 calls 103 security chip HAL service provided by hardware supplier, and then 103 security chip HAL service calls 104 security chip library; the other is that 102 user APP2 directly calls the interface of 104 security chip library. 104 security chip library reads and writes SPI device nodes provided by 105 SPI driver, and 105 SPI driver communicates with 106 security chip through SPI. Among them, 106 security chip and 104 security chip library are provided by security chip supplier. 104 security chip library is usually provided in source code (abbreviated as hsm.h and hsm.c). Hardware supplier usually only needs to do simple adaptation, and generate library (hereinafter referred to as libhsm.so) after cross compilation to use it.
[0006] However, the solution of connecting an external HSM in a more secure TEE environment has different TEE environments due to the different solutions provided by system on chip (SOC) chip manufacturers. HSM chip suppliers have not adapted the different TEE environments of SOC chip manufacturers. As a hardware supplier of the in-vehicle system, it is necessary to open up a whole link from APP to Trusted Execution Environment Client (TEEC), TEEC to TEE, TEE to TA, and TA to HSM. The entire process is huge.
[0007] The solution of external HSM in a more secure TEE environment is the future trend. Due to the change of the solution, not only the complexity of the system is increased, but also the development workload is greatly increased, delaying the development cycle. Summary of the invention
[0008] The purpose of the present invention is to overcome the defects of the prior art and provide a method and system for quickly encapsulating third-party library interfaces based on a security domain. By parsing hsm.h to generate a client Proxy code and a server Stub code tool, an innovative remote interface call tRPC based on a security domain is implemented, which greatly improves production efficiency, reduces development workload, and shortens development period.
[0009] The purpose of the present invention is achieved in one aspect as follows: A method for implementing a fast encapsulation of a third-party library interface based on a security domain, including a REE-side client Proxy and a TEE-side server Stub, comprising the following steps: The REE-side client Proxy serializes the third-party interface parameters and sends the data to the TEE side through the data transfer interface IChannelBuffer; The TEE-side server Stub deserializes the third-party interface parameters and receives the data from the REE side through the data transfer interface IChannelBuffer; The REE-side client Proxy and the TEE-side server Stub perform message transmission between the REE and TEE ends through security monitoring calls, realizing the remote interface calling mechanism tRPC based on the security domain.
[0010] As a further limitation of the present invention, it also includes a REE side Channel module and a TEE side Channel module; The REE side Channel module is connected to the client Proxy and implements the IChannelBuffer interface by calling the TEE RPC interface on the REE side; The TEE side Channel module is connected to the server-side Stub and implements the IChannelBuffer interface by calling the TEE RPC interface on the TEE side.
[0011] As a further limitation of the present invention, the code of the REE side client Proxy is integrated on the REE side, and the Proxy code is compiled to generate a library libhsm_proxy.so. The Proxy code implements all interfaces of hsm.h and acts as a proxy for the client.
[0012] As a further limitation of the present invention, the code of the TEE side server Stub is integrated on the TEE side. After the Stub code is compiled, a library libhsm_stub.so is generated. The Stub code implements all interfaces of hsm.h and acts as a proxy for the server.
[0013] Another aspect of the purpose of the present invention is achieved as follows: a system for implementing a third-party library interface based on a security domain for rapid encapsulation, comprising a REE side user space, a REE side kernel space, a TEE side user space and a TEE side kernel space; a security chip library Proxy module 204 and a TEE ClientAPI module 205 are provided in the REE side user space; a TEE subsystem 206 is provided in the REE side kernel space; a security chip TA service module 207, a security chip library Stub module 208 and a security chip library 210 are provided in the TEE side user space; an OP-TEE driver 211 and an SPI driver 212 are provided in the TEE side kernel space; The secure chip library Proxy module 204 is used to interact with the TEE subsystem 206 by calling the interface provided by the TEE ClientAPI module 205; The TEE subsystem 206 is used to communicate with the OP-TEE driver 211 on the TEE side by calling the SMC mode through security monitoring, so as to realize the call from the REE end to the TEE end; The security chip TA service module 207 is used to send the message to the lower layer through the security chip library Stub module 208; The security chip library Stub module 208 is used to encapsulate the interface 210 of the security chip library; The security chip library 210 is used to call the SPI interface provided by the SPI driver 212, and the SPI driver 212 communicates with the external security chip 213 through SPI; The secure chip library Proxy module 204 is electrically connected to the TEE Client API module 205; the TEE Client API module 205 is electrically connected to the TEE subsystem 206; The security chip TA service module 207 is electrically connected to the security chip library Stub module 208; the security chip library Stub module 208 is electrically connected to the security chip library 210; the security chip library 210 is electrically connected to the SPI driver 212; the OP-TEE driver 211 is electrically connected to the TEE subsystem 206.
[0014] As a further limitation of the present invention, the REE side user space is also provided with a user APP1 module 201, a user APP2 module 202, and a security chip HAL service 203; the user APP1 module 201 is electrically connected to the security chip HAL service 203; the user APP2 module 202 is electrically connected to the security chip library Proxy module 204.
[0015] As a further limitation of the present invention, a TEE InternalAPI module 209 is also provided in the user space on the TEE side, and the TEE InternalAPI module 209 is electrically connected to the security chip TA service module 207 and the OP-TEE driver 211; the TEE InternalAPI module 209 is used to pass the message to the security chip TA service module 207, and the OP-TEE driver 211 passes the message to the user state through the TEE InternalAPI module 209.
[0016] The present invention adopts the above technical solution, and compared with the prior art, the beneficial effects are as follows: by parsing hsm.h to generate a tool for client Proxy code and server Stub code, an innovative remote interface call tRPC based on the security domain is realized; the REE side client Proxy is connected to the Channel module, and the client Proxy realizes the serialization of third-party interface parameters, and sends data to the TEE side by relying on a set of data transmission interface IChannelBuffer, and the Channel module realizes the IChannelBuffer interface by calling the interface of TEEPC; TEE usually provides different solutions for different SOC chip manufacturers, so that when the underlying TEE communication changes, only the Channel module needs to be modified to adapt to different communication methods, ensuring that the modules above the Channel do not need to be changed.
[0017] The server Stub on the REE side is connected to the Channel module. The server Stub implements the deserialization of the third-party interface parameters and receives the data on the REE side by relying on a set of data transmission interfaces IChannelBuffer. The Channel module implements the IChannelBuffer interface by calling the TEE RPC interface. TEE usually provides different solutions for different SOC chip manufacturers. This ensures that when the underlying TEE communication changes, only the Channel module needs to be modified to adapt to different communication methods, ensuring that the modules above the Channel do not need to be changed. It realizes the software requirements of high cohesion and low coupling, greatly improves production efficiency, reduces development workload, and shortens development period. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 System block diagram of the prior art.
[0019] Figure 2 Flowchart of the present invention.
[0020] Figure 3 System block diagram of the present invention.
[0021] Figure 4 Block diagram of the vehicle-mounted system of the present invention. DETAILED DESCRIPTION
[0022] like Figure 2 The following figure shows a method for implementing a fast encapsulation of a third-party library interface based on a security domain. The client proxy code is integrated on the REE side. The proxy code is compiled to generate a library (hereinafter referred to as libhsm_proxy.so). The proxy code implements all interfaces of hsm.h and acts as a proxy for the client. The server-side Stub code is integrated on the TEE side. After the Stub code is compiled, a library is generated (hereinafter referred to as libhsm_stub.so). The Stub code implements all interfaces of hsm.h and acts as a proxy for the server. The client Proxy and server Stub implement message transmission between REE and TEE through secure monitor calls (hereinafter referred to as SMC), thereby realizing remote interface calls tRPC based on the security domain.
[0023] like Figure 3 As shown, the REE-side client Proxy is used to serialize the third-party interface parameters and send the data to the TEE side through the data transfer interface IChannelBuffer; the REE-side Channel module is connected to the client Proxy and implements the IChannelBuffer interface by calling the TEE RPC interface on the REE side; The server Stub on the TEE side is used to deserialize the third-party interface parameters and receive the data on the REE side through the data transfer interface IChannelBuffer. The Channel module on the TEE side is connected to the server Stub and implements the IChannelBuffer interface by calling the TEE RPC interface on the TEE side. The REE-side client Proxy and the TEE-side server Stub perform message transmission between the REE and TEE ends through security monitoring calls, realizing remote interface calls tRPC based on the security domain.
[0024] like Figure 4 As shown, a system for implementing a fast encapsulation of a third-party library interface based on a security domain includes a REE side user space, a REE side kernel space, a TEE side user space, and a TEE side kernel space; The user space on the REE side is provided with a user APP1 module 201, a user APP2 module 202, a security chip HAL service 203, a security chip library Proxy module 204, and a TEE ClientAPI module 205; the kernel space on the REE side is provided with a TEE subsystem 206; the user APP1 module 201 is electrically connected to the security chip HAL service 203; the user APP2 module 202 is electrically connected to the security chip library Proxy module 204; the security chip library Proxy module 204 is electrically connected to the TEE ClientAPI module 205; the TEEClientAPI module 205 is electrically connected to the TEE subsystem 206.
[0025] The REE side only needs to replace the original security chip library 104 with the security chip library Proxy module 204 generated by the tool, and no other modifications are required; the user APP1 module 201 calls the security chip HAL service 203 provided by the hardware supplier, and then the security chip HAL service 203 calls the automatically generated security chip library Proxy module 204; the user APP2 module 202 directly calls the automatically generated security chip library Proxy module 204; the security chip library Proxy module 204 interacts with the TEE subsystem 206 by calling the interface provided by the TEEClientAPI module 205, and the TEE subsystem 206 communicates with the OP-TEE driver 211 through the SMC method, thereby realizing the call from the REE end to the TEE end; A security chip TA service module 207, a security chip library Stub module 208, a TEEInternalAPI module 209 and a security chip library 210 are set in the user space on the TEE side; an OP-TEE driver 211 and an SPI driver 212 are set in the kernel space on the TEE side; the security chip TA service module 207 is electrically connected to the security chip library Stub module 208 and the TEE InternalAPI module 209; the security chip library Stub module 208 is electrically connected to the security chip library 210; the security chip library 210 is electrically connected to the SPI driver 212, and the SPI driver 212 is electrically connected to the external security chip 213; the OP-TEE driver 211 is electrically connected to the TEE subsystem 206.
[0026] The OP-TEE driver 211 on the TEE side passes the message to the user state through the TEE InternalAPI module 209, and the TEEInternalAPI module 209 passes the message to the security chip TA service 207; the security chip TA service 207 sends the message to the lower layer through the security chip library Stub module 208; the automatically generated security chip library Stub module 208 encapsulates the interface of the security chip library 210; the security chip library 210 calls the SPI interface provided by the SPI driver 212, and the SPI driver 212 communicates with the security chip 213 through SPI. In fact, the security chip library 104 and the security chip library 210 are the same component. The SPI driver 105 and the SPI driver 212 are the same component. The security chip 106 and the security chip 213 are the same component.
[0027] The present invention is not limited to the above-mentioned embodiments. On the basis of the technical solution disclosed in the present invention, technicians in this field can make some substitutions and deformations to some technical features therein according to the disclosed technical content without creative labor, and these substitutions and deformations are all within the protection scope of the present invention.
Claims
1. A method for implementing a fast encapsulation of a third-party library interface based on a security domain, characterized in that: Including the REE side client Proxy and the TEE side server Stub, including the following steps: The REE-side client Proxy serializes the third-party interface parameters and sends the data to the TEE side through the data transfer interface IChannelBuffer; The TEE-side server Stub deserializes the third-party interface parameters and receives the data from the REE side through the data transfer interface IChannelBuffer; The REE-side client Proxy and the TEE-side server Stub perform message transmission between the REE and TEE ends through security monitoring calls, realizing the remote interface calling mechanism tRPC based on the security domain.
2. According to claim 1, a method for implementing a fast encapsulation of a third-party library interface based on a security domain is characterized in that: It also includes REE side Channel module and TEE side Channel module; The REE side Channel module is connected to the client Proxy and implements the IChannelBuffer interface by calling the TEE RPC interface on the REE side; The TEE side Channel module is connected to the server-side Stub and implements the IChannelBuffer interface by calling the TEE RPC interface on the TEE side.
3. According to claim 1, a method for implementing a fast encapsulation of a third-party library interface based on a security domain is characterized in that: The REE side client Proxy code is integrated on the REE side. After the Proxy code is compiled, a library libhsm_proxy.so is generated. The Proxy code implements all interfaces of hsm.h and acts as a proxy for the client.
4. According to claim 1, a method for implementing a fast encapsulation of a third-party library interface based on a security domain is characterized in that: The TEE side server Stub code is integrated on the TEE side. After the Stub code is compiled, the library libhsm_stub.so is generated. The Stub code implements all interfaces of hsm.h and acts as a proxy for the server.
5. A system for implementing a third-party library interface based on a security domain for rapid encapsulation, comprising a REE side user space, a REE side kernel space, a TEE side user space, and a TEE side kernel space; characterized in that: The user space on the REE side is provided with a secure chip library Proxy module (204) and a TEE Client API module (205); the kernel space on the REE side is provided with a TEE subsystem (206); the user space on the TEE side is provided with a secure chip TA service module (207), a secure chip library Stub module (208), and a secure chip library (210); the kernel space on the TEE side is provided with an OP-TEE driver (211) and an SPI driver (212); The secure chip library proxy module (204) is used to interact with the TEE subsystem (206) by calling the interface provided by the TEE Client API module (205); The TEE subsystem (206) is used to communicate with the OP-TEE driver (211) on the TEE side by calling the SMC mode through security monitoring, so as to realize the call from the REE end to the TEE end; The security chip TA service module (207) is used to send the message to the lower layer through the security chip library Stub module (208); The security chip library Stub module (208) is used to encapsulate the interface (210) of the security chip library; The security chip library (210) is used to call the SPI interface provided by the SPI driver (212), and the SPI driver (212) completes communication with the external security chip (213) via SPI; The security chip library Proxy module (204) is electrically connected to the TEE Client API module (205); the TEE Client API module (205) is electrically connected to the TEE subsystem (206); The security chip TA service module (207) is electrically connected to the security chip library Stub module (208); the security chip library Stub module (208) is electrically connected to the security chip library (210); the security chip library (210) is electrically connected to the SPI driver (212); and the OP-TEE driver (211) is electrically connected to the TEE subsystem (206).
6. A system for implementing a fast encapsulation of a third-party library interface based on a security domain according to claim 5, characterized in that: The REE-side user space is also provided with a user APP1 module (201), a user APP2 module (202), and a security chip HAL service (203); the user APP1 module (201) is electrically connected to the security chip HAL service (203); and the user APP2 module (202) is electrically connected to a security chip library Proxy module (204).
7. A system for implementing a fast encapsulation of a third-party library interface based on a security domain according to claim 5, characterized in that: A TEE InternalAPI module (209) is also provided in the user space on the TEE side. The TEE InternalAPI module (209) is electrically connected to the security chip TA service module (207) and the OP-TEE driver (211); the TEE InternalAPI module (209) is used to pass messages to the security chip TA service module (207), and the OP-TEE driver (211) passes the messages to the user state through the TEEInternalAPI module (209).
