Commit Graph

456 Commits

Author SHA1 Message Date
Stefan Berger
bd77a3440a tests: Extend existing test case to use the new fsync option
Extend an existing test case to use the new fsync option to at least test
the option parser. That fsync() is actually being called is not easy to
observe.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-27 16:28:39 -04:00
Stefan Berger
093248eb4d swtpm: Add option for storage backend to use fsync
Add an option to have the storage backend use fsync whenever state is
written to disk. Advertise this capability with
'tpmstate-dir-backend-opt-fsync' and adjust a test case.

Only support for the directory-backend is implemented.

Extend the swtpm man page with a description of this new option.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-27 16:28:39 -04:00
Stefan Berger
4da66c66f9 tests: Retry NVWrite command after 0x922 return code and inc lockout counter
When returncode 0x922 is received from NVWrite then retry the command so
that it gets the expected error code from failing to provide a password.
When checking the lockout counter, increase the numbers now.

Patched versions of libtpms may not return 0x922 anymore, so write the code
that it can test both cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-12 18:46:28 -04:00
Stefan Berger
8f9166787c tests: Do not patch for OpenSSL 3.x anymore since bug seems fixed
A patch was applied to the IBMTSS2 test cases due to a bug in OpenSSL. At
least with OpenSSL 3.2.4 (and possibly much earlier), this bug has been
found to have been fixed, so disable the patching for now and leave a FIXME
in there directing that the code block can be removed entriely at some
point.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 13:17:39 -04:00
Stefan Berger
a4a9f336f5 tests: Use IBMTSS2 test v2.4.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 13:17:39 -04:00
Stefan Berger
732bbd6ad3 test: Extend existing test case with backup option
Extend an existing test case with the backup option for the directory
backend. Check correct behavior by trying to start swtpm with missing
state decryption key and ensure that file renamings are handled as
expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 08:44:42 -04:00
Stefan Berger
e3694b7b15 swtpm: Add option for storage backend to make a backup file
Add an option to have the storage backend make a backup file of
the permanent state file. Advertise this capability with
'tpmstate-dir-backend-opt-backup' and adjust a test case.

Extend the documentation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 08:44:42 -04:00
Stefan Berger
8a3592fb02 tests: Extend regex to allow for optional RSA-4096 keys
libtpms v0.11 will support RSA-4096 keys. Adjust the test case
regex for optional output of 'tpm2-rsa-keysize-4096'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-07 10:28:58 -04:00
Stefan Berger
4d2e967423 tests: Use proper command line options on GNU/Hurd systems
GNU/Hurd systems use the same sed/sha1sum/state command lines as Linux
and Cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 20:38:14 -04:00
Stefan Berger
7243fddab6 sample: Enable passing usual curve names secp256r1 or secp384r1
Enable passing the usual curve names of secp256r1 and secp384r1 instead
of ecc256 and ecc384 on the command line of swtpm-create-tpmca.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-01 12:50:34 -04:00
Stefan Berger
58c9549cdc samples: Support different key algorithms for created TPM 2 CA
Extend swtpm-create-tpm to support rsa2048 (default), rsa3072, ecc256
(NIST P256), and ecc384 (NIST P384) for the created TPM 2 CA. The names
are taken from the output of:

  tpm2_ptool addkey --help

ecc521 does not seem to work with the TPM 2 stack even though it is
advertised as a possible option.

Extend an existing test case to create an ecc256 key and extend man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-03-30 19:17:25 -04:00
Stefan Berger
64bbdcadad swtpm_setup: Do not pass a TPM 2 profile to swtpm when reconfiguring
Ensure that no profile is passed to the TPM 2 when it is to be reconfigured
by:

- Showing an error if user tries to pass a profile when also --reconfigure
  is passed
- Not taking the default profile from the swtpm_setup.conf configuration
  file if the user did not pass a profile

Extend an existing test case with a default profile in its swtpm_setup.conf
so that the above 2nd item is tested.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-03-28 11:35:22 -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
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
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
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
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
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
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
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
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
d5bfdafdc4 swtpm_setup: Support --profile-file <file> to read profile from file
Enable reading a profile from a file. Pass it as open file descriptor to
swtpm.

Adjust one test case to read a profile from a file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
cbaab161d3 swtpm: Ignore remove-disabled parameter on non-'custom' profile
Ignore the remove-disabled parameter on non-'custom' profile identified
by return value '1'. Switch to negative return values in the called function.

Extend a test case to ensure that the --profile-remove-disabled option
on swtpm_setup, which is passed through to swtpm, has no effect on 'null'
and 'default-v1' profiles.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-19 20:59:56 -04:00
Stefan Berger
6b1112aef2 swtpm: Check for good entropy source in chroot environment
Very old OpenSSL versions (e.g., 1.1.0i) are using /dev/urandom to get
entropy while newer ones are using the getrandom syscall that does not
need the device file. In some environments access to the created
/dev/urandom device file may not work (EACCESS; chroot test case) and
then OpenSSL will start failing operations that depend on good entropy.
Therefore, check the status of the random number generator after chroot.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-19 16:54:28 -04:00
Stefan Berger
51a13a7053 tests: Add a check for OPENSSL_ENABLE_SHA1_SIGNATURES in log file
CentOS 9 and RHEL >= 9.4 (maybe earlier also) are expected to log the
setting of OPENSSL_ENABLE_SHA1_SIGNATURES when a libtpms v0.9 state is
used where signing a SHA1 was allowed and needs to be enable with this
environment variable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-17 07:37:42 -04:00
Stefan Berger
1d2fd75bfd swtpm_setup: Implement --profile-remove-fips-disabled option
Implement the --profile-remove-fips-disabled option that is used to tell
swtpm to remove algorithms that are disabled by FIPS mode on the host.
Internally, this option passes the remove-fips-disabled option parameter
with the --profile option to swtpm.

