Commit Graph

1661 Commits

Author SHA1 Message Date
Stefan Berger
9746c168f0 swtpm: Add flags-opt-recreate-svn-base-secret capability
Update test case checking for --tpm2 capabilities.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-28 09:32:16 -04:00
Stefan Berger
94bb06a1fc swtpm: Add support for recreate-svn-base-secret flags option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-28 09:32:16 -04:00
Stefan Berger
395ada34d8 tests: Update IBMTSS2 test suite to v2.4.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-24 18:20:01 -04:00
Stefan Berger
ab267bfe4a swtpm: Only display profile capabilities when --tpm2 is given
Only display profile capabilities when --tpm2 is given since they are only
relevant when a TPM 2 is used.

Adjust test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-23 19:44:57 -04:00
Stefan Berger
74a3d99b93 swtpm_setup: Give fields in tpm2_authblock better names
Give two oif the (unused) fields in the tpm2_authblock better names and
since these two and the continueSession fields are always initialized with
'0', simplify the initializer macro to only take one argument.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-18 15:07:36 -04:00
Stefan Berger
a72da2dfac tests: Extend regex's with optional match for Attributes in profiles
The default-v1 profile may soon also set Attributes in the JSON and
therefore extend the regular expressions matching profiles to optionally
match for Attributes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 17:56:11 -04:00
Stefan Berger
1eb06b6f79 swtpm_setup: Always lock storage while creating initial state
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
38aa3d972c swtpm: Display tpmstate-opt-lock as a new capability
Display the new capability tpmstate-opt-lock, adjust test cases,
and document it in the swptm man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
1d17d09158 swtpm: Add support for lock option parameter to tpmstate option
To support storage backend locking on the file backend, add support for a
lock option parameter to the --tpmstate option. By default the value of
this option (if not given) has to be 'true' for the dir backend, since this
backend has always been locking, and 'false' on the file backend, since
this backend did not lock so far.

If the user chooses no storage backend locking then SWTPM_NVRAM_Unlock &
SWTPM_NVRAM_Lock_Storage do not call the backend for locking at all
anymore.

Document the new option parameter in the swtpm man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
aa483aeb6d swtpm: nvstore_linear: Add support for file-backend locking
Add support for locking the storage file using fcntl(fd, F_SETLK, ...).
Since fcntl needs a file descriptor of the actual storage file, call
SWTPM_NVRAM_LinearFile_DoOpenURI() to open the file in case it has not
been opened, yet. In case of error close the file again but be careful
about the fact that it may not have been mmap'ed, yet.

Since now all backends have .lock and .unlock nvram_backend_ops, they can
be called without checking for a NULL pointer.

Extend an existing test case with a file-backend storage lock test.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
4be72bc65a swtpm: Remove broken logic to check for neither dir nor file backend
Remove the broken logic to check for neither dir:// nor file:// backend.
If an unknow backend type is used, then it will be detected later on
and an error message will be printed out. Even though the logic was
broken it didn't seem to cause failures.

