Commit Graph

1332 Commits

Author SHA1 Message Date
Stefan Berger
6c441a5272 swtpm: Do not pass a negative file descriptor
Do not a pass a negative file descriptor to getsockopt(). This fixes
a Coverity issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-21 12:45:53 -05:00
Stefan Berger
ee40c13aaf tests: Extend encrypted state test to check for unmodified state
Extend the encrypted state test with a test case using a wrong key
for decrypting the state and make sure that the init fails and the
state files remain unmodified.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-14 07:59:04 -05:00
Stefan Berger
3ca520fd1c swtpm_ioctl: print error message in case setting state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:44:08 -05:00
Stefan Berger
e396140204 swtpm: log when the decryption of a state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:43:11 -05:00
Stefan Berger
cf47149f88 swtpm: log when the decryption of the NVRAM file fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 19:35:23 -05:00
Stefan Berger
4c046e0b46 build: add missing EXTRA_DIST files
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 13:49:24 -05:00
Stefan Berger
9cf37cbfae tests: extend INIT test with case where state file is inaccessible
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-12 17:14:33 -05:00
Stefan Berger
3760c34251 swtpm: Add truncate parameter for --log option
Enable the resetting of the log using a truncate parameter for the
--log option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:47:27 -05:00
Stefan Berger
41deaf616e swtpm: always set the logging file descriptor on libtpms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:24:12 -05:00
Stefan Berger
addf7c5e45 swtpm: Also log the control channel exchanges
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 21:48:17 -05:00
Stefan Berger
ccd1aeb15b swtpm: also log control channel commands 2017-11-10 21:32:44 -05:00
Stefan Berger
60afebf116 swtpm: Log an error if data encryption failed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
73fb0412ea swtpm: Remove file if errors occured writing it
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
f1389afb87 swtpm: Move debugging output into own function
Move some of the debugging output into its own function and
differentiate output by TPM Version number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 18:55:54 -05:00
Stefan Berger
eff9cc1672 swtpm_setup: Add options to overwrite or not overwrite TPM state
Add options --overwrite and --not-overwrite to allow or prevent
overwriting of existing TPM state. If neiter of the options is
given and existing state is found, an error is returned.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-09 10:54:07 -05:00
Stefan Berger
38304e9c81 swtpm: remove debug include file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 15:38:13 -05:00
Stefan Berger
688c8e2400 swtpm: Implemented support for PTM_SET_BUFFERSIZE command
Implement a command for setting and querying the buffer size the
TPM implementation (libtpms) is using. The setting of the
buffersize allows to reduce the size of the buffer to a size
that the interface can support so that these two sizes match
and the TPM will not produce larger responses than what the
interface can support.

Extend swtpm_ioctl with an option to set the buffersize.

Adapt the existing tests to reflect the newly supported command.
Implement a new test for getting/setting of the buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 14:53:00 -05:00
Stefan Berger
ca7f7a4006 swtpm: fix segfault introduced in aa3999
Changeset aa3999 introduced a segfault when calling
ctrlchannel_set_client_fd() with a NULL pointer. Like all the other
functions, we return with -1 in this case.

Since the segfault occurred on process shutdown no problems were
noticeable through bad test results or so.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-30 12:02:56 -04:00
Stefan Berger
061f9dce5e swtpm: Install SIGPIPE signal handler to ignore signal
Install a SIGPIPE signal handler to ignore the signal from trying
to write to a broken pipe.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
e09966f603 swtpm_setup: Fix a couple of typos
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
6098d7baae tests: implement missing wait_file_gone function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-17 17:33:23 -04:00
Stefan Berger
ead37845d8 tests: replace plain sleep with wait for PID file to be gone
Replace the short sleeps with waits for the PID file to be gone.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
6d33f6eb08 tests: increase socat timeout for slow machines
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
bd8f3581ef tests: Wait for previous socket or device to have disappeared
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
298d17822c swtpm: clean up server and ctrlchannel at the end
Introduce another parameter to ctrlchannel_new and server_new
to pass the Unix socket's path. Implement ctrlchannel_free and
server_free to clean up and remove the Unix socket's path.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
aa3999d387 swtpm: Implement ctrlchannel_set_client_fd()
Implement ctrlchannel_set_client_fd() to set a new client
fd and return its current value.

Use this new function to set the file descriptor to -1 upon
closing its associate file descriptor in the main loop.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
75f9f0d300 swtpm: Implement server_set_fd()
Implement server_set_fd() function to get the current file descriptor
and set a new one on the server structure.

