]> git.proxmox.com Git - swtpm.git/log
swtpm.git
11 months agopackaging: track dbgsym package for swtpm-libs and swtpm-tools proxmox/stable-0.8
Thomas Lamprecht [Thu, 25 May 2023 15:00:01 +0000 (17:00 +0200)]
packaging: track dbgsym package for swtpm-libs and swtpm-tools

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 months agobump version to 0.8.0+pve1
Thomas Lamprecht [Thu, 25 May 2023 14:26:45 +0000 (16:26 +0200)]
bump version to 0.8.0+pve1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 months agod/control: Proxmox maintains this package for Proxmox projects
Thomas Lamprecht [Thu, 25 May 2023 14:26:39 +0000 (16:26 +0200)]
d/control: Proxmox maintains this package for Proxmox projects

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 months agotests: skip ctrlchannel and ctrlchannel2 in sbuild
Thomas Lamprecht [Thu, 25 May 2023 14:25:27 +0000 (16:25 +0200)]
tests: skip ctrlchannel and ctrlchannel2 in sbuild

fails with some odd "still running error", but only if the unshare
mode is used.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 months agoadd packaging make file
Thomas Lamprecht [Thu, 25 May 2023 13:34:19 +0000 (15:34 +0200)]
add packaging make file

(mis)using the fact that GNU make uses the following Makefile order
GNUmakefile, makefile and Makefile.
https://www.gnu.org/software/make/manual/make.html#Makefile-Names

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
14 months agobump version to 0.8.0~bpo11+3
Thomas Lamprecht [Thu, 23 Feb 2023 11:52:25 +0000 (12:52 +0100)]
bump version to 0.8.0~bpo11+3

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
14 months agocontrol channel: add error logs upon receiving short input
Fiona Ebner [Wed, 18 Jan 2023 12:21:07 +0000 (13:21 +0100)]
control channel: add error logs upon receiving short input

There was a recent failure when migrating a production VM
> kvm: tpm-emulator: Setting the stateblob (type 1) failed with a TPM error 0x3 a parameter is bad
> kvm: error while loading state for instance 0x0 of device 'tpm-emulator'
> kvm: load of migration failed: Input/output error
and it's not clear what exactly triggered it. Note that 0x3 is
TPM_BAD_PARAMETER.

The timeout check when receiving the command+body is a good candidate,
but since poll() is called with the remaining timeout, it seems hard
to trigger. In both cases with short input, QEMU would've not managed
to even send the full header (16 bytes for CMD_SET_STATEBLOB).

Another possibility is that the blob header got corrupted and the
TPM_BAD_PARAMETER error orignated from the SWTPM_NVRAM_SetStateBlob()
call. The checks there already have logging.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
17 months agobump version to 0.8.0~bpo11+2
Thomas Lamprecht [Fri, 11 Nov 2022 14:28:08 +0000 (15:28 +0100)]
bump version to 0.8.0~bpo11+2

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agoapparmor profile: adapt state file locations PVE supports
Thomas Lamprecht [Fri, 11 Nov 2022 14:25:11 +0000 (15:25 +0100)]
apparmor profile: adapt state file locations PVE supports

