Commit Graph

926 Commits

Author SHA1 Message Date
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
7a3d1cde46 samples: Enable swtpm-localca to sign with a pkcs11 URI
Allow the user to specify a pkcs11 URI in the signingkey field
in swtpm-localca.conf.

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
2bfa8312d9 swtpm_setup.sh: Replace mktemp --tmpdir=<> with TMPDIR=<> mktemp
To avoid failures with mktemp call on BSD type of systems replace
mktemp --tmpdir=<dir> with TMPDIR=<dir> mktemp, which seems more portable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
b61e8c5fb5 swtpm_setup: Use OSX specific function to get path of executable
OS X cannot resolve the path we get from genenv("_") when running a
test script on Travis (reason unknown). So we use _NSGetExecutablePath()
instead and display the path in the error message in case realpath()
fails.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
aef6895d2a travis: Run tests on OSX, install, and run quick test
Run the build on OSX as well and run a quick test that exercises
some of the config files installed in --prefix=/usr/local

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
d16b86b7b0 build-sys: Adjust localstatedir and files using it
Adjust the localstatedir variable to not have ${prefix} if
prefix is '/usr/', otherwise use ${prefix}.

Also adjust the files that were pointing to directories that
are controlled by $localstatedir.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
0432b6535c build-sys: Fix hard coded /etc path and replace with @SYSCONFDIR@
When the project is configured with --prefix=/usr/local several configuration
files are installed to /usr/local/etc but not read by the programs that
need them. This patch fixes this issue by replacing @SYSCONFDIR@ in the source
code of those files with the actual used path.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
bc4d1d0341 debian: Add missing build dependencies
3 build dependencies were missing for a clean environment.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-16 16:03:49 -05:00
Stefan Berger
a530ec8acc debian: Change architecture for swtpm-dev from all to any
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-07 13:16:30 -05:00
Stefan Berger
5311e60e55 man: Fix man pages to include short summary in NAME section
Fix the man pages to include a short summary in the NAME section.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-07 13:16:30 -05:00
Stefan Berger
ef606d4a65 build-sys: If TPM 1.2 NVRAM area tools are missing print out a warning
Allow to build without the TPM 1.2 NVRAM area tools but print out a warning
that they are needed for TPM 1.2 certificate injection.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-15 10:06:03 -05:00
Stefan Berger
eaa658cb70 build-sys: Create m4 directory on older systems
Older systems, such as RHEL 6, need the m4 directory to be created.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-15 10:06:03 -05:00
Stefan Berger
8b9484a350 man: Extend man pages for swtpm-localca.conf for pkcs11 URIs
The signingkey entry can also be a pkcs11: URI. The semilcolons in the URI
have to be escaped due to the shell reading the entries.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-11 15:25:00 -05:00
Stefan Berger
655bc4be17 swtpm_cert: Support PKCS11 URIs for a CA using a PKCS11 module for signing
For PKCS11 modules (such as SoftHSM) to sign a TPM EK or platform
certificate we use 'pkcs11:' prefixed URIs like those URIs for
TPM 1.2 starting with tpmkey:.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-11 13:44:36 -05:00
Stefan Berger
ccb00a55cd samples: Escape the GnuTLS PKCS11 URL before using in command line
GnuTLS PKCS11 URLs have ';' in the string that we need to preserve for
passing to GnuTLS. So we escape the semicolons before using them on the
command line.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-11 13:44:36 -05:00
Stefan Berger
eaf2a1db22 travis: Use ubsan (undefined behavior sanitizer) in a test run
Add another parallel test run that uses ubsan.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 20:36:25 -05:00
Stefan Berger
b8e0cbd299 swtpm: ubsan: Make 64 bit flags field of ptm_getinfo 8-byte aligned
Make the 64bit flags field of the ptm_getinfo structure 8-byte
aligned.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 20:36:25 -05:00
Stefan Berger
50af85f7fd swtpm_bios: ubsan: Use tpm_resp_header structure to access header fields
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 20:36:25 -05:00
Stefan Berger
41c8da12ce swtpm_setup.sh: First send SIGTERM to processes then (later) SIGKILL
Implement terminate_proc, which first tries to gracefully terminate a
process and then, if synchronization is requested, waits for 1 second
for it to disappear and then kills it with SIGKILL if it didn't go away.

