Commit Graph

726 Commits

Author SHA1 Message Date
Stefan Berger
2dc486cb97 swtpm_ioctl: Define missing #define's for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
730ed7c32e swtpm_bios: include sys/socket.h for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
54ed795b60 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>
2017-10-12 13:07:46 -04:00
Stefan Berger
b20eafa7b4 swtpm: reformat source
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
1d92a4df07 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>
2017-10-11 18:57:16 -04:00
Stefan Berger
6d42968570 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>
2017-10-05 07:17:25 -04:00
Stefan Berger
a00e882c0a swtpm: remove whitespace error
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-29 13:55:56 -04:00
Amarnath Valluri
c310f1d7a0 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>
2017-09-29 13:11:44 -04:00
Amarnath Valluri
1fb8bb790f 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>
2017-09-29 13:11:01 -04:00
Stefan Berger
52d1090b74 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>
2017-09-28 09:40:16 -04:00
Stefan Berger
ec3352ff7f 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>
2017-09-28 09:40:15 -04:00
Stefan Berger
dd96bd5417 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>
2017-09-27 07:11:32 -04:00
Stefan Berger
b1fe8710d7 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>
2017-09-26 11:44:51 -04:00
Stefan Berger
f1766b31b3 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>
2017-07-25 10:59:14 -04:00
Stefan Berger
5817b1e497 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>
2017-07-18 17:16:55 -04:00
Stefan Berger
b79146caa2 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>
2017-07-18 17:08:11 -04:00
Stefan Berger
c4b8d7b443 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>
2017-07-18 17:07:59 -04:00
Stefan Berger
63ab6c3c21 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>
2017-07-11 14:04:40 -04:00
Stefan Berger
cf618c3d10 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>
2017-07-11 14:04:19 -04:00
Stefan Berger
df28cf6258 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>
2017-07-11 13:59:36 -04:00
Stefan Berger
70cb447a99 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>
2017-07-10 12:13:45 -04:00
Stefan Berger
ac78c63634 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>
2017-07-10 12:12:44 -04:00
Stefan Berger
970faf77b7 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>
2017-06-30 16:09:27 -04:00
Stefan Berger
5130f4e357 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>
2017-06-29 15:49:08 -04:00
Stefan Berger
84259c17df swtpm: Enable --migration-key for socket and chardev interfaces
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:11:33 -04:00
Stefan Berger
8a1de2ce47 swtpm: log error if broken header is detected
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:10:13 -04:00
Stefan Berger
1ff4c6c54a 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>
2017-06-15 19:10:13 -04:00
Stefan Berger
95a0542a26 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>
2017-06-15 18:54:15 -04:00
Stefan Berger
e3d8093b00 swtpm_ioctl: enable state migration for socket interface 2017-06-15 18:53:31 -04:00
Stefan Berger
dc1111362b 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>
2017-06-06 16:51:45 -04:00
Stefan Berger
3b563487b6 Extend help screen with allow-set-locality option
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 16:42:39 -04:00
Stefan Berger
a2f81ea2c6 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>
2017-06-06 14:10:01 -04:00
Stefan Berger
4a56541491 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>
2017-06-01 16:59:20 -04:00
Stefan Berger
768d657b69 Fix compilation errors on Debian Jessie 32bit ARM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 13:45:44 -04:00
Stefan Berger
b12d77106c swtpm: Refactor error response creation
Refactor the function creating the error response.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 19:16:29 -04:00
Stefan Berger
811a255869 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>
2017-04-19 18:45:35 -04:00
Stefan Berger
43153f3d26 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>
2017-04-19 18:44:47 -04:00
Stefan Berger
073e71f99e 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>
2017-04-07 11:23:30 -04:00
Stefan Berger
510f184896 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>
2017-03-31 08:55:08 -04:00
Stefan Berger
cba815690c 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>
2017-03-31 08:55:08 -04:00
Stefan Berger
93f4a38940 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>
2017-03-31 08:55:08 -04:00
Stefan Berger
8e794c635a 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>
2017-03-31 08:28:21 -04:00
Amarnath Valluri
87d56f936c 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>
2017-03-31 08:17:05 -04:00
Amarnath Valluri
0a0885cf9d 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>
2017-03-31 08:17:05 -04:00
Amarnath Valluri
93edca48a2 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>
2017-03-31 08:15:51 -04:00
Amarnath Valluri
4cb30804d6 mainloop: enumerate the pollfd indexes.
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:14:33 -04:00
Stefan Berger
3f37cc3e5f swtpm: Set errno to 0 before calling strtoul
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:14:33 -04:00
Stefan Berger
d7bbe3de5c 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>
2017-03-14 08:37:56 -04:00
Stefan Berger
faceb515c4 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>
2017-03-14 08:37:56 -04:00
Stefan Berger
753770033a 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>
2017-03-14 08:37:56 -04:00
Stefan Berger
5569ab5674 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>
2017-03-14 08:37:56 -04:00
Stefan Berger
f5b286fc7d swtpm_ioctl: initialize locality variable
Initialize the locality variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:34 -04:00
Stefan Berger
51c41a4862 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>
2017-02-03 11:21:31 -05:00
Stefan Berger
380763be6b 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>
2017-02-03 10:23:38 -05:00
Stefan Berger
c7c657ec3d 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>
2017-02-02 17:52:30 -05:00
Stefan Berger
540a9a9632 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>
2017-02-02 13:07:32 -05:00
Stefan Berger
624b11d860 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>
2017-02-02 10:50:35 -05:00
Stefan Berger
e8b5115f1a swtpm: Expose logging level to command line
Expose the logging level to the command line by extending the
log option with a level parameter.
Extend the man swtpm man page with the level parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 19:09:50 -05:00
Stefan Berger
a167784102 swtpm: Support unsigned int option
Implement support for an unsigned int option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 18:20:18 -05:00
Stefan Berger
e34f4ef8eb swtpm: Implement logging following indentation level
Introduce a log level for the logging functions. The log level
is defined by the number of spaces used for indentation. Adapt
the log functions to only log when the number of leading spaces
in a string is appropriate for logging.

