]> git.proxmox.com Git - swtpm.git/log
swtpm.git
4 years agoswtpm_setup: Switch to NIST P384 curves
Stefan Berger [Wed, 29 Apr 2020 23:22:09 +0000 (19:22 -0400)]
swtpm_setup: Switch to NIST P384 curves

Switch to NIST P384 curves for the storage primary key as well as the 2nd EK.
The EK part now complies with the following specification:

TCG PC Client Platform TPM Profile Specification for TPM 2.0
Version 1.04
Revision 37
February 3, 2020

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Create RSA 2048 and ECC NIST P256 keys and certs
Stefan Berger [Thu, 30 Apr 2020 05:41:13 +0000 (01:41 -0400)]
swtpm_setup: Create RSA 2048 and ECC NIST P256 keys and certs

Following "TCG PC Client Platform TPM Profile Specification for
TPM 2.0, version 1.04, Rev 37" create and RSA and an ECC NIST P256
key now. We will upgrade the ECC NIST key to P384 in the next
step.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Move code into tpm2_create_ek_and_cert
Stefan Berger [Thu, 30 Apr 2020 05:02:51 +0000 (01:02 -0400)]
swtpm_setup: Move code into tpm2_create_ek_and_cert

Move a whole bunch of EK and certificate creation code into its
own function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Implement function to create ECC NIST P384 EK keys
Stefan Berger [Wed, 29 Apr 2020 22:16:17 +0000 (18:16 -0400)]
swtpm_setup: Implement function to create ECC NIST P384 EK keys

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Rename NONCE_ECC to NONCE_ECC_256
Stefan Berger [Wed, 29 Apr 2020 22:36:30 +0000 (18:36 -0400)]
swtpm_setup: Rename NONCE_ECC to NONCE_ECC_256

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Pass the ECC curve id and hash alg. into functions
Stefan Berger [Wed, 29 Apr 2020 20:58:00 +0000 (16:58 -0400)]
swtpm_setup: Pass the ECC curve id and hash alg. into functions

Pass the ECC curve id and hash algorithm and the ECC_NONCE to the
function creating the ECC keys rather than hard coding them. Rename
the functions that create the NIST_P256 ECC keys to have _nist_p256
suffix in the name.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Calculate offset for 2nd ecc key part based on length
Stefan Berger [Wed, 29 Apr 2020 20:40:15 +0000 (16:40 -0400)]
swtpm_setup: Calculate offset for 2nd ecc key part based on length

Rather than passing the offset of the 2nd part of an ecc key pass
the length of the key and calculate the 2nd offset using the length.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Leave notes about version of templates that were used
Stefan Berger [Wed, 29 Apr 2020 19:48:34 +0000 (15:48 -0400)]
swtpm_setup: Leave notes about version of templates that were used

Leave a not about what version of template was used for the
RSA and ECC EK keys before updating them now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agosamples: Parse optional id= for ECC curve IDs
Stefan Berger [Wed, 29 Apr 2020 23:05:11 +0000 (19:05 -0400)]
samples: Parse optional id= for ECC curve IDs

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_cert: Support --ecc-curveid option to pass curve id
Stefan Berger [Wed, 29 Apr 2020 23:15:30 +0000 (19:15 -0400)]
swtpm_cert: Support --ecc-curveid option to pass curve id

Implement support for passing the curve id via the --curve-id
option. Default assumes secp256r1. secp384r1 is also supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Pass -pc 80 to tssgetcapability to see all 65 handles
Stefan Berger [Sat, 25 Apr 2020 16:07:22 +0000 (12:07 -0400)]
tests: Pass -pc 80 to tssgetcapability to see all 65 handles

tssgetcapability only retrieves a maximum of 64 handles by default.
However, there are 65 persisted keys. Pass -pc 80 to the command to
see all 65 Handles.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Make coverity happy by handling default case in case statement
Stefan Berger [Fri, 24 Apr 2020 19:20:23 +0000 (15:20 -0400)]
swtpm: Make coverity happy by handling default case in case statement

Handle the default cases, which shouldn't ever be reachable, and set
the tocopy to '0' so that no unitialized variable gets copied.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Add test case for loading of an NVRAM completely full with keys
Stefan Berger [Thu, 23 Apr 2020 00:55:15 +0000 (20:55 -0400)]
tests: Add test case for loading of an NVRAM completely full with keys

Add a test case that fills up the NVRAM area with as many persisted keys
as possible and then fills up the rest with an NVRAM index so that all
space is occupied. We have to be able to load this state again into the
NVRAM once the OBJECT's size increases due to RSA keys size increase,
which must have us increase the total size of NVRAM in libtpm's TPM profile.

