1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 2*49cdfc7eSAndroid Build Coastguard Worker# 3*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) International Business Machines Corp., 2005 4*49cdfc7eSAndroid Build Coastguard Worker# 5*49cdfc7eSAndroid Build Coastguard Worker# This program is free software; you can redistribute it and#or modify 6*49cdfc7eSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by 7*49cdfc7eSAndroid Build Coastguard Worker# the Free Software Foundation; either version 2 of the License, or 8*49cdfc7eSAndroid Build Coastguard Worker# (at your option) any later version. 9*49cdfc7eSAndroid Build Coastguard Worker# 10*49cdfc7eSAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful, but 11*49cdfc7eSAndroid Build Coastguard Worker# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12*49cdfc7eSAndroid Build Coastguard Worker# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13*49cdfc7eSAndroid Build Coastguard Worker# for more details. 14*49cdfc7eSAndroid Build Coastguard Worker# 15*49cdfc7eSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License 16*49cdfc7eSAndroid Build Coastguard Worker# along with this program; if not, write to the Free Software 17*49cdfc7eSAndroid Build Coastguard Worker# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18*49cdfc7eSAndroid Build Coastguard Worker# 19*49cdfc7eSAndroid Build Coastguard Worker 20*49cdfc7eSAndroid Build Coastguard Worker# test_tpm_tools.sh - Run the tpm-tools test suite. 21*49cdfc7eSAndroid Build Coastguard Worker 22*49cdfc7eSAndroid Build Coastguard Worker# Must be root to run the testsuite 23*49cdfc7eSAndroid Build Coastguard Worker#if [ $UID != 0 ] 24*49cdfc7eSAndroid Build Coastguard Worker#then 25*49cdfc7eSAndroid Build Coastguard Worker# echo "FAILED: Must be root to execute this script" 26*49cdfc7eSAndroid Build Coastguard Worker# exit 1 27*49cdfc7eSAndroid Build Coastguard Worker#fi 28*49cdfc7eSAndroid Build Coastguard Worker 29*49cdfc7eSAndroid Build Coastguard Worker# Set the LTPROOT directory 30*49cdfc7eSAndroid Build Coastguard Workercd `dirname $0` 31*49cdfc7eSAndroid Build Coastguard Workerexport LTPROOT=${PWD} 32*49cdfc7eSAndroid Build Coastguard Workerecho $LTPROOT | grep testscripts > /dev/null 2>&1 33*49cdfc7eSAndroid Build Coastguard Workerif [ $? -eq 0 ] 34*49cdfc7eSAndroid Build Coastguard Workerthen 35*49cdfc7eSAndroid Build Coastguard Worker cd .. 36*49cdfc7eSAndroid Build Coastguard Worker export LTPROOT=${PWD} 37*49cdfc7eSAndroid Build Coastguard Workerfi 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard Worker# Set the PATH to include testcase/bin 40*49cdfc7eSAndroid Build Coastguard Worker# and the sbin directories 41*49cdfc7eSAndroid Build Coastguard Workerexport LTPBIN=$LTPROOT/testcases/bin 42*49cdfc7eSAndroid Build Coastguard Workerexport PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:$LTPBIN 43*49cdfc7eSAndroid Build Coastguard Worker 44*49cdfc7eSAndroid Build Coastguard Worker# We will store the logfiles in $LTPROOT/results, so make sure 45*49cdfc7eSAndroid Build Coastguard Worker# it exists. 46*49cdfc7eSAndroid Build Coastguard Workerif [ ! -d $LTPROOT/results ] 47*49cdfc7eSAndroid Build Coastguard Workerthen 48*49cdfc7eSAndroid Build Coastguard Worker mkdir $LTPROOT/results 49*49cdfc7eSAndroid Build Coastguard Workerfi 50*49cdfc7eSAndroid Build Coastguard Worker 51*49cdfc7eSAndroid Build Coastguard Worker# Check for programs/daemons/groups... 52*49cdfc7eSAndroid Build Coastguard WorkerUSER="`whoami`" 53*49cdfc7eSAndroid Build Coastguard WorkerRC=0 54*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ] 55*49cdfc7eSAndroid Build Coastguard Workerthen 56*49cdfc7eSAndroid Build Coastguard Worker LTPTMP="/tmp" 57*49cdfc7eSAndroid Build Coastguard Workerelse 58*49cdfc7eSAndroid Build Coastguard Worker LTPTMP="$TMPBASE" 59*49cdfc7eSAndroid Build Coastguard Workerfi 60*49cdfc7eSAndroid Build Coastguard Workerexport TPM_TMPFILE="$LTPTMP/tst_tpm.err" 61*49cdfc7eSAndroid Build Coastguard Workerrm -f $TPM_TMPFILE 1>/dev/null 2>&1 62*49cdfc7eSAndroid Build Coastguard Worker 63*49cdfc7eSAndroid Build Coastguard Worker# Check for the expect command 64*49cdfc7eSAndroid Build Coastguard Workerrm -f $TPM_TMPFILE 1>/dev/null 2>&1 65*49cdfc7eSAndroid Build Coastguard Workerwhich expect 1>$TPM_TMPFILE 2>&1 66*49cdfc7eSAndroid Build Coastguard Workerif [ $? -ne 0 ] 67*49cdfc7eSAndroid Build Coastguard Workerthen 68*49cdfc7eSAndroid Build Coastguard Worker echo "The 'expect' command is not available. Be sure the expect package has been installed properly" 69*49cdfc7eSAndroid Build Coastguard Worker RC=1 70*49cdfc7eSAndroid Build Coastguard Workerfi 71*49cdfc7eSAndroid Build Coastguard Worker 72*49cdfc7eSAndroid Build Coastguard Worker# Check for TrouSerS and that it is running 73*49cdfc7eSAndroid Build Coastguard Workerrm -f $TPM_TMPFILE 1>/dev/null 2>&1 74*49cdfc7eSAndroid Build Coastguard Workerwhich tcsd 1>$TPM_TMPFILE 2>&1 75*49cdfc7eSAndroid Build Coastguard Workerif [ $? -ne 0 ] 76*49cdfc7eSAndroid Build Coastguard Workerthen 77*49cdfc7eSAndroid Build Coastguard Worker echo "The trousers TSS stack is not available. Be sure trousers has been installed properly" 78*49cdfc7eSAndroid Build Coastguard Worker if [ -f $TPM_TMPFILE ] 79*49cdfc7eSAndroid Build Coastguard Worker then 80*49cdfc7eSAndroid Build Coastguard Worker cat $TPM_TMPFILE 81*49cdfc7eSAndroid Build Coastguard Worker fi 82*49cdfc7eSAndroid Build Coastguard Worker RC=1 83*49cdfc7eSAndroid Build Coastguard Workerelse 84*49cdfc7eSAndroid Build Coastguard Worker rm -f $TPM_TMPFILE 1>/dev/null 2>&1 85*49cdfc7eSAndroid Build Coastguard Worker ps -ef 1>$TPM_TMPFILE 86*49cdfc7eSAndroid Build Coastguard Worker grep tcsd $TPM_TMPFILE 1>/dev/null 87*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 88*49cdfc7eSAndroid Build Coastguard Worker then 89*49cdfc7eSAndroid Build Coastguard Worker echo "The trousers TSS stack is not running. Be sure to start the trousers daemon (tcsd)" 90*49cdfc7eSAndroid Build Coastguard Worker RC=1 91*49cdfc7eSAndroid Build Coastguard Worker fi 92*49cdfc7eSAndroid Build Coastguard Workerfi 93*49cdfc7eSAndroid Build Coastguard Worker 94*49cdfc7eSAndroid Build Coastguard Worker# Make the opencryptoki testing optional 95*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$TPM_NOPKCS11" ] 96*49cdfc7eSAndroid Build Coastguard Workerthen 97*49cdfc7eSAndroid Build Coastguard Worker 98*49cdfc7eSAndroid Build Coastguard Worker # Check for the pkcs11 group and that the user is a member of it 99*49cdfc7eSAndroid Build Coastguard Worker grep -q ^pkcs11: /etc/group 100*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 101*49cdfc7eSAndroid Build Coastguard Worker then 102*49cdfc7eSAndroid Build Coastguard Worker echo "The 'pkcs11' group does not exist. Be sure openCryptoki has been installed properly" 103*49cdfc7eSAndroid Build Coastguard Worker RC=1 104*49cdfc7eSAndroid Build Coastguard Worker fi 105*49cdfc7eSAndroid Build Coastguard Worker 106*49cdfc7eSAndroid Build Coastguard Worker groups | grep pkcs11 1>/dev/null 2>&1 107*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 108*49cdfc7eSAndroid Build Coastguard Worker then 109*49cdfc7eSAndroid Build Coastguard Worker echo "User '$USER' is not a member of the 'pkcs11' group" 110*49cdfc7eSAndroid Build Coastguard Worker RC=1 111*49cdfc7eSAndroid Build Coastguard Worker fi 112*49cdfc7eSAndroid Build Coastguard Worker 113*49cdfc7eSAndroid Build Coastguard Worker # Check for openCryptoki and that it is running 114*49cdfc7eSAndroid Build Coastguard Worker # Additionally, delete the user's TPM token data store. 115*49cdfc7eSAndroid Build Coastguard Worker rm -f $TPM_TMPFILE 1>/dev/null 2>&1 116*49cdfc7eSAndroid Build Coastguard Worker which pkcsslotd 1>$TPM_TMPFILE 2>&1 117*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 118*49cdfc7eSAndroid Build Coastguard Worker then 119*49cdfc7eSAndroid Build Coastguard Worker echo "The openCryptoki PKCS#11 slot daemon is not available. Be sure openCryptoki has been installed properly" 120*49cdfc7eSAndroid Build Coastguard Worker if [ -f $TPM_TMPFILE ] 121*49cdfc7eSAndroid Build Coastguard Worker then 122*49cdfc7eSAndroid Build Coastguard Worker cat $TPM_TMPFILE 123*49cdfc7eSAndroid Build Coastguard Worker fi 124*49cdfc7eSAndroid Build Coastguard Worker RC=1 125*49cdfc7eSAndroid Build Coastguard Worker else 126*49cdfc7eSAndroid Build Coastguard Worker rm -f $TPM_TMPFILE 1>/dev/null 2>&1 127*49cdfc7eSAndroid Build Coastguard Worker ps -ef 1>$TPM_TMPFILE 128*49cdfc7eSAndroid Build Coastguard Worker grep pkcsslotd $TPM_TMPFILE 1>/dev/null 129*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 130*49cdfc7eSAndroid Build Coastguard Worker then 131*49cdfc7eSAndroid Build Coastguard Worker echo "The openCryptoki PKCS#11 slot daemon is not running. Be sure to start the openCryptoki slot daemon (pkcsslotd)" 132*49cdfc7eSAndroid Build Coastguard Worker RC=1 133*49cdfc7eSAndroid Build Coastguard Worker else 134*49cdfc7eSAndroid Build Coastguard Worker P11DIR=`which pkcsslotd | sed s-/sbin/pkcsslotd--` 135*49cdfc7eSAndroid Build Coastguard Worker if [ "$P11DIR" = "/usr" ] 136*49cdfc7eSAndroid Build Coastguard Worker then 137*49cdfc7eSAndroid Build Coastguard Worker P11DIR="" 138*49cdfc7eSAndroid Build Coastguard Worker fi 139*49cdfc7eSAndroid Build Coastguard Worker 140*49cdfc7eSAndroid Build Coastguard Worker grep libpkcs11_tpm $P11DIR/var/lib/opencryptoki/pk_config_data 1>/dev/null 141*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 142*49cdfc7eSAndroid Build Coastguard Worker then 143*49cdfc7eSAndroid Build Coastguard Worker echo "The TPM PKCS#11 token is not active. Be sure openCryptoki has been installed properly" 144*49cdfc7eSAndroid Build Coastguard Worker RC=1 145*49cdfc7eSAndroid Build Coastguard Worker fi 146*49cdfc7eSAndroid Build Coastguard Worker if [ -d $P11DIR/var/lib/opencryptoki/tpm/$USER ] 147*49cdfc7eSAndroid Build Coastguard Worker then 148*49cdfc7eSAndroid Build Coastguard Worker rm -rf $P11DIR/var/lib/opencryptoki/tpm/$USER 149*49cdfc7eSAndroid Build Coastguard Worker fi 150*49cdfc7eSAndroid Build Coastguard Worker fi 151*49cdfc7eSAndroid Build Coastguard Worker fi 152*49cdfc7eSAndroid Build Coastguard Workerfi 153*49cdfc7eSAndroid Build Coastguard Worker 154*49cdfc7eSAndroid Build Coastguard Workerif [ $RC -ne 0 ] 155*49cdfc7eSAndroid Build Coastguard Workerthen 156*49cdfc7eSAndroid Build Coastguard Worker exit 1 157*49cdfc7eSAndroid Build Coastguard Workerfi 158*49cdfc7eSAndroid Build Coastguard Worker 159*49cdfc7eSAndroid Build Coastguard Worker# Set known password values 160*49cdfc7eSAndroid Build Coastguard Workerexport OWN_PWD="OWN PWD" 161*49cdfc7eSAndroid Build Coastguard Workerexport NEW_OWN_PWD="NEW OWN PWD" 162*49cdfc7eSAndroid Build Coastguard Workerexport SRK_PWD="SRK PWD" 163*49cdfc7eSAndroid Build Coastguard Workerexport NEW_SRK_PWD="NEW SRK PWD" 164*49cdfc7eSAndroid Build Coastguard Workerexport P11_SO_PWD="P11 SO PWD" 165*49cdfc7eSAndroid Build Coastguard Workerexport NEW_P11_SO_PWD="NEW P11 SO PWD" 166*49cdfc7eSAndroid Build Coastguard Workerexport P11_USER_PWD="P11 USER PWD" 167*49cdfc7eSAndroid Build Coastguard Workerexport NEW_P11_USER_PWD="NEW P11 USER PWD" 168*49cdfc7eSAndroid Build Coastguard Worker 169*49cdfc7eSAndroid Build Coastguard Workerecho "Running the tpm-tools testsuite..." 170*49cdfc7eSAndroid Build Coastguard Worker$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*49cdfc7eSAndroid Build Coastguard Worker 172*49cdfc7eSAndroid Build Coastguard Workerecho "Done." 173*49cdfc7eSAndroid Build Coastguard Workerexit 0 174