]> git.proxmox.com Git - libtpms.git/log
libtpms.git
11 months agobump version to 0.9.6+pve1 proxmox/stable-0.9
Thomas Lamprecht [Thu, 25 May 2023 14:17:20 +0000 (16:17 +0200)]
bump version to 0.9.6+pve1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 months agod/control: Proxmox maintains this package for Proxmox projects
Thomas Lamprecht [Thu, 25 May 2023 14:27:37 +0000 (16:27 +0200)]
d/control: Proxmox maintains this package for Proxmox projects

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 months agofixup packaging make file
Thomas Lamprecht [Thu, 25 May 2023 14:19:56 +0000 (16:19 +0200)]
fixup packaging make file

11 months agoMerge tag 'v0.9.6' into proxmox/stable-0.9
Thomas Lamprecht [Thu, 25 May 2023 14:16:10 +0000 (16:16 +0200)]
Merge tag 'v0.9.6' into proxmox/stable-0.9

v0.9.6

11 months agoadd packaging make file
Thomas Lamprecht [Thu, 25 May 2023 14:11:57 +0000 (16:11 +0200)]
add packaging make file

(mis)using the fact that GNU make uses the following Makefile order
GNUmakefile, makefile and Makefile.
https://www.gnu.org/software/make/manual/make.html#Makefile-Names

13 months agorpm/debian: Add 0.9.6 entry in changelog v0.9.6
Stefan Berger [Wed, 22 Feb 2023 14:12:01 +0000 (09:12 -0500)]
rpm/debian: Add 0.9.6 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
13 months agoCHANGES: Updated CHANGES document for 0.9.6
Stefan Berger [Wed, 22 Feb 2023 14:09:21 +0000 (09:09 -0500)]
CHANGES: Updated CHANGES document for 0.9.6

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
13 months agotpm2: Check size of buffer before accessing it (CVE-2023-1017 & -1018)
Stefan Berger [Mon, 20 Feb 2023 19:41:10 +0000 (14:41 -0500)]
tpm2: Check size of buffer before accessing it (CVE-2023-1017 & -1018)

Check that there are sufficient bytes in the buffer before reading the
cipherSize from it. Also, reduce the bufferSize variable by the number
of bytes that make up the cipherSize to avoid reading and writing bytes
beyond the buffer in subsequent steps that do in-place decryption.

This fixes CVE-2023-1017 & CVE-2023-1018.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
13 months agobuild-sys: Build libtpms v0.9.6
Stefan Berger [Wed, 22 Feb 2023 14:08:14 +0000 (09:08 -0500)]
build-sys: Build libtpms v0.9.6

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
17 months agobump version to 0.9.5~bpo11+1
Thomas Lamprecht [Fri, 11 Nov 2022 11:39:45 +0000 (12:39 +0100)]
bump version to 0.9.5~bpo11+1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agoMerge tag 'v0.9.5' into proxmox/stable-0.9
Thomas Lamprecht [Fri, 11 Nov 2022 11:39:17 +0000 (12:39 +0100)]
Merge tag 'v0.9.5' into proxmox/stable-0.9

v0.9.5

21 months agorpm/debian: Add 0.9.5 entry in changelog v0.9.5
Stefan Berger [Thu, 30 Jun 2022 19:11:19 +0000 (15:11 -0400)]
rpm/debian: Add 0.9.5 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
21 months agoCHANGES: Updated CHANGES document for 0.9.5
Stefan Berger [Thu, 30 Jun 2022 19:06:59 +0000 (15:06 -0400)]
CHANGES: Updated CHANGES document for 0.9.5

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotpm2: Do not set RSA_FLAG_NO_BLINDING on RSA keys anymore
Stefan Berger [Sat, 4 Jun 2022 01:51:57 +0000 (21:51 -0400)]
tpm2: Do not set RSA_FLAG_NO_BLINDING on RSA keys anymore

