Commit Graph

53 Commits

Author SHA1 Message Date
Stefan Berger
695274e024 tests: Adjust tests to use new startup options
Adjust the vtpm proxy test case and others to make use of the new
startup options. Make sure that subsequent Startups sent to the
TPM fail with the expected error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-08 18:19:08 -05:00
Stefan Berger
930c7ba16e tests: Allow seccomp override w/ SWTPM_TEST_SECCOMP_OPT env var
The Ubuntu (PPA) build system executes the build on an environment that
has problems with seccomp profiles. It does not allow us to run the test
suite with swtpm applying its seccomp profile since it fails with a
'bad system call' error. To work around this we introduce the env. variable
SWTPM_TEST_SECCOMP_OPT that we can set to "--seccomp action=none" to avoid
having swtpm apply it seccomp profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-15 15:49:51 -05:00
Stefan Berger
01ad1d03f1 tests: Get swtpm PID from shell and validate against pidfile after
Get the PID of the started swtpm from the shell and validate it
against the contents of the pidfile afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
129c6b5bf2 swtpm: Add support for fd_to_filename on OS X and test it
Extend the previously modified test case to also test on
Darwin now that we are able to convert a file descriptor
to a filename.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-03 09:37:03 -04:00
Stefan Berger
19a8cdd67b tests: Use a file descriptor for the pid file on Linux and Cygwin
On Linux and Cygwin we can pass a file descriptor for the pid
file, on other platforms it doesn't work (yet).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-03 09:37:03 -04:00
Stefan Berger
8d70fd4a16 tests: Pass --runas parameter to swtpm
Pass the --runas parameter to swtpm so we can test switching it
to a given user 'nobody'.

We also have to change ownership of files and directories so that
the nobody user can write the coverage files when swtpm ends.
In the test case we then use the trick of changing file ownership
just before we terminate swtpm, which will trigger the writing
of the .gcda files. We need to have nobody own these files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
bb0aa2ad5a tests: Pass file ownership using uid and gid
Pass file ownership using the uid= and gid= parameters when run
as root and check the result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
f487473cf6 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>
2019-04-02 18:08:06 -04:00
Stefan Berger
90ae0c2783 tests: wait for files to appear or disappear after starting swtpm
Wait a few seconds for files to appear or disappear after starting the
swtpm process. This helps avoid test failures when the system is under
load.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-01 12:52:20 -04:00
Stefan Berger
45d2d092f3 tests: Increase timeout for shutdown for running with valgrind
To avoid timeouts when running the tests with valgrind, increase
the timeout until the swtpm process must have terminated after a
shutdown signal to 4 seconds.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-01 12:52:20 -04:00
Stefan Berger
a39f098fd6 swtpm: Use pbkdf2 as default kdf and sha512 for test cases
Use pbkdf2 as the default kdf and sha512 for the existing
test case. Do away with file limit of 32 bytes. This may
break backwards compatibility for some but better to do this
before a release...

Switch the existing test cases to use kdf=sha512 on the command
line where necessary to that the state for these test cases
does not need to be recreated.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
8f0f381f95 scripting: Use #!/usr/bin/env bash rather than /bin/bash
On some systems /bin/bash does not exists but the bash is somewhere
else and can be invoked with /usr/bin/env bash.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:49:12 +00:00
Stefan Berger
9e786a3ae5 tests: Enable test_ctrchannel on DragonFly BSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:14:06 +00:00
Stefan Berger
80f985897c tests: Implement support for OS/X (Darwin)
If the file descriptor 100 is open prior to trying to open
it, it must be closed first on OS/X, otherwise we get test
case failures due to interrupted connections.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:44:24 -04:00
Stefan Berger
df9eccd404 tests: Make test_ctrlchannel work on NetBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:07:20 +00:00
Stefan Berger
acdf48b0bd tests: Make test_ctrlchannel work on FreeBSD
To get /dev/ptmx on FreeBSD we need to run `kldload pty`.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 02:31:21 +00:00
Stefan Berger
47c7ea7783 tests: Make the killing of processes less noisy
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
313cf75c42 tests: Enable running tests in out-of-source builds
Pass the top_builddir and top_srcdir via TESTS_ENVIRONMENT
variable in Makefile.am.

Use TESTDIR for the path to the test directory and replace
previously used DIR in all occurences.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
36407c937b tests: Use wait_process_gone rather than kill -0
Have the test cases wait for the process to be gone after 1s using
wait_process_gone rather than trying use kill -0 once after 0.5s.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-02 08:26:53 -04:00
Stefan Berger
638bd3ba19 swtpm: Encrypt the data with a random IV every time
Whenever we encrypt the data we generate a new random IV and append a
tlv block with the IV to the byte stream. We mark the IV with different
tags depending on whether they are for the migration data or the (TPM)
data directly. All IVs are part of the HMAC and are added to it after
the data blob.

Adjust test cases that now return larger sizes of data. A constant
checksum over the data cannot be expected anymore, thus we have to remove
the verification of the checksum over the returned state (IV changes
every time).

The size of the blobs grow by 22 bytes, 6 for the tlv header, 16 bytes
for the IV (128 bit AES key).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-02 07:28:16 -04:00
Stefan Berger
27bf9db67e swtpm: Use tag-length-value blocks to store data in v2 format
Prepend tag-length-value (tlv) headers in front of all data being stored in
the byte stream following the header. This lets us uniquely identify plain
data (= TPM state), encrypted data (= encrytped TPM state), migration data
(which is wrapped plain or encrytped TPM state), and an HMAC block to
validate the plain data.

