Commit Graph

926 Commits

Author SHA1 Message Date
Stefan Berger
ad2fb40077 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>
2019-07-13 12:48:36 -04:00
Stefan Berger
a442092d8e swtpm: Convert read() to read_eintr() which handles EINTR
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
37ac6aec73 swtpm: Implement read_eintr() to read into a buffer and handle EINTR
Implement read_eintr() to read into a buffer and handle EINTR on
the way.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
ec355ee80c swtpm: Use write_full instead of plain write
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
2d921e663c swtpm: Implement write_full and writev_full
Implement write_full and writev_full that handle partial writes.

Implement writev_full using write_full since handling partial writes
with iovec's can become quite complicated.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
01ad1d03f1 tests: Get swtpm PID from shell and validate against pidfile after
Get the PID of the started swtpm from the shell and validate it
against the contents of the pidfile afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
30e12eae27 SELinux: Add rule for passing pass phrase via file descriptor
Add a rule so we can pass a passphrase from libvirt to swtpm using
a file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
0db8249cf1 tests: Extend --print-capabilities tests with test of swtpm_setup
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
166d7b4204 man: Document swtpm_setup --print-capabilities option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
1edad44acd swtpm_setup: Add --print-capabilities option
Extend swtpm_setup with the --print-capabilities option which
prints a JSON object describing supported features.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
c11bf8c5f8 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>
2019-07-12 14:18:20 -04:00
Stefan Berger
95bed8ceb4 tests: Add test case for --print-capabilities test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
14ae05b18b man: Update man pages with --print-capabilities option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
11114ba745 swtpm: Add --print-capabilities option to command line
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
1d5e07974b swtpm: Implement support for printing newly added capabilities
Implement support for printing newly added capabilities, such as
being able to read the key and password from a file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
0676fedb23 swtpm: Add missing include file to ctrlchannel.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
c2bae74975 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>
2019-07-12 14:18:20 -04:00
Stefan Berger
a794d0fe48 swtpm_setup: Avoid calling getpwnam() if change_user == false
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
51f3860dfe swtpm: Have swtpm report PTM_CAP_SEND_COMMAND_HEADER flag
Have swtpm report PTM_CAP_SEND_COMMAND_HEADER flag for a TPM 2
indicating that it knows how to handle the TCG header prefix
for the data channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
e2558a8bea swtpm: Have get_ptm_caps_supported return supported PTM_CAPs
Create function get_ptm_caps_supported and have it return the
supported PTM_CAPs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
08e619ad76 man: Add 'since v0.2' to --seccomp option documentation
--seccomp option was added in v0.2. Add this to the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
cb80f52036 swtpm: Set missing PTM_CAP_GET_INFO capability flag for CUSE TPM
CUSE TPM did not report the PTM_CAP_GET_INFO flag. This patch fixes
it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
22ecb5ce5a tests: Have IBM TSS2 test not use the raw interface anymore
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-08 07:09:16 -04:00
Stefan Berger
065bca4e18 swtpm: Handle TPM 2 command header prefix
Add support for handling the TPM 2 command header prefix that looks like this:

struct tpm2_send_command_prefix {
    uint32_t cmd;
    uint8_t  locality;
    uint32_t size;
};

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>
2019-07-08 07:09:16 -04:00
Stefan Berger
dc2895812a 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>
2019-07-08 07:09:16 -04:00
Stefan Berger
71beceeda4 swtpm: Re-add header includes for BSD
Some BSDs need more #includes than Linux does. Re-add them as I removed too many
before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-08 07:09:16 -04:00
Stefan Berger
e9f059eb2a swtpm: More cleanup in swtpm_io.c
- Simplify SWTPM_IO_Write()
- Remove unnecessary includes
- Clean up other cruft

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
6ac09331ad swtpm: Get rid of MAINLOOP_READALL flag
Now that we will always read all bytes available on a file descriptor
we don't need the MAINLOOP_READALL flag anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
e9b63593a8 swtpm: Simplify the reading of TPM commands
Simplify the readin of TPM commands to always read all available
bytes from a file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
4fd2d23b4a swtpm: Use exit in main with parameter EXIT_FAILURE/SUCCESS
Convert all return's and exit(1) to use exit with EXIT_FAILURE
or EXIT_SUCCESS as parameter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
3892b0d85c 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>
2019-07-03 11:19:23 -04:00
Stefan Berger
1ae3eff9b4 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>
2019-07-03 11:19:23 -04:00
Stefan Berger
caee678bc4 swtpm_setup: Redirect error output of swtpm_bios to stdout
Redirect the stderr output of swtpm_bioc to stdout so we can
capture the message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-03 11:19:23 -04:00
Stefan Berger
e36d7915a5 man: Fix typos in swtpm_setup man page
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-03 11:19:23 -04:00
Stefan Berger
19f9053391 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>
2019-06-28 21:48:40 -04:00
Stefan Berger
ace4a68416 man: Update swtpm_setup page with the new options for passing file descriptors
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
cd188c4adb test: Test passing file descriptor to swtpm_setup
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
fa25608f6a swtpm_setup: Allow passing file descriptor for key or password files
Also extend swtpm_setup to allow passing the file descriptor for
the key or password files or pipes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
1253088ff8 swtpm: Add missing pwdfd=<fd> to help screen
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
d398c0b923 tests: Convert existing test case to use file descriptor for reading password
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
6f57af7a03 man: Update man pages to document file descriptor for reading password
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
26933af56f swtpm: Enable reading password file from file descriptor
Enable reading the password file from a file descriptor using
--key pwdfd=<fd>

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
e7fb07e8fe swtpm: Get rid of stat() in key_read_pwdfile_fd
Get rid of stat() so that we can read from pipes as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
63717f996d swtpm: Use len as parameter to SHA512
filelen is the length of the file as it was stat'ed. len is
the number of bytes read. They should be the same. So, use
len as a parameter to SHA512() rather than filelen.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
a947bebd80 swtpm: Factor out key_load_pwdfile_fd from key_load_pwdfile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
c363aa9e7d tests: Convert existing test case to use file descriptor for reading key
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
87448aada5 man: Update man pages to document file descriptor for reading key
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
1ed09c0359 swtpm: Enable reading key from file descriptor passed via option
Enable reading the state encryption or migration keys using a
file descriptor passed via the command line option parameter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
f4be1e860c swtpm: Factor out key_load_key_fd from key_load_key
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
63def2bc64 swtpm: Consolidate the exit of parse_key_options
Consolidate the exist of the parse_key_options function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00