Commit Graph

1439 Commits

Author SHA1 Message Date
Stefan Berger
15b9ca6bc3 tests: Support filenames with spaces in some functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-05 06:39:49 -04:00
Stefan Berger
8422d06868 swtpm_setup: Create flags by shifting '1'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-05 06:39:49 -04:00
Stefan Berger
cce7503cbf tests: exit with error code if mktemp fails
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-02 08:35:49 -04:00
Stefan Berger
b08876722a swtpm_localca: Replace '+' and ',' characters in VMId's
Certain characters are not accepted by gnutls when creating the
subject with the 'CN' from the vmid, so we have to replace those
characters with another one, such as '_'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-01 10:27:10 -04: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
a5cc0bf6e2 swtpm_setup: Get active PCR banks from swtpm_setup.conf
If the user did not provide the PCR banks to activate through the command
line options, try to read it from the config file and if nothing is found
there, fall back to the DEFAULT_PCR_BANKS as set during configure time.

Move the check for the PCR banks after the access check to the
configuration file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:36:35 -04:00
Stefan Berger
87755f8cc4 swtpm_setup: Move code to activate PCR banks into own function
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:36:35 -04:00
Stefan Berger
df4046d0e4 build-sys: Add support for --enable-default-pcr-banks=list of PCR banks
Add an option that allows for the configuration of the default PCR bank
to use. This was currently hard coded to sha256 and now may be passed
via this option. The fallback is still sha256. Valid PCR bank names are
sha1, sha256, sha384, and sha512. The passed list must be a comma-
separated list of the valid PCR bank names.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:36:35 -04:00
Stefan Berger
4641f19f21 man: Add version when feature was added when missing fix some others
Add the version to items indicating when the feature was added.
Fix and unify some other ones.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:16:15 -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
d766b58d17 swtpm_setup: Add missing sys/wait.h include (BSDs)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 20:13:39 -04:00
Stefan Berger
343a038b58 swtpm: Add missing signal.h include (BSDs)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 20:13:39 -04:00
Stefan Berger
743b4d1b61 tests: Convert 2 test cases to use --daemon option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 18:58:25 -04:00
Stefan Berger
122106b8f2 tests: Add test case for chardev for swtpm --print-states option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 18:58:25 -04:00
Nicolas Williams
98d1d126cd swtpm: Make --daemon not racy
Signed-off-by: Nicolas Williams <nico@cryptonector.com>
2021-10-27 16:51:35 -04:00
Stefan Berger
26cdfc77df swtpm_setup: Only activate SHA256 PCR bank, not SHA1 bank anymore
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-22 07:39:55 -04:00
Stefan Berger
db61aeddeb man: Improve the documentation of swtpm_setup's --create-config-files
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-19 10:42:46 -04:00
Stefan Berger
c40fceb3ca swtpm_setup: Report stderr as returned by external tool (swtpm-localcal)
Report the error printed out via stderr as returned by swtpm-localca for
example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-19 08:37:58 -04:00
Stefan Berger
4c178928dc rpm: Update spec file to also work on CentOS9-stream
CentOS9 has no more trousers, so disable it for rhel >= 9.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-18 13:47:13 -04:00
Stefan Berger
6b2cb5ff5a test: Add missing _test_tpm2_file_permissions file to EXTRA_DIST
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-18 10:39:27 -04:00
Stefan Berger
9e21a3fec2 rpm/debian: Clean up packaging files
- Remove unused python3-twisted and gmp-devel.
- Add back rule to package /man8/swtpm_localca.8*

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-18 10:39:27 -04:00
Stefan Berger
c6f50af25f rpm: Remove man8/swtpm_localca.8 from specfile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-18 08:41:13 -04:00
Stefan Berger
4b5654a19f swtpm: Disable fsync on file & dir due to TPM timeouts (issue #597)
We cannot currently fsync on the TPM's state file and the dir since this
takes too long and commands in a VM may time out. The reason for this is
that the TPM 2 code occasionally writes the permanent state out even on
commands like TPM2_PCR_Extend that must not take a long time.

See explanation for this in the libtpms PR https://github.com/stefanberger/libtpms/pull/274 .

We will re-enable this feature in 'a while' once the updated libtpms
version has been made more widely available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-17 16:32:38 -04:00
Stefan Berger
8def57facd swtpm_setup: Initialize variables to avoid compiler warnings
Fix issue #591 by initializing the variables swtpm_has_tpm2 and
swtpm_has_tpm12.

swtpm_setup.c:1178:31: note: 'swtpm_has_tpm2' was declared here
     gboolean swtpm_has_tpm12, swtpm_has_tpm2;
                               ^~~~~~~~~~~~~~
swtpm_setup.c:1019:5: error: 'swtpm_has_tpm12' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     printf("{ \"type\": \"swtpm_setup\", "
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            "\"features\": [ %s%s\"cmdarg-keyfile-fd\", \"cmdarg-pwdfile-fd\", \"tpm12-not-need-root\""

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-15 08:44:14 -04:00
Stefan Berger
57b1f7ef88 swtpm: Fix case when no backend URI has been specified
It is possible to start swtpm with this command line even though
neither storage nor communication channels have been provided.

./src/swtpm/swtpm socket --flags not-need-init,startup-clear

Since sending a startup message to the TPM will cause it to
want to store permanent state, we have to handle the case when
no storage backend was given and therefore the backend_uri
is NULL.

Previously the above command line caused a NULL pointer exception
but now handles this case with the following output:

swtpm: SWTPM_NVRAM_Init: Missing backend URI.
swtpm: Error: Could not initialize libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-12 07:34:10 -04:00
Stefan Berger
0151ec3a52 swtpm: Fix a forgotten endianess-conversion
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-11 17:50:52 -04:00
Stefan Berger
e68cebaf5f swtpm_localca: Created certificates for CAs and TPM that do not expire
Rather than having the CA certificates, that are created on the fly,
expire in 10 years, have them not expire at all.

Also create TPM certificates that don't expire and extend a test
case for this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-08 14:07:02 -04:00
Stefan Berger
9f5342fc68 swtpm_cert: Allow passing -1 for days to get a non-expiring certificate
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-08 14:07:02 -04:00
Stefan Berger
634e6705c3 swtpm_setup: Exit with error code 1 on unknown option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-08 11:20:59 -04:00
Stefan Berger
79e4c44c04 swtpm_localca: Exit with error code 1 on unknown option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-08 11:20:59 -04:00
Stefan Berger
f1d425b5c1 swtpm_localca: Use g_get_user_config_dir() rather than own code
Replace own code with g_get_user_config_dir() which makes things
a lot simpler.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 19:50:24 -04:00
Stefan Berger
874c333802 swtpm_setup: Use g_get_user_config_dir() rather than own code
Replace own code with g_get_user_config_dir() which makes things
a lot simpler.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 19:50:24 -04:00
Stefan Berger
bcd5523b08 tests: Add a test case for the new swtpm_setup option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 14:27:10 -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
Stefan Berger
a7254fab5e swtpm_setup: Implement --create-user-config skip-if-exist
Implement support for skipping over creating the files
if any one of the config files already exist.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 14:27:10 -04:00
Stefan Berger
2b60723766 swtpm_setup: Implement option --create-config-files to create config files
Implement the option --create-config-files to create config files
for swtpm_setup and swtpm-localca for a user account. The files will
be created under the $XDG_CONFIG_HOME or $HOME/.config directories.

This option supports optional arguments 'overwrite' to allow overwriting
existing config files as well as the optional argument 'root' to create
config files under root's home directory. Both options can be passed
by separating them with a ','.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 14:27:10 -04:00
Stefan Berger
50670dca12 swtpm: Move ARRAY_LEN and min #define's to swtpm_utils.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-07 14:27:10 -04:00
Thomas Lamprecht
f2786a759f d/swtpm-tools postinst: create the TSS user if it does not exist
Adapted from tpm-udev [0] which handles that, but it is not really a
hard-requirement for swtpm and TSS_USER is configurable after all
(even if that is mostly used for the test system).

So, create that user and group if it does not exists to avoid errors
and failing installation.

[0]: https://salsa.debian.org/debian/tpm-udev/-/blob/master/debian/tpm-udev.postinst

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-07 12:47:08 -04:00
Thomas Lamprecht
7d0f8e1c81 d/swtpm-tools postinst: avoid trying to create/chown in non-configure steps
configure steps should be limited to get only executed on, well
configuration, so check for that and do nothing in the remaining
commands [0] the postinst can be called with.

[0]: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html#summary-of-ways-maintainer-scripts-are-called

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-07 12:47:08 -04:00
Thomas Lamprecht
088a8ca44b debian: downgrade trousers package dependency to recommended
Currently `trousers` is listed as (hard) Dependency, but it does not
seems to be required for quite a few usecases, e.g., ours where we
mainly using swtpm for providing a tpm to VMs.

With trousers in Debian one gets an additional pain point: it comes
with rather dated and in some cirumstances failing by mistake init
script [0] that can throw errors when setting up during installation
and thus fail the whole installation of swtpm as Debian policy for
`Depends` hits:

> A package will not be configured unless all of the packages listed
> in its Depends field have been correctly configured
-- [1]

Declaring dependencies for things are not a hard requirement means
that a user will be required to install more dependencies than
actually needed.

Just documenting that as fact why I investigated in the
hard-requirement on trousers in the first place, not an actual
justification - it's a packaging bug after all.

So downgrade the dependency to "Suggests", as it seems a reasonable
level when checking its documented meaning:

> This is used to declare that one package may be more useful with
> one or more others. Using this field tells the packaging system and
> the user that the listed packages are related to this one and can
> perhaps enhance its usefulness, but that installing this one without
> them is perfectly reasonable.
-- [1]

[0]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=895201
[1]: https://www.debian.org/doc/debian-policy/ch-relationships.html

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-07 09:38:43 -04:00
Stefan Berger
225d7009ba man: Enumerate the nvram-backend-dir separately
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-06 19:25:41 -04:00
Stefan Berger
e6cbc55df6 swtpm: Display the --print-states capability and document it
Display the --print-states capability in the --print-capabilites
output as cmdarg-print-states.

Document availability in the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-06 19:25:41 -04:00
Stefan Berger
2e3745db08 swtpm_setup: Move gmalloc after block that may return NULL on failure
To avoid a memory leak, move the gmalloc after a block that may
return NULL on failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 18:07:20 -04:00
Stefan Berger
b63a3e4b2e swtpm_setup: Introduce label to skip over closing of pidfile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 18:07:20 -04:00
Stefan Berger
680ad059aa swtpm: Call msync with length = 0 on Cygwin
Cygwin internally uses the Windows API call FlushViewOfFile that
seems to not like to be called with an excessive number of bytes.
Instead, call it with length = 0 so that 'the file is flushed from
the base address to the end of the mapping' and then msync() succeeds.

Source:
https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-flushviewoffile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 15:22:14 -04:00
Stefan Berger
57a8a914c7 swtpm_setup: Use SWTPM_ATTR_UNUSED on unused parameters (BSDs)
To silence the BSD gcc compiler on unused function parameters,
use SWTPM_ATTR_UNUSED.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 13:50:45 -04:00
Stefan Berger
ca3379116b swtpm_setup: Use pidfile filename rather than fd (Cygwni, BSDs)
Use the pidfile filename rather than the fd because Cygwin for example
does not seem to support passed file descriptors and also OpenBSD
does not pass some test cases because of this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 13:50:45 -04:00
Stefan Berger
0bee3d2f5e tests: Use /usr/bin/env bash rather than /bin/bash (BSDs)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 13:50:45 -04:00
Stefan Berger
4a5acef4d7 headers: Add defines for little endian data conversion (OS X)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 13:50:45 -04:00
Stefan Berger
0b5826e186 swtpm: Use compiler and system dependent header files
The header file endian.h does not exists everywhere, so we have to
use system_dependencies.h to get something similar on all systems.

Some compilers, such as gcc on FreeBSD, are picky about unused
function parameters, so we have to decorate the unused ones
with SWTPM_ATTR_UNUSED.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 13:50:45 -04:00