Commit Graph

726 Commits

Author SHA1 Message Date
Stefan Berger
0676fedb23 swtpm: Add missing include file to ctrlchannel.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
c2bae74975 swtpm: Stub handle_seccomp_options if WITH_SECCOMP is not defined
Stub out the handle_seccomp_options function and other unused
code and data if WITH_SECCOMP is not defined.

Currently the handle_seccomp_options would always be called with
a NULL string to parse if WITH_SECCOMP is not defined, so this just
eliminates the code that will never be called.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
a794d0fe48 swtpm_setup: Avoid calling getpwnam() if change_user == false
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
51f3860dfe swtpm: Have swtpm report PTM_CAP_SEND_COMMAND_HEADER flag
Have swtpm report PTM_CAP_SEND_COMMAND_HEADER flag for a TPM 2
indicating that it knows how to handle the TCG header prefix
for the data channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
e2558a8bea swtpm: Have get_ptm_caps_supported return supported PTM_CAPs
Create function get_ptm_caps_supported and have it return the
supported PTM_CAPs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
cb80f52036 swtpm: Set missing PTM_CAP_GET_INFO capability flag for CUSE TPM
CUSE TPM did not report the PTM_CAP_GET_INFO flag. This patch fixes
it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:38:07 -04:00
Stefan Berger
065bca4e18 swtpm: Handle TPM 2 command header prefix
Add support for handling the TPM 2 command header prefix that looks like this:

struct tpm2_send_command_prefix {
    uint32_t cmd;
    uint8_t  locality;
    uint32_t size;
};

This patch converts the existing send function to use an array of struct iovec
using writev() where we can optinally prepend a response header and trailer.
We detect whether the command had the above type of header prefixed and if so
indicate this with an offset into the byte stream where the normal TPM command
starts, which follows right after this header. In case such a header was found
we prepend a header in the response and append a 4-byte trailer. For TPM 1.2
there are no changes and for raw TPM 2 commands there are no changes, either.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-08 07:09:16 -04:00
Stefan Berger
dc2895812a swtpm: Have SWTPM_IO_Read read at least the 10 bytes from the TPM header
Have SWTPM_IO_Read() read at leat the 10 bytes from the (regular) TPM
header. This solves a particular problem with the TPM 2 header prefix for
which we will add support in the subsequent patch. In the prefix case the IBM
TSS 2 stack sends 4 bytes for the command, then 1 byte for the locality, and then
4 bytes for the length indicator followed by the command. If we just read once
we would only then get 4 bytes. Reading 10 bytes gets all of these plus the sub-
sequent TPM command or the whole TPM command in case this prefix header is
missing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-08 07:09:16 -04:00
Stefan Berger
71beceeda4 swtpm: Re-add header includes for BSD
Some BSDs need more #includes than Linux does. Re-add them as I removed too many
before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-08 07:09:16 -04:00
Stefan Berger
e9f059eb2a swtpm: More cleanup in swtpm_io.c
- Simplify SWTPM_IO_Write()
- Remove unnecessary includes
- Clean up other cruft

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
6ac09331ad swtpm: Get rid of MAINLOOP_READALL flag
Now that we will always read all bytes available on a file descriptor
we don't need the MAINLOOP_READALL flag anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
e9b63593a8 swtpm: Simplify the reading of TPM commands
Simplify the readin of TPM commands to always read all available
bytes from a file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
4fd2d23b4a swtpm: Use exit in main with parameter EXIT_FAILURE/SUCCESS
Convert all return's and exit(1) to use exit with EXIT_FAILURE
or EXIT_SUCCESS as parameter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-05 12:23:30 -04:00
Stefan Berger
1ae3eff9b4 swtpm_setup: Use swtpm_ioctl to re-init the TPM 1.2 for activation
Since we can only read the file descriptor for the passphrase once,
we cannot stop the TPM 1.2 and then restart it but we have to use
'swtpm_ioctl -i' to re-init it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-03 11:19:23 -04:00
Stefan Berger
caee678bc4 swtpm_setup: Redirect error output of swtpm_bios to stdout
Redirect the stderr output of swtpm_bioc to stdout so we can
capture the message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-03 11:19:23 -04:00
Stefan Berger
fa25608f6a swtpm_setup: Allow passing file descriptor for key or password files
Also extend swtpm_setup to allow passing the file descriptor for
the key or password files or pipes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
1253088ff8 swtpm: Add missing pwdfd=<fd> to help screen
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
26933af56f swtpm: Enable reading password file from file descriptor
Enable reading the password file from a file descriptor using
--key pwdfd=<fd>

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
e7fb07e8fe swtpm: Get rid of stat() in key_read_pwdfile_fd
Get rid of stat() so that we can read from pipes as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
63717f996d swtpm: Use len as parameter to SHA512
filelen is the length of the file as it was stat'ed. len is
the number of bytes read. They should be the same. So, use
len as a parameter to SHA512() rather than filelen.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
a947bebd80 swtpm: Factor out key_load_pwdfile_fd from key_load_pwdfile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
1ed09c0359 swtpm: Enable reading key from file descriptor passed via option
Enable reading the state encryption or migration keys using a
file descriptor passed via the command line option parameter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
f4be1e860c swtpm: Factor out key_load_key_fd from key_load_key
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
63def2bc64 swtpm: Consolidate the exit of parse_key_options
Consolidate the exist of the parse_key_options function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
bf5220cf20 swtpm: Add missing kdf option documentation to help screen
Add missing kdf option documentation to help screen. The kdf
option parameter support has been there since 0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
12234f8e5f swtpm: CUSE TPM needs prtcl syscall for thread pool support
The CUSE TPM needs the prctl syscall to function correctly when
commands are passed via the thread pool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-14 22:18:48 -04:00
Stefan Berger
34eb89f5a0 swtpm: Fix illegal heap access while parsing options
Fix an illegal heap access while parsing the options by making
sure that we do not access the tok variable beyond its size
when comparing a character to '=' and later on when accessing
the value after the '='.

This bug was discovered by configuring as follows on Fedora 28:
  CFLAGS="-fsanitize=address -g -ggdb" LIBS="-lasan" \
    ./configure --prefix=/usr

and running tests like this:

  sudo bash -c "SWTPM_TEST_EXPENSIVE=1 make -j32 check"

The test case test_tpm2_ctrlchannel2 indicated the error.

