Commit Graph

92 Commits

Author SHA1 Message Date
Stefan Berger
5486f0437f swtpm_setup: Add support for --profile-name option
Add support for --profile-name option that searches for a profile in a
configurable local directory or a distro directory
(typically /usr/share/swtpm/profiles).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 09:35:17 -04:00
Stefan Berger
82e3f38a82 swtpm_setup: Support default profile from file in swtpm_setup.conf
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
25eb5f75ea swtpm_setup: Read default profile from swtpm_setup.conf
If the user did not provide the profile on the command line read the
default profile from the swtpm_setup.conf configuration file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
cc9ee0fbc6 swtpm_setup: Get default rsa keysize from setup_setup.conf if not given
If the user did not provide the RSA keysize to use try to read it from
setup_setup.conf and if nothing is found there fall back to using the
internal default RSA keysize (2048).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-17 18:34:25 -04:00
Stefan Berger
1cd2dc6049 samples: swtpm-create-tpmca: Fix shellcheck issues and add to syntax-check target
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-22 17:27:05 -05:00
Stefan Berger
036fd75b1f samples: swtpm-create-tpmca: Check for missing tpmtool
Recent GnuTLS does not package tpmtool anymore. Check for
the missing tpmtool and report an error as appropriate.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-22 17:27:05 -05:00
Stefan Berger
30fa8b47d2 swtpm_setup: Write active_pcr_banks into swtpm_setup.conf
Write the active_pcr_banks into swtpm_setup.conf with the default
PCR banks from the configure script.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:36:35 -04:00
Stefan Berger
1ffa0cc472 swtpm_setup.conf: Use /usr/bin/swtpm_localca for create_certs_tool
swtpm_setup.conf has traditionally pointed to
/usr/share/swtpm/swtpm-localca for create_certs_tool but since
/usr/bin/swtpm_localca is now available, have newly created
config files point to this executable instead.

Since there are possibly many swtpm_setup.conf out there pointing
to /usr/share/swtpm/swtpm-localca, we have to still install
swtm_localca there as well and package it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-28 15:14:01 -04:00
Stefan Berger
5d4dd13e80 samples: Have swtpm-create-user-config-files run swtpm_setup
Have swtpm-create-user-config-files run swtpm_setup with the new
--create-config-files option and possible parameters.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 14:27:10 -04:00
Nick Chevsky
ddc7521653 Move swtpm_localca sources from samples/ to src/
- Move swtpm_localca's sources out of samples/ (where they no longer
  belong now that swtpm_localca is a binary) to src/swtpm_localca/.
- Tests now call the swtpm_localca binary directly at the location
  where it was built, as they do with all other compiled programs.
- Simplify samples/swtpm-localca.in and delete swtpm-localca.2inst,
  removing the now-unnecessary logic to selectively call swtpm_localca
  from different locations (samples/ when running tests vs. /usr/bin/
  post-installation).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-25 08:52:13 -04:00
Nick Chevsky
edfb8d8ad9 Move swtpm_setup.conf.in from etc/ to samples/
- Makes swtpm_setup.conf.in consistent with the rest of the sample
  configuration files in swtpm, whose templates ship in samples/ and
  install the generated files to /etc.
- Works around dh_missing(1) erroneously reporting swtpm_setup.conf as
  non-installed due to its having two copies in the build tree (one in
  etc/ and another in debian/tmp/etc/).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-21 20:30:44 -04:00
