]> git.proxmox.com Git - swtpm.git/log
swtpm.git
6 years agoSELinux: add yet more rules for svirt for libvirt support
Stefan Berger [Fri, 27 Apr 2018 16:15:10 +0000 (12:15 -0400)]
SELinux: add yet more rules for svirt for libvirt support

Non-privileged mode needs another rule and on Fedora 27 we need
a swtpm_exec_t related rule we did not need on Fedora 23.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: fix missing space after --vmid parameter
Stefan Berger [Mon, 23 Apr 2018 17:55:03 +0000 (13:55 -0400)]
swtpm_setup: fix missing space after --vmid parameter

The extern cert program was called with --vmid <foo>--tpm-spec-family ...
and failed due to a missing whitespace. This patch fixes it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosample: propagate and log error if swtpm_cert is missing
Stefan Berger [Wed, 7 Feb 2018 01:57:28 +0000 (20:57 -0500)]
sample: propagate and log error if swtpm_cert is missing

If the swtpm_cert was missing, nothing was reported in the error log. Change
this and report it in the error log rather than writing the error in the
certificate file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: set PATH so swtpm_cert can be found
Stefan Berger [Mon, 23 Apr 2018 15:50:50 +0000 (11:50 -0400)]
tests: set PATH so swtpm_cert can be found

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: make the TPM spec parameters mandatory for the EK cert
Stefan Berger [Sun, 22 Apr 2018 02:10:36 +0000 (22:10 -0400)]
swtpm_cert: make the TPM spec parameters mandatory for the EK cert

6 years agoswtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert
Stefan Berger [Sun, 22 Apr 2018 02:01:26 +0000 (22:01 -0400)]
swtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert

Use the new --info parameter for swtpm_ioctl to get TPM specification
info from the swtpm and use this as a parameter for creating the EK
certificate.

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_ioctl: implement --info option to get implementation info
Stefan Berger [Sun, 22 Apr 2018 01:49:03 +0000 (21:49 -0400)]
swtpm_ioctl: implement --info option to get implementation info

Implement the --info option that takes a flag as an argument
and returns information about the TPM implementation. Only the
value '1' has been defined for now, which returns a line as
the following:

{"TPMSpecification":{"family":"1.2","level":2,"revision":116}}

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: implement options for pass TPM spec parameters
Stefan Berger [Sun, 22 Apr 2018 02:07:47 +0000 (22:07 -0400)]
samples: implement options for pass TPM spec parameters

Implement options --tpm-spec-family, --tpm-spec-revision, and
tpm-spec-level to pass to swtpm_cert for EK creation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement CMD_GETINFO to retrieve TPM specification info
Stefan Berger [Sun, 22 Apr 2018 01:44:31 +0000 (21:44 -0400)]
swtpm: Implement CMD_GETINFO to retrieve TPM specification info

We quetry the swtpm for TPM specification info that goes into the
certificate for the EK.

Update the test cases that now see more capabilties being returned
by the swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: source common rather than test_common
Stefan Berger [Sun, 22 Apr 2018 02:13:17 +0000 (22:13 -0400)]
tests: source common rather than test_common

6 years agoman: add an example to swtpm_setup man page
Stefan Berger [Wed, 18 Apr 2018 18:51:42 +0000 (14:51 -0400)]
man: add an example to swtpm_setup man page

Add an example for how to run swtpm_setup to simulate TPM 1.2
manufacturing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: Error out if key exists but is not readable for user
Stefan Berger [Wed, 18 Apr 2018 17:53:13 +0000 (13:53 -0400)]
samples: Error out if key exists but is not readable for user

If the key is not readable as the current user, such as tss:tss,
but it is there, we don't try to create it but error out.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Error out if the Authority Key Id could not be gotten
Stefan Berger [Tue, 17 Apr 2018 12:58:04 +0000 (08:58 -0400)]
swtpm_cert: Error out if the Authority Key Id could not be gotten

Since the EK cert must have an Authority Key Id, we error out if
the signing certificate we are given does not have an Authority
Key Id. The typical reason why it wouldn't have it is that we are
using a self-signed (rootCA) certificate directly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Use a root CA for creating the issuercert for test_swtpm_cert
Stefan Berger [Tue, 17 Apr 2018 14:22:02 +0000 (10:22 -0400)]
tests: Use a root CA for creating the issuercert for test_swtpm_cert

