Commit Graph

337 Commits

Author SHA1 Message Date
Stefan Berger
420a18f1d0 tests: Use file descriptor 100 rather than 200 (fix OpenBSD)
Use file descriptor 100 rather than 200 to pass on OpenBSD

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
45ed7764fb tests: Add yet more tests for TPM 1.2 and enable auditing
Add test cases 25 and 26 and run test 25 with auditing enabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-01 06:56:31 -04:00
Stefan Berger
c4a9e78aab tests: Fix some issues with TPM 1.2 test
- Clean up state files in case the test suite was interrupted
- Allow running it from the test directory by creating an absolute
  path for TESTDIR so we can find the patch file; error out in
  case the patching fails
- Run test case 2 and 1 as well but ignore ERROR output in case
  of test 1. The errors stem from us not restarting the TPM when
  the test suite asks for it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-29 12:38:55 -04:00
Stefan Berger
b752aed8f5 tests: Add test case running TPM 1.2 test suite
Add a test case that downloads the TPM 1.2 package from sourceforge,
patches a few files for OpenSSL compatibility, and runs a few test
cases of that test suite. Look for ERROR output in the test suite.
This test suite also provides better code coverage for libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-28 20:58:04 -04:00
Stefan Berger
a18cf08504 tests: Use an empty options file in case options file is accessed
To prevent the test case from failing when an no --prefix is used
when configuring, use an empty options file via /dev/null. Otherwise
swtpm-localca starts looking for the options file in a place where
there is none.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-26 06:51:00 -04:00
Stefan Berger
a3820b8634 tests: Extend tests cases with test for active seccomp profiles
Extend existing test cases to test for active seccomp profiles.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-18 15:43:44 -04:00
Stefan Berger
e60e777c7b tests: Fix error handling if pkcs11 test runs on x86_64 with i386 executable
Softhsm cannot be installed as an i386 executable/library and as
a x86_64 executable/library on a Fedora host. The pkcs11 test then
fails since it cannot pick up the libsofthsm.so needed for an i386
executable (swtpm_cert) on a x86_64 host. This fixes test run errors
for run_test.sh by skipping the test in case swtpm_cert returns
a specific error message related to not being able to import the
pkcs11 URI object.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-28 17:03:26 -05:00
Stefan Berger
8c2cb90f11 test: Replace uname -o with uname -s
Replace single occurrence of uname -o with uname -s so it's portable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 17:56:31 -05:00
Stefan Berger
bfdad297ed tests: Use wait_process_gone rather than sleep
Use wait_process_gone with 2 seconds timeout to wait for the swtpm to
have terminated after SIGTERM or connection loss. This avoids test
failures on slow Raspberry Pi 2.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 17:56:31 -05:00
Stefan Berger
02b7d5da10 Make softhsm/pkcs11 test case work on Travis on OS X
We need to run the softhsm/pkcs11 test case as root (sudo) under OS X
so that we can write the file /etc/gnutls/pkcs11.conf. However, once
we run the tests as root we cannot run the 'brew ls' command anymore
since it refuses to run with high privileges. So, if we run as root we
need to use sudo to switch to the nobody user to run the 'brew ls'
command that gives us the name of the softhsm pkcs11 module.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 15:42:52 -05:00
Stefan Berger
b5e7e2a41f tests: Make the test case work on OS X
On OS X we need to be able to change /etc/gnutls/pkcs11.conf for
p11tool to pick up the softhsm pkcs11 module correctly. We need
(password-less) sudo to be able to do this.

Unforutnately this test case does not run on Travis since Travis
seems to require passwords under some circumstances.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 12:48:43 -05:00
Stefan Berger
34308cc7d3 tests: Add test case that uses a pkcs11 URI for signing a cert
Use SoftHSM to create a pkcs11 URI and then use the pkcs11 URI
to sign the certificate of a TPM 2.0 with this key using swtpm-localca.

This test case works with softhsm >= 2.3.0 on Fedora and should work
with a recent version of Ubuntu. If an error is encountered setting
up the softhsm2 environment, we just skip the test.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 12:48:43 -05:00
Stefan Berger
2b0f421224 tests: Gate the IBM TSS 2 related test with SWTPM_TEST_IBMTSS2
Older versions of the IBM TSS2, such as in FC26 for example, behave
slightly different than the code in the test case expects (certain
files are not generated or may have a different name). So gate this
test case with SWTPM_TEST_IBMTSS2 environment variable so we don't run
it by default if the TSS tools are found and so we do not run into
possible errors due to an older version of the stack installed on the
system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 18:57:53 -05:00
Stefan Berger
a1c9aedd77 tests: Set TPM_INTERFACE_TYPE=socsim
Set the TPM_INTERFACE_TYPE to socsim to override a potential
compile-time default.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 18:57:53 -05:00
Stefan Berger
6dbab87358 tests: Remove 'less' command from test case
Remove a 'less' command from previous debugging from the test
case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 17:08:04 -05:00
Stefan Berger
63f7079fd7 tests: Use bash's built-in echo rather than /bin/echo
The BSD's cannot use /bin/echo -en but we have to use bash's built-in
one.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 18:50:42 -05:00
Stefan Berger
078e3bcdff tests: Convert test case to also use binary formatted key
To get better code coverage, convert existing test case to
use one time a hex formatted key and the other time the same
key in binary format.