Stefan Berger
50f7d49ad3 samples: Use different script for local testing than install
Use a different script for local testing that what is installed into
/usr/share/swtpm/swtpm-localca.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-17 09:28:54 -04:00
Stefan Berger
fd00c5ff87 samples: Replace swtpm_localca with script calling swtpm-localca (issue #482)
Replace the binary swtpm_localca with a script that now calls the binary
swtpm-localca, which is to be installed in $bindir.

So that we can use this for script for calling swtpm-localca during testing
(when it is not installed), write the script in such a way that it de-
termines whether there's swtpm-localca in the same directory and if not call
it from ${bindir}/swtpm-localca.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-16 16:03:14 -04:00
Stefan Berger
84c10ba7e4 samples: swtpm_localca: Fix issues raised by -Wextra
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 15:05:03 -04:00
Stefan Berger
2c270f0407 sample: swtpm-localca: Add missing else branch for pkcs11 and PIN
Add a missing else branch that was forgotten about when the code was trans-
lated from python. This now also gets the test case
test_tpm2_samples_create_tpmca to work again when it is run from the command
line. This test case doesn't work as part of the test suite due to
concurreny issues with other test cases using tpm2-abrmd at the same.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-21 19:58:49 -04:00
Stefan Berger
932dc4e270 build-sys: Add HARDENING_CFLAGS and _LDFLAGS to all C programs
Add the HARDENING_CFLAGS and _LDFLAGS to all C programs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-04 16:04:09 -04:00
Stefan Berger
71c353a728 swtpm_localca: Adjust expiration days for 32-bit platforms
GnuTLS on 32-bit platforms complains about the long expiration time
of the certificates since they overflow the 32-bit time_t. Reduce
the duration to 12 years.

This system expresses time with a 32-bit time_t; that prevents dates after 2038 to be expressed by GnuTLS.
Overflow while parsing days

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-04 16:04:09 -04:00
Stefan Berger
4165421a9d swtpm_localca: Initialize autofreed variables to NULL (gcc-11)
This patch addresses the following gcc-11 compiler issues:

In file included from /usr/include/glib-2.0/glib.h:114,
                 from ../src/utils/swtpm_utils.h:13,
                 from swtpm_localca_utils.c:24:
swtpm_localca_utils.c: In function 'get_config_envvars':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'value' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   28 |   g_free (*pp);
      |   ^~~~~~~~~~~~
swtpm_localca_utils.c:98:37: note: 'value' was declared here
   98 |             g_autofree gchar *key, *value;
      |                                     ^~~~~
In file included from /usr/include/glib-2.0/glib.h:114,
                 from ../src/utils/swtpm_utils.h:13,
                 from swtpm_localca_utils.c:24:
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'key' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   28 |   g_free (*pp);
      |   ^~~~~~~~~~~~
swtpm_localca_utils.c:98:31: note: 'key' was declared here
   98 |             g_autofree gchar *key, *value;
      |                               ^~~

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-04 16:04:09 -04:00
Stefan Berger
e689684c57 samples: Rewrite of swtpm_localca in 'C' (addresses issue #437)
This is a 1:1 rewrite of swtpm_localca in 'C' as a final step to get
rid of the python dependency. It addresses issue #437.

Tested on: Cygwin, Fedora 33, Ubuntu Xenial & Bionic, FreeBSD,
           DragonFlyBSD, OpenBSD (i386), Mac, Debian (recent), Centos-8,
           CentOS (recent), Alpine (recent), OpenSUSE (recent),
           Fedora 28 PPC Big Endian

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-01 09:31:43 -04:00
Stefan Berger
b11da814a8 sample: swtpm-local: Fix a few minor issues
Have the statedir created in case it doesn't exist before checking for read
and write access to it.

Set the default directory where to write the results into to the current
directory '.' rather than to what would result in the root directory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-27 15:03:48 -04:00
Stefan Berger
57a5df07e1 samples: Fix typo in project URL (swptm->swtpm)
This patch fixes issue #410.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-05 16:48:55 -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
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
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
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
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
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
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
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
a73e9cb831 samples: Apply password for signing key when creating platform cert (bugfix)
Apply the password for the signing key and parent key when creating a
platform certificate. The bug was introduced in commit 961bb827
"samples: Use new pwd format option for secretly passing passwords"

Extend a test case to ensure that the passwords are always used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-15 21:08:32 -04:00
Stefan Berger
79a0bdb483 samples: Properly apply passwords for localca signing key (bugfix)
When the local CA was create the signing key of the intermediate CA
was not properly protected by the passwords. This patch fixes this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-15 21:08:32 -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
a12b09b1ea samples: Implement script to create user config files and extend man page
Implement a script that creates the user config files in the
${XDG_CONFIG_HOME} directory and sub-directories.

Extend swtpm_setup.pod showing swtpm-create-user-config-files usage.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-20 09:49:33 -04:00
Stefan Berger
217c29cb07 Revert "samples: Implement script to create user config files"
This reverts commit d09484c02d.
2020-08-20 09:49:33 -04:00
Stefan Berger
d09484c02d samples: Implement script to create user config files
Implement a script that creates the user config files in the
${XDG_CONFIG_HOME} directory and sub-directories.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 14:39:31 -04:00
Stefan Berger
d920680776 samples: Get rid of using eval when running swtpm_cert
Get rid of using eval when running swtpm_cert in swtpm-localca.
This is to avoid further evaluation of bash expression that can
spawn subshells ('$(echo foo)') or do other bad things. Bad input
could come from malformed configuration files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
b6aef51ff3 samples: Escape many more characters before calling eval on an entry
Escape many more special shell characters before calling eval on
an entry to convert a variable to its value. Uncareful writing of
a swtpm-local.conf config file could have lead to files being over-
written using '>' for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
72aac899fa samples: Parse optional id= for ECC curve IDs
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-29 20:35:04 -04:00
Stefan Berger
f30e202df6 samples: Extend script to create a CA using a TPM 2 for signing
Extend the script that creates a CA that uses a TPM 2 for signing.
For this we have to create tokens using the TPM 2 pkcs11 module's
tpm2_ptool and can then use the p11tool for creating keys.

Add a test case that requires a running tpm2-abrmd and tpm2_ptool.
Eventually the test case should (try to) start its own tpm2-abrmd
and talk to swtpm directly but the tcti module to do that isn't
available as a package, yet.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 13:09:00 -04:00
Stefan Berger
961bb827a4 samples: Use new pwd format option for secretly passing passwords
Use the swtpm_cert --signkey-pwd and --parentkey-pwd to pass key passwords
using files rather than using the command line options.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
b291eb83ed samples: Protect variables in swtpm-create-tpmca
Address several issues reported by shellcheck and protect
variables with quotes so we now can have filenames with spaces.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05:00
Stefan Berger
77819bb2e6 samples: Protect variables with quotes and address shellcheck issues
Protect variables with quotes so that pathnames with spaces are now
supported.

Adjust the accompanying test case to make use of spaces in file paths.

Address several issues found by shellcheck. Some of them are false
positives especially when it comes to protecting variables passed
to a commaned in an 'eval' line. They must not be protected, otherwise
they are not passed correctly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05: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
7a3d1cde46 samples: Enable swtpm-localca to sign with a pkcs11 URI
Allow the user to specify a pkcs11 URI in the signingkey field
in swtpm-localca.conf.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 12:48:43 -05:00
Stefan Berger
d16b86b7b0 build-sys: Adjust localstatedir and files using it
Adjust the localstatedir variable to not have ${prefix} if
prefix is '/usr/', otherwise use ${prefix}.

Also adjust the files that were pointing to directories that
are controlled by $localstatedir.

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
ccb00a55cd samples: Escape the GnuTLS PKCS11 URL before using in command line
GnuTLS PKCS11 URLs have ';' in the string that we need to preserve for
passing to GnuTLS. So we escape the semicolons before using them on the
command line.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-11 13:44:36 -05:00