Do not set the RSA_FLAG_NO_BLINDING on RSA keys anymore. The BoringSSL
documentation states the following:

"RSA_FLAG_NO_BLINDING disables blinding of private operations, which is
a dangerous thing to do. It is deprecated and should not be used. It will
be ignored whenever possible."

So, follow this documentation. OpenSSL does not seem to say much about it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotpm2: Fix a potential overflow expression (coverity)
Stefan Berger [Sat, 28 May 2022 17:38:46 +0000 (13:38 -0400)]
tpm2: Fix a potential overflow expression (coverity)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agotpm2: Fix size check in CryptSecretDecrypt
Ross Lagerwall [Mon, 23 May 2022 13:16:57 +0000 (14:16 +0100)]
tpm2: Fix size check in CryptSecretDecrypt

Check the secret size against the size of the buffer, not the size
member that has not been set yet.

Reported by Coverity.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
23 months agobuild-sys: Build libtpms v0.9.4
Stefan Berger [Wed, 25 May 2022 03:39:27 +0000 (23:39 -0400)]
build-sys: Build libtpms v0.9.4

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agorpm/debian: Add 0.9.4 entry in changelog v0.9.4
Stefan Berger [Thu, 21 Apr 2022 14:04:40 +0000 (10:04 -0400)]
rpm/debian: Add 0.9.4 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Updated CHANGES document for 0.9.4
Stefan Berger [Thu, 21 Apr 2022 13:59:27 +0000 (09:59 -0400)]
CHANGES: Updated CHANGES document for 0.9.4

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm: #undef printf in case it is #define'd (OSS-Fuzz)
Stefan Berger [Fri, 8 Apr 2022 11:46:02 +0000 (07:46 -0400)]
tpm: #undef printf in case it is #define'd (OSS-Fuzz)

The build environment used by OSS-Fuzz reports this error.

 In file included from /src/libtpms/src/tpm_debug.c:42:
 /src/libtpms/src/tpm_debug.h:69:9: error: 'printf' macro redefined [-Werror,-Wmacro-redefined]
 #define printf(...) TPMLIB_LogPrintf(__VA_ARGS__);
 :         ^
 /usr/include/x86_64-linux-gnu/bits/stdio2.h:110:11: note: previous definition is here
 # define printf(...) \
           ^
 1 error generated.

The simple fix is to #undef printf in case it is #define'd.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Initialize variables due to gcc complaint (s390x, false positive)
Steve Langasek [Wed, 30 Mar 2022 06:42:36 +0000 (08:42 +0200)]
tpm2: Initialize variables due to gcc complaint (s390x, false positive)

Detected by gcc on Ubuntu/s390x

Origin: https://git.launchpad.net/ubuntu/+source/libtpms/tree/debian/patches/uninitialized-variable.patch

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2 years agotpm12: Initialize variables due to gcc complaint (s390x, false positive)
Steve Langasek [Wed, 30 Mar 2022 06:36:51 +0000 (08:36 +0200)]
tpm12: Initialize variables due to gcc complaint (s390x, false positive)

Detected by gcc on Ubuntu/s390x

Origin: https://git.launchpad.net/ubuntu/+source/libtpms/tree/debian/patches/uninitialized-variable.patch

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2 years agoFix configure script to support _FORTIFY_SOURCE=3
Stefan Berger [Mon, 4 Apr 2022 15:03:53 +0000 (11:03 -0400)]
Fix configure script to support _FORTIFY_SOURCE=3

gcc 12.1 supports _FORTIFY_SOURCE=3. Modify the existing check for whether
_FORTIFY_SOURCE=2 can be used to test compile with the user provided
CFLAGS and only add _D_FORTIFY_SOURCE=2 to the HARDENING_CFLAGS if the
user doesn't provide anything that's not compatible.

Following an online article _FORTIFY_SOURCE=3 may add more overhead, so
we only go up to level 2 for now and let build servers or user provide
the higher level via the CFLAGS.