It looks like gcc on Ubuntu Xenial on Travis did not detect this
error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-18 07:59:53 -04:00
Stefan Berger
a9a9320aab swtpm: Add 9 more syscalls to seccomp profile blacklist
Add 9 more syscalls of concern to the seccomp profile blacklist.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-12 12:57:43 -04:00
Stefan Berger
f7de241e51 swtpm_bios: Switch to use getaddrinfo to also support IPv6
Switch the lookup of the address to use getaddrinfo so IPv6 also works.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-04 13:02:19 -04:00
Stefan Berger
1d043aef78 swtpm_ioctl: Switch to use getaddrinfo to also support IPv6
Switch the lookup of the address to use getaddrinfo so IPv6 also works.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-04 13:02:19 -04:00
Stefan Berger
129c6b5bf2 swtpm: Add support for fd_to_filename on OS X and test it
Extend the previously modified test case to also test on
Darwin now that we are able to convert a file descriptor
to a filename.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-03 09:37:03 -04:00
Stefan Berger
59b07baffc swtpm: Fix return code of change_process_owner
The return code of change_process_owner must be negative.
This patch fixes one occurrence.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
07dfd95887 swtpm: Enable support for seccomp profile
Enable support for the seccomp blacklist profile that is
enabled by default and can be disabled using the following option:

--seccomp action=none

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-18 15:43:44 -04:00
Stefan Berger
2dd48f6887 swtpm: Extend options parse for parsing seccomp options
Extend the parse that parses the seccomp options like:

--seccomp action=none|log|kill

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-18 15:43:44 -04:00
Stefan Berger
d9947892b1 swtpm: Implement function to build a blacklist seccomp profile for swtpm
We build a blacklist of syscalls that we don't want the swtpm to ever be
able to execute.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-18 15:43:44 -04:00
Stefan Berger
869df69fe0 swtpm: implement uninstall_sighandlers
Implement uninstall sighandlers to uninstall the signal handlers
and not to create another pipe.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-14 10:22:54 -04:00
Marc-André Lureau
c5a3a4f2f9 swtpm-setup: follow XDG spec more closely for default config
According to the XDG spec,
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html:
"If $XDG_CONFIG_HOME is either not set or empty, a default equal to
$HOME/.config should be used."

This fixes setting up a TPM with libvirt running in a user session.

It works by checking if configuration files are readable in the
directory priority order (XDG_CONFIG_HOME, then HOME, then SYSCONFDIR).

When libvirt is running as a system instance, $HOME isn't set, so it
will fall back on @SYSCONFDIR@ (/etc usually)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-02-26 08:36:10 -05:00
Stefan Berger
2bfa8312d9 swtpm_setup.sh: Replace mktemp --tmpdir=<> with TMPDIR=<> mktemp
To avoid failures with mktemp call on BSD type of systems replace
mktemp --tmpdir=<dir> with TMPDIR=<dir> mktemp, which seems more portable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
b61e8c5fb5 swtpm_setup: Use OSX specific function to get path of executable
OS X cannot resolve the path we get from genenv("_") when running a
test script on Travis (reason unknown). So we use _NSGetExecutablePath()
instead and display the path in the error message in case realpath()
fails.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
0432b6535c build-sys: Fix hard coded /etc path and replace with @SYSCONFDIR@
When the project is configured with --prefix=/usr/local several configuration
files are installed to /usr/local/etc but not read by the programs that
need them. This patch fixes this issue by replacing @SYSCONFDIR@ in the source
code of those files with the actual used path.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 11:28:40 -05:00
Stefan Berger
655bc4be17 swtpm_cert: Support PKCS11 URIs for a CA using a PKCS11 module for signing
For PKCS11 modules (such as SoftHSM) to sign a TPM EK or platform
certificate we use 'pkcs11:' prefixed URIs like those URIs for
TPM 1.2 starting with tpmkey:.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-11 13:44:36 -05:00
Stefan Berger
b8e0cbd299 swtpm: ubsan: Make 64 bit flags field of ptm_getinfo 8-byte aligned
Make the 64bit flags field of the ptm_getinfo structure 8-byte
aligned.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 20:36:25 -05:00
Stefan Berger
50af85f7fd swtpm_bios: ubsan: Use tpm_resp_header structure to access header fields
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 20:36:25 -05:00
Stefan Berger
41c8da12ce swtpm_setup.sh: First send SIGTERM to processes then (later) SIGKILL
Implement terminate_proc, which first tries to gracefully terminate a
process and then, if synchronization is requested, waits for 1 second
for it to disappear and then kills it with SIGKILL if it didn't go away.

Use this function for stop_tpm and stop_tcsd, which will first try
to send a SIGTERM to a process assuming it will terminate while we
do something else and then, in case the process needs to be restarted,
make sure that it's gone before it is restarted.

