Try   HackMD

111-2專題研究筆記 Week 15-16

Task Specification

In this note, I was trying to figure out several questions, including:

  • Is my laptop (macbook air 2020) support TPM? And if so is it TPM 2.0?
  • what functions can be done with my computer's TPM module?
  • What are the algorithms it uses?
  • Where does it store the key?
  • What should be done when user forget the key?
  • Can TPM increase the performance of "data in motion"?

Furthermore, I am also going to see if TPM can help CPU to complete TLS encryption/decryption.

Research

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:

  • Macbook (Retina, 12 inches, 2017)
  • Macbook Air (13-inch, 2017)
  • Macbook Pro (15-inch, 2016)

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:

  • Self testing, TPM can test the functions that will return value before the result according to standards for hardware security modules.
  • Start a session, a session is for authorization and can establishing the session key. A session key is for authorization and for encrypting parameters.
  • Create/Load objects, TPM has RAM-like register that can store objects, such like key-data struture objects. It can also load objects from outside.
  • Low-level primitives for access to some algorithms, like asymmetric encryption/decryption, symmetric encryption/decryption, or hash.
  • Generate a random number.
  • Attestation, TPM can sign an internally generated data structure.
  • Ephemeral EC Keys, TPM generate tempolary EC key for subsequent, and can record if the key is used or not to save memory space.
  • Signing and verified, TPM can validate the signature of a message that been passed into, and it also can sign a message with provided key using either asymmetric or symmetric algorithms.
  • Integrity checking, TPM holds some register recording the system status called PCR. The value stored in it is readable but not writable, unless using TPM_Extend to hash new sha-1 value along with old value to create a new value of PCR. So we can get an infinitely long system state history, a bit like how bitcoin works. Althoug a single PCR can record the whole history of system state by above method, but with TPM 2.0 there's multiple PCR for different objects.
  • Prevent dicionary attack, TPM can record a password authorization fail and trigger a counter, if the count is exceed the max value then the whole module will stop working. The counter will decrease by 1 after certain time pass.

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:

  • RSA 2048
  • ECC P256
  • ECC BN256
  • ECDH

The symmetric kind include the following algorithms:

  • AES 128
  • AES 256

Also, the HASH and HMAC algorithms:

  • SHA-1
  • SHA-2 256

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:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

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.