]> git.proxmox.com Git - swtpm.git/log
swtpm.git
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>
5 years agoswtpm: Use non-exclusive threads to have glib2 clean up after itself
Stefan Berger [Tue, 2 Oct 2018 13:24:43 +0000 (09:24 -0400)]
swtpm: Use non-exclusive threads to have glib2 clean up after itself

glib2 did not clean up a proxy thread once the pool was torn down. The
reason was that an exclusive pool was used. Switch to a non-exclusive
pool, which will cause the last thread to terminate as well and we have
a clean valgrind log now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agotests: wait for files to appear or disappear after starting swtpm
Stefan Berger [Mon, 1 Oct 2018 15:43:57 +0000 (11:43 -0400)]
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>
5 years agotests: Add delay after finding file for process to write into it
Stefan Berger [Mon, 1 Oct 2018 15:40:57 +0000 (11:40 -0400)]
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>
5 years agotests: Increase timeout for shutdown for running with valgrind
Stefan Berger [Mon, 1 Oct 2018 15:12:20 +0000 (11:12 -0400)]
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>
5 years agoswtpm: Initialize structure using memset
Stefan Berger [Sun, 30 Sep 2018 16:05:10 +0000 (12:05 -0400)]
swtpm: Initialize structure using memset

Gcc 4.9.2 on ARM does not like the initializer '= { 0 }', either.
So switch it to memset.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Initialize ptm_est type to avoid uninitialized bytes
Stefan Berger [Fri, 28 Sep 2018 12:23:13 +0000 (08:23 -0400)]
swtpm: Initialize ptm_est type to avoid uninitialized bytes

Valgrind complains about uninitialized bytes being accessed by a writev()
call in libfuse. It points to a line in the error branch
'error_not_running', but the error does not seem to come from there.
Instead, if we initialize ptm_est to zeros the problem goes away.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Exit CUSE TPM using fuse_session_exit()
Stefan Berger [Fri, 28 Sep 2018 12:01:00 +0000 (08:01 -0400)]
swtpm: Exit CUSE TPM using fuse_session_exit()

With the fuse_session now global, we can use it to exit the CUSE
TPM using fuse_session_exit().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Implement low level CUSE startup code to get to fuse_session
Stefan Berger [Fri, 28 Sep 2018 11:30:54 +0000 (07:30 -0400)]
swtpm: Implement low level CUSE startup code to get to fuse_session

To be able to get to the low level fuse_session data structure, which
allows us to terminate the program more gracefully than the exit() in
the ioctl processing code, we implement the low level cuse startup code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoSELinux: F27 needs allow for swtpm_exec_t:file map
Stefan Berger [Fri, 28 Sep 2018 11:16:54 +0000 (07:16 -0400)]
SELinux: F27 needs allow for swtpm_exec_t:file map

F27 needs an additional rule for starting the swtpm from libvirt.

Add the rule 'allow svirt_t swtpm_exec_t:file map'

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoSELinux: re-add allow rules for file entrypoint
Stefan Berger [Thu, 27 Sep 2018 19:35:04 +0000 (15:35 -0400)]
SELinux: re-add allow rules for file entrypoint

The file entrypoint rules are still needed, so add them back again.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm_ioctl: replace initializer with memset for gcc 4.2.1
Stefan Berger [Thu, 27 Sep 2018 01:55:52 +0000 (21:55 -0400)]
swtpm_ioctl: replace initializer with memset for gcc 4.2.1

gcc 4.2.1 does not accept the initializer '= { 0 }' and so we now switch
this to memset as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm_ioctl: Initialize structures for use with ioctl()
Stefan Berger [Thu, 27 Sep 2018 15:06:08 +0000 (11:06 -0400)]
swtpm_ioctl: Initialize structures for use with ioctl()

Valgrind complains that there are uninitialized bytes when ioctl() is called.
This is due to the fact that we are passing the structure to the ioctl()
without specifying how many bytes are valid in the passed buffer.
So, we initialize the buffers to 0 and the complaint is resolved.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agotests: Call function rather than running 'ps aux' to display proceses
Stefan Berger [Thu, 27 Sep 2018 14:14:12 +0000 (10:14 -0400)]
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>
5 years agotests: Replace kill_quiet after shutdown with wait_process_gone
Stefan Berger [Thu, 27 Sep 2018 13:59:14 +0000 (09:59 -0400)]
tests: Replace kill_quiet after shutdown with wait_process_gone

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Only copy length of user privided IV into possibly longer ivec
Stefan Berger [Wed, 26 Sep 2018 23:05:56 +0000 (19:05 -0400)]
swtpm: Only copy length of user privided IV into possibly longer ivec

When the AES encryption and decryption function were extended to support
256bit keys the size of the user ivec on the stack was also increased to
32 bytes. For the user provided IV we now must only copy 16 bytes in case
an 128 bit key is used. Fix the length parameter to the memcpy().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agorpm: Fix spec for passing fedora-review
Stefan Berger [Tue, 4 Sep 2018 16:54:42 +0000 (12:54 -0400)]
rpm: Fix spec for passing fedora-review

