]> git.proxmox.com Git - swtpm.git/log
swtpm.git
5 years agoswtpm_setup: Use swtpm_ioctl to re-init the TPM 1.2 for activation
Stefan Berger [Wed, 3 Jul 2019 01:18:51 +0000 (21:18 -0400)]
swtpm_setup: Use swtpm_ioctl to re-init the TPM 1.2 for activation

Since we can only read the file descriptor for the passphrase once,
we cannot stop the TPM 1.2 and then restart it but we have to use
'swtpm_ioctl -i' to re-init it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm_setup: Redirect error output of swtpm_bios to stdout
Stefan Berger [Tue, 2 Jul 2019 23:33:06 +0000 (19:33 -0400)]
swtpm_setup: Redirect error output of swtpm_bios to stdout

Redirect the stderr output of swtpm_bioc to stdout so we can
capture the message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoman: Fix typos in swtpm_setup man page
Stefan Berger [Mon, 1 Jul 2019 00:39:58 +0000 (20:39 -0400)]
man: Fix typos in swtpm_setup man page

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotest: Make sure that when key is passed state is encrypted
Stefan Berger [Thu, 27 Jun 2019 22:49:26 +0000 (18:49 -0400)]
test: Make sure that when key is passed state is encrypted

Make sure that when keyfile/keyfile-fd or pwdfile/pwdfile-fd are passed
to swtpm_setup that the resulting state is actually encrypted. We check
for encrypted state by making sure that 4-byte sequences of 0-bytes are
not there while they are there for un-encrypted state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoman: Update swtpm_setup page with the new options for passing file descriptors
Stefan Berger [Thu, 27 Jun 2019 23:13:01 +0000 (19:13 -0400)]
man: Update swtpm_setup page with the new options for passing file descriptors

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotest: Test passing file descriptor to swtpm_setup
Stefan Berger [Thu, 27 Jun 2019 22:32:29 +0000 (18:32 -0400)]
test: Test passing file descriptor to swtpm_setup

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm_setup: Allow passing file descriptor for key or password files
Stefan Berger [Thu, 27 Jun 2019 22:29:56 +0000 (18:29 -0400)]
swtpm_setup: Allow passing file descriptor for key or password files

Also extend swtpm_setup to allow passing the file descriptor for
the key or password files or pipes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Add missing pwdfd=<fd> to help screen
Stefan Berger [Thu, 27 Jun 2019 20:58:16 +0000 (16:58 -0400)]
swtpm: Add missing pwdfd=<fd> to help screen

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Convert existing test case to use file descriptor for reading password
Stefan Berger [Fri, 21 Jun 2019 20:03:11 +0000 (16:03 -0400)]
tests: Convert existing test case to use file descriptor for reading password

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoman: Update man pages to document file descriptor for reading password
Stefan Berger [Fri, 21 Jun 2019 19:59:40 +0000 (15:59 -0400)]
man: Update man pages to document file descriptor for reading password

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Enable reading password file from file descriptor
Stefan Berger [Fri, 21 Jun 2019 19:44:05 +0000 (15:44 -0400)]
swtpm: Enable reading password file from file descriptor

Enable reading the password file from a file descriptor using
--key pwdfd=<fd>

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Get rid of stat() in key_read_pwdfile_fd
Stefan Berger [Fri, 21 Jun 2019 19:40:00 +0000 (15:40 -0400)]
swtpm: Get rid of stat() in key_read_pwdfile_fd

Get rid of stat() so that we can read from pipes as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Use len as parameter to SHA512
Stefan Berger [Fri, 21 Jun 2019 19:46:34 +0000 (15:46 -0400)]
swtpm: Use len as parameter to SHA512

