]> git.proxmox.com Git - swtpm.git/log
swtpm.git
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>
6 years agotests: Check for existing chardev and use uname -s
Stefan Berger [Wed, 11 Oct 2017 18:29:13 +0000 (14:29 -0400)]
tests: Check for existing chardev and use uname -s

Check whether /dev/ptmx or /dev/ptm exists and use it to open a file
descriptor on it, raise an error otherwise.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: wrap sha1 and file size tools
Stefan Berger [Wed, 11 Oct 2017 18:27:38 +0000 (14:27 -0400)]
tests: wrap sha1 and file size tools

OpenBSD uses different tools for sha1 and file size calculations,
so we wrap them in functions and check which one to call by using
uname -s.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: use uname -s to check for Linux
Stefan Berger [Wed, 11 Oct 2017 18:16:29 +0000 (14:16 -0400)]
tests: use uname -s to check for Linux

Use uname -s to check for Linux rather than uname -o, which doesn't
seem to be supported on OpenBSD.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: write binary string into file and then cat into device
Stefan Berger [Wed, 11 Oct 2017 18:13:01 +0000 (14:13 -0400)]
tests: write binary string into file and then cat into device

Rather than using the non-bash echo tool, which doesn't seem to
support -e on OpenBSD, use the bash echo tool to write the binary
code into a file and cat the file into the device. This also works
around a problem when a sequence contains \x0a, which then seems
to be the last character written to the device if bash's echo is
used. It does this correctly when writing to a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: fix name of PID file
Stefan Berger [Wed, 11 Oct 2017 18:08:32 +0000 (14:08 -0400)]
tests: fix name of PID file

Signed-off-byt: Stefan Berger <stefanb@linux.vnet.ibm.com>

6 years agoswtpm_ioctl: Define missing #define's for OpenBSD
Stefan Berger [Wed, 11 Oct 2017 18:07:00 +0000 (14:07 -0400)]
swtpm_ioctl: Define missing #define's for OpenBSD

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_bios: include sys/socket.h for OpenBSD
Stefan Berger [Wed, 11 Oct 2017 18:04:27 +0000 (14:04 -0400)]
swtpm_bios: include sys/socket.h for OpenBSD

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

On OpenBSD the socket's name would be cut short by one letter at the
end due to an off-by-one for the calculated sockaddr struct's length.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: reformat source
Stefan Berger [Wed, 11 Oct 2017 18:03:31 +0000 (14:03 -0400)]
swtpm: reformat source

Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
6 years agoswtpm: Do not set PTM_CAP_SET_DATAFD flag on Cygwin
Stefan Berger [Fri, 6 Oct 2017 01:30:59 +0000 (21:30 -0400)]
swtpm: Do not set PTM_CAP_SET_DATAFD flag on Cygwin

The control channel of a UnixIO socket is not supported
on Cygwin, so do not present this flag. Return an error
if this command is run.

Adapt the test case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: copy 'swtpm chardev' test to test_ctrlchannel4
Stefan Berger [Fri, 6 Oct 2017 01:10:25 +0000 (21:10 -0400)]
tests: copy 'swtpm chardev' test to test_ctrlchannel4

Copy the test case that use 'swtpm chardev' to test_ctrlchannel4
and convert this test in test_ctrlchannel to use a socket. Make
test_ctrlchannel run on all platforms. test_ctrlchannel4 only
runs when WITH_CHARDEV is set in the Makefile.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Split off CMD_SET_DATAFD test into own file
Stefan Berger [Thu, 5 Oct 2017 21:25:49 +0000 (17:25 -0400)]
tests: Split off CMD_SET_DATAFD test into own file

Split off the CMD_SET_DATAFD into its own file. This test only works on
Linux, so we skip it on Cygwin for example. Otherwise it should be able
to run.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: convert test_ctrlchannel to use functions
Stefan Berger [Thu, 5 Oct 2017 21:16:20 +0000 (17:16 -0400)]
tests: convert test_ctrlchannel to use functions

Convert the test_ctrlchannel to use the functions from tests/common.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoman: Update description in man page to reflect ctrl channel commands
Stefan Berger [Wed, 4 Oct 2017 18:42:28 +0000 (14:42 -0400)]
man: Update description in man page to reflect ctrl channel commands

Update the description in the man page to reflect ioctl's and
control channel commands.

Update to the latest supported commands.

Fix a few text locations on the way.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotest: add script to test 32bit and 64bit versions
Stefan Berger [Wed, 4 Oct 2017 22:28:18 +0000 (18:28 -0400)]
test: add script to test 32bit and 64bit versions

Add a script to build and test 32 bit and 64 bit versions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_cert: add cast to avoid compile error on i686
Stefan Berger [Wed, 4 Oct 2017 22:24:56 +0000 (18:24 -0400)]
swtpm_cert: add cast to avoid compile error on i686