This addresses an issue where previously SIGTERM was sent to a process
before it was restarted but the restarting failed due to the previous
process still holding a lock on the file because it wasn't able to react
to the SIGTERM fast enough.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 10:08:26 -05:00
Stefan Berger
bd247379e9 swtpm: Uninstall signal handler before closing notication file descriptor
Uninstall the signal handler before we close the signal handler's
notification file descriptor so that signals received after the file
descriptor is closed do not cause an error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 10:08:26 -05:00
Stefan Berger
dff1c07dac swtpm_setup: Free memory in case of error
Free the allocated memory in case of an error condition.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 10:08:26 -05:00
Stefan Berger
ae98b04512 swtpm: Coverity: Check msg parameter upon return from recvmsg
Make sure that the msg parameter passed into recvmsg wasn't modified
by the library and verify that the pointers and sizes it contains are
still valid after the call. This addresses an issue raised by Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-21 10:45:10 -05:00
Stefan Berger
9746786e4b swtpm_cert: Fix memory leaks
Fix various memory leaks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-17 16:37:03 -05:00
Stefan Berger
2b1398a466 swtpm_cert: use hashAlgo as parameter for signing certificates
Ceritficates for a TPM 2 have to be signed using SHA256 and those for
a TPM 1.2 have to be signed using SHA1 (following specs). We can use
either of these algorithms when using the GnuTLS TPM support since it
will create the hash and have the TPM 1.2 sign whatever it created.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-07 10:32:10 -05:00
Stefan Berger
05d8160363 swtpm_setup: Leave swtpm_setup.sh ownership to root
swtpm_setup.sh does not need to be owned by tss:tss and in the
Fedora package it's not even allowed. So remove the install hook
that was changing the ownership.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-06 15:28:53 -05:00
Stefan Berger
79edd90c90 swtpm_setup: Implement option to backup TCSD's system_ps_file
Implement the --tcsp-system-ps-file option to make a backup of
TCSD's system_ps_file for later use of the setup TPM with the
TCSD. We need this for a test case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:15:48 -05:00
Stefan Berger
b8421f3de4 build-sys: Support --enable-test-coverage as an option
Support --enable-test-coverage as an option for compiling with
coverage instrumentation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-25 12:30:21 -04:00
Stefan Berger
0c00eb5019 swtpm: Have the CUSE TPM return the original TPM start error code
Have the CUSE TPM return the TPM start error, particularly
TPM_DECRYPT_ERROR in case a wrong key was passed, rather than the plain
TPM_FAIL error code. This was a difference with the 'other' swtpm
interfaces that already returned the original error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-25 10:32:36 -04:00
Stefan Berger
fea8979648 swtpm_cert: Allow using a TPM 1.2 signing key for signing cert
Gnutls supports TPM 1.2 keys in its API and we can use a TPM 1.2
signing key for signing the EK or platform certs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-15 20:45:48 -04:00
Stefan Berger
08682141a1 swtpm: Rename crypto functions to have SWTPM prefix
The crypto functions for AES encryption and decryption clash with crypto
function names of libtpms. Avoid this by prefixing them with SWTPM_ instead
of TPM_.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-06 18:09:08 -04:00
Stefan Berger
5478de0a0d build-sys: Link with -lrt if libc does not have clock_gettime()
On older system libc does not provide clock_gettime() so we need
to link with -lrt.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-05 22:20:49 -04:00
Lukas Vrabec
6e9052da5a Do few changes to follow distribution SELinux policy 2018-10-05 13:34:43 -04:00
Stefan Berger
0143c410fe SELinux: A few more rules needed by libvirt 4.4 on F28 for running QEMU
This patch adds rules that are needed for running QEMU with libvirt 4.4
on F28. This allows one to test the libvirt management stack and QEMU with
swtpm and SELinux in enforcing mode.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-02 12:16:36 -04:00
Stefan Berger
ebf1557dde build-sys: Move glib-2.0 dependency to CUSE TPM build
Only when the CUSE TPM is built we need the glib-2.0 dependency
(which can be removed at some point probably).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-02 10:19:31 -04:00
Stefan Berger
a6fced8d25 swtpm: Use non-exclusive threads to have glib2 clean up after itself
glib2 did not clean up a proxy thread once the pool was torn down. The
reason was that an exclusive pool was used. Switch to a non-exclusive
pool, which will cause the last thread to terminate as well and we have
a clean valgrind log now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-02 09:24:45 -04:00
Stefan Berger
b096e8938d swtpm: Initialize structure using memset
Gcc 4.9.2 on ARM does not like the initializer '= { 0 }', either.
So switch it to memset.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-30 12:05:20 -04:00
Stefan Berger
fb8fb15965 swtpm: Initialize ptm_est type to avoid uninitialized bytes
Valgrind complains about uninitialized bytes being accessed by a writev()
call in libfuse. It points to a line in the error branch
'error_not_running', but the error does not seem to come from there.
Instead, if we initialize ptm_est to zeros the problem goes away.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-28 14:37:35 -04:00
Stefan Berger
86dac14a18 swtpm: Exit CUSE TPM using fuse_session_exit()
With the fuse_session now global, we can use it to exit the CUSE
TPM using fuse_session_exit().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-28 14:37:35 -04:00
Stefan Berger
eddd5787bb swtpm: Implement low level CUSE startup code to get to fuse_session
To be able to get to the low level fuse_session data structure, which
allows us to terminate the program more gracefully than the exit() in
the ioctl processing code, we implement the low level cuse startup code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-28 14:37:35 -04:00
Stefan Berger
6c6e5c936b SELinux: F27 needs allow for swtpm_exec_t:file map
F27 needs an additional rule for starting the swtpm from libvirt.

Add the rule 'allow svirt_t swtpm_exec_t:file map'

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-28 07:17:14 -04:00
Stefan Berger
a3914f53fa SELinux: re-add allow rules for file entrypoint
The file entrypoint rules are still needed, so add them back again.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 15:35:13 -04:00
Stefan Berger
943f03f12e swtpm_ioctl: replace initializer with memset for gcc 4.2.1
gcc 4.2.1 does not accept the initializer '= { 0 }' and so we now switch
this to memset as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 21:55:55 -04:00
Stefan Berger
f070a0b5bb swtpm_ioctl: Initialize structures for use with ioctl()
Valgrind complains that there are uninitialized bytes when ioctl() is called.
This is due to the fact that we are passing the structure to the ioctl()
without specifying how many bytes are valid in the passed buffer.
So, we initialize the buffers to 0 and the complaint is resolved.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 11:07:06 -04:00
Stefan Berger
b1eb3620e2 swtpm: Only copy length of user privided IV into possibly longer ivec
When the AES encryption and decryption function were extended to support
256bit keys the size of the user ivec on the stack was also increased to
32 bytes. For the user provided IV we now must only copy 16 bytes in case
an 128 bit key is used. Fix the length parameter to the memcpy().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 19:05:59 -04:00
Stefan Berger
a246953a50 build-sys: Install libswpm_libtpms into $(libdir)/swtpm
Install the private libswtpm_libtpms into $(libdir)/swtpm
rather than into the shared libaries directory.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-25 08:35:45 -04:00
Stefan Berger
3041f38769 build-sys: Do not build man page or SELinux policy for CUSE if --without-cuse is used
To make the RPM building easier for the --without-cuse case we have to omit
a couple of files from being built so that they are not left-overs when
packing the RPM without building swtpm-cuse.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-25 08:35:45 -04:00
Stefan Berger
3b40c9167a build-sys: Fix policy package dependencies for out-of-tree build
An out-of-tree build fails to build swtpm_svirt.pp due to missing
source files from the swtpm.pp policy. Add the swtpm.{te,if,fc} files
as dependencies of the swtpm_svirt.pp policy package.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-25 08:35:45 -04:00
Stefan Berger
1e1252b153 build-sys: Fix the SELinux policy build target for parallel builds
Use .NOTPARALLEL for the SELinux policy build target to avoid running
the rule concurrently and deleting the tmp directory while another
build is running.

