1446 Commits
Author SHA1 Message Date
osy 3634bff90f swtpm: support building as shared library v0.8.99 2023-07-06 10:07:25 -07:00
Stefan Berger 2f86ffbac0 swtpm_setup: Close file descriptors passed to swtpm process on parent side
Close the file descriptors passed to the swtpm process on the parent
side for faster detection of errors in the swtpm process that can
occur if swtpm was passed a profile that it cannot run with.

Signed-off-by: Stefan Berger <[email protected]>
2023-07-01 10:26:27 -04:00
Stefan Berger bb2c7ed14e tests: Remove stray \ in front of - after already escaped '\-'
Signed-off-by: Stefan Berger <[email protected]>
2023-06-26 20:50:01 -04:00
Stefan Berger 1fa820468f tests: Fix newly detected shellcheck issues SC2086 by quoting
Shellcheck v0.9 detected more SC2086 issues.

Signed-off-by: Stefan Berger <[email protected]>
2023-06-26 20:50:01 -04:00
Stefan Berger a464c649e2 tests: Disable shellcheck SC2317
Signed-off-by: Stefan Berger <[email protected]>
2023-06-26 20:50:01 -04:00
Stefan Berger 1daa80d239 swtpm_setup: Use medium duration on TSC_PhysicalPresence to avoid timeouts
On busy systems TSC_PhysicalPresence may time out when used with short
duration, so use medium duration instead.

Signed-off-by: Stefan Berger <[email protected]>
2023-06-26 18:36:35 -04:00
Stefan Berger cfeea1b1c0 swtpm_setup: Add poll() after write() and before read() to detect errors
In case swtpm does not start properly the write() to it may work but
then the read() gets stuck. Detect a failed swtpm by adding a poll()
before the read(). Use some extended durations considering possibly
busy systems.

A terminating swtpm instance can be caused when an unacceptable
profile is passed.

Signed-off-by: Stefan Berger <[email protected]>
2023-06-24 16:01:33 -04:00
Stefan Berger 48dffac182 swtpm_ioctl: Repeatedly call PTM_GET_INFO for long responses
Fix the display of long responses that require calling PTM_GET_INFO
multiple times to get parts of the response from increasing offsets
until the whole response has been received.

Long responses are only returned when libtpms has profiles support and
several flags are passed to PTM_GET_INFO.

Signed-off-by: Stefan Berger <[email protected]>
2023-06-23 18:30:01 -04:00
Stefan Berger 9a154fa45f tests: ibmtss2: Add patch to disable x509 test with older libtpms
Older versions of libtpms need to have another patch applied that disables
x509 certificate creation (0013-Disable-x509-test-cases-part2.patch).

Signed-off-by: Stefan Berger <[email protected]>
2023-05-15 14:21:37 -04:00
Stefan Berger 3095011412 tests: Upgrade to ibmtss2 v2.0.1
Signed-off-by: Stefan Berger <[email protected]>
2023-05-11 09:24:54 -04:00
Stefan Berger ee0bce1bdf utils: Implement find_program() to try BINDIR path before PATH
To support install paths that are not covered by $PATH, and still allow
swtpm_setup and swtpm_localca to find swtpm and swtpm_cert executables,
implement find_program() to prepend the install path if only the program
name is given and otherwise fall back to g_find_program_in_path().

Update the man page stating that swtpm from the installation directory
(BINDIR) is tried to be used before one is attempted to be found in
the PATH.

Resolves: https://github.com/stefanberger/swtpm/issues/795
Signed-off-by: Stefan Berger <[email protected]>
2023-04-17 10:55:16 -04:00
Stefan Berger fd2c9fdeab utils: Consolidate compile time configuration variables in swtpm_conf.h
Signed-off-by: Stefan Berger <[email protected]>
2023-04-17 10:55:16 -04:00
ben-dav-lytle 546f2367d6 use PKG_CHECK_MODULES to check libtpms version
Signed-off-by: Ben Lytle <[email protected]>
2023-03-09 16:09:06 -05:00
Stefan Berger 459f4e7dea Travis: Update from focal to jammy and from bionic to focal
Since the tss2 package is commonly available in focal and jammy
move it into to the general list of packages to installed.

libtpm2-pkcs11-tools is available since jammy, so installed it
there to enable the TPM 2 pkcs11 tests.

