Commit Graph

35 Commits

Author SHA1 Message Date
Stefan Berger
e56316617c tests: fuzz: Store initialized permall state blob
We have to store the permall state blob once it has been initialized since
otherwise some fields are not having proper values in the internal state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-22 22:23:16 -04:00
Stefan Berger
a6c9836af5 tests: fuzz: Have state suspended and resumed after every fuzz step
Have the TPM 2's state suspended and resumed at every step to
ensure that we can marshal and unmarshal it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-22 17:37:00 -04:00
Stefan Berger
70ebecdf6a tests: fuzz: Register callbacks to avoid creating NVChip file
Register callbacks so that we don't create the NVChip file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-22 17:37:00 -04:00
Stefan Berger
a59db1faea tests: fuzz: Call die() when an error from an API call was returned
Call die() causing as assert() to be triggered if an API call
returned an unexpected failure result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-22 17:37:00 -04:00
Nicolas Iooss
bbd7b75d71 Fix many misspellings
When testing downgrading from libtpms 0.8 to 0.7 (which is not
possible), the error message which is reported is:

    libtpms/tpm2: Unexpect value for MAX_RSA_KEY_BITS; its value 3072 is
    not = 2048; (version: 2).

codespell (https://github.com/codespell-project/codespell) reports a
misspelling for "Unexpect", which should be "Unexpected". As the project
contains many more misspellings in comments, error messages and
documentation, fix all misspellings reported by codespell.

Signed-off-by: Nicolas Iooss <nicolas.iooss@ledger.fr>
2021-03-02 08:20:25 -05:00
Stefan Berger
5b8471a921 build-sys: Only build TPM 2 tests if WITH_TPM2 is set
Conditionally enable TPM 2 test cases to build and run if WITH_TPM2
is set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-13 17:02:53 -04:00
Stefan Berger
0f5d791a7d rev162: fix PCRBelongsTCBGroup for PCClient (bugfix)
Fix PCRBelongsTCBGroup by adjusting the set of PCRs that belong to the TCB
Group. The effect of this is that PCR changes to PCR 16 (for example) do
not change the pcrUpdateCounter anymore. The effect *should not* have any
negative side effects when using the TPM.

We also need to update the test cases that now show a different
pcrUpdateCounter in the responses. Also 'swtpm' test cases need
to be fixed to expect the changed result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-06-29 08:42:37 -04:00
Stefan Berger
61cb823169 tpm2: Start supporting RSA 3072 keys
Start supporting RSA 3072 keys.

NVMarshal.c: We now accept state that was written by libtpms when RSA keys
sizes were 2048 or are 3072, basically less-or-equal than 3072.

Also increase the NVRAM memory size by ~45 kb to accommodate the worst
case where the USER NVRAM is full of 65 2048 bit persisted keys whose 65
OBJECTs are now expanding and need to again fit into the NVRAM. We have
to add exactly 45760 bytes to accomodate this case. See swtpm test
case test_tpm2_save_load_state_2. 65 * 704 = 45760.

NOTE: BETTER TO NOT BACKPORT!!! MAY NEGATIVELY AFFECT UPGRADE PATH!

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 08:01:26 -04:00
Stefan Berger
391d878197 tests: Display sizes of components of OBJECT when OBJECT size changes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 08:01:26 -04:00
Stefan Berger
3dcaa01d0a tpm2: rev155: Major refactoring of header files
- Introduce Platform.h and replace usage of PlatformData.h and
  Platform_fp.h
- Drop Implementation.h since we now use TpmProfile.h (which we
  prepared previously); many #defines were moved to TpmTypes.h

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
21742dea1e Tests: Add a check for arrays that expand with new commands
Add 2 more tests checking the size of arrays in the PERSISTENT_DATA
structure which expand with new commands.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-13 08:56:37 -04:00
Stefan Berger
bd7dc396e1 tests: Add a test program to run the TPM 2 self tests
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00
Stefan Berger
edd720a1ad tests: Restrict number of command line parameters to fuzz
Restrict the number of command line parameters passed to the
fuzz program in order not to overstep command line parameter
size restrictions.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00
Stefan Berger
04971a0fb9 tests: run a lot less tests in base64decode.sh
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00
Stefan Berger
0540739531 tests: Fix memory leak in test cases
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00
Marc-André Lureau
552bd634ca build-sys: don't tweak LD_LIBRARY_PATH
libtool already provides helper scripts around executables.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-04-16 07:17:53 -04:00
Marc-André Lureau
b214dabfc8 fuzz: better oss-fuzz integration
There were a few issues with the oss-fuzz integration from commit
8373f09854 ("build-sys: add oss-fuzz
support").

When building on OSS-Fuzz, the projects should use the provided CFLAGS
and CXXFLAGS and don't append any extra sanitization / fuzzing flags.

$LIB_FUZZING_ENGINE is defined to set the library to link to, and it
is a c++ library, so we should build fuzzer with c++...

Now --enable-fuzzer is only used for -fsanitize=fuzzer.

Add a tests/fuzz-main.c as fallback, to run the corpus on other builds.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-04-01 11:22:03 -04:00
Marc-André Lureau
8373f09854 build-sys: add oss-fuzz support
This script will permit integration with Google OSS-FUZZ
https://github.com/google/oss-fuzz

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-03-27 14:19:37 -04:00
Stefan Berger
4b4c3e4ee0 tests: Add test case for testing permanent state restore
Add a test case that test the restoring of the permanent
state that must have a persisted key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-26 10:24:41 -04:00
Stefan Berger
399a07e3cd tests: Extend PCR and read again after restart of TPM with restored state
Extend the existing test case with extending PCR 10 and reading back
the result, then storing the state blobs and setting them and checking
the value of PCR 10 again.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-26 10:24:41 -04:00
Stefan Berger
139925229d build-sys: Add support for --enable-test-coverage to configure
Add support for --enable-test-coverage that sets additional CFLAGS
and LDFLAGS.

gcov creates files with suffixes .gcov, .gcno, and .gcda that we
need clean up in a few directories.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-09 11:51:41 -05:00
Stefan Berger
163f79e597 tests: Fix missing semicolon in test case
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-06 15:58:02 -05:00
Stefan Berger
580a7f7881 tests: Do not fail the test in case of an error but display message
Do not fail the entire test run in case of a failure but display an
error message instead and continue running tests.

Errors may happen in very rare cases and we just continue then while
assuming the output is logged.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-01-03 13:15:44 -05:00
Stefan Berger
eb14174640 tests: Add simple test case reading PCRs and writing state file
Add a simple test case to make sure that reading the PCRs
works as expected and that the state file is written
as expected. This state file (NVChip) is only written because
libtpms doesn't have any callbacks registered.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-17 19:52:32 -05:00
Stefan Berger
ba56737b93 tests: Wrap the fuzzer test in a script
Wrap the fuzzer test in a script to we can set up a per fuzzer
temporary directory where the NvChip file is written into.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-12-10 09:17:25 -05:00
Stefan Berger
1fe484ce67 scripting: Use #!/usr/bin/env bash rather than /bin/bash
On some systems /bin/bash does not exists but is somewhere else and can
be invoked with /usr/bin/env.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:33:34 +00:00
Marc-André Lureau
bb5d837cf8 build-sys: fix make distcheck
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-02 12:53:20 -04:00
Stefan Berger
eed97cf008 tpm2: adapt NVRAM offsets and check structure sizes
Make sure that the NVRAM offsets and structure sizes are the same
on all architectures so that we can fill up the NVRAM on one system
and migrate the state to another architecture and it will fit into
the NVRAM space there.

We leave some space for the first few data structures in the NVRAM to
grow. We do this by rounding up the NV_INDEX_RAM_DATA location to the
next kb boundary. This moves it from offset 4356 to 5120 on x86_64 and
from offset 4332 to 5120 on i386. This now leaves us with the same
amount of space for user dynamic NVRAM, which starts beyond offset 5120.

We also pad the OBJECT structure with 4 bytes so that it is the same
size on 32 and 64 bit architectures. This is a data structure that
is used in user dynamic NVRAM and should be the same size on all
architectures so that a full NVRAM always fits.

Also test the size of the NV_INDEX structure, which already has the
same size on all tested architectures (x86_64, i386, arm32, ppc64).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Marc-André Lureau
48dabdbdef tests: add fuzz test
See README for details on how to use.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-06-15 18:07:49 -04:00
Marc-André Lureau
ef356d0ddb tests: add an initial corpus for fuzzing
This is taken directly from chromiumos TPM2 repository:

    commit 172eec5ea9b46ddfe720c854fa719fdf8613b4ed
    Author: nagendra modadugu <ngm@google.com>
    Date:   Fri Sep 16 14:07:13 2016 -0700

        Add an initial fuzz test corpus for execute-command

        This commit introduces a minimized corpus for
        the test in fuzz/execute-command.cc.

        The corpus was generated by parsing the TCG test
        suite log for messages sent to the TPM.  The corpus
        includes test cases that produced crashes reported
        in chrome-os-partner:56767 and chrome-os-partner:56825.

        Future work includes defining a dictionary for the
        protocol so that mutations can be more effective,
        and also generating test-cases that improve coverage
        (e.g. create & store primary key, followed by test case).

        BUG=chrome-os-partner:50646
        BRANCH=none
        TEST=follow instructions in fuzz/README

        Change-Id: I24332c0f58996626de9a08e2780595b0b2d76350
        Signed-off-by: nagendra modadugu <ngm@google.com>
        Reviewed-on: https://chromium-review.googlesource.com/386443
        Commit-Ready: Nagendra Modadugu <ngm@google.com>
        Tested-by: Nagendra Modadugu <ngm@google.com>
        Reviewed-by: Kostya Serebryany <kcc@chromium.org>
        Reviewed-by: Mike Aizitsky <aizatsky@chromium.org>
        Reviewed-by: Bill Richardson <wfrichar@chromium.org>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
6b9d222bc1 tests: work around possibly missing tools
Implement a work-around for seq and base64 for OpenBSD where these
tools may be missing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 12:46:34 -04:00
Stefan Berger
9b392bf3fb Fix support for ARM64
Fix support for ARM64 by testing for whether __aarch64__ is defined.

Also see http://sourceforge.net/p/predef/wiki/Architectures for the
gcc preprocessor defines.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-06-30 15:04:15 -04:00
Stefan Berger
54c5659647 Remove unnecessary build files from repository
Remove unnecessary files in the repository and add boostrap.sh to create the
configure file and other files we are removing here. Users have to run
bootstrap.sh to have those files created in their build environment.
Update the INSTALL instructions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-13 16:39:13 -05:00
Stefan Berger
b888045f4f Add a test case for the TPMLIB_DecodeBlob API
Add a test case testing the TPMLIB_DecodeBlob function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-08 11:43:37 -05:00
Corey Bryant
a0098eda2d Initial import of project
This is the initial import of the libtpms library.  The libtpms library
provides software emulation of a Trusted Platform Module (TPM).  It is
intended to be used by applications when a hardware TPM is not adequate.
For example, a hypervisor can use libtpms to emulate an independent TPM
for each of it's virtual machine guests.  The library provides a high-
level API for developers to integrate the emulated TPM support into
their application.

The code was originally written by Kenneth Goldman <kgoldman@us.ibm.com>
and Stefan Berger <stefanb@us.ibm.com>.

The code is licensed under the Modified BSD License.

Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2013-10-31 15:33:22 -05:00