]> git.proxmox.com Git - swtpm.git/log
swtpm.git
5 years agotests: Use file descriptor 100 rather than 200 (fix OpenBSD)
Stefan Berger [Tue, 2 Apr 2019 13:42:52 +0000 (09:42 -0400)]
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>
5 years agotravis: Exclude libtpms directory from coverage reporting
Stefan Berger [Tue, 2 Apr 2019 11:06:21 +0000 (07:06 -0400)]
travis: Exclude libtpms directory from coverage reporting

Exclude libtpms directory from coverage reporting.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Fix return code of change_process_owner
Stefan Berger [Tue, 2 Apr 2019 16:13:03 +0000 (12:13 -0400)]
swtpm: Fix return code of change_process_owner

The return code of change_process_owner must be negative.
This patch fixes one occurrence.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Add yet more tests for TPM 1.2 and enable auditing
Stefan Berger [Fri, 29 Mar 2019 20:52:54 +0000 (16:52 -0400)]
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>
5 years agotests: Fix some issues with TPM 1.2 test
Stefan Berger [Fri, 29 Mar 2019 16:19:15 +0000 (12:19 -0400)]
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>
5 years agotests: Add test case running TPM 1.2 test suite
Stefan Berger [Thu, 28 Mar 2019 23:10:57 +0000 (19:10 -0400)]
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>
5 years agotests: Use an empty options file in case options file is accessed
Stefan Berger [Mon, 25 Mar 2019 21:04:02 +0000 (17:04 -0400)]
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>
5 years agobuild-sys: Avoid prefix=NONE if no prefix is passed to configure
Stefan Berger [Thu, 21 Mar 2019 17:17:17 +0000 (13:17 -0400)]
build-sys: Avoid prefix=NONE if no prefix is passed to configure

If no prefix is passed to the configure line we get prefix=NONE
in evaluations of variables that depend on prefix at this point.
If the user provides no --prefix we assume /usr/local as the
default and override the 'NONE' value we have at this point.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoman: Add documentation about --seccomp option to man pages
Stefan Berger [Thu, 14 Mar 2019 21:28:04 +0000 (17:28 -0400)]
man: Add documentation about --seccomp option to man pages

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodocs: Add entry to CHANGES file about seccomp profile
Stefan Berger [Thu, 14 Mar 2019 21:23:10 +0000 (17:23 -0400)]
docs: Add entry to CHANGES file about seccomp profile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agopackages: Add libseccomp-devel to rpm and debian build deps
Stefan Berger [Thu, 14 Mar 2019 21:21:40 +0000 (17:21 -0400)]
packages: Add libseccomp-devel to rpm and debian build deps

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Extend tests cases with test for active seccomp profiles
Stefan Berger [Mon, 18 Mar 2019 13:36:11 +0000 (09:36 -0400)]
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>
5 years agoswtpm: Enable support for seccomp profile
Stefan Berger [Thu, 14 Mar 2019 14:18:22 +0000 (10:18 -0400)]
swtpm: Enable support for seccomp profile

Enable support for the seccomp blacklist profile that is
enabled by default and can be disabled using the following option:

--seccomp action=none

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Extend options parse for parsing seccomp options
Stefan Berger [Thu, 14 Mar 2019 14:16:02 +0000 (10:16 -0400)]
swtpm: Extend options parse for parsing seccomp options

Extend the parse that parses the seccomp options like:

--seccomp action=none|log|kill

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Implement function to build a blacklist seccomp profile for swtpm
Stefan Berger [Thu, 14 Mar 2019 14:13:07 +0000 (10:13 -0400)]
swtpm: Implement function to build a blacklist seccomp profile for swtpm

We build a blacklist of syscalls that we don't want the swtpm to ever be
able to execute.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoTravis: Add libseccomp-dev to packages to install
Stefan Berger [Thu, 14 Mar 2019 17:46:24 +0000 (13:46 -0400)]
Travis: Add libseccomp-dev to packages to install

Do not run the 'asan' test with seccomp compiled in since the asan
libraries seem to use syscalls that we blacklist in the seccomp
profile. In particular those are:

