Commit Graph

1028 Commits

Author SHA1 Message Date
Stefan Berger
2f86b62722 tests: Squeeze spaces in case od print two space between hexbytes (OpenBSD)
The OpenBSD implementation of 'od -tx1' prints two spaces between
hexbytes, thus the grep for "00 00 00 00" fails and we report an
invalid error. This patch fixes this by squeezing the two consecutive
spaces.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-26 18:53:30 -04:00
Stefan Berger
4f56102e96 man: Improve the man page for swtpm_ioctl and add example
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-24 13:26:52 -04:00
Stefan Berger
5e39c27f55 man: Update swtpm-localca.options to reflect expected contents and format
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-24 13:26:52 -04:00
Stefan Berger
68a1d5943b man: Remove generated man pages from repo and ignore created ones
Remove the generated man pages from the repo and add the file patterns
to .gitignore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-20 09:49:33 -04:00
Stefan Berger
a12b09b1ea samples: Implement script to create user config files and extend man page
Implement a script that creates the user config files in the
${XDG_CONFIG_HOME} directory and sub-directories.

Extend swtpm_setup.pod showing swtpm-create-user-config-files usage.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-20 09:49:33 -04:00
Stefan Berger
217c29cb07 Revert "samples: Implement script to create user config files"
This reverts commit d09484c02d.
2020-08-20 09:49:33 -04:00
Stefan Berger
3a2f0be373 swtpm_setup: Accomodate for BSD sed that does not print \n as newline
BSD's sed does not print \n as newline, so we have to split the string
into different lines using tr.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 16:06:10 -04:00
Stefan Berger
d09484c02d samples: Implement script to create user config files
Implement a script that creates the user config files in the
${XDG_CONFIG_HOME} directory and sub-directories.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 14:39:31 -04:00
Stefan Berger
9c61647486 tests: Skip test if time was detected to be going backwards
We have occasional test failures on Travis running tests on OS X where
time seems to be going backwards in the dictionary attack timeout test.
This patch tries to detect that the time went backwards and skip the
test once a failure would have been detected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 14:37:21 -04:00
Stefan Berger
3bc10bd2ab build-sys: Label swtpm and swtpm_cuse with SELinux label
When running the selinux-install target also label swptm and swtpm_cuse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 14:36:10 -04:00
Stefan Berger
a7320793b8 build-sys: Add build targets selinux-install and selinux-uninstall
Add build targets selinux-install and selinux-uninstall to install
and uninstall the SELinux policy rules at a given priority. The
priority defeaults to 400, which works fine on Fedora.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-19 10:50:05 -04:00
Stefan Berger
040c7097e0 build-sys: Have configure display swtpm version being built
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-18 16:21:32 -04:00
Stefan Berger
5a223d2d69 swtpm: Change include of sys/fcntl.h to fcntl.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-16 13:18:16 -04:00
Stefan Berger
88c9deb95d swtpm_setup: Get rid of eval when calling external tool (swtpm-localca)
Get rid of using eval when calling $create_certs_tool and only use
eval for resolving variables from the config file.

We only want variable substitution for entries from configuration
files, so escape all other special shell characters that may be
making it onto the command line so that no subshells are opened
and no redirection to files can occurr.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
86b3285167 tests: Extend swtpm-localca test with odd vmid strings
Extend the swtpm-localca test with odd vmid string to ensure
that they go into the certificate unmodified.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
d920680776 samples: Get rid of using eval when running swtpm_cert
Get rid of using eval when running swtpm_cert in swtpm-localca.
This is to avoid further evaluation of bash expression that can
spawn subshells ('$(echo foo)') or do other bad things. Bad input
could come from malformed configuration files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
b6aef51ff3 samples: Escape many more characters before calling eval on an entry
Escape many more special shell characters before calling eval on
an entry to convert a variable to its value. Uncareful writing of
a swtpm-local.conf config file could have lead to files being over-
written using '>' for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-11 15:01:59 -04:00
Stefan Berger
3392e3ed87 man: Add missing -- to --rsa-keysize in documentation
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-09 21:10:25 -04:00
Stefan Berger
b25d0f812f tests: Have tpm2_ptool use store in temporary directory
Have the tpm2_ptool use a store in the temporary directory so that
with every test we have a clean environment.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-06 17:22:30 -04:00
Stefan Berger
950523c996 tests: Assign unique ports 65452/65453 to test_tpm2_save_load_state
Assign the unique port 65452/65354 to test_tpm2_save_load_state to
avoid conflict with test_tpm_probe also using

