Commit Graph

1666 Commits

Author SHA1 Message Date
Stefan Berger
5c4b2ba3a1 swtpm_setup: Create IAK hwSerialNum from data extracted from EK cert
Create the IAK hwSerialNum from the authority key identifier and
serial number extracted from the EK certificate.

Adjust a test script that now needs to use a valid certificate for the EK
so that we can get the authority key identifier and serial from it to
create the serial number for the IAK certificate.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-31 09:49:11 -04:00
Stefan Berger
969f50f9c6 swtpm_setup: Create IAK and IDevID keys and certificates
Extend swtpm_setup to create IAK and IDevID keys and certificates.

Use the same CA for signing the IAK and IDevID certificates as used for
the EK and platform certificates since all these certificates are issued
at the same time anyway.

Add documentation to the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-31 09:49:11 -04:00
Stefan Berger
25450f5dc1 swtpm_setup: Prepare primary EC key creation with 2 different nonces
Prepare the code to allow EC keys to be created with 2 different nonces.
So far always 2 identical nonces were used in all templates.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-31 09:46:44 -04:00
Stefan Berger
1d864bc987 swtpm_localca: Add support for creating IAK and IDevID certs
Add documentation to the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-31 09:46:44 -04:00
Stefan Berger
9b682820ac swtpm_localca: Add support for --tpm-serial-num command line option
Add support for the --tpm-serial-num command line option to pass it on to
swtpm_cert.

Make the vmid part of the serialNumber of the subject passed to
swtpm_cert (following an email exchange with TCG IWG).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-31 09:46:44 -04:00
Stefan Berger
ea22c92e61 swtpm_cert: Add support for creating IAK and IDevID certificates
Add support for certificate types iak and idevid. Both require the new
command line option --tpm-serial-num to be passed.

Add support for creating the ASN.1 for the SAN for the new certificates.

Advertise the support for the new certificate types using the capabilities
JSON with entries "cmdarg-tpm-serial-num" and "supports-iak-idevid".

Add documentation to the man page and extend test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-31 09:46:44 -04:00
Stefan Berger
05f4d91989 test: Exit IBM TSS2 test early if it does not support swtpm
Check the help screen for necessary supported options since the IBM TSS2
test will have to be patched to support swtpm directly. If it does not
support it, exit the tests early with an error message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-28 21:19:33 -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