TPM及TSS協議棧的安裝使用


TPM及TSS協議棧的安裝

標簽: 可信計算。


目錄

安裝環境介紹

TPM及TSS安裝

交互過程

測試代碼

環境

  • ubuntu 16.04 ubuntu 14.04 ubuntu 12.04都可以,本人使用的是Ubuntu16.04

TPM 及TSS安裝

  • 直接上干貨吧
    - 下面是仿真環境軟件包依賴關系圖
    - 安裝環境應該是由下至上按部就班的安裝。

軟件包下載百度網盤 提取碼1tug

安裝步驟

安裝libgmp

  • step one:使用sudo apt-get install m4安裝m4
  • 在百度網盤上下載gmp6.1.2
    - (1) ./configure
    - (2) make
    - (3) make check
    - (4) sudo make install

安裝TPM_emulator

  • 進入之前百度網盤下載的tpm-emulator-master文件夾下
    - (1) mkdir build
    - (2) cd build
    - (3) cmake ../
    - (4) sudo make
    - (5) sudo make install//需要權限復制文件
  • 初始化TPM
    - (1)tpmd deactivated
    - (2)killall tpmd
    - (3)tpmd clear
  • 啟動TPM
    - (1)depmod -a
    - (2) modprobe tpmd_dev
    - (3) tpmd -f -d

安裝TSS協議棧

  • 養成好習慣,安裝使用別人的東西之前,先看README文檔,可以減少很多麻煩
安裝依賴:
 Packages needed to build:
  automake > 1.4
  autoconf > 1.4
  pkgconfig
  libtool
  gtk2-devel
  openssl-devel >= 0.9.7
  pthreads library (glibc-devel)

      - 使用````sudo apt-get install 軟件包名````挨個安裝這些依賴的安裝包
      - 使用````sudo apt-get install libssl-dev````安裝openssl_dev
  • 進入之前下載的trousers0.3.14

    • (1)./configure
    • (2) make
    • (3) sudo make install
  • 啟動TSS 使用sudo tcsd -e -f啟動tss

安裝tpm-tools

  • 使用指令sudo apt-get install tpm-tools 這里需要等幾分鍾。
    -如果出現fail可能是tcsd沒有跑起來,最簡單的解決辦法就是重啟,然后重新啟動TPM TSS,重新使用指令sudo apt-get install tpm-tools
    - 查看是否安裝成功
在/usr/sbin目錄下有3個關於tpm的命令運行如下
cd /usr/sbin
./tpm_version      #查看版本號
./tpm_getpubek   #查看ek公鑰
./tpm_takeownership   #獲取owner

TPM交互

  • 安裝完TPM以及TSS還有tpm tools后。
  • Step one:啟動TPM:
    • 使用指令 sudo depmod -a //分析可載入模塊的相依性
    • 使用指令 sudo modprobe tpmd_dev//加載模塊
    • 使用指令 sudo tpmd -f -d//啟動模塊
  • 啟動成功后的信息記錄如下