The state in tests/data/tpm2state5/tpm2-00.permall was created using
libtpms 0.6.0, where only 2048 bit keys were supported and total NVRAM size
was 128kb. This state file should never be changed and always be loadable
into a current libtpms. In its USER NVRAM it holds 64 persisted 2048 bit
keys and an NVRAM index with 236 bytes. For this to stay the reference
NVRAM, we need to make sure that it fits exactly to the byte.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Repeat download of TPM 1.2 test suite with random wait intervals
Stefan Berger [Fri, 24 Apr 2020 15:17:54 +0000 (11:17 -0400)]
tests: Repeat download of TPM 1.2 test suite with random wait intervals

Sometimes the download of the TPM 1.2 test suite from sourceforge
fails. So retry up to 3 times and wait a random seconds in the interval
of [3..10] before retrying.

Check the hash of the file we downloaded to make sure we get what we
expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Invoke print capabilites after choosing TPM version
Stefan Berger [Thu, 23 Apr 2020 13:11:22 +0000 (09:11 -0400)]
swtpm: Invoke print capabilites after choosing TPM version

Invoke the printing of the capabilites after choosing the TPM version
in libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Add test case for 'swtpm <iface> --tpm2 --print-capabilities'
Stefan Berger [Thu, 23 Apr 2020 15:01:58 +0000 (11:01 -0400)]
tests: Add test case for 'swtpm <iface> --tpm2 --print-capabilities'

Add a test case testing the returned value from

  swtpm <iface> --tpm2 --print-capabilities

along with those return from swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Revert accidental port change from commit 0194fb22a
Stefan Berger [Wed, 22 Apr 2020 20:27:42 +0000 (16:27 -0400)]
tests: Revert accidental port change from commit 0194fb22a

Revert the accidental port change from commit 0194fb22a.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Remove unnecessary #include <seccomp.h> (fixes SuSE build)
Stefan Berger [Mon, 20 Apr 2020 21:54:10 +0000 (17:54 -0400)]
swtpm: Remove unnecessary #include <seccomp.h> (fixes SuSE build)

It's not necessary anymore to #include <seccomp.h> from the main programs.
Once removed, it also fixes the build on SuSE where seccomp.h is in
seccomp/seccomp.h and we didn't use the LIBSECCOMP_CFLAGS for swtpm.c etc.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Use 'cp -f' for copying over existing files (Travis issue)
Stefan Berger [Wed, 15 Apr 2020 22:32:29 +0000 (18:32 -0400)]
tests: Use 'cp -f' for copying over existing files (Travis issue)

Use 'cp -f' to force-copy over existing files. This solves an issue
seen only on Travis.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agosamples: Extend script to create a CA using a TPM 2 for signing
Stefan Berger [Tue, 30 Oct 2018 02:02:06 +0000 (22:02 -0400)]
samples: Extend script to create a CA using a TPM 2 for signing

Extend the script that creates a CA that uses a TPM 2 for signing.
For this we have to create tokens using the TPM 2 pkcs11 module's
tpm2_ptool and can then use the p11tool for creating keys.

Add a test case that requires a running tpm2-abrmd and tpm2_ptool.
Eventually the test case should (try to) start its own tpm2-abrmd
and talk to swtpm directly but the tcti module to do that isn't
available as a package, yet.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Add some recent syscalls to seccomp blacklist
Stefan Berger [Mon, 13 Apr 2020 15:58:32 +0000 (11:58 -0400)]
swtpm: Add some recent syscalls to seccomp blacklist

Add some recent syscalls to the seccomp blacklist, particularly
setter type of functions.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Address cygwin compilation warning
Stefan Berger [Sun, 12 Apr 2020 00:19:12 +0000 (20:19 -0400)]
swtpm: Address cygwin compilation warning

Compilation on cygwin reports the following issue:

In file included from key.c:43:
key.c: In function ‘key_stream_to_bin’:
key.c:135:26: error: array subscript has type ‘char’ [-Werror=char-subscripts]
  135 |            !isspace(input[digits]) &&
      |                     ~~~~~^~~~~~~~
key.c:143:40: error: array subscript has type ‘char’ [-Werror=char-subscripts]
  143 |     if (input[digits] && !isspace(input[digits]))
      |                                   ~~~~~^~~~~~~~

Address the issue using an explicit cast of char to int.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Remove some old cruft
Stefan Berger [Fri, 10 Apr 2020 12:22:37 +0000 (08:22 -0400)]
swtpm_setup: Remove some old cruft