we can have them as standard file (*most* of the time that would be
in /var/lib/vz or /mnt/pve/**), as LV/RBD in /dev or as zfs volume
anywhere, so basically we need to cut the profile in scope a lot and
allow write access in any place of the FS hierarchy for now (we plan
to have a mount namspace where we bind mount VM disk/state into in
the long term).

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agobump version to 0.8.0~bpo11+1
Thomas Lamprecht [Fri, 11 Nov 2022 11:37:00 +0000 (12:37 +0100)]
bump version to 0.8.0~bpo11+1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agodebian/rpm: Adjust changelog for 0.8.0 release v0.8.0
Stefan Berger [Thu, 10 Nov 2022 16:39:39 +0000 (11:39 -0500)]
debian/rpm: Adjust changelog for 0.8.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
17 months agoCHANGES: Add more documentation for changes in 0.8.0
Stefan Berger [Thu, 10 Nov 2022 16:43:57 +0000 (11:43 -0500)]
CHANGES: Add more documentation for changes in 0.8.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
17 months agotests: Pass --verify-profile=medium to certtool if supported
Stefan Berger [Wed, 2 Nov 2022 14:21:52 +0000 (10:21 -0400)]
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 <stefanb@linux.ibm.com>
17 months agoswtpm_setup: Configure swtpm to log to stdout/err if needed
Ross Lagerwall [Thu, 27 Oct 2022 15:30:11 +0000 (16:30 +0100)]
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 <ross.lagerwall@citrix.com>
18 months agoUpdate bug_report.md
Stefan Berger [Mon, 10 Oct 2022 11:53:26 +0000 (07:53 -0400)]
Update bug_report.md

Make exact steps to recreate the issue a requirement for the bug report.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
18 months agoswtpm: Add another exit label to avoid gcc -fanalyzer false positive
Stefan Berger [Wed, 5 Oct 2022 00:22:34 +0000 (20:22 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Return TPM_FAIL if SWTPM_NVRAM_DecrytpData is called without key
Stefan Berger [Fri, 30 Sep 2022 16:17:00 +0000 (12:17 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Fix memory leak in case realloc fails
Stefan Berger [Fri, 30 Sep 2022 14:13:05 +0000 (10:13 -0400)]
swtpm: Fix memory leak in case realloc fails

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agoCHANGES: Add documentation for changes in 0.8.0
Stefan Berger [Mon, 26 Sep 2022 19:48:35 +0000 (15:48 -0400)]
CHANGES: Add documentation for changes in 0.8.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agotests: Replicate test_ctrlchannel3 for TPM 2 to test_tpm2_ctrlchannel3
Stefan Berger [Thu, 22 Sep 2022 15:33:58 +0000 (11:33 -0400)]
tests: Replicate test_ctrlchannel3 for TPM 2 to test_tpm2_ctrlchannel3

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agotests: Test automatic termination upon loss of ctrl channel connection
Stefan Berger [Thu, 22 Sep 2022 15:01:26 +0000 (11:01 -0400)]
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 <stefanb@linux.ibm.com>
19 months agotests: Use SOCK_STREAM for CMD_SET_DATAFD socketpair
Stefan Berger [Thu, 22 Sep 2022 14:28:21 +0000 (10:28 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Extend capabilities JSON and show ctrl-opt-terminate
Stefan Berger [Thu, 22 Sep 2022 13:35:59 +0000 (09:35 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Implement terminate parameter for ctrl channel loss
Stefan Berger [Thu, 22 Sep 2022 12:47:49 +0000 (08:47 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Set tpm_running = false after TPMLIB_Terminate() on CMD_SHUTDOWN
Stefan Berger [Thu, 22 Sep 2022 12:17:15 +0000 (08:17 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Also send TPM2_Shutdown when swtpm terminates by signal
Stefan Berger [Thu, 22 Sep 2022 00:11:12 +0000 (20:11 -0400)]
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 <stefanb@linux.ibm.com>
19 months agoswtpm: Add missing '%' to %08x
Stefan Berger [Thu, 22 Sep 2022 00:09:33 +0000 (20:09 -0400)]
swtpm: Add missing '%' to %08x

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agoswtpm,man: Clarify that --terminate works only for TCP data channel
Stefan Berger [Wed, 21 Sep 2022 19:39:31 +0000 (15:39 -0400)]
swtpm,man: Clarify that --terminate works only for TCP data channel

The --terminate option is only for the TCP data channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agoswtpm: Do 300 locking retries instead of only 100
Stefan Berger [Thu, 15 Sep 2022 16:36:32 +0000 (12:36 -0400)]
swtpm: Do 300 locking retries instead of only 100

Increase the number of locking retries to 300 over 3 seconds
instead of 100 over 1 second. This gives the failing side more
time to release the lock.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agodebian: Do not remove swtpm_cuse.8 via clean file
Stefan Berger [Mon, 19 Sep 2022 12:47:39 +0000 (08:47 -0400)]
debian: Do not remove swtpm_cuse.8 via clean file

swtpm_cuse.8 is not generated anymore but its a static file now
that must not be removed anymore via the debian/clean file.

Resolves: https://github.com/stefanberger/swtpm/issues/751
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agotests: Add test case for state migration and storage locking
Stefan Berger [Thu, 11 Aug 2022 15:56:26 +0000 (11:56 -0400)]
tests: Add test case for state migration and storage locking

Add a test case that monitors the locking of the storage by swtpm using the
directory storage backend to ensure that the lock is taken at the right
time and released when required.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agoswtpm: Implement CMD_LOCK_STORAGE to lock storage
Stefan Berger [Tue, 23 Aug 2022 20:07:24 +0000 (16:07 -0400)]
swtpm: Implement CMD_LOCK_STORAGE to lock storage

Implement CMD_LOCK_STORAGE / PTM_LOCK_STORAGE for a user to be able to
lock the storage of the storage backend (if supported) after its lock
has been released for example when the 'savestate' blob was received
while the TPM state was migrated.

Also adjust test case and extend man pages.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agoswtpm: Advertise --migration option in capabilities JSON
Stefan Berger [Wed, 10 Aug 2022 21:41:25 +0000 (17:41 -0400)]
swtpm: Advertise --migration option in capabilities JSON

Advertise the capability of supporting the --migration option
in the capabilies JSON that now has the cmdarg-migration verb:

$ swtpm socket --print-capabilities | jq
{
  "type": "swtpm",
  "features": [
    "tpm-1.2",
    "tpm-2.0",
    "tpm-send-command-header",
    "flags-opt-startup",
    "flags-opt-disable-auto-shutdown",
    "cmdarg-seccomp",
    "cmdarg-key-fd",
    "cmdarg-pwd-fd",
    "cmdarg-print-states",
    "cmdarg-migration",
    "nvram-backend-dir",
    "nvram-backend-file"
  ],
  "version": "0.8.0"
}

Adjust test cases and extend man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
19 months agoswtpm: Implement release-lock-outgoing parameter for --migration option
Stefan Berger [Wed, 10 Aug 2022 20:25:36 +0000 (16:25 -0400)]
swtpm: Implement release-lock-outgoing parameter for --migration option

Implement the release-lock-outgoing parameter for the --migration option
that causes the storage lock to be released once the 'savestate' blob
transfer has been initiated. To not release the lock too early users must
first get the 'permanent' and 'volatile' state blobs and the 'savestate'
blob must be transferred as the last blob.

When migrating a VM the migration may fail and execution will then resume
on the originating side. In this fallback case the swtpm on the
destination side may need some time to terminate and release the lock.
Therefore, add a loop to the code attempting to re-lock the storage
directory on the source side for a few times until on the destination
side swtpm has released the lock. Retry the locking for 100 times
with 10ms in between. The retries will only ever be necessary if a TPM
command is immediately executed upon resume [this may be difficult
to test]. The negative side effects of this could be that the loop is not
long enough to grab the lock or that a short-duration TPM command will
time out inside the VM due to the retries delaying when it is processed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/724

19 months agoswtpm: Introduce --migration option and 'incoming' parameter
Stefan Berger [Wed, 10 Aug 2022 19:30:15 +0000 (15:30 -0400)]
swtpm: Introduce --migration option and 'incoming' parameter

Introduce the --migration option along with the 'incoming' parameter
that allows to defer the locking of the storage until either

- the reception of the TPM's state is started
- a TPM command is about to be processed

Note that the reception of CMD_INIT does not enable the storage lock.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/724

19 months agoswtpm: Move locking of storage into tpmlib_start()
Stefan Berger [Wed, 10 Aug 2022 16:17:37 +0000 (12:17 -0400)]
swtpm: Move locking of storage into tpmlib_start()

Move the locking of the storage into tpmlib_start() after the call to
TPMLIB_MainInit() which was previously doing the locking when the prepare
function was called in the SWTPM_NVRAM_Init() callback invoked by
TPMLIB_MainInit().

This allows for conditional locking in tpmlib_start() using a flag later
on.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoheaders: Apply #ifndef's for _WIN32 from QEMU project
Stefan Berger [Thu, 1 Sep 2022 14:54:19 +0000 (10:54 -0400)]
headers: Apply #ifndef's for _WIN32 from QEMU project

Apply recent changes to this file from upstream QEMU project using
a few #ifndef _WIN32 to make code compileable on Windows.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agotests: Check for fallocate tool and its support for --posix
Stefan Berger [Fri, 26 Aug 2022 17:22:04 +0000 (13:22 -0400)]
tests: Check for fallocate tool and its support for --posix

Older versions of fallocate do not support the --posix option that the test
needs. If --posix is not supported, skip the test.

Also check for availability of the losetup tool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoheaders: Synchronize with header in QEMU project
Stefan Berger [Fri, 26 Aug 2022 11:42:56 +0000 (07:42 -0400)]
headers: Synchronize with header in QEMU project

QEMU has made a change to a copy of this header file with the following
reason:

On Solaris and Haiku, the _IO() macros are defined in <sys/ioccom.h>.
Add a proper check for this header to our build system, and make sure
to include the header in tpm_ioctl.h to fix a build failure on Solaris
and Haiku.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Implement stub for fips_mode_enabled (OpenBSD)
Stefan Berger [Thu, 25 Aug 2022 20:00:10 +0000 (16:00 -0400)]
swtpm: Implement stub for fips_mode_enabled (OpenBSD)

On OpenBSD openssl/fips.h is not available and FIPS_mode() is not
available, so implement a stub for fips_mode_enabled().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Advertise the --chroot option with cmdarg-chroot
Stefan Berger [Thu, 25 Aug 2022 16:06:04 +0000 (12:06 -0400)]
swtpm: Advertise the --chroot option with cmdarg-chroot

Advertise the availability of the chroot option with the cmdarg-chroot
verb. Document it in the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agotests: If filesystem is mounted with nodev opt skip CUSE chroot test
Stefan Berger [Thu, 25 Aug 2022 15:58:06 +0000 (11:58 -0400)]
tests: If filesystem is mounted with nodev opt skip CUSE chroot test

The CUSE TPM test will not work if the filesystem the test case runs
on is mounted with the 'nodev' option since the CUSE TPM can then
not use /tmp/.../dev/cuse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Add a chroot option
Jennifer Herbert [Tue, 23 Aug 2022 16:08:10 +0000 (17:08 +0100)]
swtpm: Add a chroot option

Add an option to enter a chroot after starting swtpm. This is useful for
sandboxing purposes. When this option is used, it is expected that swtpm
is started as root and the --runas option is used to subsequently drop
privileges (otherwise the chroot could be escaped).

Signed-off-by: Jennifer Herbert <jennifer.herbert@citrix.com>
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
20 months agoswtpm_setup: Add missing description for --vmid to help screen
Stefan Berger [Wed, 24 Aug 2022 13:17:24 +0000 (09:17 -0400)]
swtpm_setup: Add missing description for --vmid to help screen

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Check for defined __SNR_MOUNT_setattr and __NR_mount_setattr
Stefan Berger [Mon, 22 Aug 2022 18:11:47 +0000 (14:11 -0400)]
swtpm: Check for defined __SNR_MOUNT_setattr and __NR_mount_setattr

Address the following compilation error on Debian:

In file included from /usr/include/seccomp.h:821,
                 from seccomp_profile.c:44:
seccomp_profile.c: In function 'create_seccomp_profile':
seccomp_profile.c:115:9: error: '__NR_mount_setattr' undeclared (first use in this function)
  115 |         SCMP_SYS(mount_setattr),
      |         ^~~~~~~~
seccomp_profile.c:115:9: note: each undeclared identifier is reported only once for each function it appears in
seccomp_profile.c:172:9: error: '__NR_quotactl_fd' undeclared (first use in this function)
  172 |         SCMP_SYS(quotactl_fd),
      |         ^~~~~~~~

We need to do this since they are defined like this:

 #define __SNR_mount_setattr             __NR_mount_setattr
 #define __SNR_quotactl_fd               __NR_quotactl_fd

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Include opensslv.h to get OPENSSL_VERSION_NUMBER
Stefan Berger [Mon, 22 Aug 2022 17:59:34 +0000 (13:59 -0400)]
swtpm: Include opensslv.h to get OPENSSL_VERSION_NUMBER

Include openssl/opensslv.h to avoid the following error on Ubuntu:

fips.c: In function 'fips_mode_enabled':
fips.c:61:16: error: implicit declaration of function 'EVP_default_properties_is_fips_enabled' [-Werror=implicit-function-declaration]
   61 |     int mode = EVP_default_properties_is_fips_enabled(NULL);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Resolves: https://github.com/stefanberger/libtpms/issues/345
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Refactor existing function to use new tpmlib_get_cmd_ordinal()
Stefan Berger [Mon, 30 May 2022 14:47:12 +0000 (10:47 -0400)]
swtpm: Refactor existing function to use new tpmlib_get_cmd_ordinal()

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agotests: Add test case to check that swtpm sends a TPM2_Shutdown
Stefan Berger [Wed, 1 Jun 2022 12:44:00 +0000 (08:44 -0400)]
tests: Add test case to check that swtpm sends a TPM2_Shutdown

Add a test case that checks that swtpm sends a TPM2_Shutdown() to the
TPM 2 upon abrupt re-initialization (CMD_INIT) or graceful shutdown
(control channel, CMD_SHUTDOWN) of the TPM 2 and avoids a potential
dictionary attack (DA) lock-out. A previously sent command failing
authorization with DA implications would otherwise trigger the
TPM_PT_LOCKOUT_COUNTER to increase by '1' if the TPM 2 was not properly
shut down by the client (guest OS) with a TPM2_Shutdown() command.

The test case tests whether a TPM2_Shutdown() is now sent before a reset.
The defined password-protected NVRAM area has the DA flag set and the test
case tries to read from it without providing a password. If we didn't send
the TPM2_Shutdown() before the test cases sends the reset (CMD_INIT), then
the dictionary attack lockout counter would be increased by one. With the
instrumentation in the previous patch the automatically sent
TPM2_Shutdown() keeps the counter at 0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Introduce disable-auto-shutdown flag for --flags option
Stefan Berger [Wed, 17 Aug 2022 18:19:59 +0000 (14:19 -0400)]
swtpm: Introduce disable-auto-shutdown flag for --flags option

Introduce disable-auto-shutdown flag for the --flags option to disable
the sending of TPM2_Shutdown() if swtpm determines that it needs to send
this command to a TPM 2 before device reset or swtpm program termination.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: If necessary send TPM2_Shutdown() before TPMLIB_Terminate()
Stefan Berger [Mon, 30 May 2022 15:10:14 +0000 (11:10 -0400)]
swtpm: If necessary send TPM2_Shutdown() before TPMLIB_Terminate()

If necessary send a TPM2_Shutdown() command to libtpms before processing
CMD_INIT. However, this is only necessary for a TPM 2 and only if the
TPM2_Shutdown command has not been sent by the client (VM TPM driver) as
the last command as it should do under normal circumstances, for example
upon graceful VM shutdown.

This fixes a bug where abrupt VM resets may trigger the TPM 2's dictionary
attack lockout logic due to the TPM 2 not having received a TPM2_Shutdown
command before it was reset using CMD_INIT for example. An OS driver is
typically supposed to send a TPM2_Shutdown to the TPM 2 but an abrupt VM
reset prevents it.

There are 3 control commands where this needs to be done since they
call TPMLIB_Terminate():

- CMD_STOP:
   This command is typically called before setting the state blobs of the
   TPM or before configuring the buffer size [QEMU, test cases].

- CMD_INIT:
   This command is called for resetting and initializing the TPM 2.

- CMD_SHUTDOWN:
   This command is called for a graceful shutdown of the TPM 2.

There are no negative side effects to be expected if TPM2_Shutdown()
is sent before any of these. Also, since none of these are sent before
the state of the TPM is marshalled (for migration for example) migrated
state will not have a TPM2_Shutdown() applied to it (accidentally).

Edk2 sends a sequence of TPM2_Shutdown(SU_STATE) + TPM2_GetRandom()
before suspend-to-ram. Upon wake up a CMD_INIT is sent to the TPM to
reset it, which in this case now requires a TPM2_Shutdown(SU_STATE)
to be sent to the TPM 2 so that certain TPM 2 state is available
again upon resume. To avoid invaliding the SU_STATE, first send a
TPM2_Shutdown(SU_STATE) in *all cases* and only if this fails send a
TPM2_Shutdown(SU_CLEAR). This way the internal state is preserved and
the VM (or user) are expected to use TPM2_Startup(SU_CLEAR) when
staring up the TPM 2 and no previous state needs to be resumed.

Note: The VM's firmware is trusted to use SU_CLEAR under normal circum-
stances and SU_STATE upon resume. So it wouldn't restore the state if
it wasn't needed.

Note: The TPM 2 spec describes the command as follows:

"This command is used to prepare the TPM for a power cycle. The
shutdownType parameter indicates how the subsequent TPM2_Startup() will be
processed.[...]
This command saves TPM state but does not change the state other than the
internal indication that the context has been saved. The TPM shall
continue to accept commands. If a subsequent command changes TPM state
saved by this command, then the effect of this command is nullified. The
TPM MAY nullify this command for any subsequent command rather than check
whether the command changed state saved by this command. If this command
is nullified and if no TPM2_Shutdown() occurs before the next
TPM2_Startup(), then the next TPM2_Startup() shall be
TPM2_Startup(CLEAR)."

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2087538
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Track last command processed by the TPM
Stefan Berger [Mon, 30 May 2022 14:40:01 +0000 (10:40 -0400)]
swtpm: Track last command processed by the TPM

Track the last command processed by the TPM so we can determine whether
we may need to send a TPM2_Shutdown() before reset of the TPM 2.

Introduce a variable lastCommand to help track the last command that
was sent to the TPM 2.

In relation to deciding whether a TPM2_Shutdown() needs to be sent, the
tracking of the last-sent command is merely an optimization since for
example a VM with EDK2 will send a TPM2_Shutdown() followed by a
TPM2_GetRandom() upon suspend-to-ram, thus indicating that the last
command was TPM2_GetRandom(). However, under most circumstances it helps
to avoid sending an additional TPM2_Shutdown() if the OS TPM driver sent
one already.

When the suspended VM resume swtpm gets a CMD_INIT that requires swtpm
to decide whether a TPM2_Shutdown() needs to be sent and per the last-sent
command it will then send a TPM2_Shutdown(SU_STATE) as in the abrupt
termination case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm_ioctl: Only close file descriptor if >= 0 (Coverity)
Stefan Berger [Tue, 16 Aug 2022 11:51:36 +0000 (07:51 -0400)]
swtpm_ioctl: Only close file descriptor if >= 0 (Coverity)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: seccomp: Check for __SNR_xyz rather than __NR_xyz
Stefan Berger [Mon, 15 Aug 2022 17:49:31 +0000 (13:49 -0400)]
swtpm: seccomp: Check for __SNR_xyz rather than __NR_xyz

If seccomp-syscalls.h lags behind the syscall definition of __NR_xyz then
the __SNR_xyz #define is not available. Therefore, switch to check for
__SNR_xyz #define because they are available if __NR_xyz is available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Implement fips_mode_enabled()
Stefan Berger [Sat, 23 Jul 2022 06:32:44 +0000 (02:32 -0400)]
swtpm: Implement fips_mode_enabled()

Implement fips_mode_enabeld() to check whether FIPS is enabledand
use the new function to check for FIPS mode enablement before
trying to disable it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Rename disable_fips_mode() and move into tpmlib_start()
Stefan Berger [Wed, 20 Jul 2022 20:58:28 +0000 (16:58 -0400)]
swtpm: Rename disable_fips_mode() and move into tpmlib_start()

Rename disable_fips_mode() to fips_mode_disable() amd move into
tpmlib_start() after TPMLIB_MainInit(). Clean up the duplicate
prototype.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Fixed typo `fs_mount` vs `fsmount` and removed duplicates.
Hans [Mon, 15 Aug 2022 12:06:27 +0000 (14:06 +0200)]
swtpm: Fixed typo `fs_mount` vs `fsmount` and removed duplicates.

The project wouldn't compile on my ubuntu 20.04.1 based system with the error message:
```
  CC       libswtpm_libtpms_la-seccomp_profile.lo
In file included from seccomp_profile.c:44:
seccomp_profile.c: In function ‘create_seccomp_profile’:
seccomp_profile.c:105:9: error: ‘__SNR_fs_mount’ undeclared (first use in this function)
  105 |         SCMP_SYS(fs_mount),
      |         ^~~~~~~~
seccomp_profile.c:105:9: note: each undeclared identifier is reported only once for each function it appears in
```

Additionally, there were some duplicates in the profile.

Signed-off-by: Hans Niklas Jacob <hnj@posteo.de>
20 months agoswtpm: Add some more recent syscalls to seccomp profile
Stefan Berger [Fri, 12 Aug 2022 16:53:27 +0000 (12:53 -0400)]
swtpm: Add some more recent syscalls to seccomp profile

Add some more recent syscalls to the disallowlist in the seccomp
profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: cuse: Extend usage of FILE_OPS_LOCK to protect a reading thread
Stefan Berger [Tue, 9 Aug 2022 23:58:33 +0000 (19:58 -0400)]
swtpm: cuse: Extend usage of FILE_OPS_LOCK to protect a reading thread

Extend usage of the FILE_OPS_LOCK to prevent other threads from reading or
writing commands or doing ioctls while the current thread is reading a
response. This prevents a race condition where ptm_read_offset is set to 0
by a thread writing a new command to the device while the current thread
is reading a response from the device and needs this offset.

Resolves: https://github.com/stefanberger/swtpm/issues/725
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agotests: Remove dump of logfile at end of test
Stefan Berger [Thu, 11 Aug 2022 15:58:44 +0000 (11:58 -0400)]
tests: Remove dump of logfile at end of test

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm_setup: Add missing newline to help screen
Stefan Berger [Wed, 10 Aug 2022 17:59:41 +0000 (13:59 -0400)]
swtpm_setup: Add missing newline to help screen

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoman: Replace swtpm_cuse man page with redirect to swtpm man page
Stefan Berger [Wed, 10 Aug 2022 22:43:07 +0000 (18:43 -0400)]
man: Replace swtpm_cuse man page with redirect to swtpm man page

The swtpm man page also covers the CUSE TPM, so do not maintain the
swtpm_cuse man page anymore but replace it with a redirect to the swtpm
mane page instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: Travial reformatting of arrays of structs
Stefan Berger [Wed, 10 Aug 2022 22:39:08 +0000 (18:39 -0400)]
swtpm: Travial reformatting of arrays of structs

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agoswtpm: cuse: Restrict opening CUSE device to one openable file descriptor
Stefan Berger [Tue, 9 Aug 2022 18:40:49 +0000 (14:40 -0400)]
swtpm: cuse: Restrict opening CUSE device to one openable file descriptor

Restrict the opening of the CUSE device to one single file descriptor. We
can modify the CUSE TPM in this way since the kernel's /dev/tpm0 cannot be
opened multiple times, either, and the CUSE TPM should behave in the same
way.

Adjust test the partial reads case to only open CUSE device file once by
using a python program. Close the open file descriptor 100 before using
swtpm_ioctl to avoid failures.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20 months agotests: Move swtpm_open_cmddev into swtpm_cmd_tx
Stefan Berger [Tue, 9 Aug 2022 20:04:43 +0000 (16:04 -0400)]
tests: Move swtpm_open_cmddev into swtpm_cmd_tx

Move swtpm_open_cmddev call into swtpm_cmd_tx since the latter function is
always called in a subshell that previously inherited the file descriptor
opened by the test cases. Remove swtpm_cmd_tx from nearly all test cases
and also remove closing of file descriptor 100 via 'exec 100>&-' from test
cases since this is not necessary anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21 months agoswtpm: Ignore error if TPMLIB_ChooseTPMVersion for printing caps fails
Stefan Berger [Tue, 19 Jul 2022 23:27:56 +0000 (19:27 -0400)]
swtpm: Ignore error if TPMLIB_ChooseTPMVersion for printing caps fails

Revert the change from the previous patch that shows an error when
TPMLIB_ChooseTPMVersion fails but rather ignore the error as before.
If a TPM 2 is supported then tpm-2.0 capability verb will be shown
and if a TPM 1.2 is supported then tpm-1.2 will be shown, thus
allowing someone reading the JSON to determine what is supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21 months agoswtpm: Move TPMLIB_ChooseTPMVersion into capabilities_print_json
Stefan Berger [Mon, 18 Jul 2022 22:24:33 +0000 (18:24 -0400)]
swtpm: Move TPMLIB_ChooseTPMVersion into capabilities_print_json

All callers to capabilities_print_json() call TPMLIB_ChooseTPMVersion
right before. Move it into the function now and check the return
code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21 months agoswtpm_setup: Implement get_swtpm_capabilities() and call from two functions
Stefan Berger [Tue, 19 Jul 2022 12:20:45 +0000 (08:20 -0400)]
swtpm_setup: Implement get_swtpm_capabilities() and call from two functions

Implement get_swtpm_capabilities() and call it from two existing functions
that now become a lot simpler.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21 months agoswtpm: Also advertise the flags-opt-startup option for the CUSE interface
Stefan Berger [Wed, 13 Jul 2022 20:43:40 +0000 (16:43 -0400)]
swtpm: Also advertise the flags-opt-startup option for the CUSE interface

Commit 6559a902 implemented support for the startup-xyz flags for the CUSE
interface but the capability has not been advertised.

Adjust test cases to reflect the new verb being shown for
--print-capabilities.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21 months agoconfigure: check for bash
William Roberts [Tue, 12 Jul 2022 17:04:10 +0000 (12:04 -0500)]
configure: check for bash

PCR Bank verification needs bash, so check for bash. While at it use the
autoconf shell construct macros over raw shell syntax which is slightly
more portable.

Examples:
./configure --enable-default-pcr-banks=sha256,sha920
checking which PCR banks to activate by default... configure: error: sha256,sha920 is an invalid list of PCR banks

./configure --enable-default-pcr-banks=sha256,sha512
checking which PCR banks to activate by default... sha256,sha512

./configure
checking which PCR banks to activate by default... sha256

Signed-off-by: William Roberts <william.c.roberts@intel.com>
22 months agogitignore: Ignore created files in man/man5/
Stefan Berger [Mon, 27 Jun 2022 14:19:35 +0000 (10:19 -0400)]
gitignore: Ignore created files in man/man5/

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoselinux: Replace hardcoded install path with @prefix@
Stefan Berger [Mon, 27 Jun 2022 12:42:38 +0000 (08:42 -0400)]
selinux: Replace hardcoded install path with @prefix@

Replace the hardcoded install path in src/selinux/swtpm.fc and
src/selinux/swtpmcuse.fc with @prefix@ and append .in to these files so
that they are generated when running configure.

Add the selinux policy input files with their suffix to the CLEANFILES
variable so they get cleaned up and 'make distcheck' works.

Resolves: https://github.com/stefanberger/swtpm/issues/711
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Disable OpenSSL FIPS mode to avoid libtpms failures
Stefan Berger [Wed, 8 Jun 2022 13:19:07 +0000 (09:19 -0400)]
swtpm: Disable OpenSSL FIPS mode to avoid libtpms failures

While libtpms does not provide any means to disable FIPS-disabled crypto
algorithms from being used, work around the issue by simply disabling the
FIPS mode of OpenSSL if it is enabled. If it cannot be disabled, exit
swtpm with a failure message that it cannot be disabled. If FIPS mode
was successfully disabled, print out a message as well.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2090219
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotests: Do not activate SHA-1 PCR bank in test case
Stefan Berger [Mon, 13 Jun 2022 18:05:25 +0000 (14:05 -0400)]
tests: Do not activate SHA-1 PCR bank in test case

For being able to run tests with runtime-deactivated SHA-1 (in libtpms),
do not test with SHA-1 bank anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm_bios: Use TPM2_ALG_SHA256 as parameter to TPM2_IncrementalSelfTest
Stefan Berger [Mon, 13 Jun 2022 18:02:48 +0000 (14:02 -0400)]
swtpm_bios: Use TPM2_ALG_SHA256 as parameter to TPM2_IncrementalSelfTest

Do not use TPM2_ALG_SHA1 anymore as parameter to TPM2_IncrementalSelfTest()
so that this also works when SHA1 support in libtpms is runtime-disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Update printed copyright notice
Stefan Berger [Sun, 12 Jun 2022 18:29:52 +0000 (14:29 -0400)]
swtpm: Update printed copyright notice

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Remove stale parameter from function documentation
Stefan Berger [Mon, 30 May 2022 15:19:03 +0000 (11:19 -0400)]
swtpm: Remove stale parameter from function documentation

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Fix a typo in an error message
Stefan Berger [Mon, 30 May 2022 15:13:58 +0000 (11:13 -0400)]
swtpm: Fix a typo in an error message

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Replace malloc + strcpy with strdup and handle OOM case
Stefan Berger [Wed, 25 May 2022 19:55:27 +0000 (15:55 -0400)]
swtpm: Replace malloc + strcpy with strdup and handle OOM case

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Handle case where unknown blobtype is given (Coverity)
Stefan Berger [Wed, 25 May 2022 19:47:04 +0000 (15:47 -0400)]
swtpm: Handle case where unknown blobtype is given (Coverity)

Handle the case where an unknown blobtype is given and therefore
cannot be translated to a filename and blobname is NULL. Previously
this would have lead to an error when trying to read the file, now
we handle the failure case earlier.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Cast '1' to uint64_t before shift and assign to uint64_t variable
Stefan Berger [Wed, 25 May 2022 19:31:05 +0000 (15:31 -0400)]
swtpm: Cast '1' to uint64_t before shift and assign to uint64_t variable

To avoid an overflowing expression cast '1' to uint64_t before shifting
it and assigning it to a uint64_t variable. In practice this kind of
overflow would never happen because there aren't that many available
PCR banks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Initialize res variable (Coverity)
Stefan Berger [Wed, 25 May 2022 18:28:09 +0000 (14:28 -0400)]
swtpm: Initialize res variable (Coverity)

Initialize the 'res' variable at the beginning of the function
even though this wouldn't be necessary in this case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Remove assignment to unused variable
Stefan Berger [Wed, 25 May 2022 18:19:36 +0000 (14:19 -0400)]
swtpm: Remove assignment to unused variable

Remove the assigment to 'res' since the subsequent code path does not
need it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_localca: Add comment that failure to read optsfile is not an issue
Stefan Berger [Wed, 25 May 2022 20:02:45 +0000 (16:02 -0400)]
swtpm_localca: Add comment that failure to read optsfile is not an issue

Add a comment stating that failure to read the optsfile is not an
issue since the optsfile does not need to exist.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_setup: Use g_strdup instead of strdup
Stefan Berger [Wed, 25 May 2022 19:13:09 +0000 (15:13 -0400)]
swtpm_setup: Use g_strdup instead of strdup

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_setup: Initialize pubek_len (Coverity)
Stefan Berger [Wed, 25 May 2022 18:23:41 +0000 (14:23 -0400)]
swtpm_setup: Initialize pubek_len (Coverity)

Initialize pubek_len even though it isn't necessary to do so since
it will be initialized in the first function to which it is passed.
However, Coverity complains about pubek_len passed to print_as_hex()
not being initialized, even though this is not possible.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_ioctl: Free variable before parsing it to avoid memory leak (Coverity)
Stefan Berger [Wed, 25 May 2022 19:19:19 +0000 (15:19 -0400)]
swtpm_ioctl: Free variable before parsing it to avoid memory leak (Coverity)

Avoid a memory leaks if --tcp is provided multiple times by freeing
the previously allocated memory in the tcp_hostname variable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_ioctl: Close file descriptor at end of main (Coverity)
Stefan Berger [Wed, 25 May 2022 18:32:53 +0000 (14:32 -0400)]
swtpm_ioctl: Close file descriptor at end of main (Coverity)

Close the file descriptor at the end of the main function.
To avoid closing random file descriptors initialize it with -1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_cert: Test for NULL pointer returned by malloc
Stefan Berger [Wed, 25 May 2022 19:34:57 +0000 (15:34 -0400)]
swtpm_cert: Test for NULL pointer returned by malloc

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)
Stefan Berger [Wed, 25 May 2022 19:26:52 +0000 (15:26 -0400)]
swtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)

Avoid memory leaks if one of the parameters --tcp, --tpm-device,
or --unix was passed multiple times by freeing the previously
parsed value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)
Stefan Berger [Wed, 25 May 2022 19:09:47 +0000 (15:09 -0400)]
swtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)

Avoid memory leaks if one of the parameters --modulus, --ecc-x,
or --ecc-y was passed multiple times by freeing the previously
parsed value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_bios: Do not assigned -1 to closed file descriptor at end of function
Stefan Berger [Wed, 25 May 2022 18:15:32 +0000 (14:15 -0400)]
swtpm_bios: Do not assigned -1 to closed file descriptor at end of function

There's no need to assigned -1 to a closed file descriptor at the
end of a function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Avoid locking directory multiple times
Stefan Berger [Wed, 11 May 2022 02:28:30 +0000 (22:28 -0400)]
swtpm: Avoid locking directory multiple times

Commit 2d3deaef29 forgot to move the check for whether the lock file has
already been opened into the new function opening the lock file and there-
fore the lock file is now opened whenever swtpm gets a PTM_INIT. This fix
prevents the reopening of the lockfile if it has already been opened.
Otherwise many PTM_INIT's will lead to failure since no more files can
be opened.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Remove support for pre-v0.1 state files without header
Stefan Berger [Fri, 6 May 2022 22:41:17 +0000 (18:41 -0400)]
swtpm: Remove support for pre-v0.1 state files without header

Remove support for TPM state files that didn't have the header
because they were created some time before v0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agotest: Recreate TPM 2 state files with header
Stefan Berger [Sat, 7 May 2022 18:18:35 +0000 (14:18 -0400)]
test: Recreate TPM 2 state files with header

Use libtpms v0.6.6 and recreate the TPM 2 state file with header.
Start swtpm with the existing state files and have it rewrite the
volatiles state (swtpm_ioctl -v) and permanent state (tssnvdefine
+ tssnvundefine) files so that the header is on the files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agotest: Recreate TPM 2 state files with header
Stefan Berger [Fri, 6 May 2022 21:28:50 +0000 (17:28 -0400)]
test: Recreate TPM 2 state files with header

Use libtpms v0.6.2 and recreate the TPM 2 state file with header.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agotest: Recreate TPM 2 state files with header
Stefan Berger [Fri, 6 May 2022 22:31:13 +0000 (18:31 -0400)]
test: Recreate TPM 2 state files with header

Recreate TPM 2 state files that didn't have a header. Use latest
version of libtpms from the stable-0.6.0 branch to create the
state that more recent version have to be able to read.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agotest: Recreate TPM 1.2 state files with header
Stefan Berger [Fri, 6 May 2022 22:08:17 +0000 (18:08 -0400)]
test: Recreate TPM 1.2 state files with header

Recreate a TPM 1.2 state file with header.

The state of the TPM 1.2 must be initialized with Startup(ST_CLEAR)
and then saved so that the proper error code appears as a result
when running this test.

The PCR values was originally created by extending PCR 10 with
sha1("test"). This was recreated using this sequence:

s=$(echo -en test | sha1sum | cut -d " " -f1 | sed -n 's/\([a-f0-9]\{2\}\)/\\x\1/pg')
echo -en $s > input
tss1extend  -ha 10 -if input

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agotest: Recreate TPM 1.2 state files with header
Stefan Berger [Fri, 6 May 2022 20:47:42 +0000 (16:47 -0400)]
test: Recreate TPM 1.2 state files with header

Recreate TPM 1.2 state files with similar content but with the state
file header. The older versions of the state files were created before
the header was introduced in v0.1. The goal is to be able to get rid
of code supporting pre-v0.1 files that had no header.

The PCR values was originally created by extending PCR 10 with
sha1("test"). This was recreated using this sequence:

s=$(echo -en test | sha1sum | cut -d " " -f1 | sed -n 's/\([a-f0-9]\{2\}\)/\\x\1/pg')
echo -en $s > input
tss1extend  -ha 10 -if input

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agodebian: Add swtpm apparmor profile
Lena Voytek [Thu, 5 May 2022 20:07:23 +0000 (13:07 -0700)]
debian: Add swtpm apparmor profile

An apparmor profile was added for Debian-based distributions in order to
increase security. This blocks swtpm from accessing restricted and unnecessary
files, folders, and network interfaces. swtpm works as normal alongside libvirt
and its configurations, however users may run into issues when using swtpm on
its own when providing it with a restricted directory. The apparmor profile can
be modified to include additional permissions by creating and adding to the
file /etc/apparmor.d/local/usr.bin.swtpm.

Signed-off-by: Lena Voytek <lena.voytek@canonical.com>
23 months agotests: Patch IBM TSS2 test suite for OpenSSL 3.x
Stefan Berger [Tue, 3 May 2022 00:46:50 +0000 (20:46 -0400)]
tests: Patch IBM TSS2 test suite for OpenSSL 3.x

Apply a patch to the IBM TSS2 v1.6 test suite when OpenSSL 3.x is de-
tected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>