Commit Graph

726 Commits

Author SHA1 Message Date
Stefan Berger
62b7fcd9f3 swtpm_ioctl: Remove unnecessary if statement (issue #392)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com)
2020-12-30 08:11:14 -05:00
Stefan Berger
36ee55222f swtpm: Unconditionally close fd if writing of pidfile fails (coverity)
Do not bother trying to keep pidfilefd open in case fd = pidfilefd,
but close it unconditionally. If writing the pidfile fails, the process
terminates anyway, besides that we only ever need to write to the
pidfile once, which is happening in this function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-12-26 13:32:19 -05:00
Stefan Berger
e1212354c5 swtpm: Adjust size of message buffer to be of size ptm_hdata
This patch fixes the following compilation issue/bug:

ctrlchannel.c: In function ‘ctrlchannel_process_fd’:
ctrlchannel.c:694:13: error: array subscript ‘ptm_hdata[0]’ is partly outside array bounds of ‘struct output[1]’ [-Werror=array-bounds]
  694 |         data->u.resp.tpm_result = htobe32(res);
      |             ^~
ctrlchannel.c:486:7: note: while referencing ‘output’
  486 |     } output;
      |       ^~~~~~

Sending hashes to the TPM is not currently used in any major
application, so this bug should not affect much.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-12-21 18:17:44 -05:00
Stefan Berger
a57c33a1f0 swtpm_setup: Increase timeout from 10s to 30s for slower machines
Older ARM processors need more time to create the initial CA keys
and then the key for the TPM. So we increase the timeout to 30s.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-12-07 14:21:21 -05:00
Stefan Berger
1efe61a69e swtpm_setup: Do not follow symlink on logfile (CVE-2020-28407)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-17 15:42:31 -05:00
Stefan Berger
04b099d14b swtpm: Do not follow symlink when accessing log file (CVE-2020-28407)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-17 15:42:31 -05:00
Stefan Berger
678d5254de swtpm: Use open() (not fopen()) when accessing statefile (CVE-2020-28407)
This patch addresses CVE-2020-28407.

Use the open() call rather than the fopen() call when accessing
the statefile and make sure we do not follow symlinks using O_NOFOLLOW.

The modification does not allow an attacker to create a symbolic link
with the name of the temporary file (TMP2-00.permall for TPM 2) and
have this point to a valueable file and swtpm ends up overwriting the
file. The success of the attack depends on the attacker having access
to the TPM's state directory (--tpmstate dir=...).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-13 09:44:05 -05:00
Stefan Berger
cf3dec63ea swtpm: Switch to open() from fopen() for the pidfile (CVE-2020-28407)
This patch addresses CVE-2020-28407.

Use the open() call rather than the fopen() call when creating a pidfile.
Also prevent us from following symbolic links when opening the pidfile for
writing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-13 09:44:05 -05:00
Stefan Berger
110ab4c908 swtpm: Do not follow symlinks when opening lockfile (CVE-2020-28407)
This patch addresses CVE-2020-28407.

