Commit Graph

1523 Commits

Author SHA1 Message Date
Stefan Berger
a61c08a4c7 build-sys: Only display warning if pkg-config for gmp fails
Since many older gmp development packages do not provide the pkg-config
file for gmp, just display a warning and fall back to default values.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-28 12:19:42 -04:00
Stefan Berger
3068b48d18 tests: Add missing 'exit 1' on unexpected file size on --reconfigure
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 17:19:29 -04:00
Stefan Berger
116953fb1d tests: Add test cases for swtpm_cert with max serial number
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 17:19:29 -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
c877bec553 swtpm_cert: Add support for serial numbers up to 20 bytes long
x509 certificate serial numbers can be up to 20 bytes long.
Support this via gmp library.

A serial number must not have its most significant bit set, which
would indicate a negative number. If this is the case, insert '0'
as the first byte.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-22 21:21:03 -04:00
Stefan Berger
605e0ce880 build-sys/rpm/debian: Add gmp library and devel package as dependency
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-22 21:21:03 -04:00
Stefan Berger
6a2c342798 utils: Add 'const' to input parameter of type 'unsigned char *'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-21 19:01:38 -04:00
Stefan Berger
a96509723f swtpm_setup: Flush spk after persisting to create room for another key
Future extensions will need room for another key, so flush the spk after
persisting it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 11:36:21 -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
f29b46f961 swtpm_setup: Refactor duplicate code into swtpm_tpm2_write_cert_nvram
Also rename the variable purpose to certtype since this better describes
what it is.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
2c96242d13 swtpm_setup: Move persisting of certificate into tpm2_persist_certificate
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
b3683ba107 swtpm_setup: Pass key_type to function creating filename for key
To make the function creating filenames for keys less ek-specific,
pass the key_type, such as "ek", into this function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
f03c5aaf71 swtpm_setup: Add scheme parameter before curveid to createprimary_ecc
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
536f545042 swtpm_setup: Rename is_ek to preserve for future extension
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
9a01be7c83 swtpm_setup: Mask-out EK and plaform certificate flags and set cert_flags
To be able to extend the flags_to_certfiles array with new certifcates
while carrying new flags for new certificate, mask-out exising EK and
platform certificate flags and set the cert_flags variable with it to limit
the view of the entries in the table.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
4617e835c6 swtpm_setup: Move common code into new function read_certificate_file()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
32a53e5c9f swtpm_utils: Use SWTPM_G_FREE macro to free memory and set pointer to NULL
Use the macro in swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
efa030b9da tests: reformat regexs for easier readability and extension
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
673ee421d2 rpm: Set BSD-3-Clause for the License on each subpackage
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-16 16:29:05 -04:00
Stefan Berger
b9e6d7c686 rpm: Split off SELinux files to build an selinux package
Follow the changes in Fedora to build a separate swtpm-selinux package
so that swtpm can also be installed without SELinux on the system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 12:36:31 -04:00
Stefan Berger
63825b296c SELinux: Add rules for user_tpm_t:sockfile to allow unlink
With a memoryBacking node added to the libvirt domain XML, the unlink
permission on user_tmp_t:sockfile becomes necessary to avoid an avc
denial.

  <currentMemory unit='KiB'>2097152</currentMemory>
  <memoryBacking>
    <hugepages>
      <page size='2048' unit='KiB'/>
    </hugepages>
  </memoryBacking>

Also add the unlink permission to the other occurrences of sock_file.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2165142
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 10:30:08 -04:00
Stefan Berger
7dac1dbf6f SELinux: Add rules for sock_file on user_tmp_t
The following command line did not function on an x86_64 host due to missing
SELinux rules:

virt-install -v \
 --name fedora-38-aarch64 \
 --ram 4096 \
 --disk path=fedora-38.img,cache=none \
 --nographics \
 --os-variant fedora38 \
 --import \
 --virt-type=qemu \
 --arch aarch64 \
 --check all=off

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2228423
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 10:30:08 -04:00
Lena Voytek
f732f489c2 debian: Allow apparmor access to qemu session bus swtpm files
When running a VM connected to qemu:///session, swtpm needs access to its own
process id and socket files in /run/user/<UID>/libvirt/qemu/run/swtpm/. Add
permissions to access them in the apparmor profile.

