]> git.proxmox.com Git - swtpm.git/log
swtpm.git
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>
6 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>
6 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>
6 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>
6 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>
7 years agoswtpm: silence printf's in TPM1.2 inherited code
Stefan Berger [Thu, 29 Jun 2017 19:49:06 +0000 (15:49 -0400)]
swtpm: silence printf's in TPM1.2 inherited code

Silence the printf's in code taken from TPM1.2.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: Increase sleep time to accomocate slow ARM
Stefan Berger [Thu, 29 Jun 2017 18:27:54 +0000 (14:27 -0400)]
tests: Increase sleep time to accomocate slow ARM

Increase the timeout from 0.2 to 1 seconds so that a tests
passes on ARM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Enable --migration-key for socket and chardev interfaces
Stefan Berger [Thu, 15 Jun 2017 23:07:07 +0000 (19:07 -0400)]
swtpm: Enable --migration-key for socket and chardev interfaces

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: log error if broken header is detected
Stefan Berger [Thu, 15 Jun 2017 23:01:37 +0000 (19:01 -0400)]
swtpm: log error if broken header is detected

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: work on a copy of argv[] variables
Stefan Berger [Thu, 15 Jun 2017 22:59:25 +0000 (18:59 -0400)]
swtpm: work on a copy of argv[] variables

While parsing the options we modified the argv[] values and
the commas disappeared, which showed when checking for the
swtpm processes using 'ps'. So, work on a copy of the options
parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Fix an endianess issue in ctrlchannel and offset bug
Stefan Berger [Thu, 15 Jun 2017 22:54:12 +0000 (18:54 -0400)]
swtpm: Fix an endianess issue in ctrlchannel and offset bug

There was an offset bug in the code getting the state blobs
from a client.

Also fix an endianess bug in a control channel command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_ioctl: enable state migration for socket interface
Stefan Berger [Thu, 15 Jun 2017 22:53:31 +0000 (18:53 -0400)]
swtpm_ioctl: enable state migration for socket interface

7 years agoImplement allow-set-locality for CUSE TPM and extend test case.
Stefan Berger [Tue, 6 Jun 2017 20:44:16 +0000 (16:44 -0400)]
Implement allow-set-locality for CUSE TPM and extend test case.

Implement allow-set-locality for CUSE TPM and extend the existing
locality test case with commands that try to write the SetLocality
comamnd to the device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoExtend help screen with allow-set-locality option
Stefan Berger [Tue, 6 Jun 2017 20:42:37 +0000 (16:42 -0400)]
Extend help screen with allow-set-locality option

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoImplement support for --locality allow-set-locality option
Stefan Berger [Tue, 6 Jun 2017 18:09:59 +0000 (14:09 -0400)]
Implement support for --locality allow-set-locality option

Implement support for --locality allow-set-locality option that
is primarily useful in cases when the VTPM proxy access is enabled
by file descriptor passing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: Extend existing test with one for rejection of locality 4
Stefan Berger [Thu, 1 Jun 2017 20:29:14 +0000 (16:29 -0400)]
tests: Extend existing test with one for rejection of locality 4

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoAdd options for locality handling and SetLocality command
Stefan Berger [Thu, 1 Jun 2017 20:00:15 +0000 (16:00 -0400)]
Add options for locality handling and SetLocality command

Add options for locality handling so that commands in locality
4 for example are rejected per command line parameter. This is
useful when the vTPM is used with containers.

Also implement the custom TPM/TPM2_SetLocality command to allow
the Linux vTPM proxy driver to set the locality in which subsequent
TPM commands will be executed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: Increase socat timeout to avoid errors on slow ARM
Stefan Berger [Wed, 31 May 2017 21:47:09 +0000 (17:47 -0400)]
tests: Increase socat timeout to avoid errors on slow ARM

Avoid getting useless test failures on ARM due to low timeout settings
of socat.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agobuild: test for linux-* rather than linux-gnu
Stefan Berger [Wed, 31 May 2017 21:45:51 +0000 (17:45 -0400)]
build: test for linux-* rather than linux-gnu