Do some improvements on the test code on the way.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 17:07:31 -05:00
Stefan Berger
13b76898a5 tests: Add missing file sizes and some other reorg to test case
2 file sizes were missing. Also use $() to execut commands rather
than ``. Use get_filesize to get the size of a file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 17:07:31 -05:00
Stefan Berger
660ec54272 tests: Allow passing SWTPM_CERT from command line
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-17 16:37:03 -05:00
Stefan Berger
4bd99ad965 tests: Extend swtpm-create-tpmca test with 'well known' password
Extend the swtpm-create-tpmca test with test cases using the
'well known' password of 20 zero bytes if tpmtool supports the
--srk-well-known option.

Besides that, extend the existing test to actually use the TPM CA
for signing a TPM 1.2 or TPM 2 (test) EK and check the contents of the
certificate by grepping through the text info provided by certtool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-09 14:18:25 -05:00
Stefan Berger
a0e7fbc05e tests: Refactor swtpm-create-tpmca test for easier extension
Refactor the swtpm-create-tpmca test case so we can use it for
testing with the 'well known' (20 bytes of zeros) SRK password
in the next pass.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-09 14:18:25 -05:00
Stefan Berger
7cdc7ea483 tests: Add a test case for the TPM CA setup script
Run the TPM CA setup script with a local swtpm and tcsd instance.
We have to take ownership of the TPM and set its SRK passwork so
that the TPM CA setup script can create a signing key as a child
key of the SRK.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:15:48 -05:00
Stefan Berger
15a14c552a samples: Add support for password protected root CA priv. key
Support creation and usage of the root CA with a password protected
private key. The root CA's key password can be set using the environment
variable SWTPM_ROOTCA_PASSWORD.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-25 10:32:36 -04:00
Stefan Berger
f759520c02 tests: Check expected error output against expected error message
Some tests are expected to fail. Capture the error output and test it
against epected error output. This also makes the test output less
noisy.

Also remove some other output noise.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
148010c0b6 tests: Shut down swtpm at the end to avoid kill
Shut down the swtpm process at the end to avoid it being killed
and with that getting noise in the test log.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
08c8820a74 tests: Return a string from get_file_hash if file not found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
3ad55f8c3a tests: Only run test_tpm2_samples_swtpm_localca if certtool was found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-06 18:09:08 -04:00
Stefan Berger
03c7fe4566 tests: Get the IBM TSS2 test suite and run it
Get the IBM TSS2 test suite from its git repo, compile it, and run
its test suite if SWTPM_TEST_EXPENSIVE=1 is set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-05 13:34:22 -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
c46d6717ae tests: Add delay after finding file for process to write into it
Add a delay of 0.2s after a file is found in wait_for_file so that the
process can also write into it. Sometimes we are also interested in the
content and don't seem to get the content since we didn't wait for
the file to have been written to. It happens occasionally when the system
is under load that we don't seem to be able to read the file content
afterwards.

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
100317d541 tests: Call function rather than running 'ps aux' to display proceses
Call a function display_processes_by_name that displays all processes
if needed. The function is quiet, though.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 10:19:09 -04:00
Stefan Berger
4dd376c3b4 tests: Replace kill_quiet after shutdown with wait_process_gone
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 09:59:17 -04:00
Stefan Berger
b4372fe50f tests: Use python3 rather than python for the test programs
Fedora policy seems to be to use python3 explicitly for the hashbang
rather than python, which could be either python2 or python3. So convert
it to python3. Also adapt configure.ac to require python3 executable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-25 08:35:45 -04:00
Stefan Berger
71d9581aa4 tests: Extend test cases with aes-256-cbc state file encryption
Extend existing test cases with aes-256-cbc state file encryption.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 12:23:22 -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
c51c07a016 tests: Pass top level source dir to test cases for out-of-tree builds
Some test cases that root has to run did not pass the out-of-tree
builds. We need to pass the top level source dir to these test cases
and change some variable accessing config files to the right directory
for the out-of-tree build to work.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-01 14:49:49 -04: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
8aff5f7665 tests: set CERTTOOL to gnutls-certtool on OS/X
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:40:01 -04:00
Stefan Berger
526bf3754e tests: Use --cs for swtpm_bios rather than ambiguous -cs
The -cs parameter to swtpm_bios is like -c -s and therefore ambiguous.
Use the unambiguous long version --cs. This makes the test case work
on NetBSD, which does not support getopt_long_only().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:10:01 +00: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
4f1912e8e8 tests: fix and enable test_tpm2_ctrlchannel2
test_tpm2_ctrlchannel2 was not active and was not complete. This
patch fixes the test case and activates it. It uses chardev, so
it needs to be gated by WITH_CHARDEV.

