POST
Some useful knowledge for Fingerprint Application on Trusty TEE
I have completed an Android platform fingerprint application on Trusty TEE recently for my work. This page will try to give some useful information, which is a summary of my work and might be helpful for somebody who wants to bring up a fingerprint application on Trusty TEE.
1. Trusty TEE
As one of the biometric authentication on the Android platform, fingerprint implementation must meet android security specifications. Android uses a separate secure Operating System (OS) to guarantee the security of biometric applications - we call it TEE (Trusted Execution Environment), Which runs on the same processor as the Android OS and is isolated from the rest of the system by both hardware and software. They run parallel to each other but secure OS has access to the full power of a device’s main processor and memory but is completely isolated.
There is multiple commercial TEE OS on the Android platform supported by third-party companies, Such as QSEE, ISEE, TBase, and so on. Trusty is one of them and unlike them, Trusty TEE is supported by Google. Trusty TEE is trying to provide the users a reliable and free open source alternative for their Trusted Execution Environment.
Google official documents provides more information about 「Trusty TEE」.
2. Memory restriction
2.1 Memory
The total memory that Trusty TEE can provide is 32M, suggests allocate 10M memory (heap + stack + ta image) for fingerprint to use. For example, using 6M heap and 3M stack.
2.2 Buffer
- a. The communication between CA and TA is limited in size, and the overall size is limited to 128KB, including message header. Therefore, the buffer size
TAC_SHARED_BUFFER_SIZE
should be less than 128K.
- b. Accordingly, the actual data size that can be used for effective transmission between CA and TA is limited to
- c. When the data to be transferred is greater than the maximum limit, consider transferring in batches.
- d. Change the size of heap and stack in the manifest file.
3. TEE Communication
- Adopt the dynamic TA mechanism which will load TA and run TA’s main function when CA calls function
connect()
. When CA callsdisconnect()
the TA process exits. Therefore, in a life cycle, there is no need to connect or disconnect each IPC communication. - There are many IPC communications between CA and TA. Every time IPC communication, the buffer received and sent by CA needs to be reallocated. The same buffer should not be used by IPC multiple times. In our code, this method has already been implemented.
- Trusty TEE provides 2 ports for communication,
secure port
andnon-secure port
.
Secure port - for other TA app access.
Non secure port - for CA access TA app.
For fingerprint, it needs to usenon-secure port
and if has payment requirement, needs to usesecure port
. - Should define the same port name between CA and TA, An example that we are using “com.android.trusty.fpctzapp”.
- Should use unique UUID to differentiate from other fingerprint vendors.
- About IPC: the Trusty APIs use
to send/retrieve messages between CA and TA, the calling sequence should be correct. One lesson learned in my software bring up is that the communication was failed after executed one-time successful communication. The communication was hang up after then and TA wasn’t able to get the message from CA. The failure was due to missing the put_msg()
calling after executed read_msg()
.
4. SPI
It is related to the hardware platform, on Spreadtrum SC9863, it doesn’t need to configure SPI and will only use ioctl()
for transmission.
5. Others
5.1 How to build ?
5.1.1 Toolchain
It is recommended to use the arm-eabi-4.8 tool chain of Android code package:
5.1.2 Build
put the TA code fpctzapp into SDK app/demo/ folder.
run command
5.1.3 Output Image
output two image files fpctzapp.elf and fpctzapp.syms.elf (which contains symbol table for debug purpose)
5.2 Tools
5.2.1 uuidgen
Output two image files fpctzapp.elf
and fpctzapp.syms.elf
(which contains symbol table for debug purpose)
5.2.2 addr2line
To find the line number of error occurrence from symbol table. In the
5.2.3 signta.py
Signature tool for signing the TA image. In the
command for signature.
5.3 Logs
5.3.1 TA load successfully
5.3.2 Failure with TA wasn’t signed or signatue wasn’t match
5.3.3 TA APP wasn’t running properly, CA lost communication