Update the test case test_swtpm_cert to have its issuercert signed
by a created root CA so that we have the Authority Key Id in the cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: Create a root CA that signs the cert used for creating TPM certs
Stefan Berger [Tue, 17 Apr 2018 12:52:26 +0000 (08:52 -0400)]
samples: Create a root CA that signs the cert used for creating TPM certs

We are currently missing the Authority Key Id in the certificate used for
creating the EK cert. To get this, we create a root CA for our local CA
and use that root CA to sign the local CA's certificate. Our local
CA is now an intermediate CA and the Authority Key Id can now be copied
into the EK cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: log output of tool creating cert
Stefan Berger [Tue, 17 Apr 2018 14:13:16 +0000 (10:13 -0400)]
swtpm_setup: log output of tool creating cert

Log the output of the tool that is creating the certificate and
prefix every line with the name of the tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: run exec in a subshell when suppressing errors
Stefan Berger [Tue, 17 Apr 2018 14:02:14 +0000 (10:02 -0400)]
swtpm_setup: run exec in a subshell when suppressing errors

To not loose stderr we have to run the exec command in a subshell
and suppress the output of the subshell otherwise the exec command
seems to close stderr on us.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Add Subject Directory Attributes to EK cert
Stefan Berger [Mon, 16 Apr 2018 19:18:52 +0000 (15:18 -0400)]
swtpm_cert: Add Subject Directory Attributes to EK cert

Create the TPMSpecification SEQUENCE and add it to the subject
directory attributes of an EK cert.

The code generates the same ASN.1 for the Subject Directory Attributes
as the example in the EK spec has.

> openssl asn1parse -in ${cert} -strparse 603
    0:d=0  hl=2 l=  30 cons: SEQUENCE
    2:d=1  hl=2 l=  28 cons: SEQUENCE
    4:d=2  hl=2 l=   5 prim: OBJECT            :2.23.133.2.16
   11:d=2  hl=2 l=  19 cons: SET
   13:d=3  hl=2 l=  17 cons: SEQUENCE
   15:d=4  hl=2 l=   3 prim: UTF8STRING        :1.2
   20:d=4  hl=2 l=   4 prim: INTEGER           :41010000
   26:d=4  hl=2 l=   4 prim: INTEGER           :7B000000

Extend existing test case so they create the ASN.1 as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: cleanup whitespace errors
Stefan Berger [Mon, 16 Apr 2018 19:39:50 +0000 (15:39 -0400)]
swtpm_cert: cleanup whitespace errors

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: factor out encode_asn1 function
Stefan Berger [Mon, 16 Apr 2018 19:16:17 +0000 (15:16 -0400)]
swtpm_cert: factor out encode_asn1 function

Move common code into encode_asn1 function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: Use the --add-header option for TPM 1.2
Stefan Berger [Thu, 12 Apr 2018 17:19:46 +0000 (13:19 -0400)]
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>
6 years agoswtpm_cert: Implement --add-header option for adding TPM 1.2 NVRAM header
Stefan Berger [Thu, 12 Apr 2018 17:17:37 +0000 (13:17 -0400)]
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>
6 years agoswtpm: Implement mode parameter for --tpmstate option
Stefan Berger [Tue, 10 Apr 2018 18:21:42 +0000 (14:21 -0400)]
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>
6 years agorpm build: Update SELinux policy files for swtpm and swtpm_cuse
Stefan Berger [Mon, 9 Apr 2018 18:38:12 +0000 (14:38 -0400)]
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>
6 years agoselinux: replace swtpmcuse_svirt with swtpm_svirt
Stefan Berger [Mon, 9 Apr 2018 16:06:47 +0000 (12:06 -0400)]
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>
6 years agoswtpm_setup: allow passing of uid numbers for user Ids.
Stefan Berger [Thu, 5 Apr 2018 17:42:27 +0000 (13:42 -0400)]
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>
6 years agoswtpm: allow passing of uid numbers for user Ids.
Stefan Berger [Thu, 5 Apr 2018 17:40:46 +0000 (13:40 -0400)]
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>
6 years agoswtpm: Also remove pidfile at end if fd was passed
Stefan Berger [Thu, 5 Apr 2018 17:12:21 +0000 (13:12 -0400)]
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>
6 years agoswtpm: Allow file desciptor passing for pid file
Stefan Berger [Thu, 5 Apr 2018 14:43:23 +0000 (10:43 -0400)]
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>
6 years agoselinux: update policy for swtpm to support libvirt integration
Stefan Berger [Wed, 4 Apr 2018 15:14:51 +0000 (11:14 -0400)]
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>
6 years agoswtpm: Add 'uid' and 'gid' parameter to set UnxiIO file ownership
Stefan Berger [Tue, 3 Apr 2018 00:38:35 +0000 (20:38 -0400)]
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>
6 years agoswtpm: Add 'mode' parameter to allow setting UnixIO path file mode bits
Stefan Berger [Mon, 2 Apr 2018 23:37:22 +0000 (19:37 -0400)]
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>
6 years agotests: test fails earlier now that blobs are validated
Stefan Berger [Wed, 28 Mar 2018 02:04:20 +0000 (22:04 -0400)]
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>
6 years agoRegister libtpms callbacks a lot earlier
Stefan Berger [Wed, 28 Mar 2018 02:00:17 +0000 (22:00 -0400)]
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>
6 years agotravis: checkout tpm2-preview.rev146.v2 branch of libtpms
Stefan Berger [Wed, 14 Mar 2018 19:27:43 +0000 (15:27 -0400)]
travis: checkout tpm2-preview.rev146.v2 branch of libtpms

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: add hex numbers to CMD_* enums
Stefan Berger [Mon, 5 Mar 2018 18:25:22 +0000 (13:25 -0500)]
swtpm: add hex numbers to CMD_* enums

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Fix memory leak in ctrlchannel related to sockpath
Stefan Berger [Sun, 18 Feb 2018 02:11:10 +0000 (21:11 -0500)]
swtpm: Fix memory leak in ctrlchannel related to sockpath

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: fix memory leaks when getting or setting state
Stefan Berger [Sun, 18 Feb 2018 02:00:23 +0000 (21:00 -0500)]
swtpm: fix memory leaks when getting or setting state

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Also check the state blob in the CUSE TPM
Stefan Berger [Sat, 17 Feb 2018 20:31:07 +0000 (15:31 -0500)]
swtpm: Also check the state blob in the CUSE TPM

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Validate state blobs after setting them
Stefan Berger [Sat, 17 Feb 2018 19:11:55 +0000 (14:11 -0500)]
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>
6 years agotests: Fix SWTPM_EXEC to be SWTPM_EXE
Stefan Berger [Sat, 17 Feb 2018 19:21:48 +0000 (14:21 -0500)]
tests: Fix SWTPM_EXEC to be SWTPM_EXE

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agodebian: Remove runtime dependency on expect tool
Stefan Berger [Mon, 12 Feb 2018 15:32:08 +0000 (10:32 -0500)]
debian: Remove runtime dependency on expect tool

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agorpm: Remove runtime dependency on expect tool
Stefan Berger [Mon, 12 Feb 2018 15:30:42 +0000 (10:30 -0500)]
rpm: Remove runtime dependency on expect tool

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: avoid using expect tool whenever possible
Stefan Berger [Mon, 12 Feb 2018 15:28:45 +0000 (10:28 -0500)]
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>
6 years agoswtpm_setup: Strictly use passwords as specified by user
Stefan Berger [Mon, 12 Feb 2018 15:10:31 +0000 (10:10 -0500)]
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>
6 years agobuild: add missing load_vtpm_proxy file for 'make dist'
Stefan Berger [Tue, 6 Feb 2018 15:38:03 +0000 (10:38 -0500)]
build: add missing load_vtpm_proxy file for 'make dist'

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: loop in case poll sets errno EINTR
Stefan Berger [Tue, 30 Jan 2018 14:07:42 +0000 (09:07 -0500)]
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>
6 years agoswtpm: close client file descriptor if POLLERR is indicated
Stefan Berger [Tue, 30 Jan 2018 13:54:30 +0000 (08:54 -0500)]
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>
6 years agoswtpm: Refuse to accept passed file descriptors < 3
Stefan Berger [Tue, 30 Jan 2018 13:51:27 +0000 (08:51 -0500)]
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>
6 years agoswtpm: reformat tpm_ioctl.h to also fit QEMU
Stefan Berger [Mon, 22 Jan 2018 00:27:31 +0000 (19:27 -0500)]
swtpm: reformat tpm_ioctl.h to also fit QEMU

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agodebian: add a few more files to the tools package
Stefan Berger [Thu, 18 Jan 2018 22:24:50 +0000 (17:24 -0500)]
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>
6 years agotreewide: remove executable bit from config files and c-code
Marc Kleine-Budde [Tue, 24 Oct 2017 13:24:53 +0000 (15:24 +0200)]
treewide: remove executable bit from config files and c-code

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
6 years agoswtpm_setup: fix typo in help screen
Stefan Berger [Fri, 12 Jan 2018 14:48:37 +0000 (09:48 -0500)]
swtpm_setup: fix typo in help screen

--no-overwrite -> --not-overwrite

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Sign cert using SHA256
Stefan Berger [Tue, 2 Jan 2018 14:25:06 +0000 (09:25 -0500)]
swtpm_cert: Sign cert using SHA256

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: pass --subject to swtpm_cert since certtool needs a subject
Stefan Berger [Fri, 22 Dec 2017 02:14:48 +0000 (21:14 -0500)]
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>
6 years agoswtpm_setup: Only pass through vmid parameter if it was set
Stefan Berger [Thu, 21 Dec 2017 01:15:59 +0000 (20:15 -0500)]
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>
6 years agosamples: error if swtpm-localca gets an unsupported option passed
Stefan Berger [Thu, 21 Dec 2017 01:13:59 +0000 (20:13 -0500)]
samples: error if swtpm-localca gets an unsupported option passed

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Fix broken certificate verification
Stefan Berger [Wed, 20 Dec 2017 15:51:18 +0000 (10:51 -0500)]
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>
6 years agotests: Also TPM 1.2 a valid buffer size range
Stefan Berger [Tue, 19 Dec 2017 01:45:53 +0000 (20:45 -0500)]
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>
6 years agoswtpm: reformat iovec and initialize input variable with zeros
Stefan Berger [Sun, 10 Dec 2017 16:28:54 +0000 (11:28 -0500)]
swtpm: reformat iovec and initialize input variable with zeros

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: check for invalid file descriptor (< 0)
Stefan Berger [Fri, 8 Dec 2017 14:43:07 +0000 (09:43 -0500)]
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>
6 years agoswtpm_bios: only copy the size of the source string + 1 byte
Stefan Berger [Fri, 8 Dec 2017 00:52:54 +0000 (19:52 -0500)]
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>
6 years agoswtpm_ioctl: only copy the size of the source string + 1 byte
Stefan Berger [Thu, 7 Dec 2017 23:06:36 +0000 (18:06 -0500)]
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>
6 years agoswtpm_ioctl: check for filename and input NULL pointers
Stefan Berger [Thu, 7 Dec 2017 22:50:14 +0000 (17:50 -0500)]
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>
6 years agoswtpm_ioctl: in get_blobtype() check for blobtype NULL pointer
Stefan Berger [Thu, 7 Dec 2017 22:45:18 +0000 (17:45 -0500)]
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>
6 years agoswtpm_bios: Coverity: use void * for the command
Stefan Berger [Thu, 7 Dec 2017 22:05:58 +0000 (17:05 -0500)]
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>
6 years agoswtpm: Remove usage of TPMVersion enum
Stefan Berger [Tue, 5 Dec 2017 17:48:57 +0000 (12:48 -0500)]
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>
6 years agoswtpm_ioctl: explicitly check for numbytes < 0
Stefan Berger [Tue, 5 Dec 2017 17:45:27 +0000 (12:45 -0500)]
swtpm_ioctl: explicitly check for numbytes < 0

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Do not pass a negative file descriptor
Stefan Berger [Tue, 21 Nov 2017 17:43:29 +0000 (12:43 -0500)]
swtpm: Do not pass a negative file descriptor

