• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20setup()
21{
22	RC=0				# Return code from commands.
23
24	if [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ]
25	then
26		LTPTMP="/tmp"
27	else
28		LTPTMP="$TMPBASE"
29	fi
30
31	export TPM_TMPFILE="$LTPTMP/tst_tpm.err"
32	rm -f $TPM_TMPFILE 2>&1
33
34	# Set the file to be protected and the related output files
35	export TPM_DATAFILE="$LTPBIN/tpmtoken_protect_data.txt"
36	export TPM_ENCDATA="$LTPTMP/tst_tpm_data.enc"
37	rm -f $TPM_ENCDATA 2>&1
38	export TPM_DECDATA="$LTPTMP/tst_tpm_data.dec"
39	rm -f $TPM_DECDATA 2>&1
40
41	# Set known password values
42	if [ -z "$P11_SO_PWD" ]
43	then
44		export P11_SO_PWD="P11 SO PWD"
45	fi
46	if [ -z "$P11_USER_PWD" ]
47	then
48		export P11_USER_PWD="P11 USER PWD"
49	fi
50
51	tst_resm TINFO "INIT: Inititalizing tests."
52
53	which tpmtoken_protect 1>$TPM_TMPFILE 2>&1 || RC=$?
54	if [ $RC -ne 0 ]
55	then
56		tst_brk TBROK $TPM_TMPFILE NULL \
57			"Setup: tpmtoken_protect command does not exist. Reason:"
58		return $RC
59	fi
60
61	return $RC
62}
63
64test01()
65{
66	RC=0				# Return value from commands
67	export TCID=tpmtoken_protect01	# Test ID
68	export TST_COUNT=1		# Test number
69
70	tpmtoken_protect_tests_exp01.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
71	if [ $RC -eq 0 ]
72	then
73		tst_resm TPASS "'tpmtoken_protect -e -i $TPM_DATAFILE -o $TPM_ENCDATA' passed."
74		RC=0
75	else
76		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_protect -e -i $TPM_DATAFILE -o $TPM_ENCDATA' failed."
77		RC=1
78	fi
79	return $RC
80}
81
82test02()
83{
84	RC=0				# Return value from commands
85	export TCID=tpmtoken_protect02	# Test ID
86	export TST_COUNT=2		# Test number
87
88	tpmtoken_protect_tests_exp02.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
89	if [ $RC -eq 0 ]
90	then
91		tst_resm TPASS "'tpmtoken_protect -d -i $TPM_ENCDATA -o $TPM_DECDATA' passed."
92		RC=0
93	else
94		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_protect -d -i $TPM_ENCDATA -o $TPM_DECDATA' failed."
95		RC=1
96	fi
97	return $RC
98}
99
100test03()
101{
102	RC=0				# Return value from commands
103	export TCID=tpmtoken_protect03	# Test ID
104	export TST_COUNT=3		# Test number
105
106	diff $TPM_DATAFILE $TPM_DECDATA 1>$TPM_TMPFILE 2>&1 || RC=$?
107	if [ $RC -eq 0 ]
108	then
109		tst_resm TPASS "'diff $TPM_DATAFILE $TPM_DECDATA' passed."
110		RC=0
111	else
112		tst_res TFAIL $TPM_TMPFILE "'diff $TPM_DATAFILE $TPM_DECDATA' failed."
113		RC=1
114	fi
115	return $RC
116}
117
118cleanup()
119{
120	rm -f $TPM_TMPFILE 2>&1
121	rm -f $TPM_ENCDATA 2>&1
122	rm -f $TPM_DECDATA 2>&1
123}
124
125# Function:	main
126#
127# Description:	- Execute all tests, report results.
128#
129# Exit:		- zero on success
130# 		- non-zero on failure.
131
132TFAILCNT=0			# Set TFAILCNT to 0, increment on failure.
133RC=0				# Return code from tests.
134
135export TCID=tpmtoken_protect	# Test ID
136export TST_TOTAL=3		# Total numner of tests in this file.
137export TST_COUNT=0		# Initialize identifier
138
139if [ -n "$TPM_NOPKCS11" ]
140then
141	tst_resm TINFO "'tpmtoken_protect' skipped."
142	exit $TFAILCNT
143fi
144
145setup || exit $RC		# Exit if initializing testcases fails.
146
147test01 || TFAILCNT=$(($TFAILCNT+1))
148test02 || TFAILCNT=$(($TFAILCNT+1))
149test03 || TFAILCNT=$(($TFAILCNT+1))
150
151cleanup
152
153exit $TFAILCNT
154