Commit Graph

274 Commits

Author SHA1 Message Date
Stefan Berger
5c7f8386ce tests: Use python twisted for sendmsg on python 2
Rather than sending two separate messages with the bare python 2
API, use the python twisted package to send the control and data
in one sendmsg() call. This avoids occasional test failures in
the ctrlchannel test case that is currently sending the data and
control part of the message in 2 steps, which can lead to the
recpient not seeing the whole message.

Add python-twisted as a build dependency to the rpm and Debian
builds and the .travis.yml.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-29 14:15:26 -04:00
Stefan Berger
8d4d320b9c tests: reformat .py code to have pep8 pass without errors
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-29 13:55:56 -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
f3a149175c tests: add functions for running swtpm and swtpm_ioctl
To be able to run tests with either one of the interfaces, add function
for running swtpm and swtpm_ioctl commands and form the command line
parameters dependent on the type of interface being passed. We rely on
environment variables to provide the specific parameters that are needed
to run the program with the appropriate parameters.

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
f18c4cce67 tests: Increase sleep time to accomocate slow ARM
Increase the timeout from 0.2 to 1 seconds so that a tests
passes on ARM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-29 14:27:58 -04:00
Stefan Berger
dc1111362b Implement allow-set-locality for CUSE TPM and extend test case.
Implement allow-set-locality for CUSE TPM and extend the existing
locality test case with commands that try to write the SetLocality
comamnd to the device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 16:51:45 -04:00
Stefan Berger
cb35cba105 tests: Extend existing test with one for rejection of locality 4
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-01 16:59:20 -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
Amarnath Valluri
93edca48a2 swtpm: Added support for passing control channel client fd.
New option '--ctrl clientfd=<fd>' is added to the control socket parameters.
The passed 'fd' is used as control channel client-fd and treated as single
client mode.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:15:51 -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
cde5f608e5 tests: Skip CUSE TPM related tests if cuse module is not available
Skip the CUSE TPM related tests if the CUSE kernel module is not
available. Return similar error messages for both CUSE and VTPM proxy
module if they are not available.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-02 09:01:55 -05:00
Stefan Berger
4994a97e52 tests: Fix return code to skip test
Fix the return code indicating that the test code be skipped.
We need to return 77.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-01 17:28:18 -05:00
Stefan Berger
ca906a0212 tests: Wait for chardev to appear
Wait for the chardev the VTPM proxy device creates to actually appear.
In some cases the exec statement opening the file would otherwise
create a file /dev/tpm0 for example and subsequently tests then ended
up failing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-24 08:43:50 -05:00
Stefan Berger
2308308b5f tests: Add a test case for swtpm using the vTPM proxy device
Add a test case for swtpm chardev using the vTPM proxy device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 09:47:01 -05:00
Stefan Berger
498433f7b5 Detect whether to build with chardev
Detect whether to build with the chardev interface and only run tests that
need the chardev if it is supported on a particular platform.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-03 07:18:38 -05:00
Stefan Berger
f26ec8c8c7 Conditionally run tests
Conditionally run tests if building with CUSE interface or if
building with swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 21:01:16 -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
01eb4d3a3b swtpm_ioctl: Add support for UnixIO and TCP control channel
Add support for UnixIO and TCP control channels. Both types of
transport require that packets are sent in big endian format
and therefore some code needs to be adjusted for that. The
ioctl interface is local and in that case no endianess conversion
is done.