Do not a pass a negative file descriptor to getsockopt(). This fixes
a Coverity issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Extend encrypted state test to check for unmodified state
Stefan Berger [Tue, 14 Nov 2017 12:57:53 +0000 (07:57 -0500)]
tests: Extend encrypted state test to check for unmodified state

Extend the encrypted state test with a test case using a wrong key
for decrypting the state and make sure that the init fails and the
state files remain unmodified.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_ioctl: print error message in case setting state blob fails
Stefan Berger [Tue, 14 Nov 2017 01:44:06 +0000 (20:44 -0500)]
swtpm_ioctl: print error message in case setting state blob fails

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: log when the decryption of a state blob fails
Stefan Berger [Tue, 14 Nov 2017 01:43:01 +0000 (20:43 -0500)]
swtpm: log when the decryption of a state blob fails

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: log when the decryption of the NVRAM file fails
Stefan Berger [Tue, 14 Nov 2017 00:34:00 +0000 (19:34 -0500)]
swtpm: log when the decryption of the NVRAM file fails

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: add missing EXTRA_DIST files
Stefan Berger [Mon, 13 Nov 2017 18:49:13 +0000 (13:49 -0500)]
build: add missing EXTRA_DIST files

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: extend INIT test with case where state file is inaccessible
Stefan Berger [Sun, 12 Nov 2017 15:23:04 +0000 (10:23 -0500)]
tests: extend INIT test with case where state file is inaccessible

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Add truncate parameter for --log option
Stefan Berger [Sat, 11 Nov 2017 19:47:25 +0000 (14:47 -0500)]
swtpm: Add truncate parameter for --log option

Enable the resetting of the log using a truncate parameter for the
--log option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: always set the logging file descriptor on libtpms
Stefan Berger [Sat, 11 Nov 2017 19:24:09 +0000 (14:24 -0500)]
swtpm: always set the logging file descriptor on libtpms

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Also log the control channel exchanges
Stefan Berger [Sat, 11 Nov 2017 02:48:12 +0000 (21:48 -0500)]
swtpm: Also log the control channel exchanges

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: also log control channel commands
Stefan Berger [Sat, 11 Nov 2017 02:32:44 +0000 (21:32 -0500)]
swtpm: also log control channel commands

6 years agoswtpm: Log an error if data encryption failed
Stefan Berger [Sat, 11 Nov 2017 00:01:16 +0000 (19:01 -0500)]
swtpm: Log an error if data encryption failed

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Remove file if errors occured writing it
Stefan Berger [Fri, 10 Nov 2017 23:58:24 +0000 (18:58 -0500)]
swtpm: Remove file if errors occured writing it

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Move debugging output into own function
Stefan Berger [Fri, 10 Nov 2017 19:39:34 +0000 (14:39 -0500)]
swtpm: Move debugging output into own function

Move some of the debugging output into its own function and
differentiate output by TPM Version number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Add options to overwrite or not overwrite TPM state
Stefan Berger [Thu, 9 Nov 2017 15:46:42 +0000 (10:46 -0500)]
swtpm_setup: Add options to overwrite or not overwrite TPM state

Add options --overwrite and --not-overwrite to allow or prevent
overwriting of existing TPM state. If neiter of the options is
given and existing state is found, an error is returned.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: remove debug include file
Stefan Berger [Sun, 5 Nov 2017 20:38:11 +0000 (15:38 -0500)]
swtpm: remove debug include file

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implemented support for PTM_SET_BUFFERSIZE command
Stefan Berger [Sat, 4 Nov 2017 23:33:13 +0000 (19:33 -0400)]
swtpm: Implemented support for PTM_SET_BUFFERSIZE command

Implement a command for setting and querying the buffer size the
TPM implementation (libtpms) is using. The setting of the
buffersize allows to reduce the size of the buffer to a size
that the interface can support so that these two sizes match
and the TPM will not produce larger responses than what the
interface can support.

Extend swtpm_ioctl with an option to set the buffersize.