Signed-off-by: Stefan Berger <[email protected]>
2023-02-27 07:10:10 -05:00
Stefan Berger 5e6e13802d Travis: Update from bionic to focal and from xenial to bionic
Since the package libasan2 does not exist in focal anymore, remove. The
bionic builds do not seem to require this package to be installed (maybe
it's already there), so there's no need to install it in a before_script.

Signed-off-by: Stefan Berger <[email protected]>
2023-02-23 11:13:56 -05:00
Stefan Berger 29ceff5c33 swtpm_localca: Add missing NULL option to end of array
Signed-off-by: Stefan Berger <[email protected]>
2023-02-22 17:27:05 -05:00
Stefan Berger 1cd2dc6049 samples: swtpm-create-tpmca: Fix shellcheck issues and add to syntax-check target
Signed-off-by: Stefan Berger <[email protected]>
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 <[email protected]>
2023-02-22 17:27:05 -05:00
Stefan Berger dbcb69d0ee man8: Update swtpm-create-tpmca with missing TPM 2 reference
Signed-off-by: Stefan Berger <[email protected]>
2023-02-22 17:27:05 -05:00
Stefan Berger 346b3d6265 tests: Fix shellcheck issue SC2148 by adding missing shell directive
Signed-off-by: Stefan Berger <[email protected]>
2023-01-31 10:37:31 -05:00
Stefan Berger c2b54e6ab5 tests: Fix shellcheck issue SC2148 by adding a shell directive
Signed-off-by: Stefan Berger <[email protected]>
2023-01-30 18:25:45 -05:00
Stefan Berger b40fc82700 tests: Fix 2 cases of shellcheck SC2001 using bash search-replace
Signed-off-by: Stefan Berger <[email protected]>
2023-01-30 18:25:45 -05:00
Stefan Berger c8699ccd1b tests: Disable shellcheck SC2010 in two cases
Signed-off-by: Stefan Berger <[email protected]>
2023-01-30 18:25:45 -05:00
Stefan Berger e5ccc7bb37 tests: Fix shellcheck issue SC2115 by using "${var:?}"
Signed-off-by: Stefan Berger <[email protected]>
2023-01-29 15:04:00 -05:00
Stefan Berger 5704342aa8 tests: Fix shellcheck issue SC2181 by if cmd; ...
Signed-off-by: Stefan Berger <[email protected]>
2023-01-27 11:58:54 -05:00
Stefan Berger 4cad2bb32e tests: Fix shellcheck issue SC2143 by using grep -q
Signed-off-by: Stefan Berger <[email protected]>
2023-01-26 08:12:59 -05:00
Stefan Berger 20655646c6 tests: Fix shellcheck issue SC2126 by using 'grep -c'
Signed-off-by: Stefan Berger <[email protected]>
2023-01-14 13:31:53 -05:00
Stefan Berger 5b51dc6a58 tests: Fix issues related to SC2164
Signed-off-by: Stefan Berger <[email protected]>
2023-01-13 21:02:51 -05:00
Stefan Berger fd7a812b24 tests: Fix code to pass shellcheck with some errors disabled
Fix the test cases to pass shellcheck with some of the errors
disable.

Signed-off-by: Stefan Berger <[email protected]>
2023-01-13 13:59:02 -05:00
Michal Privoznik 72d9c031a0 swtpm_setup: Initialized @argv in get_swtpm_capabilities()
The compiler (though wrongly) identifies that the @argv variable
inside of get_swtpm_capabilities() function cam be used
uninitialized. While this is a spurious warning, it's common
practice to initialize g_autofree variables to NULL.

Signed-off-by: Michal Privoznik <[email protected]>
2022-12-21 13:54:38 -05:00
Michal Privoznik a78d02ceec man: Install swtpm_cuse.8 iff WITH_CUSE
Users have option to disable CUSE interface (just pass
--without-cuse argument to the configure script). But the
swtpm_cuse.8 man page is installed regardless of the argument.
This leaves distros having to remove the file before packing
builddir into packages.

Signed-off-by: Michal Privoznik <[email protected]>
2022-12-21 13:54:38 -05:00
Michal Privoznik c6b78f49f5 swtpm: Restore logging to stderr on log open failure
When opening a log file fails (--log file=/some/path) for
whatever reason the @logfd variable is left set to -1 (the retval
of open()). And due to how _logprintf() is written, the
subsequent attempt to log this failure (logprintf()) returns too
early not printing the useful error.

Therefore, restore the original (CONSOLE_LOGGING) value.

Signed-off-by: Michal Privoznik <[email protected]>
2022-12-02 11:08:46 -05:00
Michal Privoznik dcd1b575e6 swtpm.spec: Reflect minimal gnutls version
The configure script requires at least gnutls-3.4.0 but this is
not reflected in the spec file.

Signed-off-by: Michal Privoznik <[email protected]>
2022-11-11 11:58:29 -05:00
Stefan Berger 6709a4ee54 build-sys: Bump up version to 0.9.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <[email protected]>
2022-11-11 11:58:11 -05:00
Stefan Berger 2ae7b01937 debian/rpm: Adjust changelog for 0.8.0 release
Signed-off-by: Stefan Berger <[email protected]>
2022-11-10 12:24:08 -05:00
Stefan Berger 441d8839d2 CHANGES: Add more documentation for changes in 0.8.0
Signed-off-by: Stefan Berger <[email protected]>
2022-11-10 12:24:08 -05:00
Stefan Berger 22e975dc05 tests: Pass --verify-profile=medium to certtool if supported
certtool emits the following message if --verify-profile is not
passed:

Note that no verification profile was selected. In the future the medium profile will be enabled by default.
Use --verify-profile low to apply the default verification of NORMAL priority string.

Pass the --verify-profile option if certtool supports it (since ~3.6.12).

Signed-off-by: Stefan Berger <[email protected]>
2022-11-02 11:14:19 -04:00
Ross Lagerwall a2abd3b67d swtpm_setup: Configure swtpm to log to stdout/err if needed
If swtpm_setup is configured with a log file, it launches swtpm
configured with the same log file. If not, swtpm_setup logs will go to
stdout/stderr and it should configure swtpm to do the same.

Signed-off-by: Ross Lagerwall <[email protected]>
2022-11-01 18:01:47 -04:00
Stefan Berger 66117eefa8 Update bug_report.md
Make exact steps to recreate the issue a requirement for the bug report.

Signed-off-by: Stefan Berger <[email protected]>
2022-10-10 07:53:26 -04:00
Stefan Berger 87ce53ffc4 swtpm: Add another exit label to avoid gcc -fanalyzer false positive
Move existing exit label before the return statement and add another
label that includes the free(filebuffer). This avoids a false positive
by 'gcc -fanalyzer' that seems to think that free(filebuffer)
would double-free filebuffer after filebuffer = realloc(tmp, ..)
failure.

Signed-off-by: Stefan Berger <[email protected]>
2022-10-05 07:37:14 -04:00
Stefan Berger 7d79ecd694 swtpm: Return TPM_FAIL if SWTPM_NVRAM_DecrytpData is called without key
Return TPM_FAIL if SWTPM_NVRAM_DecryptData() is called without a key or
if an unhandle type of encryption mode is encountered. Previously this
function would return no error but also would not do any decryption if
no key was provided. Consequently, it would then also not return a byte
array with decrypted data which in turn could led to potential NULL
pointer accesses in subsequent calls. However, all current callers check
whether they have a valid key before they call this function. So the
change is primarily done for static analyzers, such as gcc -fanalyzer,
to ease code analysis.

Signed-off-by: Stefan Berger <[email protected]>
2022-09-30 13:12:06 -04:00
Stefan Berger c94a1c4cbd swtpm: Fix memory leak in case realloc fails
Signed-off-by: Stefan Berger <[email protected]>
2022-09-30 11:06:13 -04:00
Stefan Berger 8cbb6dae18 CHANGES: Add documentation for changes in 0.8.0
Signed-off-by: Stefan Berger <[email protected]>
2022-09-29 07:36:32 -04:00
Stefan Berger aa92bbf615 tests: Replicate test_ctrlchannel3 for TPM 2 to test_tpm2_ctrlchannel3
Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 13:27:38 -04:00
Stefan Berger 9c5bb4ac73 tests: Test automatic termination upon loss of ctrl channel connection
Extend the test_ctrlchannel3 to test for automatic termination of swtpm
upon loss of control channel connection.

Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 13:27:38 -04:00
Stefan Berger 1f36b7fec4 tests: Use SOCK_STREAM for CMD_SET_DATAFD socketpair
Switch to SOCK_STREAM for the CMD_SET_DATAFD socketpair where the one
end is passed to swtpm to test that this type of socket will cause
automatic termination of swtpm when the connection is lost. This is also
the socket type that QEMU uses.

Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 13:27:38 -04:00
Stefan Berger d5296e19e7 swtpm: Extend capabilities JSON and show ctrl-opt-terminate
Extend the capabilities JSON and show the support for the terminate
parameter of the --ctrl option.

Adjust test cases.

Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 13:27:38 -04:00
Stefan Berger 6ecf5880ed swtpm: Implement terminate parameter for ctrl channel loss
Implement support for the terminate parameter for the control channel
option so that swtpm terminates once the control channel connection is
lost. The primary use case is QEMU that holds the control channel
permanently.

Resolves: https://github.com/stefanberger/swtpm/issues/753
Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 13:27:38 -04:00
Stefan Berger 185832c8d4 swtpm: Set tpm_running = false after TPMLIB_Terminate() on CMD_SHUTDOWN
Set tpm_running = false after TPMLIB_Terminate() call on CMD_SHUTDOWN
to prevent a call to tpmlib_maybe_send_tpm2_shutdown() at the exit
of the mainloop.

Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 09:52:10 -04:00
Stefan Berger aa2ed3e460 swtpm: Also send TPM2_Shutdown when swtpm terminates by signal
Also send TPM2_Shutdown when swtpm is terminated by a signal or due to
lost connection (--terminate option). Previously supported reasons for
sending the TPM2_Shutdown were primarily related to commands sent via
the command channel.

Signed-off-by: Stefan Berger <[email protected]>
2022-09-22 09:52:10 -04:00