We seem to be missing a dependency on selinux-policy-devel, so add it.
The name of the source tar has to be set to what 'make dist' produces.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agorpm: swtpm-tools requires swtpm of the exact same version
Stefan Berger [Mon, 17 Sep 2018 20:53:41 +0000 (16:53 -0400)]
rpm: swtpm-tools requires swtpm of the exact same version

Tie swtpm-tools updating to swtpm updating and vice versa by requiring
swtpm-tools the swtpm package to have the same version.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agotests: Use python3 rather than python for the test programs
Stefan Berger [Wed, 19 Sep 2018 02:14:45 +0000 (22:14 -0400)]
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>
5 years agobuild-sys: Install libswpm_libtpms into $(libdir)/swtpm
Stefan Berger [Tue, 18 Sep 2018 19:49:47 +0000 (15:49 -0400)]
build-sys: Install libswpm_libtpms into $(libdir)/swtpm

Install the private libswtpm_libtpms into $(libdir)/swtpm
rather than into the shared libaries directory.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Replace AC_PROG_LIBTOOL with LT_INIT
Stefan Berger [Tue, 18 Sep 2018 16:23:19 +0000 (12:23 -0400)]
build-sys: Replace AC_PROG_LIBTOOL with LT_INIT

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Do not build man page or SELinux policy for CUSE if --without-cuse is...
Stefan Berger [Mon, 17 Sep 2018 20:35:00 +0000 (16:35 -0400)]
build-sys: Do not build man page or SELinux policy for CUSE if --without-cuse is used

To make the RPM building easier for the --without-cuse case we have to omit
a couple of files from being built so that they are not left-overs when
packing the RPM without building swtpm-cuse.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agorpm: Replace %bcond_with gnutls with %bcond_without gnutls
Stefan Berger [Mon, 17 Sep 2018 19:11:54 +0000 (15:11 -0400)]
rpm: Replace %bcond_with gnutls with %bcond_without gnutls

The meaning of %bcond_without is that it enables a feature by default.
We want to buld with gnutls, so enable it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agorpm: Add entry to changelog
Stefan Berger [Mon, 17 Sep 2018 17:35:34 +0000 (13:35 -0400)]
rpm: Add entry to changelog

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Fix policy package dependencies for out-of-tree build
Stefan Berger [Tue, 25 Sep 2018 12:33:53 +0000 (08:33 -0400)]
build-sys: Fix policy package dependencies for out-of-tree build

An out-of-tree build fails to build swtpm_svirt.pp due to missing
source files from the swtpm.pp policy. Add the swtpm.{te,if,fc} files
as dependencies of the swtpm_svirt.pp policy package.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Fix the SELinux policy build target for parallel builds
Stefan Berger [Mon, 17 Sep 2018 17:14:42 +0000 (13:14 -0400)]
build-sys: Fix the SELinux policy build target for parallel builds

Use .NOTPARALLEL for the SELinux policy build target to avoid running
the rule concurrently and deleting the tmp directory while another
build is running.

For some reason it is not possible to use $(MAKE) since otherwise the
building of the policy package fails.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agodocu: Cut down the README to its minimum
Stefan Berger [Tue, 18 Sep 2018 18:13:07 +0000 (14:13 -0400)]
docu: Cut down the README to its minimum

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoSELinux: Fix some nits in the SELinux policy files
Stefan Berger [Mon, 24 Sep 2018 15:14:15 +0000 (11:14 -0400)]
SELinux: Fix some nits in the SELinux policy files

This patch is partially from Lukas Vrabec (lvrabec@redhat.com) and fixes
some nits in the SELinux policy.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoSELinux: Install policy package files to /usr/share/selinux/packages
Stefan Berger [Tue, 4 Sep 2018 17:31:30 +0000 (13:31 -0400)]
SELinux: Install policy package files to /usr/share/selinux/packages

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agobuild-sys: Create compressed policy package files
Stefan Berger [Tue, 4 Sep 2018 16:39:12 +0000 (12:39 -0400)]
build-sys: Create compressed policy package files

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoSELinux: Extend SELinux policy with rules for svirt_tcg
Stefan Berger [Tue, 4 Sep 2018 16:29:13 +0000 (12:29 -0400)]
SELinux: Extend SELinux policy with rules for svirt_tcg

Extend the SELinux policy with rules for svirt_tcg when
QEMU is not being started with KVM by libvirt.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoSELinux: Fix title in interface file
Stefan Berger [Tue, 4 Sep 2018 16:27:23 +0000 (12:27 -0400)]
SELinux: Fix title in interface file

