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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Stefan Berger [Thu, 4 Jul 2019 13:17:10 +0000 (13:17 +0000)]
swtpm_setup: Test filenames for empty string before trying to remove
rm on NetBsd prints out an error message when trying to remove a file
with an empty filename. Avoid this situation by checking for non-empty
filenames first.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Mon, 24 Jun 2019 16:22:57 +0000 (12:22 -0400)]
swtpm: Stub handle_seccomp_options if WITH_SECCOMP is not defined
Stub out the handle_seccomp_options function and other unused
code and data if WITH_SECCOMP is not defined.
Currently the handle_seccomp_options would always be called with
a NULL string to parse if WITH_SECCOMP is not defined, so this just
eliminates the code that will never be called.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This patch converts the existing send function to use an array of struct iovec
using writev() where we can optinally prepend a response header and trailer.
We detect whether the command had the above type of header prefixed and if so
indicate this with an offset into the byte stream where the normal TPM command
starts, which follows right after this header. In case such a header was found
we prepend a header in the response and append a 4-byte trailer. For TPM 1.2
there are no changes and for raw TPM 2 commands there are no changes, either.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Fri, 5 Jul 2019 20:43:50 +0000 (16:43 -0400)]
swtpm: Have SWTPM_IO_Read read at least the 10 bytes from the TPM header
Have SWTPM_IO_Read() read at leat the 10 bytes from the (regular) TPM
header. This solves a particular problem with the TPM 2 header prefix for
which we will add support in the subsequent patch. In the prefix case the IBM
TSS 2 stack sends 4 bytes for the command, then 1 byte for the locality, and then
4 bytes for the length indicator followed by the command. If we just read once
we would only then get 4 bytes. Reading 10 bytes gets all of these plus the sub-
sequent TPM command or the whole TPM command in case this prefix header is
missing.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Wed, 3 Jul 2019 01:25:40 +0000 (21:25 -0400)]
tests: Add TPM 1.2 test cases for passing key and passphrase via fd
Add TPM 1.2 test cases to test_parameters for testing the passing of key
and passphrase via file descriptor. Also extend the test to check whether
the state files are encrypted.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Wed, 3 Jul 2019 01:18:51 +0000 (21:18 -0400)]
swtpm_setup: Use swtpm_ioctl to re-init the TPM 1.2 for activation
Since we can only read the file descriptor for the passphrase once,
we cannot stop the TPM 1.2 and then restart it but we have to use
'swtpm_ioctl -i' to re-init it.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Thu, 27 Jun 2019 22:49:26 +0000 (18:49 -0400)]
test: Make sure that when key is passed state is encrypted
Make sure that when keyfile/keyfile-fd or pwdfile/pwdfile-fd are passed
to swtpm_setup that the resulting state is actually encrypted. We check
for encrypted state by making sure that 4-byte sequences of 0-bytes are
not there while they are there for un-encrypted state.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>