Call the log function of libtpms to set the file descriptor to
log to, the log level, and log line prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 18:20:17 -05:00
Stefan Berger
f44aec27e0 swtpm: Fix buffer used in logging output
Fix the buffer used in the logging output.

Signed-off-b: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 17:52:25 -05:00
Stefan Berger
8047b5d62d Add bindaddr and ifname parameters to --server option on help screen
Fix the missing mentioning of the bindaddr and ifname parameters for
the --server option on the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 08:55:53 -05:00
Stefan Berger
4c6fc24467 Errno is not set after inet_pton
Do not call strerror(errno) after failure from inet_pton.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 08:55:49 -05:00
Stefan Berger
c751e32ec7 Only compile vTPM proxy support if available on platform
Support for vTPM proxy is only available on Linux.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 08:55:07 -05:00
Stefan Berger
099c9cb64b Announce the TPM frontend device name and major/minor numbers
Announce the TPM frontend device name and major/minor numbers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-14 15:28:05 -05:00
Stefan Berger
794f84982d swtpm: print TPM commands read from file descriptor
Print TPM commands read from the file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-13 21:48:12 -05:00
Stefan Berger
ee8b6c2d65 Implement option --vtpm-proxy to create Linux vtpm proxy device
Implement the option --vtpm-proxy that create a Linux vtpm proxy device
and makes the chardev TPM listen on the anaonymous file descriptor that
is returned from the ioctl creating the device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-13 21:45:04 -05:00
Stefan Berger
3a8a06ad0a Display chardev choice only if compiled in
Only display the chardev choice if chardev support has been
compiled in.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-03 08:22:55 -05:00
Stefan Berger
498433f7b5 Detect whether to build with chardev
Detect whether to build with the chardev interface and only run tests that
need the chardev if it is supported on a particular platform.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-03 07:18:38 -05:00
Stefan Berger
9d64b92375 Return EXIT_FAILURE if unknown command was given
Return EXIT_FAILURE to the caller if an unknown command was given.

Signed-off-by: Stefan Berger <stefan@linux.vnet.ibm.com>
2017-01-02 20:53:28 -05:00
Stefan Berger
6286beacd2 Enable building on cygwin
Enable building the swtpm on cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 20:53:28 -05:00
Stefan Berger
c3fdf68860 Skip swtpm_setup build if NVRAM tools are not available
When NVRAM tools are not available we skip building swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 20:53:28 -05:00
Stefan Berger
09d1a532ba Add configure option --with-cuse to enable building without CUSE
Enable building without CUSE interface using --without-cuse.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 18:54:30 -05:00
Stefan Berger
3aa53709a1 swtpm_setup: support --tpmstate as alias for --tpm-state
Support --tpm-state option as an alias for the --tpmstate option.
--tpm-state is a parameter that is also supported by the swtpm
program, so for consistency reasons we should have the same name
for the option here.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 20:26:53 -04:00
Stefan Berger
471d8daef2 swtpm_ioctl: Add missing option descriptions to usage page
Add missing --unix and tcp option descriptions to the usage page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 20:15:01 -04:00
Stefan Berger
4c707474d5 swtpm_bios: Fix typo in usage page
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 20:14:00 -04:00
Stefan Berger
01eb4d3a3b swtpm_ioctl: Add support for UnixIO and TCP control channel
Add support for UnixIO and TCP control channels. Both types of
transport require that packets are sent in big endian format
and therefore some code needs to be adjusted for that. The
ioctl interface is local and in that case no endianess conversion
is done.

