Commit Graph

1332 Commits

Author SHA1 Message Date
Stefan Berger
1fe885aaba swtpm_cert: cleanup whitespace errors
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-16 21:22:19 -04:00
Stefan Berger
c8c2ff3eaa swtpm_cert: factor out encode_asn1 function
Move common code into encode_asn1 function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-16 21:22:19 -04:00
Stefan Berger
8740ec5765 samples: Use the --add-header option for TPM 1.2
Use the --add-header option when writing a cert for a TPM 1.2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-12 13:20:21 -04:00
Stefan Berger
8c473d6176 swtpm_cert: Implement --add-header option for adding TPM 1.2 NVRAM header
TPM 1.2 certificates need a header when written to NVRAM. This patch
adds a --add-header option for this and prepends the header to.
Also see TCG PC Specific Inmplementation Specification section 7.4.4 and
7.4.5.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-12 13:17:39 -04:00
Stefan Berger
640f1fab05 swtpm: Implement mode parameter for --tpmstate option
Implement a mode parameter for the tpmstate option so that the user
can choose what the file mode bits of the TPM's state files will be.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-10 14:30:14 -04:00
Stefan Berger
929a112936 rpm build: Update SELinux policy files for swtpm and swtpm_cuse
swtpm use swtpm.pp and swtpm_svirt.pp. swtpm_cuse only uses
swtpm_cuse.pp now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-09 15:08:52 -04:00
Stefan Berger
6fcd12236a selinux: replace swtpmcuse_svirt with swtpm_svirt
Replace the previously used swtpmcuse_svirt type of policy with
swtpm_svirt. This policy contains the minimum set of rules necessary
to start swtpm from within libvirt.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-04-09 12:08:46 -04:00
Stefan Berger
8e2525924d swtpm_setup: allow passing of uid numbers for user Ids.
Try to parse a userid as an integer first and only if that fails,
interpret it as a name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-05 18:24:28 -04:00
Stefan Berger
cebb1a9c1f swtpm: allow passing of uid numbers for user Ids.
Try to parse a userid as an integer first and only if that fails,
interpret it as a name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-05 18:24:28 -04:00
Stefan Berger
f4286d0a0e swtpm: Also remove pidfile at end if fd was passed
Address the issue that the pidfile needs to be removed at the end if
a file descriptor was passed in. So we have to look up the file
given the file descriptor and by using /proc/self/fd/.
We also want to make sure that the given file descriptor describes
a regular file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-05 18:24:26 -04:00
Stefan Berger
db60877590 swtpm: Allow file desciptor passing for pid file
Allow the passing of a file descriptor where the PID file will
be written into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-05 10:43:25 -04:00
Stefan Berger
0d00e18f87 selinux: update policy for swtpm to support libvirt integration
Update the SELinux for swtpm so that swtpm can be launched from
libvirtd and QEMU can access swtpm's UnixIO socket and talk to it.

Use this as follows:

> cd src/selinux
> make clean all
> semodule -i *.pp
> restorecon /usr/bin/swtpm*

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-04 12:37:18 -04:00
Stefan Berger
f34e01a5a9 swtpm: Add 'uid' and 'gid' parameter to set UnxiIO file ownership
Implement support for uid and gid parameters that allows us to set the file
ownership of a UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-03 07:48:25 -04:00
Stefan Berger
682fe58172 swtpm: Add 'mode' parameter to allow setting UnixIO path file mode bits
Implement support for a mode parameter that allows us to set the file
mode bits on a UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-03 07:30:56 -04:00
Stefan Berger
a31a26ea0a tests: test fails earlier now that blobs are validated
Loading an invalid state blobs now fails ealier since libtpms is
called to check whether it can accept the blob.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 22:04:23 -04:00
Stefan Berger
7f46fa867f Register libtpms callbacks a lot earlier
Create tpmlib_register_callbacks and call it to register the
libtpms callbacks a lot earlier. Before it was done in tpmlib_start,
which was invoked by CMD_INIT, which was after state blobs could
have been set already.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 22:00:20 -04:00
Stefan Berger
55369fb652 travis: checkout tpm2-preview.rev146.v2 branch of libtpms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-14 15:38:01 -04:00
Stefan Berger
86b27a739e swtpm: add hex numbers to CMD_* enums
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-05 13:25:32 -05:00
Stefan Berger
66a10b3028 swtpm: Fix memory leak in ctrlchannel related to sockpath
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:11:12 -05:00
Stefan Berger
716608eca2 swtpm: fix memory leaks when getting or setting state
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:00:25 -05:00
Stefan Berger
98059a2908 swtpm: Also check the state blob in the CUSE TPM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 15:31:09 -05:00
Stefan Berger
b085ff2335 swtpm: Validate state blobs after setting them
Validate the state blobs after they have been set (during
state migration) so that we can fall back to the migration
source in case they are not accepted by the TPM.