aaronhoo@aaronhoo:~/tpm/tpm-emulator-master$ sudo tpmd -f -d
tpmd.c:523: Info: starting TPM Emulator daemon (1.2.0.7-475)
tpmd.c:102: Info: parsing options
tpmd.c:109: Debug: debug mode enabled
tpmd.c:228: Info: installing signal handlers
tpmd.c:387: Info: staring main loop
tpmd.c:302: Info: initializing socket /var/run/tpm/tpmd_socket:0
tpmd.c:401: Debug: initializing TPM emulator
tpm_emulator_extern.c:101: Info: _tpm_extern_init()
tpm_emulator_extern.c:104: Debug: openening random device /dev/urandom
tpm_cmd_handler.c:4113: Debug: tpm_emulator_init(2, 0x00000000)
tpm_startup.c:29: Info: TPM_Init()
tpm_testing.c:243: Info: TPM_SelfTestFull()
tpm_testing.c:39: Debug: tpm_test_prng()
tpm_testing.c:69: Debug: Monobit: 9948
tpm_testing.c:70: Debug: Poker:   11.3
tpm_testing.c:71: Debug: run_1:   2487, 2525
tpm_testing.c:72: Debug: run_2:   1280, 1299
tpm_testing.c:73: Debug: run_3:   672, 617
tpm_testing.c:74: Debug: run_4:   302, 295
tpm_testing.c:75: Debug: run_5:   139, 145
tpm_testing.c:76: Debug: run_6+:  156, 155
tpm_testing.c:77: Debug: run_34:  0
tpm_testing.c:111: Debug: tpm_test_sha1()
tpm_testing.c:157: Debug: tpm_test_hmac()
tpm_testing.c:184: Debug: tpm_test_rsa_EK()
tpm_testing.c:186: Debug: tpm_rsa_generate_key()
tpm_testing.c:191: Debug: testing endorsement key
tpm_testing.c:197: Debug: tpm_rsa_sign(RSA_SSA_PKCS1_SHA1)
tpm_testing.c:200: Debug: tpm_rsa_verify(RSA_SSA_PKCS1_SHA1)
tpm_testing.c:203: Debug: tpm_rsa_sign(RSA_SSA_PKCS1_DER)
tpm_testing.c:206: Debug: tpm_rsa_verify(RSA_SSA_PKCS1_DER)
tpm_testing.c:210: Debug: tpm_rsa_encrypt(RSA_ES_PKCSV15)
tpm_testing.c:214: Debug: tpm_rsa_decrypt(RSA_ES_PKCSV15)
tpm_testing.c:218: Debug: verify plain text
tpm_testing.c:221: Debug: tpm_rsa_encrypt(RSA_ES_OAEP_SHA1)
tpm_testing.c:225: Debug: tpm_rsa_decrypt(RSA_ES_OAEP_SHA1)
tpm_testing.c:229: Debug: verify plain text
tpm_testing.c:261: Info: Self-Test succeeded
tpm_startup.c:43: Info: TPM_Startup(2)
tpmd.c:412: Debug: waiting for connections...

編寫一個測試程序,測試TPM是否正常使用


  • 啟動TPM后新開一個終端,輸入指令sudo tcsd -e -f 啟動tss
  • 啟動成功后如下圖:

  • 新開一個端口,設置授權,授權方式由編寫的代碼中的參數決定
tpm_takeownership setup an owner on the system's TPM (via the TPM_TakeOwnership API). This operation requires the TPM to be enabled and can be restricted by tpm_setownable. The command will prompt for owner and SRK passwords and confirmations of these if executed without either of the -well-known options, otherwise, a secret of all zeros is set for the requested password. After the second confirmation, be patient as the command may take awhile.

-h, --help
    Display command usage info. 
-v, --version
    Display command version info. 
-l, --log [none|error|info|debug]
    Set logging level. 
-u, --unicode
    Use TSS UNICODE encoding for passwords to comply with applications using TSS popup boxes 
-y, --owner-well-known
    Set a secret of all zeros (20 bytes of zeros) as the owner's secret. 
-z, --srk-well-known
    Set a secret of all zeros (20 bytes of zeros) as the SRK secret. 

啟動成功后,編寫一個測試程序,測試TSS是否正常使用

  • 使用gcc指令進行編譯,-l去鏈接需要使用到的庫,生成可執行文件。
    • 例如:我有一個test.c文件需要編譯。可以使用gcc test.c -o exp -ltspi
    • 大概的意思就是鏈接tspi編譯test.c 生成 一個可執行文件exp
  • 注意不同的代碼,需要鏈接的庫可能不一樣所以-l后面跟的庫名根據代碼而定。

關於測試代碼:

[安裝中遇見的問題參考我的這一篇博客](http://www.cnblogs.com/hpl20155329/p/8586362.html)

[TPM交互看這篇博客](http://www.cnblogs.com/hpl20155329/p/9013003.html)

還有就是參考老師的實驗指導書。

初學可信 若有錯誤之處 ,請大佬們指出。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM