Commit Graph

1028 Commits

Author SHA1 Message Date
Stefan Berger
695274e024 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>
2020-02-08 18:19:08 -05:00
Stefan Berger
041a70e7b0 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>
2020-02-08 18:19:08 -05:00
Stefan Berger
e6bc4bdf0a 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>
2020-02-08 18:19:08 -05:00
Stefan Berger
99f442f37c 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>
2020-02-04 19:55:47 -05:00
Stefan Berger
28f1209816 tests: Display SWTPM_CERT that's being used during test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
6eef00e416 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>
2020-01-30 08:52:58 -05:00
Stefan Berger
a718f2a9e7 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>
2020-01-30 08:52:58 -05:00
Stefan Berger
88c7bdc9e3 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>
2020-01-30 08:52:58 -05:00
Stefan Berger
961bb827a4 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>
2020-01-30 08:52:58 -05:00
Stefan Berger
b35eb9fcd5 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>
2020-01-30 08:52:58 -05:00
Stefan Berger
b291eb83ed 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>
2020-01-27 09:16:16 -05:00
Stefan Berger
f9547ddc2c 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>
2020-01-27 09:16:16 -05:00
Stefan Berger
77819bb2e6 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>
2020-01-27 09:16:16 -05:00
Stefan Berger
d66f4d1e03 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>
2020-01-22 19:32:24 -05:00
Stefan Berger
3eef9811b9 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>
2020-01-22 19:32:24 -05:00
Stefan Berger
f27256f154 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>
2020-01-22 19:32:24 -05:00
Stefan Berger
abadb408a9 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>
2020-01-22 19:32:24 -05:00
Stefan Berger
de10d7cd59 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>
2020-01-17 20:07:37 -05:00
Stefan Berger
930c7ba16e 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>
2020-01-15 15:49:51 -05:00
Stefan Berger
194bfc66b9 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>
2020-01-14 20:26:36 -05:00
Stefan Berger
0232f78f0d 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>
2020-01-14 20:26:36 -05:00
Stefan Berger
c5748a5354 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>
2020-01-13 15:03:01 -05:00
Stefan Berger
f59c33009d 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>
2020-01-13 15:03:01 -05:00
Stefan Berger
9c2e4dc58a 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>
2020-01-13 15:03:01 -05:00
Stefan Berger
84f350dace 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>
2020-01-13 15:03:01 -05:00
Stefan Berger
996ad55fbc 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>
2020-01-13 15:03:01 -05:00
Stefan Berger
41cae9e1bd 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>
2020-01-13 15:03:01 -05:00
Stefan Berger
fa0ecd9951 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>
2020-01-09 14:22:50 -05:00
Stefan Berger
5196855ad1 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>
2020-01-07 20:06:03 -05:00
Stefan Berger
a7c4f3734a 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>
2020-01-07 11:18:10 -05:00
Stefan Berger
d396839543 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>
2019-12-26 00:08:35 -05:00
Stefan Berger
8330ccd07e swtpm_ioctl: Fix uninitialized variable 'pgi'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-12-23 15:06:33 -05:00
Stefan Berger
8e95c996d2 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>
2019-12-23 14:14:25 -05:00
Stefan Berger
8dc2415d53 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>
2019-12-20 23:11:06 -05:00
George Almasi
b3c0b158e6 Fix a 1 letter typo in INSTALL instructions
Signed-off-by: George Almasi <gheorghe@us.ibm.com>
2019-12-04 16:13:53 -05:00
Stefan Berger
60e3abc3c8 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>
2019-11-27 11:20:26 -05:00
Stefan Berger
c359fed0a2 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>
2019-11-18 07:34:19 -05:00
Stefan Berger
0151abba99 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>
2019-10-25 10:54:54 -04:00
Stefan Berger
132bbf7b7a 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>
2019-10-22 12:39:29 -04:00
Jeremy Liu
36bfbb7432 Correct parameter name typo
Signed-off-by: Jeremy Liu <liujiong@gohighsec.com>
2019-10-17 12:29:38 -04:00
Stefan Berger
a85b7d2823 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>
2019-10-11 08:34:30 -04:00
Stefan Berger
1ce7293d3c 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>
2019-08-08 09:36:04 -04:00
Stefan Berger
ab1b346ef0 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>
2019-07-26 20:38:46 -04:00
Stefan Berger
bea37691ac swtpm: Fix typo in error report: HMAC instead of hash
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-25 10:09:25 -04:00
Stefan Berger
5c5d3b793b 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>
2019-07-23 10:06:20 -04:00
Stefan Berger
7491ed0f2a 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>
2019-07-23 10:06:20 -04:00
Stefan Berger
bac3fc7ce1 rpm: Adjust the RPM spec for 0.2.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 13:47:02 -04:00
Stefan Berger
817d3a8863 tests: Fix spelling of call to function validate_pidfile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 10:31:07 -04:00
Stefan Berger
c487ba77e5 debian: Adjust changelog for 0.2.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-16 14:28:28 -04:00
Stefan Berger
e6512b84c6 CHANGES: Write changelog for v0.2.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-16 14:26:32 -04:00