Commit Graph

1661 Commits

Author SHA1 Message Date
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
607eb54b3e ci: Fix the github build action building libtpms in the container
Split the download and untarring from the build of libtpms so that the
build actually happens. Otherwise it was not building libtpms anymore but
seems to have been using a cached version of the container that had an
older version of libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 14:35:33 -04:00
Stefan Berger
d496df181a swtpm: Check whether SHA1 signature support is disabled in profile
To avoid setting the environment variable OPENSSL_ENABLE_SHA1_SIGNATURES
check whether SHA1 signature support is disabled in the TPM 2 profile.
It is disabled if either 'fips-host' or the pair 'no-sha1-signing' and
'no-sha1-verification' are found among the enabled attributes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 14:34:00 -04:00
Stefan Berger
0ddc7ed254 swtpm: Use TPMLIB_WasManufactured to check whether profile was applied
Use TPMLIB_WasManufactured to check whether a profile was applied since a
new instance was created. If a profile was given and no new TPM 2 instance
was created then display an error message and exit with an error code.
This avoids silently ignoring a provided profile that was not applied
since the TPM 2 instance already existed.

Make sure that a profile is only applied once by swtpm by clearing the
json_profile once TPMLIB_MainInit succeeded.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-30 17:29:03 -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
e5c9bf2467 ci: Installed docker-compose since it has gone missing
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-26 17:10:08 -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
863476868e swtpm: Display error messages if g_setenv fails
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-21 10:44:27 -04:00
Stefan Berger
8d31d88c69 swtpm: Determine whether OpenSSL needs to be configured (FIPs, SHA1 signature)
Get the list of enabled 'RuntimeAlgorithms' from libtpms and determine
whether any of these enabled algorithms is disabled in OpenSSL due to FIPS
mode. If FIPS mode on the host is enabled then disabled FIPS mode in
OpenSSL so that the TPM 2 can function properly.

The following algorithms are disabled when OpenSSL is in FIPS mode:
- camellia
- rsaes
- tdes
- ECC keys <224 bits
- RSA keys <2048 bits

Per openssl-ciphers man page it should be possible to disable the following
algorithms use by cipher-suites:

- AES128, AES256, AES
- CAMELLIA128, CAMELLIA256, CAMELLIA
- 3DES
- SHA1, SHA, SHA256, SHA384
- CBC

Note: It's not clear at what API level these are disabled. I have not been able
to use !SHA256 to disabled SHA256.

Also test whether signatures with SHA1 are working and enable them by setting
OPENSSL_ENABLE_SHA1_SIGNATURES=1.

The following output is expected for RHEL 9.x and CentOS 9 but does not
appear on Fedora 40 since there sha1 signatures are not (yet) disabled.

> swtpm socket \
    --tpmstate dir=/tmp/myvtpm \
    --ctrl type=tcp,port=2322 \
    --server type=tcp,port=2321,disconnect \
    --flags not-need-init,startup-clear \
    --log level=0 \
    --tpm2 \
    --profile name=null
Warning: Profile-enabled algorithms contain disabled 'RSA-1024-sign(SHA1, pkcs1-pss)'
Warning: Setting OPENSSL_ENABLE_SHA1_SIGNATURES=1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 20:53:53 -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
350b6a5a83 man: Describe profile option for swtpm_setup.conf
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-28 11:50:49 -04:00
ethan-thompson
b720d291b2 style: found and fixed some typos in the man pages
Signed-off-by: ethan-thompson <ethan.thompson@networkradius.com>
2024-07-26 15:56:52 -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
Stefan Berger
201de9a616 tests: Adjust sed expressions to work with BSD's sed
A version of sed on FreeBSD requires some adjustments to the sed
expressions for the test case to work. It does not support the
following:
- insertion of newline using '\n' -> replace with $'...\\\n...'
- request for matching of at least one character using '\+'
  -> replace with '*' to match any number

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-24 10:14:27 -04:00
Stefan Berger
4a7af5333f tests: Fix some issue with test for swtpm_setup --profile
Fix the following issues:
- use a regular expression instead of hard coded '4' to match
  StateFormatLevel number that will change in the future