- clone
- sigaltstack
- ptrace

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agobuild-sys: Add libbsecomp to configure.ac
Stefan Berger [Wed, 13 Mar 2019 22:27:53 +0000 (18:27 -0400)]
build-sys: Add libbsecomp to configure.ac

Implement support for --with-seccomp and --without-seccomp for Linux
systems with --with-seccomp being the default. On all other systems
--without-seccomp is the implicit default.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: implement uninstall_sighandlers
Stefan Berger [Wed, 13 Mar 2019 21:04:29 +0000 (17:04 -0400)]
swtpm: implement uninstall_sighandlers

Implement uninstall sighandlers to uninstall the signal handlers
and not to create another pipe.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm-setup: follow XDG spec more closely for default config
Marc-André Lureau [Tue, 19 Feb 2019 15:36:23 +0000 (16:36 +0100)]
swtpm-setup: follow XDG spec more closely for default config

According to the XDG spec,
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html:
"If $XDG_CONFIG_HOME is either not set or empty, a default equal to
$HOME/.config should be used."

This fixes setting up a TPM with libvirt running in a user session.

It works by checking if configuration files are readable in the
directory priority order (XDG_CONFIG_HOME, then HOME, then SYSCONFDIR).

When libvirt is running as a system instance, $HOME isn't set, so it
will fall back on @SYSCONFDIR@ (/etc usually)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agorpm: Adjust RPM spec file for 0.1 release
Stefan Berger [Mon, 4 Feb 2019 21:00:18 +0000 (16:00 -0500)]
rpm: Adjust RPM spec file for 0.1 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoTravis: Get Travis to submit to Coverity again
Stefan Berger [Fri, 1 Feb 2019 19:29:58 +0000 (14:29 -0500)]
Travis: Get Travis to submit to Coverity again

The extension of the travis.yml with the matrix broke the Coverity
submission. This patch fixes this. We have to build libtpms in
build_command_prepend since before_script now does something different.

We only build in task .1 and exit early on all the other ones if
we are using the coverity_scan git branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoSet version to 0.2.0 for next release
Stefan Berger [Mon, 4 Feb 2019 19:35:38 +0000 (14:35 -0500)]
Set version to 0.2.0 for next release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodebian: Edit changelog for 0.1.0 release
Stefan Berger [Mon, 28 Jan 2019 20:59:15 +0000 (20:59 +0000)]
debian: Edit changelog for 0.1.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodoc: Create CHANGES file for initial release
Stefan Berger [Mon, 28 Jan 2019 17:41:06 +0000 (12:41 -0500)]
doc: Create CHANGES file for initial release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodebian: Fix libtpms0 dependency and force gnutls availability
Stefan Berger [Mon, 28 Jan 2019 18:13:47 +0000 (13:13 -0500)]
debian: Fix libtpms0 dependency and force gnutls availability

Libtpms is now libtpms0 as a dependency.
Gnutls is neede for swtpm_cert to create the certs. Force it to
be available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodebian: Add post install script for swtpm-tools
Stefan Berger [Mon, 28 Jan 2019 20:46:55 +0000 (20:46 +0000)]
debian: Add post install script for swtpm-tools

