tpmtoken_setpasswd_tests.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #! /bin/sh
  2. #
  3. # Copyright (c) International Business Machines Corp., 2005
  4. #
  5. # This program is free software; you can redistribute it and#or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. # for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. setup()
  20. {
  21. RC=0 # Return code from commands.
  22. if [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ]
  23. then
  24. LTPTMP="/tmp"
  25. else
  26. LTPTMP="$TMPBASE"
  27. fi
  28. export TPM_TMPFILE="$LTPTMP/tst_tpm.err"
  29. rm -f $TPM_TMPFILE 2>&1
  30. # Set known password values
  31. if [ -z "$P11_SO_PWD" ]
  32. then
  33. export P11_SO_PWD="P11 SO PWD"
  34. fi
  35. if [ -z "$NEW_P11_SO_PWD" ]
  36. then
  37. export NEW_P11_SO_PWD="NEW P11 SO PWD"
  38. fi
  39. if [ -z "$P11_USER_PWD" ]
  40. then
  41. export P11_USER_PWD="P11 USER PWD"
  42. fi
  43. if [ -z "$NEW_P11_USER_PWD" ]
  44. then
  45. export NEW_P11_USER_PWD="NEW P11 USER PWD"
  46. fi
  47. tst_resm TINFO "INIT: Inititalizing tests."
  48. which tpmtoken_setpasswd 1>$TPM_TMPFILE 2>&1 || RC=$?
  49. if [ $RC -ne 0 ]
  50. then
  51. tst_brk TBROK $TPM_TMPFILE NULL \
  52. "Setup: tpmtoken_setpasswd command does not exist. Reason:"
  53. return $RC
  54. fi
  55. return $RC
  56. }
  57. test01()
  58. {
  59. RC=0 # Return value from commands
  60. export TCID=tpmtoken_setpasswd01 # Test ID
  61. export TST_COUNT=1 # Test number
  62. tpmtoken_setpasswd_tests_exp01.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
  63. if [ $RC -eq 0 ]
  64. then
  65. tst_resm TPASS "'tpmtoken_setpasswd' passed."
  66. RC=0
  67. else
  68. tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd' failed."
  69. RC=1
  70. fi
  71. return $RC
  72. }
  73. test02()
  74. {
  75. RC=0 # Return value from commands
  76. export TCID=tpmtoken_setpasswd02 # Test ID
  77. export TST_COUNT=2 # Test number
  78. tpmtoken_setpasswd_tests_exp02.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
  79. if [ $RC -eq 0 ]
  80. then
  81. tst_resm TPASS "'tpmtoken_setpasswd --security-officer' passed."
  82. RC=0
  83. else
  84. tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd --security-officer' failed."
  85. RC=1
  86. fi
  87. return $RC
  88. }
  89. test03()
  90. {
  91. RC=0 # Return value from commands
  92. export TCID=tpmtoken_setpasswd03 # Test ID
  93. export TST_COUNT=3 # Test number
  94. tpmtoken_setpasswd_tests_exp03.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
  95. if [ $RC -eq 0 ]
  96. then
  97. tst_resm TPASS "'tpmtoken_setpasswd' passed."
  98. RC=0
  99. else
  100. tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd' failed."
  101. RC=1
  102. fi
  103. return $RC
  104. }
  105. test04()
  106. {
  107. RC=0 # Return value from commands
  108. export TCID=tpmtoken_setpasswd04 # Test ID
  109. export TST_COUNT=4 # Test number
  110. tpmtoken_setpasswd_tests_exp04.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
  111. if [ $RC -eq 0 ]
  112. then
  113. tst_resm TPASS "'tpmtoken_setpasswd --security-officer' passed."
  114. RC=0
  115. else
  116. tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd --security-officer' failed."
  117. RC=1
  118. fi
  119. return $RC
  120. }
  121. cleanup()
  122. {
  123. rm -f $TPM_TMPFILE 2>&1
  124. }
  125. # Function: main
  126. #
  127. # Description: - Execute all tests, report results.
  128. #
  129. # Exit: - zero on success
  130. # - non-zero on failure.
  131. TFAILCNT=0 # Set TFAILCNT to 0, increment on failure.
  132. RC=0 # Return code from tests.
  133. export TCID=tpmtoken_setpasswd # Test ID
  134. export TST_TOTAL=4 # Total numner of tests in this file.
  135. export TST_COUNT=0 # Initialize identifier
  136. if [ -n "$TPM_NOPKCS11" ]
  137. then
  138. tst_resm TINFO "'tpmtoken_setpasswd' skipped."
  139. exit $TFAILCNT
  140. fi
  141. setup || exit $RC # Exit if initializing testcases fails.
  142. test01 || TFAILCNT=$(($TFAILCNT+1))
  143. test02 || TFAILCNT=$(($TFAILCNT+1))
  144. test03 || TFAILCNT=$(($TFAILCNT+1))
  145. test04 || TFAILCNT=$(($TFAILCNT+1))
  146. cleanup
  147. exit $TFAILCNT