fapi-authorize-policy.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/mySignKey
  12. POLICY_SIGN_KEY_PATH=HS/SRK/myPolicySignKey
  13. PCR_POLICY_DATA=$TEMP_DIR/pol_pcr16_0.json
  14. AUTHORIZE_POLICY_DATA=$TEMP_DIR/pol_authorize_ref.json
  15. POLICY_PCR=policy/pcr-policy
  16. POLICY_AUTHORIZE=policy/authorize-policy
  17. POLICY_REF=$TEMP_DIR/policy_ref.file
  18. SIGNATURE_FILE=$TEMP_DIR/signature.file
  19. PUBLIC_KEY_FILE=$TEMP_DIR/public_key.file
  20. DIGEST_FILE=$TEMP_DIR/digest.file
  21. LOG_FILE=$TEMP_DIR/log.file
  22. touch $LOG_FILE
  23. EMPTY_FILE=$TEMP_DIR/empty.file
  24. BIG_FILE=$TEMP_DIR/big_file.file
  25. echo -n 01234567890123456789012345678901 > $DIGEST_FILE
  26. echo 'f0f1f2f3f4f5f6f7f8f9' | xxd -r -p > $POLICY_REF
  27. tss2 provision
  28. tss2 import --path=$POLICY_PCR --importData=$PCR_POLICY_DATA
  29. tss2 import --path=$POLICY_AUTHORIZE --importData=$AUTHORIZE_POLICY_DATA
  30. echo "tss2 import with EMPTY_FILE" # Expected to fail
  31. expect <<EOF
  32. spawn sh -c "tss2 import --path=$POLICY_AUTHORIZE --importData=$EMPTY_FILE 2> $LOG_FILE"
  33. set ret [wait]
  34. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  35. set file [open $LOG_FILE r]
  36. set log [read \$file]
  37. close $file
  38. send_user "[lindex \$log]\n"
  39. exit 1
  40. }
  41. EOF
  42. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  43. echo "Error: AddressSanitizer triggered."
  44. cat $LOG_FILE
  45. exit 1
  46. fi
  47. echo "tss2 import with BIG_FILE" # Expected to fail
  48. expect <<EOF
  49. spawn sh -c "tss2 import --path=$POLICY_AUTHORIZE --importData=$BIG_FILE 2> $LOG_FILE"
  50. set ret [wait]
  51. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  52. set file [open $LOG_FILE r]
  53. set log [read \$file]
  54. close $file
  55. send_user "[lindex \$log]\n"
  56. exit 1
  57. }
  58. EOF
  59. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  60. echo "Error: AddressSanitizer triggered."
  61. cat $LOG_FILE
  62. exit 1
  63. fi
  64. tss2 createkey --path=$POLICY_SIGN_KEY_PATH --type="noDa, sign" --authValue=""
  65. tss2 authorizepolicy --keyPath=$POLICY_SIGN_KEY_PATH --policyPath=$POLICY_PCR \
  66. --policyRef=$POLICY_REF
  67. tss2 createkey --path=$KEY_PATH --type="noDa, sign" \
  68. --policyPath=$POLICY_AUTHORIZE --authValue=""
  69. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  70. tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=$DIGEST_FILE \
  71. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  72. else
  73. tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  74. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  75. fi
  76. echo "tss2 sign with BIG_FILE" # Expected to fail
  77. expect <<EOF
  78. spawn sh -c "tss2 sign --keyPath=$KEY_PATH --padding=RSA_PSS --digest=$BIG_FILE \
  79. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE 2> $LOG_FILE"
  80. set ret [wait]
  81. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  82. set file [open $LOG_FILE r]
  83. set log [read \$file]
  84. close $file
  85. send_user "[lindex \$log]\n"
  86. exit 1
  87. }
  88. EOF
  89. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  90. echo "Error: AddressSanitizer triggered."
  91. cat $LOG_FILE
  92. exit 1
  93. fi
  94. expect <<EOF
  95. # Try with missing policyPath
  96. spawn tss2 authorizepolicy --keyPath=$POLICY_SIGN_KEY_PATH \
  97. --policyRef=$POLICY_REF
  98. set ret [wait]
  99. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  100. Command has not failed as expected\n"
  101. exit 1
  102. }
  103. EOF
  104. expect <<EOF
  105. # Try with missing keyPath
  106. spawn tss2 authorizepolicy \
  107. --policyPath=$POLICY_PCR --policyRef=$POLICY_REF
  108. set ret [wait]
  109. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  110. Command has not failed as expected\n"
  111. exit 1
  112. }
  113. EOF
  114. echo "tss2 authorizepolicy with EMPTY_FILE" # Expected to succeed
  115. tss2 authorizepolicy --keyPath=$POLICY_SIGN_KEY_PATH --policyPath=$POLICY_PCR \
  116. --policyRef=$EMPTY_FILE
  117. echo "tss2 authorizepolicy with BIG_FILE" # Expected to fail
  118. expect <<EOF
  119. spawn sh -c "tss2 authorizepolicy --keyPath=$POLICY_SIGN_KEY_PATH \
  120. --policyPath=$POLICY_PCR --policyRef=$BIG_FILE 2> $LOG_FILE"
  121. set ret [wait]
  122. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  123. set file [open $LOG_FILE r]
  124. set log [read \$file]
  125. close $file
  126. send_user "[lindex \$log]\n"
  127. exit 1
  128. }
  129. EOF
  130. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  131. echo "Error: AddressSanitizer triggered."
  132. cat $LOG_FILE
  133. exit 1
  134. fi
  135. exit 0