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