Commit Graph

1258 Commits

Author SHA1 Message Date
Stefan Berger
dc4e3f6313 rpm/debian: Add 0.9.0 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-28 16:55:28 -04:00
Stefan Berger
ab25f924d1 CHANGES: Updated CHANGES document for 0.9.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-28 16:55:28 -04:00
Stefan Berger
4bc846f869 build-sys: Use -DOPENSSL_SUPPRESS_DEPRECATED to suppress warning (OSSL 3)
Instead of using -Wno-deprecated-declarations use
-DOPENSSL_SUPPRESS_DEPRECATED to only suppress OpenSSL deprecated
declarations warnings.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:52:22 -04:00
Stefan Berger
f45bafa9bd build-sys: Add -Wno-deprecated-declarations to default CFLAGS (OSSL 3)
To be able to build with OpenSSL 3.0 we need to added
-Wno-deprecated-declarations to the default CFLAGS.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-15 13:28:08 -04:00
Stefan Berger
3091ef1184 build-sys: Test for functions if #defines are not found (OSSL 3)
OpenSSL 3.0 has converted several RSA-related #defines to functions, so
that AX_CHECK_DEFINE only works for OpenSSL 1.1.0 but for OpenSSL 3.0.0
we have to also use AC_CHECK_LIB to determine whether the function is
available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-15 13:28:08 -04:00
Stefan Berger
ed94c7fd14 tpm2: Only call EVP_PKEY_CTX_set0_rsa_oaep_label when label != NULL (OSSL 3)
EVP_PKEY_CTX_set0_rsa_oaep_label must only be called with label != NULL.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-15 13:28:08 -04:00
Stefan Berger
c8a7074bb6 tpm2: Use EVP_PKEY_get1_RSA() rather than EVP_PKEY_get0_RSA (OSSL 3)
OpenSSL 3.0 has changed the signature of EVP_PKEY_get0_RSA() from

struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);

to

const struct rsa_st *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);

We now have to use EVP_PKEY_get1_RSA with this signature so that we can
access the RSA key. The signature of that function hasn't changed between
OpenSSL 1.1.0 and 3.0.0.

struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);

Free the additional reference held on the RSA key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-15 13:28:08 -04:00
Stefan Berger
9eb9677795 tpm2: Marshal event sequence objects' hash state
Event sequence objects were never properly marshalled and when their state
was saved and later restored their state may have been corrupted. Fix this
now by also marshalling the state of event sequence objects.

Bump up the version of the HASH_OBJECT's header to '3' so that previously
written state can be resumed if an event sequence object is encountered
and we only unmarshal an event sequence object when the version is at least
'3'.

Fixes issue #259.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-09 12:28:17 -04:00
Stefan Berger
b06558d32b tpm2: Report supported Camellia keysizes in the JSON
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-06 13:42:06 -04:00
Stefan Berger
1522d293f5 tpm2: Enable ALG_CAMELLIA in TpmProfile.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-06 13:42:06 -04:00
Stefan Berger
d78e6e3879 tpm2: Add more compile-time constants to array
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-06 13:42:06 -04:00
Stefan Berger
5e97c2e78d tpm2: Make exp. size of compile-time constants dependent on header version
Make the expected array size of compile-time constants dependent on
the version of the header. This way we can add elements to the array
while bumping up the version of the header.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-06 13:42:06 -04:00
Stefan Berger
1d99fa711e git: Fix erroneous gitignore entries
Fix erroneous gitignore entries that previously showed with the
following command line:

git ls-files -i --exclude-standard -c

Resolves #249.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-02 13:50:24 -04:00
Stefan Berger
a9657246e2 tpm2: Extend asym key test case data generation script with sm4
Extend the test case data generation script with sm4. Since several
distros' openssl do not support sm4, we need to test for whether sm4
is supported by the installed openssl.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-02 12:03:23 -04:00
JerryDevis
4c19adce30 Update SymmetricTestData.h
update the selftest data in dataOut_SM4_CTR