Also have tpmstate_set_mode return void since it cannot fail.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
eb5875793e swtpm: nvstore_linear: Add comment to SWTPM_NVSTORE_LINEAR_MAX_STATES
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
fc57f557d8 swtpm: nvstore_linear_file: Initialize file descriptor to -1
Since 0 is a valid file descriptor and checks for valid file descriptors
is typically '>= 0', initialize the file descriptor to -1 to indicate
that it is unused.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
8ba4ec3c43 swtpm: Refactor parts into SWTPM_NVRAM_LinearFile_DoOpenURI
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 10:49:01 -04:00
Stefan Berger
e159d26671 tests: Use ${CERTTOOL} rather than certtool (OS X)
On OS X we have to use ${CERTTOOL} rather than certtool to get
gnutls-certtool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-13 19:46:15 -04:00
Stefan Berger
86e8f8b861 swtpm_setup: Rename parameter from optarg to opt_arg (OS X,Wshadow)
Rename the optarg parameter to opt_arg since compiler on OS X
gives a -Wshadow warning.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-13 19:46:15 -04:00
Stefan Berger
47f37b0551 swtpm_ioctl: Rename parameter from optarg to opt_arg (OS X,Wshadow)
Rename the optarg parameter to opt_arg since compiler on OS X
gives a -Wshadow warning.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-13 19:46:15 -04:00
Stefan Berger
799290d229 swtpm_bios: Rename parameter from optarg to opt_arg (OS X,Wshadow)
Rename the optarg parameter to opt_arg since compiler on OS X
gives a -Wshadow warning.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-13 19:46:15 -04:00
Stefan Berger
489483f100 swtpm: Fix typo in header guard #define
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-13 19:46:15 -04:00
Stefan Berger
06168658cb Revert "swtpm: Print message in case error response is too long"
This reverts commit 8d4b247e3d since
CMD_GET_STATEBLOB can have more than 4 bytes in response when an
error happened (long-standing protocol error).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-12 13:19:05 -04:00
Stefan Berger
8d4b247e3d swtpm: Print message in case error response is too long
All error messages must only be 4 bytes long. Print an error message if
this is not the case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-11 17:34:36 -04:00
Stefan Berger
3a0ff17329 swtpm_ioctl: Use ptm_cap_n for non-CUSE PTM_GET_CAPABILITY response
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-11 17:34:36 -04:00
Stefan Berger
47c96a0c64 swtpm: Use ptm_cap_n to build PTM_GET_CAPABILITY response
Use the new ptm_caps_n to create the response for PTM_GET_CAPABILITY in the
socket and chardev implementations. Due to how the result was created
before, the tpm_result part of the response will always have to be
TPM_SUCCESS, since it was always 0 before.

Leave the CUSE implementation untouched since there the result was returned
in native endianess resulting in the first 4 bytes carrying the capability
flags.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-11 17:34:36 -04:00
Stefan Berger
7499734f98 swtpm: Define a structure to return PTM_GET_CAPABILITY result
Define a structure to use for returning the PTM_GET_CAPABILITY result that
resembles the layout of all the commands' structures. Since only 17bits for
capabilities are currenlty defined and they are returned in big endian
format as part of a 64bit number, this change can be done without any side
effects. The upper 32bit of this number now become the tpm_result, which
will always be 0. The lower 32bits are the possible capability flags, of
which the 17 are used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-11 17:34:36 -04:00
Stefan Berger
f29b870b5a cuse: Move display of help screen into function
Move the display of the help screen into its own function to be able
to usage fprintf with the help screen as format string to avoid static
analyzer warnings.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-08 12:11:37 -04:00
Stefan Berger
7b2ee0ed2e tests: Test activation of PCR banks when not all are available
Restrict available PCR banks to sha256 & sha384 and try to enable sha256
and sha512 and check the expected results.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-08 10:42:47 -04:00
Stefan Berger
3f551e1dc1 swtpm: Implement --print-info to run TPMLIB_GetInfo with flags
Implement --print-info that takes a number as argument and uses this number
as flags to call TPMLIB_GetInfo with. Display the JSON string and exit.

Extend the man page and update other parts where swtpm_ioctl is not necessary
anymore to use.

Extend a test case to also check that swtpm now returns the same result as
swtpm_ioctl does.

Append cmdarg-print-info to printed out capabilties. Adjust test cases.
(Expect 'profiles' to always be part of capabilties JSON.)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-07 11:09:04 -04:00
Stefan Berger
770abf3ff0 tests: Fix a typo in the name of a profile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 18:20:18 -04:00
Stefan Berger
8f670605b5 tests: Enable SWTPM_TEST_PROFILE for running test_tpm2_ibmtss2 with profile
Enable SWTPM_TEST_PROFILE for running the test_tpm2_ibmtss2 test cases
with a user provided profile. Document it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 18:20:18 -04:00
Stefan Berger
2fee0e7bb5 man: Improvements and fixes to swtpm_setup manpage
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 18:20:18 -04:00
Stefan Berger
50e7429b5b man: Improvements and fixes to swtpm manpage
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 18:20:18 -04:00
Stefan Berger
c6db0e3185 swtpm: Support 'remove-disabled' for 'custom:'-prefixed profile names
Extend the support for 'remove-disabled' option parameter of the --profile
option to also work for profiles whose name starts with 'custom:'.