https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source#what_s_next_for__fortify_source

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Check return code of BN_div()
Stefan Berger [Wed, 30 Mar 2022 14:14:51 +0000 (10:14 -0400)]
tpm2: Check return code of BN_div()

Check the return code of BN_div() when calculating Q and Qr of
a private key.

Resolves: https://github.com/stefanberger/libtpms/issues/304
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Build libtpms v0.9.4
Stefan Berger [Wed, 30 Mar 2022 15:23:56 +0000 (11:23 -0400)]
build-sys: Build libtpms v0.9.4

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agorpm/debian: Add 0.9.3 entry in changelog v0.9.3
Stefan Berger [Mon, 7 Mar 2022 11:58:09 +0000 (06:58 -0500)]
rpm/debian: Add 0.9.3 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Updated CHANGES document for 0.9.3
Stefan Berger [Mon, 7 Mar 2022 11:53:29 +0000 (06:53 -0500)]
CHANGES: Updated CHANGES document for 0.9.3

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Add probing for -fstack-protector
Stefan Berger [Wed, 2 Mar 2022 17:29:59 +0000 (12:29 -0500)]
build-sys: Add probing for -fstack-protector

Add probing for -fstack-protector to the existing
-fstack-protector-strong since not all platforms support either one
of them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Do not call EVP_PKEY_CTX_set0_rsa_oaep_label() for label of size 0 (OSSL 3)
Juergen Repp [Sat, 19 Feb 2022 11:59:32 +0000 (12:59 +0100)]
tpm2: Do not call EVP_PKEY_CTX_set0_rsa_oaep_label() for label of size 0 (OSSL 3)

Openssl 3.0 did return an error if EVP_PKEY_CTX_set0_rsa_oaep_label was called
with label size 0. The function should only be called if the size of the label
is greater 0.
With this fix TPM2_RSA_Encrypt/Decrypt did work with OpenSSL 1.1 and 3.0
for encryption without label.

Signed-off-by: Juergen Repp <juergen.repp@sit.fraunhofer.de>
2 years agobuild-sys: Build libtpms v0.9.3
Stefan Berger [Wed, 2 Mar 2022 12:31:41 +0000 (07:31 -0500)]
build-sys: Build libtpms v0.9.3

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobump version to 0.9.2~bpo11+1
Thomas Lamprecht [Tue, 22 Feb 2022 07:12:44 +0000 (08:12 +0100)]
bump version to 0.9.2~bpo11+1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agoMerge tag 'v0.9.2' into proxmox/0.9.2-1
Thomas Lamprecht [Tue, 22 Feb 2022 07:11:18 +0000 (08:11 +0100)]
Merge tag 'v0.9.2' into proxmox/0.9.2-1

v0.9.2

2 years agorpm/debian: Add 0.9.2 entry in changelog v0.9.2
Stefan Berger [Wed, 5 Jan 2022 15:53:27 +0000 (10:53 -0500)]
rpm/debian: Add 0.9.2 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Updated CHANGES document for 0.9.1
Stefan Berger [Tue, 4 Jan 2022 20:04:07 +0000 (15:04 -0500)]
CHANGES: Updated CHANGES document for 0.9.1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: When writing state initialize s_ContextSlotMask if not set
Stefan Berger [Tue, 4 Jan 2022 19:45:31 +0000 (14:45 -0500)]
tpm2: When writing state initialize s_ContextSlotMask if not set

If s_ContextSlotMask was not set since the TPM 2 was not initialized
by a call to TPM_Manufacture() or the state was not resumed, then
initialize the s_ContextSlotMask to 0xffff.

This situation can occur if a VM with an attached swtpm was started
and the VM's firmware either doesn't support TPM or didn't get to
initialize the vTPM.

The following commands recreated the issue with a SeaBIOS-only VM that
had no attached hard disk but an attached TPM 2:

virsh start BIOS-only-VM ; virsh save BIOS-only-VM save.bin ; \
 virsh restore save.bin

Error: Failed to restore domain from save.bin
error: internal error: qemu unexpectedly closed the monitor: \
2022-01-04T19:26:18.835851Z qemu-system-x86_64: tpm-emulator: Setting the stateblob (type 2) failed with a TPM error 0x3 a parameter is bad
2022-01-04T19:26:18.835899Z qemu-system-x86_64: error while loading state for instance 0x0 of device 'tpm-emulator'
2022-01-04T19:26:18.835929Z qemu-system-x86_64: load of migration failed: Input/output error

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2035731
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Build libtpms v0.9.2
Stefan Berger [Tue, 4 Jan 2022 20:02:01 +0000 (15:02 -0500)]
build-sys: Build libtpms v0.9.2

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Updated CHANGES document for 0.9.1 v0.9.1
Stefan Berger [Wed, 24 Nov 2021 12:51:41 +0000 (07:51 -0500)]
CHANGES: Updated CHANGES document for 0.9.1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agorpm/debian: Add 0.9.1 entry in changelog
Stefan Berger [Wed, 24 Nov 2021 12:50:17 +0000 (07:50 -0500)]
rpm/debian: Add 0.9.1 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoFix "maybe-uninitialized" warning
kpcyrd [Fri, 29 Oct 2021 12:17:32 +0000 (14:17 +0200)]
Fix "maybe-uninitialized" warning

exp_array_size is always initialized if `rc == TPM_RC_SUCCESS` and never used
if `rc != TPM_RC_SUCCESS` but some compilers have trouble noticing this.

Signed-off-by: kpcyrd <git@rxv.cc>
2 years agotpm2: Do not write permanent state if only clock changed
Stefan Berger [Fri, 15 Oct 2021 13:20:30 +0000 (09:20 -0400)]
tpm2: Do not write permanent state if only clock changed

To avoid timeouts on short-running commands, such as TPM2_PCR_Extend,
avoid triggering the writing of the permanent state of the TPM 2
if only the clock was updated. So the clock by itself will not cause
the permanent state to be written out anymore but there have to be
other reasons as well.

The state will still be written out upon a TPM2_Shutdown, which is
supposed to be the last command to be sent to the TPM when shutting
down the VM/vTPM. Also, the permanent state will still carry the
latest clock value if it is retrieved via control channel for
VM/VTPM suspend.

The case that may be affected, but is of lesser importance, is the one
where swtpm's volatile state is written to storage using 'swtpm_ioctl -v'
and then swtpm is terminated and restarted (similar to suspend/resume)
and the permanent state file is read from storage but does not contain
the latest clock value. In this case the go.clock will be updated when
the first command after resume is executed.

