Commit Graph

191 Commits

Author SHA1 Message Date
Stefan Berger
f6f858eada man: Add some clarification to the nameing of profiles in files
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-08 11:57:26 -05:00
Stefan Berger
2c8865a3ac man: Format JSON maps for better display
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-08 11:57:26 -05: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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
4b008b9067 Revert "utils: Implement find_program() to try BINDIR path before PATH"
Test cases using swtpm_localca were failing because swtpm_localca
now picked up the swtpm_cert installed in /usr/bin/swtpm_cert rather
than the one in the PATH. This revert fixes the issue and users will
have to adjust their PATH for out-of-PATH installations.

Resolves: https://github.com/stefanberger/swtpm/issues/829
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-09-01 22:48:45 -04:00
Stefan Berger
1950b1765d swtpm_localca: Add support for up to 20 bytes serial numbers
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-22 21:21:03 -04:00
Stefan Berger
3e93c9b324 swtpm_localca: Introduce --key as more generic alias for --ek
swtpm_localca may also receive the key parameters of other keys than
the ek, therefore introduce the --key alias for --ek and rename the
variable ekparmas to key_params throughout the code.

Extend the man page to describe the --key option as an alias that
is to be used for other public key parameters than specifically those
of an ek.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 11:36:21 -04:00
Stefan Berger
004aa538dd man: Fix a few spelling mistakes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-17 20:46:43 -04:00
Stefan Berger
ee0bce1bdf utils: Implement find_program() to try BINDIR path before PATH
To support install paths that are not covered by $PATH, and still allow
swtpm_setup and swtpm_localca to find swtpm and swtpm_cert executables,
implement find_program() to prepend the install path if only the program
name is given and otherwise fall back to g_find_program_in_path().

Update the man page stating that swtpm from the installation directory
(BINDIR) is tried to be used before one is attempted to be found in
the PATH.

Resolves: https://github.com/stefanberger/swtpm/issues/795
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-04-17 10:55:16 -04:00
Stefan Berger
dbcb69d0ee man8: Update swtpm-create-tpmca with missing TPM 2 reference
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-22 17:27:05 -05:00
Michal Privoznik
a78d02ceec man: Install swtpm_cuse.8 iff WITH_CUSE
Users have option to disable CUSE interface (just pass
--without-cuse argument to the configure script). But the
swtpm_cuse.8 man page is installed regardless of the argument.
This leaves distros having to remove the file before packing
builddir into packages.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-12-21 13:54:38 -05:00
Stefan Berger
6ecf5880ed swtpm: Implement terminate parameter for ctrl channel loss
Implement support for the terminate parameter for the control channel
option so that swtpm terminates once the control channel connection is
lost. The primary use case is QEMU that holds the control channel
permanently.

Resolves: https://github.com/stefanberger/swtpm/issues/753
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 13:27:38 -04:00
Stefan Berger
448f6326d7 swtpm,man: Clarify that --terminate works only for TCP data channel
The --terminate option is only for the TCP data channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-21 17:20:18 -04:00
Stefan Berger
6fbb219db9 swtpm: Implement CMD_LOCK_STORAGE to lock storage
Implement CMD_LOCK_STORAGE / PTM_LOCK_STORAGE for a user to be able to
lock the storage of the storage backend (if supported) after its lock
has been released for example when the 'savestate' blob was received
while the TPM state was migrated.

Also adjust test case and extend man pages.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-06 14:08:45 -04:00
Stefan Berger
e821754bb6 swtpm: Advertise --migration option in capabilities JSON
Advertise the capability of supporting the --migration option
in the capabilies JSON that now has the cmdarg-migration verb:

$ swtpm socket --print-capabilities | jq
{
  "type": "swtpm",
  "features": [
    "tpm-1.2",
    "tpm-2.0",
    "tpm-send-command-header",
    "flags-opt-startup",
    "flags-opt-disable-auto-shutdown",
    "cmdarg-seccomp",
    "cmdarg-key-fd",
    "cmdarg-pwd-fd",
    "cmdarg-print-states",
    "cmdarg-migration",
    "nvram-backend-dir",
    "nvram-backend-file"
  ],
  "version": "0.8.0"
}

Adjust test cases and extend man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-06 14:08:45 -04:00
Stefan Berger
120d414693 swtpm: Implement release-lock-outgoing parameter for --migration option
Implement the release-lock-outgoing parameter for the --migration option
that causes the storage lock to be released once the 'savestate' blob
transfer has been initiated. To not release the lock too early users must
first get the 'permanent' and 'volatile' state blobs and the 'savestate'
blob must be transferred as the last blob.

When migrating a VM the migration may fail and execution will then resume
on the originating side. In this fallback case the swtpm on the
destination side may need some time to terminate and release the lock.
Therefore, add a loop to the code attempting to re-lock the storage
directory on the source side for a few times until on the destination
side swtpm has released the lock. Retry the locking for 100 times
with 10ms in between. The retries will only ever be necessary if a TPM
command is immediately executed upon resume [this may be difficult
to test]. The negative side effects of this could be that the loop is not
long enough to grab the lock or that a short-duration TPM command will
time out inside the VM due to the retries delaying when it is processed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/724
2022-09-06 14:08:45 -04:00
Stefan Berger
8a2bbeceba swtpm: Introduce --migration option and 'incoming' parameter
Introduce the --migration option along with the 'incoming' parameter
that allows to defer the locking of the storage until either

- the reception of the TPM's state is started
- a TPM command is about to be processed

