In this note, I was trying to figure out several questions, including:
Furthermore, I am also going to see if TPM can help CPU to complete TLS encryption/decryption.
At first, TPM was included on the motherboard. TCG (Trusted Computing Group) anounced the TPM regulations for the shortcomings of software-only computer defense approach. When malware gain the privilege level as high as the antivirus software, it will be completely useless. More over, The malware is becoming more sophisticated that it can affect not only the system memory sections but also firmware, bootloader code, and that can't be sense by software-only defense system. We need a system that can record and verify the state outside the system memory space, also with cheap cost, so we have TPM 1.2 chip.
Now for the first question: Is my laptop (macbook air 2020) support TPM? And if so is it TPM 2.0? The answer is no. In fact, most macbooks don't have TPM support, except some of them, like:
Althoug all of the above have TPM, the module is actually intergrated into ther CPUs. After 2016, Intel and AMD integrate TPM module into their CPUs, so these macbooks are only using CPUs with TPM, their motherboards still can't support it. But my laptop indeed has a secure chip for hardware defense system, which is the Apple T2 chip and can do almost all the tricks that TPM module can play, we'll talk about T2 chip later.
I also found out that my PC (AMD R5 3600 CPU with A520 Aorus Elite mother board) have the TPU 2.0 module which is motherboared based, and that's why I can update it to Windows 11, for Windows 11 is only for the platform that support TPM 2.0. The implementaion of TPM 2.0 by AMD is called ftpm, firmware based TPM. So I planned to further testing the performance and differencies of R5 3600 TPM and T2 chip in the future, and studying ftpm by this article.
So now I'll focus om my PC's TPM 2.0 module, with the seconed question: what functions can be done with my computer's TPM module? Well, there is a lot. Though I haven't tried any of them, I will list a few functions I collected in this ducument, which is the library by TCG's latest release of TPM 2.0 command collection.
The TPM 2.0 module can do the following funcions:
I have dig out some most important funcions TPM support, now let's look deeper with our third question: What are the algorithms it uses? In general, TPM use two kinds of algorithms to do the encryption/decryption, that is asymmetric or symmetric.
The asymmetric kind include the following algorithms:
The symmetric kind include the following algorithms:
Also, the HASH and HMAC algorithms:
Now we can also see the fourth question: Where does it store the key? By this library that describes the architecture of TPM, TPM holds two kinds of memory that is volatile memory and non-volatile memory, like the graph below:
The volatile memory holds transient data, which will lost when power is removed. This memory contains the register for integrity check we mentioned before, it also holds object and session that can be created by user, so it holds their keys. User can create/load a object contains key and data into this memory, so this "temporary" key is kept in here, same as the key used by session (if any).
As for the non-volatile memory, it stores persistent datas. Some of the NV memory is available for allocation and use by the platform authorized by the TPM owner. This NV memory stores the TPM primary seed, which is used to generate symmetric keys, asymmetric keys or some proof values. The platform (which may means the firmware) can also store its platform primary seed in here.
Let us move on to the fifth question: What should be done when user forget the key? along with this article. Well, that is quite frustrated because TPM is designed to protect the key stored inside it against all kinds of attack. For example, because of the fact that TPM is bind with its motherboard, so it's not possible to just replace the TPM module itself since almost every component on the motherboard is valided by TPM.
So, this article here introduced an approach to prevent the situation that the whole computer is down when the key is lost, which is using externel device to backup some critical data within TPM modure and some encrypted data archieve, though those functions come with Professional Package along with OEM products of Infineon Inc. which is the writer of the atricle we're using.
For the final question: Can TPM increase the performance of “data in motion”? That is, for example, replacing the role of CPU in TLS operations. Can we passed the decryption/encryption procedures to TPM module to reduce the delay of https comunication? The answer is yes. This github page introduced an api called TPM2-TSS, which is a stack of apis from user space to TPM module. With this, we can make almost every funcions of OPENSSL pass to TPM module to accomplish hardware acceleration of encryption/decryption algorithms, including open a TLS secure connection.
We can download the project from here, I only tested version 1.1.0. We can install it by:
$ sudo apt -y install \
build-essential \
autoconf \
autoconf-archive \
automake \
m4 \
libtool \
gcc \
pkg-config \
libssl-dev \
pandoc \
doxygen
$ cd tpm2-tss-engine
$ ./bootstrap
$ ./configure
$ make -j$(nproc)
$ sudo make install
The OS I chosed is ubuntu 20.04 linux. Now, we can simply create a TLS key and its self-signed certificate to open a secure TLS connection:
$ ./tpm2tss-genkey -a rsa rsa.tss
$ openssl req -new -x509 -engine tpm2tss -key rsa.tss -keyform engine -out rsa.crt
Then we can start a TLS server by:
$ openssl s_server -cert rsa.crt -key rsa.tss -keyform engine -engine tpm2tss -accept 8443
Now with another client, we can establish a connection to the server, via:
$ openssl s_client -connect nemo.org:8443 -cipher ECDHE-RSA-AES128-GCM-SHA256
A TLS connection server will "respect" the cipher method chosed by the client, so in the client's command I chosed the ECDHE-RSA-ASE128-GCM_SHA256 method which is ECDH-256 key exchange with AES-128 and supported by my PC's TPM module.