Signed-off-by: Stefran Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 14:54:52 -04:00
Marc-André Lureau
611a198637 build-sys: fix make distcheck
- fix paths
- ignore chmod issues (they are more package/distro issues)
- scripts are already executable

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-08 09:58:22 -04:00
Stefan Berger
28c4645454 tests: Activate test case for swtpm-localca
With the SAN data in the certificate properly generated and accepted by
certtool, we can now activate the test case for swtpm-localca.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 14:22:12 -04:00
Stefan Berger
e92942a8b0 tests: quirk for Cygwin
On Cygwin the swtpm_setup executable is located in src/swtpm_setup/.libs
dir and we need to copy the swtpm_setup.sh file there as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
64faf455fb build-sys: Build swtpm_setup on all supported platforms
Introduce compile-time variable HAVE_TCSD if the TCSD could
be found. It influences whether TPM 1.2 related swtpm_setup
test cases can be run. If it is set, they can be run.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
c50cb6cba9 tests: Run TPM 2 related swtpm_setup tests under less restrictions
Run TPM 2 related swtpm_setup tests under less restrictions.
For TPM 2 related tests only WITH_GNUTLS, which allows swtpm_cert
to be built, needs to be set since swtpm_setup is now being built
under all conditions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
5d0136d07b tests: Remove root requirement for test_tpm2_swtpm_setup_create_cert
Remove the requirement to run the test_tpm2_swtpm_setup_create_cert
test with root rights. It's not necessary to run this as root.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
610cd51e5b tests: Make python test code independent of python 2 or 3
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
26320a82b2 tests: skip sha512 related test if pcrallocate does not support it
Older versions of pcrallocate do not support sha512. Skip the test
that needs it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04: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
0550d91d52 tests: Check for approximate expected file size with a regex
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
e049a947a9 tests: Adapt loop to handle slow or busy systems
Adapt the loop that is polling for the authentication failure due
to lockout until a certain time. We run the tests also when $timeout
has been reached but don't care for the result if it failed. This
accomodates slow or busy systems that run some of the commands too
slowly and allow the TPM to release the lockout.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
be4bc80df0 tests: Add TPM 2 test for testing the DA timeouts with state suspend/resume
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
5211d89dfb Update EXTRA_DIST files to be able to build RPM from tar
A few files were wrong in the EXTRA_DIST file list due to changes to
test cases. Add the proper files.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
9e3fab9817 tests: Update test case due to SHA512 support in libtpms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
9a08b03c57 tests: Test key written to and loaded from volatile state
Test that a key written to volatile state is properly loaded again
and produces the same signature as before.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
6a41f8e19f tests: Add a test case for checking certs created by swtpm_localca
Test the certs created by swtpm_localca by verifying the certificate
chain and checking their key usage.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
75d3393189 tests: Add test cases for encrypted state
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
70ed60be38 tests: Add test_tpm2_migration_key test case
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
c88b36f0a9 tests: Add TPM 2 test case tpm_tpm2_resume_volatile
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
f84a0f11b5 tests: Add test case for testing TPM 2 volatile state
Add a test case that tests the TPM 2 volatile state. This test
requires the latest TPM2 version of libtpms that also writes the
TPM Established bit into the volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
6a110a5a7e tests: Check TPM2 state using TPM2 utilities
Check the TPM2 state using the TPM2 utilities, if available.

Create persistent state and check it, then shut down the TPM 2 and
restart it, and check the persistent state again.

Use previously created state and have the TPM 2 start with it
and check the persistent state. The persistent state must be
readable on little and big endian machines.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
023423eb41 tests: Add test cases for state suspension and resumption
libtpms preview branch tpm2-preview.rev142 enables volatile state
marshalling and unmarshalling which in turn enables the suspending
and resumption of the TPM state. This patch enables the capabilty
bits and adds test cases for testing the TPM state suspending and
resumption.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
08da93a96f swtpm_setup: Implement support for ECC keys
Implement support in swtpm_setup.sh so that the TPM's primary key
can be an ECC key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
276eee02b4 swtpm_cert: Support for Elliptic Curve keys
Provide support for creating certificates for TPM2 ECC type of keys.

