Commit Graph

1439 Commits

Author SHA1 Message Date
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
Stefan Berger
374b66913f swtpm: Address Coverity's dead code complaint
Signed-off-by: stefan Berger <stefanb@linux.ibm.com>
2019-07-13 21:53:13 -04:00
Stefan Berger
a38cb19b97 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>
2019-07-13 21:26:10 -04:00
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