Cast the exponent to unsigned long int to avoid a compiler
error reporting comparison of signed and unsigned integers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: Allow to specify SWTPM_EXE, SWTPM_IOCTL and SWTPM_BIOS for tests
Stefan Berger [Wed, 4 Oct 2017 20:20:20 +0000 (16:20 -0400)]
tests: Allow to specify SWTPM_EXE, SWTPM_IOCTL and SWTPM_BIOS for tests

To enable the test suite to for example run a mixture of 32- and
64bit executables, allow users to specify the executables to use by
setting the variables SWTPM_EXE, SWTPM_IOCTL, and SWTPM_BIOS via
command line.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: use send1msg() in place of sendmsg() for older twisted versions
Stefan Berger [Fri, 29 Sep 2017 23:48:31 +0000 (19:48 -0400)]
tests: use send1msg() in place of sendmsg() for older twisted versions

Use the send1msg() ot the twisted sendmsg package since sendmsg()
is only supported in more recent versions of twisted.

Following this we also don't need to install a recent version of twisted
via pip on Travis, which runs Ubuntu 14.04.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoUpdate INSTALL file for Debian
Denis Issoupov [Fri, 29 Sep 2017 23:26:22 +0000 (16:26 -0700)]
Update INSTALL file for Debian

7 years agotests: Use python twisted for sendmsg on python 2
Stefan Berger [Fri, 29 Sep 2017 17:53:06 +0000 (13:53 -0400)]
tests: Use python twisted for sendmsg on python 2

Rather than sending two separate messages with the bare python 2
API, use the python twisted package to send the control and data
in one sendmsg() call. This avoids occasional test failures in
the ctrlchannel test case that is currently sending the data and
control part of the message in 2 steps, which can lead to the
recpient not seeing the whole message.

Add python-twisted as a build dependency to the rpm and Debian
builds and the .travis.yml.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: remove whitespace error
Stefan Berger [Fri, 29 Sep 2017 17:28:42 +0000 (13:28 -0400)]
swtpm: remove whitespace error

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotravis: Add pep8 test for python code
Stefan Berger [Fri, 29 Sep 2017 17:35:50 +0000 (13:35 -0400)]
travis: Add pep8 test for python code

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: reformat .py code to have pep8 pass without errors
Stefan Berger [Fri, 29 Sep 2017 17:28:07 +0000 (13:28 -0400)]
tests: reformat .py code to have pep8 pass without errors

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoRemove code duplication related to TCP socket creation
Amarnath Valluri [Thu, 21 Sep 2017 12:11:42 +0000 (15:11 +0300)]
Remove code duplication related to TCP socket creation

Consider TPM_PORT environment at the time of parsing server options. This way we
can avoid the code duplication, hence removed obslote code.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
7 years agoSupport added to receive data socket over control socket
Amarnath Valluri [Wed, 20 Sep 2017 13:09:46 +0000 (16:09 +0300)]
Support added to receive data socket over control socket

As objected by QEMU upstream developers to use two different sockets for
starting/using of swtpm, This commit adds support for passing unix domain
socket over control channel.

The summary of the changes include:
 - Defined new control command CMD_SET_DATAFD, using this clients can send data
   socket.
 - set mlp.fd and mlp.flags outside of the mainloop
 - updated the testcases

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
7 years agoswtpm: switch to recvmsg for receiving data
Stefan Berger [Wed, 27 Sep 2017 20:13:51 +0000 (16:13 -0400)]
swtpm: switch to recvmsg for receiving data

In preparation for receiving control messages via UnixIO sockets,
switch to recvmsg() for receiving the first chunk of data.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: enable receiving control commands in chunks
Stefan Berger [Wed, 27 Sep 2017 16:08:24 +0000 (12:08 -0400)]
swtpm: enable receiving control commands in chunks

Enable receiving control commands in small chnunks. Allow 500ms
for the whole control command to be received.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: add missing PTM_CAP_GET_CONFIG to returned flags
Stefan Berger [Wed, 27 Sep 2017 11:11:13 +0000 (07:11 -0400)]
swtpm: add missing PTM_CAP_GET_CONFIG to returned flags

Add the missing PTM_CAP_GET_CONFIG to the returned flags.

Fix the order of the flags on the way.

Fix the test cases that test for the flags.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Make 32bit CUSE swtpm work on 64bit host
Stefan Berger [Tue, 26 Sep 2017 15:39:28 +0000 (11:39 -0400)]
swtpm: Make 32bit CUSE swtpm work on 64bit host

Remove the check for the FUSE_IOCTL_COMPAT flag to make a 32bit
CUSE swtpm work on 64bit host.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoBuild: Fix coverity_scan parameters
Stefan Berger [Fri, 22 Sep 2017 14:04:55 +0000 (10:04 -0400)]
Build: Fix coverity_scan parameters