Fix the title in the interface file to say 'swtpm'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoTravis: Fix the coverity scan build
Stefan Berger [Mon, 24 Sep 2018 20:56:39 +0000 (16:56 -0400)]
Travis: Fix the coverity scan build

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoek-cert: Initialize datum variable to prevent unintialized access
Stefan Berger [Mon, 24 Sep 2018 21:34:14 +0000 (17:34 -0400)]
ek-cert: Initialize datum variable to prevent unintialized access

Coverity scan shows an uninitialized access in case an error is
encountered and the cleanup path is taken before datum was initialized.
Fix the error by initializing the variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm_cert: Fix a potential buffer overrun error
Stefan Berger [Mon, 24 Sep 2018 21:24:29 +0000 (17:24 -0400)]
swtpm_cert: Fix a potential buffer overrun error

Coverity scan discovered a buffer overrun error in case the
datum->size = 0. Fix the error.

The function with the potential error is not called if datum->size == 0.

Also make the 'size' variable larger so there cannot be a overrun in
'size = datum->size + sizeof(buffer) - i'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Initialize hdrflags to 0 in case no header was read
Stefan Berger [Mon, 24 Sep 2018 20:42:20 +0000 (16:42 -0400)]
swtpm: Initialize hdrflags to 0 in case no header was read

The hdrflags need to be initialized to 0 in case no header
was read from the file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agogit: Ignore install-sh
Stefan Berger [Mon, 17 Sep 2018 16:52:02 +0000 (12:52 -0400)]
git: Ignore install-sh

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoman: Replace bindaddress with bindaddr in swtpm man page
Stefan Berger [Mon, 17 Sep 2018 14:41:57 +0000 (10:41 -0400)]
man: Replace bindaddress with bindaddr in swtpm man page

The swtpm man page incorrectly showed binaddress as the option parameter
for the address to bind to. It must be called bindaddr.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agotests: Extend test cases with aes-256-cbc state file encryption
Stefan Berger [Mon, 17 Sep 2018 14:26:51 +0000 (10:26 -0400)]
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>
5 years agoswtpm_setup: Add support for choosing the cipher
Stefan Berger [Sat, 15 Sep 2018 18:21:52 +0000 (14:21 -0400)]
swtpm_setup: Add support for choosing the cipher

Implement command line support for choosing the cipher to use for
the TPM state encryption. Either aes-128-cbc or aes-256-cbc can be
used. The same cipher has to be passed on the swtpm command line
when using the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Check the size of the user's key against expected size
Stefan Berger [Sat, 15 Sep 2018 18:03:50 +0000 (14:03 -0400)]
swtpm: Check the size of the user's key against expected size

Use the flags in the header to check the size of the provided key(s) against
the one(s) from the user. There are the state and migration keys, each has
a different flag in the header if a 256bit key was used. We display an error
about the mismatching key size against expected size if the given key is of
the wrong size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Add support for aes-256-cbc
Stefan Berger [Sat, 15 Sep 2018 00:19:03 +0000 (20:19 -0400)]
swtpm: Add support for aes-256-cbc

Extend the buffer the key is read into to hold an 256bit key.

Add support for aes-256-cbc. Also, aes-128-cbc is now a synonym for
aes-cbc.

Update the man pages to reflect the AES 128 support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Extend en- and decryption functions for 256 bit keys
Stefan Berger [Fri, 14 Sep 2018 23:38:54 +0000 (19:38 -0400)]
swtpm: Extend en- and decryption functions for 256 bit keys

Enable 256 bit AES keys in the en- and decryption functions.
Set a flag in the header to at least indicate whether 128bit
or 256bit keys were used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Prepare key parsing functions to accept 256 bit keys
Stefan Berger [Fri, 14 Sep 2018 23:32:53 +0000 (19:32 -0400)]
swtpm: Prepare key parsing functions to accept 256 bit keys

Prepare the functions that parse or read the key from a file
to accept 256 bit keys.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Remove unnecessary fields from symmetric key structure
Stefan Berger [Fri, 14 Sep 2018 23:00:33 +0000 (19:00 -0400)]
swtpm: Remove unnecessary fields from symmetric key structure

Remove the valid field from the symmtric key structure and
user userKeyLength > 0 instead, which is the same.

Also remove the tag and fill fields, which were originally used in
TPM 1.2.

Use function calls to test whether the file or migration key is
available where possible.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Add key length to symmetric key structure
Stefan Berger [Fri, 14 Sep 2018 22:49:03 +0000 (18:49 -0400)]
swtpm: Add key length to symmetric key structure

To get rid of the hard coded AES key size of 128, we add a filed
userKeyLength that describes the length of the key being used.
We replace TPM_AES_BLOCK_SIZE with userKeyLength where possible.

Rename TPM_AES_BLOCK_SIZE to SWTPM_AES_BLOCK_SIZE.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
5 years agoswtpm: Use pbkdf2 as default kdf and sha512 for test cases
Stefan Berger [Fri, 14 Sep 2018 21:37:08 +0000 (17:37 -0400)]
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>