Prevent us from following symliks when we open the lockfile
for writing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-13 09:44:05 -05:00
Stefan Berger
401c9e57a7 swtpm_cert: Switch to open() from fopen() for writing certificate
Switch to open from fopen() and make sure we do not follow symlinks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-13 09:44:05 -05:00
Stefan Berger
22419acee0 swtpm: Move setup of vtpm proxy device into own function
Lift the code that sets up the vtpm proxy device out of the main
function and put it into its own function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-29 18:02:36 -04:00
Stefan Berger
6559a90269 swtpm_cuse: Implement support for --flags startup-xyz options
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-13 17:08:05 -04:00
Stefan Berger
7eb2c29187 swtpm_cuse: Implement support for --flags not-need-init for CUSE TPM
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-13 17:08:05 -04:00
Stefan Berger
2ba2248351 swtpm_setup: Do not truncate logfile when testing write-access
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-06 15:05:08 -04:00
Stefan Berger
1d6a1554a6 swtpm_setup: Remove TPM state file in case error occurred
Remove the TPM state file in case an error occurred.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-06 15:05:08 -04:00
Stefan Berger
07ea18bc38 build-sys: Add python-install and python-uninstall targets
To force the installation of the python programs add a python-install
target. This solves an installation issue with non-standard prefix,
like not using /usr or /usr/local, as may be the case on OS X (Apple)
when using homebrew. It leaves the 'make distcheck' working, which also
uses a non-standard prefix and where we don't want to install the tools
due to issues with removing them afterwards where pip3 cannot be used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-05 12:06:05 -04:00
Stefan Berger
3fde803eb6 swtpm: Write state files atomically using file renaming
To support writing state files atomically we first write into
a temporary file and then rename it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-05 08:56:20 -04:00
Stefan Berger
3f2bde0891 swtpm_setup: Add missing --print-capabilities to help screen
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-02 15:15:04 -04:00
Stefan Berger
d437937f39 swtpm: Prefix debug print function with SWTPM rather than TPM
To avoid clashes with libtpms print functions, prefix the print function
in swtpm with SWTPM_ rather than TPM_. This may matter on older systems
where libtpms could call into swtpm's TPM_PrintAll function due to it
having the same name as libtpms's function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-29 18:12:22 -04:00
Stefan Berger
03c00c0247 swtpm_setup: Do not hardcode '/etc' but use SYSCONFDIR
Do not hardcode the /etc path but use the compile-time generated
SYSCONFDIR instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-23 09:42:38 -04:00
Stefan Berger
31ac728852 swtpm_setup: Fix support for -h and -? options
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-21 13:17:39 -04:00
Stefan Berger
ecabc015ae swtpm_setup: Add missing .config path when using ${HOME}
During the rewrite the additonal "/.config/" got dropped from the
path when using ${HOME} for locating he default config file.
Re-add it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-17 13:05:37 -04:00
Jonas Witschel
3dafa38eb7 build-sys: add configure option to disable installation of Python module
Distributions often have their own guidelines regarding installation of Python
modules (e.g. Arch Linux mandates using --optimize=1 for setup.py install,
which the Makefile in this project does not do). Add an option
"--disable-python-installation" (disabled by default) to allow skipping the
Python installation process entirely so that distributions can take care of
this process manually in their preferred way.

Signed-off-by: Jonas Witschel <diabonas@archlinux.org>
2020-09-14 07:40:31 -04:00
Stefan Berger
0586d2f55a build-sys: Use -Wl,-z,relro and -Wl,-z,now only when linking (clang)
Clang complains if eiher one of those linker flags are used during compilation:

clang-9: error: -Wl,-z,relro: 'linker' input unused [-Werror,-Wunused-command-line-argument]
clang-9: error: -Wl,-z,now: 'linker' input unused [-Werror,-Wunused-command-line-argument]

This patch applies those flags only when linking.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-12 10:55:32 -04:00
Stefan Berger
3064a72ff0 swtpm_setup: Get rid of 'c' code and support changing user in python
Get rid of the 'c' code that only changed the user and add for support of
the --runas option to change to a different user in the python part.

To get 'make distcheck' to work I needed to name the swtpm_setup python
script with the suffix .in so that it gets copied to the build directory
as swtpm_setup. We need to change execute permissions on this file after
copying.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-09 09:53:05 -04:00
Stefan Berger
094dba930f swtpm_setup: Fix wrong variable name detected by pylint 2.4.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-09 09:53:05 -04:00
Stefan Berger
cc410ca91b swtpm_setup: Switch over to new python tool and get rid of the bash script
Switch over to the new python implementation of swtpm_setup. We need to
also adjust test cases that involved the tcsd that otherwise fail for
various reasons. For in-place testing we need to adjust the PYTHONPATH
and PATH so that swtpm_setup.py can be found and so that swtpm_setup.py
then finds swtpm if it is not explicitly passed as parameter.

Adjust the man page for swtpm_setup to reflect the changes.