This fixes the swtpm issue https://github.com/stefanberger/swtpm/issues/597.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Build libtpms v0.9.1
Stefan Berger [Fri, 15 Oct 2021 16:25:40 +0000 (12:25 -0400)]
build-sys: Build libtpms v0.9.1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobump version to 0.9.0+1
Thomas Lamprecht [Tue, 5 Oct 2021 04:41:30 +0000 (06:41 +0200)]
bump version to 0.9.0+1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agorpm/debian: Add 0.9.0 entry in changelog v0.9.0
Stefan Berger [Tue, 28 Sep 2021 20:01:45 +0000 (16:01 -0400)]
rpm/debian: Add 0.9.0 entry in changelog

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Updated CHANGES document for 0.9.0
Stefan Berger [Tue, 28 Sep 2021 20:03:07 +0000 (16:03 -0400)]
CHANGES: Updated CHANGES document for 0.9.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Use -DOPENSSL_SUPPRESS_DEPRECATED to suppress warning (OSSL 3)
Stefan Berger [Tue, 21 Sep 2021 16:40:39 +0000 (12:40 -0400)]
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>
2 years agobuild-sys: Add -Wno-deprecated-declarations to default CFLAGS (OSSL 3)
Stefan Berger [Tue, 14 Sep 2021 21:56:19 +0000 (17:56 -0400)]
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>
2 years agobuild-sys: Test for functions if #defines are not found (OSSL 3)
Stefan Berger [Tue, 14 Sep 2021 21:43:46 +0000 (17:43 -0400)]
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>
2 years agotpm2: Only call EVP_PKEY_CTX_set0_rsa_oaep_label when label != NULL (OSSL 3)
Stefan Berger [Wed, 15 Sep 2021 02:23:17 +0000 (22:23 -0400)]
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>
2 years agotpm2: Use EVP_PKEY_get1_RSA() rather than EVP_PKEY_get0_RSA (OSSL 3)
Stefan Berger [Wed, 15 Sep 2021 00:53:15 +0000 (20:53 -0400)]
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>
2 years agotpm2: Marshal event sequence objects' hash state
Stefan Berger [Thu, 9 Sep 2021 12:44:48 +0000 (08:44 -0400)]
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>
2 years agotpm2: Report supported Camellia keysizes in the JSON
Stefan Berger [Wed, 4 Aug 2021 17:49:37 +0000 (13:49 -0400)]
tpm2: Report supported Camellia keysizes in the JSON

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Enable ALG_CAMELLIA in TpmProfile.h
Stefan Berger [Fri, 3 Sep 2021 13:11:27 +0000 (09:11 -0400)]
tpm2: Enable ALG_CAMELLIA in TpmProfile.h

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Add more compile-time constants to array
Stefan Berger [Wed, 4 Aug 2021 17:49:36 +0000 (13:49 -0400)]
tpm2: Add more compile-time constants to array

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Make exp. size of compile-time constants dependent on header version
Stefan Berger [Wed, 4 Aug 2021 17:49:34 +0000 (13:49 -0400)]
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>
2 years agogit: Fix erroneous gitignore entries
Stefan Berger [Mon, 30 Aug 2021 07:26:52 +0000 (09:26 +0200)]
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>
2 years agotpm2: Extend asym key test case data generation script with sm4
Stefan Berger [Wed, 1 Sep 2021 15:42:55 +0000 (15:42 +0000)]
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>
2 years agoUpdate SymmetricTestData.h
JerryDevis [Wed, 1 Sep 2021 13:01:06 +0000 (21:01 +0800)]
Update SymmetricTestData.h

update the selftest data in dataOut_SM4_CTR