Remove some commented code and some code that isn't executed any
differently for the user id that's running it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Create orderly NVRAM indices and then clear TPM 2 (for coverage)
Stefan Berger [Fri, 10 Apr 2020 00:32:46 +0000 (20:32 -0400)]
tests: Create orderly NVRAM indices and then clear TPM 2 (for coverage)

Create orderly NVRAM indices and then clear the TPM 2 so that NvDeleteRam()
gets executed and we get better code coverage.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Modify test to create 2 orderly indices
Stefan Berger [Thu, 9 Apr 2020 22:54:37 +0000 (18:54 -0400)]
tests: Modify test to create 2 orderly indices

Modify the test_tpm2_save_load_state_3 to create 2 orderly NVRAM indices
in the first two locations. Those indices will be cleared by a reset
of the TPM and therefore cannot be read once the TPM 2 restarts after
the reset. This also provides better test coverage.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoTravis: Run IBM TSS2 for coverage; use Bionic
Stefan Berger [Thu, 9 Apr 2020 14:56:38 +0000 (10:56 -0400)]
Travis: Run IBM TSS2 for coverage; use Bionic

The IBM TSS2 is available starting with Bionic. Use it there
to extend the test coverage of the code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Change localhost to 127.0.0.1 or explicityly set 127.0.0.1
Stefan Berger [Thu, 9 Apr 2020 16:50:03 +0000 (12:50 -0400)]
tests: Change localhost to 127.0.0.1 or explicityly set 127.0.0.1

To make the test cases work on Travis on Bionic replace all occurrences of
localhost with 127.0.0.1. The only affected client tools seem to be those
related to the TPM 1.2 and the IBM TSS2. For some reason the API used
there cannot resolve localhost to 127.0.0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Explicitly set TCSD_TCP_DEVICE_HOSTNAME=127.0.0.1
Stefan Berger [Thu, 9 Apr 2020 22:18:00 +0000 (18:18 -0400)]
swtpm_setup: Explicitly set TCSD_TCP_DEVICE_HOSTNAME=127.0.0.1

To make swtpm_setup.sh work on Travis on Bionic we need to
explicitly set TCSD_TCP_DEVICE_HOSTAME=127.0.0.1 since lookup
of localhost (with the API the tcsd is using) does not work.
It doesn't negatively affect any other use case, so no problem
setting it.

Also replace localhost in the bash tcp device path with 127.0.0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Run all tests again in run_test
Stefan Berger [Tue, 7 Apr 2020 20:48:26 +0000 (16:48 -0400)]
tests: Run all tests again in run_test

Previous commit broke the run_test script and only ended up running
the first test. This  patch fixes it and displays an success message
at the end.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Disable CUSE interface testing in run_test.sh
Stefan Berger [Tue, 7 Apr 2020 19:46:34 +0000 (15:46 -0400)]
tests: Disable CUSE interface testing in run_test.sh

Diable testing with the CUSE interface in run_test.sh. The CUSE driver
in Linux seems to have some stability problems.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Better detect a 32 bit TPM for the TPM2 derived keys test
Stefan Berger [Tue, 7 Apr 2020 19:30:25 +0000 (15:30 -0400)]
tests: Better detect a 32 bit TPM for the TPM2 derived keys test