We now can run swtpm_setup as any user. However, libvirt still runs it
as tss:tss (for example), which is then creating the signing key as tss:tss
as well. Ideally libvirt would run it as tss:root or any other combination
since the tss group may be used for user wanting to access /dev/tpmrm0 for
example. We at least change the directory ownership of /var/lib/swtpm-localca
to tss:root and keep the world out of this directory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-28 16:27:15 -04:00
Stefan Berger
eee8cb5dfb swtpm_setup: Rewrite swtpm_setup.sh in python
Rewrite swtpm_setup.sh in python. Use a permanent connection from the
tool to swtpm via passing file descriptors of a unix socketpair. Implement
all functionality in python so that we don't rely on trousers and tpm-tools
for swtpm_setup. This now allows any user to setup a TPM 1.2 whereas before
it had to be root or the tss user.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-28 16:27:15 -04:00
Stefan Berger
3a2f0be373 swtpm_setup: Accomodate for BSD sed that does not print \n as newline
BSD's sed does not print \n as newline, so we have to split the string
into different lines using tr.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 16:06:10 -04:00
Stefan Berger
3bc10bd2ab build-sys: Label swtpm and swtpm_cuse with SELinux label
When running the selinux-install target also label swptm and swtpm_cuse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 14:36:10 -04:00
Stefan Berger
a7320793b8 build-sys: Add build targets selinux-install and selinux-uninstall
Add build targets selinux-install and selinux-uninstall to install
and uninstall the SELinux policy rules at a given priority. The
priority defeaults to 400, which works fine on Fedora.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 10:50:05 -04:00
Stefan Berger
5a223d2d69 swtpm: Change include of sys/fcntl.h to fcntl.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-16 13:18:16 -04:00
Stefan Berger
88c9deb95d swtpm_setup: Get rid of eval when calling external tool (swtpm-localca)
Get rid of using eval when calling $create_certs_tool and only use
eval for resolving variables from the config file.

We only want variable substitution for entries from configuration
files, so escape all other special shell characters that may be
making it onto the command line so that no subshells are opened
and no redirection to files can occurr.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
b71a228538 swtpm_setup: Only change file and directory ownership if needed
Change the file and directory ownership of tcsd related files only if it
is absolutely needed. It is not needed if we are running as user TCSD_USER
in group TCSD_GROUP because then the files were created with the needed
owner and group. This avoids problems when trying to change file ownership
when invoked by libvirt where we do not have the capabilities to change
file ownership even as root.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
0d9d33fb05 swtpm_setup: Allow group read-rights on $TCSD_CONFIG file if tss user != tss group
When the TSS_USER != TSS_GROUP, e.g., user 'root' and group 'tss', then
tcsd requires that the access mode bits on the $TCSD_CONFIG file are set
to 0640, otherwise we get this error:

TCSD ERROR: TCSD config file (/tmp/tmp.Yd4LIF7mCE) must be mode 0640

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
9d8d6d0378 swtpm_setup: log errors from tcsd in logfile
Redirect stdout and stderr from tcsd into a file and if tcsd reported
an error copy the error into the logfile. This makes debugging tcsd
related issues, such as ownership or access mode issues, easier.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
0371b63bec build-sys: Explicitly link libswtpm_libtpms with -lcrypto (Gentoo)
This patch fixes the following linker issue reported for Gentoo in
issue #280.

ld.lld: error: /var/tmp/portage/app-crypt/swtpm-0.3.1-r1/work/swtpm-0.3.1/src/swtpm/.libs/libswtpm_libtpms.so: undefined reference to EVP_sha512
ld.lld: error: /var/tmp/portage/app-crypt/swtpm-0.3.1-r1/work/swtpm-0.3.1/src/swtpm/.libs/libswtpm_libtpms.so: undefined reference to PKCS5_PBKDF2_HMAC
ld.lld: error: /var/tmp/portage/app-crypt/swtpm-0.3.1-r1/work/swtpm-0.3.1/src/swtpm/.libs/libswtpm_libtpms.so: undefined reference to SHA512

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-21 20:52:34 -04:00
Seunghun Han
2bc601bba5 Fix typos in code and man pages
This patch fixes typos of code and man pages reported by lintian.

Signed-off-by: Seunghun Han <kkamagui@gmail.com>
2020-06-15 08:11:34 -04:00
Stefan Berger
b79970f637 swtpm_setup: Create the RSA 3072 EK key with an empty nonce
Create the RSA 3072 EK key with an empty nonce rather than a nonce full
of 0 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-18 09:26:47 -04:00
Stefan Berger
20fd182c24 swtpm_setup: Put RSA 3072 EK Certificate into NVRAM idx 0x01c0001c
Put the RSA 3072 EK Certificate into NVRAM index 0x01c0001c.