Use this function to transfer the server file descriptor from the
server structure to the mainloop structure and have the main loop
close the file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
fa3d8e4910 swtpm_ioctl: Display error in case of read() returns < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
35e571b43c tests: Wait for swtpm to open socket or chardev
Rather than waiting for some time poll for the swtpm to either
open a socket or chardev.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
0f648eda0b tests: Fix filename used for volatilestate
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
06b8d0327b build: fix linker SEARCH_DIR extraction for OpenBSD and Cygwin
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
6ee0bd79d7 swtpm: Fix header inclusion for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
7654523273 tests: Check for existing chardev and use uname -s
Check whether /dev/ptmx or /dev/ptm exists and use it to open a file
descriptor on it, raise an error otherwise.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
597d06eeef tests: wrap sha1 and file size tools
OpenBSD uses different tools for sha1 and file size calculations,
so we wrap them in functions and check which one to call by using
uname -s.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
415bf5563d tests: use uname -s to check for Linux
Use uname -s to check for Linux rather than uname -o, which doesn't
seem to be supported on OpenBSD.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
27aad7283c tests: write binary string into file and then cat into device
Rather than using the non-bash echo tool, which doesn't seem to
support -e on OpenBSD, use the bash echo tool to write the binary
code into a file and cat the file into the device. This also works
around a problem when a sequence contains \x0a, which then seems
to be the last character written to the device if bash's echo is
used. It does this correctly when writing to a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
ea06f14b99 tests: fix name of PID file
Signed-off-byt: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
2dc486cb97 swtpm_ioctl: Define missing #define's for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
730ed7c32e swtpm_bios: include sys/socket.h for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
54ed795b60 swtpm: Fix off-by-one for sockaddr len for OpenBSD
On OpenBSD the socket's name would be cut short by one letter at the
end due to an off-by-one for the calculated sockaddr struct's length.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
b20eafa7b4 swtpm: reformat source
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
1d92a4df07 swtpm: Do not set PTM_CAP_SET_DATAFD flag on Cygwin
The control channel of a UnixIO socket is not supported
on Cygwin, so do not present this flag. Return an error
if this command is run.

Adapt the test case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-11 18:57:16 -04:00
Stefan Berger
1eef338e69 tests: copy 'swtpm chardev' test to test_ctrlchannel4
Copy the test case that use 'swtpm chardev' to test_ctrlchannel4
and convert this test in test_ctrlchannel to use a socket. Make
test_ctrlchannel run on all platforms. test_ctrlchannel4 only
runs when WITH_CHARDEV is set in the Makefile.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-11 18:57:16 -04:00
Stefan Berger
281cb8ac8c tests: Split off CMD_SET_DATAFD test into own file
Split off the CMD_SET_DATAFD into its own file. This test only works on
Linux, so we skip it on Cygwin for example. Otherwise it should be able
to run.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-11 18:57:16 -04:00
Stefan Berger
a19a868316 tests: convert test_ctrlchannel to use functions
Convert the test_ctrlchannel to use the functions from tests/common.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-11 18:57:16 -04:00
Stefan Berger
66250d635a man: Update description in man page to reflect ctrl channel commands
Update the description in the man page to reflect ioctl's and
control channel commands.

Update to the latest supported commands.

Fix a few text locations on the way.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 09:47:15 -04:00
Stefan Berger
2a312e9f30 test: add script to test 32bit and 64bit versions
Add a script to build and test 32 bit and 64 bit versions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 07:17:25 -04:00
Stefan Berger
6d42968570 swtpm_cert: add cast to avoid compile error on i686
Cast the exponent to unsigned long int to avoid a compiler
error reporting comparison of signed and unsigned integers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 07:17:25 -04:00
Stefan Berger
19e05751c7 tests: Allow to specify SWTPM_EXE, SWTPM_IOCTL and SWTPM_BIOS for tests
To enable the test suite to for example run a mixture of 32- and
64bit executables, allow users to specify the executables to use by
setting the variables SWTPM_EXE, SWTPM_IOCTL, and SWTPM_BIOS via
command line.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 07:17:25 -04:00
Stefan Berger
c2ca9afc2c tests: use send1msg() in place of sendmsg() for older twisted versions
Use the send1msg() ot the twisted sendmsg package since sendmsg()
is only supported in more recent versions of twisted.

Following this we also don't need to install a recent version of twisted
via pip on Travis, which runs Ubuntu 14.04.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-29 20:03:14 -04:00