- get all available profiles from running tpm rather than only the active
  profile -> use --info 0x40
- only compare with regular experssion if it is non-empty because
  this otherwise fails on Cygwin

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-23 16:47:08 -04:00
Stefan Berger
6a01a97e1d swtpm: Check whether bufferSize parameter is too small (Coverity)
Check whether the bufferSize parameter is too small and an underflow of the
expression bufferSize - offset could theoretically occur. However, in
practice this will never happen since the caller will always provide a
bufferSize of around 4kb.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-23 09:19:52 -04:00
Stefan Berger
88a89f4970 swtpm: Join parameters for string formatting
Since 'comma1' will always be true combine it with cmdarg_profile into one
string formatting parameter following the same formatting as further above.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-23 09:19:52 -04:00
Stefan Berger
415700e8f7 swtpm: Check for error code returned by sysconf call
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-23 09:19:52 -04:00
Stefan Berger
3c1e535efb tests: Move testing of profiles from a dev branch to master branch
Now that master has the profile support, make the test case also use it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 11:57:12 -04:00
Stefan Berger
eefbd3fb93 tests: Update to ibmtpm20tss v2.3.1 with rev183 tests
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 11:57:12 -04:00
Stefan Berger
77d42c9ac9 tests: Remove unncessary patches for ibmtss2 test suite
With swtpm now requiring libtpms >= 0.10 some of the patches applied to
the IBM TSS2 test suite have become obsolete. Remove them but also
have swtpm use the default-v1 profile that enables some of the newer
commands that were previously disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 11:57:12 -04:00
Stefan Berger
25eb5f75ea swtpm_setup: Read default profile from swtpm_setup.conf
If the user did not provide the profile on the command line read the
default profile from the swtpm_setup.conf configuration file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
96fe5afac7 swtpm: Add support for --print-profiles option
Add support for --print-profiles option to print all profiles supported
by libtpms.

Usage:

  swtpm socket --tpm2 --print-profiles | jq

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
62aaf0a251 tests: Add test case for testing profiles across libtpms versions
Add a test case for testing profiles across libtpms versions. For now only
an instance with the NULL profile is being tested with the latest libtpms
version and the state is then attempted to be used by libtpms v0.9.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
3785d49329 tests: Test the --profile option of swtpm_setup and swtpm
Implement test cases for swtpm_setup and swtpm exercising the
--profile option.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
8bfa8399b3 swtpm_setup: Print profile names as part of capabilities JSON
Print a list of names of profiles implemented by libtpms as part of the
capabilities JSON. The profiles map will only be visible if libtpms v0.10
with the TPMLIB_SetProfile() API is used.

swtpm_setup --print-capabilities --tpm2 | jq
{
  "type": "swtpm_setup",
  "features": [
    [...]
  ],
  "profiles": [
    "default-v1",
    "null",
    "custom"
  ],
  "version": "0.10.0"
}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
df11aeb6b9 swtpm_setup: Add support for --profile parameter
Add support for the --profile parameter that allows a user to select
a profile for the TPM 2 instance. The profile parameter must be a
string-formatted JSON map describing the profile to use.

Resolves: https://github.com/stefanberger/libtpms/issues/284
Resolves: https://github.com/stefanberger/swtpm/issues/710
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
3a49ce1302 swtpm: Print profile names as part of capabilities JSON
Print a list of names of profiles implemented by libtpms as part of the
capabilities JSON. The profiles map will only be visible if libtpms v0.10
with the TPMLIB_SetProfile() API is used.