Add a new test case that uses the extended swtpm_ioctl tool to
test the control channel.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 16:58:48 -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
85bae89bb0 tests: source script relative to directory
'source' tests_cuse relative to the tests directory

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 22:16:00 -04:00
Stefan Berger
4ec7d70fe8 swtpm_bios: redirect error output to stderr
Redirect all error output to stderr.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 21:51:55 -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
4372c7feb8 tests: Display logfile upon failure
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-13 10:35:20 -05: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
Stefan Berger
cf56d345bd tests: Deactivate the checking for the certificate size
Deactivate the checking for the certificate size since different
GnuTLS versions may create certificates of different sizes by adding
additional fields or other data to the cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-13 21:58:38 -05:00
Stefan Berger
96038cdfec tests: move modprobe cuse into common file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-13 21:23:12 -05:00
Stefan Berger
86b6ffca75 swtpm: use endian.hi for endianess conversion
Use the macros defined in endian.h for endianess conversion.

Fix the conversion of a 64bit variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:25:17 -05:00
Stefan Berger
ffcb6535d3 swtpm_bios: Add option to give up physical presence
Extend the swtpm_bios tool with an option to give up physical presence.

Have the TPM error codes reflected in the exit error of 128.

Add a test case for the tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 18:23:13 -05:00
Stefan Berger
02017e62b0 test: fix file permission
Signed-off-ny: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-28 10:47:38 -05:00
Stefan Berger
6852f6c89b swtpm: introduce control channel for chardev TPM
Implement a control channel for the 'chardev' swtpm that implements
a minimal set of control messages for now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 22:13:37 -05:00
Stefan Berger
6e7df39f22 build: remove hardcoded tss user and group
Adding forgotten file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-03 10:13:46 -05:00
Stefan Berger
c4ac0a11e9 build: remove hardcoded tss user and group
Remove the hardcodes tss user and group and to configure with
--with-tss-user=tss --with-tss-group=tss to set the tss user
and group to be used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-02 20:47:37 -05:00
Stefan Berger
bc525ccdab swtpm: Add support for --tpmstate dir=<dir> command line parameter
Add support for the --tpmstate dir=<dir> command line parameter.
It will be used instead of the TPM_PATH, unless it is not set.

Adapt two test cases for the new parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-27 21:58:10 -04:00
Stefan Berger
b215173767 swtpm: Add command line parameter for pidfile
Add support for --pid file=<pidfile> command line parameter support.
The swtpm_cuse and swtpm now write their process IDs (pids) into
a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-26 06:34:14 -04:00
Stefan Berger
c43ad8fac2 tests: Skip test since it requires root rights
The swtpm_setup needs to either be run as root or as tss user.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
2015-10-16 15:56:23 -04:00
Stefan Berger
2c3c8d27d2 tests: fix more typos
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-08-03 09:56:27 -04:00
Stefan Berger
2773883b3e test: fix a typo
Fix a typing error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-08-03 07:01:13 -04:00
Stefan Berger
84d2e89a74 swtpm_setup: remove PATH extension to local dir
Remove the extension of PATH to the local dir('.') from swtpm_setup.sh
and adapt test cases accordingly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-02 10:50:05 -04:00
Stefan Berger
a8279cfde4 test: poll for port closure
Poll for the swtpm with socket interface port to close the port

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-30 13:32:22 -04:00
Stefan Berger
53b55e7145 test: poll for port available
Poll for the swtpm with socket interface port to become available for
usage.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-30 13:08:12 -04:00
Stefan Berger
d7fc046934 tests: cleanup testcases
Cleanup the test cases:
- remove unnecessary sleeps
- check exit code of swtpm_ioctl

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-30 10:42:15 -04:00
Stefan Berger
05cd79b843 Support read()/write() for TPM state blob transfer
Support the read/write interface and POSIX API calls for transfer of
TPM state blobs.

