fapi-key-change-auth.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. PW1=abc
  12. PW2=def
  13. KEY_PATH=HS/SRK/myRSASign
  14. DIGEST_FILE=$TEMP_DIR/digest.file
  15. SIGNATURE_FILE=$TEMP_DIR/signature.file
  16. PUBLIC_KEY_FILE=$TEMP_DIR/public_key.file
  17. IMPORTED_KEY_NAME=importedPubKey
  18. PADDINGS="RSA_PSS"
  19. set -x
  20. tss2 provision
  21. echo 0123456789012345678 > $DIGEST_FILE
  22. tss2 createkey --path=$KEY_PATH --type="noDa, sign" --authValue=$PW1
  23. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  24. expect <<EOF
  25. # Try interactive prompt
  26. spawn tss2 sign --keyPath=$KEY_PATH --padding=$PADDINGS --digest=$DIGEST_FILE \
  27. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  28. expect "Authorize object: "
  29. send "$PW1\r"
  30. set ret [wait]
  31. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  32. send_user "Using interactive prompt has failed\n"
  33. exit 1
  34. }
  35. EOF
  36. else
  37. expect <<EOF
  38. # Try interactive prompt
  39. spawn tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  40. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  41. expect "Authorize object: "
  42. send "$PW1\r"
  43. set ret [wait]
  44. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  45. send_user "Using interactive prompt has failed\n"
  46. exit 1
  47. }
  48. EOF
  49. fi
  50. expect <<EOF
  51. # Try interactive prompt with 2 different passwords
  52. spawn tss2 changeauth --entityPath=$KEY_PATH
  53. expect "Authorize object Password: "
  54. send "1\r"
  55. expect "Authorize object Retype password: "
  56. send "2\r"
  57. expect {
  58. "Passwords do not match." {
  59. } eof {
  60. send_user "Expected password mismatch, but got nothing, or
  61. rather EOF\n"
  62. exit 1
  63. }
  64. }
  65. set ret [wait]
  66. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  67. send_user "Using interactive prompt with different passwords
  68. has not failed\n"
  69. exit 1
  70. }
  71. EOF
  72. expect <<EOF
  73. # Try interactive prompt
  74. spawn tss2 changeauth --entityPath=$KEY_PATH --authValue=$PW2
  75. expect "Authorize object: "
  76. send "$PW1\r"
  77. set ret [wait]
  78. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  79. send_user "Using interactive prompt has failed\n"
  80. exit 1
  81. }
  82. EOF
  83. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  84. expect <<EOF
  85. # Check if system asks for auth value
  86. spawn tss2 sign --keyPath=$KEY_PATH --padding=$PADDINGS --digest=$DIGEST_FILE \
  87. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE --force
  88. expect {
  89. "Authorize object: " {
  90. } eof {
  91. send_user "The system has not asked for password\n"
  92. exit 1
  93. }
  94. }
  95. send "$PW2\r"
  96. set ret [wait]
  97. if {[lindex \$ret 2] || [lindex \$ret 3]} {
  98. send_user "Passing password has failed\n"
  99. exit 1
  100. }
  101. EOF
  102. else
  103. expect <<EOF
  104. # Check if system asks for auth value
  105. spawn tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  106. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE --force
  107. expect {
  108. "Authorize object: " {
  109. } eof {
  110. send_user "The system has not asked for password\n"
  111. exit 1
  112. }
  113. }
  114. send "$PW2\r"
  115. set ret [wait]
  116. if {[lindex \$ret 2] || [lindex \$ret 3]} {
  117. send_user "Passing password has failed\n"
  118. exit 1
  119. }
  120. EOF
  121. fi
  122. exit 0