Note that the reception of CMD_INIT does not enable the storage lock.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/724
2022-09-06 14:08:45 -04:00
Stefan Berger
cdc39fd977 swtpm: Advertise the --chroot option with cmdarg-chroot
Advertise the availability of the chroot option with the cmdarg-chroot
verb. Document it in the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-08-25 13:13:20 -04:00
Jennifer Herbert
68e5428492 swtpm: Add a chroot option
Add an option to enter a chroot after starting swtpm. This is useful for
sandboxing purposes. When this option is used, it is expected that swtpm
is started as root and the --runas option is used to subsequently drop
privileges (otherwise the chroot could be escaped).

Signed-off-by: Jennifer Herbert <jennifer.herbert@citrix.com>
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2022-08-25 10:04:35 -04:00
Stefan Berger
97e910af58 swtpm: Introduce disable-auto-shutdown flag for --flags option
Introduce disable-auto-shutdown flag for the --flags option to disable
the sending of TPM2_Shutdown() if swtpm determines that it needs to send
this command to a TPM 2 before device reset or swtpm program termination.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-08-18 09:50:16 -04:00
Stefan Berger
9b3add22ac swtpm: If necessary send TPM2_Shutdown() before TPMLIB_Terminate()
If necessary send a TPM2_Shutdown() command to libtpms before processing
CMD_INIT. However, this is only necessary for a TPM 2 and only if the
TPM2_Shutdown command has not been sent by the client (VM TPM driver) as
the last command as it should do under normal circumstances, for example
upon graceful VM shutdown.

This fixes a bug where abrupt VM resets may trigger the TPM 2's dictionary
attack lockout logic due to the TPM 2 not having received a TPM2_Shutdown
command before it was reset using CMD_INIT for example. An OS driver is
typically supposed to send a TPM2_Shutdown to the TPM 2 but an abrupt VM
reset prevents it.

There are 3 control commands where this needs to be done since they
call TPMLIB_Terminate():

- CMD_STOP:
   This command is typically called before setting the state blobs of the
   TPM or before configuring the buffer size [QEMU, test cases].

- CMD_INIT:
   This command is called for resetting and initializing the TPM 2.

- CMD_SHUTDOWN:
   This command is called for a graceful shutdown of the TPM 2.

There are no negative side effects to be expected if TPM2_Shutdown()
is sent before any of these. Also, since none of these are sent before
the state of the TPM is marshalled (for migration for example) migrated
state will not have a TPM2_Shutdown() applied to it (accidentally).

Edk2 sends a sequence of TPM2_Shutdown(SU_STATE) + TPM2_GetRandom()
before suspend-to-ram. Upon wake up a CMD_INIT is sent to the TPM to
reset it, which in this case now requires a TPM2_Shutdown(SU_STATE)
to be sent to the TPM 2 so that certain TPM 2 state is available
again upon resume. To avoid invaliding the SU_STATE, first send a
TPM2_Shutdown(SU_STATE) in *all cases* and only if this fails send a
TPM2_Shutdown(SU_CLEAR). This way the internal state is preserved and
the VM (or user) are expected to use TPM2_Startup(SU_CLEAR) when
staring up the TPM 2 and no previous state needs to be resumed.

Note: The VM's firmware is trusted to use SU_CLEAR under normal circum-
stances and SU_STATE upon resume. So it wouldn't restore the state if
it wasn't needed.

Note: The TPM 2 spec describes the command as follows:

"This command is used to prepare the TPM for a power cycle. The
shutdownType parameter indicates how the subsequent TPM2_Startup() will be
processed.[...]
This command saves TPM state but does not change the state other than the
internal indication that the context has been saved. The TPM shall
continue to accept commands. If a subsequent command changes TPM state
saved by this command, then the effect of this command is nullified. The
TPM MAY nullify this command for any subsequent command rather than check
whether the command changed state saved by this command. If this command
is nullified and if no TPM2_Shutdown() occurs before the next
TPM2_Startup(), then the next TPM2_Startup() shall be
TPM2_Startup(CLEAR)."

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2087538
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-08-18 09:50:16 -04:00
Stefan Berger
0fb6f9001b man: Replace swtpm_cuse man page with redirect to swtpm man page
The swtpm man page also covers the CUSE TPM, so do not maintain the
swtpm_cuse man page anymore but replace it with a redirect to the swtpm
mane page instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-08-10 19:30:35 -04:00
Stefan Berger
5796d4895f man: Add missing .config directory to path description when using ${HOME}
When the ${HOME} directory is used for finding swtpm_setup.conf it is
to be found in ${HOME}/.config/swtpm_setup.conf.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/664
2022-02-23 09:17:11 -05:00
Seunghun Han
33aa135545 Move *.conf and *.options to man5
According to the man page sections guideline, man8 should be used
for system administration commands. So this commit moves *.conf and
*.options files to man5.

Signed-off-by: Seunghun Han <kkamagui@gmail.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-22 18:30:17 -05:00
Stefan Berger
25d4ac2d3a swtpm_setup: Add support for --reconfigure flag to change active PCR banks
Add support for --reconfigure option for the swtpm_setup to be able to
change the active PCR banks. This option only works with --tpm2 and does
not allow to pass several other options such --create-ek or
--create-ek-cert or --create-platform-cert that would alter the state of
the TPM 2 in other ways.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-05 06:39:49 -04:00
Stefan Berger
a5cc0bf6e2 swtpm_setup: Get active PCR banks from swtpm_setup.conf
If the user did not provide the PCR banks to activate through the command
line options, try to read it from the config file and if nothing is found
there, fall back to the DEFAULT_PCR_BANKS as set during configure time.

Move the check for the PCR banks after the access check to the
configuration file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:36:35 -04:00
Stefan Berger
4641f19f21 man: Add version when feature was added when missing fix some others
Add the version to items indicating when the feature was added.
Fix and unify some other ones.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:16:15 -04:00