filelen is the length of the file as it was stat'ed. len is
the number of bytes read. They should be the same. So, use
len as a parameter to SHA512() rather than filelen.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Factor out key_load_pwdfile_fd from key_load_pwdfile
Stefan Berger [Fri, 21 Jun 2019 19:30:47 +0000 (15:30 -0400)]
swtpm: Factor out key_load_pwdfile_fd from key_load_pwdfile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agotests: Convert existing test case to use file descriptor for reading key
Stefan Berger [Fri, 21 Jun 2019 19:00:32 +0000 (15:00 -0400)]
tests: Convert existing test case to use file descriptor for reading key

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoman: Update man pages to document file descriptor for reading key
Stefan Berger [Fri, 21 Jun 2019 18:46:54 +0000 (14:46 -0400)]
man: Update man pages to document file descriptor for reading key

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Enable reading key from file descriptor passed via option
Stefan Berger [Fri, 21 Jun 2019 18:42:31 +0000 (14:42 -0400)]
swtpm: Enable reading key from file descriptor passed via option

Enable reading the state encryption or migration keys using a
file descriptor passed via the command line option parameter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Factor out key_load_key_fd from key_load_key
Stefan Berger [Fri, 21 Jun 2019 18:35:54 +0000 (14:35 -0400)]
swtpm: Factor out key_load_key_fd from key_load_key

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Consolidate the exit of parse_key_options
Stefan Berger [Fri, 21 Jun 2019 18:28:09 +0000 (14:28 -0400)]
swtpm: Consolidate the exit of parse_key_options

Consolidate the exist of the parse_key_options function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agoswtpm: Add missing kdf option documentation to help screen
Stefan Berger [Fri, 21 Jun 2019 18:18:27 +0000 (14:18 -0400)]
swtpm: Add missing kdf option documentation to help screen

Add missing kdf option documentation to help screen. The kdf
option parameter support has been there since 0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agotests: Do not run key derivation test on ppc64
Stefan Berger [Thu, 20 Jun 2019 14:32:05 +0000 (10:32 -0400)]
tests: Do not run key derivation test on ppc64

The old prime number generation algorithm also does not return
the same numbers on ppc64 (big endian) as on x86_64 or ppc64le,
so do not run the test there.

Signed-off-by: Stefan Berger <stefanb@linu.ibm.com>
5 years agotests: Add test case for deriving key from primary key
Stefan Berger [Tue, 18 Jun 2019 15:41:31 +0000 (11:41 -0400)]
tests: Add test case for deriving key from primary key

Add a test case that tests the derivation of an EC key from the
primary key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Ensure that derived keys are always the same for the same state
Stefan Berger [Fri, 14 Jun 2019 00:07:12 +0000 (20:07 -0400)]
tests: Ensure that derived keys are always the same for the same state

Using the same initial state, the derived keys always have to be the
same.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: CUSE TPM needs prtcl syscall for thread pool support
Stefan Berger [Fri, 14 Jun 2019 02:05:51 +0000 (22:05 -0400)]
swtpm: CUSE TPM needs prtcl syscall for thread pool support

The CUSE TPM needs the prctl syscall to function correctly when
commands are passed via the thread pool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Use tag v1470 for revision of ibmtss2 test suite
Stefan Berger [Thu, 6 Jun 2019 00:55:38 +0000 (20:55 -0400)]
tests: Use tag v1470 for revision of ibmtss2 test suite

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoTravis: Set LIBTPMS_CFLAGS when sanitizing swtpm
Stefan Berger [Wed, 17 Apr 2019 22:25:05 +0000 (18:25 -0400)]
Travis: Set LIBTPMS_CFLAGS when sanitizing swtpm

Set the LIBTPMS_CFLAGS for libtpms to sanitize the same as we sanitize
in swtpm. Also set UBSAN_OPTIONS and ASAN_OPTIONS for directing runtime
behavior to halt_on_error=1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Fix illegal heap access while parsing options
Stefan Berger [Wed, 17 Apr 2019 22:08:03 +0000 (18:08 -0400)]
swtpm: Fix illegal heap access while parsing options

Fix an illegal heap access while parsing the options by making
sure that we do not access the tok variable beyond its size
when comparing a character to '=' and later on when accessing
the value after the '='.

This bug was discovered by configuring as follows on Fedora 28:
  CFLAGS="-fsanitize=address -g -ggdb" LIBS="-lasan" \
    ./configure --prefix=/usr

and running tests like this:

  sudo bash -c "SWTPM_TEST_EXPENSIVE=1 make -j32 check"

The test case test_tpm2_ctrlchannel2 indicated the error.

