fapi-export-key_ecc.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/myRSADecrypt"
  12. KEY_PATH_PARENT="HS/SRK/myParent"
  13. JSON_POLICY=$TEMP_DIR/pol_duplicate.json
  14. DUPLICATE_POLICY=policy/duplicate-policy
  15. EXPORTED_KEY=$TEMP_DIR/exportedKey
  16. EXPORTED_PARENT_KEY=$TEMP_DIR/exportedParentKey
  17. LOADED_KEY="myNewParent"
  18. tss2 provision
  19. tss2 import --path=$DUPLICATE_POLICY --importData=$JSON_POLICY
  20. expect <<EOF
  21. # Try with missing path
  22. spawn tss2 import --importData=$JSON_POLICY
  23. set ret [wait]
  24. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  25. Command has not failed as expected\n"
  26. exit 1
  27. }
  28. EOF
  29. expect <<EOF
  30. # Try with missing importData
  31. spawn tss2 import --path=$DUPLICATE_POLICY
  32. set ret [wait]
  33. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  34. Command has not failed as expected\n"
  35. exit 1
  36. }
  37. EOF
  38. tss2 createkey --path=$KEY_PATH_PARENT --type="restricted, decrypt, noDA" \
  39. --authValue=""
  40. tss2 exportkey --pathOfKeyToDuplicate=$KEY_PATH_PARENT \
  41. --exportedData=$EXPORTED_PARENT_KEY --force
  42. tss2 import --path="ext/$LOADED_KEY" --importData=$EXPORTED_PARENT_KEY
  43. tss2 createkey --path=$KEY_PATH --type="noDa, exportable, decrypt" \
  44. --policyPath=$DUPLICATE_POLICY --authValue=""
  45. tss2 exportkey --pathOfKeyToDuplicate=$KEY_PATH \
  46. --pathToPublicKeyOfNewParent="ext/$LOADED_KEY" --exportedData=$EXPORTED_KEY
  47. expect <<EOF
  48. # Try with missing exportedData
  49. spawn tss2 exportkey --pathOfKeyToDuplicate=$KEY_PATH \
  50. --pathToPublicKeyOfNewParent="ext/$LOADED_KEY"
  51. set ret [wait]
  52. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  53. Command has not failed as expected\n"
  54. exit 1
  55. }
  56. EOF
  57. expect <<EOF
  58. # Try with missing pathOfKeyToDuplicate
  59. spawn tss2 exportkey --pathToPublicKeyOfNewParent="ext/$LOADED_KEY" \
  60. --exportedData=$EXPORTED_KEY
  61. set ret [wait]
  62. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  63. Command has not failed as expected\n"
  64. exit 1
  65. }
  66. EOF
  67. expect <<EOF
  68. # Try to fail command
  69. spawn tss2 exportkey --pathOfKeyToDuplicate=$KEY_PATH \
  70. --pathToPublicKeyOfNewParent="ext/$LOADED_KEY" --exportedData=
  71. set ret [wait]
  72. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  73. Command has not failed as expected\n"
  74. exit 1
  75. }
  76. EOF
  77. expect <<EOF
  78. # Try to fail writing to output
  79. spawn tss2 exportkey --pathOfKeyToDuplicate=$KEY_PATH \
  80. --pathToPublicKeyOfNewParent="ext/$LOADED_KEY" --exportedData=$EXPORTED_KEY
  81. set ret [wait]
  82. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  83. Command has not failed as expected\n"
  84. exit 1
  85. }
  86. EOF
  87. exit 0