fapi-seal-unseal_ecc.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. set -e
  2. source helpers.sh
  3. start_up
  4. CRYPTO_PROFILE="ECC"
  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/sealKey
  12. SEALED_DATA_FILE=$TEMP_DIR/seal-data.file
  13. SEAL_DATA="data to seal"
  14. printf "$SEAL_DATA" > $SEALED_DATA_FILE
  15. UNSEALED_DATA_FILE=$TEMP_DIR/unsealed-data.file
  16. PCR_POLICY_DATA=$TEMP_DIR/pol_pcr16_0.json
  17. POLICY_PCR=policy/pcr-policy
  18. COUNT_FILE=$TEMP_DIR/count.file
  19. EMPTY_FILE=$TEMP_DIR/empty.file
  20. BIG_FILE=$TEMP_DIR/big_file.file
  21. LOG_FILE=$TEMP_DIR/log.file
  22. touch $LOG_FILE
  23. tss2 provision
  24. expect <<EOF
  25. # Try interactive prompt with different passwords
  26. spawn tss2 createseal --path=$KEY_PATH --policyPath=$POLICY_PCR --type="noDa" \
  27. --data=$SEALED_DATA_FILE
  28. expect "Authorize object Password: "
  29. send "1\r"
  30. expect "Authorize object Retype password: "
  31. send "2\r"
  32. set ret [wait]
  33. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  34. send_user "Using interactive prompt with different passwords
  35. has not failed as expected.\n"
  36. exit 1
  37. }
  38. EOF
  39. expect <<EOF
  40. # Try with missing path
  41. spawn tss2 createseal --type="noDa" --data=$SEALED_DATA_FILE --authValue=""
  42. set ret [wait]
  43. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  44. Command has not failed as expected\n"
  45. exit 1
  46. }
  47. EOF
  48. tss2 import --path=$POLICY_PCR --importData=$PCR_POLICY_DATA
  49. echo "tss2 createseal with EMPTY_FILE" # Expected to fail
  50. expect <<EOF
  51. spawn sh -c "tss2 createseal --path=$KEY_PATH --policyPath=$POLICY_PCR \
  52. --type=\"noDa\" --data=$EMPTY_FILE --authValue=\"\" 2> $LOG_FILE"
  53. set ret [wait]
  54. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  55. set file [open $LOG_FILE r]
  56. set log [read \$file]
  57. close $file
  58. send_user "[lindex \$log]\n"
  59. exit 1
  60. }
  61. EOF
  62. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  63. echo "Error: AddressSanitizer triggered."
  64. cat $LOG_FILE
  65. exit 1
  66. fi
  67. echo "tss2 createseal with BIG_FILE" # Expected to fail
  68. expect <<EOF
  69. spawn sh -c "tss2 createseal --path=$KEY_PATH --policyPath=$POLICY_PCR \
  70. --type=\"noDa\" --data=$BIG_FILE --authValue=\"\" 2> $LOG_FILE"
  71. set ret [wait]
  72. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  73. set file [open $LOG_FILE r]
  74. set log [read \$file]
  75. close $file
  76. send_user "[lindex \$log]\n"
  77. exit 1
  78. }
  79. EOF
  80. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  81. echo "Error: AddressSanitizer triggered."
  82. cat $LOG_FILE
  83. exit 1
  84. fi
  85. tss2 createseal --path=$KEY_PATH --policyPath=$POLICY_PCR --type="noDa" \
  86. --data=$SEALED_DATA_FILE --authValue=""
  87. tss2 unseal --path=$KEY_PATH --data=$UNSEALED_DATA_FILE --force
  88. if [ "`xxd $UNSEALED_DATA_FILE`" != "`xxd $SEALED_DATA_FILE`" ]; then
  89. echo "Seal/Unseal failed"
  90. exit 1
  91. fi
  92. tss2 delete --path=$KEY_PATH
  93. printf "$SEAL_DATA" | tss2 createseal --path=$KEY_PATH --policyPath=$POLICY_PCR --type="noDa" \
  94. --data=- --authValue=""
  95. UNSEALED_DATA=$(tss2 unseal --path=$KEY_PATH --data=- | xxd)
  96. V1=$(printf "$SEAL_DATA" | xxd)
  97. V2=$UNSEALED_DATA
  98. if [ "$V1" != "$V2" ]; then
  99. echo "Seal/Unseal failed"
  100. exit 1
  101. fi
  102. expect <<EOF
  103. # Try with missing path
  104. spawn tss2 unseal --data=$UNSEALED_DATA_FILE --force
  105. set ret [wait]
  106. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  107. Command has not failed as expected\n"
  108. exit 1
  109. }
  110. EOF
  111. # Unseal with password
  112. tss2 delete --path=$KEY_PATH
  113. tss2 createseal --path=$KEY_PATH --data=$SEALED_DATA_FILE --authValue="abc"
  114. printf "" > $UNSEALED_DATA_FILE
  115. expect <<EOF
  116. spawn tss2 unseal --path=$KEY_PATH --data=$UNSEALED_DATA_FILE --force
  117. expect "Authorize object : "
  118. send "abc\r"
  119. set ret [wait]
  120. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  121. send_user "Authorization failed\n"
  122. exit 1
  123. }
  124. EOF
  125. V1=$(printf "$SEAL_DATA" | xxd)
  126. V2=$"`xxd $UNSEALED_DATA_FILE`"
  127. if [ "$V1" != "$V2" ]; then
  128. echo "Seal/Unseal failed"
  129. exit 1
  130. fi
  131. # Try with missing type
  132. tss2 delete --path=$KEY_PATH
  133. tss2 createseal --path $KEY_PATH --data=$SEALED_DATA_FILE --authValue=""
  134. # Try with missing data
  135. tss2 unseal --path=$KEY_PATH --force
  136. # Try with size parameter
  137. tss2 delete --path $KEY_PATH
  138. expect <<EOF
  139. # Try with size and data
  140. spawn tss2 createseal --path $KEY_PATH --data $UNSEALED_DATA_FILE --size 6 --authValue ""
  141. set ret [wait]
  142. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  143. Command has not failed as expected\n"
  144. exit 1
  145. }
  146. EOF
  147. expect <<EOF
  148. # Try with wrong size
  149. spawn tss2 createseal --path $KEY_PATH --size abc --authValue ""
  150. set ret [wait]
  151. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  152. Command has not failed as expected\n"
  153. exit 1
  154. }
  155. EOF
  156. expect <<EOF
  157. # Try with wrong size
  158. spawn tss2 createseal --path $KEY_PATH --size 4294967296 --authValue ""
  159. set ret [wait]
  160. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  161. Command has not failed as expected\n"
  162. exit 1
  163. }
  164. EOF
  165. tss2 createseal --path $KEY_PATH --size 15 --authValue ""
  166. tss2 unseal --path $KEY_PATH --data $UNSEALED_DATA_FILE --force
  167. wc -c $UNSEALED_DATA_FILE | awk '{print $1}'> $COUNT_FILE
  168. if [ "$(< $COUNT_FILE)" != "15" ]; then
  169. echo "Wrong size"
  170. exit 99
  171. fi
  172. printf "" > $SEALED_DATA_FILE
  173. expect <<EOF
  174. # Try with empty seal file
  175. spawn tss2 createseal --path $KEY_PATH --data $SEALED_DATA_FILE --authValue ""
  176. set ret [wait]
  177. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  178. Command has not failed as expected\n"
  179. exit 1
  180. }
  181. EOF
  182. exit 0