swtpm socket --print-capabilities  --tpm2| jq
{
  "type": "swtpm",
  "features": [
    [...]
  ],
  "profiles": {
    "names": [
      "default-v1",
      "null",
      "custom"
    ],
    ...
  },
  "version": "0.10.0"
}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
fb9ef19ac8 swtpm: Display new capability to allow setting a profile
Display the new capability verb 'cmdarg-profile' indicating that the
--profile option with the name= and profile= parameters is supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
0184b9113d swtpm: Add support for --profile option to set a profile on TPM 2
Add support for the --profile option for a TPM 2. The 'name=' parameter
allows a user to select a specific profile available in libtpms. The
'profile=' parameter allows a user to pass a JSON profile that must
contain a name field with a profile known to libtpms. It may contain
an algorithm field that has a comma-separated list of verbs with the
names of algorithms that the TPM 2 is supposed to provide.

The --profile option only has an effect the first time a TPM 2 is started
since afterwards whenever the state of the TPM 2 is read, the profile
found in the state is being used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
02ca22e7f6 swtpm: Support parsing of JSON maps as option values
Allow passing a JSON map as part of an option value in the format of
--foo name={...},... Prior to this patch this would not have worked since
the option values were broken apart around commas, which a map may also
contain. Now, if a '{' is following the '=', the value is attempted to be
parsed as a JSON map and the end of the map is searched considering
possibly embedded maps.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Stefan Berger
718714e9f2 build-sys: Require that libtpms v0.10 is available for TPMLIB_SetProfile
Libtpms v0.10 adds the TPMLIB_SetProfile call that swtpm needs to set a
profile. Check whether the API call is available in the local libtpms
installation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 09:46:58 -04:00
Boris Glimcher
103616f3b7 ci: disable ARM docker build for now
And fixing default branch name

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-19 11:52:37 -04:00
Boris Glimcher
319a4840f1 Publish docker image also to DockerHub
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-19 11:52:37 -04:00
Boris Glimcher
52546d50d1 ci: add new release action to run when published
It is better to have it as separate action.
So it can grow with nore thiungs to do on release.

It calls existing docker build and push to avoid duplication.

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-18 16:48:21 -04:00
Boris Glimcher
4135ee7e5b ci: add testing via docker compose
Auto testing as well as good example on:
how to run SWTPM in docker or compose.

Simply run `docker-compose up` to bring both swtpm and test.
Or run `docker-compose up --build --force-recreate` to re-build.
Or run `docker-compose up swtpm` to only start swtpm service without
test.

Added new job in the github action to automate this as well.

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-18 16:48:21 -04:00
Boris Glimcher
4d22ce8a22 ci: adding linter and builder github action
Fixes #869

Using popular Hadolint linter for dockers.
Using standard GitHub action for building.

Build will also publish to GHCR after PR is merged, not before.

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-18 16:48:21 -04:00
Boris Glimcher
7d6aac0434 Adding alpine based dockerfile
Fixed #869

Used multi-stage build here to reduce final image size.
Builder should have packages for dev and compile.
Final image should only have dependencies for runtime.

Building is simple using `docker build .` command.

Or `docker build --build-arg="LIBTPMS_BRANCH=v0.9.6" .`
if you want another branch/tag of libtpms.

Next patch will add:
- linter
- build
- tpm2 tools testing

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-18 16:48:21 -04:00
Stefan Berger
cc9ee0fbc6 swtpm_setup: Get default rsa keysize from setup_setup.conf if not given
If the user did not provide the RSA keysize to use try to read it from
setup_setup.conf and if nothing is found there fall back to using the
internal default RSA keysize (2048).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-17 18:34:25 -04:00
Stefan Berger
5dfc42c622 swtpm_setup: Factor-out read_file_lines from get_default_pcr_banks
Factor-out read_file_lines from get_default_pcr_banks and pass the array
of lines from the config file into get_default_pcr_banks now. Now other
functions will also be able to access the lines from the config file
without having to re-read the config file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-17 18:34:25 -04:00
Marc-André Lureau
d6ca69ad46 tests: drop the need to set INSTALLED=1 when running tests
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 10:38:38 -04:00
Marc-André Lureau
24b8e202b6 tests: teach them to run installed
Rely on "common" variables.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 10:38:38 -04:00