The simplest way to detect whether SWTPM_EXE is a 64 bit application on
Linux is to check whether it links against any library in a */lib64/*
directory and only if this is the case we run a particular test case for
which we know what keys 64 bit TPMs are producing given a pre-created
state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Use the IBM TSS2 v1.4.0's test suite
Stefan Berger [Tue, 7 Apr 2020 15:14:14 +0000 (11:14 -0400)]
tests: Use the IBM TSS2 v1.4.0's test suite

Upgrade to use the IBM TSS2 tests from v1.4.0 but eliminate all testing
with 3072 bit RSA keys.

This test also passes with libtpms 0.6.0 and 0.7.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoRPM: Adjust version to 0.4.0 at beginning of dev cycle
Stefan Berger [Tue, 7 Apr 2020 14:40:15 +0000 (10:40 -0400)]
RPM: Adjust version to 0.4.0 at beginning of dev cycle

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoDebian: Adjust changelog for 0.4.0~dev1 developer release
Stefan Berger [Tue, 7 Apr 2020 14:39:12 +0000 (10:39 -0400)]
Debian: Adjust changelog for 0.4.0~dev1 developer release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agobuild-sys: Bump up version to 0.4.0 at beginning of dev cycle
Stefan Berger [Tue, 7 Apr 2020 14:37:56 +0000 (10:37 -0400)]
build-sys: Bump up version to 0.4.0 at beginning of dev cycle

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoTravis: Checkout a certain libtpms revision
Stefan Berger [Wed, 18 Mar 2020 12:13:09 +0000 (08:13 -0400)]
Travis: Checkout a certain libtpms revision

Allow specifying a libtpms revision to test with, defaulting to
master branch.

Have the OS X test use the stable-0.6.0 branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Fix vtpm proxy case without startup flags
Stefan Berger [Fri, 6 Mar 2020 15:16:33 +0000 (10:16 -0500)]
swtpm: Fix vtpm proxy case without startup flags

'swtpm chardev --vptm-proxy' currently requires a '--flag startup-xyz'
to be passed since otherwise the need_init_cmd variable would not be
set to false and swtpm would terminate after sending the startup
command. To maintain backwards compatibility we have to always
set the need_init_cmd variable to false for the --vtpm-proxy case
and must not require a startup flag to be passed.

Roll back one of the test case to not use the startup flag.

Fixes: e6bc4bdf0 ('swtpm: Enable sending startup commands ...')
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Skip test 4 of derived keys in case an allowed error is encounterd
Stefan Berger [Wed, 26 Feb 2020 02:34:21 +0000 (21:34 -0500)]
tests: Skip test 4 of derived keys in case an allowed error is encounterd

libtpms may not support TDES, so we have to skip test case 4 in
case we encounter an allowed error message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoRPM: Update gitcommit for a useful 0.3.0 checkout
Stefan Berger [Mon, 17 Feb 2020 17:13:25 +0000 (12:13 -0500)]
RPM: Update gitcommit for a useful 0.3.0 checkout

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoTravis: Run make check with VERBOSE=1
Stefan Berger [Mon, 17 Feb 2020 17:05:14 +0000 (12:05 -0500)]
Travis: Run make check with VERBOSE=1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoDebian: Adjust changelog for 0.3.0 release
Stefan Berger [Fri, 14 Feb 2020 13:22:48 +0000 (08:22 -0500)]
Debian: Adjust changelog for 0.3.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoDebian: Remove CUSE TPM from build and adjust rules file
Stefan Berger [Fri, 14 Feb 2020 13:25:11 +0000 (08:25 -0500)]
Debian: Remove CUSE TPM from build and adjust rules file

Remove the CUSE TPM from the build and adjust the rules file
so that the build works on Ubuntu servers for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoRPM: Adjust changelog for 0.3.0 release
Stefan Berger [Sun, 16 Feb 2020 19:37:50 +0000 (14:37 -0500)]
RPM: Adjust changelog for 0.3.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agobuild-sys: Set version to 0.3.0 for next release
Stefan Berger [Fri, 14 Feb 2020 18:06:14 +0000 (13:06 -0500)]
build-sys: Set version to 0.3.0 for next release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoCHANGES: Add documentation for changes in 0.3.0
Stefan Berger [Fri, 14 Feb 2020 13:18:47 +0000 (08:18 -0500)]
CHANGES: Add documentation for changes in 0.3.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Only call memcpy if tocopy != 0 (coverity)
Stefan Berger [Fri, 14 Feb 2020 14:22:10 +0000 (09:22 -0500)]
swtpm: Only call memcpy if tocopy != 0 (coverity)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Skip swtpm_cert --print-capabilities test if not compiled
Stefan Berger [Fri, 14 Feb 2020 00:59:38 +0000 (19:59 -0500)]
tests: Skip swtpm_cert --print-capabilities test if not compiled

If swtpm_cert is not compiled, do not attempt the --print-capabilities
test.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Adjust tests to use new startup options
Stefan Berger [Fri, 7 Feb 2020 15:32:04 +0000 (10:32 -0500)]
tests: Adjust tests to use new startup options

Adjust the vtpm proxy test case and others to make use of the new
startup options. Make sure that subsequent Startups sent to the
TPM fail with the expected error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoman: Document new startup options and capabilities advertisement
Stefan Berger [Fri, 7 Feb 2020 15:26:49 +0000 (10:26 -0500)]
man: Document new startup options and capabilities advertisement

Add documentation about the new startup options support as well
as the new capability and its meaning.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Enable sending startup commands before processing commands
Stefan Berger [Fri, 7 Feb 2020 15:19:33 +0000 (10:19 -0500)]
swtpm: Enable sending startup commands before processing commands

The vtpm proxy device requires that the TPM be 'Startup' otherwise it
fails sending the first command to it and will send the 'Startup'
(SU_CLEAR/TPM_ST_CLEAR) itself while adding a log entry. We want to
avoid the kernel log entry.

Add options to the existing --flags option that allows one to start
up the TPM 1.2 or TPM 2.0 with the startup types 'clear', 'state'
and 'deactivate' (TPM 1.2 only). Extend the --print-capabilities to
advertise the availability of these options with the string
'flags-opt-startup'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Wait longer for port to close when running with valgrind
Stefan Berger [Wed, 5 Feb 2020 00:26:45 +0000 (19:26 -0500)]
tests: Wait longer for port to close when running with valgrind

Give swtpm more time to close the port. This became an issue when running
the tests and all executables are valgrind'ed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Display SWTPM_CERT that's being used during test
Stefan Berger [Sun, 26 Jan 2020 14:40:49 +0000 (09:40 -0500)]
tests: Display SWTPM_CERT that's being used during test

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_cert: Accept serial numbers that use up to 64bits
Stefan Berger [Sun, 26 Jan 2020 05:14:09 +0000 (00:14 -0500)]
swtpm_cert: Accept serial numbers that use up to 64bits

Accept serial number that use up to 64bits.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_cert: Use getopt_long_only to parse options
Stefan Berger [Sun, 26 Jan 2020 04:56:42 +0000 (23:56 -0500)]
swtpm_cert: Use getopt_long_only to parse options

Convert the code to use getopt_long_only for parsing the options.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_cert: Add support for --print-capabilities option
Stefan Berger [Mon, 27 Jan 2020 18:45:39 +0000 (13:45 -0500)]
swtpm_cert: Add support for --print-capabilities option

Add support for the --print-capabilities option to display newly
added capabilities. Adpat the man page and related test case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agosamples: Use new pwd format option for secretly passing passwords
Stefan Berger [Sun, 26 Jan 2020 03:38:50 +0000 (22:38 -0500)]
samples: Use new pwd format option for secretly passing passwords

Use the swtpm_cert --signkey-pwd and --parentkey-pwd to pass key passwords
using files rather than using the command line options.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_cert: Allow passing signing key and parent key via new option
Stefan Berger [Sun, 26 Jan 2020 03:31:08 +0000 (22:31 -0500)]
swtpm_cert: Allow passing signing key and parent key via new option

Allow passing signing key and parent key via files and file descriptors
and environment variables. Adapt a test case to exercise this new
functionality.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agosamples: Protect variables in swtpm-create-tpmca
Stefan Berger [Fri, 24 Jan 2020 20:49:51 +0000 (15:49 -0500)]
samples: Protect variables in swtpm-create-tpmca

Address several issues reported by shellcheck and protect
variables with quotes so we now can have filenames with spaces.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Enable spaces in paths and other variables
Stefan Berger [Fri, 24 Jan 2020 14:12:33 +0000 (09:12 -0500)]
swtpm_setup: Enable spaces in paths and other variables

This patch addresses several issues found with shellcheck. In particular
it now enables variables with spaces in them, such as file paths that
contain spaces.

Adjust one of the accompanying test cases to use spaces in the path.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agosamples: Protect variables with quotes and address shellcheck issues
Stefan Berger [Fri, 24 Jan 2020 14:11:33 +0000 (09:11 -0500)]
samples: Protect variables with quotes and address shellcheck issues

Protect variables with quotes so that pathnames with spaces are now
supported.

Adjust the accompanying test case to make use of spaces in file paths.

Address several issues found by shellcheck. Some of them are false
positives especially when it comes to protecting variables passed
to a commaned in an 'eval' line. They must not be protected, otherwise
they are not passed correctly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_ioctl: Calculate strlen(input) only once
Stefan Berger [Tue, 21 Jan 2020 21:38:44 +0000 (16:38 -0500)]
swtpm_ioctl: Calculate strlen(input) only once

Calculate the strlen(input) only once at the beginning.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_ioctl: Block SIGPIPE so we can get EPIPE on write()
Stefan Berger [Tue, 21 Jan 2020 21:35:53 +0000 (16:35 -0500)]
swtpm_ioctl: Block SIGPIPE so we can get EPIPE on write()

Block the SIGPIPE so that a failing write() can return an EPIPE
rather than killing the process with a SIGPIPE.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_bios: Block SIGPIPE so we can get EPIPE on write()
Stefan Berger [Tue, 21 Jan 2020 21:34:19 +0000 (16:34 -0500)]
swtpm_bios: Block SIGPIPE so we can get EPIPE on write()

Block the SIGPIPE so that a failing write() can return an EPIPE
rather than killing the process with a SIGPIPE.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Only accept() new client ctrl connection if we have none
Stefan Berger [Tue, 21 Jan 2020 21:32:48 +0000 (16:32 -0500)]
swtpm: Only accept() new client ctrl connection if we have none

Only accept new client connection on the control channel if we
currently do not have a client on the control channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Do not fail on future PCR banks' hashes
Stefan Berger [Fri, 17 Jan 2020 21:08:45 +0000 (16:08 -0500)]
swtpm_setup: Do not fail on future PCR banks' hashes

swtpm_setup will fail once libtpms starts supporting other PCR
hash banks than sha1, sha256, sha384, sha512, and sm3-256. So,
this patch allows to choose active PCR banks of the SHA3 series.
Further, unknown hash banks will not fail the tool anymore when
it tries to determine which hash banks are supported by the TPM
since it will then add the hex number of the hash algorithm to
the collection of supported hashes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Allow seccomp override w/ SWTPM_TEST_SECCOMP_OPT env var
Stefan Berger [Wed, 15 Jan 2020 01:29:49 +0000 (20:29 -0500)]
tests: Allow seccomp override w/ SWTPM_TEST_SECCOMP_OPT env var

The Ubuntu (PPA) build system executes the build on an environment that
has problems with seccomp profiles. It does not allow us to run the test
suite with swtpm applying its seccomp profile since it fails with a
'bad system call' error. To work around this we introduce the env. variable
SWTPM_TEST_SECCOMP_OPT that we can set to "--seccomp action=none" to avoid
having swtpm apply it seccomp profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agodebian: Fix issues reported by lintian and changelog format issues
Stefan Berger [Tue, 14 Jan 2020 19:34:52 +0000 (19:34 +0000)]
debian: Fix issues reported by lintian and changelog format issues

Fix several issues reported by lintian and the format of
the changelog.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agobuild-sys: Display check result for build with libseccomp
Stefan Berger [Tue, 14 Jan 2020 19:31:18 +0000 (19:31 +0000)]
build-sys: Display check result for build with libseccomp

Display the check result of 'yes' or 'no' for whether we build
with libseccomp.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Move local functions to common file and handle errors better
Stefan Berger [Sun, 12 Jan 2020 22:41:56 +0000 (17:41 -0500)]
tests: Move local functions to common file and handle errors better

Move wait_port_open and wait_port_closed to common file and handle
the timeout errors in test_commandline.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Wait for PID file rather than reading it right away
Stefan Berger [Thu, 9 Jan 2020 23:42:57 +0000 (18:42 -0500)]
tests: Wait for PID file rather than reading it right away

Wait for the PID file to appear rather than reading it right away.
This addresses an issue when runnin the test suite under valgrind
(make -j $(nproc) check).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Protect ${SWTPM_EXE} with quotes when passing to function
Stefan Berger [Sun, 12 Jan 2020 22:26:10 +0000 (17:26 -0500)]
tests: Protect ${SWTPM_EXE} with quotes when passing to function

SWTPM_EXE may be 'valgrind ... swtpm', so we have to protect it with quotes
when passing it as a parameter to a function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Use 1st part of SWTPM_EXE/SWTPM_IOCTL to determine executable
Stefan Berger [Thu, 9 Jan 2020 21:48:30 +0000 (16:48 -0500)]
swtpm_setup: Use 1st part of SWTPM_EXE/SWTPM_IOCTL to determine executable

Search for the SWTPM_EXE / SWTPM_IOCTL executable using 'type -P' to
determine whether it is an executable rather than assuming a full path
is given on which we can check -x.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: delay reading of pidfile if found empty
Stefan Berger [Thu, 9 Jan 2020 21:36:35 +0000 (16:36 -0500)]
tests: delay reading of pidfile if found empty

Delay the reading of the PID file if it is found to be empty.
This can happend if swtpm is run by valgrind.

Also, use the passed parameters rather than the global ones to check
the PID file contents against the expected pid. So far this worked
because PID and PID_FILE were variables used by every caller.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Adjust timeouts for running executables with valgrind
Stefan Berger [Thu, 9 Jan 2020 19:57:01 +0000 (14:57 -0500)]
tests: Adjust timeouts for running executables with valgrind

When running the TPM 1.2 vtpm_proxy test cases by launching the
swtpm with valgrind it may take a long time for the log to be
written and the device to appear. This is due to the self test
of the TPM 1.2 taking a while. So we need to move the reading
of the device into a loop and set the timeout of the loop to 10s
so that it passed under these circumstances.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Keep reserved range of file descriptors for swtpm_setup.sh
Stefan Berger [Wed, 8 Jan 2020 19:52:20 +0000 (14:52 -0500)]
swtpm_setup: Keep reserved range of file descriptors for swtpm_setup.sh

swtpm_setup.sh uses file descriptor 100 for 'exec 100 <> ...'.
So we have to make sure that the file descriptor inherited from
the caller of swtpm_setup does not overlap with a reserved range
to be used by swtpm_setup.sh, which we declare to be [100..109].

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_setup: Log about encryption and fix c&p error in err msg
Stefan Berger [Tue, 7 Jan 2020 22:05:38 +0000 (17:05 -0500)]
swtpm_setup: Log about encryption and fix c&p error in err msg

Fix a cut and paste error in the error message output and be more
verbose in log about encryption when using file descriptors.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm: Add --print-capabilities to help screen of 'swtpm chardev'
Stefan Berger [Tue, 7 Jan 2020 15:51:49 +0000 (10:51 -0500)]
swtpm: Add --print-capabilities to help screen of 'swtpm chardev'

The --print-capabilities is missing in the 'swtpm chardev' help screen
but the code is there to interpret the command line flag. This patch
adds the missing lines to the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Fix key derivation TDES test cases to actually create TDES keys
Stefan Berger [Thu, 26 Dec 2019 04:38:51 +0000 (23:38 -0500)]
tests: Fix key derivation TDES test cases to actually create TDES keys

The byte stream contained the TDES identifier at the wrong position,
so no TDES key was created. This patch fixes this but needs an update
to libtpms since some unmarshalling/marshaling code related to TDES
was missing there as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_ioctl: Fix uninitialized variable 'pgi'
Stefan Berger [Mon, 23 Dec 2019 19:56:16 +0000 (14:56 -0500)]
swtpm_ioctl: Fix uninitialized variable 'pgi'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Add test cases for new CrytpAdjustPrimeCandidate algo
Stefan Berger [Tue, 18 Jun 2019 20:23:12 +0000 (16:23 -0400)]
tests: Add test cases for new CrytpAdjustPrimeCandidate algo

Extend the existing key derivation test case for TPM 2 with test cases
that use a newer TPM 2 state where we now exercise the new
CryptAdjustPrimeCandidate algorithm that produces the same results on
big and little enidan 32 bit and 64 bit machines. This newer algorithm
is available in libtpms with revision 155 of the TPM 2 code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Have IBM TSS2 test case use tags/v1.3.0 of the TPM 2.0 TSS repo
Stefan Berger [Sat, 21 Dec 2019 00:06:06 +0000 (19:06 -0500)]
tests: Have IBM TSS2 test case use tags/v1.3.0 of the TPM 2.0 TSS repo

Use v1.3.0 of the IBM TSS 2.0 repo.

Depending on the revision that libtpms implements, some test cases have to be
replaced with empty files.

The test suite now works with the libtpms stable-0.6.0 and stable-0.7.0
branches. A patch fixing an NV PIN issue needed to be applied to those
branches.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoFix a 1 letter typo in INSTALL instructions
George Almasi [Tue, 3 Dec 2019 18:59:25 +0000 (18:59 +0000)]
Fix a 1 letter typo in INSTALL instructions

Signed-off-by: George Almasi <gheorghe@us.ibm.com>
4 years agoTravis: Add asan build for non-openssl usage in libtpms
Stefan Berger [Wed, 27 Nov 2019 16:01:13 +0000 (11:01 -0500)]
Travis: Add asan build for non-openssl usage in libtpms

Since I am not often using the non-openssl crypto function usage
in libtpms, add a build to Travis that exercises the old code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agotests: Protect variable with executable with quotes
Stefan Berger [Mon, 18 Nov 2019 12:00:36 +0000 (07:00 -0500)]
tests: Protect variable with executable with quotes

The test_print_capability is failing if SWTPM_EXE is for example
holding more than one parameter like 'valgrind ... /bin/swtpm' since the
variable was not protected with quotes. This patch fixes this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoTravis: Work around failing OsX builds due to brew error
Stefan Berger [Thu, 24 Oct 2019 20:27:29 +0000 (16:27 -0400)]
Travis: Work around failing OsX builds due to brew error

The Travis build on OSX was failing due to the following error:

/usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative': \
   /usr/local/Homebrew/Library/Homebrew/global.rb:110: \
   syntax error, unexpected keyword_rescue, expecting keyword_end (SyntaxError)

from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'

The command "brew tap discoteq/discoteq" failed and exited with 1 during .

This patch resolves the issue.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoswtpm_cert: Use gnutls_x509_crt_get_subject_key_id API call for subj keyId
Stefan Berger [Tue, 22 Oct 2019 15:06:32 +0000 (11:06 -0400)]
swtpm_cert: Use gnutls_x509_crt_get_subject_key_id API call for subj keyId

Use the gnutls_x509_crt_get_subject_key_id() API call to get the subject
key ID of the signer's certificate rather than gnutls_x509_crt_get_key_id().
The latter returns the same result most of the time but there are instances
when this is not the case and the returned result is wrong.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
4 years agoCorrect parameter name typo
Jeremy Liu [Mon, 14 Oct 2019 09:50:25 +0000 (17:50 +0800)]
Correct parameter name typo

Signed-off-by: Jeremy Liu <liujiong@gohighsec.com>
4 years agoswtpm_cert: Fix OIDs for TPM 2 platforms data
Stefan Berger [Wed, 9 Oct 2019 20:01:07 +0000 (16:01 -0400)]
swtpm_cert: Fix OIDs for TPM 2 platforms data

The OIDs for the TPM 1.2 and TPM 2 platform data
are different (though have the same name in the spec).
Adapt them for the TPM 2 case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Skip seccomp check if env. sets up seccomp profile
Stefan Berger [Thu, 8 Aug 2019 10:47:24 +0000 (06:47 -0400)]
tests: Skip seccomp check if env. sets up seccomp profile

If the test environment is running in a seccomp profile do not check
that the seccomp profile of the swtpm process runs with the action
provided in --seccomp action=... since the environment may override
this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoSELinux: Need more rules for QEMU and KVM type of VMs on F30
Stefan Berger [Fri, 26 Jul 2019 23:02:48 +0000 (19:02 -0400)]
SELinux: Need more rules for QEMU and KVM type of VMs on F30

More rules are needed for QEMU and KVM type VMs on F30.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Fix typo in error report: HMAC instead of hash
Stefan Berger [Thu, 25 Jul 2019 11:07:00 +0000 (07:07 -0400)]
swtpm: Fix typo in error report: HMAC instead of hash

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Use writev_full rather than writev; fixes --vtpm-proxy EIO error
Stefan Berger [Tue, 23 Jul 2019 12:09:11 +0000 (08:09 -0400)]
swtpm: Use writev_full rather than writev; fixes --vtpm-proxy EIO error

We have to use writev_full() when --vtpm-proxy is used since writev()
does not seem to work and we get an EIO error. writev_full() uses write(),
so we can use it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoSELinux: A few more rules needed for F30
Stefan Berger [Tue, 23 Jul 2019 11:42:37 +0000 (07:42 -0400)]
SELinux: A few more rules needed for F30

A few more rules are needed on Fedora 30 to have libvirt start swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agorpm: Adjust the RPM spec for 0.2.0 release
Stefan Berger [Tue, 16 Jul 2019 18:38:34 +0000 (14:38 -0400)]
rpm: Adjust the RPM spec for 0.2.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agotests: Fix spelling of call to function validate_pidfile
Stefan Berger [Fri, 19 Jul 2019 14:11:00 +0000 (10:11 -0400)]
tests: Fix spelling of call to function validate_pidfile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agodebian: Adjust changelog for 0.2.0 release
Stefan Berger [Tue, 16 Jul 2019 18:28:24 +0000 (14:28 -0400)]
debian: Adjust changelog for 0.2.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoCHANGES: Write changelog for v0.2.0
Stefan Berger [Tue, 16 Jul 2019 18:26:29 +0000 (14:26 -0400)]
CHANGES: Write changelog for v0.2.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Address Coverity's dead code complaint
Stefan Berger [Sun, 14 Jul 2019 01:29:46 +0000 (21:29 -0400)]
swtpm: Address Coverity's dead code complaint

Signed-off-by: stefan Berger <stefanb@linux.ibm.com>
5 years agoTravis: Only clone libtpms if libtpms dir does not exist
Stefan Berger [Sat, 13 Jul 2019 20:54:59 +0000 (16:54 -0400)]
Travis: Only clone libtpms if libtpms dir does not exist

Only build the libtpms dir if it doesn't exist. When we do a Coverity
scan build it looks like we are now running the script afterwards as
well and this creates a build failure due to the 2nd clone.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
5 years agoswtpm: Loop over poll() in case of EINTR
Stefan Berger [Sat, 13 Jul 2019 01:04:04 +0000 (21:04 -0400)]
swtpm: Loop over poll() in case of EINTR

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>