]> git.proxmox.com Git - swtpm.git/log
swtpm.git
3 years agodebian/rpm: Adjust changelog for 0.6.0 release
Stefan Berger [Wed, 2 Jun 2021 20:21:56 +0000 (16:21 -0400)]
debian/rpm: Adjust changelog for 0.6.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoCHANGES: Add more documentation for changes in 0.6.0
Stefan Berger [Wed, 2 Jun 2021 20:02:13 +0000 (16:02 -0400)]
CHANGES: Add more documentation for changes in 0.6.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Add HARDENING_CFLAGS and _LDFLAGS to all C programs
Stefan Berger [Fri, 4 Jun 2021 12:04:21 +0000 (08:04 -0400)]
build-sys: Add HARDENING_CFLAGS and _LDFLAGS to all C programs

Add the HARDENING_CFLAGS and _LDFLAGS to all C programs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Add 2021 as year in the Copyright notice
Stefan Berger [Thu, 3 Jun 2021 20:34:25 +0000 (16:34 -0400)]
swtpm: Add 2021 as year in the Copyright notice

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoTravis: Remove much of the python related stuff
Stefan Berger [Thu, 3 Jun 2021 15:50:15 +0000 (11:50 -0400)]
Travis: Remove much of the python related stuff

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agodebian/rpm: Remove left-over python files that do not exist anymore
Stefan Berger [Wed, 2 Jun 2021 20:28:13 +0000 (16:28 -0400)]
debian/rpm: Remove left-over python files that do not exist anymore

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Display json-glib and glib related cflags and libs
Stefan Berger [Thu, 3 Jun 2021 15:10:38 +0000 (11:10 -0400)]
build-sys: Display json-glib and glib related cflags and libs

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Fix the strjoin for the PID file path
Stefan Berger [Thu, 3 Jun 2021 21:08:10 +0000 (17:08 -0400)]
swtpm_setup: Fix the strjoin for the PID file path

The path for the PID file was not joined correctly and was missing
a '/'. Fix this now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_localca: Adjust expiration days for 32-bit platforms
Stefan Berger [Thu, 3 Jun 2021 14:18:21 +0000 (10:18 -0400)]
swtpm_localca: Adjust expiration days for 32-bit platforms

GnuTLS on 32-bit platforms complains about the long expiration time
of the certificates since they overflow the 32-bit time_t. Reduce
the duration to 12 years.

This system expresses time with a 32-bit time_t; that prevents dates after 2038 to be expressed by GnuTLS.
Overflow while parsing days

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Initialize autfreed variables with NULL (gcc-11)
Stefan Berger [Thu, 3 Jun 2021 14:04:53 +0000 (10:04 -0400)]
swtpm_setup: Initialize autfreed variables with NULL (gcc-11)

This patch addresses the following gcc-11 compiler issues:

In file included from /usr/include/glib-2.0/glib.h:114,
                 from swtpm_setup_utils.c:14:
swtpm_setup_utils.c: In function 'get_config_value':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'tmp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   28 |   g_free (*pp);
      |   ^~~~~~~~~~~~
swtpm_setup_utils.c:36:31: note: 'tmp' was declared here
   36 |             g_autofree gchar *tmp;
      |                               ^~~

swtpm.c: In function 'swtpm_start':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'pidfile_file' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   28 |   g_free (*pp);
      |   ^~~~~~~~~~~~
swtpm.c:54:23: note: 'pidfile_file' was declared here
   54 |     g_autofree gchar *pidfile_file;
      |                       ^~~~~~~~~~~~

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_localca: Initialize autofreed variables to NULL (gcc-11)
Stefan Berger [Thu, 3 Jun 2021 13:54:43 +0000 (09:54 -0400)]
swtpm_localca: Initialize autofreed variables to NULL (gcc-11)

This patch addresses the following gcc-11 compiler issues:

In file included from /usr/include/glib-2.0/glib.h:114,
                 from ../src/utils/swtpm_utils.h:13,
                 from swtpm_localca_utils.c:24:
swtpm_localca_utils.c: In function 'get_config_envvars':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'value' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   28 |   g_free (*pp);
      |   ^~~~~~~~~~~~
swtpm_localca_utils.c:98:37: note: 'value' was declared here
   98 |             g_autofree gchar *key, *value;
      |                                     ^~~~~
In file included from /usr/include/glib-2.0/glib.h:114,
                 from ../src/utils/swtpm_utils.h:13,
                 from swtpm_localca_utils.c:24:
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'key' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   28 |   g_free (*pp);
      |   ^~~~~~~~~~~~