Add a new test case that uses the extended swtpm_ioctl tool to
test the control channel.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 16:58:48 -04:00
Stefan Berger
aeee2dc88b swtpm: Fix typo in command name
Fix a typo in two command names so that they are similar to
the command name spelling used for the ioctl's.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 16:58:44 -04:00
Stefan Berger
bf2cee5c73 swtpm_ioctl: replace return codes in main()
Replace the return codes in main with EXIT_SUCCESS and EXIT_FAILURE.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 10:55:28 -04:00
Stefan Berger
37dcf15b86 swtpm_ioctl: add --tpm-device command line option
Add support for providing the TPM device via command line option
--tpm-device <device>.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 10:46:10 -04:00
Stefan Berger
96cc5d6027 swtpm_ioctl: switch to using getopt_long for option parsing
Rather than parsing the option on our own use getopt_long() now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-19 14:21:58 -04:00
Stefan Berger
fc4e289617 swtpm_bios: Add support for UnixIO socket
Add support for UnixIO socker using --unixio command line
option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 17:21:20 -04:00
Stefan Berger
7382352955 swtpm: Add support for commands over UnixIO socket
Add support for receiving TPM commands over UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 17:15:08 -04:00
Stefan Berger
ea898d5b63 swtpm_bios: Add option parameter --tcp to connect to TCP socket
Add support for connecting to a TCP socket where a TPM is listening
for commands.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 15:46:23 -04:00
Stefan Berger
e8e4cbe52c swtpm_bios: Add empty option as last one in the list.
Add an empty option as the last one in the list.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 15:44:44 -04:00
Stefan Berger
4ec7d70fe8 swtpm_bios: redirect error output to stderr
Redirect all error output to stderr.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 21:51:55 -04:00
Stefan Berger
04b607b346 swtpm_bios: add --tpm-device command line option
Add support for providing the TPM device via command line option
--tpm-device <device>.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 21:51:18 -04:00
Stefan Berger
8d69193426 swtpm_bios: switch to using getopt_long for option parsing
Rather than parsing the option on our own use getopt_long()
now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 18:20:35 -04:00
Stefan Berger
5647fe1536 Fix the size of the receive buffer
Fix the size of the receive buffer input.body to match the largest
buffer any type of command has.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-14 14:25:09 -04:00
Stefan Berger
492a635e69 swtpm: Add support for setting the locality on the TPM
Implement the CMD_SET_LOCALITY command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-26 13:27:03 -04:00
Stefan Berger
6a2dd35b41 swtpm: Add support for sending state blobs to the TPM
Implement the CMD_SET_STATE_BLOB command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 23:47:44 -04:00
Stefan Berger
8f387d55e6 swtpm: Add support for getting state blobs from the TPM
Add support for CMD_GET_STATE_BLOB to get the current state of
the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 23:39:24 -04:00
Stefan Berger
a7a261a7e0 swtpm: move function to convert blobtype to name to tpmlib.c
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 10:30:56 -04:00
Stefan Berger
73e0c38d8e swtpm: Check for bad input packets sizes
Check all commands for bad input packet sizes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 09:52:54 -04:00
Stefan Berger
3488d25f45 swtpm: Implement resetting the establishment bit with a command
Implement the resetting of the establishment bit with a command

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 22:00:24 -04:00
Stefan Berger
b5fbddbcf1 swtpm: deactivate reset establishment
Deactivate the code around resetting the TPM established bit
since its implementation currently requires libtpms 0.6.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 14:33:58 -04:00
Stefan Berger
03e0099137 swtpm: Implement two more control channel commands.
Implement two more control channel commands:
- CMD_STORE_VOLATILE
- CMD_HASH_DATA