For some reason it is not possible to use $(MAKE) since otherwise the
building of the policy package fails.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:48:41 -04:00
Stefan Berger
ca14f1cfd9 SELinux: Fix some nits in the SELinux policy files
This patch is partially from Lukas Vrabec (lvrabec@redhat.com) and fixes
some nits in the SELinux policy.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:48:41 -04:00
Stefan Berger
5b09de83a2 SELinux: Install policy package files to /usr/share/selinux/packages
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:48:41 -04:00
Stefan Berger
0f05604869 build-sys: Create compressed policy package files
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:48:41 -04:00
Stefan Berger
b88244ebeb SELinux: Extend SELinux policy with rules for svirt_tcg
Extend the SELinux policy with rules for svirt_tcg when
QEMU is not being started with KVM by libvirt.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:48:41 -04:00
Stefan Berger
b28f585c41 SELinux: Fix title in interface file
Fix the title in the interface file to say 'swtpm'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:48:41 -04:00
Stefan Berger
caae7b1ad7 ek-cert: Initialize datum variable to prevent unintialized access
Coverity scan shows an uninitialized access in case an error is
encountered and the cleanup path is taken before datum was initialized.
Fix the error by initializing the variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:46:58 -04:00
Stefan Berger
cc6c586f78 swtpm_cert: Fix a potential buffer overrun error
Coverity scan discovered a buffer overrun error in case the
datum->size = 0. Fix the error.

The function with the potential error is not called if datum->size == 0.

Also make the 'size' variable larger so there cannot be a overrun in
'size = datum->size + sizeof(buffer) - i'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 17:46:39 -04:00
Stefan Berger
aded2b6f69 swtpm: Initialize hdrflags to 0 in case no header was read
The hdrflags need to be initialized to 0 in case no header
was read from the file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-24 16:42:47 -04:00
Stefan Berger
2e260468cb swtpm_setup: Add support for choosing the cipher
Implement command line support for choosing the cipher to use for
the TPM state encryption. Either aes-128-cbc or aes-256-cbc can be
used. The same cipher has to be passed on the swtpm command line
when using the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
8ce50494c7 swtpm: Check the size of the user's key against expected size
Use the flags in the header to check the size of the provided key(s) against
the one(s) from the user. There are the state and migration keys, each has
a different flag in the header if a 256bit key was used. We display an error
about the mismatching key size against expected size if the given key is of
the wrong size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
68a5b24124 swtpm: Add support for aes-256-cbc
Extend the buffer the key is read into to hold an 256bit key.

Add support for aes-256-cbc. Also, aes-128-cbc is now a synonym for
aes-cbc.

Update the man pages to reflect the AES 128 support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
6e58cbeae2 swtpm: Extend en- and decryption functions for 256 bit keys
Enable 256 bit AES keys in the en- and decryption functions.
Set a flag in the header to at least indicate whether 128bit
or 256bit keys were used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
748df6eea9 swtpm: Prepare key parsing functions to accept 256 bit keys
Prepare the functions that parse or read the key from a file
to accept 256 bit keys.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
3916364950 swtpm: Remove unnecessary fields from symmetric key structure
Remove the valid field from the symmtric key structure and
user userKeyLength > 0 instead, which is the same.

Also remove the tag and fill fields, which were originally used in
TPM 1.2.

Use function calls to test whether the file or migration key is
available where possible.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
e7ba49110c swtpm: Add key length to symmetric key structure
To get rid of the hard coded AES key size of 128, we add a filed
userKeyLength that describes the length of the key being used.
We replace TPM_AES_BLOCK_SIZE with userKeyLength where possible.

Rename TPM_AES_BLOCK_SIZE to SWTPM_AES_BLOCK_SIZE.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
a39f098fd6 swtpm: Use pbkdf2 as default kdf and sha512 for test cases
Use pbkdf2 as the default kdf and sha512 for the existing
test case. Do away with file limit of 32 bytes. This may
break backwards compatibility for some but better to do this
before a release...