Use this function for stop_tpm and stop_tcsd, which will first try
to send a SIGTERM to a process assuming it will terminate while we
do something else and then, in case the process needs to be restarted,
make sure that it's gone before it is restarted.

This addresses an issue where previously SIGTERM was sent to a process
before it was restarted but the restarting failed due to the previous
process still holding a lock on the file because it wasn't able to react
to the SIGTERM fast enough.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 10:08:26 -05:00
Stefan Berger
bd247379e9 swtpm: Uninstall signal handler before closing notication file descriptor
Uninstall the signal handler before we close the signal handler's
notification file descriptor so that signals received after the file
descriptor is closed do not cause an error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 10:08:26 -05:00
Stefan Berger
dff1c07dac swtpm_setup: Free memory in case of error
Free the allocated memory in case of an error condition.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 10:08:26 -05:00
Stefan Berger
ae98b04512 swtpm: Coverity: Check msg parameter upon return from recvmsg
Make sure that the msg parameter passed into recvmsg wasn't modified
by the library and verify that the pointers and sizes it contains are
still valid after the call. This addresses an issue raised by Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-21 10:45:10 -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
7fcd5fb45f travis: Add a build using asan for leak and address sanitization
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-18 21:30:57 -05:00
Stefan Berger
cc582b7abd travis: Use $(nproc) and reformat the yaml a bit
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-18 21:30:57 -05:00
Stefan Berger
31867f1abe travis: Use 2 parallel test runs
Parameterize the before_script and script phases and run two of them
in parallel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-18 21:30:57 -05:00
Stefan Berger
1ad9c01651 travis: introduce a matrix for running multiple parallel tests
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-18 21:30:57 -05:00
Stefan Berger
458ea56b9e travis: Move packages to install into addons section
Move the packages to install into the addons section and
rename the before_install section to before_script section.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-18 21:30:57 -05:00
Stefan Berger
7ad2ff99e8 travis: Use libtpms master branch now
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-18 21:30:57 -05:00
Stefan Berger
b78b6af2f8 build-sys: Set action-if-found in AC_CHECK_LIB where missing
Prevent the LIBS variable from collecting all kinds of libraries
by setting the action-if-found parameter in AC_CHECK_LIB. This
avoid linking of executables with unnecessary libraries.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-17 16:37:03 -05:00
Stefan Berger
9746786e4b swtpm_cert: Fix memory leaks
Fix various memory leaks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-17 16:37:03 -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
e0c04ff832 samples: Enable support for well known SRK password (TPM 1.2)
If tpmtool supports --srk-well-known we also support the well known
SRK password and allow the user not to provide an SRK password on
the command line.

This patch should have been applied before the previous patch that
tests this. Luckily, only very few systems have tpmtool with
--srk-well-known so that the order would matter there (and cause test
failures).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-09 15:07:54 -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
2b1398a466 swtpm_cert: use hashAlgo as parameter for signing certificates
Ceritficates for a TPM 2 have to be signed using SHA256 and those for
a TPM 1.2 have to be signed using SHA1 (following specs). We can use
either of these algorithms when using the GnuTLS TPM support since it
will create the hash and have the TPM 1.2 sign whatever it created.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-07 10:32:10 -05:00
Stefan Berger
05d8160363 swtpm_setup: Leave swtpm_setup.sh ownership to root
swtpm_setup.sh does not need to be owned by tss:tss and in the
Fedora package it's not even allowed. So remove the install hook
that was changing the ownership.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-06 15:28:53 -05:00
Stefan Berger
588c06362b samples: Require an SRK password for TPM 1.2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:23:11 -05:00
Stefan Berger
7be0768859 samples: Return result code from expect script to caller
Return the result code from the expect script to the caller.
Also, display possible log messages in case the private key file
was not written properly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:23:11 -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
79edd90c90 swtpm_setup: Implement option to backup TCSD's system_ps_file
Implement the --tcsp-system-ps-file option to make a backup of
TCSD's system_ps_file for later use of the setup TPM with the
TCSD. We need this for a test case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:15:48 -05:00
Stefan Berger
c782a85a8f debian: we need python3-twisted for a test case
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-29 21:21:22 +00:00