1. 程式人生 > >通過TSS軟體棧使用TPM——獲取並改變TPM暫存器

通過TSS軟體棧使用TPM——獲取並改變TPM暫存器

https://www.cnblogs.com/summer2017/p/7719088.html

實驗使用TPM_Emulator代替TPM硬體,原理是一樣的。(學習網站:http://blog.csdn.net/buaa_shang/article/details/26157253)

1.登入系統後通過命令啟動TPM模擬器:

sudo modprobe tpmd_dev

sudo tpmd -f -d clear

2.啟動TrouSerS軟體棧

sudo tcsd -e -f

//另外可建立一個資料夾,裡面新建一個.c檔案,可用vim編輯器編寫,儲存後,用gcc工具對.c檔案進行編譯,然後執行即可。

[email protected]:~$ mkdir myFiles
[email protected]:~$ cd myFiles/
[email protected]:~/myFiles$ vim tpm1.c

 View Code


[email protected]:~/myFiles$ ls -al
總用量 12
drwxrwxr-x  2 shm shm 4096 10月 23 20:43 .
drwxr-xr-x 40 shm shm 4096 10月 23 20:43 ..
-rw-rw-r--  1 shm shm 3608 10月 23 20:43 tpm1.c

[email protected]:~/myFiles$ gcc tpm1.c -o tpm1 -ltspi
[email protected]:~/myFiles$ ./tpm1 -p 0    

//注:通過-p選項指定要修改的PCR暫存器的序號(此處為PCR0,只是為了演示,PCR0用來存放可信啟動過程中的度量值)

//下圖為程式輸出的沒有修改前PCR暫存器內值的情況:


Create Context : Success
Context Connect : Success
Get TPM Handle : Success
Get the SRK handle : Success
Get the SRK policy : Success
PCR 00 00000000000000000000000000000000000000
PCR 01 00000000000000000000000000000000000000
PCR 02 00000000000000000000000000000000000000
PCR 03 00000000000000000000000000000000000000
PCR 04 00000000000000000000000000000000000000
PCR 05 00000000000000000000000000000000000000
PCR 06 00000000000000000000000000000000000000
PCR 07 00000000000000000000000000000000000000
PCR 08 00000000000000000000000000000000000000
PCR 09 00000000000000000000000000000000000000
PCR 10 00000000000000000000000000000000000000
PCR 11 00000000000000000000000000000000000000
PCR 12 00000000000000000000000000000000000000
PCR 13 00000000000000000000000000000000000000
PCR 14 00000000000000000000000000000000000000
PCR 15 00000000000000000000000000000000000000
PCR 16 ffffffffffffffffffffffffffffffffffffff
PCR 17 ffffffffffffffffffffffffffffffffffffff
PCR 18 ffffffffffffffffffffffffffffffffffffff
PCR 19 ffffffffffffffffffffffffffffffffffffff
PCR 20 ffffffffffffffffffffffffffffffffffffff
PCR 21 ffffffffffffffffffffffffffffffffffffff
PCR 22 ffffffffffffffffffffffffffffffffffffff
PCR 23 ffffffffffffffffffffffffffffffffffffff
//修改成功後的PCR值輸出:  可見PCR0中160bit值被修改了。(通過PCR_Extend操作後所有PCR暫存器內值的情況:
 Command line arguments:
argv[0] : ./tpm1
argv[1] : -p
argv[2] : 0
Extended the PCR : Success
PCR 00 30b94d3d773fe9349dba938c5ced5981b95220
PCR 01 00000000000000000000000000000000000000
PCR 02 00000000000000000000000000000000000000
PCR 03 00000000000000000000000000000000000000
PCR 04 00000000000000000000000000000000000000
PCR 05 00000000000000000000000000000000000000
PCR 06 00000000000000000000000000000000000000
PCR 07 00000000000000000000000000000000000000
PCR 08 00000000000000000000000000000000000000
PCR 09 00000000000000000000000000000000000000
PCR 10 00000000000000000000000000000000000000
PCR 11 00000000000000000000000000000000000000
PCR 12 00000000000000000000000000000000000000
PCR 13 00000000000000000000000000000000000000
PCR 14 00000000000000000000000000000000000000
PCR 15 00000000000000000000000000000000000000
PCR 16 ffffffffffffffffffffffffffffffffffffff
PCR 17 ffffffffffffffffffffffffffffffffffffff
PCR 18 ffffffffffffffffffffffffffffffffffffff
PCR 19 ffffffffffffffffffffffffffffffffffffff
PCR 20 ffffffffffffffffffffffffffffffffffffff
PCR 21 ffffffffffffffffffffffffffffffffffffff
PCR 22 ffffffffffffffffffffffffffffffffffffff
PCR 23 ffffffffffffffffffffffffffffffffffffff

[email protected]:~/myFiles$