We keep support for version 1 for reading the data but convert them to
version 2 when writing them out. This way we loose backwards compatibility
(downgrading of swtpm is not possible), but it allows us to extend the state
in the future by adding addition blocks with tlv headers.

Version 1 of the encryption was prepending the hash on the plaintext data
then encrypting all of it. This method is not so good. In version 2 we now
use Encrypt-then-MAC (EtM) where we encrypt the data and then calculate an
HMAC on the encrypted data.

Files written by the swtpm didn't have a header before. Now they also get a
header. This means that the state written into files and the state retrieved
using the API (swtpm_ioctl --save) have the same format, but still differ
in so far as the API wraps the data in a tlv header for migration, which the
files written out as state would never get.

Adapt a couple of test cases show file sizes and hashes have changed now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-20 10:05:45 -04:00
Stefan Berger
2b8a668dbb swtpm: Implement CMD_GETINFO to retrieve TPM specification info
We quetry the swtpm for TPM specification info that goes into the
certificate for the EK.

Update the test cases that now see more capabilties being returned
by the swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:00:26 -04: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
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
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
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
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
Amarnath Valluri
1fb8bb790f Support added to receive data socket over control socket
As objected by QEMU upstream developers to use two different sockets for
starting/using of swtpm, This commit adds support for passing unix domain
socket over control channel.

The summary of the changes include:
 - Defined new control command CMD_SET_DATAFD, using this clients can send data
   socket.
 - set mlp.fd and mlp.flags outside of the mainloop
 - updated the testcases

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-09-29 13:11:01 -04:00
Stefan Berger
dd96bd5417 swtpm: add missing PTM_CAP_GET_CONFIG to returned flags
Add the missing PTM_CAP_GET_CONFIG to the returned flags.

Fix the order of the flags on the way.

Fix the test cases that test for the flags.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-27 07:11:32 -04:00
Stefan Berger
01aa2ed3af tests: Run tests also on socket interfaces
Refactor the tests so that they all run on socket interfaces as well.

Use socket ports in the range of 65400-65499 for TPM 1.2 tests.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00
Stefan Berger
63ab6c3c21 Introduce '--flag not-need-init' for socket and chardev
Change the startup behavior with respect to requiring an INIT command
via control channel. We change this for the socket and chardev
interfaces so that the behavior now is the same as that of the CUSE
interface.

Introduce the --flag not-need-init command line option for the socket
and chardev interfaces to allow the old behavior using this option.

Adapt some of the test cases and swtpm_setup.sh.in that now need this
command line flag.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00
Stefan Berger
bbf12ed918 tests: Increase socat timeout to avoid errors on slow ARM
Avoid getting useless test failures on ARM due to low timeout settings
of socat.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 17:47:11 -04:00
Stefan Berger
9606607075 tests: create unix_tx function to use socat to talk to Unix socket
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 17:26:44 -04:00
Stefan Berger
89d85f9a93 test: Add --log parameter to test logging
Add the --log parameter to test log levels 1 and 20.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-03 15:15:31 -05:00
Stefan Berger
70f3e24891 tests: Use a function to wait for pid file to appear
Introduce wait_for_file function to wait for a file for a max. amount of
time and have that function poll for the file to appear.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 13:57:35 -04:00
Stefan Berger
aeee2dc88b swtpm: Fix typo in command name
Fix a typo in two command names so that they are similar to
the command name spelling used for the ioctl's.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 16:58:44 -04:00
Stefan Berger
492a635e69 swtpm: Add support for setting the locality on the TPM
Implement the CMD_SET_LOCALITY command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-26 13:27:03 -04:00
Stefan Berger
6a2dd35b41 swtpm: Add support for sending state blobs to the TPM
Implement the CMD_SET_STATE_BLOB command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 23:47:44 -04:00
Stefan Berger
8f387d55e6 swtpm: Add support for getting state blobs from the TPM
Add support for CMD_GET_STATE_BLOB to get the current state of
the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 23:39:24 -04:00
Stefan Berger
3488d25f45 swtpm: Implement resetting the establishment bit with a command
Implement the resetting of the establishment bit with a command

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 22:00:24 -04:00
Stefan Berger
b5fbddbcf1 swtpm: deactivate reset establishment
Deactivate the code around resetting the TPM established bit
since its implementation currently requires libtpms 0.6.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 14:33:58 -04:00
Stefan Berger
03e0099137 swtpm: Implement two more control channel commands.
Implement two more control channel commands:
- CMD_STORE_VOLATILE
- CMD_HASH_DATA

Implement test cases.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 09:34:59 -04:00
Stefan Berger
f56a0cd2a5 swtpm: Further implement the control channel for socket and chardev
Further implement the control channel for the socket and chardev
interface swtpms.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 15:25:18 -04:00
Stefan Berger
4716d35a69 swtpm: Rename --connect to --server
Rename the --connect option to --server.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-20 14:50:40 -04:00
Stefan Berger
9ddc699812 swtpm: Add the control channel to the socket interface TPM
Add the control channel to the socket interface TPM as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 16:51:19 -04:00
Stefan Berger
e11a75527e tests: add timeout to socat
Add a timeout to socat so that on slower machines the tests succeed.

Clean up an #include.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-21 03:26:46 -05:00
Stefan Berger
804e74728e swtpm: add CMD_SHUTDOWN to control channel
Extend the control channel with CMD_SHUTDOWN to shut down the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 20:55:15 -05:00