Commit Graph

394 Commits

Author SHA1 Message Date
Stefan Berger
545738181e tests: Replace ${SWTPM}.pid with swtpm.pid in PID filename in 2 test cases
The PID filename was generated using the ${SWTPM} environment variable,
which caused test failures if set to a URL for example. Replace it with
'swptm'.

This issue was reported in issue #454.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-28 13:39:56 -04:00
Nick Chevsky
ddc7521653 Move swtpm_localca sources from samples/ to src/
- Move swtpm_localca's sources out of samples/ (where they no longer
  belong now that swtpm_localca is a binary) to src/swtpm_localca/.
- Tests now call the swtpm_localca binary directly at the location
  where it was built, as they do with all other compiled programs.
- Simplify samples/swtpm-localca.in and delete swtpm-localca.2inst,
  removing the now-unnecessary logic to selectively call swtpm_localca
  from different locations (samples/ when running tests vs. /usr/bin/
  post-installation).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-25 08:52:13 -04:00
Nick Chevsky
edfb8d8ad9 Move swtpm_setup.conf.in from etc/ to samples/
- Makes swtpm_setup.conf.in consistent with the rest of the sample
  configuration files in swtpm, whose templates ship in samples/ and
  install the generated files to /etc.
- Works around dh_missing(1) erroneously reporting swtpm_setup.conf as
  non-installed due to its having two copies in the build tree (one in
  etc/ and another in debian/tmp/etc/).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-21 20:30:44 -04:00
Stefan Berger
3acc2ee1ce tests: Add test_tpm2_save_load_state to the tests to run
The test test_tpm2_save_load_state seems to have been forgotten
about and was not run. Add it now to the the tests to run.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-13 18:23:39 -04:00
Stefan Berger
7be5d76679 test: Extend TPM 1.2 test case to also cover 'savestate'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-07 15:44:46 -04:00
Stefan Berger
b517f350a2 tests: Use --allow-signing with --decryption in some swtpm_setup test
To increase coverage, use --allow-signing along with --decryption in
some swtpm_setup test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-07 15:44:46 -04:00
Stefan Berger
978d22bcec tests: Add swtpm_setup test cases with --lock-nvram and --create-spk options
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-29 11:26:30 -04:00
Stefan Berger
53a81d0c9c tests: Kill tpm2-abrmd with SIGKILL rather SIGTERM
Kill an unterminated tpm2-abrmd with SIGKILL rather than SIGTERM

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-21 19:58:49 -04:00
Stefan Berger
3252334cba tests: Use common vars for executables in swtpm_setup_create_cert tests
Use the variables from tests/common for executables used in the
swtpm_setup_create_cert tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-16 14:00:18 -04:00
Stefan Berger
0df3ec7180 tests: Test resolving env. variabels in swtpm_setup config file
Modify a test case and write an environment variable into the
swtpm_setup.conf config file to test that it gets resolved.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-01 09:31:43 -04:00
Stefan Berger
527a9b6063 tests: Allow volatile state file >= 9000 bytes in test_tpm2_migration_key
Changes to libtpms will require that the volatile state files
during this test may be larger than 9000 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-12 16:03:19 -04:00
Stefan Berger
8e30907db2 tests: Add a Readme describing how to run the swtpm tests
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-17 19:19:10 -04:00
Stefan Berger
be6ba388a2 tests: Store and also restore the volatile state at every step
Add restoring of the volatile state after having it stored.

Since this is now taking a long time it must be explicitly enabled
by setting the environment variable SWTPM_TEST_STORE_VOLATILE=1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-17 19:19:10 -04:00
Stefan Berger
b91575e7da tests: Set test-check local user.name and user.email before git am
If we are running the tests as a user that doesn't have a git config
setup we run into the following issue when trying to apply patches
suing 'git am':

Committer identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

This patch fixes this by setting the git config on the local checkout
before using 'git am'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-17 19:19:10 -04:00
Stefan Berger
e78c9db255 tests: Apply patches to IBM TSS2 test suite
Apply patches to the IBM TSS2 test suite rather than using sed on its
files and other types of file manipulations.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-01 07:54:27 -05:00
Stefan Berger
e5bb6f4ec5 tests: Move setting CERRTOOL variable to tests-common
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-01 07:54:27 -05:00
Stefan Berger
12c35fd016 tests: Add test for libtpms issue number 195 (needs latest libtpms now)
This patch adds a test case for testing the fix for libtpms
issue 195: https://github.com/stefanberger/libtpms/issues/195

This patch now requires that the latest TPM version from master or the
branches is installed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 16:22:02 -05:00
Stefan Berger
4d4d24fb56 tests: Use the IBM TSS2 v1.6.0's test suite
Upgrade to use the IBM TSS2 tests from v1.6.0.

