fapi-get-tpm-blobs.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. set -e
  2. source helpers.sh
  3. start_up
  4. CRYPTO_PROFILE="RSA"
  5. setup_fapi $CRYPTO_PROFILE
  6. function cleanup {
  7. tss2 delete --path=/
  8. shut_down
  9. }
  10. trap cleanup EXIT
  11. KEY_PATH="HS/SRK/myRSASign"
  12. PUBLIC_KEY_FILE=$TEMP_DIR/pub_key.file
  13. PRIVATE_KEY_FILE=$TEMP_DIR/priv_key.file
  14. POLICY_FILE=$TEMP_DIR/policy.file
  15. PCR_POLICY_DATA=$TEMP_DIR/pol_pcr16_0.json
  16. POLICY_PCR=policy/pcr-policy
  17. tss2 provision
  18. tss2 import --path=$POLICY_PCR --importData=$PCR_POLICY_DATA
  19. tss2 createkey --path=$KEY_PATH --policyPath=$POLICY_PCR --type="noDa, sign" \
  20. --authValue=""
  21. tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=$PUBLIC_KEY_FILE \
  22. --tpm2bPrivate=$PRIVATE_KEY_FILE --policy=$POLICY_FILE --force
  23. expect <<EOF
  24. # Try with missing path
  25. spawn tss2 gettpmblobs --tpm2bPublic=$PUBLIC_KEY_FILE \
  26. --tpm2bPrivate=$PRIVATE_KEY_FILE --policy=$POLICY_FILE
  27. set ret [wait]
  28. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  29. Command has not failed as expected\n"
  30. exit 1
  31. }
  32. EOF
  33. expect <<EOF
  34. # Try with missing tpm2bPublic
  35. spawn tss2 gettpmblobs --path=$KEY_PATH \
  36. --tpm2bPrivate=$PRIVATE_KEY_FILE --policy=$POLICY_FILE
  37. set ret [wait]
  38. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  39. Command has not failed as expected\n"
  40. exit 1
  41. }
  42. EOF
  43. expect <<EOF
  44. # Try with missing tpm2bPrivate
  45. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=$PUBLIC_KEY_FILE \
  46. --policy=$POLICY_FILE
  47. set ret [wait]
  48. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  49. Command has not failed as expected\n"
  50. exit 1
  51. }
  52. EOF
  53. expect <<EOF
  54. # Try with missing policy
  55. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=$PUBLIC_KEY_FILE \
  56. --tpm2bPrivate=$PRIVATE_KEY_FILE
  57. set ret [wait]
  58. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  59. Command has not failed as expected\n"
  60. exit 1
  61. }
  62. EOF
  63. expect <<EOF
  64. # Try with existing directory PUBLIC_KEY_FILE
  65. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=$PUBLIC_KEY_FILE \
  66. --tpm2bPrivate=$PRIVATE_KEY_FILE --policy=$POLICY_FILE
  67. set ret [wait]
  68. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  69. Command has not failed as expected\n"
  70. exit 1
  71. }
  72. EOF
  73. expect <<EOF
  74. # Try with multiple stdout (1)
  75. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=- \
  76. --tpm2bPrivate=- --policy=$POLICY_FILE --force
  77. set ret [wait]
  78. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  79. Command has not failed as expected\n"
  80. exit 1
  81. }
  82. EOF
  83. expect <<EOF
  84. # Try with multiple stdout (2)
  85. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=$PUBLIC_KEY_FILE \
  86. --tpm2bPrivate=- --policy=- --force
  87. set ret [wait]
  88. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  89. Command has not failed as expected\n"
  90. exit 1
  91. }
  92. EOF
  93. expect <<EOF
  94. # Try with multiple stdout (3)
  95. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=- \
  96. --tpm2bPrivate=$PRIVATE_KEY_FILE --policy=- --force
  97. set ret [wait]
  98. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  99. Command has not failed as expected\n"
  100. exit 1
  101. }
  102. EOF
  103. expect <<EOF
  104. # Try with multiple stdout (4)
  105. spawn tss2 gettpmblobs --path=$KEY_PATH --tpm2bPublic=- \
  106. --tpm2bPrivate=- --policy=- --force
  107. set ret [wait]
  108. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  109. Command has not failed as expected\n"
  110. exit 1
  111. }
  112. EOF
  113. exit 0