Signed-off-by: JerryDevis <seclab@huawei.com>
2021-09-02 10:55:05 -04:00
Marc-André Lureau
3482da113c build-sys: add with_tpm1/with_tpm2 variables to .pc
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-08-06 08:04:37 -04:00
Marc-André Lureau
057242b84d build-sys: add optional --with-tpm1
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-08-06 08:04:37 -04:00
Marc-André Lureau
e60c35ecf9 Move common debug, memory & nvfile units to src/
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-08-06 08:04:37 -04:00
Stefan Berger
aa579cee5b tpm2: Use EC_POINT_set/get_affine_coordinates on OpenSSL >= 1.1
Use the EC_POINT_set/get_affine_coordinates function on OpenSSL >= 1.1.
These function are a 1:1 replacement for the
EC_POINT_set/get_affine_coordinates_GFp functions and are available
since OpenSSL 1.1 and are deprecated in OpenSSL 3.0.

This patch addresses one aspect of the OpenSSL 3.0 issues raised in
issue #215.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-04 08:57:20 -04:00
Stefan Berger
7899608f2a tpm2: Enable supported AES bit size cases using #if AES_<size>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-29 19:15:51 -04:00
Stefan Berger
8b889f50fe tpm2: Enable supported Camellia bit size cases using #if Camellia_<size>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-29 19:15:51 -04:00
Stefan Berger
034a5c0248 tpm2: NVMarshal: Handle index orderly RAM without 0-sized terminating node
The NVRAM entries in s_indexOrderlyRam array do not need to contain a
0-sized terminating node. Instead, the entries may fill up this 512
byte array so that no NV_RAM_HEADER structure fits anymore. The fact
that no more NV_RAM_HEADER structure fits is also an indicator for the
last entry. We need to account for this in the code marshalling and
unmarshalling the entries so that we stop marshalling the entries
then and similarly stop unmarshalling.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-23 15:54:58 -04:00
Stefan Berger
17255da54c tpm2: Initialize a whole OBJECT before using it
Initialize a while OBJECT before using it. This is necessary since
an OBJECT may also be used as a HASH_OBJECT via the ANY_OBJECT
union and that HASH_OBJECT can leave bad size inidicators in TPM2B
buffer in the OBJECT. To get rid of this problem we reset the whole
OBJECT to 0 before using it. This is as if the memory for the
OBJECT was just initialized.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-23 15:54:58 -04:00
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
Nick Chevsky
d68ef5f0bc Debian packaging improvements
- debian/clean: Clean up files not automatically caught by
  `debian/rules clean`.
- debian/control:
  - Add new recommended/required fields and bump Standards-Version.
  - Remove redundant build dependences that are implied transitively.
  - Move libtpms0's ${misc:Pre-Depends} dependency to `Pre-Depends`.
    Resolves `depends-on-misc-pre-depends` Lintian warning.
  - Sort packages and dependency lists alphabetically as per
    wrap-and-sort(1).
- debian/not-installed: List non-installed files to avoid
  dh_missing(1) warnings.
- debian/rules:
  - Remove unused architecture variable.
  - Remove redundant --parallel, --with autoreconf flags.
  - Remove redundant `dh_update_autotools_config` call.
