Commit Graph

1661 Commits

Author SHA1 Message Date
Stefan Berger
72f2022827 swtpm_setup: Support --profile-file-fd to read profile from file descriptor
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -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
d488dbe7fd swtpm: Support --profile fd=<fd> to read profile from file descriptor
Enable reading a profile from a given file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
3171cbae02 swtpm: Support --profile file=<filename> to read profile from file
Enable reading a profile from a file.

If setting a profile fails, display the profile in the error message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
9ef3db088a swtpm: Return error if json_parser_get_root returns NULL
An empty input string will for example cause json_parser_get_root to return
NULL. Return early in this case to avoid glib error messages.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
12f7f004e7 swtpm: check for len > 0 before calling strncmp
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
3d0fb38187 swtpm: Convert json_get_submap to use g_autoptr on variables
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 13:37:15 -04:00
Stefan Berger
748e6c0f66 swtpm: Initialize seccomp_action with default value
Initialize seccomp_action with a default value that it will also
get assigned when handle_seccomp_options is called. This is done
to silence a static analyzer even though it's not necessary.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 09:20:08 -04:00
Stefan Berger
65c7c72959 swtpm: Implement concat_varrays and fix casts in concat_array calls
Implement concat_varrays that takes gchar ** as input and returns gchar **.
The concat_arrays has the identical implementation but takes const gchar **
as parameters and returns const gchar **. Use concat_arrays from
concat_varrays. Adjust all callers to cast arrays with constant strings to
const gchar *[] when calling concat_arrays. Modify some callers to call
concat_varrays now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 09:20:08 -04:00
Stefan Berger
dba5fa616e utils: Implement wrappers for g_spawn_sync and g_spawn_async
Implement warpper for g_spawn_sync and g_spawn_async that that take argv
and envp arguments as 'const gchar **' since they will be called like
this from swtpm_localca and swtpm_setup. Internally glib also uses the
parameters like this when calling fork_exec() for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 09:20:08 -04:00
Stefan Berger
402c31df25 swtpm_setup: Initialize key_description with a default string
Initialize key_description with a default string rather than using it
possibly uninitialized. In practice it would never be used uninitialized
since if a platform certificate is to be created, then the ek certificate
would have also been created and therefore swtpm2->ops->create_ek()
would have been called and set key_description.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
bdb8327bab swtpm_bios: Use const char * where a constant string is assigned later
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
871fb98167 swtpm_bios: Prefix all global variables with g_
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
40eb964a81 swtpm_cert: Add void to functions without parameters
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
6748e30f30 swtpm: cuse: Rename global msg to g_msg to avoid shadowing in places
Avoid shadowing global msg through local variables with the same name
by renaming the global msg to g_msg.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
60ca849a57 swtpm: cuse: Remove unused passwd variable
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
245e3d79a3 swtpm: cuse: Add SWTPM_ATTR_UNUSED to an unused variable
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
d8b2ab4758 swtpm: Use variable for malloc rather than size of struct
Avoid this type of complaint from static analyzer:

src/swtpm/tpmlib.c:392:37: note: Result of 'malloc' is converted to a
   pointer of type 'unsigned char', which is incompatible with sizeof
   operand type 'struct tpm_resp_header'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
9ae02d555f swtpm: Cast parameter to OSSL_PARAM_construct_utf8_string
OSSL_PARAM_construct_utf8_string takes a char * as parameter.
The OpenSSL code base casts constant strings to char *, so we can do this
also.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
d6c9ebbcbd swtpm: Prefix global variables with g_
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
45063edb9f swtpm: Make tpm_running a parameter to mainLoop
Remove tpm_running as a global variable to make it a parameter to
mainLoop.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
de5a99f9bb swtpm: Convert char * initialized with constant strings to const char *
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
f28d2ec722 swtpm: Cast to char * to avoid arithmetic on void *
To avoid arithmetic on void * cast the variable to char *.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
0056d9b5ee swtpm: Change order of parameters to calloc
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
1416fbf4dc swtpm: Make variable a const char * that is assigned a constant string
serverdata will be assiged a const char * later on, therefore make it a
const char *. This can then also be passed into options_parse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
91178e92aa swtpm: Convert options_parse function to take const char *
Some function pass a const char * into the options parse function.
Therefore, convert it to accept a const char * now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-22 16:03:36 -04:00
Stefan Berger
e63fb9acf1 swtpm_setup: Always log the active profile
Extend the list of SWTPM_INFO flags with recently added flags for
TPMLIB_GetInfo. Use the CMD_GET_INFO control channel command to get
the currently active profile for a TPM 2 from swtpm and display it in
the log unless it is reconfigured.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-20 10:18:21 -04:00
Stefan Berger
9edfc18b3e swtpm: Have tpmlib_maybe_configure_openssl return -1 on error
The single caller does not need to be adjusted.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-19 20:59:56 -04:00
Stefan Berger
8f7a57561f swtpm: Have json_get_submap_value return -1 on error
None of its callers need to be adjusted.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-19 20:59:56 -04:00
Stefan Berger
2ede504c75 swtpm: Have get_profiles return -1 on error
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-19 20:59:56 -04:00
Stefan Berger
12b0b4013a swtpm: Have json_get/set_map_key_value return negative error codes
Adjust all callers.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-19 20:59:56 -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
bd91c7628d swtpm: Fix a typo in a return code
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
017f99cedd swtpm: Implement a check for HMAC+sha1 for testing future restrictions
HMAC+sha1 may be restricted next, so test for it but do not support
forced removal of support for it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-17 11:44:27 -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
8e497a6a60 swtpm: Implement functions to get and set key values in a JSON map
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-16 13:20:46 -04:00
Stefan Berger
be1f9cd75c swtpm: Implement strv_remove, strv_dedup, and strv_extend
strv_remove: Remove matches from a 2nd array in a 1st array
strv_dedup:  Remove duplicates in an array
strv_extend: Append elements of a 2nd array to a 1st array

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-16 13:20:46 -04:00
Stefan Berger
db6f67b25b swtpm: Prefix public function from check_algos with 'check_'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-16 13:20:46 -04:00
Stefan Berger
a946f381f9 swtpm: Convert check_rsaes to check_rsa_encryption
Convert check_rsaes to check_rsa_encryption that can also be used for
testing of unpadded RSA encryption.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-16 13:20:46 -04:00
Stefan Berger
da9e7636b7 swtpm: Use the padding parameter passed to swtpm_rsa_sign
Do not ignore the padding parameter passed to swtpm_rsasign but use
it as parameter to the OpenSSL function.

Change "rsapss" to "tsassa" in one case where it was wrong.

Also rename swtpm_rsasign to swtpm_rsa_sign.

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
46c95ff849 swtpm: Add SWTPM_ATTR_UNUSED to unused function parameters
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-13 16:02:58 -04:00
Stefan Berger
28292591cb CI/CD: Avoid caching of container build to get latest libtpms version
Avoid caching of container builds to get latest libtpms version and therefore
pass tests that depend on changes to libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-12 10:35:47 -04:00
Stefan Berger
cc8591ba93 man: Add missing cmdarg-profile to swtpm_setup man page
Add missing cmdarg-profile to the man page of swtpm_setup and adjust the
order to follow the order of the application output.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-10 08:01:41 -04:00