This patch requires the latest version of libtpms 0.6
from the master branch.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 14:24:06 -05:00
Stefan Berger
d3029efd95 tests: Fix SWTPM_EXEC to be SWTPM_EXE
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 14:24:06 -05:00
Stefan Berger
d75b1b5627 debian: Remove runtime dependency on expect tool
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:32:10 -05:00
Stefan Berger
6e17ee7bc3 rpm: Remove runtime dependency on expect tool
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:30:44 -05:00
Stefan Berger
6e79c3b32d swtpm_setup: avoid using expect tool whenever possible
Avoid using the expect tool as much as possible. Use it only if
the user requested a special owner and/or SRK password.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:29:37 -05:00
Stefan Berger
78c185487e swtpm_setup: Strictly use passwords as specified by user
Use the passwords as specified by the user also when only temporarily
taking ownership. Use the zero password in case nothing has been
provided by the user. This is a first step to loosen the dependency
on expect, which pulls in too many dependencies.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:10:33 -05:00
Stefan Berger
84629d2c5d build: add missing load_vtpm_proxy file for 'make dist'
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-06 10:38:03 -05:00
Stefan Berger
bf544661b0 swtpm: loop in case poll sets errno EINTR
In case the poll() is interrupted by a signal handler and we
get EINTR, we loop again assuming that the signal handler will
send us a notification to end.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:07:46 -05:00
Stefan Berger
4a10cb1380 swtpm: close client file descriptor if POLLERR is indicated
POLLERR is indicated in some error cases when using the chardev with the
vtpm_proxy with runc. In case the flag is set, we terminate the client
connection rather than endlessly looping.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:01:01 -05:00
Stefan Berger
83764896f0 swtpm: Refuse to accept passed file descriptors < 3
File descriptors 0, 1, and 2, when used for file descriptor passing,
as is the case in some older version of runc/docker-ce (17.06), do
not work. So we refuse accepting these values and log the error message.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:01:01 -05:00
Stefan Berger
10241197c2 swtpm: reformat tpm_ioctl.h to also fit QEMU
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-21 19:27:33 -05:00
Stefan Berger
353ede4a17 debian: add a few more files to the tools package
Add a few more config files and the swtpm-localca tool to the
tools package.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-18 17:26:58 -05:00
Marc Kleine-Budde
3f548f90a0 treewide: remove executable bit from config files and c-code
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2018-01-17 10:45:25 -05:00
Stefan Berger
e5477e193f swtpm_setup: fix typo in help screen
--no-overwrite -> --not-overwrite

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-12 09:48:40 -05:00
Stefan Berger
be5557f3ff swtpm_cert: Sign cert using SHA256
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-02 09:41:34 -05:00
Stefan Berger
5ceed802cc samples: pass --subject to swtpm_cert since certtool needs a subject
Certtool seems to not verify a certificate chain properly unless
the certificate has a distinguished name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-21 21:14:48 -05:00
Stefan Berger
a8bc74fd01 swtpm_setup: Only pass through vmid parameter if it was set
Only pass through the vmid parameter to the tool creating the cert
if this parameter was set. The tool creating the cert may require
it or ignore it and is supposed to be able to track certificates
for which it minted certs using this parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 20:18:54 -05:00
Stefan Berger
863d1a157c samples: error if swtpm-localca gets an unsupported option passed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 20:18:54 -05:00
Stefan Berger
5b1090a583 swtpm_cert: Fix broken certificate verification
The certificate chain could not be verified due to a wrong
API call for getting the authority key id where the key id
was gotten instead.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 11:12:15 -05:00
Stefan Berger
d0f4f18352 tests: Also TPM 1.2 a valid buffer size range
Adapt the test case to check whether the TPM accepted the 4000 byte
buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-18 20:45:56 -05:00
Stefan Berger
8e9edf696a swtpm: reformat iovec and initialize input variable with zeros
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-10 11:28:59 -05:00
Stefan Berger
7306ee278a swtpm: check for invalid file descriptor (< 0)
Check for an invalid file descriptor in SWTPM_IO_Read before accessing
it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-08 09:44:17 -05:00
Stefan Berger
a56a22540e swtpm_bios: only copy the size of the source string + 1 byte
Determine the size of the unix_path parameter and then only copy
those number of bytes + terminating null into the destination.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 19:53:41 -05:00
Stefan Berger
f42eec69f3 swtpm_ioctl: only copy the size of the source string + 1 byte
Determine the size of the unix_path parameter and then only copy
those number of bytes + terminating null into the destination.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 18:06:38 -05:00
Stefan Berger
3bb2b4675a swtpm_ioctl: check for filename and input NULL pointers
Check whether filename and input pointers are NULL pointers.
Per previous code this is currently not possibly but should
resolve some issues with Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:52:27 -05:00
Stefan Berger
5d62484fb7 swtpm_ioctl: in get_blobtype() check for blobtype NULL pointer
Check whether the passed blobtype is a NULL pointer

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:45:20 -05:00
Stefan Berger
aaab5d0b16 swtpm_bios: Coverity: use void * for the command
Use void * for the command rather than tpm_header *, which we do
not need. This addresses a few Coverity complaints.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:06:00 -05:00
Stefan Berger
4f4f2f0a7e swtpm: Remove usage of TPMVersion enum
To allow it to compile with libtpms's master, remove the usage of
TPMLIB_TPMVersion type.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:50:21 -05:00
Stefan Berger
182fbb20d6 swtpm_ioctl: explicitly check for numbytes < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:45:31 -05:00