Signed-off-by: JerryDevis <seclab@huawei.com>
2 years agobuild-sys: add with_tpm1/with_tpm2 variables to .pc
Marc-André Lureau [Thu, 5 Aug 2021 15:08:13 +0000 (19:08 +0400)]
build-sys: add with_tpm1/with_tpm2 variables to .pc

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agobuild-sys: add optional --with-tpm1
Marc-André Lureau [Thu, 5 Aug 2021 11:22:49 +0000 (15:22 +0400)]
build-sys: add optional --with-tpm1

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agoMove common debug, memory & nvfile units to src/
Marc-André Lureau [Thu, 5 Aug 2021 10:21:54 +0000 (14:21 +0400)]
Move common debug, memory & nvfile units to src/

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2 years agotpm2: Use EC_POINT_set/get_affine_coordinates on OpenSSL >= 1.1
Stefan Berger [Tue, 3 Aug 2021 12:22:23 +0000 (08:22 -0400)]
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>
2 years agotpm2: Enable supported AES bit size cases using #if AES_<size>
Stefan Berger [Thu, 29 Jul 2021 22:10:49 +0000 (18:10 -0400)]
tpm2: Enable supported AES bit size cases using #if AES_<size>

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Enable supported Camellia bit size cases using #if Camellia_<size>
Stefan Berger [Thu, 29 Jul 2021 22:04:28 +0000 (18:04 -0400)]
tpm2: Enable supported Camellia bit size cases using #if Camellia_<size>

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: NVMarshal: Handle index orderly RAM without 0-sized terminating node
Stefan Berger [Fri, 23 Jul 2021 17:29:00 +0000 (13:29 -0400)]
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>
2 years agotpm2: Initialize a whole OBJECT before using it
Stefan Berger [Fri, 23 Jul 2021 01:23:58 +0000 (21:23 -0400)]
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>
2 years agotests: fuzz: Store initialized permall state blob
Stefan Berger [Thu, 22 Jul 2021 22:58:19 +0000 (18:58 -0400)]
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>
2 years agotests: fuzz: Have state suspended and resumed after every fuzz step
Stefan Berger [Thu, 22 Jul 2021 15:44:46 +0000 (11:44 -0400)]
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>
2 years agotests: fuzz: Register callbacks to avoid creating NVChip file
Stefan Berger [Thu, 22 Jul 2021 15:02:09 +0000 (11:02 -0400)]
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>
2 years agotests: fuzz: Call die() when an error from an API call was returned
Stefan Berger [Thu, 22 Jul 2021 14:59:16 +0000 (10:59 -0400)]
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>
2 years agoDebian packaging improvements
Nick Chevsky [Thu, 22 Jul 2021 19:02:31 +0000 (14:02 -0500)]
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>
2 years agoman3: Fix errors in code example in TPMLIB_RegisterCallbacks
Stefan Berger [Thu, 22 Jul 2021 14:47:30 +0000 (10:47 -0400)]
man3: Fix errors in code example in TPMLIB_RegisterCallbacks

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotpm2: Use #if ALG_CAMELLIA rather than #if 0
Stefan Berger [Wed, 21 Jul 2021 18:26:17 +0000 (14:26 -0400)]
tpm2: Use #if ALG_CAMELLIA rather than #if 0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoImprovements to .gitignore
Nick Chevsky [Tue, 20 Jul 2021 19:48:24 +0000 (14:48 -0500)]
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>
2 years agotpm2: Avoid compiler warning by using memcpy instead of MemoryCopy (gcc 10.3)
Stefan Berger [Fri, 9 Jul 2021 19:08:36 +0000 (15:08 -0400)]
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>
2 years agotpm2: Restore original value if unmarsalled value was illegal
Stefan Berger [Thu, 24 Jun 2021 00:54:44 +0000 (20:54 -0400)]
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>
2 years agotpm2: Add maxSize parameter to TPM2B_Marshal for sanity checks
Stefan Berger [Mon, 21 Jun 2021 19:10:14 +0000 (15:10 -0400)]
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>
2 years agotpm2: Reset TPM2B buffer sizes after test fails for valid buffer size
Stefan Berger [Mon, 21 Jun 2021 18:04:34 +0000 (14:04 -0400)]
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>
2 years agobuild-sys: Run autoupdate on configure.ac for autconf 2.71
Stefan Berger [Mon, 21 Jun 2021 21:51:14 +0000 (17:51 -0400)]
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>
2 years agotpm2: Consume padding bytes in TPM2_ContextLoad() (Win2k19, issue #217)
Stefan Berger [Fri, 28 May 2021 22:32:25 +0000 (18:32 -0400)]
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>
2 years agoTravis: Install libjson-glib-dev and drop a few python dependencies
Stefan Berger [Fri, 28 May 2021 17:37:31 +0000 (13:37 -0400)]
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>
2 years agobuild-sys: leave CFLAGS/LDFLAGS for user to be defined
Marc-André Lureau [Tue, 18 May 2021 13:10:52 +0000 (17:10 +0400)]
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>
2 years agotpm2: Switch to UINT16 for CONTEXT_SLOT and 64k context gap
Stefan Berger [Fri, 30 Apr 2021 20:44:03 +0000 (16:44 -0400)]
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>
2 years agodebian: Fix build warnings by updating compat to '10' and dh functions
Stefan Berger [Fri, 7 May 2021 01:02:17 +0000 (21:02 -0400)]
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>
2 years agotpm2: Surround all occurrences of BLOCK_SKIP_READ() with tests of 'rc'
Stefan Berger [Tue, 4 May 2021 15:37:29 +0000 (11:37 -0400)]
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>
3 years agotpm2: Implement a cache for the private exponent D and prime Q
Stefan Berger [Thu, 25 Feb 2021 19:05:28 +0000 (14:05 -0500)]
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>
3 years agorev164: Bump spec version, year, and day to rev164
Stefan Berger [Mon, 15 Mar 2021 19:01:21 +0000 (15:01 -0400)]
rev164: Bump spec version, year, and day to rev164

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Introduce FOR_EACH_SYM and use it
Stefan Berger [Tue, 23 Feb 2021 00:33:10 +0000 (19:33 -0500)]
rev164: Introduce FOR_EACH_SYM and use it

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Sync TpmToOsslHash.h SM3_256 support
Stefan Berger [Tue, 23 Feb 2021 01:04:18 +0000 (20:04 -0500)]
rev164: Sync TpmToOsslHash.h SM3_256 support

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Adjust SMAC_IMPLEMENTED define
Stefan Berger [Tue, 23 Feb 2021 01:01:30 +0000 (20:01 -0500)]
rev164: Adjust SMAC_IMPLEMENTED define

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Sync DebugHelpers.c
Stefan Berger [Tue, 23 Feb 2021 00:58:12 +0000 (19:58 -0500)]
rev164: Sync DebugHelpers.c

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Change AGL_XYZ_VALUE to equivalend TPM_ALG_XYZ
Stefan Berger [Mon, 22 Feb 2021 23:47:24 +0000 (18:47 -0500)]
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>
3 years agorev164: Introduce FOR_EACH_HASH and use it
Stefan Berger [Mon, 22 Feb 2021 22:04:38 +0000 (17:04 -0500)]
rev164: Introduce FOR_EACH_HASH and use it

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Change return types from BOOL to bool
Stefan Berger [Mon, 22 Feb 2021 21:50:47 +0000 (16:50 -0500)]
rev164: Change return types from BOOL to bool

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Use multiple BOOLs to evaluate rather than single one
Stefan Berger [Mon, 22 Feb 2021 21:49:08 +0000 (16:49 -0500)]
rev164: Use multiple BOOLs to evaluate rather than single one

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Remove unreachable return statement
Stefan Berger [Mon, 22 Feb 2021 21:47:54 +0000 (16:47 -0500)]
rev164: Remove unreachable return statement

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Fix a comparison (< to <=) in unused code (bugfix?)
Stefan Berger [Mon, 22 Feb 2021 21:46:53 +0000 (16:46 -0500)]
rev164: Fix a comparison (< to <=) in unused code (bugfix?)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: sync NvFileSize.c
Stefan Berger [Mon, 22 Feb 2021 21:21:50 +0000 (16:21 -0500)]
rev164: sync NvFileSize.c

3 years agorev164: Resolve long chain of logical ands (trivial)
Stefan Berger [Mon, 22 Feb 2021 21:17:23 +0000 (16:17 -0500)]
rev164: Resolve long chain of logical ands (trivial)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Add (unused) SM3 and SHA3 related digests to HashTestData
Stefan Berger [Mon, 22 Feb 2021 21:00:19 +0000 (16:00 -0500)]
rev164: Add (unused) SM3 and SHA3 related digests to HashTestData

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agorev164: Add (unused) SHA3 related defines for CONTEXT_HASH_ALGORITHM
Stefan Berger [Mon, 22 Feb 2021 20:56:32 +0000 (15:56 -0500)]
rev164: Add (unused) SHA3 related defines for CONTEXT_HASH_ALGORITHM

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>