Commit Graph

1332 Commits

Author SHA1 Message Date
Eiichi Tsukata
20ca1eb311 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>
2021-08-18 16:06:20 -04:00
Stefan Berger
346dc3d512 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>
2021-08-14 16:01:37 -04:00
Stefan Berger
7edc44d576 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>
2021-08-13 17:13:22 -04:00
Stefan Berger
e43946a597 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>
2021-08-13 13:36:39 -04:00
Stefan Berger
8f57999d82 swtpm: Clear keys on heap at termination
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-13 10:34:40 -04:00
Eiichi Tsukata
59ad2983fd 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>
2021-08-13 07:15:05 -04:00
Eiichi Tsukata
86931b4f30 swtpm: Add "nvram-backend-dir" capability
Append "nvram-backend-dir" to --print-capabilities output.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2021-08-13 06:35:18 -04:00
Eiichi Tsukata
b82eb7e788 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>
2021-08-13 06:35:18 -04:00
Eiichi Tsukata
2d3deaef29 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>
2021-08-13 06:35:18 -04:00
Stefan Berger
3eac247752 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>
2021-08-10 09:38:48 -04:00
Stefan Berger
afef705061 swtpm_setup: Make error message better when swtpm is not an exectuable
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-10 09:38:48 -04:00
Stefan Berger
a93586190a tests: Fix test case number in case of test being skipped
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-10 09:38:48 -04:00
Marc-André Lureau
55404e260b man: update man pages with new capabilities
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-08-10 07:13:24 -04:00
Marc-André Lureau
155ccdf561 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>
2021-08-10 07:13:24 -04:00
Marc-André Lureau
c48dd1e279 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>
2021-08-10 07:13:24 -04:00
Stefan Berger
f1adde9f29 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>
2021-08-10 07:13:24 -04:00
Marc-André Lureau
da8752b1f7 swtpm: report 'tpm-1.2' & 'tpm-2.0' in --print-capabilities
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-08-10 07:13:24 -04:00
Marc-André Lureau
ccaf99f12c 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>
2021-08-10 07:13:24 -04:00
Nick Chevsky
6961ec4878 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>
2021-08-02 07:46:00 -04:00
Stefan Berger
6f7a1e2769 swtpm: Use the pollfd array's enums as indices when initializing the array
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-01 18:49:27 -04:00
Stefan Berger
a735e4c0b4 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>
2021-07-30 16:45:22 -04:00
Stefan Berger
78559edde9 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>
2021-07-30 16:45:22 -04:00
Stefan Berger
a4cead5a8a 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>
2021-07-30 16:45:22 -04:00
Stefan Berger
dbb1bbf87d 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>
2021-07-30 16:45:22 -04:00
Stefan Berger
545738181e 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>
2021-07-28 13:39:56 -04:00
Nick Chevsky
3d5ae5e1d6 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>
2021-07-27 20:05:41 -04:00
Stefan Berger
cab1e2186f 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>
2021-07-27 15:39:48 -04:00
Stefan Berger
da7338961b 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>
2021-07-27 15:39:48 -04:00
Stefan Berger
cbaf04b48d Revert "build-sys: Remove AC_SUBST() for AM_CFLAGS and AM_LDFLAGS"
This reverts commit 47f973ed71.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-27 15:39:48 -04:00
Stefan Berger
71a4e33adc Revert "build-sys: Remove using AM_CFLAGS and AM_LDFLAGS"
This reverts commit 7f81d31288.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-27 15:39:48 -04:00
Stefan Berger
c4ad8da0a6 Revert "build-sys: Report $CFLAGS and $LDFLAGS at the end"
This reverts commit 5c5856ea8f.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-27 15:39:48 -04:00
Nick Chevsky
4eb47cb0ca 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>
2021-07-26 17:22:41 -04:00
Nick Chevsky
ddc7521653 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>
2021-07-25 08:52:13 -04:00
Nick Chevsky
edfb8d8ad9 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>
2021-07-21 20:30:44 -04:00
Nick Chevsky
bc898369ee 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>
2021-07-21 18:05:26 -04:00
Nick Chevsky
bb6d019a2e Remove obsolete manpage for swtpm_setup.sh(8)
swtpm_setup.sh was replaced by swtpm_setup in v0.5.0.

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-21 16:05:54 -04:00
Stefan Berger
0ba20a2114 docs: Update INSTALL document
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-21 09:04:24 -04:00
Nick Chevsky
aab15ef386 Correct old reference to swtpm_setup.sh in manpage
swtpm_setup.sh(8) was replaced by swtpm_setup(8) in v0.5.0.

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-21 07:55:32 -04:00
Nick Chevsky
cbd3d39d0e Add missing title to swtpm-create-tpmca(8) manual page
Fixes `bad-whatis-entry` Lintian warning [1].

[1] https://lintian.debian.org/tags/bad-whatis-entry

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-21 07:34:26 -04:00
Nick Chevsky
d08db4b4c9 Improvements to .gitignore
- Add auto-generated files debian/autoreconf.*
- Remove *.patch (Quilt requires these under debian/patches/)

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-20 20:57:30 -04:00
Stefan Berger
50f7d49ad3 samples: Use different script for local testing than install
Use a different script for local testing that what is installed into
/usr/share/swtpm/swtpm-localca.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-17 09:28:54 -04:00
Stefan Berger
fd00c5ff87 samples: Replace swtpm_localca with script calling swtpm-localca (issue #482)
Replace the binary swtpm_localca with a script that now calls the binary
swtpm-localca, which is to be installed in $bindir.

So that we can use this for script for calling swtpm-localca during testing
(when it is not installed), write the script in such a way that it de-
termines whether there's swtpm-localca in the same directory and if not call
it from ${bindir}/swtpm-localca.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-16 16:03:14 -04:00
Stefan Berger
05f64f5529 swtpm_setup: Fix compiler errors when memcpy is a macro (Cygwin)
Since commit 502cb1129a -D_FORTIFY_SOURCE=2 is passed to the gcc
command line resulting in memcpy() becoming a macro on Cygwin, which
then causes the following compiler errors due to the anonymous arrays
being used:

swtpm.c: In function ‘swtpm_tpm2_createprimary_ek_rsa’:
swtpm.c:686:26: error: macro "memcpy" passed 34 arguments, but takes just 3
  686 |         }, authpolicy_len);
      |                          ^
In file included from /usr/include/string.h:180,
                 from swtpm.c:15:
/usr/include/ssp/string.h:97: note: macro "memcpy" defined here
   97 | #define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len)
      |
swtpm.c:682:9: error: statement with no effect [-Werror=unused-value]
  682 |         memcpy(authpolicy, (unsigned char []){
      |         ^~~~~~
swtpm.c:698:26: error: macro "memcpy" passed 50 arguments, but takes just 3
  698 |         }, authpolicy_len);
      |                          ^

The solution is to surround the anonymous array definitions with '( )'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-14 14:16:26 -04:00
Stefan Berger
3d75c96537 man8: Add missing '\' to list of pod files and reduce EXTRA_DIST files
Add a missing '\' to the list of pod files and reduce the EXTRA_DIST
files list to only those that available via git and not generated.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-13 22:19:38 -04:00
Stefan Berger
3acc2ee1ce tests: Add test_tpm2_save_load_state to the tests to run
The test test_tpm2_save_load_state seems to have been forgotten
about and was not run. Add it now to the the tests to run.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-13 18:23:39 -04:00
Andrea Bolognani
5e73e324bd configure: Fix spacing for HARDENING_*FLAGS
Currently multiple spaces are used when a single one would do,
which will still achieve the same result but is not quite as
aesthetically pleasing :)

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2021-07-08 08:29:02 -04:00
Andrea Bolognani
502cb1129a configure: Fix typo TPM2 -> TMP2
This will result in -D_FORTIFY_SOURCE=2 actually being added to
HARDENING_CFLAGS where applicable.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2021-07-08 08:29:02 -04:00
Stefan Berger
7be5d76679 test: Extend TPM 1.2 test case to also cover 'savestate'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-07 15:44:46 -04:00
Stefan Berger
b517f350a2 tests: Use --allow-signing with --decryption in some swtpm_setup test
To increase coverage, use --allow-signing along with --decryption in
some swtpm_setup test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-07 15:44:46 -04:00
Stefan Berger
978d22bcec tests: Add swtpm_setup test cases with --lock-nvram and --create-spk options
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-29 11:26:30 -04:00