Add a post install script for swtpm-tools that creates
the /var/lib/swtpm-localca directory and changes ownersip
on it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agorun_test.sh: Replace -j8 with -j$(nproc)
Stefan Berger [Mon, 28 Jan 2019 19:50:14 +0000 (14:50 -0500)]
run_test.sh: Replace -j8 with -j$(nproc)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Fix error handling if pkcs11 test runs on x86_64 with i386 executable
Stefan Berger [Mon, 28 Jan 2019 19:46:35 +0000 (14:46 -0500)]
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>
5 years agotest: Replace uname -o with uname -s
Stefan Berger [Wed, 23 Jan 2019 21:52:16 +0000 (16:52 -0500)]
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>
5 years agotests: Use wait_process_gone rather than sleep
Stefan Berger [Wed, 23 Jan 2019 21:39:13 +0000 (16:39 -0500)]
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>
5 years agoMake softhsm/pkcs11 test case work on Travis on OS X
Stefan Berger [Wed, 23 Jan 2019 17:56:13 +0000 (12:56 -0500)]
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>
5 years agotests: Make the test case work on OS X
Stefan Berger [Tue, 22 Jan 2019 21:46:58 +0000 (16:46 -0500)]
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>
5 years agotests: Add test case that uses a pkcs11 URI for signing a cert
Stefan Berger [Tue, 22 Jan 2019 20:59:24 +0000 (15:59 -0500)]
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>
5 years agosamples: Enable swtpm-localca to sign with a pkcs11 URI
Stefan Berger [Tue, 22 Jan 2019 21:02:13 +0000 (16:02 -0500)]
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>
5 years agotests: Gate the IBM TSS 2 related test with SWTPM_TEST_IBMTSS2
Stefan Berger [Thu, 17 Jan 2019 23:45:55 +0000 (18:45 -0500)]
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>
5 years agotests: Set TPM_INTERFACE_TYPE=socsim
Stefan Berger [Thu, 17 Jan 2019 23:42:54 +0000 (18:42 -0500)]
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>
5 years agotests: Remove 'less' command from test case
Stefan Berger [Thu, 17 Jan 2019 22:08:02 +0000 (17:08 -0500)]
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>
5 years agoswtpm_setup.sh: Replace mktemp --tmpdir=<> with TMPDIR=<> mktemp
Stefan Berger [Thu, 17 Jan 2019 15:22:03 +0000 (10:22 -0500)]
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>
5 years agoswtpm_setup: Use OSX specific function to get path of executable
Stefan Berger [Thu, 17 Jan 2019 11:27:23 +0000 (06:27 -0500)]
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>
5 years agotravis: Run tests on OSX, install, and run quick test
Stefan Berger [Wed, 16 Jan 2019 17:00:05 +0000 (12:00 -0500)]
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>
5 years agobuild-sys: Adjust localstatedir and files using it
Stefan Berger [Wed, 16 Jan 2019 16:04:49 +0000 (16:04 +0000)]
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>
5 years agobuild-sys: Fix hard coded /etc path and replace with @SYSCONFDIR@
Stefan Berger [Wed, 16 Jan 2019 13:49:51 +0000 (08:49 -0500)]
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>
5 years agodebian: Add missing build dependencies
Stefan Berger [Wed, 16 Jan 2019 20:46:53 +0000 (20:46 +0000)]
debian: Add missing build dependencies