Add a test cases passing this option and check that the resulting profiles
have key sizes adjusted and relevant attributes set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-16 13:20:46 -04:00
Stefan Berger
c3de83e7fe swtpm: Implement function to check whether a crypto algorithm is disabled
Implement a function that checks whether a crypto algorithm identified by
TPM algorithm identifiers is disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-16 13:20:46 -04:00
Stefan Berger
50a746ff11 test: Consolidate custom profile test cases and check for StateFormatLevel
Consoldiate some test cases related to the custom profile and add
additional checks for various StateFormatLevels.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-13 18:25:52 -04:00
Stefan Berger
02555ce58a tests: Convert test_samples_create_tpmca to run installed
Convert the TPM 1.2 test case test_samples_create_tpmca to be able to run
installed. It also needs to have the test_config file installed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-13 16:02:58 -04:00
Stefan Berger
f122f14a56 test: Wrap sed -i in sed-inplace
Since there is a BSD variant of sed that requires a parameter for the -i
option provide a sed-inplace wrapper script.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-13 16:02:58 -04:00
Stefan Berger
29b5a04031 test: Wrap install -D in fileinstall
Since there is a BSD variant of install that does not support the -D option
like install on Linux, provide a fileinstall wrapper script.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-13 16:02:58 -04:00
Stefan Berger
a0e9d4b3fe swtpm: Print cmdarg-print-profiles as part of capabilities
Commit 96fe5afa forgot to add cmdarg-print-profiles to the list of
capabilities. Also fix typo in the man page and sort shown output
to match application output.

Fixes: 96fe5afa ("swtpm: Add support for --print-profiles option")
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-10 08:01:41 -04:00
Stefan Berger
54583a87b5 tests: Mention test_tpm2_libtpms_versions_profiles requiring env. variables
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-27 09:07:02 -04:00
Marc-André Lureau
fe4b82c62d tests: fix installed test-tpm12
Use an absolute path for TESTDIR, as we refer to it from different
directories.

Also fix killing gone swtpm process.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-08-27 07:49:10 -04:00
Marc-André Lureau
d93a6c2f5f tests: source common under ${TESTDIR}
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-08-27 07:49:10 -04:00
Marc-André Lureau
603396664f tests: allow running ibmtss2 tests against installed version
Run against the installed version only when SWTPM_TEST_IBMTSS is
set to the directory that has the tests, otherwise, build the known
version.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-08-27 07:49:10 -04:00
Stefan Berger
0da1dcc8a3 tests: Derive support for CUSE from SWTPM_EXE help screen
Use 'swtpm --help | grep cuse' to determine whether CUSE interface
is supported and CUSE related tests need to run. Make sure that
SWTPM_EXE is available when test_cuse is sourced.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-26 20:00:14 -04:00
Stefan Berger
4ef45bc7f5 tests: Remove SWTPM variable and usage
SWTPM was set to 'swtpm' and only for uninstalled tests. Remove it and
replace its usage with 'swtpm' everywhere.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-26 20:00:14 -04:00
Stefan Berger
ec792ce855 tests: Convert more test cases to rely on variables from common
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-26 20:00:14 -04:00
Stefan Berger
1d6996ee87 tests: Skip test_tpm2_libtpms_versions_profiles if not run from git checkout
Skip the test_tpm2_libtpms_versions_profiles since it requires that swtpm is
built from a git checkout so that various versions of swtpm can be built.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-26 20:00:14 -04:00
Stefan Berger
5677f2caf5 tests: Set OPENSSL_ENABLE_SHA1_SIGNATURES=1 for IBMTSS2 test
The IBMTSS2 tests suite creates signatures over SHA1 that may now fail on
RHEL 9.x and CentOS 9. To have these tests succeed set
OPENSSL_ENABLE_SHA1_SIGNATURES=1 so the tests do not need to be modified
and also check that the TPM 2 can handle SHA1 signatures as before.
'swtpm socket --tpm2' should set this environment variable automatically
if needed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-21 12:13:26 -04:00
Stefan Berger
f54ba57448 tests: Add missing 7th parameter to function call
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 11:39:03 -04:00
Stefan Berger
e3cdb5d29c tests: Update IBMTSS2 test suite to v2.3.2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-19 10:59:31 -04:00
Stefan Berger
40ee803480 tests: Extend test case testing across libtpms versions
- Use 3072bit RSA keys if possible; not possible on Ubuntu 22.04
- Add test case with NIST p256 key and signing
- Store modified files in git repo *after* the copy of the repo
- Suppress more tools output

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-24 20:46:42 -04:00