Extend the test cases and the man pages.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
15226ad9a5 Support TPM 2 in swtpm_setup and swtpm_setup.sh
Support TPM 2 in swtpm_setup and swtpm_setup.sh.
Implement support for all command line options except for:
 o --take-ownership and anything related to ownership passwords
 o --lock-nvram
 o --display

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
e5ffc74dc8 swtpm_cert: Add support for TPM2
TPM2 allows the primary key to also be a signing key, so in case
--tpm2 is provided, --allow-signing can be provided as well in
case the primary can also be used for signing operations.

We use SHA256 for the signing algorithm when TPM 2 is being used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
8fcec541f8 Extend swtpm_bios with --tpm2 to support a TPM 2
Extend the swtpm_bios tool with a --tpm2 command line parameter
to support TPM 2 initialization.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
3008874c91 tests: Add test cases for TPM2
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -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
03e5abef60 tests: Skip CUSE tests if not compiled with CUSE interface
Check for a '#define WITH_CUSE 1' line in config.h to determine whether
the swtpm was compiled with the CUSE interface and skip the tests with
the CUSE interface if no such line can be found.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-11 10:35:14 -04:00
Stefan Berger
142a2974ae tests: Poll for 1 second after PID file was found to be gone
Poll for process to be gone for 1 seconds after a shutdown was requested
and it was found that the PID file had been removed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-04 16:10:27 -04:00
Stefan Berger
2fe082cde6 Use TPMLIB_SetState to set state blobs
Rather than writing to files directly and having to validate the state in
those files using TPMLIB_ValidatetState(), we now use the new
TPMLIB_SetState() call to set the TPM's state blobs. The advantage of this
call is that it doesn't overwrite state files and ends up leaving state in
files that the TPM cannot use. Instead, it validates the state immediately
when the blob is set and returns an error in case the state cannot be
accepted.

We need to adapt one test case that now gets a failure earlier than before.
Before the TPM_INIT failed, now setting the encrypted blob fails because it
cannot be decrypted and thus cannot be accepted by the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-14 09:22:11 -04:00
Stefan Berger
029e1bd05a tests: wait for 0.5 seconds before swtpm must be gone
To avoid test failures in test_ctrchannel2 due to the swtpm process
still running after it has removed the PID file, give it 0.5 seconds
to actually terminate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-04 13:45:21 -04:00
Stefan Berger
f0a22e6e32 tests: set PATH so swtpm_cert can be found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 11:58:59 -04:00
Stefan Berger
e2951df791 swtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert
Use the new --info parameter for swtpm_ioctl to get TPM specification
info from the swtpm and use this as a parameter for creating the EK
certificate.

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:03:43 -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
d40700020b tests: source common rather than test_common 2018-04-23 09:56:40 -04:00
Stefan Berger
a8667992e0 tests: Use a root CA for creating the issuercert for test_swtpm_cert
Update the test case test_swtpm_cert to have its issuercert signed
by a created root CA so that we have the Authority Key Id in the cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-17 10:52:35 -04:00
Stefan Berger
68baacd721 swtpm_cert: Add Subject Directory Attributes to EK cert
Create the TPMSpecification SEQUENCE and add it to the subject
directory attributes of an EK cert.

The code generates the same ASN.1 for the Subject Directory Attributes
as the example in the EK spec has.

> openssl asn1parse -in ${cert} -strparse 603
    0:d=0  hl=2 l=  30 cons: SEQUENCE
    2:d=1  hl=2 l=  28 cons: SEQUENCE
    4:d=2  hl=2 l=   5 prim: OBJECT            :2.23.133.2.16
   11:d=2  hl=2 l=  19 cons: SET
   13:d=3  hl=2 l=  17 cons: SEQUENCE
   15:d=4  hl=2 l=   3 prim: UTF8STRING        :1.2
   20:d=4  hl=2 l=   4 prim: INTEGER           :41010000
   26:d=4  hl=2 l=   4 prim: INTEGER           :7B000000

Extend existing test case so they create the ASN.1 as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-16 21:22:19 -04:00
Stefan Berger
a31a26ea0a tests: test fails earlier now that blobs are validated
Loading an invalid state blobs now fails ealier since libtpms is
called to check whether it can accept the blob.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 22:04:23 -04:00
Stefan Berger
d3029efd95 tests: Fix SWTPM_EXEC to be SWTPM_EXE
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 14:24:06 -05:00
Stefan Berger
84629d2c5d build: add missing load_vtpm_proxy file for 'make dist'
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-06 10:38:03 -05:00
Marc Kleine-Budde
3f548f90a0 treewide: remove executable bit from config files and c-code
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2018-01-17 10:45:25 -05:00
Stefan Berger
d0f4f18352 tests: Also TPM 1.2 a valid buffer size range
Adapt the test case to check whether the TPM accepted the 4000 byte
buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-18 20:45:56 -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
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
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
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
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
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
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
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
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