3 build dependencies were missing for a clean environment.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodebian: Change architecture for swtpm-dev from all to any
Stefan Berger [Mon, 7 Jan 2019 17:42:26 +0000 (17:42 +0000)]
debian: Change architecture for swtpm-dev from all to any

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoman: Fix man pages to include short summary in NAME section
Stefan Berger [Mon, 7 Jan 2019 17:06:58 +0000 (17:06 +0000)]
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>
5 years agobuild-sys: If TPM 1.2 NVRAM area tools are missing print out a warning
Stefan Berger [Sat, 15 Dec 2018 14:07:50 +0000 (08:07 -0600)]
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>
5 years agobuild-sys: Create m4 directory on older systems
Stefan Berger [Sat, 15 Dec 2018 14:06:42 +0000 (08:06 -0600)]
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>
5 years agoman: Extend man pages for swtpm-localca.conf for pkcs11 URIs
Stefan Berger [Tue, 11 Dec 2018 20:21:34 +0000 (15:21 -0500)]
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>
5 years agoswtpm_cert: Support PKCS11 URIs for a CA using a PKCS11 module for signing
Stefan Berger [Tue, 30 Oct 2018 13:32:13 +0000 (09:32 -0400)]
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>
5 years agosamples: Escape the GnuTLS PKCS11 URL before using in command line
Stefan Berger [Mon, 22 Oct 2018 22:17:00 +0000 (18:17 -0400)]
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>
5 years agotravis: Use ubsan (undefined behavior sanitizer) in a test run
Stefan Berger [Fri, 23 Nov 2018 23:32:39 +0000 (18:32 -0500)]
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>
5 years agoswtpm: ubsan: Make 64 bit flags field of ptm_getinfo 8-byte aligned
Stefan Berger [Sat, 24 Nov 2018 01:21:08 +0000 (20:21 -0500)]
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>
5 years agoswtpm_bios: ubsan: Use tpm_resp_header structure to access header fields
Stefan Berger [Sat, 24 Nov 2018 01:19:26 +0000 (20:19 -0500)]
swtpm_bios: ubsan: Use tpm_resp_header structure to access header fields

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm_setup.sh: First send SIGTERM to processes then (later) SIGKILL
Stefan Berger [Thu, 22 Nov 2018 16:16:28 +0000 (11:16 -0500)]
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>
5 years agoswtpm: Uninstall signal handler before closing notication file descriptor
Stefan Berger [Thu, 22 Nov 2018 20:46:09 +0000 (15:46 -0500)]
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>
5 years agoswtpm_setup: Free memory in case of error
Stefan Berger [Thu, 22 Nov 2018 15:55:48 +0000 (10:55 -0500)]
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>
5 years agoswtpm: Coverity: Check msg parameter upon return from recvmsg
Stefan Berger [Mon, 19 Nov 2018 18:53:38 +0000 (13:53 -0500)]
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>
5 years agotests: Use bash's built-in echo rather than /bin/echo
Stefan Berger [Mon, 19 Nov 2018 23:43:30 +0000 (18:43 -0500)]
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>
5 years agotests: Convert test case to also use binary formatted key
Stefan Berger [Mon, 19 Nov 2018 22:00:53 +0000 (17:00 -0500)]
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>
5 years agotests: Add missing file sizes and some other reorg to test case
Stefan Berger [Mon, 19 Nov 2018 21:22:34 +0000 (16:22 -0500)]
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>
5 years agotravis: Add a build using asan for leak and address sanitization
Stefan Berger [Sun, 18 Nov 2018 23:50:38 +0000 (18:50 -0500)]
travis: Add a build using asan for leak and address sanitization

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotravis: Use $(nproc) and reformat the yaml a bit
Stefan Berger [Sun, 18 Nov 2018 23:41:09 +0000 (18:41 -0500)]
travis: Use $(nproc) and reformat the yaml a bit

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotravis: Use 2 parallel test runs
Stefan Berger [Sun, 18 Nov 2018 23:27:28 +0000 (18:27 -0500)]
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>
5 years agotravis: introduce a matrix for running multiple parallel tests
Stefan Berger [Sun, 18 Nov 2018 23:18:50 +0000 (18:18 -0500)]
travis: introduce a matrix for running multiple parallel tests

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotravis: Move packages to install into addons section
Stefan Berger [Sun, 18 Nov 2018 22:54:26 +0000 (17:54 -0500)]
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>
5 years agotravis: Use libtpms master branch now
Stefan Berger [Sun, 18 Nov 2018 22:50:17 +0000 (17:50 -0500)]
travis: Use libtpms master branch now

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agobuild-sys: Set action-if-found in AC_CHECK_LIB where missing
Stefan Berger [Sat, 17 Nov 2018 20:29:53 +0000 (15:29 -0500)]
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>
5 years agoswtpm_cert: Fix memory leaks
Stefan Berger [Sat, 17 Nov 2018 20:07:40 +0000 (15:07 -0500)]
swtpm_cert: Fix memory leaks