swtpm_localca_utils.c:98:31: note: 'key' was declared here
   98 |             g_autofree gchar *key, *value;
      |                               ^~~

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorpm: Readd swtpm.spec to be able to easily install dependencies
Stefan Berger [Fri, 4 Jun 2021 15:31:59 +0000 (11:31 -0400)]
rpm: Readd swtpm.spec to be able to easily install dependencies

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorpm: Move spec file and include it in dist archives
Andrea Bolognani [Thu, 3 Jun 2021 17:54:43 +0000 (19:54 +0200)]
rpm: Move spec file and include it in dist archives

Having the spec file in the top-level directory of the dist
archive makes it possible to build rpms with a single,
convenient command.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agorpm: Drop git information
Andrea Bolognani [Thu, 3 Jun 2021 17:32:48 +0000 (19:32 +0200)]
rpm: Drop git information

Using these instead of the regular version number makes it
more complicated than necessary to perform builds, and there
doesn't seem to be any advantage in keeping them around.

After this change, the rpm building instructions contained in
the INSTALL file actually work.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agorpm: Remove unnecessary string substitution
Andrea Bolognani [Thu, 3 Jun 2021 18:14:39 +0000 (20:14 +0200)]
rpm: Remove unnecessary string substitution

These are never going to change, so using string substitution
serves no purpose beyon mild obfuscation.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agorpm: Use HTTPS URL
Andrea Bolognani [Thu, 3 Jun 2021 17:25:35 +0000 (19:25 +0200)]
rpm: Use HTTPS URL

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agorpm: Drop swtpm.spec
Andrea Bolognani [Thu, 3 Jun 2021 16:03:44 +0000 (18:03 +0200)]
rpm: Drop swtpm.spec

This file is generated from swtpm.spec.in, and as such should
not be tracked in git; in fact, an entry for it exists in the
gitignore file.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agoINSTALL: Don't make the user run configure twice
Andrea Bolognani [Thu, 3 Jun 2021 16:16:31 +0000 (18:16 +0200)]
INSTALL: Don't make the user run configure twice

autogen.sh will automatically invoke configure passing it any
command line arguments it received, so we shouldn't instruct
the user to unnecessarily run it again immediately afterwards.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agogitignore: Ignore .gch files
Andrea Bolognani [Thu, 3 Jun 2021 16:01:50 +0000 (18:01 +0200)]
gitignore: Ignore .gch files

Configure generates include/swtpm/tpm_ioctl.h.gch when trying
to figure out which hardening options can be enabled.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agoutils: Have logit and logerr call alog to unify their code
Stefan Berger [Mon, 31 May 2021 20:29:02 +0000 (16:29 -0400)]
utils: Have logit and logerr call alog to unify their code

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Test resolving env. variabels in swtpm_setup config file
Stefan Berger [Mon, 31 May 2021 17:16:39 +0000 (13:16 -0400)]
tests: Test resolving env. variabels in swtpm_setup config file

