Commit Graph

61 Commits

Author SHA1 Message Date
Stefan Berger
5d6a33f834 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-24 11:00:47 -04:00
Stefan Berger
e439f15324 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-16 12:36:21 -04:00
Stefan Berger
b57616893d 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-16 12:36:21 -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
Stefan Berger
e0c04ff832 samples: Enable support for well known SRK password (TPM 1.2)
If tpmtool supports --srk-well-known we also support the well known
SRK password and allow the user not to provide an SRK password on
the command line.

This patch should have been applied before the previous patch that
tests this. Luckily, only very few systems have tpmtool with
--srk-well-known so that the order would matter there (and cause test
failures).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-09 15:07:54 -05:00
Stefan Berger
588c06362b samples: Require an SRK password for TPM 1.2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:23:11 -05:00
Stefan Berger
7be0768859 samples: Return result code from expect script to caller
Return the result code from the expect script to the caller.
Also, display possible log messages in case the private key file
was not written properly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:23:11 -05:00
Stefan Berger
3327d83878 samples: Fix a typo
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-25 10:32:36 -04:00
Stefan Berger
15a14c552a samples: Add support for password protected root CA priv. key
Support creation and usage of the root CA with a password protected
private key. The root CA's key password can be set using the environment
variable SWTPM_ROOTCA_PASSWORD.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-25 10:32:36 -04:00
Stefan Berger
05f4d55f1f samples: Add a script to create a TPM 1.2 intermediate CA
This (experimental) script uses GnuTLS tpmtool to create a TPM 1.2
intermediate CA that can sign a vTPM's EK and platform certificates.

Add a man page for this tool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-15 20:45:48 -04:00
Stefan Berger
07c786d1a0 samples: Enable support for TPM 1.2 signing keys for cert signing via GnuTLS
GnuTLS can use TPM 1.2 keys for signing. For this we just need to support
key URLs in the GnuTLS format:

tpmkey:uuid=...
tpmkey:file=...

We don't try to read these URLs as files but pass them through as URLs to
the swtpm_cert tool that will then try to sign with the TPM 1.2 key by
passing the URL to GnuTLS API calls.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-15 20:45:48 -04:00
Stefan Berger
33e1e50849 samples: Add a usage screen to swtpm-loclca to show upon --help
swtpm-localca was missing a help screen. This patch adds it and
is shown when --help or -? or -h is passed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-12 17:43:19 -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
b63000fa8d samples: set CERTTOOL to gnutls-certtool on OS/X
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:39:00 -04:00
Stefan Berger
f13d2a045c sample: wrap flock in flock_fd for support on OS/X
OS/X has a flock (v0.2.3) implementation using

brew tap discoteq/discoteq
brew install flock

The current version doesn't support -x as a parameter for
an exclusive lock but uses an exclusive lock when no parameter
is passed at all.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:27:25 -04:00
Stefan Berger
44eac994b6 samples: use flock -x rather than flock -e
flock -e does not work on NetBSD, so replace it with flock -x,
which should work everywhere.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:01:40 +00:00
Stefan Berger
2266da36d9 samples: create lock with name .lock.swtpm-localca rather than .lock
To avoid clashes with the lock files created by swtpm, have
swtpm-localca creata a lock file with the name .lock.swtpm-localca
so they can share directories if necessary.

This patch makes tests/test_tpm2_swtpm_setup_create_cert run on
OpenBSD since the swtpm and swtpm-localca then do not interfere
with the file locks. This doesn't seem to be an issue on Linux
or Cygwin, though, where probably the file locking is implemented
differently.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.om>
2018-08-26 16:03:53 -04:00
Stefan Berger
da6ca6fab6 samples: OpenBSD scripting fixes
OpenBSD uses an older sed implementation that doesn't understand the
meaning of the '+' for getting one or multiple occurrences of a letter.
Work around this by not using it and trimming white spaces at the end
of a variable using bash.

Use 100 as file descriptor rather than 200 to accomodate OpenBSD,
which only support file descriptors <= 127.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:52 -04:00
Marc-André Lureau
611a198637 build-sys: fix make distcheck
- fix paths
- ignore chmod issues (they are more package/distro issues)
- scripts are already executable

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-08 09:58:22 -04:00
Stefan Berger
8a55b8ac08 swtpm-localca: Cleanse variable before running eval on it
Cleanse the tmp variable before running eval on it. This is to prevent
execution of commands that a hidden in variable values read from a config
file. We only need to resolve the values of variables and don't want
the execution of a subshell command initated by either $(...) or `...` .

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Marc-André Lureau
f9cbc39124 swtpm-localca: create directory for keys if needed
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-07 12:19:47 -04:00
Marc-André Lureau
a89f460d49 swtpm-localca: evaluate config variables
This will allow to expand environment variables in config files, such as:
statedir = $XDG_RUNTIME_DIR/swtpm-localca

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

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
a3b68edd6d samples: add support for signing key password
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
aaefebcf96 samples: add support for signing and key encipherment options
To allow the creation of EKs with signing and/or key encipherment
capabilities, add the --allow-signing and --decryption options
to swtpm-localca program.

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

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

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-29 12:16:49 -04:00
Stefan Berger
2fb204666a samples: remove the TPM attribute parameters from the options file
Since swtpm_setup now uses the swtpm_ioctl tool to get some of the
TPM attributes directly from the TPM, we don't need to pass these
options via the options file anymore.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-05 01:09:46 -04:00
Stefan Berger
f6accfb869 sample: propagate and log error if swtpm_cert is missing
If the swtpm_cert was missing, nothing was reported in the error log. Change
this and report it in the error log rather than writing the error in the
certificate file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 11:58:59 -04:00
Stefan Berger
ab37e6f383 samples: implement options for pass TPM spec parameters
Implement options --tpm-spec-family, --tpm-spec-revision, and
tpm-spec-level to pass to swtpm_cert for EK creation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:00:47 -04:00
Stefan Berger
4713f2996a samples: Error out if key exists but is not readable for user
If the key is not readable as the current user, such as tss:tss,
but it is there, we don't try to create it but error out.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-18 14:53:55 -04:00
Stefan Berger
373a90840c samples: Create a root CA that signs the cert used for creating TPM certs
We are currently missing the Authority Key Id in the certificate used for
creating the EK cert. To get this, we create a root CA for our local CA
and use that root CA to sign the local CA's certificate. Our local
CA is now an intermediate CA and the Authority Key Id can now be copied
into the EK cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-17 10:52:35 -04:00
Stefan Berger
8740ec5765 samples: Use the --add-header option for TPM 1.2
Use the --add-header option when writing a cert for a TPM 1.2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-12 13:20:21 -04:00
Stefan Berger
5ceed802cc samples: pass --subject to swtpm_cert since certtool needs a subject
Certtool seems to not verify a certificate chain properly unless
the certificate has a distinguished name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-21 21:14:48 -05:00