- debian/*.install:
  - Remove redundant `#! /usr/bin/dh-exec` lines.
  - Sort entries alphabetically as per wrap-and-sort(1).

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-22 16:48:09 -04:00
Stefan Berger
04f85e2fc1 man3: Fix errors in code example in TPMLIB_RegisterCallbacks
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-22 13:21:45 -04:00
Stefan Berger
71b33cb9e0 tpm2: Use #if ALG_CAMELLIA rather than #if 0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-22 13:21:45 -04:00
Nick Chevsky
a1a7748e0b Improvements to .gitignore
- Add auto-generated files *.gch, debian/autoreconf.*, tests/NVChip
- Add .pc/ (temporary directory used by Quilt for patch management)
- Remove *.patch (Quilt requires these under debian/patches/)
- Change incorrect debian/libtpms/ to debian/libtpms0/

Signed-off-by: Nick Chevsky <nchevsky@users.noreply.github.com>
2021-07-20 18:10:32 -04:00
Stefan Berger
98b34147ad tpm2: Avoid compiler warning by using memcpy instead of MemoryCopy (gcc 10.3)
Fix the following compiler warning from gcc 10.3.0 by using memcpy
instead of MemoryCopy (fixes issue #229).

tpm2/NVDynamic.c: In function 'NvRamGetEnd':
tpm2/NVDynamic.c:378:12: warning: function may return address of local variable [-Wreturn-local-addr]
  378 |     return iter;
      |            ^
tpm2/NVDynamic.c:339:26: note: declared here
  339 |     NV_RAM_HEADER        header;
      |                          ^
tpm2/NVDynamic.c: In function 'NvRamGetIndex':
tpm2/NVDynamic.c:411:12: warning: function may return address of local variable [-Wreturn-local-addr]
  411 |     return currentAddr;
      |            ^
tpm2/NVDynamic.c:339:26: note: declared here
  339 |     NV_RAM_HEADER        header;
      |                          ^

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-09 16:21:16 -04:00
Stefan Berger
2e6173c273 tpm2: Restore original value if unmarsalled value was illegal
Restore the original value of the memory location where data from
a stream was unmarshalled and the unmarshalled value was found to
be illegal. The goal is to not keep illegal values in memory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 09:08:44 -04:00
Stefan Berger
7981d9ad90 tpm2: Add maxSize parameter to TPM2B_Marshal for sanity checks
Add maxSize parameter to TPM2B_Marshal and assert on it checking
the size of the data intended to be marshaled versus the maximum
buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-23 11:51:34 -04:00
Stefan Berger
2f30d620d3 tpm2: Reset TPM2B buffer sizes after test fails for valid buffer size
Reset the buffer size indicator in a TPM2B type of buffer after it failed
the test for the maximum buffer size it allows. This prevents having bad
buffer sizes in memory that can come to haunt us when writing the volatile
state for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-23 11:51:34 -04:00
Stefan Berger
dd088932d7 build-sys: Run autoupdate on configure.ac for autconf 2.71
Run autoupdate and address the following issue:

configure.ac:10: warning: 'AM_CONFIG_HEADER': this macro is obsolete.
configure.ac:10: You should use the 'AC_CONFIG_HEADERS' macro instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-21 21:54:25 -04:00
Stefan Berger
be5fabf155 tpm2: Consume padding bytes in TPM2_ContextLoad() (Win2k19, issue #217)
Windows 2019 Server padds the TPM_ContextLoad() command with additional
bytes up to TPM_PT_MAX_OBJECT_CONTEXT for the TPMS_CONTEXT part. Since
libtpms does not use an OBJECT to serialize the keys (anymore) it now
uses less bytes than the MAXimum of TPM_PT_MAX_OBJECT_CONTEXT bytes and
the padding leaves some unconsumed bytes that end up failing the command
since no left-over bytes are allowed in any command.

When unconsumed bytes are left in TPMS_CONTEXT_Unmarshal() we check that
the original passed in size was that of TPM_PT_MAX_OBJECT_CONTEXT and
only then consume the additional padding bytes. Luckily only one command
calls TPMS_CONTEXT_Unmarshal() so that no unwanted side effects should
occur anywhere else, such as no bytes left for unmarshalling the next
structure.

The wisdom behind the padding is not quite clear but it feels like
ill-fixing the code to work around a Windows 2019 server bug...

This patch fixes issed #217

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-01 06:39:35 -04:00
Stefan Berger
a3bdddaa8e Travis: Install libjson-glib-dev and drop a few python dependencies
Since swtpm_setup has been rewritten in 'C' now we can drop a few
python dependencies but need libjson-glib-dev as a new dependency
for testing with swtpm's master branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-29 19:44:34 -04:00
Marc-André Lureau
96383e1e9c build-sys: leave CFLAGS/LDFLAGS for user to be defined
This allows user to set specific flags during compilation, without
overriding configure-time cflags necessary for compilation.

See also:
https://www.gnu.org/software/automake/manual/html_node/User-Variables.html
https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-18 12:21:31 -04:00
Stefan Berger
db1fd5948b tpm2: Switch to UINT16 for CONTEXT_SLOT and 64k context gap
This patch addresses issue #209.

The context gap for libtpms is currently only 0xff due to the CONTEXT_SLOT
being a UINT8. To extend this to 0xffff, we need to define the CONTEXT_SLOT
as UINT16 and introduce a global variable s_ContextArrayMask that takes on
two valid values, 0xff for simulating the CONTEXT_SLOT when it was UINT8
and 0xffff for usage with the new CONTEXT_SLOT of type UINT16. All
occurrences of casts to CONTEXT_SLOT are replaced with a macro
CONTEXT_SLOT_MASKED that applies this mask to a value instead of using the
cast. We also use it for some calculations to avoid spilling over from
1 byte into 2 bytes for example. The cast with the new code is the same as
applying the mask 0xffff, and using the 0xff mask we can simulate the old
CONTEXT_SLOT (1 byte), which we need for seamlessly resuming old state. We
switch from the 0xff mask to the 0xffff mask when the TPM is reset.

There's one place where the s_ContextArrayMask is initialized to 0xff, and
this is when we resume 'old' STATE_RESET_DATA. The places where it is
intialized to 0xffff are in TPM_Manufacture() and
TPM_SessionStartup(SU_CLEAR), both of which are not called after resuming
state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-13 08:53:26 -04:00
Stefan Berger
31925c8e33 debian: Fix build warnings by updating compat to '10' and dh functions
This patch fixes the following issue pointed out in issue #212:

dh clean --parallel --with autotools-dev --with autoreconf
dh: warning: Compatibility levels before 10 are deprecated (level 9 in use)
dh: warning: The autotools-dev sequence is deprecated and replaced by dh in debhelper (>= 9.20160115)
dh: warning: This feature will be removed in compat 12.
   dh_auto_clean -O--parallel
dh_auto_clean: warning: Compatibility levels before 10 are deprecated (level 9 in use)
	make -j4 distclean

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-07 15:05:58 -04:00
Stefan Berger
251d9a12c3 tpm2: Surround all occurrences of BLOCK_SKIP_READ() with tests of 'rc'
Do not call BLOCK_SKIP_READ once rc has been set to any error value.
Therefore, surround all occurrences of BLOCK_SKIP_READ() with tests
of 'rc'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-04 14:23:35 -04:00
Stefan Berger
fdb9ad3b73 tpm2: Implement a cache for the private exponent D and prime Q
Implement a cache for the private exponent 'D' and prime 'Q' so that we
do not have to recalculate 'Q' and 'D' every time an RSA key is used. For
a cache hit we now use ~34000 cycles and on a cache miss it needs around
130000 cycles. Previously it needed around 100000 cycles to calcuate 'Q'
and 'D'. Assuming that keys will be reused and the cache is big enough
for the number of keys being use (64 entries), it seems well worth it.

This solution is better than extending the OBJECT with 'D' since OBJECT is
kept in the TPM's NVRAM and we would then need more memory to store OBJECTs
there.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-23 15:39:27 -04:00
Stefan Berger
23b27060b6 rev164: Bump spec version, year, and day to rev164
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00
Stefan Berger
cc2accea2b rev164: Introduce FOR_EACH_SYM and use it
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00
Stefan Berger
941c8ebdc8 rev164: Sync TpmToOsslHash.h SM3_256 support
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00
Stefan Berger
f01a41e5cf rev164: Adjust SMAC_IMPLEMENTED define
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00
Stefan Berger
b15b2e6527 rev164: Sync DebugHelpers.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00
Stefan Berger
9137a773d8 rev164: Change AGL_XYZ_VALUE to equivalend TPM_ALG_XYZ
$ grep -En "ALG_[A-Z]*_VALUE" src/tpm2/TpmTypes.h
71:#define     ALG_ERROR_VALUE             0x0000
72:#define TPM_ALG_ERROR                   (TPM_ALG_ID)(ALG_ERROR_VALUE)
73:#define     ALG_RSA_VALUE               0x0001
74:#define TPM_ALG_RSA                     (TPM_ALG_ID)(ALG_RSA_VALUE)
[...]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00
Stefan Berger
97d2df2510 rev164: Introduce FOR_EACH_HASH and use it
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-19 15:59:52 -04:00