Modify a test case and write an environment variable into the
swtpm_setup.conf config file to test that it gets resolved.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agosamples: Rewrite of swtpm_localca in 'C' (addresses issue #437)
Stefan Berger [Mon, 24 May 2021 14:43:49 +0000 (10:43 -0400)]
samples: Rewrite of swtpm_localca in 'C' (addresses issue #437)

This is a 1:1 rewrite of swtpm_localca in 'C' as a final step to get
rid of the python dependency. It addresses issue #437.

Tested on: Cygwin, Fedora 33, Ubuntu Xenial & Bionic, FreeBSD,
           DragonFlyBSD, OpenBSD (i386), Mac, Debian (recent), Centos-8,
           CentOS (recent), Alpine (recent), OpenSUSE (recent),
           Fedora 28 PPC Big Endian

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Add proper DEPENDENCY for swtpm_setup on swtpm_utils.la
Stefan Berger [Sun, 30 May 2021 00:33:11 +0000 (20:33 -0400)]
swtpm_setup: Add proper DEPENDENCY for swtpm_setup on swtpm_utils.la

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Rewrite in 'C' (addresses issue #437)
Stefan Berger [Mon, 17 May 2021 11:36:36 +0000 (07:36 -0400)]
swtpm_setup: Rewrite in 'C' (addresses issue #437)

This is a 1:1 rewrite of swtpm_setup in 'C' as a first step to get
rid of the python dependency. It addresses issue #437.

Tested on: Cygwin, Fedora 33, Ubuntu Xenial & Bionic, FreeBSD,
           DragonFlyBSD, OpenBSD (i386), Mac, Debian (recent), Centos-8,
           CentOS (recent), Alpine (recent), OpenSUSE (recent)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoheaders: Add defines for GetInfo flags
Stefan Berger [Mon, 24 May 2021 12:44:34 +0000 (08:44 -0400)]
headers: Add defines for GetInfo flags

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agosample: swtpm-local: Fix a few minor issues
Stefan Berger [Thu, 27 May 2021 17:10:04 +0000 (13:10 -0400)]
sample: swtpm-local: Fix a few minor issues

Have the statedir created in case it doesn't exist before checking for read
and write access to it.

Set the default directory where to write the results into to the current
directory '.' rather than to what would result in the root directory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Fix TPM 1.2 default SRK and owner password and help screen
Stefan Berger [Wed, 26 May 2021 20:30:11 +0000 (16:30 -0400)]
swtpm_setup: Fix TPM 1.2 default SRK and owner password and help screen

Some of the wording in the help screen was odd, so rephrase it.

Fix the default owner and SRK passwords for the TPM 1.2 case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Fix some minor issue
Stefan Berger [Wed, 26 May 2021 20:27:40 +0000 (16:27 -0400)]
swtpm_setup: Fix some minor issue

Fix some typos. The value for TPM2_ALG_SHA3_512 was wrong but also is
currently not used since libtpms does not support it yet.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Only define single .PHONY
Stefan Berger [Mon, 24 May 2021 14:00:22 +0000 (10:00 -0400)]
build-sys: Only define single .PHONY

Fix the following issue due to multiple .PHONY definitions.

Makefile.am:34: warning: .PHONY was already defined in condition WITH_SELINUX, which is included in condition TRUE ...
Makefile.am:28: ... '.PHONY' previously defined here

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Fix cleanup issue complain by 'make distcheck'
Stefan Berger [Mon, 24 May 2021 13:55:05 +0000 (09:55 -0400)]
build-sys: Fix cleanup issue complain by 'make distcheck'

Fix the following `make distcheck` cleanup issue:

ERROR: files left in build directory after distclean:
./man/man8/swtpm_cuse.8

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Initialize key structure before calling OpenSSL function (Coverity)
Stefan Berger [Sat, 22 May 2021 13:45:15 +0000 (09:45 -0400)]
swtpm: Initialize key structure before calling OpenSSL function (Coverity)

Initialize the key structure before loading the key into it. This
resolves an issue raised by Coverity, but doesn't seem to be really
necessary.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_cert: rename deprecated libtasn1 types
Jonas Witschel [Wed, 19 May 2021 08:30:41 +0000 (10:30 +0200)]
swtpm_cert: rename deprecated libtasn1 types

These types have been renamed in libtasn1 version 3.0 (released 2012-10-28).
The most recent libtasn1 version 4.17.0 (released 2021-05-13) now prints
deprecation warnings that are made fatal by -Werror:

ek-cert.c:76:13: error: 'ASN1_ARRAY_TYPE' macro is deprecated, use 'asn1_static_node' instead. [-Werror]
   76 | extern const ASN1_ARRAY_TYPE tpm_asn1_tab[];
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[...]

The new types were introduced almost ten years ago, so they should be pretty
universally available by now.

Signed-off-by: Jonas Witschel <diabonas@archlinux.org>
3 years agobuild-sys: leave CFLAGS/LDFLAGS for user to be defined
Marc-André Lureau [Tue, 18 May 2021 13:18:55 +0000 (17:18 +0400)]
build-sys: leave CFLAGS/LDFLAGS for user to be defined

This allows user to set specific flags during compilation, without
overriding configure-time cflags necessary for compilation.

See also:
https://www.gnu.org/software/automake/manual/html_node/User-Variables.html
https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
3 years agotests: Allow volatile state file >= 9000 bytes in test_tpm2_migration_key
Stefan Berger [Wed, 12 May 2021 17:03:12 +0000 (13:03 -0400)]
tests: Allow volatile state file >= 9000 bytes in test_tpm2_migration_key

Changes to libtpms will require that the volatile state files
during this test may be larger than 9000 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoDebian: Fix build warnings by updating compat to '10'
Stefan Berger [Fri, 7 May 2021 01:27:03 +0000 (21:27 -0400)]
Debian: Fix build warnings by updating compat to '10'

Thos patch fixes the following issue when building a Debian package:

dh clean --parallel
dh: warning: Compatibility levels before 10 are deprecated (level 9 in use)
   dh_auto_clean -O--parallel
dh_auto_clean: warning: Compatibility levels before 10 are deprecated (level 9 in use)
   dh_clean -O--parallel
dh_clean: warning: Compatibility levels before 10 are deprecated (level 9 in use)
 dpkg-source -b .

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Free error that was set by failed options_parse
Stefan Berger [Sun, 21 Mar 2021 01:17:55 +0000 (21:17 -0400)]
swtpm: Free error that was set by failed options_parse

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Add a Readme describing how to run the swtpm tests
Stefan Berger [Wed, 17 Mar 2021 21:00:14 +0000 (17:00 -0400)]
tests: Add a Readme describing how to run the swtpm tests

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Store and also restore the volatile state at every step
Stefan Berger [Wed, 17 Mar 2021 20:17:03 +0000 (16:17 -0400)]
tests: Store and also restore the volatile state at every step

Add restoring of the volatile state after having it stored.

Since this is now taking a long time it must be explicitly enabled
by setting the environment variable SWTPM_TEST_STORE_VOLATILE=1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Set test-check local user.name and user.email before git am
Stefan Berger [Wed, 17 Mar 2021 19:56:14 +0000 (15:56 -0400)]
tests: Set test-check local user.name and user.email before git am

If we are running the tests as a user that doesn't have a git config
setup we run into the following issue when trying to apply patches
suing 'git am':

Committer identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

This patch fixes this by setting the git config on the local checkout
before using 'git am'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Check for minimum required gnutls 3.4.0
Stefan Berger [Mon, 15 Mar 2021 14:06:43 +0000 (10:06 -0400)]
build-sys: Check for minimum required gnutls 3.4.0

RHEL 7's gnutls 3.3.29 does not take the private key passwords like later
versions take it. We require at least 3.4.0, though I am not entirely sure
when that change occurred. We may actually require >3.4.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Apply patches to IBM TSS2 test suite
Stefan Berger [Sun, 28 Feb 2021 23:45:25 +0000 (18:45 -0500)]
tests: Apply patches to IBM TSS2 test suite

Apply patches to the IBM TSS2 test suite rather than using sed on its
files and other types of file manipulations.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Move setting CERRTOOL variable to tests-common
Stefan Berger [Sat, 27 Feb 2021 01:32:10 +0000 (20:32 -0500)]
tests: Move setting CERRTOOL variable to tests-common

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Write note about non-standard EK when using --allow-signing
Stefan Berger [Sun, 28 Feb 2021 21:10:11 +0000 (16:10 -0500)]
swtpm_setup: Write note about non-standard EK when using --allow-signing

Write a note in swtpm_setup's help screen and man page that the usage
of --allow-signing will lead to a non-standard EK. Be more precise in the
man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Add test for libtpms issue number 195 (needs latest libtpms now)
Stefan Berger [Fri, 26 Feb 2021 16:01:25 +0000 (11:01 -0500)]
tests: Add test for libtpms issue number 195 (needs latest libtpms now)

This patch adds a test case for testing the fix for libtpms
issue 195: https://github.com/stefanberger/libtpms/issues/195

This patch now requires that the latest TPM version from master or the
branches is installed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_ioctl: Use timeouts for communicating with swtpm (Unix socket)
Stefan Berger [Sat, 20 Feb 2021 18:40:48 +0000 (13:40 -0500)]
swtpm_ioctl: Use timeouts for communicating with swtpm (Unix socket)

Start using timeouts when communicating with swtpm over Unix sockets so
that swtpm_ioctl does not just hang when it cannot communicate with swtpm
such as establishing a connection or reading results. This is because swtpm
listens to nlye one control channel connections.

This patch addresses an aspect of the problem reported in issue #415
but may also starting hiding bugs if certain operations are done in
the wrong order, as was the case in libvirt (6.10 & 7.0).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Use the IBM TSS2 v1.6.0's test suite
Stefan Berger [Wed, 24 Feb 2021 15:28:15 +0000 (10:28 -0500)]
tests: Use the IBM TSS2 v1.6.0's test suite

Upgrade to use the IBM TSS2 tests from v1.6.0.

Add a patch that eliminates all testing of 3072 bit RSA keys in case
libtpms does not support such keys. Also disable a test case related
to ACT for older revisions.

This test passes with libtpms 0.8.0 as well libtpms 0.6.0 and 0.7.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Wait a bit for pid file content; dump log on failure
Stefan Berger [Sun, 21 Feb 2021 15:43:21 +0000 (10:43 -0500)]
tests: Wait a bit for pid file content; dump log on failure

test_samples_create_tpmca needs to wait longer for the pid file content
to be there not just until the file is available.

test_tpm2_save_load_state_2 needs to dump the TPM log file on failure.
Failures occurred rarely because the previous instance of swtpm had
not shut down yet and released the lock file while the new instance
wanted to lock the lockfile. So we have to wait a bit until the
previous instance is gone.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoman: Change 'shell variable' to 'environment variable' in swtpm-localca.conf
Stefan Berger [Fri, 19 Feb 2021 13:26:06 +0000 (08:26 -0500)]
man: Change 'shell variable' to 'environment variable' in swtpm-localca.conf

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
3 years agotests: Fix spelling error swptm->swtpm
Stefan Berger [Fri, 5 Feb 2021 19:54:45 +0000 (14:54 -0500)]
tests: Fix spelling error swptm->swtpm

This patch fixes issue #410.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Fix spelling in comment (SWPTM->SWTPM)
Stefan Berger [Fri, 5 Feb 2021 19:50:53 +0000 (14:50 -0500)]
swtpm: Fix spelling in comment (SWPTM->SWTPM)

This patch fixes issue #410.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Fix typo in project URL (swptm->swtpm)
Stefan Berger [Fri, 5 Feb 2021 19:49:11 +0000 (14:49 -0500)]
swtpm_setup: Fix typo in project URL (swptm->swtpm)

This fixes issue #410.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agosamples: Fix typo in project URL (swptm->swtpm)
Stefan Berger [Fri, 5 Feb 2021 19:48:08 +0000 (14:48 -0500)]
samples: Fix typo in project URL (swptm->swtpm)

This patch fixes issue #410.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Replace OSError with ValueError (Cygwin bugfix)
Stefan Berger [Tue, 2 Feb 2021 02:11:23 +0000 (21:11 -0500)]
swtpm_setup: Replace OSError with ValueError (Cygwin bugfix)

A wrong domain to socketpair() causes a ValueError, not an OSError.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Probe for supported socketpair domain (cygwin bugfix)
Stefan Berger [Mon, 1 Feb 2021 17:14:48 +0000 (12:14 -0500)]
swtpm_setup: Probe for supported socketpair domain (cygwin bugfix)

We need to probe for the support socketpair() domain. On Linux only
socket.AF_UNIX is support and on Cygwin AF_INET works.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoTravis: Upgrade pip to v20.3.3
Stefan Berger [Fri, 29 Jan 2021 13:34:48 +0000 (08:34 -0500)]
Travis: Upgrade pip to v20.3.3

Pip 21.0.0 seems to be broken when upgraded to on Xenial. So
let's just only upgrade to 20.3.3.

$ sudo pip3 install --upgrade cryptography
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Check for python cryptography version
Stefan Berger [Tue, 19 Jan 2021 02:45:03 +0000 (02:45 +0000)]
build-sys: Check for python cryptography version

We need at least 2.1.x, 2.1.4, that supports OAEP.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Fix --print-capabilities for 'swtpm chardev'
Stefan Berger [Wed, 13 Jan 2021 12:17:45 +0000 (07:17 -0500)]
swtpm: Fix --print-capabilities for 'swtpm chardev'

This patch fixes the following issue:

$ ./src/swtpm/swtpm chardev --print-capabilities --tpm2
swtpm: Error: Missing character device or file descriptor

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoUpdate the doc of the flag to connect to TPM via UnixIO socket
Lili Zhu [Wed, 13 Jan 2021 03:19:22 +0000 (22:19 -0500)]
Update the doc of the flag to connect to TPM via UnixIO socket

Modify the flag from "--unixio" to "--unix"

Signed-off-by: Lili Zhu <lizhu@redhat.com>
3 years agoswtpm_cuse: Support parial reads (issue #376)
Stefan Berger [Tue, 29 Dec 2020 23:27:26 +0000 (18:27 -0500)]
swtpm_cuse: Support parial reads (issue #376)

This patch adds support for partial reads to the CUSE swtpm.

We introduce a ptm_read_offset variable that holds the offset where to read
from next. It is reset every time a command has been processed as part of a
write() so that subsequent read()s start reading from offset 0. It is
advanced by the number of bytes that were read.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Remove unused file_ops_lock from threadpool.c (asan)
Stefan Berger [Sun, 3 Jan 2021 15:03:35 +0000 (10:03 -0500)]
swtpm: Remove unused file_ops_lock from threadpool.c (asan)

Asan reports this error for the CUSE TPM. The file_ops_lock was accidentally
duplicated in a code move of threadpool related code out of cuse_tpm.c
This patch removes the unused file_ops_lock from threadpool.c to resolve
the ASAN issue.

=================================================================
==545493==ERROR: AddressSanitizer: odr-violation (0x000000419340):
  [1] size=8 'file_ops_lock' cuse_tpm.c:112:8
  [2] size=8 'file_ops_lock' threadpool.c:55:8
These globals were registered at these points:
  [1]:
    #0 0x14f6c27f3cc8  (/lib64/libasan.so.6+0x37cc8)
    #1 0x40c2c3 in _sub_I_00099_1 (/home/stefanb/tmp/swtpm/src/swtpm/.libs/lt-swtpm+0x40c2c3)
    #2 0x40c31c in __libc_csu_init (/home/stefanb/tmp/swtpm/src/swtpm/.libs/lt-swtpm+0x40c31c)

  [2]:
    #0 0x14f6c27f3cc8  (/lib64/libasan.so.6+0x37cc8)
    #1 0x14f6c27aad1a in _sub_I_00099_1 (/home/stefanb/tmp/swtpm/src/swtpm/.libs/libswtpm_libtpms.so.0+0x25d1a)
    #2 0x14f6c31dc7b1 in call_init.part.0 (/lib64/ld-linux-x86-64.so.2+0x117b1)

==545493==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'file_ops_lock' at cuse_tpm.c:112:8
==545493==ABORTING

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Free buffer after failure to realloc (cppcheck)
Stefan Berger [Sat, 2 Jan 2021 14:48:45 +0000 (09:48 -0500)]
swtpm: Free buffer after failure to realloc (cppcheck)

Free the original buffer after failure to realloc().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Remove global unused variable input (issue #395)
Stefan Berger [Sat, 2 Jan 2021 14:20:39 +0000 (09:20 -0500)]
swtpm: Remove global unused variable input (issue #395)

Remove the global unused variable with name input. This was detected
by cppcheck.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoman8: Mark device parameter as optional
Stefan Berger [Tue, 29 Dec 2020 22:56:20 +0000 (17:56 -0500)]
man8: Mark device parameter as optional

Since the device can be passed using --tpm-device <device>, we now
mark the last parameter, which can also be the device, as optional.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_ioctl: Remove unnecessary if statement (issue #392)
Stefan Berger [Tue, 29 Dec 2020 22:53:41 +0000 (17:53 -0500)]
swtpm_ioctl: Remove unnecessary if statement (issue #392)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com)
3 years agogithub: Update issues templates
Stefan Berger [Mon, 28 Dec 2020 03:49:45 +0000 (22:49 -0500)]
github: Update issues templates

Update the issues template.

3 years agoswtpm: Unconditionally close fd if writing of pidfile fails (coverity)
Stefan Berger [Sat, 26 Dec 2020 04:30:34 +0000 (23:30 -0500)]
swtpm: Unconditionally close fd if writing of pidfile fails (coverity)

Do not bother trying to keep pidfilefd open in case fd = pidfilefd,
but close it unconditionally. If writing the pidfile fails, the process
terminates anyway, besides that we only ever need to write to the
pidfile once, which is happening in this function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Adjust size of message buffer to be of size ptm_hdata
Stefan Berger [Mon, 21 Dec 2020 17:32:34 +0000 (12:32 -0500)]
swtpm: Adjust size of message buffer to be of size ptm_hdata

This patch fixes the following compilation issue/bug:

ctrlchannel.c: In function ‘ctrlchannel_process_fd’:
ctrlchannel.c:694:13: error: array subscript ‘ptm_hdata[0]’ is partly outside array bounds of ‘struct output[1]’ [-Werror=array-bounds]
  694 |         data->u.resp.tpm_result = htobe32(res);
      |             ^~
ctrlchannel.c:486:7: note: while referencing ‘output’
  486 |     } output;
      |       ^~~~~~

Sending hashes to the TPM is not currently used in any major
application, so this bug should not affect much.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Increase timeout from 10s to 30s for slower machines
Stefan Berger [Mon, 7 Dec 2020 12:52:35 +0000 (07:52 -0500)]
swtpm_setup: Increase timeout from 10s to 30s for slower machines

Older ARM processors need more time to create the initial CA keys
and then the key for the TPM. So we increase the timeout to 30s.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoTravis: Remove OSX CI/CD due to costs
Stefan Berger [Tue, 17 Nov 2020 21:54:06 +0000 (16:54 -0500)]
Travis: Remove OSX CI/CD due to costs

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agosamples: Do not follow symlink on logfile (CVE-2020-28407)
Stefan Berger [Tue, 17 Nov 2020 18:03:56 +0000 (13:03 -0500)]
samples: Do not follow symlink on logfile (CVE-2020-28407)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Do not follow symlink on logfile (CVE-2020-28407)
Stefan Berger [Tue, 17 Nov 2020 17:56:58 +0000 (12:56 -0500)]
swtpm_setup: Do not follow symlink on logfile (CVE-2020-28407)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Do not follow symlink when accessing log file (CVE-2020-28407)
Stefan Berger [Tue, 17 Nov 2020 17:47:55 +0000 (12:47 -0500)]
swtpm: Do not follow symlink when accessing log file (CVE-2020-28407)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Use open() (not fopen()) when accessing statefile (CVE-2020-28407)
Stefan Berger [Mon, 9 Nov 2020 02:41:54 +0000 (21:41 -0500)]
swtpm: Use open() (not fopen()) when accessing statefile (CVE-2020-28407)

This patch addresses CVE-2020-28407.

Use the open() call rather than the fopen() call when accessing
the statefile and make sure we do not follow symlinks using O_NOFOLLOW.

The modification does not allow an attacker to create a symbolic link
with the name of the temporary file (TMP2-00.permall for TPM 2) and
have this point to a valueable file and swtpm ends up overwriting the
file. The success of the attack depends on the attacker having access
to the TPM's state directory (--tpmstate dir=...).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Switch to open() from fopen() for the pidfile (CVE-2020-28407)
Stefan Berger [Mon, 9 Nov 2020 03:21:23 +0000 (22:21 -0500)]
swtpm: Switch to open() from fopen() for the pidfile (CVE-2020-28407)

This patch addresses CVE-2020-28407.

Use the open() call rather than the fopen() call when creating a pidfile.
Also prevent us from following symbolic links when opening the pidfile for
writing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Do not follow symlinks when opening lockfile (CVE-2020-28407)
Stefan Berger [Mon, 9 Nov 2020 02:45:40 +0000 (21:45 -0500)]
swtpm: Do not follow symlinks when opening lockfile (CVE-2020-28407)

This patch addresses CVE-2020-28407.

Prevent us from following symliks when we open the lockfile
for writing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_cert: Switch to open() from fopen() for writing certificate
Stefan Berger [Mon, 9 Nov 2020 02:40:35 +0000 (21:40 -0500)]
swtpm_cert: Switch to open() from fopen() for writing certificate

Switch to open from fopen() and make sure we do not follow symlinks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: fix configure python cryptography error message
Eiichi Tsukata [Wed, 11 Nov 2020 07:50:18 +0000 (07:50 +0000)]
build-sys: fix configure python cryptography error message

Currently it shows "python setuptools is required" if "import
cryptography" failed.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
3 years agotests: Try with tcsd.conf ownership of root:tss if tss:tss did not work
Stefan Berger [Mon, 9 Nov 2020 00:14:11 +0000 (19:14 -0500)]
tests: Try with tcsd.conf ownership of root:tss if tss:tss did not work

Due to recent changes in tcsd, it doesn't accept 'tss:tss 0600' anymore
for the tcsd config file but we need to use 'root:tss 0640' for it.
So far only Fedora seems to be affected. It now depends on whether tcsd
has been patched what ownership is required. So we try first the old
configuration and then the new one.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Move setup of vtpm proxy device into own function
Stefan Berger [Thu, 29 Oct 2020 15:06:18 +0000 (11:06 -0400)]
swtpm: Move setup of vtpm proxy device into own function

Lift the code that sets up the vtpm proxy device out of the main
function and put it into its own function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agosamples: Require --root flag if root user runs script
Stefan Berger [Wed, 28 Oct 2020 01:17:39 +0000 (21:17 -0400)]
samples: Require --root flag if root user runs script

Since the config files created by the swtpm-create-user-config-files
script will shadow those typically installed in /etc, we now require the
option --root if 'root' runs this script so that root is aware what he is
doing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Bump up version to 0.6.0 at beginning of dev cycle
Stefan Berger [Fri, 9 Oct 2020 18:16:22 +0000 (14:16 -0400)]
build-sys: Bump up version to 0.6.0 at beginning of dev cycle

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agodebian: drop revision from version, illegal for native-format packages
наб [Wed, 7 Oct 2020 22:56:15 +0000 (00:56 +0200)]
debian: drop revision from version, illegal for native-format packages

$ dpkg-buildpackage -us -uc
dpkg-buildpackage: info: source package swtpm
dpkg-buildpackage: info: source version 0.5.0-1
dpkg-buildpackage: info: source distribution RELEASED
dpkg-buildpackage: info: source changed by Stefan Berger <stefanb@linux.ibm.com>
dpkg-source: error: can't build with source format '3.0 (native)':
native package version may not have a revision

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
3 years agoman: Fix enc[yr]ption typo in swtpm_setup manpage
наб [Tue, 27 Oct 2020 19:07:57 +0000 (20:07 +0100)]
man: Fix enc[yr]ption typo in swtpm_setup manpage

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
3 years agoman: Extend man pages with --flags support for CUSE TPM
Stefan Berger [Mon, 12 Oct 2020 22:05:30 +0000 (18:05 -0400)]
man: Extend man pages with --flags support for CUSE TPM

Also fix an error in the man page on the way. 'startup-deactivated'
can only be used with a TPM 1.2, not a TPM 2.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_cuse: Implement support for --flags startup-xyz options
Stefan Berger [Mon, 12 Oct 2020 22:09:27 +0000 (18:09 -0400)]
swtpm_cuse: Implement support for --flags startup-xyz options

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_cuse: Implement support for --flags not-need-init for CUSE TPM
Stefan Berger [Mon, 12 Oct 2020 19:55:02 +0000 (15:55 -0400)]
swtpm_cuse: Implement support for --flags not-need-init for CUSE TPM

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agodebian/rpm: Adjust changelog for 0.5.0 release
Stefan Berger [Wed, 7 Oct 2020 15:31:20 +0000 (11:31 -0400)]
debian/rpm: Adjust changelog for 0.5.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoCHANGES: Add documentation for changes in 0.5.0
Stefan Berger [Mon, 21 Sep 2020 16:38:00 +0000 (12:38 -0400)]
CHANGES: Add documentation for changes in 0.5.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agosamples: Do not truncate logfile when testing write-access
Stefan Berger [Tue, 6 Oct 2020 17:31:32 +0000 (13:31 -0400)]
samples: Do not truncate logfile when testing write-access

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Do not truncate logfile when testing write-access
Stefan Berger [Tue, 6 Oct 2020 17:29:42 +0000 (13:29 -0400)]
swtpm_setup: Do not truncate logfile when testing write-access

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Remove TPM state file in case error occurred
Stefan Berger [Tue, 6 Oct 2020 16:48:38 +0000 (12:48 -0400)]
swtpm_setup: Remove TPM state file in case error occurred

Remove the TPM state file in case an error occurred.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agobuild-sys: Add python-install and python-uninstall targets
Stefan Berger [Mon, 5 Oct 2020 11:49:20 +0000 (07:49 -0400)]
build-sys: Add python-install and python-uninstall targets

To force the installation of the python programs add a python-install
target. This solves an installation issue with non-standard prefix,
like not using /usr or /usr/local, as may be the case on OS X (Apple)
when using homebrew. It leaves the 'make distcheck' working, which also
uses a non-standard prefix and where we don't want to install the tools
due to issues with removing them afterwards where pip3 cannot be used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Fix path to swtpm-localca
Stefan Berger [Mon, 5 Oct 2020 13:27:51 +0000 (09:27 -0400)]
tests: Fix path to swtpm-localca

This patch fixes the path to swtpm-localca to avoid this type of
error because of swtpm_localca_conf having been created in another
directory. This error occurred whan running

sudo bash -c "make -j32 distcheck"

Traceback (most recent call last):
  File "/home/stefanb/tmp/swtpm/swtpm-0.5.0/samples/swtpm-localca", line 5, in <
    from py_swtpm_localca.swtpm_localca import main
  File "/home/stefanb/tmp/swtpm/swtpm-0.5.0/samples/py_swtpm_localca/swtpm_local
    from py_swtpm_localca.swtpm_localca_conf import SYSCONFDIR
ModuleNotFoundError: No module named 'py_swtpm_localca.swtpm_localca_conf'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Write state files atomically using file renaming
Stefan Berger [Fri, 2 Oct 2020 20:29:18 +0000 (16:29 -0400)]
swtpm: Write state files atomically using file renaming

To support writing state files atomically we first write into
a temporary file and then rename it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agotests: Allow 'ss' as an alternative to 'netstat'
Stefan Berger [Fri, 2 Oct 2020 19:05:53 +0000 (15:05 -0400)]
tests: Allow 'ss' as an alternative to 'netstat'

Some distros (openSUSE) have deprecated the 'net-tools' package,
so we allow for 'ss' as an alternative tool from the
iproute/iproute2 package. This is only relevant for test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm_setup: Add missing --print-capabilities to help screen
Stefan Berger [Fri, 2 Oct 2020 17:32:28 +0000 (13:32 -0400)]
swtpm_setup: Add missing --print-capabilities to help screen

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agoswtpm: Prefix debug print function with SWTPM rather than TPM
Stefan Berger [Tue, 29 Sep 2020 21:34:53 +0000 (17:34 -0400)]
swtpm: Prefix debug print function with SWTPM rather than TPM

To avoid clashes with libtpms print functions, prefix the print function
in swtpm with SWTPM_ rather than TPM_. This may matter on older systems
where libtpms could call into swtpm's TPM_PrintAll function due to it
having the same name as libtpms's function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoUse correct LDFLAGS for non-standard libtpms locations
Elms [Thu, 24 Sep 2020 20:33:25 +0000 (13:33 -0700)]
Use correct LDFLAGS for non-standard libtpms locations

4 years agosamples: Use ${HOME}/.config if XDG_CONFIG_HOME is not set (RHEL)
Stefan Berger [Wed, 23 Sep 2020 20:32:30 +0000 (16:32 -0400)]
samples: Use ${HOME}/.config if XDG_CONFIG_HOME is not set (RHEL)

When creating the user config files, fall back to using ${HOME}/.config
if XDG_CONFIG_HOME is not set on a system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Do not hardcode '/etc' but use SYSCONFDIR
Stefan Berger [Wed, 23 Sep 2020 13:09:43 +0000 (09:09 -0400)]
swtpm_setup: Do not hardcode '/etc' but use SYSCONFDIR

Do not hardcode the /etc path but use the compile-time generated
SYSCONFDIR instead.

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