Implement test cases.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 09:34:59 -04:00
Stefan Berger
f56a0cd2a5 swtpm: Further implement the control channel for socket and chardev
Further implement the control channel for the socket and chardev
interface swtpms.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 15:25:18 -04:00
Stefan Berger
3f4b2d599e Make TCP socket port reusable
Set the SO_REUSEADDR socket option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 12:59:24 -04:00
Stefan Berger
708a1a471e swtpm: Fix parsing of the options
Fix the parsing of the command line options.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 12:47:00 -04:00
Stefan Berger
c2d04f537b swtpm: Fix application of flag mask
Fix the application of the flag mask.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 12:46:56 -04:00
Stefan Berger
9195be7f87 swtpm: Listen for TCP connections
Fix a problem with the socket TPM not listening for TCP connections.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 11:29:54 -04:00
Stefan Berger
4716d35a69 swtpm: Rename --connect to --server
Rename the --connect option to --server.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-20 14:50:40 -04:00
Stefan Berger
16eb0ff25a swtpm: Extend TCP server parameters with bind address
Extend TCP server parameters with an IPv4/IPv6 bind address
parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-20 14:49:36 -04:00
Stefan Berger
9ddc699812 swtpm: Add the control channel to the socket interface TPM
Add the control channel to the socket interface TPM as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 16:51:19 -04:00
Stefan Berger
b959335e5d swtpm: let socket and character interfaces share the mainloop
Let the socket and character interfaces share the same mainloop
function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 15:55:35 -04:00
Stefan Berger
bfa865a7a1 Prepare the mainloop function for usage by the socket interface
Prepare the mainloop function so that it can be used by the socket
interface as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 15:14:16 -04:00
Stefan Berger
320d90641e swtpm: move chardev's mainloop into own file
Move the swtpm chardev main loop into its own file for sharing
with the socket interface.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 14:27:09 -04:00
Stefan Berger
7c0a033f96 swtpm: add --connect option support
Add support for --connect option for the socket version of the TPM.
This parameter takes the type, port, file descriptor and disconnect
options. Only TCP connections are currently supported.

See updated man pages.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 13:36:40 -04:00
Stefan Berger
45cfd52628 tpm_fastpath
Only let certain commands that are cancelable be processed
by the thread. Directly process all other commands.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-16 20:03:06 -04:00
Stefan Berger
81c55814dd swtpm_bios: Exit with error if TPM needs to be reset for activation
Exit with error code 129 if the TPM needs to be reset to become activated.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-02-18 09:55:23 -05:00
Stefan Berger
37c73b4ba7 build: Add tpm_bios.h to noinst_HEADERS
tpm_bios.h was missing in the tar created by 'make dist'. This patch
fixes it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-25 16:26:00 -05:00
Stefan Berger
3b64478713 swtpm_bios: use data structures to write commands
Use TPM data structures and constants to write commands.

Fix white space errors on the way.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 11:21:14 -05:00
Stefan Berger
ed29bd7229 swtpm: do not compare positive integer with < 0
Do not compare positive integer with < 0.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 10:07:55 -05:00
Stefan Berger
71b91c9cef swtpm: do not compare positive integer with < 0
Do not compare positivie integer with < 0.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 09:42:50 -05:00
Stefan Berger
feee88b0d8 swtpm: use ioctl structure to return values
Use the ioctl structures to return values. Properly initialize the
TPM result value.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 09:40:44 -05:00
Stefan Berger
1e0296851f swtpm: check for unsupported file descriptor types
Rather than checking whether the given file descriptor is a character
device, check whether it is one of the unsupported ones. This addresses
a problem when passing anonymous file descriptors that are not character
devices.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-22 07:43:59 -05:00
Stefan Berger
ffc498b4ca swtpm_setup: send command for EK creation directly
Send the TPM command for EK creation directly; it requires no
crytpo and can be hard coded.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-13 20:07:12 -05:00
Stefan Berger
4a37440a4d build: Link libswtpm_libtpms with glib libs
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-12 19:52:29 -05:00
Stefan Berger
c9de5f0ab1 build: add threadpool.h
Add the threadpool.h to the noinst headers, so it ends up in the tgz file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-29 04:30:27 -05:00
Stefan Berger
c3c7e8f364 swtpm_bios: Introduce durations to wait for command completions
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-29 04:25:42 -05:00
Stefan Berger
abac744529 swtpm_bios: use select for waiting for response
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-28 20:35:29 -05:00
Stefan Berger
1c1efe2dab swtpm: move threadpool code out of cuse-tpm
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-28 16:13:53 -05:00
Stefan Berger
28a18c29b3 swtpm_setup: improve error handling
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-28 16:10:10 -05:00
Stefan Berger
bb420d7481 swtpm: move process owership to common file and enable in all implementations
Move the code to change process ownership into its own function and enable
--runas|-r <owner> in all implementations.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-27 18:17:49 -05:00
Stefan Berger
e11a75527e tests: add timeout to socat
Add a timeout to socat so that on slower machines the tests succeed.