Extend the swtpm_ioctl program to support this as well. Use the
environment variable SWTPM_IOCTL_BUFFERSIZE to set the size of the
buffer to use and enable the read/write interface in this (test)
program.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-04 18:49:25 -04:00
Stefan Berger
25fee77410 Extend test cases with large permanent state
For being able to test the transfer of larger state blobs, extend the existing
test case with creating a large NVRAM location that becomes part of the permanent
state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-04 10:55:32 -04:00
Stefan Berger
b89c956e1f tests: remove saving of volatile state before saving blob
Remove the explicit saving of volatile state before saving the volatile
state blob to a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
bd98690a4a Add ioctl to get configuration flags about keys in use
Add an ioctl that lets an application retrieve which keys are in use by the
TPM, i.e., file encryption or migration key

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-26 07:30:38 -04:00
Stefan Berger
8236603be8 tests: add volatilestate.bin to EXTRA_DIST
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 15:46:04 -04:00
Stefan Berger
1680c41d9e swtpm: Add a command line option for a migration key
The migration key ensures that TPM state blobs, when retrieved using the
ioctl for getting state blobs, are always encrypted with this key.
When the state is later on loaded back into the TPM using the ioctl
to set the state blobs, the migration key is used to decrypt them.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:18:44 -04:00
Stefan Berger
4dfb26d9b4 tests: do not let test_resume_volatile touch files in git
Have test_resume_volatile create a temporary dir and copy test files to it
that may be modified during the test run.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-24 21:37:11 -04:00
Stefan Berger
b902468900 swtpm: integrity protect the encrypt TPM state
Integrity protect the TPM state when it is written in entrypted form.
libtpms state (for TPM1.2) is also integrity protecting the blobs, but
we better determine the integrity of the decrypted data on the layer
above it.
2015-05-19 16:35:08 -04:00
Stefan Berger
0dba8f77eb tests: add test case that certificate is created automatically
Add a test case that ensures that swtpm-localca automatically
creates a signing key and issuer cert if none is available.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 09:35:55 -04:00
Stefan Berger
d379cbb4a4 test: Use TPM_ResetEstablishmentBit command in some tests
Rather than only using the ioctl to reset the TPM Establishment
bit in a given locality, also use the TPM_ResetEstablishmentBit
command for it in some test cases.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-02 09:19:46 -04:00
Stefan Berger
a4b00166dd tests: Fix test case output
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-01 16:25:54 -04:00
Stefan Berger
0722cffd12 tests: Extends test_volatilestate with checks on establishment bit
Extend the testcase test_volatilestate with check on the TPM
establishment bit and that it is saved across volatile save/load
operations.
2015-05-01 12:24:39 -04:00
Stefan Berger
9fb43c7a98 test: Terminate swtpm in case testcase is aborted
Send a SIGTERM to the swtpm in case the testcase is aborted.
2015-04-28 20:16:47 -04:00
Stefan Berger
1140f4c656 tests: bail out if modprobe cuse fails
Terminate the test case immediately if modprobe cuse fails.
2015-04-02 06:43:39 -04:00
Stefan Berger
950040f03c swtpm_cuse: implement STOP ioctl
Implement a STOP ioctl in the swtpm and swtpm_ioctl client.
Modify test cases to used swtpm_ioctl --stop.
2015-03-16 11:50:03 -04:00
Stefan Berger
198ebab3c1 Add new ioctls for getting and setting state blobs
Add new ioctls to get and set the 3 different types of state blobs
from and to the CUSE TPM. Add test cases for testing the new ioctl's
on a CUSE TPM that stores the state encrypted and on a CUSE TPM that
stores it non-encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-12 09:32:28 -04:00
Stefan Berger
e150007d18 Allow tests to run in parallel
Create uniqe names for the /dev/vtpm* so that tests can run in parallel.
Also separate the state directories of the TPMs into individual temporary
dirs.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-12-19 16:10:59 -05:00
Stefan Berger
bb3c6bf625 Search for external echo tool
Search for bash-external echo tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-12-18 22:27:53 -05:00
Stefan Berger
0321a3808d Add ioctl to reset the establishment bit
Add an ioctl to reset the establishment bit. It takes as an
argument the locality to use.
2014-12-08 11:35:16 -05:00
Stefan Berger
e46a2b6686 merging swtpm-tools into this project 2014-12-05 13:43:21 -05:00