Add a patch that eliminates all testing of 3072 bit RSA keys in case
libtpms does not support such keys. Also disable a test case related
to ACT for older revisions.

This test passes with libtpms 0.8.0 as well libtpms 0.6.0 and 0.7.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-24 12:23:27 -05:00
Stefan Berger
eeb87a8673 tests: Wait a bit for pid file content; dump log on failure
test_samples_create_tpmca needs to wait longer for the pid file content
to be there not just until the file is available.

test_tpm2_save_load_state_2 needs to dump the TPM log file on failure.
Failures occurred rarely because the previous instance of swtpm had
not shut down yet and released the lock file while the new instance
wanted to lock the lockfile. So we have to wait a bit until the
previous instance is gone.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-21 11:52:05 -05:00
Stefan Berger
468f7e61c3 tests: Fix spelling error swptm->swtpm
This patch fixes issue #410.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-05 16:48:55 -05:00
Stefan Berger
c396f23f50 swtpm: Fix --print-capabilities for 'swtpm chardev'
This patch fixes the following issue:

$ ./src/swtpm/swtpm chardev --print-capabilities --tpm2
swtpm: Error: Missing character device or file descriptor

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-01-13 11:32:16 -05:00
Stefan Berger
024073c5cc swtpm_cuse: Support parial reads (issue #376)
This patch adds support for partial reads to the CUSE swtpm.

We introduce a ptm_read_offset variable that holds the offset where to read
from next. It is reset every time a command has been processed as part of a
write() so that subsequent read()s start reading from offset 0. It is
advanced by the number of bytes that were read.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-01-04 07:51:50 -05:00
Stefan Berger
b945230493 tests: Try with tcsd.conf ownership of root:tss if tss:tss did not work
Due to recent changes in tcsd, it doesn't accept 'tss:tss 0600' anymore
for the tcsd config file but we need to use 'root:tss 0640' for it.
So far only Fedora seems to be affected. It now depends on whether tcsd
has been patched what ownership is required. So we try first the old
configuration and then the new one.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-09 08:51:08 -05:00
Stefan Berger
9591808d18 tests: Fix path to swtpm-localca
This patch fixes the path to swtpm-localca to avoid this type of
error because of swtpm_localca_conf having been created in another
directory. This error occurred whan running

sudo bash -c "make -j32 distcheck"

Traceback (most recent call last):
  File "/home/stefanb/tmp/swtpm/swtpm-0.5.0/samples/swtpm-localca", line 5, in <
    from py_swtpm_localca.swtpm_localca import main
  File "/home/stefanb/tmp/swtpm/swtpm-0.5.0/samples/py_swtpm_localca/swtpm_local
    from py_swtpm_localca.swtpm_localca_conf import SYSCONFDIR
ModuleNotFoundError: No module named 'py_swtpm_localca.swtpm_localca_conf'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-05 10:03:18 -04:00
Stefan Berger
d4c60e44ce tests: Allow 'ss' as an alternative to 'netstat'
Some distros (openSUSE) have deprecated the 'net-tools' package,
so we allow for 'ss' as an alternative tool from the
iproute/iproute2 package. This is only relevant for test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-02 15:56:42 -04:00
Stefan Berger
8bac7cdf22 tests: start tpm2-abrmd for test case
Start tpm2-abrmd for the test case 'test_tpm2_samples_create_tpmca' rather than
expecting it to be already running.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-22 11:40:57 -04:00
Stefan Berger
a73e9cb831 samples: Apply password for signing key when creating platform cert (bugfix)
Apply the password for the signing key and parent key when creating a
platform certificate. The bug was introduced in commit 961bb827
"samples: Use new pwd format option for secretly passing passwords"

Extend a test case to ensure that the passwords are always used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-15 21:08:32 -04:00
Stefan Berger
3064a72ff0 swtpm_setup: Get rid of 'c' code and support changing user in python
Get rid of the 'c' code that only changed the user and add for support of
the --runas option to change to a different user in the python part.

To get 'make distcheck' to work I needed to name the swtpm_setup python
script with the suffix .in so that it gets copied to the build directory
as swtpm_setup. We need to change execute permissions on this file after
copying.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-09-09 09:53:05 -04:00
Stefan Berger
cc410ca91b swtpm_setup: Switch over to new python tool and get rid of the bash script
Switch over to the new python implementation of swtpm_setup. We need to
also adjust test cases that involved the tcsd that otherwise fail for
various reasons. For in-place testing we need to adjust the PYTHONPATH
and PATH so that swtpm_setup.py can be found and so that swtpm_setup.py
then finds swtpm if it is not explicitly passed as parameter.

Adjust the man page for swtpm_setup to reflect the changes.

We now can run swtpm_setup as any user. However, libvirt still runs it
as tss:tss (for example), which is then creating the signing key as tss:tss
as well. Ideally libvirt would run it as tss:root or any other combination
since the tss group may be used for user wanting to access /dev/tpmrm0 for
example. We at least change the directory ownership of /var/lib/swtpm-localca
to tss:root and keep the world out of this directory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-28 16:27:15 -04:00
Stefan Berger
83f4e96045 tests: Have softhsm_setup use the temporary directory now
Modify the pkcs11 related test case to set the environment variable for
softhsm_setup to use the temporary directory for config file and state
of softhsm. Also set the SOFTHSM2_CONF environment variable since
certtool also uses the pkcs11 module which in turn will look for its
config file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-27 20:26:27 -04:00
Stefan Berger
9da72af4fc tests: Enable softhsm_setup to work with a temporary directory
Use softhsm's SOFTHSM2_CONF environment variable to set the directory
where the configration file is located so that we can now use a temporary
directory for the location of the directory. Use the environment variable
SOFTHSM_SETUP_CONFIGDIR to set the directory where softhsm_setup can
setup its temporary environment for the config file and state of softhsm.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-27 20:26:27 -04:00
Stefan Berger
3677084246 tests: Have softhsm_setup generate private key and add getpubkey command
Have softhsm_setup generate a private key on every start. Also add
a getpubkey command.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-27 20:26:27 -04:00
Stefan Berger
acc3b68c77 tests: Fix tests for slow/busy system by taking time again (DA timeout test)
Slow systems, like Cygwin, need so much time from taking the time to sending
the command that we need to take the current time again to check whether the
success is valid. Previously the test may have failed since the old time that
was taken did not allow the success to be valid.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-08-26 21:34:16 -04:00
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
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
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
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
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
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
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
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
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
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
Stefan Berger
3fca79b82c tests: Pass -pc 80 to tssgetcapability to see all 65 handles
tssgetcapability only retrieves a maximum of 64 handles by default.
However, there are 65 persisted keys. Pass -pc 80 to the command to
see all 65 Handles.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-25 13:43:10 -04:00
Stefan Berger
f956bce305 tests: Add test case for loading of an NVRAM completely full with keys
Add a test case that fills up the NVRAM area with as many persisted keys
as possible and then fills up the rest with an NVRAM index so that all
space is occupied. We have to be able to load this state again into the
NVRAM once the OBJECT's size increases due to RSA keys size increase,
which must have us increase the total size of NVRAM in libtpm's TPM profile.

The state in tests/data/tpm2state5/tpm2-00.permall was created using
libtpms 0.6.0, where only 2048 bit keys were supported and total NVRAM size
was 128kb. This state file should never be changed and always be loadable
into a current libtpms. In its USER NVRAM it holds 64 persisted 2048 bit
keys and an NVRAM index with 236 bytes. For this to stay the reference
NVRAM, we need to make sure that it fits exactly to the byte.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-24 15:03:03 -04:00
Stefan Berger
ea87b5d6ec tests: Repeat download of TPM 1.2 test suite with random wait intervals
Sometimes the download of the TPM 1.2 test suite from sourceforge
fails. So retry up to 3 times and wait a random seconds in the interval
of [3..10] before retrying.

Check the hash of the file we downloaded to make sure we get what we
expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-24 12:56:08 -04:00
Stefan Berger
ea7f80176e tests: Add test case for 'swtpm <iface> --tpm2 --print-capabilities'
Add a test case testing the returned value from

  swtpm <iface> --tpm2 --print-capabilities

along with those return from swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-23 16:02:47 -04:00
Stefan Berger
e5155b4fc5 tests: Revert accidental port change from commit 0194fb22a
Revert the accidental port change from commit 0194fb22a.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-22 16:54:19 -04:00
Stefan Berger
ebd36883b2 tests: Use 'cp -f' for copying over existing files (Travis issue)
Use 'cp -f' to force-copy over existing files. This solves an issue
seen only on Travis.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-15 19:28:26 -04:00
Stefan Berger
f30e202df6 samples: Extend script to create a CA using a TPM 2 for signing
Extend the script that creates a CA that uses a TPM 2 for signing.
For this we have to create tokens using the TPM 2 pkcs11 module's
tpm2_ptool and can then use the p11tool for creating keys.

Add a test case that requires a running tpm2-abrmd and tpm2_ptool.
Eventually the test case should (try to) start its own tpm2-abrmd
and talk to swtpm directly but the tcti module to do that isn't
available as a package, yet.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 13:09:00 -04:00
Stefan Berger
ecdee41147 tests: Create orderly NVRAM indices and then clear TPM 2 (for coverage)
Create orderly NVRAM indices and then clear the TPM 2 so that NvDeleteRam()
gets executed and we get better code coverage.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-09 20:43:43 -04:00
Stefan Berger
39b49a4e71 tests: Modify test to create 2 orderly indices
Modify the test_tpm2_save_load_state_3 to create 2 orderly NVRAM indices
in the first two locations. Those indices will be cleared by a reset
of the TPM and therefore cannot be read once the TPM 2 restarts after
the reset. This also provides better test coverage.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-09 19:39:38 -04:00
Stefan Berger
0194fb22a5 Travis: Run IBM TSS2 for coverage; use Bionic
The IBM TSS2 is available starting with Bionic. Use it there
to extend the test coverage of the code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-09 19:39:38 -04:00
Stefan Berger
3e7555c469 tests: Change localhost to 127.0.0.1 or explicityly set 127.0.0.1
To make the test cases work on Travis on Bionic replace all occurrences of
localhost with 127.0.0.1. The only affected client tools seem to be those
related to the TPM 1.2 and the IBM TSS2. For some reason the API used
there cannot resolve localhost to 127.0.0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-09 19:39:38 -04:00
Stefan Berger
4931b93890 tests: Better detect a 32 bit TPM for the TPM2 derived keys test
The simplest way to detect whether SWTPM_EXE is a 64 bit application on
Linux is to check whether it links against any library in a */lib64/*
directory and only if this is the case we run a particular test case for
which we know what keys 64 bit TPMs are producing given a pre-created
state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-07 16:10:28 -04:00
Stefan Berger
8415d39d5f tests: Use the IBM TSS2 v1.4.0's test suite
Upgrade to use the IBM TSS2 tests from v1.4.0 but eliminate all testing
with 3072 bit RSA keys.

This test also passes with libtpms 0.6.0 and 0.7.0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-07 12:59:27 -04:00
Stefan Berger
cb5ab582d1 swtpm: Fix vtpm proxy case without startup flags
'swtpm chardev --vptm-proxy' currently requires a '--flag startup-xyz'
to be passed since otherwise the need_init_cmd variable would not be
set to false and swtpm would terminate after sending the startup
command. To maintain backwards compatibility we have to always
set the need_init_cmd variable to false for the --vtpm-proxy case
and must not require a startup flag to be passed.

Roll back one of the test case to not use the startup flag.

Fixes: e6bc4bdf0 ('swtpm: Enable sending startup commands ...')
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-03-07 09:09:14 -05:00
Stefan Berger
dfd36eb387 tests: Skip test 4 of derived keys in case an allowed error is encounterd
libtpms may not support TDES, so we have to skip test case 4 in
case we encounter an allowed error message.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-26 10:15:50 -05:00
Stefan Berger
195353de60 tests: Skip swtpm_cert --print-capabilities test if not compiled
If swtpm_cert is not compiled, do not attempt the --print-capabilities
test.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-13 20:38:48 -05:00
Stefan Berger
695274e024 tests: Adjust tests to use new startup options
Adjust the vtpm proxy test case and others to make use of the new
startup options. Make sure that subsequent Startups sent to the
TPM fail with the expected error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-08 18:19:08 -05:00
Stefan Berger
99f442f37c tests: Wait longer for port to close when running with valgrind
Give swtpm more time to close the port. This became an issue when running
the tests and all executables are valgrind'ed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-02-04 19:55:47 -05:00
Stefan Berger
28f1209816 tests: Display SWTPM_CERT that's being used during test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
88c7bdc9e3 swtpm_cert: Add support for --print-capabilities option
Add support for the --print-capabilities option to display newly
added capabilities. Adpat the man page and related test case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
b35eb9fcd5 swtpm_cert: Allow passing signing key and parent key via new option
Allow passing signing key and parent key via files and file descriptors
and environment variables. Adapt a test case to exercise this new
functionality.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
b291eb83ed samples: Protect variables in swtpm-create-tpmca
Address several issues reported by shellcheck and protect
variables with quotes so we now can have filenames with spaces.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05:00
Stefan Berger
f9547ddc2c swtpm_setup: Enable spaces in paths and other variables
This patch addresses several issues found with shellcheck. In particular
it now enables variables with spaces in them, such as file paths that
contain spaces.

Adjust one of the accompanying test cases to use spaces in the path.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05:00
Stefan Berger
77819bb2e6 samples: Protect variables with quotes and address shellcheck issues
Protect variables with quotes so that pathnames with spaces are now
supported.

Adjust the accompanying test case to make use of spaces in file paths.

Address several issues found by shellcheck. Some of them are false
positives especially when it comes to protecting variables passed
to a commaned in an 'eval' line. They must not be protected, otherwise
they are not passed correctly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05:00
Stefan Berger
930c7ba16e tests: Allow seccomp override w/ SWTPM_TEST_SECCOMP_OPT env var
The Ubuntu (PPA) build system executes the build on an environment that
has problems with seccomp profiles. It does not allow us to run the test
suite with swtpm applying its seccomp profile since it fails with a
'bad system call' error. To work around this we introduce the env. variable
SWTPM_TEST_SECCOMP_OPT that we can set to "--seccomp action=none" to avoid
having swtpm apply it seccomp profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-15 15:49:51 -05:00
Stefan Berger
c5748a5354 tests: Move local functions to common file and handle errors better
Move wait_port_open and wait_port_closed to common file and handle
the timeout errors in test_commandline.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
f59c33009d tests: Wait for PID file rather than reading it right away
Wait for the PID file to appear rather than reading it right away.
This addresses an issue when runnin the test suite under valgrind
(make -j $(nproc) check).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
9c2e4dc58a tests: Protect ${SWTPM_EXE} with quotes when passing to function
SWTPM_EXE may be 'valgrind ... swtpm', so we have to protect it with quotes
when passing it as a parameter to a function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
996ad55fbc tests: delay reading of pidfile if found empty
Delay the reading of the PID file if it is found to be empty.
This can happend if swtpm is run by valgrind.

Also, use the passed parameters rather than the global ones to check
the PID file contents against the expected pid. So far this worked
because PID and PID_FILE were variables used by every caller.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
41cae9e1bd tests: Adjust timeouts for running executables with valgrind
When running the TPM 1.2 vtpm_proxy test cases by launching the
swtpm with valgrind it may take a long time for the log to be
written and the device to appear. This is due to the self test
of the TPM 1.2 taking a while. So we need to move the reading
of the device into a loop and set the timeout of the loop to 10s
so that it passed under these circumstances.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
d396839543 tests: Fix key derivation TDES test cases to actually create TDES keys
The byte stream contained the TDES identifier at the wrong position,
so no TDES key was created. This patch fixes this but needs an update
to libtpms since some unmarshalling/marshaling code related to TDES
was missing there as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-12-26 00:08:35 -05:00
Stefan Berger
8e95c996d2 tests: Add test cases for new CrytpAdjustPrimeCandidate algo
Extend the existing key derivation test case for TPM 2 with test cases
that use a newer TPM 2 state where we now exercise the new
CryptAdjustPrimeCandidate algorithm that produces the same results on
big and little enidan 32 bit and 64 bit machines. This newer algorithm
is available in libtpms with revision 155 of the TPM 2 code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-12-23 14:14:25 -05:00
Stefan Berger
8dc2415d53 tests: Have IBM TSS2 test case use tags/v1.3.0 of the TPM 2.0 TSS repo
Use v1.3.0 of the IBM TSS 2.0 repo.

Depending on the revision that libtpms implements, some test cases have to be
replaced with empty files.

The test suite now works with the libtpms stable-0.6.0 and stable-0.7.0
branches. A patch fixing an NV PIN issue needed to be applied to those
branches.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-12-20 23:11:06 -05:00
Stefan Berger
c359fed0a2 tests: Protect variable with executable with quotes
The test_print_capability is failing if SWTPM_EXE is for example
holding more than one parameter like 'valgrind ... /bin/swtpm' since the
variable was not protected with quotes. This patch fixes this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-11-18 07:34:19 -05:00
Stefan Berger
1ce7293d3c tests: Skip seccomp check if env. sets up seccomp profile
If the test environment is running in a seccomp profile do not check
that the seccomp profile of the swtpm process runs with the action
provided in --seccomp action=... since the environment may override
this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-08-08 09:36:04 -04:00
Stefan Berger
817d3a8863 tests: Fix spelling of call to function validate_pidfile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 10:31:07 -04:00
Stefan Berger
01ad1d03f1 tests: Get swtpm PID from shell and validate against pidfile after
Get the PID of the started swtpm from the shell and validate it
against the contents of the pidfile afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
0db8249cf1 tests: Extend --print-capabilities tests with test of swtpm_setup
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
95bed8ceb4 tests: Add test case for --print-capabilities test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
22ecb5ce5a tests: Have IBM TSS2 test not use the raw interface anymore
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-08 07:09:16 -04:00
Stefan Berger
3892b0d85c tests: Add TPM 1.2 test cases for passing key and passphrase via fd
Add TPM 1.2 test cases to test_parameters for testing the passing of key
and passphrase via file descriptor. Also extend the test to check whether
the state files are encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-03 11:19:23 -04:00
Stefan Berger
19f9053391 test: Make sure that when key is passed state is encrypted
Make sure that when keyfile/keyfile-fd or pwdfile/pwdfile-fd are passed
to swtpm_setup that the resulting state is actually encrypted. We check
for encrypted state by making sure that 4-byte sequences of 0-bytes are
not there while they are there for un-encrypted state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
cd188c4adb test: Test passing file descriptor to swtpm_setup
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-28 21:48:40 -04:00
Stefan Berger
d398c0b923 tests: Convert existing test case to use file descriptor for reading password
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
c363aa9e7d tests: Convert existing test case to use file descriptor for reading key
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-06-24 07:27:39 -04:00
Stefan Berger
2d14c61866 tests: Do not run key derivation test on ppc64
The old prime number generation algorithm also does not return
the same numbers on ppc64 (big endian) as on x86_64 or ppc64le,
so do not run the test there.

Signed-off-by: Stefan Berger <stefanb@linu.ibm.com>
2019-06-20 13:20:32 -04:00
Stefan Berger
50a61bbc59 tests: Add test case for deriving key from primary key
Add a test case that tests the derivation of an EC key from the
primary key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-18 17:09:56 -04:00
Stefan Berger
d617dd6d1b tests: Ensure that derived keys are always the same for the same state
Using the same initial state, the derived keys always have to be the
same.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-14 22:18:48 -04:00
Stefan Berger
4ba6012cef tests: Use tag v1470 for revision of ibmtss2 test suite
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-05 21:31:05 -04:00
Stefan Berger
86e8f60584 tests: wait for file content in wait_for_file
When the PID_FILE is passed to swtpm as a file descriptor in one test,
we already create a file without content when running
'exec 100<>$PID_FILE'. So we have to extend wait_for_file to also
wait for file content since the 0.2 seconds delay are sometimes not
enough for content to have been written. Otherwise we do not get the
PID of the process. We can extend the function in this way since all
its usages imply that some content should become available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-08 10:17:32 -04:00
Stefan Berger
9bbe79d853 tests: Convert test case to use IPv6 bindaddr ::1 where available
Use the IPv6 bindaddr ::1 where available on Linux. Travis doesn't
seem to support IPv6 addresses at the moment.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-04 13:02:19 -04:00
Stefan Berger
129c6b5bf2 swtpm: Add support for fd_to_filename on OS X and test it
Extend the previously modified test case to also test on
Darwin now that we are able to convert a file descriptor
to a filename.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-03 09:37:03 -04:00
Stefan Berger
19a8cdd67b tests: Use a file descriptor for the pid file on Linux and Cygwin
On Linux and Cygwin we can pass a file descriptor for the pid
file, on other platforms it doesn't work (yet).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-03 09:37:03 -04:00
Stefan Berger
8d70fd4a16 tests: Pass --runas parameter to swtpm
Pass the --runas parameter to swtpm so we can test switching it
to a given user 'nobody'.

We also have to change ownership of files and directories so that
the nobody user can write the coverage files when swtpm ends.
In the test case we then use the trick of changing file ownership
just before we terminate swtpm, which will trigger the writing
of the .gcda files. We need to have nobody own these files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
e533180b17 tests: Use file descriptor passing for log file
Convert test case to use file descriptor passing for the log file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
bb0aa2ad5a tests: Pass file ownership using uid and gid
Pass file ownership using the uid= and gid= parameters when run
as root and check the result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
f487473cf6 tests: Use mode= to set file mode bits in test and check them
Use the mode= parameter of the TPM's state file and a unix
socket to have swtpm set the file mode bits and check that
they are set as expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
420a18f1d0 tests: Use file descriptor 100 rather than 200 (fix OpenBSD)
Use file descriptor 100 rather than 200 to pass on OpenBSD

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
45ed7764fb tests: Add yet more tests for TPM 1.2 and enable auditing
Add test cases 25 and 26 and run test 25 with auditing enabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-01 06:56:31 -04:00
Stefan Berger
c4a9e78aab tests: Fix some issues with TPM 1.2 test
- Clean up state files in case the test suite was interrupted
- Allow running it from the test directory by creating an absolute
  path for TESTDIR so we can find the patch file; error out in
  case the patching fails
- Run test case 2 and 1 as well but ignore ERROR output in case
  of test 1. The errors stem from us not restarting the TPM when
  the test suite asks for it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-29 12:38:55 -04:00
Stefan Berger
b752aed8f5 tests: Add test case running TPM 1.2 test suite
Add a test case that downloads the TPM 1.2 package from sourceforge,
patches a few files for OpenSSL compatibility, and runs a few test
cases of that test suite. Look for ERROR output in the test suite.
This test suite also provides better code coverage for libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-28 20:58:04 -04:00
Stefan Berger
a18cf08504 tests: Use an empty options file in case options file is accessed
To prevent the test case from failing when an no --prefix is used
when configuring, use an empty options file via /dev/null. Otherwise
swtpm-localca starts looking for the options file in a place where
there is none.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-26 06:51:00 -04:00
Stefan Berger
a3820b8634 tests: Extend tests cases with test for active seccomp profiles
Extend existing test cases to test for active seccomp profiles.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-18 15:43:44 -04:00
Stefan Berger
e60e777c7b tests: Fix error handling if pkcs11 test runs on x86_64 with i386 executable
Softhsm cannot be installed as an i386 executable/library and as
a x86_64 executable/library on a Fedora host. The pkcs11 test then
fails since it cannot pick up the libsofthsm.so needed for an i386
executable (swtpm_cert) on a x86_64 host. This fixes test run errors
for run_test.sh by skipping the test in case swtpm_cert returns
a specific error message related to not being able to import the
pkcs11 URI object.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-28 17:03:26 -05:00
Stefan Berger
8c2cb90f11 test: Replace uname -o with uname -s
Replace single occurrence of uname -o with uname -s so it's portable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 17:56:31 -05:00
Stefan Berger
bfdad297ed tests: Use wait_process_gone rather than sleep
Use wait_process_gone with 2 seconds timeout to wait for the swtpm to
have terminated after SIGTERM or connection loss. This avoids test
failures on slow Raspberry Pi 2.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 17:56:31 -05:00
Stefan Berger
02b7d5da10 Make softhsm/pkcs11 test case work on Travis on OS X
We need to run the softhsm/pkcs11 test case as root (sudo) under OS X
so that we can write the file /etc/gnutls/pkcs11.conf. However, once
we run the tests as root we cannot run the 'brew ls' command anymore
since it refuses to run with high privileges. So, if we run as root we
need to use sudo to switch to the nobody user to run the 'brew ls'
command that gives us the name of the softhsm pkcs11 module.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 15:42:52 -05:00
Stefan Berger
b5e7e2a41f tests: Make the test case work on OS X
On OS X we need to be able to change /etc/gnutls/pkcs11.conf for
p11tool to pick up the softhsm pkcs11 module correctly. We need
(password-less) sudo to be able to do this.

Unforutnately this test case does not run on Travis since Travis
seems to require passwords under some circumstances.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 12:48:43 -05:00
Stefan Berger
34308cc7d3 tests: Add test case that uses a pkcs11 URI for signing a cert
Use SoftHSM to create a pkcs11 URI and then use the pkcs11 URI
to sign the certificate of a TPM 2.0 with this key using swtpm-localca.

This test case works with softhsm >= 2.3.0 on Fedora and should work
with a recent version of Ubuntu. If an error is encountered setting
up the softhsm2 environment, we just skip the test.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-23 12:48:43 -05:00
Stefan Berger
2b0f421224 tests: Gate the IBM TSS 2 related test with SWTPM_TEST_IBMTSS2
Older versions of the IBM TSS2, such as in FC26 for example, behave
slightly different than the code in the test case expects (certain
files are not generated or may have a different name). So gate this
test case with SWTPM_TEST_IBMTSS2 environment variable so we don't run
it by default if the TSS tools are found and so we do not run into
possible errors due to an older version of the stack installed on the
system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 18:57:53 -05:00
Stefan Berger
a1c9aedd77 tests: Set TPM_INTERFACE_TYPE=socsim
Set the TPM_INTERFACE_TYPE to socsim to override a potential
compile-time default.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 18:57:53 -05:00
Stefan Berger
6dbab87358 tests: Remove 'less' command from test case
Remove a 'less' command from previous debugging from the test
case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-17 17:08:04 -05:00
Stefan Berger
63f7079fd7 tests: Use bash's built-in echo rather than /bin/echo
The BSD's cannot use /bin/echo -en but we have to use bash's built-in
one.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 18:50:42 -05:00
Stefan Berger
078e3bcdff tests: Convert test case to also use binary formatted key
To get better code coverage, convert existing test case to
use one time a hex formatted key and the other time the same
key in binary format.

Do some improvements on the test code on the way.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 17:07:31 -05:00
Stefan Berger
13b76898a5 tests: Add missing file sizes and some other reorg to test case
2 file sizes were missing. Also use $() to execut commands rather
than ``. Use get_filesize to get the size of a file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 17:07:31 -05:00
Stefan Berger
660ec54272 tests: Allow passing SWTPM_CERT from command line
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-17 16:37:03 -05:00
Stefan Berger
4bd99ad965 tests: Extend swtpm-create-tpmca test with 'well known' password
Extend the swtpm-create-tpmca test with test cases using the
'well known' password of 20 zero bytes if tpmtool supports the
--srk-well-known option.

Besides that, extend the existing test to actually use the TPM CA
for signing a TPM 1.2 or TPM 2 (test) EK and check the contents of the
certificate by grepping through the text info provided by certtool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-09 14:18:25 -05:00
Stefan Berger
a0e7fbc05e tests: Refactor swtpm-create-tpmca test for easier extension
Refactor the swtpm-create-tpmca test case so we can use it for
testing with the 'well known' (20 bytes of zeros) SRK password
in the next pass.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-09 14:18:25 -05:00
Stefan Berger
7cdc7ea483 tests: Add a test case for the TPM CA setup script
Run the TPM CA setup script with a local swtpm and tcsd instance.
We have to take ownership of the TPM and set its SRK passwork so
that the TPM CA setup script can create a signing key as a child
key of the SRK.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-05 15:15:48 -05:00
Stefan Berger
15a14c552a samples: Add support for password protected root CA priv. key
Support creation and usage of the root CA with a password protected
private key. The root CA's key password can be set using the environment
variable SWTPM_ROOTCA_PASSWORD.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-25 10:32:36 -04:00
Stefan Berger
f759520c02 tests: Check expected error output against expected error message
Some tests are expected to fail. Capture the error output and test it
against epected error output. This also makes the test output less
noisy.

Also remove some other output noise.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
148010c0b6 tests: Shut down swtpm at the end to avoid kill
Shut down the swtpm process at the end to avoid it being killed
and with that getting noise in the test log.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
08c8820a74 tests: Return a string from get_file_hash if file not found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
3ad55f8c3a tests: Only run test_tpm2_samples_swtpm_localca if certtool was found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-06 18:09:08 -04:00
Stefan Berger
03c7fe4566 tests: Get the IBM TSS2 test suite and run it
Get the IBM TSS2 test suite from its git repo, compile it, and run
its test suite if SWTPM_TEST_EXPENSIVE=1 is set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-05 13:34:22 -04:00
Stefan Berger
90ae0c2783 tests: wait for files to appear or disappear after starting swtpm
Wait a few seconds for files to appear or disappear after starting the
swtpm process. This helps avoid test failures when the system is under
load.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-01 12:52:20 -04:00
Stefan Berger
c46d6717ae tests: Add delay after finding file for process to write into it
Add a delay of 0.2s after a file is found in wait_for_file so that the
process can also write into it. Sometimes we are also interested in the
content and don't seem to get the content since we didn't wait for
the file to have been written to. It happens occasionally when the system
is under load that we don't seem to be able to read the file content
afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-01 12:52:20 -04:00
Stefan Berger
45d2d092f3 tests: Increase timeout for shutdown for running with valgrind
To avoid timeouts when running the tests with valgrind, increase
the timeout until the swtpm process must have terminated after a
shutdown signal to 4 seconds.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-01 12:52:20 -04:00
Stefan Berger
100317d541 tests: Call function rather than running 'ps aux' to display proceses
Call a function display_processes_by_name that displays all processes
if needed. The function is quiet, though.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 10:19:09 -04:00
Stefan Berger
4dd376c3b4 tests: Replace kill_quiet after shutdown with wait_process_gone
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 09:59:17 -04:00
Stefan Berger
b4372fe50f tests: Use python3 rather than python for the test programs
Fedora policy seems to be to use python3 explicitly for the hashbang
rather than python, which could be either python2 or python3. So convert
it to python3. Also adapt configure.ac to require python3 executable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-25 08:35:45 -04:00
Stefan Berger
71d9581aa4 tests: Extend test cases with aes-256-cbc state file encryption
Extend existing test cases with aes-256-cbc state file encryption.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 12:23:22 -04:00
Stefan Berger
a39f098fd6 swtpm: Use pbkdf2 as default kdf and sha512 for test cases
Use pbkdf2 as the default kdf and sha512 for the existing
test case. Do away with file limit of 32 bytes. This may
break backwards compatibility for some but better to do this
before a release...

Switch the existing test cases to use kdf=sha512 on the command
line where necessary to that the state for these test cases
does not need to be recreated.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 11:45:44 -04:00
Stefan Berger
8f0f381f95 scripting: Use #!/usr/bin/env bash rather than /bin/bash
On some systems /bin/bash does not exists but the bash is somewhere
else and can be invoked with /usr/bin/env bash.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:49:12 +00:00
Stefan Berger
9e786a3ae5 tests: Enable test_ctrchannel on DragonFly BSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:14:06 +00:00
Stefan Berger
c51c07a016 tests: Pass top level source dir to test cases for out-of-tree builds
Some test cases that root has to run did not pass the out-of-tree
builds. We need to pass the top level source dir to these test cases
and change some variable accessing config files to the right directory
for the out-of-tree build to work.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-01 14:49:49 -04:00
Stefan Berger
80f985897c tests: Implement support for OS/X (Darwin)
If the file descriptor 100 is open prior to trying to open
it, it must be closed first on OS/X, otherwise we get test
case failures due to interrupted connections.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:44:24 -04:00
Stefan Berger
8aff5f7665 tests: set CERTTOOL to gnutls-certtool on OS/X
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:40:01 -04:00
Stefan Berger
526bf3754e tests: Use --cs for swtpm_bios rather than ambiguous -cs
The -cs parameter to swtpm_bios is like -c -s and therefore ambiguous.
Use the unambiguous long version --cs. This makes the test case work
on NetBSD, which does not support getopt_long_only().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:10:01 +00:00
Stefan Berger
df9eccd404 tests: Make test_ctrlchannel work on NetBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:07:20 +00:00