It looks like gcc on Ubuntu Xenial on Travis did not detect this
error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Add 9 more syscalls to seccomp profile blacklist
Stefan Berger [Fri, 12 Apr 2019 16:42:13 +0000 (12:42 -0400)]
swtpm: Add 9 more syscalls to seccomp profile blacklist

Add 9 more syscalls of concern to the seccomp profile blacklist.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: wait for file content in wait_for_file
Stefan Berger [Mon, 8 Apr 2019 11:27:47 +0000 (07:27 -0400)]
tests: wait for file content in wait_for_file

When the PID_FILE is passed to swtpm as a file descriptor in one test,
we already create a file without content when running
'exec 100<>$PID_FILE'. So we have to extend wait_for_file to also
wait for file content since the 0.2 seconds delay are sometimes not
enough for content to have been written. Otherwise we do not get the
PID of the process. We can extend the function in this way since all
its usages imply that some content should become available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Convert test case to use IPv6 bindaddr ::1 where available
Stefan Berger [Thu, 4 Apr 2019 16:13:21 +0000 (12:13 -0400)]
tests: Convert test case to use IPv6 bindaddr ::1 where available

Use the IPv6 bindaddr ::1 where available on Linux. Travis doesn't
seem to support IPv6 addresses at the moment.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm_bios: Switch to use getaddrinfo to also support IPv6
Stefan Berger [Thu, 4 Apr 2019 16:10:12 +0000 (12:10 -0400)]
swtpm_bios: Switch to use getaddrinfo to also support IPv6

Switch the lookup of the address to use getaddrinfo so IPv6 also works.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm_ioctl: Switch to use getaddrinfo to also support IPv6
Stefan Berger [Thu, 4 Apr 2019 16:09:00 +0000 (12:09 -0400)]
swtpm_ioctl: Switch to use getaddrinfo to also support IPv6

Switch the lookup of the address to use getaddrinfo so IPv6 also works.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotravis: Run cpp-coveralls without sudo
Stefan Berger [Wed, 3 Apr 2019 15:57:56 +0000 (11:57 -0400)]
travis: Run cpp-coveralls without sudo

Adjust directory and file ownerships so that we don't have to
run cpp-coveralls under sudo.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Add support for fd_to_filename on OS X and test it
Stefan Berger [Wed, 3 Apr 2019 11:25:59 +0000 (07:25 -0400)]
swtpm: Add support for fd_to_filename on OS X and test it

Extend the previously modified test case to also test on
Darwin now that we are able to convert a file descriptor
to a filename.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Use a file descriptor for the pid file on Linux and Cygwin
Stefan Berger [Wed, 3 Apr 2019 11:06:05 +0000 (07:06 -0400)]
tests: Use a file descriptor for the pid file on Linux and Cygwin

On Linux and Cygwin we can pass a file descriptor for the pid
file, on other platforms it doesn't work (yet).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Pass --runas parameter to swtpm
Stefan Berger [Tue, 2 Apr 2019 14:28:06 +0000 (10:28 -0400)]
tests: Pass --runas parameter to swtpm

Pass the --runas parameter to swtpm so we can test switching it
to a given user 'nobody'.

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

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Use file descriptor passing for log file
Stefan Berger [Tue, 2 Apr 2019 14:04:16 +0000 (10:04 -0400)]
tests: Use file descriptor passing for log file

Convert test case to use file descriptor passing for the log file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Pass file ownership using uid and gid
Stefan Berger [Tue, 2 Apr 2019 13:37:26 +0000 (09:37 -0400)]
tests: Pass file ownership using uid and gid

Pass file ownership using the uid= and gid= parameters when run
as root and check the result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Use mode= to set file mode bits in test and check them
Stefan Berger [Tue, 2 Apr 2019 13:22:58 +0000 (09:22 -0400)]
tests: Use mode= to set file mode bits in test and check them

Use the mode= parameter of the TPM's state file and a unix
socket to have swtpm set the file mode bits and check that
they are set as expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agogitignore: Ignore files related to gcov
Stefan Berger [Tue, 2 Apr 2019 18:40:54 +0000 (14:40 -0400)]
gitignore: Ignore files related to gcov

Ignore files related to gcov.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
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>