Commit Graph

1028 Commits

Author SHA1 Message Date
Stefan Berger
c7c2f90aeb swtpm_setup: bugfix: Create ECC storage primary key in owner hierarchy
The ECC storage primary key was mistakently created in the endorsement
hierarchy but should be in the owner hierarchy. This patch corrects this
to have this key created in the owner hierarchy (like the RSA key),
thus using 0x40 00 00 01.

This only mattered if one used --create-spk and --ecc together.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-01 15:27:40 -04:00
Stefan Berger
6d0ef98c50 swtpm_setup: return result of called function rather than 0
Return the result of the called function rather than 0.

Fixes: d65f5ae1 ("swtpm_setup: Create RSA 2048 and ECC NIST P256 keys and certs")
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-01 11:53:38 -04:00
Stefan Berger
21af92fd04 swtpm_setup: bugfix: remove tpm2_stirrandom and tpm2_changeeps
Remove tpm2_stirrandom, which we should not need to run on a newly
created TPM 2.
Also remove tpm2_changeeps which was called twice when creating two
EKs, thus invalidating a previous EK that may have been created.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 22:20:08 -04:00
Stefan Berger
f58ead05d8 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>
2020-04-30 13:41:50 -04:00
Stefan Berger
d65f5ae13b 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>
2020-04-30 13:41:50 -04:00
Stefan Berger
8dd0eb5d44 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>
2020-04-30 13:41:50 -04:00
Stefan Berger
3d663bacd7 swtpm_setup: Implement function to create ECC NIST P384 EK keys
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 13:41:50 -04:00
Stefan Berger
e8d9126d7b swtpm_setup: Rename NONCE_ECC to NONCE_ECC_256
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
ee95fd88c0 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>
2020-04-29 20:35:04 -04:00
Stefan Berger
8b0367e3b3 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>
2020-04-29 20:35:04 -04:00
Stefan Berger
5f694dbcb7 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>
2020-04-29 20:35:04 -04:00
Stefan Berger
72aac899fa samples: Parse optional id= for ECC curve IDs
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
fbc42b8d9f 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>
2020-04-29 20:35:04 -04:00
Stefan Berger
3fca79b82c 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>
2020-04-25 13:43:10 -04:00
Stefan Berger
d14934f3a6 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>
2020-04-24 16:20:26 -04:00
Stefan Berger
f956bce305 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>
2020-04-24 15:03:03 -04:00
Stefan Berger
ea87b5d6ec 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>
2020-04-24 12:56:08 -04:00
Stefan Berger
3a3a9f5b5f 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>
2020-04-23 16:40:13 -04:00
Stefan Berger
ea7f80176e 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>
2020-04-23 16:02:47 -04:00
Stefan Berger
e5155b4fc5 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>
2020-04-22 16:54:19 -04:00
Stefan Berger
548eb6859b 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>
2020-04-20 19:31:09 -04:00
Stefan Berger
ebd36883b2 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>
2020-04-15 19:28:26 -04:00
Stefan Berger
f30e202df6 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>
2020-04-14 13:09:00 -04:00
Stefan Berger
eb9cfa963a 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>
2020-04-13 12:26:11 -04:00
Stefan Berger
dd92f45898 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>
2020-04-12 14:32:38 -04:00
Stefan Berger
bacb56b4ec 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>
2020-04-10 09:35:20 -04:00
Stefan Berger
ecdee41147 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>
2020-04-09 20:43:43 -04:00
Stefan Berger
39b49a4e71 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>
2020-04-09 19:39:38 -04:00
Stefan Berger
0194fb22a5 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>
2020-04-09 19:39:38 -04:00
Stefan Berger
3e7555c469 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>
2020-04-09 19:39:38 -04:00
Stefan Berger
029e9d4638 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>
2020-04-09 19:39:38 -04:00
Stefan Berger
b5b48d4134 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>
2020-04-07 17:14:10 -04:00
Stefan Berger
80b0943a4f 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>
2020-04-07 16:10:28 -04:00
Stefan Berger
4931b93890 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>
2020-04-07 16:10:28 -04:00
Stefan Berger
8415d39d5f 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>
2020-04-07 12:59:27 -04:00
Stefan Berger
8ee811f98b RPM: Adjust version to 0.4.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-07 11:16:49 -04:00
Stefan Berger
728af8972a Debian: Adjust changelog for 0.4.0~dev1 developer release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-07 11:16:49 -04:00
Stefan Berger
3e3d2c82dd build-sys: Bump up version to 0.4.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-07 11:16:49 -04:00
Stefan Berger
ba65323def 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>
2020-03-18 09:20:50 -04:00
Stefan Berger
cb5ab582d1 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>
2020-03-07 09:09:14 -05:00
Stefan Berger
dfd36eb387 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>
2020-02-26 10:15:50 -05:00
Stefan Berger
74ae43bd8e RPM: Update gitcommit for a useful 0.3.0 checkout
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-17 13:58:03 -05:00
Stefan Berger
3b269659df Travis: Run make check with VERBOSE=1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-17 13:58:03 -05:00
Stefan Berger
38f36f30e3 Debian: Adjust changelog for 0.3.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-17 12:11:31 -05:00
Stefan Berger
27d3fc877b 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>
2020-02-17 12:11:31 -05:00
Stefan Berger
9c72780580 RPM: Adjust changelog for 0.3.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-17 12:11:31 -05:00
Stefan Berger
2e187bc299 build-sys: Set version to 0.3.0 for next release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-17 12:11:31 -05:00
Stefan Berger
16952a5fdc CHANGES: Add documentation for changes in 0.3.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-17 12:11:31 -05:00
Stefan Berger
d1083d1164 swtpm: Only call memcpy if tocopy != 0 (coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-14 09:53:32 -05:00
Stefan Berger
195353de60 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>
2020-02-13 20:38:48 -05:00