]> git.proxmox.com Git - swtpm.git/log
swtpm.git
2 years agoswtpm_setup: Move gmalloc after block that may return NULL on failure v0.7.0-rc1
Stefan Berger [Tue, 5 Oct 2021 20:22:25 +0000 (16:22 -0400)]
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>
2 years agoswtpm_setup: Introduce label to skip over closing of pidfile
Stefan Berger [Tue, 5 Oct 2021 20:18:25 +0000 (16:18 -0400)]
swtpm_setup: Introduce label to skip over closing of pidfile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Call msync with length = 0 on Cygwin
Stefan Berger [Tue, 5 Oct 2021 18:29:51 +0000 (14:29 -0400)]
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>
2 years agoswtpm_setup: Use SWTPM_ATTR_UNUSED on unused parameters (BSDs)
Stefan Berger [Tue, 5 Oct 2021 16:46:40 +0000 (12:46 -0400)]
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>
2 years agoswtpm_setup: Use pidfile filename rather than fd (Cygwni, BSDs)
Stefan Berger [Tue, 5 Oct 2021 16:39:49 +0000 (12:39 -0400)]
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>
2 years agotests: Use /usr/bin/env bash rather than /bin/bash (BSDs)
Stefan Berger [Tue, 5 Oct 2021 16:36:48 +0000 (12:36 -0400)]
tests: Use /usr/bin/env bash rather than /bin/bash (BSDs)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoheaders: Add defines for little endian data conversion (OS X)
Stefan Berger [Tue, 5 Oct 2021 15:37:54 +0000 (11:37 -0400)]
headers: Add defines for little endian data conversion (OS X)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Use compiler and system dependent header files
Stefan Berger [Tue, 5 Oct 2021 15:22:24 +0000 (11:22 -0400)]
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>
2 years agoswtpm: Use sys/mount.h and support block devs only if BLKGETSIZE64 exists
Stefan Berger [Tue, 5 Oct 2021 15:17:01 +0000 (11:17 -0400)]
swtpm: Use sys/mount.h and support block devs only if BLKGETSIZE64 exists

The header file fs/linux.h only exists on Linux but we can also
use sys/mount.h, which also exists on Cygwin and the BSDs.

Only support  block devices if BLKGETSIZE64 is defined.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: mention dir:// and file:// in man page and usage
Stefan Reiter [Thu, 30 Sep 2021 13:59:40 +0000 (15:59 +0200)]
swtpm_setup: mention dir:// and file:// in man page and usage

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: add test case to exercise file backend
Stefan Reiter [Thu, 30 Sep 2021 09:27:14 +0000 (11:27 +0200)]
swtpm_setup: add test case to exercise file backend

heavily copy-pas^W inspired by 'test_swtpm_setup_overwrite'

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: add file backend
Stefan Reiter [Thu, 30 Sep 2021 08:40:01 +0000 (10:40 +0200)]
swtpm_setup: add file backend

Add a second backend for supporting the file:// linear nvram store in
swtpm.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: add abstract swtpm_backend_ops with dir:// implementation
Stefan Reiter [Thu, 30 Sep 2021 08:03:05 +0000 (10:03 +0200)]
swtpm_setup: add abstract swtpm_backend_ops with dir:// implementation

Abstract away implementation specific code for handling TPM state in
swtpm_setup. The current code for handling directories is moved to
'swtpm_backend_dir.c'.

Where possible, the input argument is simply passed verbatim as
'backend-uri' to swtpm.

No functional change intended, aside from supporting 'dir://' as
optional prefix. The checks for lock-file accessibility are moved to
check_access(), but that shouldn't affect anything AFAICT.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: use mkstemp for pidfile
Stefan Reiter [Thu, 30 Sep 2021 08:17:57 +0000 (10:17 +0200)]
swtpm_setup: use mkstemp for pidfile

This avoids issues with state backends where we don't have a convenient
directory for a pidfile available.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: remove redundant delete_state function
Stefan Reiter [Thu, 30 Sep 2021 07:30:45 +0000 (09:30 +0200)]
swtpm_setup: remove redundant delete_state function

...and use delete_swtpm_statefiles instead. This function iterates the
folder instead of just deleting one file, but since it is already called
before the init call guarded here, it can only affect files created by
this run anyway.

Note that delete_state had slightly different return semantics, but it
doesn't matter, as the return value is ignored here anyway (best effort
cleanup).

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add "nvram-backend-linear" capability
Stefan Reiter [Thu, 5 Aug 2021 12:22:46 +0000 (14:22 +0200)]
swtpm: Add "nvram-backend-linear" capability

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add "file://" backend to man page
Stefan Reiter [Thu, 5 Aug 2021 12:18:09 +0000 (14:18 +0200)]
swtpm: Add "file://" backend to man page

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add tests for "linear file" backend
Stefan Reiter [Thu, 5 Aug 2021 12:14:15 +0000 (14:14 +0200)]
swtpm: Add tests for "linear file" backend

Adapt save_load_state tests to include coverage of the "linear file"
backend mode. "tpm2" is save/load is tested with both a regular file and
a loop device to excercise the blockdev mmap code.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add "linear file" nvram store backend
Stefan Reiter [Thu, 5 Aug 2021 12:09:55 +0000 (14:09 +0200)]
swtpm: Add "linear file" nvram store backend

Implements a second abstraction layer as an NVRAM storage backend: The
"linear" backend stores data in a simple format that can contain
multiple files (multiple TPM states and numbers) in one linear address
space. This can then be mapped to files or other "block-device-like"
interfaces using nvram_linear_file_ops implementations.

A simple one using mmap is provided with the URI type "file://".

Does not support any locking at the moment, users must ensure exclusive
access themselves.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agotests: Skip TPM 2 pkcs11-related test when ASAN is used
Stefan Berger [Mon, 4 Oct 2021 22:07:43 +0000 (18:07 -0400)]
tests: Skip TPM 2 pkcs11-related test when ASAN is used

The key is freed using 'gnutls_privkey_deinit(pkcs11key)', yet the
following memory leaks show up that are most likely in the pkcs11 module.
Skip the test if ASAN is being used to avoid the test failure.

Direct leak of 55080 byte(s) in 1 object(s) allocated from:
    #0 0x7fdabb152af7 in calloc (/lib64/libasan.so.6+0xaeaf7)
    #1 0x7fdab6b737c6 in C_Initialize (/usr/lib64/pkcs11/libtpm2_pkcs11.so+0x147c6)
    #2 0x7fdab9a5f8a9 in initialize_module_inlock_reentrant (/lib64/libp11-kit.so.0+0x2b8a9)
    #3 0x7fdab9a5fc88 in managed_C_Initialize (/lib64/libp11-kit.so.0+0x2bc88)
    #4 0x7fdab9a66018 in p11_kit_modules_initialize (/lib64/libp11-kit.so.0+0x32018)
    #5 0x7fdab9a66778 in p11_kit_modules_load_and_initialize (/lib64/libp11-kit.so.0+0x32778)
    #6 0x7fdabab10dc5 in auto_load (/lib64/libgnutls.so.30+0x9cdc5)
    #7 0x7fdabab12656 in gnutls_pkcs11_init (/lib64/libgnutls.so.30+0x9e656)
    #8 0x7fdabab12779 in _gnutls_pkcs11_check_init (/lib64/libgnutls.so.30+0x9e779)
    #9 0x7fdabab1af1f in gnutls_pkcs11_privkey_import_url (/lib64/libgnutls.so.30+0xa6f1f)
    #10 0x7fdabaaee0e3 in gnutls_privkey_import_url (/lib64/libgnutls.so.30+0x7a0e3)
    #11 0x40abee in main /home/stefanb/dev/swtpm/src/swtpm_cert/ek-cert.c:1399
    #12 0x7fdab9f5ab74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
    #13 0x40366d in _start (/home/stefanb/dev/swtpm/src/swtpm_cert/swtpm_cert+0x40366d)

Indirect leak of 8208 byte(s) in 1 object(s) allocated from:
    #0 0x7fdabb152af7 in calloc (/lib64/libasan.so.6+0xaeaf7)
    #1 0x7fdab6b736f9 in C_Initialize (/usr/lib64/pkcs11/libtpm2_pkcs11.so+0x146f9)
    #2 0x7fdab9a5f8a9 in initialize_module_inlock_reentrant (/lib64/libp11-kit.so.0+0x2b8a9)
    #3 0x7fdab9a5fc88 in managed_C_Initialize (/lib64/libp11-kit.so.0+0x2bc88)
    #4 0x7fdab9a66018 in p11_kit_modules_initialize (/lib64/libp11-kit.so.0+0x32018)
    #5 0x7fdab9a66778 in p11_kit_modules_load_and_initialize (/lib64/libp11-kit.so.0+0x32778)
    #6 0x7fdabab10dc5 in auto_load (/lib64/libgnutls.so.30+0x9cdc5)
    #7 0x7fdabab12656 in gnutls_pkcs11_init (/lib64/libgnutls.so.30+0x9e656)
    #8 0x7fdabab12779 in _gnutls_pkcs11_check_init (/lib64/libgnutls.so.30+0x9e779)
    #9 0x7fdabab1af1f in gnutls_pkcs11_privkey_import_url (/lib64/libgnutls.so.30+0xa6f1f)
    #10 0x7fdabaaee0e3 in gnutls_privkey_import_url (/lib64/libgnutls.so.30+0x7a0e3)
    #11 0x40abee in main /home/stefanb/dev/swtpm/src/swtpm_cert/ek-cert.c:1399
    #12 0x7fdab9f5ab74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
    #13 0x40366d in _start (/home/stefanb/dev/swtpm/src/swtpm_cert/swtpm_cert+0x40366d)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Make fsync-related errors non-fatal (for libvirt using AppArmor)
Stefan Berger [Fri, 1 Oct 2021 20:50:07 +0000 (16:50 -0400)]
swtpm: Make fsync-related errors non-fatal (for libvirt using AppArmor)

Only recent libvirt versions have the patch for the AppArmor profile for
libvirt to allow fsync after opening a directory for reading. Rather
than failing hard on the open-directory-for-reading error, log it once
and continue and do not try it again after.

This patch addresses the problems seen on Ubuntu related to an older
version of libvirt without the AppArmor profile update.
- issue #484
- issue #549
- issue #559

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoRevert "swtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)"
Stefan Berger [Fri, 1 Oct 2021 20:43:18 +0000 (16:43 -0400)]
Revert "swtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)"

This reverts commit 04cb07fa6c02afdf16c1adb4b5c202d93c6b190c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoUpdate bug_report.md
Stefan Berger [Sat, 2 Oct 2021 15:18:02 +0000 (11:18 -0400)]
Update bug_report.md

Ask users to include log files, such as libvirt log files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)
Stefan Berger [Fri, 1 Oct 2021 13:18:58 +0000 (09:18 -0400)]
swtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)

Only recent libvirt versions have the patch for the AppArmor profile
for libvirt to allow fsync on dir and directory. Rather than failing
hard on this error, log it once and continue and do not try fsync
again after.

This patch addresses the problems seen on Ubuntu related to an older
version of libvirt without the AppArmor profile update.
- issue #484
- issue #549
- issue #559

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Fix errno comparison on end-of-directory (FreeBSD)
Stefan Berger [Thu, 30 Sep 2021 17:40:26 +0000 (13:40 -0400)]
swtpm_setup: Fix errno comparison on end-of-directory (FreeBSD)

FreeBSD may return errno EINVAL beside ENOENT once there are no more
entries in a directory to walk over. It claims that readdir() follows
the getdirentries() return codes, which do include EINVAL but not
ENOENT. But ENOENT is also being used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Fix memory leak on arrays of strings
Stefan Berger [Wed, 29 Sep 2021 23:58:56 +0000 (19:58 -0400)]
swtpm_localca: Fix memory leak on arrays of strings

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Use return from main rather than exit to resolve ASAN issue
Stefan Berger [Wed, 29 Sep 2021 23:20:32 +0000 (19:20 -0400)]
swtpm_localca: Use return from main rather than exit to resolve ASAN issue

Use return rather than exit() when returning from main so that g_autofree'd
variables can be freed.

This resolves issue #568 that occurs with clang only.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use return from main rather than exit to resolve ASAN issue
Stefan Berger [Wed, 29 Sep 2021 23:17:59 +0000 (19:17 -0400)]
swtpm_setup: Use return from main rather than exit to resolve ASAN issue

Use return rather than exit() when returning from main so that g_autofree'd
variables can be freed.

This resolves issue #568 that occurs with clang only.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Use nm and grep to check for ASAN
Stefan Berger [Wed, 29 Sep 2021 16:35:58 +0000 (12:35 -0400)]
tests: Use nm and grep to check for ASAN

clang doesn't link executables built with ASAN support to libasan, like
gcc does, so we have to use nm rather than ldd for checking for whether
the executable was built with ASAN. nm is part of the binutils package
and should be available on all systems where gcc was installed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Fix a TPM 1.2/TCSD related memory leak
Stefan Berger [Wed, 29 Sep 2021 15:55:39 +0000 (11:55 -0400)]
swtpm_localca: Fix a TPM 1.2/TCSD related memory leak

Auto-free the variables used for holding values read from the config
file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Replace bad '~' with '\!'
Stefan Berger [Wed, 29 Sep 2021 16:07:35 +0000 (12:07 -0400)]
tests: Replace bad '~' with '\!'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Forward --logfile option to swtpm
Eiichi Tsukata [Wed, 22 Sep 2021 06:22:28 +0000 (15:22 +0900)]
swtpm_setup: Forward --logfile option to swtpm

Whenever swtpm_setup is executed with --logfile option, forward the
option to swtpm (--log file=...). This helps debugging swtpm
initialization issues.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Initialize logging as early as possible
Eiichi Tsukata [Wed, 22 Sep 2021 06:59:34 +0000 (15:59 +0900)]
swtpm: Initialize logging as early as possible

Parse "--log" option earlier to help debugging initialization issues.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agobuild-sys: Minor error message typo fix for glib
Eiichi Tsukata [Wed, 29 Sep 2021 00:53:12 +0000 (09:53 +0900)]
build-sys: Minor error message typo fix for glib

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agobuild-sys: Introduce --enable-sanitizers to configure
Eiichi Tsukata [Tue, 28 Sep 2021 05:35:20 +0000 (14:35 +0900)]
build-sys: Introduce --enable-sanitizers to configure

This enables address and undefined sanitizers.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agotest: Fix test_tpm2_file_permissions for BSD
Stefan Berger [Tue, 28 Sep 2021 14:08:29 +0000 (10:08 -0400)]
test: Fix test_tpm2_file_permissions for BSD

BSD cp does not understand the -d option, so remove it.
It's better to use "su -u nobody -c '...'" than sudo, which makes
this test also work on the BSDs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Add a test case for testing --runas and ability to access files
Stefan Berger [Sun, 26 Sep 2021 02:26:40 +0000 (22:26 -0400)]
tests: Add a test case for testing --runas and ability to access files

Add a test case for testing the --runas parameter and the ability to access
existing files that have restrictive access permission so that only allow
the --runas user is able to access these files. This is to ensure that
swtpm can access these files properly when the handling of options and the
changing to the --runas user is moved around within swtpm.

Skip the test case if swtpm is linked with ASAN since then we get these
types of error messages that fail tests:

==== Starting swtpm with interfaces socket+socket ====
==3303263==LeakSanitizer has encountered a fatal error.
==3303263==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==3303263==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Fix exit code on error to be '1'.
Stefan Berger [Mon, 27 Sep 2021 22:26:43 +0000 (18:26 -0400)]
swtpm_setup: Fix exit code on error to be '1'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Add size to each type of state and use JSON object
Stefan Berger [Mon, 27 Sep 2021 15:02:47 +0000 (11:02 -0400)]
swtpm: Add size to each type of state and use JSON object