Clean up an #include.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-21 03:26:46 -05:00
Stefan Berger
804e74728e swtpm: add CMD_SHUTDOWN to control channel
Extend the control channel with CMD_SHUTDOWN to shut down the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 20:55:15 -05:00
Stefan Berger
78c5f924bf swtpm: add cuse TPM interface option to swtpm
Now that the CUSE TPM part is BSD licensed, extend the swtpm
program with the cuse option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 20:06:57 -05:00
Stefan Berger
ddf99d057a swtpm: clean up single letter options
Remove single letter options that are not described in the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 13:17:08 -05:00
Stefan Berger
12837911ce swtpm: do not ignore write return value
If the 'swtpm chardev' receives an error on write() or not all bytes
could be written, log an error and terminate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-13 21:49:49 -05:00
Stefan Berger
86b6ffca75 swtpm: use endian.hi for endianess conversion
Use the macros defined in endian.h for endianess conversion.

Fix the conversion of a 64bit variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:25:17 -05:00
Stefan Berger
2b4c6da540 swtpm: add missing dirent.h include
On PowerKVM dirent.h needs to be included.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:24:43 -05:00
Stefan Berger
db33da6b78 build: fix build of rpm
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:24:23 -05:00
Stefan Berger
5f1ef9565d swtpm: Replace the CUSE TPM with the new implementation
Replace the CUSE TPM with the new BSD implementation.
Update the license references and the license itself.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 15:01:57 -05:00
Stefan Berger
57d542a01c swtpm: transfer the rest of the code
Transfer the rest of the CUSE TPM code into the new application.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
82cf754a79 swtpm: Implement ptm_init_done function
Implement the ptm_init_done function

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
6a102bc764 swtpm: Implement command line option parsing and main function
Implement the command line option parsing and the main() function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
6e0dc3ddd5 swtpm: Re-implement CUSE TPM under BSD license
Eric Richter implemented a clean-room skeleton CUSE driver which
we will now convert to the CUSE TPM. The goal is to replace the
GPL CUSE TPM implementation with this 3-clause BSD implementation.
Among other things, this makes it easier to link with OpenSSL.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
ffcb6535d3 swtpm_bios: Add option to give up physical presence
Extend the swtpm_bios tool with an option to give up physical presence.

Have the TPM error codes reflected in the exit error of 128.

Add a test case for the tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 18:23:13 -05:00
Stefan Berger
a1030ba771 swtpm_ioctl: do not display help screen on -h
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 09:31:55 -05:00
Stefan Berger
57e53b78ea swtpm: Add option to only display version info
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 07:32:53 -05:00
Stefan Berger
a1fa5d77e2 swtpm: add version info to all programs
Move src/swtpm/swtpm.h.in to include/swtpm.h.in to make it commonly
available. Adapt all other programs to use it and display version information
in the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-03 19:31:10 -05:00
Stefan Berger
a7bd0ebffc swtpm: poll for HUP as well
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-03 09:15:59 -05:00
Stefan Berger
8a68446e73 swtpm_setup: enable help screen for normal users
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-29 17:05:22 -05:00
Stefan Berger
a3c8e71a1d swtpm: fix some coverity errors
Fix some errors raised by Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-29 01:48:13 -05:00
Stefan Berger
6852f6c89b swtpm: introduce control channel for chardev TPM
Implement a control channel for the 'chardev' swtpm that implements
a minimal set of control messages for now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 22:13:37 -05:00
Stefan Berger
7a00ba8b7c swtpm: Fix typo in error message
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 22:13:36 -05:00
Stefan Berger
1bebb6be04 swtpm: consoldiate code
Consolidate common code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 17:58:32 -05:00
Stefan Berger
c8ba316097 swtpm: fix TPM_DEBUG define
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 10:25:17 -05:00
Stefan Berger
12ef7d4e47 swtpm chardev: remove not supported command line option
Remove a not supported command line option from the help screen of
'swtpm chardev'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 10:24:00 -05:00
Stefan Berger
e47bd065ff swtpm: remove pidfile after process exits
Remove the pidfile once swtpm process exits.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-15 13:55:06 -05:00
Stefan Berger
29cfd0a4fd swtpm: add support for listening on chardev
Add support for 'swtpm chardev' that listens for TPM commands on a given
character device and sends responses through it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-08 14:13:23 -05:00
Stefan Berger
27a3c23967 swtpm: make all possible variables static
Some of the variables in swtpm.c were not static, fix this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-08 13:46:17 -05:00
Stefan Berger
c4ac0a11e9 build: remove hardcoded tss user and group
Remove the hardcodes tss user and group and to configure with
--with-tss-user=tss --with-tss-group=tss to set the tss user
and group to be used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-02 20:47:37 -05:00
Stefan Berger
118cc15230 swtpm: Check for existing device
Check for an existing device with the same name and print an error
if the device already exists.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-29 11:00:56 -04:00
Stefan Berger
6e710866f3 swtpm: report missing TPM state path
Report missing TPM state path as soon as possible.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-29 10:48:30 -04:00
Stefan Berger
bc525ccdab swtpm: Add support for --tpmstate dir=<dir> command line parameter
Add support for the --tpmstate dir=<dir> command line parameter.
It will be used instead of the TPM_PATH, unless it is not set.