SWTPM_SERVER_PORT=65526
SWTPM_CTRL_PORT=65527

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-06 15:37:10 -04:00
Stefan Berger
3fcb474588 tests: Assign unique ports 65450/65451 to test_tpm2_sample_create_tpmca
Assign the unique ports 65450/65451 to test_tpm2_sample_create_tpmca
to avoid clashes with test_samples_create_tpmca that is using

SWTPM_SERVER_PORT=65434
SWTPM_CTRL_PORT=65435

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-06 15:37:10 -04:00
Stefan Berger
354934df35 tests: Assign unique ports 65448/65449 to test_tpm2_setbuffersize
Assign unique ports 65448/65449 to test_tpm2_setbuffersize to avoid clash
with test_samples_create_tpmca using TCSD_LISTEN_PORT=65436.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-06 15:37:10 -04:00
Stefan Berger
63b19c2203 tests: Modify sample key to be 2048 bit rather than only 2033 bit
The generated sample keys started with 00010203, thus leaving the upper
15 bits of the key as '0', which in turn causes gnutls to think that the
key is only 2033 bit long, thus rejecting certificate verification once
the min-verification-profile is set to 'medium' in gnutls's config file
in /etc/crypto-policies/back-ends/gnutls.config.

We now create sample keys starting with 800102, which sets the highest bit.

This fixes test errors on Fedora Rawhide due to the change in the
min-verification-profile setting in gnutls.config.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-31 12:38:59 -04:00
Jonas Witschel
609dfd873a build-sys: fix test for netstat if tcsd is not available
A typo in the condition meant that netstat was always required regardless of
whether tcsd is available or not.

Signed-off-by: Jonas Witschel <diabonas@archlinux.org>
2020-07-28 10:30:23 -04:00
Stefan Berger
58c14c3c24 tests: Squeeze spaces in case od print two space between hexbytes (OpenBSD)
The OpenBSD implementation of 'od -tx1' prints two spaces between
hexbytes, thus the grep for "00 00 00 00" fails and we report an
invalid error. This patch fixes this by squeezing the two consecutive
spaces.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 15:47:39 -04:00
Stefan Berger
aa88eebe32 build-sys: Check whether tss user and group are available
If the tcsd (trousers) is available, TPM 1.2 support should work as well.
Typically the tss user and group should be defined at this point, but
this may not always be the case, so make sure that this user and group
are available on the system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
b71a228538 swtpm_setup: Only change file and directory ownership if needed
Change the file and directory ownership of tcsd related files only if it
is absolutely needed. It is not needed if we are running as user TCSD_USER
in group TCSD_GROUP because then the files were created with the needed
owner and group. This avoids problems when trying to change file ownership
when invoked by libvirt where we do not have the capabilities to change
file ownership even as root.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
0d9d33fb05 swtpm_setup: Allow group read-rights on $TCSD_CONFIG file if tss user != tss group
When the TSS_USER != TSS_GROUP, e.g., user 'root' and group 'tss', then
tcsd requires that the access mode bits on the $TCSD_CONFIG file are set
to 0640, otherwise we get this error:

TCSD ERROR: TCSD config file (/tmp/tmp.Yd4LIF7mCE) must be mode 0640

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
9d8d6d0378 swtpm_setup: log errors from tcsd in logfile
Redirect stdout and stderr from tcsd into a file and if tcsd reported
an error copy the error into the logfile. This makes debugging tcsd
related issues, such as ownership or access mode issues, easier.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 10:50:08 -04:00
Stefan Berger
3b33116d97 build-sys: Error out if libtpms.pc cannot be found and request PKG_CONFIG_PATH be set
Error out if libtpms.pc cannot be found for pkg-config. This now requires that an
in-place libtpms be accessed like this:

PKG_CONFIG_PATH=/home/stefanb/libtpms/ \
	LIBTPMS_CFLAGS=-I/home/stefanb/libtpms/include/ \
	LIBTPMS_LDFLAGS=-L/home/stefanb/libtpms/src/.libs/ \
	./configure --prefix=/usr

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-24 08:33:05 -04:00
Stefan Berger
e9b08c7178 CHANGES: Add documentation for changes in 0.4.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-21 20:52:34 -04:00
Stefan Berger
0371b63bec build-sys: Explicitly link libswtpm_libtpms with -lcrypto (Gentoo)
This patch fixes the following linker issue reported for Gentoo in
issue #280.

ld.lld: error: /var/tmp/portage/app-crypt/swtpm-0.3.1-r1/work/swtpm-0.3.1/src/swtpm/.libs/libswtpm_libtpms.so: undefined reference to EVP_sha512
ld.lld: error: /var/tmp/portage/app-crypt/swtpm-0.3.1-r1/work/swtpm-0.3.1/src/swtpm/.libs/libswtpm_libtpms.so: undefined reference to PKCS5_PBKDF2_HMAC
ld.lld: error: /var/tmp/portage/app-crypt/swtpm-0.3.1-r1/work/swtpm-0.3.1/src/swtpm/.libs/libswtpm_libtpms.so: undefined reference to SHA512

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-21 20:52:34 -04:00
Stefan Berger
b381e1eb29 build-sys: Use AC_COMPILE_IFELSE to check for unused linker flags (clang)
This patch fixes a clang issue report in issue #280.

clang does not use ld, so we cannot grep for support of certain linker
flags but have to test-compile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-21 20:52:34 -04:00
Stefan Berger
605e823f39 tests: Use the IBM TSS2 v1.5.0's test suite
Upgrade to use the IBM TSS2 tests from v1.5.0.

Add a patch that eliminates all testing of 3072 bit RSA keys in case
libtpms does not support such keys. This test also passes with libtpms
0.6.0 and 0.7.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-13 11:10:56 -04:00
Stefan Berger
6b75ea0dfe debian: Address some issues raised by lintian
Remove swtpm_cuse related install script since not needed anymore.

Also address the following issues:

E: swtpm-tools: unknown-control-interpreter control/postinst #!/usr/bin/env
W: swtpm: syntax-error-in-debian-changelog line 25 "bad key-value after `;': `urgency medium'"

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-07 15:47:28 -04:00
Stefan Berger
497febc2bc tests: Adapt test cases' expected PCR result due to libtpms TPM 2 fix
libtpms version 0.6.3, 0.7.3, and master have a change to the TPM 2 code
that affects the pcrUpdateCounter, which now returns a smaller value than
before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-06-29 08:18:23 -04:00
Stefan Berger
13cb26d846 build-sys: Enable automake silent rules
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-06-18 14:05:03 -04:00
Seunghun Han
2bc601bba5 Fix typos in code and man pages
This patch fixes typos of code and man pages reported by lintian.

Signed-off-by: Seunghun Han <kkamagui@gmail.com>
2020-06-15 08:11:34 -04:00
Seunghun Han
fb5256bfcb Add line breaks in a man page
This patch fixes line break warnings reported by the lintian tool.

Signed-off-by: Seunghun Han <kkamagui@gmail.com>
2020-06-15 08:11:34 -04:00
Stefan Berger
646ec441b3 tests: Skip derived key test 1st part on big endian machines
The first part of the derived key test only works fine on 64 bit
little endian machines. Skip big endian machines.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 13:18:54 -04:00
Stefan Berger
b79970f637 swtpm_setup: Create the RSA 3072 EK key with an empty nonce
Create the RSA 3072 EK key with an empty nonce rather than a nonce full
of 0 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-18 09:26:47 -04:00
Stefan Berger
20fd182c24 swtpm_setup: Put RSA 3072 EK Certificate into NVRAM idx 0x01c0001c
Put the RSA 3072 EK Certificate into NVRAM index 0x01c0001c.