Signed-off-by: Lena Voytek <lena.voytek@canonical.com>
2023-08-10 20:03:06 -04:00
Ross Lagerwall
51ccd2378b Make stdout unbuffered in swtpm_{setup,localca}
swtpm_setup and swtpm_localca may be run by a toolstack with log
messages going to a pipe via stdout. Set stdout to be unbuffered to
avoid log messages being lost if the process terminates unexpectedly.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2023-08-02 10:05:07 -04:00
Stefan Berger
67152d3e18 tests: Fix spelling mistakes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-17 20:46:43 -04:00
Stefan Berger
f954e3b9d2 Fix a few spelling errors in code
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-17 20:46:43 -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
34f1e2a1b0 swtpm_setup: Exit with '0' upon --version rather than '1'.
The --version option was using the wrong goto label error rather than
out to now also exit with exitcode 0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-12 21:03:28 -04:00
Stefan Berger
2f86ffbac0 swtpm_setup: Close file descriptors passed to swtpm process on parent side
Close the file descriptors passed to the swtpm process on the parent
side for faster detection of errors in the swtpm process that can
occur if swtpm was passed a profile that it cannot run with.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-01 10:26:27 -04:00
Stefan Berger
bb2c7ed14e tests: Remove stray \ in front of - after already escaped '\-'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-06-26 20:50:01 -04:00
Stefan Berger
1fa820468f tests: Fix newly detected shellcheck issues SC2086 by quoting
Shellcheck v0.9 detected more SC2086 issues.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-06-26 20:50:01 -04:00
Stefan Berger
a464c649e2 tests: Disable shellcheck SC2317
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-06-26 20:50:01 -04:00
Stefan Berger
1daa80d239 swtpm_setup: Use medium duration on TSC_PhysicalPresence to avoid timeouts
On busy systems TSC_PhysicalPresence may time out when used with short
duration, so use medium duration instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-06-26 18:36:35 -04:00
Stefan Berger
cfeea1b1c0 swtpm_setup: Add poll() after write() and before read() to detect errors
In case swtpm does not start properly the write() to it may work but
then the read() gets stuck. Detect a failed swtpm by adding a poll()
before the read(). Use some extended durations considering possibly
busy systems.

A terminating swtpm instance can be caused when an unacceptable
profile is passed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-06-24 16:01:33 -04:00
Stefan Berger
48dffac182 swtpm_ioctl: Repeatedly call PTM_GET_INFO for long responses
Fix the display of long responses that require calling PTM_GET_INFO
multiple times to get parts of the response from increasing offsets
until the whole response has been received.

Long responses are only returned when libtpms has profiles support and
several flags are passed to PTM_GET_INFO.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-06-23 18:30:01 -04:00
Stefan Berger
9a154fa45f tests: ibmtss2: Add patch to disable x509 test with older libtpms
Older versions of libtpms need to have another patch applied that disables
x509 certificate creation (0013-Disable-x509-test-cases-part2.patch).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-05-15 14:21:37 -04:00
Stefan Berger
3095011412 tests: Upgrade to ibmtss2 v2.0.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-05-11 09:24:54 -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
fd2c9fdeab utils: Consolidate compile time configuration variables in swtpm_conf.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-04-17 10:55:16 -04:00
ben-dav-lytle
546f2367d6 use PKG_CHECK_MODULES to check libtpms version
Signed-off-by: Ben Lytle <ben.dav.lytle@hpe.com>
2023-03-09 16:09:06 -05:00
Stefan Berger
459f4e7dea Travis: Update from focal to jammy and from bionic to focal
Since the tss2 package is commonly available in focal and jammy
move it into to the general list of packages to installed.

libtpm2-pkcs11-tools is available since jammy, so installed it
there to enable the TPM 2 pkcs11 tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-27 07:10:10 -05:00
Stefan Berger
5e6e13802d Travis: Update from bionic to focal and from xenial to bionic
Since the package libasan2 does not exist in focal anymore, remove. The
bionic builds do not seem to require this package to be installed (maybe
it's already there), so there's no need to install it in a before_script.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 11:13:56 -05:00
Stefan Berger
29ceff5c33 swtpm_localca: Add missing NULL option to end of array
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-22 17:27:05 -05:00
Stefan Berger
1cd2dc6049 samples: swtpm-create-tpmca: Fix shellcheck issues and add to syntax-check target
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-22 17:27:05 -05:00
Stefan Berger
036fd75b1f samples: swtpm-create-tpmca: Check for missing tpmtool
Recent GnuTLS does not package tpmtool anymore. Check for
the missing tpmtool and report an error as appropriate.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-22 17:27:05 -05: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
Stefan Berger
346b3d6265 tests: Fix shellcheck issue SC2148 by adding missing shell directive
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-01-31 10:37:31 -05:00
Stefan Berger
c2b54e6ab5 tests: Fix shellcheck issue SC2148 by adding a shell directive
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-01-30 18:25:45 -05:00
Stefan Berger
b40fc82700 tests: Fix 2 cases of shellcheck SC2001 using bash search-replace
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-01-30 18:25:45 -05:00
Stefan Berger
c8699ccd1b tests: Disable shellcheck SC2010 in two cases
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-01-30 18:25:45 -05:00