mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-01-26 18:30:52 +00:00
tests: Use mode= to set file mode bits in test and check them
Use the mode= parameter of the TPM's state file and a unix socket to have swtpm set the file mode bits and check that they are set as expected. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
e617652a57
commit
f487473cf6
13
tests/common
13
tests/common
@ -615,6 +615,19 @@ function get_filesize()
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the file mode bits in octal format
|
||||
#
|
||||
# @1: filename
|
||||
function get_filemode()
|
||||
{
|
||||
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
|
||||
stat -c%a $1
|
||||
else
|
||||
# BSDs
|
||||
stat -f%Lp $1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the SHA1 of a file
|
||||
#
|
||||
# @1: filename
|
||||
|
||||
@ -66,10 +66,11 @@ function wait_port_closed()
|
||||
}
|
||||
|
||||
# Test 1: test port and directory command line parameters; use log level 20
|
||||
FILEMODE=641
|
||||
|
||||
$SWTPM_EXE socket \
|
||||
-p $PORT \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--tpmstate dir=$TPMDIR,mode=$FILEMODE \
|
||||
--pid file=$PID_FILE \
|
||||
--log file=$LOG_FILE,level=20 \
|
||||
--flags not-need-init &
|
||||
@ -95,12 +96,19 @@ if [ "$PIDF" != "$PID" ]; then
|
||||
fi
|
||||
|
||||
${SWTPM_BIOS} &>/dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Test 1 failed: tpm_bios did not work"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filemode=$(get_filemode ${TPMDIR}/tpm-00.permall)
|
||||
if [ "$filemode" != "$FILEMODE" ]; then
|
||||
echo "Filemode bits are wrong"
|
||||
echo "Expected: $FILEMODE"
|
||||
echo "Actual : $filemode"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_logfile_patterns_level_20 $LOG_FILE
|
||||
rm -f $LOG_FILE
|
||||
|
||||
|
||||
@ -31,6 +31,12 @@ source ${TESTDIR}/common
|
||||
|
||||
# Test 1: test the control channel on the socket tpm
|
||||
|
||||
if [[ "$(uname -s)" =~ CYGWIN_NT- ]]; then
|
||||
FILEMODE=661
|
||||
else
|
||||
FILEMODE=621
|
||||
fi
|
||||
|
||||
case "$(uname -s)" in
|
||||
FreeBSD)
|
||||
kldload pty
|
||||
@ -50,7 +56,7 @@ $SWTPM_EXE socket \
|
||||
--fd 100 \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \
|
||||
--ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH,mode=$FILEMODE \
|
||||
--log file=$LOG_FILE,level=20 &
|
||||
|
||||
exec 100>&-
|
||||
@ -76,6 +82,14 @@ if [ "$res" != "$exp" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filemode=$(get_filemode $SWTPM_CTRL_UNIX_PATH)
|
||||
if [ "$filemode" != "$FILEMODE" ]; then
|
||||
echo "Filemode bits are wrong"
|
||||
echo "Expected: $FILEMODE"
|
||||
echo "Actual : $filemode"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
|
||||
res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')"
|
||||
exp=" 00 00 00 00"
|
||||
|
||||
@ -31,13 +31,14 @@ function cleanup()
|
||||
|
||||
# Test 1: test the control channel on the chardev tpm
|
||||
|
||||
FILEMODE=621
|
||||
# use a pseudo terminal
|
||||
exec 100<>/dev/ptmx
|
||||
$SWTPM_EXE chardev \
|
||||
--fd 100 \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH \
|
||||
--ctrl type=unixio,path=$SOCK_PATH,mode=$FILEMODE \
|
||||
--tpm2 &
|
||||
|
||||
if wait_for_file $PID_FILE 3; then
|
||||
@ -54,6 +55,14 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filemode=$(get_filemode $SOCK_PATH)
|
||||
if [ "$filemode" != "$FILEMODE" ]; then
|
||||
echo "Filemode bits are wrong"
|
||||
echo "Expected: $FILEMODE"
|
||||
echo "Actual : $filemode"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exp="ptm capability is 0x([[:xdigit:]]+)"
|
||||
if ! [[ "$act" =~ ^${exp}$ ]]; then
|
||||
echo "Error: Expected string following regular expression '$exp' from ioctl tool but got '$act'."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user