Signed-off-by: Stefan Berger stefanb@linux.ibm.com>
2020-05-18 09:26:47 -04:00
James Bottomley
b4374c3392 build-sys: Let swtpm build with in-place libtpms
Building things like this in-place is really useful when you can't be
bothered to package and install them for your distribution but still
want to use them.  This patch allows building swtpm with libtpms in
place.  Simply specify the location to LDFLAGS and CFLAGS on the
configure line

LIBTPMS_CFLAGS=-I/home/jejb/git/libtpms/include/ LIBTPMS_LDFLAGS=-L/home/jejb/git/libtpms/src/.libs/ ./configure

It will then build a version that can run in-place.

I also think it corrects a bug in the original in that if pkg-config
had specified a non standard library location, the version check
wouldn't have used it.

Signed-off-by: James E.J. Bottomley <jejb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-12 13:50:37 -04:00
Stefan Berger
7dc24c2f8c swtpm_setup: Allow to create largest possible EK
By passing '--rsa-keysize max' allow to create the largest possible RSA
EK key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
5fea46927d tests: Extend swtpm_setup test cases to also test with RSA 3072 bit keys
Extend a few test cases to also test with RSA 3072 bit keys if they
are supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
6c5b7c2d86 swtpm_setup: Add support for RSA 3072 bit EK keys
Extend the creation of the EK key to support also 3072 bits RSA keys.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
80d7bb488c swtpm_setup: Report supported RSA key sizes useful for EK key creation
Extend the --print-capabilities option to also report supported RSA
key sizes. Only the TPM 2 may support anything else than 2048 bit RSA
keys, so we only consult 'swtpm socket --tpm2 --print-capabilities'
and grep for 2048 and 3072 key sizes and report them.
If nothing is found, nothing is reported, as before, and 2048 bit RSA
keys should be assumed.

'swtpm_setup --tpm2 --print-capabilities' may now show the following:
{
  "type": "swtpm_setup",
  "features": [
    "cmdarg-keyfile-fd",
    "cmdarg-pwdfile-fd",
    "tpm2-rsa-keysize-2048",
    "tpm2-rsa-keysize-3072"
  ]
}

Also adjust a test case to use a regular expression for matching
against an expected string that may nor may not have rsa-keysize
verbs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-05 09:12:21 -04:00
Stefan Berger
8abf473257 tests: Remove RSA 3072 tests only if libtpms not show RSA 3072 support
Check the libtpms capabilities via 'swtpm_ioctl -i 4' to see whether
libtpms supports RSA 3072 bit keys. Only if this is not the case
deactivate all RSA 3072 bit key tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 18:12:24 -04:00
Stefan Berger
c6b52d18e0 swtpm: Construct RSA key size capabilities from TPMLIB_GetInfo()
Construct RSA key size capability strings from libtpms TPMLIB_GetInfo()
string so that we can easily show which RSA key sizes are supported by
the TPM 2 implementation. If none are advertised, 1024 & 2048 can be
assumed to be supported.

'swtpm socket --tpm2 --print-capabilities' may now print the following:
{
  "type": "swtpm",
  "features": [
    "tpm-send-command-header",
    "flags-opt-startup",
    "cmdarg-seccomp",
    "cmdarg-key-fd",
    "cmdarg-pwd-fd",
    "no-tpm12-tools",
    "rsa-keysize-1024",
    "rsa-keysize-2048",
    "rsa-keysize-3072"
  ]
}

We need to adapt the related test case to use a regular expression since
the rsa-keysize-xyz strings may or may not be there depending on libtpms
version.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 18:12:24 -04:00
Stefan Berger
1974f2ce20 swtpm_setup: Report 'no-tpm12-tools' if tcsd or tpm-tools missing
If the host is missing tcsd (trousers) or the tpm-tools, swtpm_setup
will now report the 'no-tpm12-tools' verb like this:

> swtpm_setup --print-capabilities | jq

{
  "type": "swtpm_setup",
  "features": [
    "cmdarg-keyfile-fd",
    "cmdarg-pwdfile-fd",
    "no-tpm12-tools"
  ]
}

The only TPM 1.2 setup parameter that requires interaction with
the TPM 1.2 that can be pass is then '--createek'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-01 17:47:03 -04:00