Switch the existing test cases to use kdf=sha512 on the command
line where necessary to that the state for these test cases
does not need to be recreated.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
8f0f381f95 scripting: Use #!/usr/bin/env bash rather than /bin/bash
On some systems /bin/bash does not exists but the bash is somewhere
else and can be invoked with /usr/bin/env bash.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:49:12 +00:00
Stefan Berger
54854cff1a swtpm_setup: Enable on DragonFly BSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:12:33 +00:00
Stefan Berger
f3a1b29d8b SELinux: Explicitly list policy package file dependencies
The building of rpm files fails due to some issues with the rules. To make
this work we explicily list the policy packages' dependencies and use them
in the rules. This now make 'make distcheck' work and lets us build an RPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-04 12:05:51 -04:00
Stefan Berger
87668f53f4 SELinux: Fix Makefile.am for out-of-tree builds
Fix the Makefile.am for out-of-tree builds so that 'make distcheck'
runs without errors.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-01 14:18:23 -04:00
Stefan Berger
9c9ed515f4 build-sys: Include -T$(top_srcdir)/include for out-of-tree builds
For sys_dependencies.h to be found during out-of-tree builds we
need to include -I$(top_srcdir)/include.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-01 11:45:09 -04:00
Stefan Berger
6e552e9889 swtpm_setup: Implement support for OS/X (Darwin)
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:40:55 -04:00
Stefan Berger
bd8f4cae3a swtpm_setup: Use env var '_' to get path of program on OS/X
OS/X also does not have a proc filesystem, so we use the '_'
environment variable to determine the path of the program.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 14:59:37 -04:00
Stefan Berger
af23737e6e swtpm: Work around deprecated daemon() on OS X
The daemon() call is deprecated on OS X. This patch works around it so
that we can compiled with -Wall -Werror and still can use the daemon()
call while avoiding compiler errors due to this function's deprecation
marking in stdlib.h.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 14:22:09 -04:00
Stefan Berger
c7d22cf60a swtpm: Remove unused mainloop parameter from functions
Remove the struct mainLoopParams type of parameter from functions
where it is not needed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 12:38:08 -04:00
Stefan Berger
1294b307b5 swtpm: Fix typo in name of header guards
OS X compiler detected a typo in the name of the header guards.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 12:33:41 -04:00
Stefan Berger
2559aa9451 Move conditional includes into sys_dependencies.h
Move the OS specific conditional includes into sys_dependencies.h
while adding OS X support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 11:48:10 -04:00
Stefan Berger
89edc2240c swtpm_setup: Support NetBSD
NetBSD support for swptm_setup.sh.in is like OpenBSD and FreeBSD.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:05:07 +00:00
Stefan Berger
33bee66cf1 tools: Make compileable on NetBSD
Make the tools compileable on NetBSD.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:03:31 +00:00
Stefan Berger
91004268f0 swtpm_setup: Make work on FreeBSD; adapt echo -en
Make swtpm_setup.sh work on FreeBSD.
A common fix for the problem related to echo stopping to write
data into a socket after the first occurrence of \x0a sees to
write it into a pipe and cat the data from there.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-28 22:16:07 -04:00
Stefan Berger
401e670232 tools: Make compileable on FreeBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 01:18:46 +00:00
Stefan Berger
f37f86c0dc swtpm_setup: Adapt NVRAM indices for ECC keys
A (draft) specification indicates the ECC key NVRAM indices to use.
Adapt the code to use them in case of EK ECC key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-27 11:03:43 -04:00
Stefan Berger
6d462f2e06 swtpm_setup.sh: wrap stat in get_filesize
The OpenBSD stat tool uses -f%z to return the file size in bytes.
So we wrap stat in get_filesize and call it with different parameters
depending on the system.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
e7194c6648 swtpm_setup.sh: Adapt od and echo usage for OpenBSD
On OpenBSD 6.2 we have an older version of od that does not support the
-w parameter. Also we have to use the bash echo there since /bin/echo
does not support the -e parameter. We are using /bin/echo on the other
systems since there was (once) a bug when \x0a had to be converted to a
hex number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
4b6a84190c swtpm_setup: OpenBSD: replace access to proc filesystem
OpenBSD does not have a proc file system from which we could
determine the path that swtpm_setup was run from and where we
expect swtpm_setup.sh to be located in as well. Using getenv("_")
seems to work as a replacement in the OpenBSD case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
e69423f277 swtpm_setup: Replace shuf usage with $RANDOM.
Replace usage of shuf with a get_random function that produces
a random number between an upper and lower bound.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:52 -04:00
Stefan Berger
e4405317b3 swtpm_ioctl: Fix number of bytes passed into and expect from ctrl channel
Fix the number of bytes passed into the control channel for commands
and expected for responses. The pointer to the memory is ok.
This fixes uninitialized memory errors reported by valgrind.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 11:28:08 -04:00
Stefan Berger
cd2f547d6a swtpm_ioctl: Fix memmory leak before process exit
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 11:28:08 -04:00
Stefan Berger
fc36ef35ea swtpm: fix memory leak related to tpmstate directory
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 11:27:48 -04:00
Stefan Berger
9c8202ed79 swtpm: free a CUSE related parameter upon exit
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:19:52 -04:00
Stefan Berger
321a22cc66 swtpm: Fix memory leak related to log prefix
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:19:31 -04:00
Stefan Berger
40185e481b swtpm: implement ptm_cleanup for cleanup before exit
Implement a common function for cleaning up before exit.
This should now always remove the pid file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:19:01 -04:00
Stefan Berger
ccfe1b9654 swtpm: fix memory leak when freeing server struct upon exit
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:18:35 -04:00
Stefan Berger
8cafe9d1df swtpm: free pidfile when cleaning up
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:04:03 -04:00
Marc-André Lureau
611a198637 build-sys: fix make distcheck
- fix paths
- ignore chmod issues (they are more package/distro issues)
- scripts are already executable

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-08 09:58:22 -04:00
Stefan Berger
64faf455fb build-sys: Build swtpm_setup on all supported platforms
Introduce compile-time variable HAVE_TCSD if the TCSD could
be found. It influences whether TPM 1.2 related swtpm_setup
test cases can be run. If it is set, they can be run.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
04e45e3cde swtpm_setup: get rid of netstat dependency
Get rid of the dependency on netstat so that we can at least support
swtpm_setup with TPM 2 on Cygwin and BSD later on. This is the first
step into this direction.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
db45e52d67 swtpm_setup: Only try to find tcsd in TPM 1.2 case
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
6da1e3c4a6 swtpm_setup: remove duplicate setting of ECHO variable
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
8579c6de36 swtpm_setup: also check availability of netstat tool in TPM 2 case
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
71ee437f7f swtpm_setup: check for availability of netstat tool
Check that the netstat tool, which may not be required to be installed,
is indeed installed and usable with a set of command line options.

If this tool is not installed it may end up causing swtpm_setup to
hang forever.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
430a39d335 build-sys: Use $(top_builddir) instead of $(top_srcdir) for include/swtpm.h
The include file include/swtpm.h will be generated from swtpm.h.in and
reside under the $(top_builddir) rather than the $(top_srcdir).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
7f086ef946 swtpm_setup: Send TPM2_Shutdown(SU_CLEAR) at end of manufacturing
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
9f4d8af2f0 swtpm_setup: Enable allocation of initially active PCR banks
Implement --pcr-banks to allow a user to choose the set of active
PCR banks. We determine the PCR banks available and enable those
that the user chose and that are available.

The log will now print out the following:

Successfully activated PCR banks sha1,sha256 among sha1,sha256,sha384.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Marc-André Lureau
331d78dbca swtpm: use XDG_CONFIG_HOME to locate config files
This allows to run swtpm_setup as regular user.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
71948dee9d swtpm_setup: Fix 0-size TPM 2 platform certificate in NVRAM
Remove the -s parameter to tpm2_nv_define since it was causing
a 0-size NVRAM location to be created for the platform cert.
Also use the nvindex parameter rather than TPM2_NV_INDEX_PlatformCert
for addressing the platform NVRAM index.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
ec421480cc swtpm_setup: print the NVRAM indices when logging
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
fc60d68597 swtpm_setup: adjust flags for TPM 2 NVRAM locations
Adjust the flags for the TPM 2 NVRAM locations to adhere to the
specification:

