fapi-sign-verify_ecc.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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/myRSASign
  12. DIGEST_FILE=$TEMP_DIR/digest.file
  13. SIGNATURE_FILE=$TEMP_DIR/signature.file
  14. PUBLIC_KEY_FILE=$TEMP_DIR/public_key.file
  15. IMPORTED_KEY_NAME="importedPubKey"
  16. PUB_KEY_DIR="ext"
  17. EMPTY_FILE=$TEMP_DIR/empty.file
  18. BIG_FILE=$TEMP_DIR/big_file.file
  19. LOG_FILE=$TEMP_DIR/log.file
  20. touch $LOG_FILE
  21. tss2 provision
  22. echo -n "01234567890123456789" > $DIGEST_FILE
  23. tss2 createkey --path=$KEY_PATH --type="noDa, sign" --authValue=""
  24. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  25. echo -n `cat $DIGEST_FILE` | tss2 sign --digest=- --keyPath=$KEY_PATH \
  26. --padding="RSA_PSS" --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  27. else
  28. echo -n `cat $DIGEST_FILE` | tss2 sign --digest=- --keyPath=$KEY_PATH \
  29. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  30. fi
  31. tss2 import --path=$IMPORTED_KEY_NAME --importData=$PUBLIC_KEY_FILE
  32. tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  33. --digest=$DIGEST_FILE --signature=$SIGNATURE_FILE
  34. echo "tss2 verifysignature with EMPTY_FILE digest" # Expected to fail
  35. expect <<EOF
  36. spawn sh -c "tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  37. --digest=$EMPTY_FILE --signature=$SIGNATURE_FILE 2> $LOG_FILE"
  38. set ret [wait]
  39. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  40. set file [open $LOG_FILE r]
  41. set log [read \$file]
  42. close $file
  43. send_user "[lindex \$log]\n"
  44. exit 1
  45. }
  46. EOF
  47. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  48. echo "Error: AddressSanitizer triggered."
  49. cat $LOG_FILE
  50. exit 1
  51. fi
  52. echo "tss2 verifysignature with BIG_FILE digest" # Expected to fail
  53. expect <<EOF
  54. spawn sh -c "tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  55. --digest=$BIG_FILE --signature=$SIGNATURE_FILE 2> $LOG_FILE"
  56. set ret [wait]
  57. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  58. set file [open $LOG_FILE r]
  59. set log [read \$file]
  60. close $file
  61. send_user "[lindex \$log]\n"
  62. exit 1
  63. }
  64. EOF
  65. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  66. echo "Error: AddressSanitizer triggered."
  67. cat $LOG_FILE
  68. exit 1
  69. fi
  70. echo "tss2 verifysignature with EMPTY_FILE signature" # Expected to fail
  71. expect <<EOF
  72. spawn sh -c "tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  73. --digest=$DIGEST_FILE --signature=$EMPTY_FILE 2> $LOG_FILE"
  74. set ret [wait]
  75. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  76. set file [open $LOG_FILE r]
  77. set log [read \$file]
  78. close $file
  79. send_user "[lindex \$log]\n"
  80. exit 1
  81. }
  82. EOF
  83. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  84. echo "Error: AddressSanitizer triggered."
  85. cat $LOG_FILE
  86. exit 1
  87. fi
  88. echo "tss2 verifysignature with BIG_FILE signature" # Expected to fail
  89. expect <<EOF
  90. spawn sh -c "tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  91. --digest=$DIGEST_FILE --signature=$BIG_FILE 2> $LOG_FILE"
  92. set ret [wait]
  93. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  94. set file [open $LOG_FILE r]
  95. set log [read \$file]
  96. close $file
  97. send_user "[lindex \$log]\n"
  98. exit 1
  99. }
  100. EOF
  101. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  102. echo "Error: AddressSanitizer triggered."
  103. cat $LOG_FILE
  104. exit 1
  105. fi
  106. # Try without certificate
  107. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  108. tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=$DIGEST_FILE \
  109. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE --force
  110. else
  111. tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  112. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE --force
  113. fi
  114. # Try without public key
  115. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  116. tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=$DIGEST_FILE \
  117. --signature=$SIGNATURE_FILE --force
  118. else
  119. tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  120. --signature=$SIGNATURE_FILE --force
  121. fi
  122. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  123. expect <<EOF
  124. # Try with missing keyPath
  125. spawn tss2 sign --padding="RSA_PSS" --digest=$DIGEST_FILE \
  126. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  127. set ret [wait]
  128. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  129. Command has not failed as expected\n"
  130. exit 1
  131. }
  132. EOF
  133. else
  134. expect <<EOF
  135. # Try with missing keyPath
  136. spawn tss2 sign --digest=$DIGEST_FILE \
  137. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  138. set ret [wait]
  139. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  140. Command has not failed as expected\n"
  141. exit 1
  142. }
  143. EOF
  144. fi
  145. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  146. expect <<EOF
  147. # Try with missing digest
  148. spawn tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" \
  149. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  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. else
  157. expect <<EOF
  158. # Try with missing digest
  159. spawn tss2 sign --keyPath=$KEY_PATH \
  160. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  161. set ret [wait]
  162. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  163. Command has not failed as expected\n"
  164. exit 1
  165. }
  166. EOF
  167. fi
  168. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  169. expect <<EOF
  170. # Try with missing signature
  171. spawn tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=$DIGEST_FILE \
  172. --publicKey=$PUBLIC_KEY_FILE
  173. set ret [wait]
  174. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  175. Command has not failed as expected\n"
  176. exit 1
  177. }
  178. EOF
  179. else
  180. expect <<EOF
  181. # Try with missing signature
  182. spawn tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  183. --publicKey=$PUBLIC_KEY_FILE
  184. set ret [wait]
  185. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  186. Command has not failed as expected\n"
  187. exit 1
  188. }
  189. EOF
  190. fi
  191. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  192. expect <<EOF
  193. # Try with multiple stdins with publicKey and with certificate
  194. spawn tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=$DIGEST_FILE \
  195. --signature=- --publicKey=- --certificate -
  196. set ret [wait]
  197. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  198. Command has not failed as expected\n"
  199. exit 1
  200. }
  201. EOF
  202. else
  203. expect <<EOF
  204. # Try with multiple stdins with publicKey and with certificate
  205. spawn tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  206. --signature=- --publicKey=- --certificate -
  207. set ret [wait]
  208. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  209. Command has not failed as expected\n"
  210. exit 1
  211. }
  212. EOF
  213. fi
  214. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  215. expect <<EOF
  216. # Try with multiple stdins without publicKey and with certificate
  217. spawn tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=$DIGEST_FILE \
  218. --signature=- --certificate=-
  219. set ret [wait]
  220. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  221. Command has not failed as expected\n"
  222. exit 1
  223. }
  224. EOF
  225. else
  226. expect <<EOF
  227. # Try with multiple stdins without publicKey and with certificate
  228. spawn tss2 sign --keyPath=$KEY_PATH --digest=$DIGEST_FILE \
  229. --signature=- --certificate=-
  230. set ret [wait]
  231. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  232. Command has not failed as expected\n"
  233. exit 1
  234. }
  235. EOF
  236. fi
  237. if [ "$CRYPTO_PROFILE" = "RSA" ]; then
  238. expect <<EOF
  239. # Try with missing digest file
  240. spawn tss2 sign --keyPath=$KEY_PATH --padding="RSA_PSS" --digest=abc \
  241. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  242. set ret [wait]
  243. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  244. Command has not failed as expected\n"
  245. exit 1
  246. }
  247. EOF
  248. else
  249. expect <<EOF
  250. # Try with missing digest file
  251. spawn tss2 sign --keyPath=$KEY_PATH --digest=abc \
  252. --signature=$SIGNATURE_FILE --publicKey=$PUBLIC_KEY_FILE
  253. set ret [wait]
  254. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  255. Command has not failed as expected\n"
  256. exit 1
  257. }
  258. EOF
  259. fi
  260. expect <<EOF
  261. # Try with missing keyPath
  262. spawn tss2 verifysignature \
  263. --digest=$DIGEST_FILE --signature=$SIGNATURE_FILE
  264. set ret [wait]
  265. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  266. Command has not failed as expected\n"
  267. exit 1
  268. }
  269. EOF
  270. expect <<EOF
  271. # Try with missing digest
  272. spawn tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  273. --signature=$SIGNATURE_FILE
  274. set ret [wait]
  275. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  276. Command has not failed as expected\n"
  277. exit 1
  278. }
  279. EOF
  280. expect <<EOF
  281. # Try with missing signature
  282. spawn tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  283. --digest=$DIGEST_FILE
  284. set ret [wait]
  285. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  286. Command has not failed as expected\n"
  287. exit 1
  288. }
  289. EOF
  290. expect <<EOF
  291. # Try with multiple stdins
  292. spawn tss2 verifysignature --keyPath=$PUB_KEY_DIR/$IMPORTED_KEY_NAME \
  293. --digest=- --signature=-
  294. set ret [wait]
  295. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  296. Command has not failed as expected\n"
  297. exit 1
  298. }
  299. EOF
  300. exit 0