Add the size of the type state to the --print-states output and switch
back to a JSON object when enumerating the blobs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Fix tests using tpm2-abrmd by preventing concurrency
Stefan Berger [Mon, 27 Sep 2021 02:38:50 +0000 (22:38 -0400)]
tests: Fix tests using tpm2-abrmd by preventing concurrency

The two tests test_tpm2_samples_create_tpmca and
test_tpm2_swtpm_localca_pkcs11 cannot complete successfully if run in
parallel. To solve this issue, introduce a dependency via the log files
to prevent parallel execution of the two test. We have to append the
.test suffix to their names to be able to do this.

docs:
https://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html

Resolves issue #501, though the problem with stability of the tpm2 pkcs11
module is not resolved.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Search for all state files and use abstracted names in JSON
Stefan Berger [Sat, 25 Sep 2021 00:23:22 +0000 (20:23 -0400)]
swtpm: Search for all state files and use abstracted names in JSON

Search for all the state files not just the permanent state and
when printing the JSON use the abstracted names rather than concrete
filenames that are only valid for the dir backend but will likely
not exist in other backends.

Adjust swtpm_setup to search for the abstracted name and also
adjust the error message to print out the abstracted name.

Adjust the test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Implement CheckState interface function for checking for stateblob
Stefan Berger [Sat, 25 Sep 2021 00:24:52 +0000 (20:24 -0400)]
swtpm: Implement CheckState interface function for checking for stateblob

Implement a CheckState interface function for checking for the
TPM_PERMANENT_ALL_NAME blog. The dirctory backend does a simple stat on the
file without actually reading it, which otherwise may require the (correct)
key if it was encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Remove all interface functions from swtpm_nvstore_dir.h
Stefan Berger [Sat, 25 Sep 2021 00:24:32 +0000 (20:24 -0400)]
swtpm: Remove all interface functions from swtpm_nvstore_dir.h

Remove all interface functions from swtpm_nvstore_dir.h and make them
static in swtpm_nvstore_dir.c. This way we avoid direct calls to these
functions from elsewhere.

Move the declaration of the interface structure into swtpm_nvstore.h
to get rid of swtpm_nvstore_dir.h entirely.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Get rid of printf's in swtpm_aes.c
Stefan Berger [Wed, 22 Sep 2021 13:31:14 +0000 (09:31 -0400)]
swtpm: Get rid of printf's in swtpm_aes.c

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Cleanup storage backend on shutdown to unlock dir
Stefan Berger [Tue, 21 Sep 2021 18:39:36 +0000 (14:39 -0400)]
swtpm: Cleanup storage backend on shutdown to unlock dir

Cleanup on the storage backend side on shutdown to unlock the
locked directory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswptm_ioctl: Eliminate an unreachable statement
Stefan Berger [Tue, 21 Sep 2021 19:15:10 +0000 (15:15 -0400)]
swptm_ioctl: Eliminate an unreachable statement

If is_chardev is false, then we have a buffersize of 4096 bytes per
the following statement:

322    if (!is_chardev)
323        buffersize = 4096;

With this we end up in the following if branch:

384        if (buffersize) {
385            /* continue with the read interface */
[...]
418
419            break;
420        } else {

Per the break in line 419 we leave the loop, thus cannot reach the
statement we remove:

423        if (!is_chardev)
424            break;

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Don't set END_ON_HUP flag in CMD_SET_DATAFD handler
Nick Chevsky [Sat, 18 Sep 2021 21:23:55 +0000 (16:23 -0500)]
swtpm: Don't set END_ON_HUP flag in CMD_SET_DATAFD handler

Don't set flag MAIN_LOOP_FLAG_END_ON_HUP in the handler for control
channel command CMD_SET_DATAFD, since this caused the swtpm daemon to
unconditionally terminate when the data channel connection dropped.
Removing the flag allows this behavior to be controlled by the user
via the --terminate command-line switch, as it was meant to be.

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2 years agoswtpm: Use EVP_CIPHER in SWTPM_SymmetricKeyData_Encrypt/Decrypt
Stefan Berger [Mon, 20 Sep 2021 01:49:02 +0000 (21:49 -0400)]
swtpm: Use EVP_CIPHER in SWTPM_SymmetricKeyData_Encrypt/Decrypt

Use the EVP_CIPHER implementation for the AES CBC computations. This
API has been supported already in OpenSSL 1.1.x for sure and is also
not deprecated in OpenSSL 3.0.

This now resolves issue #538.
We can build src/swtpm without having to suppress deprecated API warnings.
Since this is the last issue related to OpenSSL deprecated APIs, we don't
need to suppress any OpenSSL 3.0 deprecated API warnings anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use non-deprecated APIs to contruct RSA key (OSSL 3)
Stefan Berger [Mon, 20 Sep 2021 13:35:23 +0000 (09:35 -0400)]
swtpm_setup: Use non-deprecated APIs to contruct RSA key (OSSL 3)

Use only non-deprecated APIs to construct RSA key when compiling with
OpenSSL 3.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Move check for pkey = NULL right after creation
Stefan Berger [Mon, 20 Sep 2021 13:06:32 +0000 (09:06 -0400)]
swtpm_setup: Move check for pkey = NULL right after creation

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: selinux: Compare absolute path against absolute path
Stefan Berger [Mon, 20 Sep 2021 23:32:30 +0000 (19:32 -0400)]
build-sys: selinux: Compare absolute path against absolute path

This patch fixes issue #533.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Add implementation of SWTPM_HMAC using OpenSSL 3.0 APIs
Stefan Berger [Mon, 20 Sep 2021 01:05:07 +0000 (21:05 -0400)]
swtpm: Add implementation of SWTPM_HMAC using OpenSSL 3.0 APIs

Add an implementation of SWTPM_HMAC using non-deprecated APIs when
compiling with OpenSSL 3.0.

This partially addresses issue #538.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoTravis: Remove python3-twisted package from being installed
Stefan Berger [Sun, 19 Sep 2021 23:44:35 +0000 (19:44 -0400)]
Travis: Remove python3-twisted package from being installed

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Remove check for pip3 that was used by python swtpm_setup
Stefan Berger [Sun, 19 Sep 2021 23:42:18 +0000 (19:42 -0400)]
build-sys: Remove check for pip3 that was used by python swtpm_setup

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Remove import of twisted package function for python2
Stefan Berger [Sun, 19 Sep 2021 23:41:33 +0000 (19:41 -0400)]
test: Remove import of twisted package function for python2

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Use -DOPENSSL_SUPPRESS_DEPRECATED (OSSL 3)
Stefan Berger [Sat, 18 Sep 2021 19:04:29 +0000 (15:04 -0400)]
build-sys: Use -DOPENSSL_SUPPRESS_DEPRECATED (OSSL 3)

Use the (undocumented) OPENSSL_SUPPRESS_DEPRECATED to suppress the
deprecated API warnings when compiling swtpm and swtpm_setup with
OpenSSL 3.0.0 replacing the global -Wno-deprecated-declarations.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Fix test_tpm2_save_load_state_da_timeout rare timer race
Eiichi Tsukata [Thu, 16 Sep 2021 04:59:46 +0000 (13:59 +0900)]
tests: Fix test_tpm2_save_load_state_da_timeout rare timer race

When there is a delay between "Sending TPM2_NV_Write with wrong
password" and "timenow=$(date +%s)", the test can fail with "Error: Did
not get expected failure from TPM2_NV_Write() with good password.
Lockout should be enabled.". This can sometimes happen on slow or busy
systems.

To stabilize the test, this patch introduces precise recovery time
measurement ($timerecovery) and check good password works after that
time. As for lockout timeout, moves starting timer just before
TPM2_NV_Write and check good password fails before that time.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agobuild-sys: Add -Wno-deprecated-declarations to default CFLAGS (OSSL 3)
Stefan Berger [Wed, 15 Sep 2021 15:34:02 +0000 (11:34 -0400)]
build-sys: Add -Wno-deprecated-declarations to default CFLAGS (OSSL 3)

To be able to build with OpenSSL 3.0 we need to added
-Wno-deprecated-declarations to the default CFLAGS.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Fix SWTPM_NVRAM_PrintJson() error handling logic
Eiichi Tsukata [Thu, 9 Sep 2021 06:10:11 +0000 (15:10 +0900)]
swtpm: Fix SWTPM_NVRAM_PrintJson() error handling logic

Return -1 when SWTPM_NVRAM_GetFilenameForName() or
SWTPM_NVRAM_Init() fails.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Rename SWTPM_NVRAM_Print_Json()
Eiichi Tsukata [Thu, 9 Sep 2021 06:08:52 +0000 (15:08 +0900)]
swtpm: Rename SWTPM_NVRAM_Print_Json()

Rename that to SWTPM_NVRAM_PrintJson() to conform the existing function
naming rule.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agotests: Fix test_tpm2_print_states
Eiichi Tsukata [Thu, 9 Sep 2021 06:07:01 +0000 (15:07 +0900)]
tests: Fix test_tpm2_print_states

Currently it's wrongly running _test_print_states.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm_setup: Use --print-states in check_state_overwrite()
Eiichi Tsukata [Fri, 27 Aug 2021 00:24:41 +0000 (09:24 +0900)]
swtpm_setup: Use --print-states in check_state_overwrite()

Instead of directly accessing TPM state store file, use --print-states
to check if there is existing state file or not. This can reduce TPM
state directory dependencies of swtpm_setup.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Add --print-states for reporting TPM states status
Eiichi Tsukata [Fri, 27 Aug 2021 00:22:19 +0000 (09:22 +0900)]
swtpm: Add --print-states for reporting TPM states status

--print-states reports TPM states stored in --tpmstate backend.
This feature is supposed to be used by swtpm_setup for checking TPM state
existence.

Sample output is as follows:

  $ swtpm socket --print-states --tpmstate dir=/tmp --tpm2 | jq .
  {
    "type": "swtpm",
    "states": [
      {
        "name": "tpm2-00.permall"
      }
    ]
  }

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Add GetFilepathForName()
Eiichi Tsukata [Mon, 23 Aug 2021 07:34:14 +0000 (16:34 +0900)]
swtpm: Add GetFilepathForName()

Introduce GetFilepathForName() and use it to get a rooted state file
path instead of existing GetFilenameForName().
Move GetFilenameForName() to swtpm_nvstore.c so that other TPM state
store backend can use it.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm_setup: Add tests for --overwrite options
Eiichi Tsukata [Tue, 17 Aug 2021 05:13:40 +0000 (14:13 +0900)]
swtpm_setup: Add tests for --overwrite options

The tests for the following options:
- with "--overwrite"
- with "--not-overwrite"
- without "--overwrite" nor "--not-overwrite"

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm_setup: Use temp dir for certs instead of TPM state dir
Eiichi Tsukata [Thu, 12 Aug 2021 06:19:40 +0000 (15:19 +0900)]
swtpm_setup: Use temp dir for certs instead of TPM state dir

Currently swtpm_setup saves ek.cert and platform.cert to TPM state
directory and removes them later. As the usage of these files are
temporary, temp directory can be used for this purpose. This reduces
dependencies on TPM state dir, which is convenient for pluggable state
store (https://github.com/stefanberger/swtpm/issues/461).

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agotests: Skip chardev related tests after checking for chardev support
Stefan Berger [Sat, 14 Aug 2021 18:18:37 +0000 (14:18 -0400)]
tests: Skip chardev related tests after checking for chardev support

Skip tests that require the chardev after checking for the chardev
interface support in swtpm. Remove the conditional addition of chardev
related tests from the Makefile.am.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Add missing braces around TPM_DEBUG after if statement
Stefan Berger [Fri, 13 Aug 2021 19:52:15 +0000 (15:52 -0400)]
swtpm: Add missing braces around TPM_DEBUG after if statement

Fix the following compilation issue:

swtpm_nvstore_dir.c: In function 'SWTPM_NVRAM_Validate_Dir':
swtpm_nvstore_dir.c:149:86: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
         TPM_DEBUG("SWTPM_NVRAM_Validate_Dir: Rooted state path %s\n", tpm_state_path);
                                                                                      ^
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Allow sched_setattr in seccomp profile for CUSE TPM
Stefan Berger [Fri, 13 Aug 2021 13:51:21 +0000 (09:51 -0400)]
swtpm: Allow sched_setattr in seccomp profile for CUSE TPM

glib's (v2.68) g_thread_pool_new() calls the syscall sched_setattr(),
which we must allow to avoid termination of the CUSE TPM.

This patch resolves issue #520.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Clear keys on heap at termination
Stefan Berger [Fri, 13 Aug 2021 13:08:11 +0000 (09:08 -0400)]
swtpm: Clear keys on heap at termination

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Wipe out key to ensure it is not left on the stack
Eiichi Tsukata [Thu, 12 Aug 2021 07:27:27 +0000 (16:27 +0900)]
swtpm: Wipe out key to ensure it is not left on the stack

This change is conforming to the following SEI CERT recommendation.

MEM03-C. Clear sensitive information stored in reusable resources:
https://wiki.sei.cmu.edu/confluence/display/c/MEM03-C.+Clear+sensitive+information+stored+in+reusable+resources

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Add "nvram-backend-dir" capability
Eiichi Tsukata [Tue, 27 Jul 2021 01:22:17 +0000 (10:22 +0900)]
swtpm: Add "nvram-backend-dir" capability

Append "nvram-backend-dir" to --print-capabilities output.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Add options for pluggable backend (--tpmstate backend-uri)
Eiichi Tsukata [Wed, 14 Jul 2021 07:02:07 +0000 (16:02 +0900)]
swtpm: Add options for pluggable backend (--tpmstate backend-uri)

Add an options to specify pluggable backend URI.

Ex:
  --tpmstate backend-uri=dir://<path_to_dir>

Backend URI is specific to each backend plugin which points to the
location of the NVRAM files.
Currently, "dir" is the only one available backend. In this case
backend-uri should be a path to the directory where files are stored.

This option is designed to compatible with existing "dir" option.
If "dir" is specified, swtpm prioritize "dir" ignoring "backend-uri".

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Abstract NVRAM interface for pluggable state store
Eiichi Tsukata [Fri, 25 Jun 2021 02:29:44 +0000 (11:29 +0900)]
swtpm: Abstract NVRAM interface for pluggable state store

Related GH issue: https://github.com/stefanberger/swtpm/issues/461

This patch adds an abstraction layer to NVRAM state store implementation
for pluggable storage backends. No functional changes are intended in
this change. The default state store backend ("dir backend") keeps
current behavior.

To make swtpm ready for pluggable store, this patch moves file related
operations to the seperate file (swtpm_nvstore_dir.c) and defined the
interface for plugins (nvram_backend_ops in swtpm_nvstore.h). The
interface can be used by each plugin which will be added later.

With the interface, each plugin can access its "backend_uri" which
points to the location of the backend storage, for example S3 bucket
URL or iSCSI URL, and decide how it stores TPM state data.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm_setup: Add support for checking for TPM 1.2 and TPM 2 support
Stefan Berger [Mon, 9 Aug 2021 21:09:02 +0000 (17:09 -0400)]
swtpm_setup: Add support for checking for TPM 1.2 and TPM 2 support

Implement get_supported_tpm_versions to get swtpm's support for TPM 1.2
and TPM 2 and use it error out in case user choose a TPM version that
is not supported. Also display the supported TPM versions in the
capabilites JSON.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Make error message better when swtpm is not an exectuable
Stefan Berger [Tue, 10 Aug 2021 11:24:44 +0000 (07:24 -0400)]
swtpm_setup: Make error message better when swtpm is not an exectuable

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Fix test case number in case of test being skipped
Stefan Berger [Tue, 10 Aug 2021 11:26:35 +0000 (07:26 -0400)]
tests: Fix test case number in case of test being skipped

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoman: update man pages with new capabilities
Marc-André Lureau [Mon, 9 Aug 2021 19:43:22 +0000 (23:43 +0400)]
man: update man pages with new capabilities

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agoswtpm*: report 'version' in --print-capabilities
Marc-André Lureau [Mon, 9 Aug 2021 13:46:16 +0000 (17:46 +0400)]
swtpm*: report 'version' in --print-capabilities

The "version" field can be used to decide when capabilities are
supported/reported and give some library build details.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agotests: test for availability of TPM 2.0 support in swtpm
Marc-André Lureau [Sat, 7 Aug 2021 17:36:42 +0000 (13:36 -0400)]
tests: test for availability of TPM 2.0 support in swtpm

Skip test cases for TPM 2.0 if TPM 2.0 support is not provided by swtpm.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agotests: test for availability of TPM 1.2 support in swtpm
Stefan Berger [Mon, 9 Aug 2021 12:10:07 +0000 (08:10 -0400)]
tests: test for availability of TPM 1.2 support in swtpm

Skip test cases for TPM 1.2 if TPM 1.2 support is not provided by swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
[ skip more tests ]
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agoswtpm: report 'tpm-1.2' & 'tpm-2.0' in --print-capabilities
Marc-André Lureau [Fri, 6 Aug 2021 15:13:18 +0000 (19:13 +0400)]
swtpm: report 'tpm-1.2' & 'tpm-2.0' in --print-capabilities

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agoswtpm: ignore failure to choose version for --print-capabilities
Marc-André Lureau [Fri, 6 Aug 2021 13:32:17 +0000 (17:32 +0400)]
swtpm: ignore failure to choose version for --print-capabilities

A version was selected early for TPMLIB_GetInfo() to succeed in
--print-capabilities. TPM 1.2 is the default version, but can now be
disabled in libtpms.

Ignore the error when the version is unsupported by libtpms and skip
reporting the GetInfo related details.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agoswtpm: Preserve mlp->flags in CMD_SET_DATAFD handler
Nick Chevsky [Sat, 31 Jul 2021 17:17:59 +0000 (12:17 -0500)]
swtpm: Preserve mlp->flags in CMD_SET_DATAFD handler

Fix the handler for control channel command CMD_SET_DATAFD so that
it ORs new bits onto mlp->flags instead of overwriting its value.
This was causing loss of flags previously set during command-line
argument parsing, which resulted in user-provided options (e.g.
--terminate) to be permanently ignored if command CMD_SET_DATAFD
was at any point received on the control channel.

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2 years agoswtpm: Use the pollfd array's enums as indices when initializing the array
Stefan Berger [Sat, 31 Jul 2021 23:38:54 +0000 (19:38 -0400)]
swtpm: Use the pollfd array's enums as indices when initializing the array

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Use the --write-ek-cert-files option and check for files
Stefan Berger [Mon, 14 Jun 2021 20:02:29 +0000 (16:02 -0400)]
tests: Use the --write-ek-cert-files option and check for files

Use the --write-ek-cert-files option in existing test cases
and check for written files and correctness of the files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Support --write-ek-cert-files as an option
Stefan Berger [Fri, 11 Jun 2021 00:53:45 +0000 (20:53 -0400)]
swtpm_setup: Support --write-ek-cert-files as an option

Write the EK certificate files into the directory specified as parameter
to the --write-ek-cert-files option.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Get key description from function generating the EK key
Stefan Berger [Fri, 11 Jun 2021 00:05:05 +0000 (20:05 -0400)]
swtpm_setup: Get key description from function generating the EK key

Pass an optional key_description parameter through the APIs to be able to
get the a human readable key description, such as 'rsa2048' or 'secp384r1'
of the key that was created.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Move functions checking for directory access to library
Stefan Berger [Thu, 17 Jun 2021 15:13:58 +0000 (11:13 -0400)]
swtpm_setup: Move functions checking for directory access to library

Move code from setpm_setup into new function check_directory_access
that checks for existence of directory and access to it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Replace ${SWTPM}.pid with swtpm.pid in PID filename in 2 test cases
Stefan Berger [Wed, 28 Jul 2021 12:49:40 +0000 (08:49 -0400)]
tests: Replace ${SWTPM}.pid with swtpm.pid in PID filename in 2 test cases

The PID filename was generated using the ${SWTPM} environment variable,
which caused test failures if set to a URL for example. Replace it with
'swptm'.

This issue was reported in issue #454.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoChange swtpm-localca to swtpm_localca in manpages
Nick Chevsky [Tue, 27 Jul 2021 18:54:45 +0000 (13:54 -0500)]
Change swtpm-localca to swtpm_localca in manpages

- Move content of swtpm-localca(8) manual page to swtpm_localca(8)
  and make swtpm-localca(8) an alias for swtpm_localca(8), mirroring
  the fact that /usr/bin/swtpm_localca is the actual program and
  /usr/share/swtpm/swtpm-localca a wrapper for it.
- Change references to `swtpm-localca` in manual pages' content to
  `swtpm_localca`, reflecting the actual name of the program they are
  meant to document.

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2 years agobuild-sys: Add MY_CFLAGS, CFLAGS, and MY_LDFLAGS to all Makefile.am's
Stefan Berger [Mon, 26 Jul 2021 20:57:24 +0000 (16:57 -0400)]
build-sys: Add MY_CFLAGS, CFLAGS, and MY_LDFLAGS to all Makefile.am's

Add MY_CFLAGS, CFLAGS, and MY_LDFLAGS to all Makefile.am's so that they
can be defined during configure time as well as CFLAGS added during
build time. LDFLAGS were already handled correctly during build-time.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Rename AM_CFLAGS/LDFLAGS to MY_CFLAGS/LDFLAGS
Stefan Berger [Tue, 27 Jul 2021 14:13:49 +0000 (10:13 -0400)]
build-sys: Rename AM_CFLAGS/LDFLAGS to MY_CFLAGS/LDFLAGS

To avoid the following warning use MY_ as a prefix for the offending
variables that have AM_ as a prefix:

configure.ac:587: warning: macro 'AM_CFLAGS' not found in library
configure.ac:590: warning: macro 'AM_LDFLAGS' not found in library

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoRevert "build-sys: Remove AC_SUBST() for AM_CFLAGS and AM_LDFLAGS"
Stefan Berger [Mon, 26 Jul 2021 20:57:54 +0000 (16:57 -0400)]
Revert "build-sys: Remove AC_SUBST() for AM_CFLAGS and AM_LDFLAGS"

This reverts commit 47f973ed71a2c6baec58ed5aa6c0106cff64add6.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoRevert "build-sys: Remove using AM_CFLAGS and AM_LDFLAGS"
Stefan Berger [Mon, 26 Jul 2021 20:57:49 +0000 (16:57 -0400)]
Revert "build-sys: Remove using AM_CFLAGS and AM_LDFLAGS"

This reverts commit 7f81d3128804fc4753d263ff39062fb706bc666c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoRevert "build-sys: Report $CFLAGS and $LDFLAGS at the end"
Stefan Berger [Mon, 26 Jul 2021 20:57:39 +0000 (16:57 -0400)]
Revert "build-sys: Report $CFLAGS and $LDFLAGS at the end"

This reverts commit 5c5856ea8fce978a20051e3efc4d7ad4c6e35d10.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoDebian packaging improvements
Nick Chevsky [Fri, 23 Jul 2021 20:15:22 +0000 (15:15 -0500)]
Debian packaging improvements

- debian/clean: Add files that were not being automatically cleaned
  up by dh(1)'s `clean` target.
- debian/control:
  - Add new recommended/required fields and bump Standards-Version.
  - Remove redundant build dependencies that are implied transitively.
  - Bump debhelper dependency version to match debian/compat.
  - Move swtpm-libs's ${misc:Pre-Depends} dependency to `Pre-Depends`.
    Resolves `depends-on-misc-pre-depends` Lintian warning.
  - Sort packages and dependency lists alphabetically as per
    wrap-and-sort(1).
- debian/not-installed: List deliberately non-installed files to
  avoid dh_missing(1) warnings.
- debian/rules:
  - Pass --no-scripts to dh_makeshlibs(1) in order to keep a
    ldconfig(8) trigger from being implicitly added, which for
    this package was redundant and triggered Lintian warning
    `package-has-unnecessary-activation-of-ldconfig-trigger`.
  - Remove redundant --parallel dh flag.
  - Remove redundant dh_usrlocal override.
- debian/*.install:
  - Add swtpm-create-tpmca(8) and its manpage, which were missing.
  - Remove redundant `#! /usr/bin/dh-exec` lines.
  - Sort entries alphabetically as per wrap-and-sort(1).
- debian/swtpm-tools.postinst.in: Add `set -e` to fail in case of
  error. Fixes `maintainer-script-ignores-errors` Lintian warning.

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2 years agoMove swtpm_localca sources from samples/ to src/
Nick Chevsky [Sat, 24 Jul 2021 18:54:40 +0000 (13:54 -0500)]
Move swtpm_localca sources from samples/ to src/

- Move swtpm_localca's sources out of samples/ (where they no longer
  belong now that swtpm_localca is a binary) to src/swtpm_localca/.
- Tests now call the swtpm_localca binary directly at the location
  where it was built, as they do with all other compiled programs.
- Simplify samples/swtpm-localca.in and delete swtpm-localca.2inst,
  removing the now-unnecessary logic to selectively call swtpm_localca
  from different locations (samples/ when running tests vs. /usr/bin/
  post-installation).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2 years agoMove swtpm_setup.conf.in from etc/ to samples/
Nick Chevsky [Wed, 21 Jul 2021 18:09:33 +0000 (13:09 -0500)]
Move swtpm_setup.conf.in from etc/ to samples/
- Makes swtpm_setup.conf.in consistent with the rest of the sample
  configuration files in swtpm, whose templates ship in samples/ and
  install the generated files to /etc.
- Works around dh_missing(1) erroneously reporting swtpm_setup.conf as
  non-installed due to its having two copies in the build tree (one in
  etc/ and another in debian/tmp/etc/).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2 years agoRemove swtpm.spec from .gitignore
Nick Chevsky [Wed, 21 Jul 2021 20:30:44 +0000 (15:30 -0500)]
Remove swtpm.spec from .gitignore
Even though swtpm.spec is an auto-generated file, the author would
like to keep it in the repository for ease of installing dependencies
during development. As long as the file is meant to be versioned, it
should not be in .gitignore. Discussion for context:
https://github.com/stefanberger/swtpm/pull/496#issuecomment-884432135

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>