Commit Graph

1150 Commits

Author SHA1 Message Date
Stefan Berger
5e9e47337e man8: Mark device parameter as optional
Since the device can be passed using --tpm-device <device>, we now
mark the last parameter, which can also be the device, as optional.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-12-30 08:11:14 -05:00
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
fba278cc4b github: Update issues templates
Update the issues template.
2020-12-27 22:49:45 -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
f495d8fc9b Travis: Remove OSX CI/CD due to costs
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-17 16:55:45 -05:00
Stefan Berger
3a2b8391ef samples: 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
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
Eiichi Tsukata
2c42f4be50 build-sys: fix configure python cryptography error message
Currently it shows "python setuptools is required" if "import
cryptography" failed.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2020-11-11 10:40:39 -05:00
Stefan Berger
b945230493 tests: Try with tcsd.conf ownership of root:tss if tss:tss did not work
Due to recent changes in tcsd, it doesn't accept 'tss:tss 0600' anymore
for the tcsd config file but we need to use 'root:tss 0640' for it.
So far only Fedora seems to be affected. It now depends on whether tcsd
has been patched what ownership is required. So we try first the old
configuration and then the new one.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-09 08:51:08 -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
812917a952 samples: Require --root flag if root user runs script
Since the config files created by the swtpm-create-user-config-files
script will shadow those typically installed in /etc, we now require the
option --root if 'root' runs this script so that root is aware what he is
doing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-28 08:32:50 -04:00
Stefan Berger
2caa41bd15 build-sys: Bump up version to 0.6.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-28 08:32:50 -04:00
наб
3dea271c67 debian: drop revision from version, illegal for native-format packages
$ dpkg-buildpackage -us -uc
dpkg-buildpackage: info: source package swtpm
dpkg-buildpackage: info: source version 0.5.0-1
dpkg-buildpackage: info: source distribution RELEASED
dpkg-buildpackage: info: source changed by Stefan Berger <stefanb@linux.ibm.com>
dpkg-source: error: can't build with source format '3.0 (native)':
native package version may not have a revision

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
2020-10-28 08:32:50 -04:00
наб
755881ba27 man: Fix enc[yr]ption typo in swtpm_setup manpage
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
2020-10-27 22:27:36 -04:00
Stefan Berger
ab40d27ab1 man: Extend man pages with --flags support for CUSE TPM
Also fix an error in the man page on the way. 'startup-deactivated'
can only be used with a TPM 1.2, not a TPM 2.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-13 17:08:05 -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
b931e10985 debian/rpm: Adjust changelog for 0.5.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-07 14:24:43 -04:00
Stefan Berger
611c589691 CHANGES: Add documentation for changes in 0.5.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-07 14:24:43 -04:00
Stefan Berger
5af35971b8 samples: 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
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
9591808d18 tests: Fix path to swtpm-localca
This patch fixes the path to swtpm-localca to avoid this type of
error because of swtpm_localca_conf having been created in another
directory. This error occurred whan running

sudo bash -c "make -j32 distcheck"

Traceback (most recent call last):
  File "/home/stefanb/tmp/swtpm/swtpm-0.5.0/samples/swtpm-localca", line 5, in <
    from py_swtpm_localca.swtpm_localca import main
  File "/home/stefanb/tmp/swtpm/swtpm-0.5.0/samples/py_swtpm_localca/swtpm_local
    from py_swtpm_localca.swtpm_localca_conf import SYSCONFDIR
ModuleNotFoundError: No module named 'py_swtpm_localca.swtpm_localca_conf'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-05 10:03:18 -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
d4c60e44ce tests: Allow 'ss' as an alternative to 'netstat'
Some distros (openSUSE) have deprecated the 'net-tools' package,
so we allow for 'ss' as an alternative tool from the
iproute/iproute2 package. This is only relevant for test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-02 15:56:42 -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
Elms
8d086ee9de Use correct LDFLAGS for non-standard libtpms locations 2020-09-24 21:30:10 -04:00
Stefan Berger
48275746e3 samples: Use ${HOME}/.config if XDG_CONFIG_HOME is not set (RHEL)
When creating the user config files, fall back to using ${HOME}/.config
if XDG_CONFIG_HOME is not set on a system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-23 18:14:23 -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
7419536fb9 rpm: Create swtpm-tools-pkcs11 package
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-22 12:27:16 -04:00
Stefan Berger
3a3e5661f0 debian/rpm: Adjust packaged files for swptm-localca in python
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-22 12:27:16 -04:00
Stefan Berger
8bac7cdf22 tests: start tpm2-abrmd for test case
Start tpm2-abrmd for the test case 'test_tpm2_samples_create_tpmca' rather than
expecting it to be already running.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-22 11:40:57 -04:00
Stefan Berger
7b72dfedec samples: swtpm-localca: Pass password via template file when possible
Pass the CA's private key password via the template file. Remove recently
added old GnuTLS support. Extend man page with a paragraph about short-
comings of certtool that doesn't seem to allow private key password being
passed either as environment variable or template file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-21 16:01:20 -04:00
Stefan Berger
c73771b0c5 samples: Fix support for -h and -? options in swtpm-localca
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-21 13:17:39 -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
3ed0744de0 samples: Add --password parameter for older GnuTLS versions
Older versions of GnuTLS need --password on the command line while
newer versions require GNUTLS_PIN to be set to pass the password.
So, this patch accomodates older versions of GnuTLS.

Older version of GnuTLS seem to NOT be able to handle a CA private
key needing a password and a signing key needing a password when
creating the intermediate CA. So this case of 2 passwords will
always fail.

The value of the local CA is not so high that passing passwords on
the command line would be an issue. Later on when using the CA the
password are set via environment variables, so not visible to other
users.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-18 20:12:01 -04:00
Stefan Berger
14d2d4381d samples: Add support for pkcs11 module environment variables to config file
Add support for pkcs11 module environment variables to the config file.
These variables may have the following format:

   env:VARNAME=VALUE

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-18 12:09:11 -04:00
Stefan Berger
cc592a0931 samples: Also allow signingkey_password to be used not just 'SWTPM_PKCS11_PIN'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-18 12:09:11 -04:00
Stefan Berger
1ed75624a6 Travis: Run pylint on new swtpm-localca, remove flock on OS X
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-18 12:09:11 -04:00
Stefan Berger
b71da43026 samples: Rewrite swtpm-localca in python
Rewrite swtpm-localca in python and get rid of the bash file and the flock
dependency.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-18 12:09:11 -04:00
Stefan Berger
4cd9390bed man: Extend man pages with further locations of options and config files
Extend the man pages with further locations for the options and config
files in ${XDG_CONFIG_HOME} or ${HOME}/.confg.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-18 12:09:11 -04:00