Adapt the existing tests to reflect the newly supported command.
Implement a new test for getting/setting of the buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: fix segfault introduced in aa3999
Stefan Berger [Mon, 30 Oct 2017 15:49:21 +0000 (11:49 -0400)]
swtpm: fix segfault introduced in aa3999

Changeset aa3999 introduced a segfault when calling
ctrlchannel_set_client_fd() with a NULL pointer. Like all the other
functions, we return with -1 in this case.

Since the segfault occurred on process shutdown no problems were
noticeable through bad test results or so.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Install SIGPIPE signal handler to ignore signal
Stefan Berger [Wed, 25 Oct 2017 15:28:06 +0000 (11:28 -0400)]
swtpm: Install SIGPIPE signal handler to ignore signal

Install a SIGPIPE signal handler to ignore the signal from trying
to write to a broken pipe.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Fix a couple of typos
Stefan Berger [Mon, 23 Oct 2017 12:57:06 +0000 (08:57 -0400)]
swtpm_setup: Fix a couple of typos

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: implement missing wait_file_gone function
Stefan Berger [Tue, 17 Oct 2017 17:49:59 +0000 (13:49 -0400)]
tests: implement missing wait_file_gone function

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: replace plain sleep with wait for PID file to be gone
Stefan Berger [Sun, 15 Oct 2017 21:17:38 +0000 (17:17 -0400)]
tests: replace plain sleep with wait for PID file to be gone

Replace the short sleeps with waits for the PID file to be gone.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: increase socat timeout for slow machines
Stefan Berger [Sun, 15 Oct 2017 17:57:23 +0000 (13:57 -0400)]
tests: increase socat timeout for slow machines

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Wait for previous socket or device to have disappeared
Stefan Berger [Sat, 14 Oct 2017 20:28:38 +0000 (16:28 -0400)]
tests: Wait for previous socket or device to have disappeared

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: clean up server and ctrlchannel at the end
Stefan Berger [Sat, 14 Oct 2017 20:26:28 +0000 (16:26 -0400)]
swtpm: clean up server and ctrlchannel at the end

Introduce another parameter to ctrlchannel_new and server_new
to pass the Unix socket's path. Implement ctrlchannel_free and
server_free to clean up and remove the Unix socket's path.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement ctrlchannel_set_client_fd()
Stefan Berger [Mon, 16 Oct 2017 17:02:01 +0000 (13:02 -0400)]
swtpm: Implement ctrlchannel_set_client_fd()

Implement ctrlchannel_set_client_fd() to set a new client
fd and return its current value.

Use this new function to set the file descriptor to -1 upon
closing its associate file descriptor in the main loop.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement server_set_fd()
Stefan Berger [Mon, 16 Oct 2017 17:11:40 +0000 (13:11 -0400)]
swtpm: Implement server_set_fd()

Implement server_set_fd() function to get the current file descriptor
and set a new one on the server structure.

Use this function to transfer the server file descriptor from the
server structure to the mainloop structure and have the main loop
close the file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_ioctl: Display error in case of read() returns < 0
Stefan Berger [Sat, 14 Oct 2017 18:59:36 +0000 (14:59 -0400)]
swtpm_ioctl: Display error in case of read() returns < 0

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Wait for swtpm to open socket or chardev
Stefan Berger [Sat, 14 Oct 2017 13:39:33 +0000 (09:39 -0400)]
tests: Wait for swtpm to open socket or chardev

Rather than waiting for some time poll for the swtpm to either
open a socket or chardev.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Fix filename used for volatilestate
Stefan Berger [Sat, 14 Oct 2017 21:54:38 +0000 (17:54 -0400)]
tests: Fix filename used for volatilestate

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: fix linker SEARCH_DIR extraction for OpenBSD and Cygwin
Stefan Berger [Wed, 11 Oct 2017 18:03:31 +0000 (14:03 -0400)]
build: fix linker SEARCH_DIR extraction for OpenBSD and Cygwin

Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
6 years agoswtpm: Fix header inclusion for OpenBSD
Stefan Berger [Wed, 11 Oct 2017 18:03:31 +0000 (14:03 -0400)]
swtpm: Fix header inclusion for OpenBSD

Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>