Adapt two test cases for the new parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-27 21:58:10 -04:00
Stefan Berger
b215173767 swtpm: Add command line parameter for pidfile
Add support for --pid file=<pidfile> command line parameter support.
The swtpm_cuse and swtpm now write their process IDs (pids) into
a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-26 06:34:14 -04:00
Stefan Berger
7d4b4514a3 build: enable RPM building for non-root users
Disable the chown commands when building an RPM; we try to detect this
by the usage of DESTDIR.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-16 19:08:43 -04:00
Stefan Berger
373a9be985 Some more changes to the ioctl's
Some more changes to tpm_ioctl.h including
- comment for request and response part of an ioctl
- unified format
- prefix all constants with PTM_

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-03 18:41:33 -04:00
Stefan Berger
8e45d3e25e swtpm_cert: remove unnecessary file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-02 18:05:17 -04:00
Stefan Berger
84d2e89a74 swtpm_setup: remove PATH extension to local dir
Remove the extension of PATH to the local dir('.') from swtpm_setup.sh
and adapt test cases accordingly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-02 10:50:05 -04:00
Stefan Berger
4f185f6e45 swtpm_setup: cleanup
Cleanup the code a bit:
 o added description to several functions
 o remove empty lines between functions
 o cleanup the usage screen
 o fix the parameters to logerr

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-01 21:01:59 -04:00
Stefan Berger
a209a01816 swtpm_cuse: be more consistent with input buffer size checks
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-23 14:04:59 -04:00
Stefan Berger
ff1a99d7e6 swtpm: receiving of TPM state blob ends once last byte has been copied
The receiving of TPM state blob ends when the last byte has been copied
into a response to the user. No more request need to be sent afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-05 16:28:09 -04:00
Stefan Berger
c896156107 swtpm: delete blob file if set blob has length 0
If a blob with length 0 is set, we make sure the corresponding file
that would hold this blob is not available.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-05 16:25:33 -04:00
Stefan Berger
05cd79b843 Support read()/write() for TPM state blob transfer
Support the read/write interface and POSIX API calls for transfer of
TPM state blobs.