TCG PC Client Platform: TPM Profile (PTP) Specification
Family "2.0"; Level 00; Rev 01.03 v22; May 22, 2017

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
af94ba189e swtpm_setup: use variable for determining the NVRAM index to write into
To prepare for writing data into different locations for ECC keys,
assign a variable the location of the NVRAM to write RSA related data
into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
044d4c7f0e swtpm_setup: write EK non-standard template into NVRAM location
We write the EK template into the NVRAM location when it is non-standard.
It's non-standard once the EK can be used for signing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
230d4a043e swtpm_setup: refactor code to create template separately
Refactor the code creating the RSA and ECC key to create the
template separately.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
bab61563af swtpm_setup: Add --decryption for enabling key encipherment
Add the --decryption option to enable key encipherment separately
from enabling signing for the EK. The key encipherment is not set
but needs to be set if --allow-signing is used and key encipherment
is also requested.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
770e7b8189 swtpm_cert: Add option --decryption to use for key encipherment
In case of a TPM 2 we allow the creation of a signing key by passing
--allow signing. To also enable key encipherment, we add the --decryption
option to allow key encipherment and signing at the same time.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
ab20ebb815 swtpm_setup: Also create the primary storage keys as ECC keys
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
60bee0c78c swtpm_setup: Prepare code for ECC primary storage key
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
2bafefe287 swtpm_setup: Create EK and SPK with different handles
Use the standard EK and SRK handles per IWG spec
"TCG TPM v2.0 Provisioning Guidance"; Version 1.0, Rev 1.0, March 15 2017

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
7137394899 swtpm_setup: create a storage primary key
Create a storage primary key and print the handle of the created key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
41a1289043 swtpm_setup: rename tpm2_createprimary to tpm2_create_ek
Rename tpm_createprimary to tpm2_create_ek and print handle of
created EK.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
391edf1c96 swtpm_setup: rename key creation function to have _ek in the name
Rename all TPM 2 key creation functions to have _ek in the name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
cc1c5b7f3f swtpm_setup: create tpm2_createprimary_rsa_params for common code
Create the tpm2_createprimary_rsa_params function that has common code
for creating a primary RSA key with parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
250de46920 swtpm_setup: Pass non evict key handle when creating key
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
814c812e06 swtpm_setup: Don't require root privileges to run it for a TPM 2
Don't require root privileges to run swtpm_setup with a TPM 2 target.
For TPM 1.2 we need the high privilges due to TrouSerS wanting to be
started as root (or 'tss'), but for TPM 2 we do not use any tools
to manufacture the initial state that would require high privileges.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
023423eb41 tests: Add test cases for state suspension and resumption
libtpms preview branch tpm2-preview.rev142 enables volatile state
marshalling and unmarshalling which in turn enables the suspending
and resumption of the TPM state. This patch enables the capabilty
bits and adds test cases for testing the TPM state suspending and
resumption.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
3269485302 swtpm: Fix --tpm2 parameter handling for socket version of TPM
Fix the --tpm2 parameter handlng for the socket version of the TPM. It did
not work so far.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
08da93a96f swtpm_setup: Implement support for ECC keys
Implement support in swtpm_setup.sh so that the TPM's primary key
can be an ECC key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
276eee02b4 swtpm_cert: Support for Elliptic Curve keys
Provide support for creating certificates for TPM2 ECC type of keys.

Extend the test cases and the man pages.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
15226ad9a5 Support TPM 2 in swtpm_setup and swtpm_setup.sh
Support TPM 2 in swtpm_setup and swtpm_setup.sh.
Implement support for all command line options except for:
 o --take-ownership and anything related to ownership passwords
 o --lock-nvram
 o --display

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
e5ffc74dc8 swtpm_cert: Add support for TPM2
TPM2 allows the primary key to also be a signing key, so in case
--tpm2 is provided, --allow-signing can be provided as well in
case the primary can also be used for signing operations.

We use SHA256 for the signing algorithm when TPM 2 is being used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
8fcec541f8 Extend swtpm_bios with --tpm2 to support a TPM 2
Extend the swtpm_bios tool with a --tpm2 command line parameter
to support TPM 2 initialization.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
15dfd665c1 swtpm: Call API call for resetting the TPM Established flag
Call the libtpms API for resetting the TPM Established flag rather
than sending a TPM command, which only works for TPM1.2.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
326e7b5a75 swtpm: Implement support for TPM2 command cancellation
Extend the TPM2 support with command cancellation support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
fbc596abbb swtpm: Provide support for TPM2 using --tpm2
Implement support for TPM2. Some of the capabilities are not supported yet in
this patch.

Extend the man pages with description for --tpm2.

Missing: configure should probe for needed API calls in libtpms

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
66b42f52ef swtpm_cert: Prepend a 'special' ASN.1 byte sequence to the SAN data
The subject alternative name need to have a special sequence of
bytes prepended to them for certtool to accept the data. Also TCG's
sample certificate does show the sequence. The byte sequence is of
the form: 0x30 <subsequent length> 0xa4 <subsequent length> <data>

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:10 -04:00
Stefan Berger
32af260953 swtpm_cert: Do set authority key id explicitly
The previous patch's reversal was partially wrong. The authority
key id needs to be set explicitly from the key id of the signing
key of the issuing CA.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:09:56 -04:00
Stefan Berger
3d35c00c52 swtpm_cert: Remove copying of authority key id
Remove the copying of the authority key id from the given issuer
cert to the created cert since this copies the wrong key id and
besides that it will be set automatically when the certificate is
created.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 09:31:59 -04:00
Stefan Berger
f9b679597f swtpm: Use file lock to prevent concurrent access to state files
Create a .lock file in the directory with the TPM state and get
a lock on this file and hold on to the lock until swtpm ends.
This precludes other swtpm instances to step on the same state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-05 18:39:04 -04:00
Stefan Berger
638bd3ba19 swtpm: Encrypt the data with a random IV every time
Whenever we encrypt the data we generate a new random IV and append a
tlv block with the IV to the byte stream. We mark the IV with different
tags depending on whether they are for the migration data or the (TPM)
data directly. All IVs are part of the HMAC and are added to it after
the data blob.

Adjust test cases that now return larger sizes of data. A constant
checksum over the data cannot be expected anymore, thus we have to remove
the verification of the checksum over the returned state (IV changes
every time).