Signed-off-by: Stefan Berger stefanb@linux.ibm.com>
2020-05-18 09:26:47 -04:00
Stefan Berger
7dc24c2f8c swtpm_setup: Allow to create largest possible EK
By passing '--rsa-keysize max' allow to create the largest possible RSA
EK key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
6c5b7c2d86 swtpm_setup: Add support for RSA 3072 bit EK keys
Extend the creation of the EK key to support also 3072 bits RSA keys.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
80d7bb488c swtpm_setup: Report supported RSA key sizes useful for EK key creation
Extend the --print-capabilities option to also report supported RSA
key sizes. Only the TPM 2 may support anything else than 2048 bit RSA
keys, so we only consult 'swtpm socket --tpm2 --print-capabilities'
and grep for 2048 and 3072 key sizes and report them.
If nothing is found, nothing is reported, as before, and 2048 bit RSA
keys should be assumed.

'swtpm_setup --tpm2 --print-capabilities' may now show the following:
{
  "type": "swtpm_setup",
  "features": [
    "cmdarg-keyfile-fd",
    "cmdarg-pwdfile-fd",
    "tpm2-rsa-keysize-2048",
    "tpm2-rsa-keysize-3072"
  ]
}

Also adjust a test case to use a regular expression for matching
against an expected string that may nor may not have rsa-keysize
verbs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
c6b52d18e0 swtpm: Construct RSA key size capabilities from TPMLIB_GetInfo()
Construct RSA key size capability strings from libtpms TPMLIB_GetInfo()
string so that we can easily show which RSA key sizes are supported by
the TPM 2 implementation. If none are advertised, 1024 & 2048 can be
assumed to be supported.

'swtpm socket --tpm2 --print-capabilities' may now print the following:
{
  "type": "swtpm",
  "features": [
    "tpm-send-command-header",
    "flags-opt-startup",
    "cmdarg-seccomp",
    "cmdarg-key-fd",
    "cmdarg-pwd-fd",
    "no-tpm12-tools",
    "rsa-keysize-1024",
    "rsa-keysize-2048",
    "rsa-keysize-3072"
  ]
}

We need to adapt the related test case to use a regular expression since
the rsa-keysize-xyz strings may or may not be there depending on libtpms
version.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 18:12:24 -04:00
Stefan Berger
1974f2ce20 swtpm_setup: Report 'no-tpm12-tools' if tcsd or tpm-tools missing
If the host is missing tcsd (trousers) or the tpm-tools, swtpm_setup
will now report the 'no-tpm12-tools' verb like this:

> swtpm_setup --print-capabilities | jq

{
  "type": "swtpm_setup",
  "features": [
    "cmdarg-keyfile-fd",
    "cmdarg-pwdfile-fd",
    "no-tpm12-tools"
  ]
}

The only TPM 1.2 setup parameter that requires interaction with
the TPM 1.2 that can be pass is then '--createek'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-01 17:47:03 -04:00
Stefan Berger
c7c2f90aeb swtpm_setup: bugfix: Create ECC storage primary key in owner hierarchy
The ECC storage primary key was mistakently created in the endorsement
hierarchy but should be in the owner hierarchy. This patch corrects this
to have this key created in the owner hierarchy (like the RSA key),
thus using 0x40 00 00 01.

This only mattered if one used --create-spk and --ecc together.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-01 15:27:40 -04:00
Stefan Berger
6d0ef98c50 swtpm_setup: return result of called function rather than 0
Return the result of the called function rather than 0.

Fixes: d65f5ae1 ("swtpm_setup: Create RSA 2048 and ECC NIST P256 keys and certs")
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-01 11:53:38 -04:00
Stefan Berger
21af92fd04 swtpm_setup: bugfix: remove tpm2_stirrandom and tpm2_changeeps
Remove tpm2_stirrandom, which we should not need to run on a newly
created TPM 2.
Also remove tpm2_changeeps which was called twice when creating two
EKs, thus invalidating a previous EK that may have been created.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 22:20:08 -04:00
Stefan Berger
f58ead05d8 swtpm_setup: Switch to NIST P384 curves
Switch to NIST P384 curves for the storage primary key as well as the 2nd EK.
The EK part now complies with the following specification:

TCG PC Client Platform TPM Profile Specification for TPM 2.0
Version 1.04
Revision 37
February 3, 2020

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 13:41:50 -04:00
Stefan Berger
d65f5ae13b swtpm_setup: Create RSA 2048 and ECC NIST P256 keys and certs
Following "TCG PC Client Platform TPM Profile Specification for
TPM 2.0, version 1.04, Rev 37" create and RSA and an ECC NIST P256
key now. We will upgrade the ECC NIST key to P384 in the next
step.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 13:41:50 -04:00
Stefan Berger
8dd0eb5d44 swtpm_setup: Move code into tpm2_create_ek_and_cert
Move a whole bunch of EK and certificate creation code into its
own function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 13:41:50 -04:00
Stefan Berger
3d663bacd7 swtpm_setup: Implement function to create ECC NIST P384 EK keys
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-30 13:41:50 -04:00
Stefan Berger
e8d9126d7b swtpm_setup: Rename NONCE_ECC to NONCE_ECC_256
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
ee95fd88c0 swtpm_setup: Pass the ECC curve id and hash alg. into functions
Pass the ECC curve id and hash algorithm and the ECC_NONCE to the
function creating the ECC keys rather than hard coding them. Rename
the functions that create the NIST_P256 ECC keys to have _nist_p256
suffix in the name.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
8b0367e3b3 swtpm_setup: Calculate offset for 2nd ecc key part based on length
Rather than passing the offset of the 2nd part of an ecc key pass
the length of the key and calculate the 2nd offset using the length.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
5f694dbcb7 swtpm_setup: Leave notes about version of templates that were used
Leave a not about what version of template was used for the
RSA and ECC EK keys before updating them now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
fbc42b8d9f swtpm_cert: Support --ecc-curveid option to pass curve id
Implement support for passing the curve id via the --curve-id
option. Default assumes secp256r1. secp384r1 is also supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
d14934f3a6 swtpm: Make coverity happy by handling default case in case statement
Handle the default cases, which shouldn't ever be reachable, and set
the tocopy to '0' so that no unitialized variable gets copied.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-24 16:20:26 -04:00
Stefan Berger
3a3a9f5b5f swtpm: Invoke print capabilites after choosing TPM version
Invoke the printing of the capabilites after choosing the TPM version
in libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-23 16:40:13 -04:00
Stefan Berger
548eb6859b swtpm: Remove unnecessary #include <seccomp.h> (fixes SuSE build)
It's not necessary anymore to #include <seccomp.h> from the main programs.
Once removed, it also fixes the build on SuSE where seccomp.h is in
seccomp/seccomp.h and we didn't use the LIBSECCOMP_CFLAGS for swtpm.c etc.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-20 19:31:09 -04:00
Stefan Berger
eb9cfa963a swtpm: Add some recent syscalls to seccomp blacklist
Add some recent syscalls to the seccomp blacklist, particularly
setter type of functions.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-13 12:26:11 -04:00
Stefan Berger
dd92f45898 swtpm: Address cygwin compilation warning
Compilation on cygwin reports the following issue:

In file included from key.c:43:
key.c: In function ‘key_stream_to_bin’:
key.c:135:26: error: array subscript has type ‘char’ [-Werror=char-subscripts]
  135 |            !isspace(input[digits]) &&
      |                     ~~~~~^~~~~~~~
key.c:143:40: error: array subscript has type ‘char’ [-Werror=char-subscripts]
  143 |     if (input[digits] && !isspace(input[digits]))
      |                                   ~~~~~^~~~~~~~

Address the issue using an explicit cast of char to int.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-12 14:32:38 -04:00
Stefan Berger
bacb56b4ec swtpm_setup: Remove some old cruft
Remove some commented code and some code that isn't executed any
differently for the user id that's running it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-10 09:35:20 -04:00
Stefan Berger
029e9d4638 swtpm_setup: Explicitly set TCSD_TCP_DEVICE_HOSTNAME=127.0.0.1
To make swtpm_setup.sh work on Travis on Bionic we need to
explicitly set TCSD_TCP_DEVICE_HOSTAME=127.0.0.1 since lookup
of localhost (with the API the tcsd is using) does not work.
It doesn't negatively affect any other use case, so no problem
setting it.