Extend the swtpm_ioctl program to support this as well. Use the
environment variable SWTPM_IOCTL_BUFFERSIZE to set the size of the
buffer to use and enable the read/write interface in this (test)
program.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-04 18:49:25 -04:00
Stefan Berger
5e60c24f40 remove the tpm_number from the public interface
Remove the tpm_number from the public interface (while we still can do that)

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
31380fe68e tpm_ioctl: Remove _t from the types
Since POSIX reserves the *_t namespace of types, remove it from
all our typedefs. While doing that, adjust the typedefs to all have
the prefix ptm_ .

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
857daa32b9 tpm_ioctl: convert blob type to 32 bit int
Convert the blob type to 32bit int (while we still can do that ... )

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
8f3b270ab0 swtpm: move code to set state blob into own function
Move the code that sets the TPM's state blob into its own function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
22fda83bf9 swtpm: move code to get the TPM state blobs into own function
Move the code to get the TPM state blobs into is own function and introduce
a caching layer that retrieves the state blob from the TPM once and has
subsequent requests to copy the state work on the cached blob.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
ad976d1a2e Add copyright stanza where missing; update date
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-26 20:52:40 -04:00
Stefan Berger
bd98690a4a Add ioctl to get configuration flags about keys in use
Add an ioctl that lets an application retrieve which keys are in use by the
TPM, i.e., file encryption or migration key

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-26 07:30:38 -04:00
Stefan Berger
1680c41d9e swtpm: Add a command line option for a migration key
The migration key ensures that TPM state blobs, when retrieved using the
ioctl for getting state blobs, are always encrypted with this key.
When the state is later on loaded back into the TPM using the ioctl
to set the state blobs, the migration key is used to decrypt them.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:18:44 -04:00
Stefan Berger
082533af22 swtpm: Have crypto functions use a key as parameter
Have the crypto functions use a key as a parameter rather than having them
operate on a specific fixed key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:12:23 -04:00
Stefan Berger
81264f7356 swtpm: break apart key parsing function
Break the key parsing function apart into a common parsing function
and one specific to the file encryption key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:12:23 -04:00
Stefan Berger
bed4894cd7 swtpm: prepend a header in front of all blobs retrieved from the TPM
Prepend a header in front of all blobs retrieved from the TPM.
Write flags into this header indicating whether the blob is
encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:12:23 -04:00
Stefan Berger
b902468900 swtpm: integrity protect the encrypt TPM state
Integrity protect the TPM state when it is written in entrypted form.
libtpms state (for TPM1.2) is also integrity protecting the blobs, but
we better determine the integrity of the decrypted data on the layer
above it.
2015-05-19 16:35:08 -04:00
Stefan Berger
fdbc203585 swtpm: more precise error message if setuid doesn't work
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-16 17:59:39 -04:00
Stefan Berger
af0ef0205a swtpm: assign value to saveptr used in strtok_r
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:59:16 -04:00
Stefan Berger
c6ba40fc53 swtpm: Ignore the return value of a write op before closing connection
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:54:45 -04:00
Stefan Berger
0a7e8d236d swtpm_setup: Annotate that we pass argv to execv intentionately
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:51:16 -04:00
Stefan Berger
74e53a6268 swtpm: No need to compare locality with negative values
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:48:20 -04:00
Stefan Berger
0268ef45d2 swtpm: change type of len from size_t to ssize_t
Change the type of the len variable from size_t to ssize_t for
comparison against neg. values to work.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:48:20 -04:00
Stefan Berger
414e0e8960 swtpm_ioclt: no need to compare locality with values < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:48:11 -04:00
Stefan Berger
38a9453322 swtpm_cert: change variable type from unsigned char to char
Change variable type of val1 and val2 from unsigned char to char for
the comparison with neg. numbers to work.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:24:27 -04:00
Stefan Berger
3df8cbf91b swtpm_cuse: no need to compare uint8_t locality with < 0.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:20:16 -04:00
Stefan Berger
da521f048b swtpm: replace size_t with ssize_t for variable taking read() return value
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:18:23 -04:00
Stefan Berger
fddbb58d48 swtpm: Check file descriptor >= 0 before closing
Check the file descriptor for >= 0 before closing it. Hopefully
this makes Coverity happy.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:09:05 -04:00
Stefan Berger
9e89ffa12d swtpm_bios: Remove UNIXIO socket related code since not used
We do not support UNIXIO sockets for communicatin with the swtpm
yet, so remove this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:04:03 -04:00
Stefan Berger
e387a34eab swtpm_ioctl: Move code for loading TPM stateblobs to own function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-11 06:42:27 -04:00
Stefan Berger
eafb7054d8 swtpm_ioctl: Move code for saving TPM stateblobs to own function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-11 06:41:42 -04:00
Stefan Berger
5ef047fedf swtpm_ioctl: move hashing code into own function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-10 10:28:57 -04:00
Stefan Berger
6b7aefa9c2 swtpm: cleanup and commented ptm_ioctl
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-09 08:44:11 -04:00
Stefan Berger
6d7d0dd5e6 swtpm_ioctl: source formatting
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-09 08:41:04 -04:00
Stefan Berger
cdbfb7be1a swtpm_setup: Print error in case 'eval' fails on file permissions etc.
Also have the log function print out all parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-04 01:27:48 -04:00
Stefan Berger
798694516e swtpm_setup: fix variable name typo
Fix a typo in a variable name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-04 02:58:17 -04:00
Stefan Berger
58548ac677 swtpm: document some more code
Add documentation to the include file and some functions in  the source
code files.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>jo
2015-03-30 10:06:49 -04:00
Stefan Berger
337247ef6c swtpm: add documentation to options source code
Add documentation to the options source code and introduce an explicit
default value to return in case an option was not found while parsing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-30 07:24:08 -04:00
Stefan Berger
292fc83f3e swtpm_cuse: automatically remove volatile state after retireval
Automatically remove the volatile state file after retrieval.
2015-03-19 15:44:22 -04:00
Stefan Berger
950040f03c swtpm_cuse: implement STOP ioctl
Implement a STOP ioctl in the swtpm and swtpm_ioctl client.
Modify test cases to used swtpm_ioctl --stop.
2015-03-16 11:50:03 -04:00
Stefan Berger
33e241b562 swtpm_ioctl: if blob cannot be found TPM_NON_FATAL is returned
It's not a fatal error if a blob is not returned and the CUSE TPM replies
with TPM_NON_FATAL error code.
2015-03-16 11:19:44 -04:00
Stefan Berger
c552bcdca3 swtpm_setup: reuse existing function to stop processes 2015-03-16 11:14:53 -04:00
Stefan Berger
36a7d09481 swtpm_setup: check swtpm port
Also check the port of the swtpm before proceeding.
Fix a typo in the code.
2015-03-14 20:43:10 -04:00
Stefan Berger
ba3535aa9c swtpm_setup: remove debugging code 2015-03-13 14:52:11 -04:00
Stefan Berger
3e5085efff swtpm_setup: Test connection with tcsd
On rare occassions TCSD refuses connections after start and nothing
works; so we test the connection with TCSD and kill it if it doesn't
work.