The size of the blobs grow by 22 bytes, 6 for the tlv header, 16 bytes
for the IV (128 bit AES key).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-02 07:28:16 -04:00
Stefan Berger
2536897da6 swtpm: Get the IV from a tag-length-value block in the data stream
Get the IV from a tlv block in the data stream. If none is found, which
is the case when reading older state, we get a NULL pointer for the IV
and call the functions with the NULL pointer, which provides backwards
compatibility.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-02 07:27:20 -04:00
Stefan Berger
43de0add14 swtpm: Add IV as parameter to AES CBC encryption/decryption function
Enable a caller to pass an IV into the AES CBC encryption/decryption
function. If the caller passes NULL, we use the IV with all zeroes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-02 07:26:17 -04:00
Stefan Berger
ec54294d51 swtpm: Refactor HMAC calculation so we can later pass the IV as well
Refactor the functions calculating the HMAC so that we can later on
pass the IV for the AES CBC encryption as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-30 08:04:42 -04:00
Stefan Berger
d2cd1d6e4e swtpm: get rid of TPM_Malloc/TPM_Free/TPM_Realloc
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-20 10:05:45 -04:00
Stefan Berger
27bf9db67e swtpm: Use tag-length-value blocks to store data in v2 format
Prepend tag-length-value (tlv) headers in front of all data being stored in
the byte stream following the header. This lets us uniquely identify plain
data (= TPM state), encrypted data (= encrytped TPM state), migration data
(which is wrapped plain or encrytped TPM state), and an HMAC block to
validate the plain data.

We keep support for version 1 for reading the data but convert them to
version 2 when writing them out. This way we loose backwards compatibility
(downgrading of swtpm is not possible), but it allows us to extend the state
in the future by adding addition blocks with tlv headers.

Version 1 of the encryption was prepending the hash on the plaintext data
then encrypting all of it. This method is not so good. In version 2 we now
use Encrypt-then-MAC (EtM) where we encrypt the data and then calculate an
HMAC on the encrypted data.

Files written by the swtpm didn't have a header before. Now they also get a
header. This means that the state written into files and the state retrieved
using the API (swtpm_ioctl --save) have the same format, but still differ
in so far as the API wraps the data in a tlv header for migration, which the
files written out as state would never get.

Adapt a couple of test cases show file sizes and hashes have changed now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-20 10:05:45 -04:00
Stefan Berger
3c22251dd8 swtpm: Implement functions for supporting tag-length-value
Implement functions for supporting tag-length-value headers
in the byte stream we store the TPM's data into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-20 09:23:18 -04:00
Stefan Berger
7849b6c67f build: Remove FreeBL support since libtpms does not support it
Remove FreeBL support for swtpm since there will not be support
for FreeBL with TPM 2 in libtpms.

Since a lot of documentation shows --with-openssl, we leave that for
now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 09:08:24 -04:00
Stefan Berger
5409034b5f build-sys: Remove '/' after $(DESTDIR)
Remove the unnecessary '/' after $(DESTDIR).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-29 12:16:49 -04:00
Stefan Berger
39f684b39a Do not call close() with a negative value
Check the value of *pidfilefd before calling close(*pidfilefd).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-14 16:58:08 -04:00
Stefan Berger
5b63c5dbff Use memcpy rather than strncpy and leave note in code
Coverity found that the usage of strncpy may leave an unterminated
string. In this case it is ok, if the string is unterminated since
it would only be the part of a response and the client would have
to collect all the parts as indicated by the total length of the
string. So we use memcpy instead and leave a note in the code. So
far the strings would not nearly be 3k to get close to the maximum.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-14 16:54:04 -04:00
Stefan Berger
2fe082cde6 Use TPMLIB_SetState to set state blobs
Rather than writing to files directly and having to validate the state in
those files using TPMLIB_ValidatetState(), we now use the new
TPMLIB_SetState() call to set the TPM's state blobs. The advantage of this
call is that it doesn't overwrite state files and ends up leaving state in
files that the TPM cannot use. Instead, it validates the state immediately
when the blob is set and returns an error in case the state cannot be
accepted.

We need to adapt one test case that now gets a failure earlier than before.
Before the TPM_INIT failed, now setting the encrypted blob fails because it
cannot be decrypted and thus cannot be accepted by the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-14 09:22:11 -04:00
Stefan Berger
a6e219a6cb swtpm_cert: do not set the subject in the certificate
For TPM 1.2 the spec says that we must not set the subject, so we
do not set it but keep it around for TPM 2 certificates.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-08 12:04:04 -04:00
Stefan Berger
649bd18a14 swtpm_cert: Usa sha-1WithRSAEncryption for TPM 1.2 signature algorithm
Use sha1 rather than sha256 for the TPM 1.2 signature algorithm.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-07 15:40:54 -04:00
Stefan Berger
53161369f4 swtpm_cert: Build platform and TPM info for platform certificate
Build the platform and TPM information into the platform certificate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-07 15:40:54 -04:00
Stefan Berger
f8883a4749 swtpm_cert: Set SAN's ASN.1 using lower level function
To make the ASN.1 look like the one from the spec. we have to
use a lower-level GNUTLS API function to set it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-07 15:40:54 -04:00
Stefan Berger
1bbd38e97f swtpm_cert: put ASN.1 creation code into own functions
Put the code that creates the ASN.1 for the platform and
TPM manufacturer info into their own functions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-07 15:40:54 -04:00
Stefan Berger
23234a3859 swtpm_cert: fix a copy and paste error related to TPM attributes
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-05 01:24:15 -04:00
Stefan Berger
2ba290ac56 swtpm_setup: get tpm manufacturer, fw version, etc. via swtpm_ioctl
Use the swtpm_ioctl tool also to get TPM manufacturer, firmware
version and TPM model and pass it to the external tool creating
the certificate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-05 01:09:39 -04:00
Stefan Berger
ff641f7cdc swtpm_cert: simplify two's completement implementation
Simplify the two's complement implementation by converting the number
into a big endian and writing it out into a byte array that is prefixed
with a 0-byte. This covers all unsigned ints while the previous imple-
mentation would have been wrong once the number exceeded 255.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-04 17:02:03 -04:00
Stefan Berger
81b4af8722 swtpm_cert: calculate two's complement of numbers for ASN.1
Calculate the two's completement of the spec_level and spec_revision
numbers so that ASN.1 properly stores them as unsigned integers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-04 13:31:30 -04:00
Stefan Berger
4f769ec675 swtpm_cert: Use certificate specific OIDs in Extended Key Usage field
Create ASN.1 for the Extended Key Usage field for the EK certificate
that has the oid 2.23.133.8.1 and for the platform certificate the
oid 2.23.133.8.2. Both are registered OIDs:

http://oid-info.com/get/2.23.133.8.1
http://oid-info.com/get/2.23.133.8.2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-04 11:36:16 -04:00
Stefan Berger
3b70a0afa4 SELinux: yet more rules needed for recent Fedora
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-27 12:55:07 -04:00
Stefan Berger
73e136cbc1 SELinux: add yet more rules for svirt for libvirt support
Non-privileged mode needs another rule and on Fedora 27 we need
a swtpm_exec_t related rule we did not need on Fedora 23.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-27 12:21:07 -04:00
Stefan Berger
a6780589b4 swtpm_setup: fix missing space after --vmid parameter
The extern cert program was called with --vmid <foo>--tpm-spec-family ...
and failed due to a missing whitespace. This patch fixes it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 13:55:05 -04:00
Stefan Berger
9670d26d99 swtpm_cert: make the TPM spec parameters mandatory for the EK cert 2018-04-23 10:03:43 -04:00
Stefan Berger
e2951df791 swtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert
Use the new --info parameter for swtpm_ioctl to get TPM specification
info from the swtpm and use this as a parameter for creating the EK
certificate.

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:03:43 -04:00
Stefan Berger
0dda8245d2 swtpm_ioctl: implement --info option to get implementation info
Implement the --info option that takes a flag as an argument
and returns information about the TPM implementation. Only the
value '1' has been defined for now, which returns a line as
the following:

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

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:01:07 -04:00
Stefan Berger
2b8a668dbb swtpm: Implement CMD_GETINFO to retrieve TPM specification info
We quetry the swtpm for TPM specification info that goes into the
certificate for the EK.

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:00:26 -04:00
Stefan Berger
e32c525f5f swtpm_cert: Error out if the Authority Key Id could not be gotten
Since the EK cert must have an Authority Key Id, we error out if
the signing certificate we are given does not have an Authority
Key Id. The typical reason why it wouldn't have it is that we are
using a self-signed (rootCA) certificate directly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-17 10:52:35 -04:00
Stefan Berger
a692723e9d swtpm_setup: log output of tool creating cert
Log the output of the tool that is creating the certificate and
prefix every line with the name of the tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-17 10:52:35 -04:00
Stefan Berger
c6436e4821 swtpm_setup: run exec in a subshell when suppressing errors
To not loose stderr we have to run the exec command in a subshell
and suppress the output of the subshell otherwise the exec command
seems to close stderr on us.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-17 10:52:35 -04:00
Stefan Berger
68baacd721 swtpm_cert: Add Subject Directory Attributes to EK cert
Create the TPMSpecification SEQUENCE and add it to the subject
directory attributes of an EK cert.

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

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

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

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

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

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

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

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

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

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

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

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

Use this as follows:

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

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

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

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 22:00:20 -04:00
Stefan Berger
66a10b3028 swtpm: Fix memory leak in ctrlchannel related to sockpath
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:11:12 -05:00
Stefan Berger
716608eca2 swtpm: fix memory leaks when getting or setting state
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:00:25 -05:00
Stefan Berger
98059a2908 swtpm: Also check the state blob in the CUSE TPM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 15:31:09 -05:00
Stefan Berger
b085ff2335 swtpm: Validate state blobs after setting them
Validate the state blobs after they have been set (during
state migration) so that we can fall back to the migration
source in case they are not accepted by the TPM.

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 14:24:06 -05:00
Stefan Berger
6e79c3b32d swtpm_setup: avoid using expect tool whenever possible
Avoid using the expect tool as much as possible. Use it only if
the user requested a special owner and/or SRK password.

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:10:33 -05:00
Stefan Berger
bf544661b0 swtpm: loop in case poll sets errno EINTR
In case the poll() is interrupted by a signal handler and we
get EINTR, we loop again assuming that the signal handler will
send us a notification to end.

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

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

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-12 09:48:40 -05:00
Stefan Berger
be5557f3ff swtpm_cert: Sign cert using SHA256
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-02 09:41:34 -05:00
Stefan Berger
a8bc74fd01 swtpm_setup: Only pass through vmid parameter if it was set
Only pass through the vmid parameter to the tool creating the cert
if this parameter was set. The tool creating the cert may require
it or ignore it and is supposed to be able to track certificates
for which it minted certs using this parameter.

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

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

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

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

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

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

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

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:50:21 -05:00
Stefan Berger
182fbb20d6 swtpm_ioctl: explicitly check for numbytes < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:45:31 -05:00
Stefan Berger
6c441a5272 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>
2017-11-21 12:45:53 -05:00
Stefan Berger
3ca520fd1c swtpm_ioctl: print error message in case setting state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:44:08 -05:00
Stefan Berger
e396140204 swtpm: log when the decryption of a state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:43:11 -05:00
Stefan Berger
cf47149f88 swtpm: log when the decryption of the NVRAM file fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 19:35:23 -05:00
Stefan Berger
3760c34251 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>
2017-11-11 14:47:27 -05:00
Stefan Berger
41deaf616e swtpm: always set the logging file descriptor on libtpms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:24:12 -05:00
Stefan Berger
addf7c5e45 swtpm: Also log the control channel exchanges
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 21:48:17 -05:00
Stefan Berger
ccd1aeb15b swtpm: also log control channel commands 2017-11-10 21:32:44 -05:00
Stefan Berger
60afebf116 swtpm: Log an error if data encryption failed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
73fb0412ea swtpm: Remove file if errors occured writing it
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
f1389afb87 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>
2017-11-10 18:55:54 -05:00
Stefan Berger
eff9cc1672 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>
2017-11-09 10:54:07 -05:00
Stefan Berger
38304e9c81 swtpm: remove debug include file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 15:38:13 -05:00
Stefan Berger
688c8e2400 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>
2017-11-05 14:53:00 -05:00
Stefan Berger
ca7f7a4006 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>
2017-10-30 12:02:56 -04:00
Stefan Berger
061f9dce5e 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>
2017-10-27 08:37:40 -04:00
Stefan Berger
e09966f603 swtpm_setup: Fix a couple of typos
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
298d17822c 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>
2017-10-16 14:19:48 -04:00
Stefan Berger
aa3999d387 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>
2017-10-16 14:19:48 -04:00
Stefan Berger
75f9f0d300 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>
2017-10-16 14:19:48 -04:00
Stefan Berger
fa3d8e4910 swtpm_ioctl: Display error in case of read() returns < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
6ee0bd79d7 swtpm: Fix header inclusion for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
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