Modify an existing test case to use custom:test as profile name with this
option.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 18:20:18 -04:00
Stefan Berger
4faf8eca44 man: Better describe --get-info option parameters for swtpm_ioctl
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 18:20:18 -04:00
Stefan Berger
47d37ccba2 debian: Add rules for reading profiles from distro and local dirs
Allow a user to pass profiles from the distro or local dirs directly
to swtpm. A rule to allow reading profiles from somewhere under the
HOME directory already exists.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 09:35:17 -04:00
Stefan Berger
34e5103045 swtpm_setup: Implement --print-profiles to display all profiles
Implement support for the --print-profiles option to search the local
and distro profiles directories for profiles (files with .json extension)
and then get the built-in ones from swtpm. Print them all to stdout.

Extend a test case and add description to the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 09:35:17 -04:00
Stefan Berger
3d7b2445c3 swtpm_setup: Add profile entries to swtpm_setup.conf written by swtpm_setup
Have swtpm_setup --create-config-files write profile entries into
swtpm_setup.conf.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 09:35:17 -04:00
Stefan Berger
5486f0437f swtpm_setup: Add support for --profile-name option
Add support for --profile-name option that searches for a profile in a
configurable local directory or a distro directory
(typically /usr/share/swtpm/profiles).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-02 09:35:17 -04:00
Stefan Berger
7198e0d716 swtpm_setup: Accept profiles with name starting with 'custom:'
Accept profiles that start their name with 'custom:' and do not exceed
32 characters. The content of these profiles will be derived from the
built-in 'custom' profile unless Algorithms, Commands, or Attributes
are provided on the command line.

Adjust a test case to test with profile name starting with 'custom:'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-01 19:12:05 -04:00
Stefan Berger
82fb09c6a2 selinux: Change write to append for appending to log
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-01 09:57:34 -04:00
Stefan Berger
2d4a4c57cc selinux: Add rule for logging to svirt_image_t labeled files from swtpm_t
I was able to recreate the issue on one of my machines where swtpm_t
was trying to append to the log labeled with svirt_image_t. On another
machine this combination of labels does not seem to cause a problem.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2306817
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-30 21:32:22 -04:00
Stefan Berger
aa78a302ec swtpm: Display stderr in case swtpm --print-capabilities failed
When swtpm --print-capabilities for example fails to be able to access
the log file that swtpm_setup logs into, then it may fail to run. In
this case log the stderr output of swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-30 17:01:04 -04:00
Stefan Berger
2e2124928f swtpm_setup: Return error if reading of config file failed
Return an error if the reading of the config file failed so that
config_file_lines can never be NULL. Remove all checks for
config_file_lines == NULL.

It's very unlikely reading of the config file failed since there's a file
access check right before it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-27 15:12:58 -04:00
Stefan Berger
2e42685e6d swtpm_setup: Move checking access to and reading of config file into function
Move the checking of access to and reading of the configuration file into
its own function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-27 15:12:58 -04:00
Stefan Berger
e29457defc Dockerfile: Fix casing of 'as'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-25 07:20:37 -04:00
Stefan Berger
3a1be75d04 swtpm_setup: Fix counting of profile related options
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 16:58:06 -04:00
Stefan Berger
e91b27911f swtpm: Initialize empty array
Initialize the empty array authpolicy[0] to quiet a static analyzer.
This array only serves the purpose of providing a non-NULL pointer
when passed to memconcat.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 13:22:56 -04:00
Stefan Berger
c0589349c0 swtpm: Return TPM_FAIL from invalid header version case
Return TPM_FAIL in case of an invalid header version number to avoid a
potential segmentation fault when accessing an unavailable buffer due to
the header parser not returning an error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 13:22:56 -04:00
Stefan Berger
8ea14c6ea5 swtpm: Check gerror before calling g_error_free
To avoid glib warning messages check the gerror before calling
g_error_free with it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 13:22:56 -04:00
Stefan Berger
04ebf36775 build-sys: Add -Wshadow to the CFLAGS
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 13:22:56 -04:00
Stefan Berger
82e3f38a82 swtpm_setup: Support default profile from file in swtpm_setup.conf
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00