Home | History | Annotate | Download | only in testscripts
      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 
     20 # test_tpm_tools.sh - Run the tpm-tools test suite.
     21 
     22 # Must be root to run the testsuite
     23 #if [ $UID != 0 ]
     24 #then
     25 #	echo "FAILED: Must be root to execute this script"
     26 #	exit 1
     27 #fi
     28 
     29 # Set the LTPROOT directory
     30 cd `dirname $0`
     31 export LTPROOT=${PWD}
     32 echo $LTPROOT | grep testscripts > /dev/null 2>&1
     33 if [ $? -eq 0 ]
     34 then
     35 	cd ..
     36 	export LTPROOT=${PWD}
     37 fi
     38 
     39 # Set the PATH to include testcase/bin
     40 # and the sbin directories
     41 export LTPBIN=$LTPROOT/testcases/bin
     42 export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:$LTPBIN
     43 
     44 # We will store the logfiles in $LTPROOT/results, so make sure
     45 # it exists.
     46 if [ ! -d $LTPROOT/results ]
     47 then
     48 	mkdir $LTPROOT/results
     49 fi
     50 
     51 # Check for programs/daemons/groups...
     52 USER="`whoami`"
     53 RC=0
     54 if [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ]
     55 then
     56 	LTPTMP="/tmp"
     57 else
     58 	LTPTMP="$TMPBASE"
     59 fi
     60 export TPM_TMPFILE="$LTPTMP/tst_tpm.err"
     61 rm -f $TPM_TMPFILE 1>/dev/null 2>&1
     62 
     63 # Check for the expect command
     64 rm -f $TPM_TMPFILE 1>/dev/null 2>&1
     65 which expect 1>$TPM_TMPFILE 2>&1
     66 if [ $? -ne 0 ]
     67 then
     68 	echo "The 'expect' command is not available.  Be sure the expect package has been installed properly"
     69 	RC=1
     70 fi
     71 
     72 # Check for TrouSerS and that it is running
     73 rm -f $TPM_TMPFILE 1>/dev/null 2>&1
     74 which tcsd 1>$TPM_TMPFILE 2>&1
     75 if [ $? -ne 0 ]
     76 then
     77 	echo "The trousers TSS stack is not available.  Be sure trousers has been installed properly"
     78 	if [ -f $TPM_TMPFILE ]
     79 	then
     80 		cat $TPM_TMPFILE
     81 	fi
     82 	RC=1
     83 else
     84 	rm -f $TPM_TMPFILE 1>/dev/null 2>&1
     85 	ps -ef 1>$TPM_TMPFILE
     86 	grep tcsd $TPM_TMPFILE 1>/dev/null
     87 	if [ $? -ne 0 ]
     88 	then
     89 		echo "The trousers TSS stack is not running.  Be sure to start the trousers daemon (tcsd)"
     90 		RC=1
     91 	fi
     92 fi
     93 
     94 # Make the opencryptoki testing optional
     95 if [ -z "$TPM_NOPKCS11" ]
     96 then
     97 
     98 	# Check for the pkcs11 group and that the user is a member of it
     99 	grep -q ^pkcs11: /etc/group
    100 	if [ $? -ne 0 ]
    101 	then
    102 		echo "The 'pkcs11' group does not exist.  Be sure openCryptoki has been installed properly"
    103 		RC=1
    104 	fi
    105 
    106 	groups | grep pkcs11 1>/dev/null 2>&1
    107 	if [ $? -ne 0 ]
    108 	then
    109 		echo "User '$USER' is not a member of the 'pkcs11' group"
    110 		RC=1
    111 	fi
    112 
    113 	# Check for openCryptoki and that it is running
    114 	#   Additionally, delete the user's TPM token data store.
    115 	rm -f $TPM_TMPFILE 1>/dev/null 2>&1
    116 	which pkcsslotd 1>$TPM_TMPFILE 2>&1
    117 	if [ $? -ne 0 ]
    118 	then
    119 		echo "The openCryptoki PKCS#11 slot daemon is not available.  Be sure openCryptoki has been installed properly"
    120 		if [ -f $TPM_TMPFILE ]
    121 		then
    122 			cat $TPM_TMPFILE
    123 		fi
    124 		RC=1
    125 	else
    126 		rm -f $TPM_TMPFILE 1>/dev/null 2>&1
    127 		ps -ef 1>$TPM_TMPFILE
    128 		grep pkcsslotd $TPM_TMPFILE 1>/dev/null
    129 		if [ $? -ne 0 ]
    130 		then
    131 			echo "The openCryptoki PKCS#11 slot daemon is not running.  Be sure to start the openCryptoki slot daemon (pkcsslotd)"
    132 			RC=1
    133 		else
    134 			P11DIR=`which pkcsslotd | sed s-/sbin/pkcsslotd--`
    135 			if [ "$P11DIR" = "/usr" ]
    136 			then
    137 				P11DIR=""
    138 			fi
    139 
    140 			grep libpkcs11_tpm $P11DIR/var/lib/opencryptoki/pk_config_data 1>/dev/null
    141 			if [ $? -ne 0 ]
    142 			then
    143 				echo "The TPM PKCS#11 token is not active.  Be sure openCryptoki has been installed properly"
    144 				RC=1
    145 			fi
    146 			if [ -d $P11DIR/var/lib/opencryptoki/tpm/$USER ]
    147 			then
    148 				rm -rf $P11DIR/var/lib/opencryptoki/tpm/$USER
    149 			fi
    150 		fi
    151 	fi
    152 fi
    153 
    154 if [ $RC -ne 0 ]
    155 then
    156 	exit 1
    157 fi
    158 
    159 # Set known password values
    160 export OWN_PWD="OWN PWD"
    161 export NEW_OWN_PWD="NEW OWN PWD"
    162 export SRK_PWD="SRK PWD"
    163 export NEW_SRK_PWD="NEW SRK PWD"
    164 export P11_SO_PWD="P11 SO PWD"
    165 export NEW_P11_SO_PWD="NEW P11 SO PWD"
    166 export P11_USER_PWD="P11 USER PWD"
    167 export NEW_P11_USER_PWD="NEW P11 USER PWD"
    168 
    169 echo "Running the tpm-tools testsuite..."
    170 $LTPROOT/bin/ltp-pan -d 5 -S -a $LTPROOT/results/tpm_tools -n ltp-tpm-tools -l $LTPROOT/results/tpm_tools.logfile -o $LTPROOT/results/tpm_tools.outfile -p -f $LTPROOT/runtest/tpm_tools
    171 
    172 echo "Done."
    173 exit 0
    174