Fix various memory leaks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Allow passing SWTPM_CERT from command line
Stefan Berger [Sat, 17 Nov 2018 19:59:24 +0000 (14:59 -0500)]
tests: Allow passing SWTPM_CERT from command line

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agosamples: Enable support for well known SRK password (TPM 1.2)
Stefan Berger [Fri, 9 Nov 2018 20:01:09 +0000 (15:01 -0500)]
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>
5 years agotests: Extend swtpm-create-tpmca test with 'well known' password
Stefan Berger [Tue, 6 Nov 2018 21:19:13 +0000 (16:19 -0500)]
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>
5 years agotests: Refactor swtpm-create-tpmca test for easier extension
Stefan Berger [Tue, 6 Nov 2018 18:21:46 +0000 (13:21 -0500)]
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>
5 years agoswtpm_cert: use hashAlgo as parameter for signing certificates
Stefan Berger [Wed, 7 Nov 2018 14:40:32 +0000 (09:40 -0500)]
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>
5 years agoswtpm_setup: Leave swtpm_setup.sh ownership to root
Stefan Berger [Tue, 6 Nov 2018 20:03:41 +0000 (15:03 -0500)]
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>
5 years agosamples: Require an SRK password for TPM 1.2
Stefan Berger [Mon, 5 Nov 2018 01:16:39 +0000 (20:16 -0500)]
samples: Require an SRK password for TPM 1.2

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agosamples: Return result code from expect script to caller
Stefan Berger [Thu, 1 Nov 2018 20:35:40 +0000 (16:35 -0400)]
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>
5 years agotests: Add a test case for the TPM CA setup script
Stefan Berger [Mon, 5 Nov 2018 18:22:13 +0000 (13:22 -0500)]
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>
5 years agoswtpm_setup: Implement option to backup TCSD's system_ps_file
Stefan Berger [Mon, 5 Nov 2018 18:19:17 +0000 (13:19 -0500)]
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>
5 years agodebian: we need python3-twisted for a test case
Stefan Berger [Mon, 29 Oct 2018 21:21:22 +0000 (21:21 +0000)]
debian: we need python3-twisted for a test case

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotravis: Integrate with Coveralls.io
Stefan Berger [Thu, 25 Oct 2018 12:59:52 +0000 (08:59 -0400)]
travis: Integrate with Coveralls.io

Integrate the Travis builds with Coveralls.io by sumitting the coverage
results to Coveralls.io.

We have to run the coveralls script with sudo rights since otherwise we
get permission denied errors.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agobuild-sys: Support --enable-test-coverage as an option
Stefan Berger [Thu, 25 Oct 2018 00:29:00 +0000 (20:29 -0400)]
build-sys: Support --enable-test-coverage as an option

Support --enable-test-coverage as an option for compiling with
coverage instrumentation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agobuild-sys: Support --disable-hardening as an option
Stefan Berger [Wed, 24 Oct 2018 23:39:22 +0000 (19:39 -0400)]
build-sys: Support --disable-hardening as an option

By default the hardening compiler flags are enabled and
--disable-hardening disables them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Have the CUSE TPM return the original TPM start error code
Stefan Berger [Thu, 25 Oct 2018 00:21:59 +0000 (20:21 -0400)]
swtpm: Have the CUSE TPM return the original TPM start error code

Have the CUSE TPM return the TPM start error, particularly
TPM_DECRYPT_ERROR in case a wrong key was passed, rather than the plain
TPM_FAIL error code. This was a difference with the 'other' swtpm
interfaces that already returned the original error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agosamples: Fix a typo
Stefan Berger [Wed, 24 Oct 2018 13:16:16 +0000 (09:16 -0400)]
samples: Fix a typo

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agosamples: Add support for password protected root CA priv. key
Stefan Berger [Wed, 17 Oct 2018 12:15:16 +0000 (08:15 -0400)]
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>
5 years agosamples: Add a script to create a TPM 1.2 intermediate CA
Stefan Berger [Thu, 11 Oct 2018 13:44:07 +0000 (09:44 -0400)]
samples: Add a script to create a TPM 1.2 intermediate CA

This (experimental) script uses GnuTLS tpmtool to create a TPM 1.2
intermediate CA that can sign a vTPM's EK and platform certificates.

Add a man page for this tool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agosamples: Enable support for TPM 1.2 signing keys for cert signing via GnuTLS
Stefan Berger [Thu, 11 Oct 2018 12:44:09 +0000 (08:44 -0400)]
samples: Enable support for TPM 1.2 signing keys for cert signing via GnuTLS