This now seems to fix the tests/test_parameters that occosionally
had been reporting an error.
2015-03-13 12:35:59 -04:00
Stefan Berger
f55b697663 Only allow a single command per TCP connection to be sent
Only allow a single command per TCP connection to be sent to
the socket TPM. This solves a problem with the test_parameters
testcase where the TPM seems to get stuck in the poll().
However, the testcase still is not entirely error-free.
2015-03-12 21:45:34 -04:00
Stefan Berger
bba74db294 Only list LISTEN sockets when checking on tcsd
Only list LISTEN sockets when checking whether tcsd has started
listening on a socket, yet.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-12 14:21:59 -04:00
Stefan Berger
198ebab3c1 Add new ioctls for getting and setting state blobs
Add new ioctls to get and set the 3 different types of state blobs
from and to the CUSE TPM. Add test cases for testing the new ioctl's
on a CUSE TPM that stores the state encrypted and on a CUSE TPM that
stores it non-encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-12 09:32:28 -04:00
Stefan Berger
5fd9856094 Show error message when not installing as root
Only root can change the ownership of swtpm_setup.sh to tss:tss, so
only root can install the file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-02-20 18:44:47 -05:00
Stefan Berger
f97114cc4c Fix build on RHEL6 where we need -lgthread-2.0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 18:16:09 -05:00
Stefan Berger
ca84b6cde7 Allocate TPM command buffer on heap rather than on the stack
Allocate the TPM command buffer on the heap. Previously it was
allocated on the stack.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 17:56:26 -05:00
Stefan Berger
a84f2372ba Change void * to concrete structure.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 17:29:54 -05:00
Stefan Berger
e6085e9615 Add some hardening flags to compiler and linker
Protect the stack, create position indep. executables, use Relocation
Read-Only (RELRO) and have the linker resolve all symbols upon
program start.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 17:08:40 -05:00
Stefan Berger
410683fa05 Remove unused wrapper tcsd-launcher.c
Remove the unused wrapper program tcsd-launcher.c.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-19 14:47:35 -05:00
Stefan Berger
ec37bb56cb Make SELinux policy extension support chooseable
Extend configure.ac to make SELinux policy extension support
chooseable. By default configure will check whether SELinux
support is installed on the local system and will add SELinux
policy extension support if support is found.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-12-19 09:28:47 -05:00
Stefan Berger
3bbdd7bc76 Support for openssl
Also support swtpm using OpenSSL library. 
Introduce --with-openssl in configure.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-12-18 22:19:57 -05:00
Stefan Berger
ba2f0af638 Enable building of rpms on RHEL 7
Some tweaks to enable building of RPMs on RHEL 7.
2014-12-09 20:37:27 -05:00
Stefan Berger
09c58b7003 Make compileable on RHEL 7 for ppc64
There are some tiny adjustments needed for linking on RHEL 7 for ppc64.
Otherwise it works there now as well.
2014-12-09 20:10:00 -05:00
Stefan Berger
baecda4040 Link programs with minimal set of libraries
Don't build up a global LIBS variable but put the libraries into
individual variables that can be used for linking individual programs
with. Do the same for CFLAGS.
2014-12-09 19:59:27 -05:00
Stefan Berger
0321a3808d Add ioctl to reset the establishment bit
Add an ioctl to reset the establishment bit. It takes as an
argument the locality to use.
2014-12-08 11:35:16 -05:00
Stefan Berger
6e93fdef0f add new README files for the tools and modify main README file 2014-12-05 15:11:15 -05:00
Stefan Berger
e46a2b6686 merging swtpm-tools into this project 2014-12-05 13:43:21 -05:00
Stefan Berger
6fc8fb9f4c initialize errno to 0 before strtoul call 2014-12-05 12:43:45 -05:00
Stefan Berger
f163b20210 initial check-in 2014-12-05 11:16:03 -05:00