Check for linux-* when testing $host_os so we properly detect
when to set WITH_VTPM_PROXY.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotests: create unix_tx function to use socat to talk to Unix socket
Stefan Berger [Wed, 31 May 2017 21:26:00 +0000 (17:26 -0400)]
tests: create unix_tx function to use socat to talk to Unix socket

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix compilation errors on Debian Jessie 32bit ARM
Stefan Berger [Wed, 31 May 2017 17:45:42 +0000 (13:45 -0400)]
Fix compilation errors on Debian Jessie 32bit ARM

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Refactor error response creation
Stefan Berger [Wed, 19 Apr 2017 23:12:56 +0000 (19:12 -0400)]
swtpm: Refactor error response creation

Refactor the function creating the error response.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Have the tpm_req_header struct packed
Stefan Berger [Wed, 19 Apr 2017 21:46:56 +0000 (17:46 -0400)]
swtpm: Have the tpm_req_header struct packed

Add missing __attribute__((packed) to tpm_req_header struct.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Check return code < 0 from handle_server_options
Stefan Berger [Tue, 18 Apr 2017 23:44:57 +0000 (19:44 -0400)]
swtpm: Check return code < 0 from handle_server_options

Fix the missing check of return code from handle_server_options
to check for negative value like all the other checks also do.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Add missing space after hex number
Stefan Berger [Fri, 7 Apr 2017 15:23:27 +0000 (11:23 -0400)]
swtpm: Add missing space after hex number

Add a missing space character after display of a hex number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Fix memory leak related to option parameters
Stefan Berger [Thu, 30 Mar 2017 00:41:37 +0000 (20:41 -0400)]
swtpm: Fix memory leak related to option parameters

Fix a memory leak related to the option parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Use logprintf wherever possible
Stefan Berger [Fri, 31 Mar 2017 12:41:08 +0000 (08:41 -0400)]
swtpm: Use logprintf wherever possible

Use logprintf wherever possible. While the logging is not set up,
print error messages to stderr and prefix them with 'swtpm: '. After
the logging has been set up all error messages go into the log file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: add logging option prefix=<prefix>
Stefan Berger [Wed, 29 Mar 2017 19:13:56 +0000 (15:13 -0400)]
swtpm: add logging option prefix=<prefix>

Add support for logging each line of output with a prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Use buffer printing for TPM_PrintAll
Stefan Berger [Wed, 29 Mar 2017 19:06:13 +0000 (15:06 -0400)]
swtpm: Use buffer printing for TPM_PrintAll

Use a buffer for printing in TPM_PrintAll. Emit the buffer
upon a new line. This prepares for printing every line with
a prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoRead all data at once incase of non-stream sockets.
Amarnath Valluri [Mon, 27 Mar 2017 08:24:59 +0000 (11:24 +0300)]
Read all data at once incase of non-stream sockets.

Add MAIN_LOOP_FLAG_READALL for non SOCK_STREAM client sockets. This allows
reading all socket data once.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
7 years agoswtpm: Keep client data connection alive
Amarnath Valluri [Fri, 31 Mar 2017 06:54:38 +0000 (09:54 +0300)]
swtpm: Keep client data connection alive

swtpm server is closing the client data connection after serving a single
request, which shall not happen. Hence added MAIN_LOOP_FLAG_KEEP_CONNECTION
mainloop flag to keep the client data connection alive, till client is alive.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
7 years agoswtpm: Added support for passing control channel client fd.
Amarnath Valluri [Wed, 15 Mar 2017 20:10:29 +0000 (22:10 +0200)]
swtpm: Added support for passing control channel client fd.

New option '--ctrl clientfd=<fd>' is added to the control socket parameters.
The passed 'fd' is used as control channel client-fd and treated as single
client mode.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
7 years agomainloop: enumerate the pollfd indexes.
Amarnath Valluri [Tue, 21 Mar 2017 13:30:57 +0000 (15:30 +0200)]
mainloop: enumerate the pollfd indexes.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
7 years agoswtpm: Set errno to 0 before calling strtoul
Stefan Berger [Fri, 31 Mar 2017 12:11:25 +0000 (08:11 -0400)]
swtpm: Set errno to 0 before calling strtoul

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_ioctl: Rearrange code for Unix client socket setup
Stefan Berger [Tue, 14 Mar 2017 11:32:08 +0000 (07:32 -0400)]
swtpm_ioctl: Rearrange code for Unix client socket setup

Rearrange the code of the setup of the Unix client socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_bios: Rearrange code for Unix client socket setup
Stefan Berger [Tue, 14 Mar 2017 12:28:24 +0000 (08:28 -0400)]
swtpm_bios: Rearrange code for Unix client socket setup

Rearrange the code of the setup of the Unix client socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Initialize variables in ctrlchannel_return_state
Stefan Berger [Tue, 14 Mar 2017 11:58:32 +0000 (07:58 -0400)]
swtpm: Initialize variables in ctrlchannel_return_state

Initialize variables in ctrlchannel_return_state so that all error cases
are properly handled.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: describe ctrlchannel_process_fd function
Stefan Berger [Tue, 14 Mar 2017 11:53:58 +0000 (07:53 -0400)]
swtpm: describe ctrlchannel_process_fd function

Describe purpose and parameters of the ctrlchannel_process_fd function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_ioctl: initialize locality variable
Stefan Berger [Tue, 14 Mar 2017 11:32:08 +0000 (07:32 -0400)]
swtpm_ioctl: initialize locality variable

Initialize the locality variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoMerge pull request #25 from pohly/patch-1
Stefan Berger [Wed, 1 Mar 2017 15:03:28 +0000 (10:03 -0500)]
Merge pull request #25 from pohly/patch-1

README: clarify status of qemu tpm patches

7 years agotest: Add --log parameter to test logging
Stefan Berger [Fri, 3 Feb 2017 20:09:41 +0000 (15:09 -0500)]
test: Add --log parameter to test logging

Add the --log parameter to test log levels 1 and 20.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: set default log level to 1
Stefan Berger [Fri, 3 Feb 2017 16:21:29 +0000 (11:21 -0500)]
swtpm: set default log level to 1

Set the default log level to 1 so that console output is shown.
This can be turned off with --log level=0

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm: Set loglevel to 1 if log file or file descriptor is given
Stefan Berger [Fri, 3 Feb 2017 15:22:27 +0000 (10:22 -0500)]
swtpm: Set loglevel to 1 if log file or file descriptor is given

Set the default log level to 1 if log file or file descriptors are
given.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoman pages: make log level bold
Stefan Berger [Thu, 2 Feb 2017 22:53:15 +0000 (17:53 -0500)]
man pages: make log level bold

Fix the log level parameter to appear in bold.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_cuse: Add log level parameter to help screen and man page
Stefan Berger [Thu, 2 Feb 2017 22:45:40 +0000 (17:45 -0500)]
swtpm_cuse: Add log level parameter to help screen and man page

Add the log level parameter to the CUSE TPM's help screen and man
page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_cert: Create sets of items
Stefan Berger [Thu, 2 Feb 2017 18:07:29 +0000 (13:07 -0500)]
swtpm_cert: Create sets of items

Following the example in the Appendix A.1 of the TCG EK Credential
Profile Spec Version 2.0, a ASN.1 SET is supposed to be created for
each one of the items. This patch fixes the format.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoswtpm_cert: use GNUTLS 3.5 function to set TPM data
Stefan Berger [Thu, 2 Feb 2017 15:49:58 +0000 (10:49 -0500)]
swtpm_cert: use GNUTLS 3.5 function to set TPM data

Use the GNUTLS 3.5 function gnutls_x509_crt_set_subject_alt_othername
to set the TP<M and platform manufacturer info since the other function
does not accept binary data.

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