GnuTLS can use TPM 1.2 keys for signing. For this we just need to support
key URLs in the GnuTLS format:

tpmkey:uuid=...
tpmkey:file=...

We don't try to read these URLs as files but pass them through as URLs to
the swtpm_cert tool that will then try to sign with the TPM 1.2 key by
passing the URL to GnuTLS API calls.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm_cert: Allow using a TPM 1.2 signing key for signing cert
Stefan Berger [Thu, 11 Oct 2018 12:20:04 +0000 (08:20 -0400)]
swtpm_cert: Allow using a TPM 1.2 signing key for signing cert

Gnutls supports TPM 1.2 keys in its API and we can use a TPM 1.2
signing key for signing the EK or platform certs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agosamples: Add a usage screen to swtpm-loclca to show upon --help
Stefan Berger [Thu, 11 Oct 2018 12:10:45 +0000 (08:10 -0400)]
samples: Add a usage screen to swtpm-loclca to show upon --help

swtpm-localca was missing a help screen. This patch adds it and
is shown when --help or -? or -h is passed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Check expected error output against expected error message
Stefan Berger [Sun, 7 Oct 2018 21:04:53 +0000 (17:04 -0400)]
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>
5 years agotests: Shut down swtpm at the end to avoid kill
Stefan Berger [Sun, 7 Oct 2018 20:46:40 +0000 (16:46 -0400)]
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>
5 years agotests: Return a string from get_file_hash if file not found
Stefan Berger [Sun, 7 Oct 2018 20:43:57 +0000 (16:43 -0400)]
tests: Return a string from get_file_hash if file not found

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agotests: Only run test_tpm2_samples_swtpm_localca if certtool was found
Stefan Berger [Sat, 6 Oct 2018 22:02:10 +0000 (18:02 -0400)]
tests: Only run test_tpm2_samples_swtpm_localca if certtool was found

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Rename crypto functions to have SWTPM prefix
Stefan Berger [Sat, 6 Oct 2018 21:41:53 +0000 (17:41 -0400)]
swtpm: Rename crypto functions to have SWTPM prefix

The crypto functions for AES encryption and decryption clash with crypto
function names of libtpms. Avoid this by prefixing them with SWTPM_ instead
of TPM_.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Link with -lrt if libc does not have clock_gettime()
Stefan Berger [Sat, 6 Oct 2018 01:23:21 +0000 (21:23 -0400)]
build-sys: Link with -lrt if libc does not have clock_gettime()

On older system libc does not provide clock_gettime() so we need
to link with -lrt.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Pass header file to compiler for checking for supported flag
Stefan Berger [Sat, 6 Oct 2018 01:08:04 +0000 (21:08 -0400)]
build-sys: Pass header file to compiler for checking for supported flag

Older versions of gcc need some input file to compile so that
we learn whether -fstack-protector-strong is supported.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoDo few changes to follow distribution SELinux policy
Lukas Vrabec [Fri, 5 Oct 2018 08:59:53 +0000 (10:59 +0200)]
Do few changes to follow distribution SELinux policy

5 years agotests: Get the IBM TSS2 test suite and run it
Stefan Berger [Fri, 5 Oct 2018 00:21:19 +0000 (20:21 -0400)]
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>
5 years agoSELinux: A few more rules needed by libvirt 4.4 on F28 for running QEMU
Stefan Berger [Mon, 1 Oct 2018 20:42:51 +0000 (16:42 -0400)]
SELinux: A few more rules needed by libvirt 4.4 on F28 for running QEMU

This patch adds rules that are needed for running QEMU with libvirt 4.4
on F28. This allows one to test the libvirt management stack and QEMU with
swtpm and SELinux in enforcing mode.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Move glib-2.0 dependency to CUSE TPM build
Stefan Berger [Tue, 2 Oct 2018 14:13:27 +0000 (10:13 -0400)]
build-sys: Move glib-2.0 dependency to CUSE TPM build

Only when the CUSE TPM is built we need the glib-2.0 dependency
(which can be removed at some point probably).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>