Use a new and encrypted token. Fix other parameters. Build works now
and submits to coverity if coverty_scan branch is pushed to.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoExtend Travis integration with Coverity Scans
Stefan Berger [Fri, 22 Sep 2017 13:46:23 +0000 (09:46 -0400)]
Extend Travis integration with Coverity Scans

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoci: add .travis.yml
Stefan Berger [Mon, 31 Jul 2017 16:49:49 +0000 (12:49 -0400)]
ci: add .travis.yml

Add script for integration with Travis.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: raise error on unhandle command line parameters
Stefan Berger [Tue, 25 Jul 2017 14:59:12 +0000 (10:59 -0400)]
swtpm: raise error on unhandle command line parameters

Raise an error on unhandled non-option command line parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix possible illegal buffer access
Stefan Berger [Tue, 18 Jul 2017 21:02:59 +0000 (17:02 -0400)]
Fix possible illegal buffer access

Fix possible illegal buffer access in case a character device
is used via ioctl. In this case we have to make sure we only
access the number of bytes in the ioctl structure itself.

In case of a socket, make sure we received enough bytes to
be able to access the payload.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix memory leak of tpmstatedir in case of error
Stefan Berger [Tue, 18 Jul 2017 20:40:05 +0000 (16:40 -0400)]
Fix memory leak of tpmstatedir in case of error

Fix memory leak of tpmstatedir in case of error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix memory leak of pidfile in case of error
Stefan Berger [Tue, 18 Jul 2017 20:37:39 +0000 (16:37 -0400)]
Fix memory leak of pidfile in case of error

Fix memory leak of pidfile in case of error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: Run tests also on socket interfaces
Stefan Berger [Sun, 9 Jul 2017 08:05:51 +0000 (04:05 -0400)]
tests: Run tests also on socket interfaces

Refactor the tests so that they all run on socket interfaces as well.

Use socket ports in the range of 65400-65499 for TPM 1.2 tests.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: add functions for running swtpm and swtpm_ioctl
Stefan Berger [Thu, 15 Jun 2017 17:14:17 +0000 (13:14 -0400)]
tests: add functions for running swtpm and swtpm_ioctl

To be able to run tests with either one of the interfaces, add function
for running swtpm and swtpm_ioctl commands and form the command line
parameters dependent on the type of interface being passed. We rely on
environment variables to provide the specific parameters that are needed
to run the program with the appropriate parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoIntroduce '--flag not-need-init' for socket and chardev
Stefan Berger [Mon, 10 Jul 2017 14:29:10 +0000 (10:29 -0400)]
Introduce '--flag not-need-init' for socket and chardev

Change the startup behavior with respect to requiring an INIT command
via control channel. We change this for the socket and chardev
interfaces so that the behavior now is the same as that of the CUSE
interface.

Introduce the --flag not-need-init command line option for the socket
and chardev interfaces to allow the old behavior using this option.

Adapt some of the test cases and swtpm_setup.sh.in that now need this
command line flag.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_setup: Allow running swtpm_setup as tss directly
Stefan Berger [Tue, 11 Jul 2017 17:19:40 +0000 (13:19 -0400)]
swtpm_setup: Allow running swtpm_setup as tss directly

Allow running swtpm_setup directly as tss user using the following
command lines as an example for how to do it:

mkdir /tmp/test-tss
chown tss:tss /tmp/test-tss
chmod 770 /tmp/test-tss
su -c "swtpm_setup --tpm-state /tmp/test-tss" -s /bin/sh tss

This change prevents us from requiring invocation under the root
user.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_setup: replace show_help variable by change_user
Stefan Berger [Tue, 11 Jul 2017 17:12:01 +0000 (13:12 -0400)]
swtpm_setup: replace show_help variable by change_user

Replace the show_help variable with change_user varaible with
opposite logic. The name of the variable is better for upcoming
changes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix return code for ResetEstablishmentBit
Stefan Berger [Sun, 9 Jul 2017 15:20:16 +0000 (11:20 -0400)]
Fix return code for ResetEstablishmentBit

If the return code from the command processing function is 0,
get the error code from the command response and return that one
instead. The problem was that clients though resetting the
establishment bit worked in locality 0 for example, while it did
not.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix a parameter problem in non-Linux function prototype
Stefan Berger [Sun, 9 Jul 2017 15:21:21 +0000 (11:21 -0400)]
Fix a parameter problem in non-Linux function prototype

A parameter from the TPM2 backport had not been removed. Fix it so
it compiles on cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_ioctl: fix ctrlcmd return parameter and fix state recv logic
Stefan Berger [Fri, 30 Jun 2017 19:52:32 +0000 (15:52 -0400)]
swtpm_ioctl: fix ctrlcmd return parameter and fix state recv logic

Return the number of bytes received in case ctrlcmd does not
use an ioctl because in this case we need to know how many bytes
we received in the response.

The receiving of the state blob also needs to take into account
how many bytes were received in the initial response so we write
the proper amount of bytes from that response into the file.

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