Also replace localhost in the bash tcp device path with 127.0.0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-09 19:39:38 -04:00
Stefan Berger
cb5ab582d1 swtpm: Fix vtpm proxy case without startup flags
'swtpm chardev --vptm-proxy' currently requires a '--flag startup-xyz'
to be passed since otherwise the need_init_cmd variable would not be
set to false and swtpm would terminate after sending the startup
command. To maintain backwards compatibility we have to always
set the need_init_cmd variable to false for the --vtpm-proxy case
and must not require a startup flag to be passed.

Roll back one of the test case to not use the startup flag.

Fixes: e6bc4bdf0 ('swtpm: Enable sending startup commands ...')
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-03-07 09:09:14 -05:00
Stefan Berger
d1083d1164 swtpm: Only call memcpy if tocopy != 0 (coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-14 09:53:32 -05:00
Stefan Berger
e6bc4bdf0a swtpm: Enable sending startup commands before processing commands
The vtpm proxy device requires that the TPM be 'Startup' otherwise it
fails sending the first command to it and will send the 'Startup'
(SU_CLEAR/TPM_ST_CLEAR) itself while adding a log entry. We want to
avoid the kernel log entry.

Add options to the existing --flags option that allows one to start
up the TPM 1.2 or TPM 2.0 with the startup types 'clear', 'state'
and 'deactivate' (TPM 1.2 only). Extend the --print-capabilities to
advertise the availability of these options with the string
'flags-opt-startup'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-08 18:19:08 -05:00
Stefan Berger
6eef00e416 swtpm_cert: Accept serial numbers that use up to 64bits
Accept serial number that use up to 64bits.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
a718f2a9e7 swtpm_cert: Use getopt_long_only to parse options
Convert the code to use getopt_long_only for parsing the options.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
88c7bdc9e3 swtpm_cert: Add support for --print-capabilities option
Add support for the --print-capabilities option to display newly
added capabilities. Adpat the man page and related test case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
b35eb9fcd5 swtpm_cert: Allow passing signing key and parent key via new option
Allow passing signing key and parent key via files and file descriptors
and environment variables. Adapt a test case to exercise this new
functionality.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
f9547ddc2c swtpm_setup: Enable spaces in paths and other variables
This patch addresses several issues found with shellcheck. In particular
it now enables variables with spaces in them, such as file paths that
contain spaces.

Adjust one of the accompanying test cases to use spaces in the path.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05:00
Stefan Berger
d66f4d1e03 swtpm_ioctl: Calculate strlen(input) only once
Calculate the strlen(input) only once at the beginning.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-22 19:32:24 -05:00
Stefan Berger
3eef9811b9 swtpm_ioctl: Block SIGPIPE so we can get EPIPE on write()
Block the SIGPIPE so that a failing write() can return an EPIPE
rather than killing the process with a SIGPIPE.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-22 19:32:24 -05:00
Stefan Berger
f27256f154 swtpm_bios: Block SIGPIPE so we can get EPIPE on write()
Block the SIGPIPE so that a failing write() can return an EPIPE
rather than killing the process with a SIGPIPE.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-22 19:32:24 -05:00
Stefan Berger
abadb408a9 swtpm: Only accept() new client ctrl connection if we have none
Only accept new client connection on the control channel if we
currently do not have a client on the control channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-22 19:32:24 -05:00
Stefan Berger
de10d7cd59 swtpm_setup: Do not fail on future PCR banks' hashes
swtpm_setup will fail once libtpms starts supporting other PCR
hash banks than sha1, sha256, sha384, sha512, and sm3-256. So,
this patch allows to choose active PCR banks of the SHA3 series.
Further, unknown hash banks will not fail the tool anymore when
it tries to determine which hash banks are supported by the TPM
since it will then add the hex number of the hash algorithm to
the collection of supported hashes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-17 20:07:37 -05:00
Stefan Berger
84f350dace swtpm_setup: Use 1st part of SWTPM_EXE/SWTPM_IOCTL to determine executable
Search for the SWTPM_EXE / SWTPM_IOCTL executable using 'type -P' to
determine whether it is an executable rather than assuming a full path
is given on which we can check -x.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
fa0ecd9951 swtpm_setup: Keep reserved range of file descriptors for swtpm_setup.sh
swtpm_setup.sh uses file descriptor 100 for 'exec 100 <> ...'.
So we have to make sure that the file descriptor inherited from
the caller of swtpm_setup does not overlap with a reserved range
to be used by swtpm_setup.sh, which we declare to be [100..109].

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-09 14:22:50 -05:00
Stefan Berger
5196855ad1 swtpm_setup: Log about encryption and fix c&p error in err msg
Fix a cut and paste error in the error message output and be more
verbose in log about encryption when using file descriptors.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-07 20:06:03 -05:00
Stefan Berger
a7c4f3734a swtpm: Add --print-capabilities to help screen of 'swtpm chardev'
The --print-capabilities is missing in the 'swtpm chardev' help screen
but the code is there to interpret the command line flag. This patch
adds the missing lines to the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-07 11:18:10 -05:00
Stefan Berger
8330ccd07e swtpm_ioctl: Fix uninitialized variable 'pgi'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-12-23 15:06:33 -05:00
Stefan Berger
132bbf7b7a swtpm_cert: Use gnutls_x509_crt_get_subject_key_id API call for subj keyId
Use the gnutls_x509_crt_get_subject_key_id() API call to get the subject
key ID of the signer's certificate rather than gnutls_x509_crt_get_key_id().
The latter returns the same result most of the time but there are instances
when this is not the case and the returned result is wrong.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-10-22 12:39:29 -04:00
Jeremy Liu
36bfbb7432 Correct parameter name typo
Signed-off-by: Jeremy Liu <liujiong@gohighsec.com>
2019-10-17 12:29:38 -04:00
Stefan Berger
a85b7d2823 swtpm_cert: Fix OIDs for TPM 2 platforms data
The OIDs for the TPM 1.2 and TPM 2 platform data
are different (though have the same name in the spec).
Adapt them for the TPM 2 case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-10-11 08:34:30 -04:00
Stefan Berger
ab1b346ef0 SELinux: Need more rules for QEMU and KVM type of VMs on F30
More rules are needed for QEMU and KVM type VMs on F30.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-26 20:38:46 -04:00
Stefan Berger
bea37691ac swtpm: Fix typo in error report: HMAC instead of hash
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-25 10:09:25 -04:00
Stefan Berger
5c5d3b793b swtpm: Use writev_full rather than writev; fixes --vtpm-proxy EIO error
We have to use writev_full() when --vtpm-proxy is used since writev()
does not seem to work and we get an EIO error. writev_full() uses write(),
so we can use it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-23 10:06:20 -04:00
Stefan Berger
7491ed0f2a SELinux: A few more rules needed for F30
A few more rules are needed on Fedora 30 to have libvirt start swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-23 10:06:20 -04:00
Stefan Berger
374b66913f swtpm: Address Coverity's dead code complaint
Signed-off-by: stefan Berger <stefanb@linux.ibm.com>
2019-07-13 21:53:13 -04:00
Stefan Berger
ad2fb40077 swtpm: Loop over poll() in case of EINTR
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
a442092d8e swtpm: Convert read() to read_eintr() which handles EINTR
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
37ac6aec73 swtpm: Implement read_eintr() to read into a buffer and handle EINTR
Implement read_eintr() to read into a buffer and handle EINTR on
the way.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
ec355ee80c swtpm: Use write_full instead of plain write
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
2d921e663c swtpm: Implement write_full and writev_full
Implement write_full and writev_full that handle partial writes.

Implement writev_full using write_full since handling partial writes
with iovec's can become quite complicated.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
30e12eae27 SELinux: Add rule for passing pass phrase via file descriptor
Add a rule so we can pass a passphrase from libvirt to swtpm using
a file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
1edad44acd swtpm_setup: Add --print-capabilities option
Extend swtpm_setup with the --print-capabilities option which
prints a JSON object describing supported features.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
c11bf8c5f8 swtpm_setup: Test filenames for empty string before trying to remove
rm on NetBsd prints out an error message when trying to remove a file
with an empty filename. Avoid this situation by checking for non-empty
filenames first.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
11114ba745 swtpm: Add --print-capabilities option to command line
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
1d5e07974b swtpm: Implement support for printing newly added capabilities
Implement support for printing newly added capabilities, such as
being able to read the key and password from a file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
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