]> git.proxmox.com Git - libtpms.git/log
libtpms.git
6 years agotpm2: Call _rpc__Signal_PowerOff inside TPM2_Terminate
Stefan Berger [Wed, 14 Mar 2018 18:45:13 +0000 (14:45 -0400)]
tpm2: Call _rpc__Signal_PowerOff inside TPM2_Terminate

This way we can later on detect whether the TPM 2 is running
(= powered on).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: add missing newline after error message
Stefan Berger [Sun, 25 Feb 2018 20:02:34 +0000 (15:02 -0500)]
tpm2: add missing newline after error message

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Build libtpms with TPM 2 code now
Stefan Berger [Mon, 24 Jul 2017 18:08:25 +0000 (14:08 -0400)]
tpm2: Build libtpms with TPM 2 code now

Now that patches for writing the state into files and extensions
to their headers have all been applied we can build the TPM 2
code into the library.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Write marshalled NvChip into file and read it
Stefan Berger [Fri, 23 Feb 2018 22:32:37 +0000 (17:32 -0500)]
tpm2: Write marshalled NvChip into file and read it

When storing, marshalled the NvChip memory's contents and write the byte
stream into the file rather than the NvChip directly. When reading, assume
we get a marshalled NvChip file and we now need to unmarshal the byte
stream and reconstruct the NvChip.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Add test harness for marshalling and reconstructing NVChip
Stefan Berger [Thu, 22 Feb 2018 19:02:25 +0000 (14:02 -0500)]
tpm2: Add test harness for marshalling and reconstructing NVChip

6 years agotpm2: Enable skipping of compile-time optional variables when unmarshalling
Stefan Berger [Sat, 24 Feb 2018 20:01:58 +0000 (15:01 -0500)]
tpm2: Enable skipping of compile-time optional variables when unmarshalling

Some variables are compile-time optional and can be skipped if they are
contained in the byte stream but the implementation does not need them.
We enable this with a few simple macros that we use to replace those parts
where the has_block variables are written into the byte stream. On the
unmarshalling side we check whether the block is in the byte stream and
whether the implementation needs the block and react appropriately
including skipping over the block in the byte stream or skipping over the
code unmarshalling the data.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Remove first parameter from NV_HEADER_Marshal
Stefan Berger [Fri, 23 Feb 2018 23:53:58 +0000 (18:53 -0500)]
tpm2: Remove first parameter from NV_HEADER_Marshal

Remove the NV_HEADER parameter from NV_Header_Marshal() function.
In the single case where it was needed, initialize a UINT32 with
the 'magic'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Revert NVChip memory layout to native
Stefan Berger [Fri, 23 Feb 2018 18:49:17 +0000 (13:49 -0500)]
tpm2: Revert NVChip memory layout to native

Get rid of all the changes to have the NvChip written in big
endian format. Remove test case.

Now the NvChip in memory holds data in native format.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Implement function to marshal and reconstruct the NvChip
Stefan Berger [Thu, 22 Feb 2018 18:50:46 +0000 (13:50 -0500)]
tpm2: Implement function to marshal and reconstruct the NvChip

Marshal the NvChip memory into a byte stream and reconstruct the
NvChip memory from the byte stream.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Push nvOffset and structure size parameters into functions
Stefan Berger [Tue, 20 Feb 2018 19:28:55 +0000 (14:28 -0500)]
tpm2: Push nvOffset and structure size parameters into functions

Push the nvOffset parameter where either one of the 4 state blobs
found in the NVRAM file can be found. Also push the size parameter
into the functions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Major rework of state marshalling breaking compatibility
Stefan Berger [Mon, 19 Feb 2018 22:09:03 +0000 (17:09 -0500)]
tpm2: Major rework of state marshalling breaking compatibility

In one big step, marshal more variables and constants for volatilestate:

- compile-time constants related to data structures marshalled as part
  of the volatile state as well as some other ones

- variables related to time that fix problems with dictionary attack
  related timeouts

- 3 failure related variables

Also introduce magic and version headers when marshalling all the
internal data structures.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Add missing offset checks and comments about gaps to test case
Stefan Berger [Tue, 20 Feb 2018 16:00:04 +0000 (11:00 -0500)]
tpm2: Add missing offset checks and comments about gaps to test case

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Make tpmclock() a public function
Stefan Berger [Mon, 19 Feb 2018 22:07:32 +0000 (17:07 -0500)]
tpm2: Make tpmclock() a public function

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Update comments on variables stored in volatile state
Stefan Berger [Mon, 19 Feb 2018 21:07:07 +0000 (16:07 -0500)]
tpm2: Update comments on variables stored in volatile state

Update the comments on some of the variables we are storing
as part of storing volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Fix memory leak in VolatileLoad()
Stefan Berger [Sun, 18 Feb 2018 02:21:38 +0000 (21:21 -0500)]
tpm2: Fix memory leak in VolatileLoad()

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Implement TPM2_ValidateState
Stefan Berger [Sat, 17 Feb 2018 20:24:42 +0000 (15:24 -0500)]
tpm2: Implement TPM2_ValidateState

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Have VolatileLoad() return TPM_RC
Stefan Berger [Sat, 17 Feb 2018 16:36:32 +0000 (11:36 -0500)]
tpm2: Have VolatileLoad() return TPM_RC

Have VolatileLoad return a TPM_RC so the caller can see
whether the loading of the volatiles state succeeded.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Activate failure mode if any blobs could not be handled
Stefan Berger [Sat, 17 Feb 2018 03:17:33 +0000 (22:17 -0500)]
tpm2: Activate failure mode if any blobs could not be handled

When any of the NVRAM blobs could not be handled properly we put
the TPM into failure mode. This should only happen if someone
corrupts the state or if the state blobs are more recent than
what the TPM supports.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: extract header init and check from SWAP functions
Stefan Berger [Sat, 17 Feb 2018 02:19:11 +0000 (21:19 -0500)]
tpm2: extract header init and check from SWAP functions

Extract the initialization of the header fom the SWAP functions
and initialize the header by the appropriat callers of the SWAP
functions.

Version and magic can be 0 when first read after NVRAM was
initialized. So we initialize it then.

Add skeleton code where the upgrade of the data structure would
have to happen later on.

Refuse to accept newer versions of structures than what is supported
at the moment. In particular, return error codes in case the blobs
that were read are not supported.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Enforce version of volatile state blob
Stefan Berger [Fri, 9 Feb 2018 18:11:29 +0000 (13:11 -0500)]
tpm2: Enforce version of volatile state blob

Enforce the version of the volatile state blob. Do not accept a more
recent version than what we support at this point, so downgrading of
state is prevented this way.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Fix compiler error due to comparison with different signedness
Stefan Berger [Tue, 19 Dec 2017 12:12:39 +0000 (07:12 -0500)]
tpm2: Fix compiler error due to comparison with different signedness

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Build Debian 0.6.0-1-dev1
Stefan Berger [Mon, 13 Nov 2017 18:09:31 +0000 (13:09 -0500)]
build: Build Debian 0.6.0-1-dev1

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Build RPM 0.6.0-1_dev1
Stefan Berger [Mon, 13 Nov 2017 17:58:31 +0000 (12:58 -0500)]
build: Build RPM 0.6.0-1_dev1

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: NVRAM file does exist if we get TPM_DECRYPT_ERROR
Stefan Berger [Tue, 14 Nov 2017 00:28:12 +0000 (19:28 -0500)]
tpm2: NVRAM file does exist if we get TPM_DECRYPT_ERROR

In case the NVRAM file cannot be decrypted we get a TPM_DECRYPT_ERROR
error which also indicates that the file exists. So do not return FALSE
in this case, which would delete the existing file and start over with
a blank file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: add missing header filenames
Stefan Berger [Mon, 13 Nov 2017 17:24:47 +0000 (12:24 -0500)]
tpm2: add missing header filenames

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Handle failures better
Stefan Berger [Sat, 11 Nov 2017 04:02:28 +0000 (23:02 -0500)]
tpm2: Handle failures better

The current TpmFail() implementation invokes longjmp() at the end
and crashes with a segmentation fault if setjmp() wasn't called before.
To avoid this we implement TpmSetFailureMode() that logs the failure and
sets the TPM into failure mode. Since NVRAM may set failure mode before
the CryptInit() is called, we need to make sure we don't reset the failure
mode variable in case CryptInit() succeeds. In this case we now call the
FAIL_NOCMD() macro.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: make I/O buffer sizes adjustable
Stefan Berger [Sun, 5 Nov 2017 16:28:19 +0000 (11:28 -0500)]
tpm2: make I/O buffer sizes adjustable

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: comment out _COMMAND_FLAGS_ since not needed
Stefan Berger [Thu, 2 Nov 2017 13:22:49 +0000 (09:22 -0400)]
tpm2: comment out _COMMAND_FLAGS_ since not needed

Implement bitfield support for _COMMAND_FLAGS_ but comment it
out since the structure is not used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Create real random numbers to get different keys
Stefan Berger [Wed, 1 Nov 2017 00:29:18 +0000 (20:29 -0400)]
tpm2: Create real random numbers to get different keys

Do not use rand() for creating random numbers since this only
creates pseudo random numbers and the keys always end up being
the same since it wasn't seeded, either.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Make compileable on OpenBSD
Stefan Berger [Thu, 12 Oct 2017 01:14:16 +0000 (21:14 -0400)]
tpm2: Make compileable on OpenBSD

Make TPM 2 code compileable on OpenBSD where we have an older version
of gcc with missing builtin swap functions and where endianes #defines
area also different.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoPort TPM 2 to OpenSSL 1.1
Stefan Berger [Mon, 25 Sep 2017 21:44:36 +0000 (17:44 -0400)]
Port TPM 2 to OpenSSL 1.1

Port the TPM 2 code to OpenSSL 1.1 by accessing the OpenSSL BIGNUM
only via its public functions. To get there it is necessary to
implement the Bn2bin() function that converts the TPM internal
representation of a bigNum to an array of unsigned chars that can
then be passed to the OpenSSL BN_bin2bn() function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: add test for checking proper offsets in NVRAM
Stefan Berger [Sat, 30 Sep 2017 22:48:37 +0000 (18:48 -0400)]
tpm2: add test for checking proper offsets in NVRAM

Add a test for checking for proper offsets in the NVRAM that
must never change.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Choose the TPM2 NVRAM memory to be 64kb
Stefan Berger [Fri, 10 Nov 2017 22:21:42 +0000 (17:21 -0500)]
tpm2: Choose the TPM2 NVRAM memory to be 64kb

For this to work increase the maximum allocatable memory chunk
supported by TPM_Malloc() to 128k.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Create functions ANY_OBJECT_Marshal/Unmarshal/SWAP
Stefan Berger [Tue, 24 Oct 2017 19:48:06 +0000 (15:48 -0400)]
tpm2: Create functions ANY_OBJECT_Marshal/Unmarshal/SWAP

Create functions ANY_OBJECT_Marshal/Unmarshal/SWAP so that
we can then handle OBJECT and HASH_OBJECT dependening on the
attribute flags.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Support bitfields for big endian
Stefan Berger [Wed, 25 Oct 2017 20:21:51 +0000 (16:21 -0400)]
tpm2: Support bitfields for big endian

6 years agotpm2: Add padding to structs for 32bit arch alignments
Stefan Berger [Thu, 5 Oct 2017 13:33:38 +0000 (09:33 -0400)]
tpm2: Add padding to structs for 32bit arch alignments

Some data structures need padding bytes to align the data
structures on 32bit machines to resemble the alignment on
64bit machines. Without it we wouldn't be able to resume
the state on a 32bit machine written by a 64bit machine.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: fix marshalling/unmarshalling of BOOL for big endian
Stefan Berger [Mon, 24 Jul 2017 22:36:07 +0000 (18:36 -0400)]
tpm2: fix marshalling/unmarshalling of BOOL for big endian

BOOL is an int and therefore we cannot just write out the
single byte at the address of the BOOL. On big endian systems
the BOOL value is at offset 3. So we implement functions for
marshalling and unmarshalling of a BOOL as a single byte and
do the conversion with the 'int' there.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Prepend header to NVRAM written structs and roundup their sizes
Stefan Berger [Thu, 6 Apr 2017 15:19:01 +0000 (11:19 -0400)]
tpm2: Prepend header to NVRAM written structs and roundup their sizes

Round up the sizes of the structures written into NVRAM so we
have some space in front of them.

Prepend a heaer in front of the structure written into NVRAM. Initialize
them with a version number and a magic. The version number should
theoretically allow us to read TPM 2 state of different revisions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Write TPMEstablished BOOL in volatile state
Stefan Berger [Wed, 14 Jun 2017 17:57:06 +0000 (13:57 -0400)]
tpm2: Write TPMEstablished BOOL in volatile state

Write the TPMEstablished BOOL in volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Add functions to write state in big endian format
Stefan Berger [Thu, 16 Mar 2017 01:52:23 +0000 (21:52 -0400)]
tpm2: Add functions to write state in big endian format

Add functions to marshal the volatile state of the TPM. We write it in
big endian format.

Add functions to write the data structure in big endian format
into NVRAM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoEnable TPM 2 on big endian systems
Stefan Berger [Tue, 28 Mar 2017 23:27:03 +0000 (19:27 -0400)]
Enable TPM 2 on big endian systems

Enable TPM 2 on big endian systems.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Clean up the NV_LIST_TERMINATOR structure
Stefan Berger [Wed, 22 Mar 2017 23:36:27 +0000 (19:36 -0400)]
tpm2: Clean up the NV_LIST_TERMINATOR structure

Clean up code around the NV_LIST_TERMINATOR structure. It's not
an array of bytes or UINT32s, but a UINT32 followed by a UINT64.

6 years agoSupport for TPMEstablished flag in TPM2 code
Stefan Berger [Wed, 21 Dec 2016 21:26:19 +0000 (16:26 -0500)]
Support for TPMEstablished flag in TPM2 code

Resolve a few TPMEstablishment bit related FIXMEs by implementing
supporting functions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Return failure code if TPM was put into failure mode
Stefan Berger [Thu, 15 Jun 2017 16:29:13 +0000 (12:29 -0400)]
tpm2: Return failure code if TPM was put into failure mode

Return a failure code to the control command initiated
initialization of the TPM 2.

Reset the failure move on every INIT call so that corrections
can be done without having to restart the TPM emulator.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoIntegrate the TPM 2 into the library; do not compile with TPM 2 yet
Stefan Berger [Wed, 21 Dec 2016 21:26:19 +0000 (16:26 -0500)]
Integrate the TPM 2 into the library; do not compile with TPM 2 yet

Introduce --with-tpm2 for ./configure to enable building with
TPM 2 functionality. Delay the building of TPM 2 code until more
patches are applied and the vTPM state that's created has a chance
of being backwards compatible.

Extend the libtpms API to allow user to choose version of TPM.

Missing functionality at this point:
- TPM 2 needs to be extended to serialize and deserialize its volatile state
- Handling of the establishment bit

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoRevert "Fix TPM_PROOF to work with older versions"
Stefan Berger [Fri, 10 Nov 2017 22:28:23 +0000 (17:28 -0500)]
Revert "Fix TPM_PROOF to work with older versions"

This reverts commit 986eb59f13f12c0452895c7c0fbbffb338787132.

6 years agoFix TPM_PROOF to work with older versions
Stefan Berger [Mon, 24 Jul 2017 15:08:41 +0000 (11:08 -0400)]
Fix TPM_PROOF to work with older versions

6 years agoChoose build switches for TPM2
Stefan Berger [Wed, 15 Mar 2017 20:14:17 +0000 (16:14 -0400)]
Choose build switches for TPM2

Choose build switches:
- do not build with SIMULATION; fix the code to avoid missing symbols

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Make RADIX_BITS dependent on openssl #defines
Stefan Berger [Wed, 31 May 2017 18:52:20 +0000 (14:52 -0400)]
tpm2: Make RADIX_BITS dependent on openssl #defines

Make the #define RADIX_BITS dependent on #defines set by the
OpenSSL library: THIRTY_TWO_BIT and SIXTY_FOUR_BIT_LONG

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: fix a bug in rev146 of the TPM2 code
Stefan Berger [Mon, 24 Jul 2017 16:27:03 +0000 (12:27 -0400)]
tpm2: fix a bug in rev146 of the TPM2 code

6 years agoFix compilation errors in the TPM 2 code
Stefan Berger [Wed, 21 Dec 2016 21:26:19 +0000 (16:26 -0500)]
Fix compilation errors in the TPM 2 code

Fix compilation errors in the TPM 2 code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoExtend license texts with TPM 2 specifics
Stefan Berger [Wed, 21 Dec 2016 21:26:19 +0000 (16:26 -0500)]
Extend license texts with TPM 2 specifics

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpgrade from rev 142 to rev 146
Stefan Berger [Sun, 23 Jul 2017 20:01:39 +0000 (16:01 -0400)]
Upgrade from rev 142 to rev 146

This is the diff patch between rev 142 and 146.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoAdd TPM 2 code
Stefan Berger [Wed, 21 Dec 2016 21:26:18 +0000 (16:26 -0500)]
Add TPM 2 code

Add TPM 2 code.

This is rev. 142 code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUse malloc/free rather than TPM_Malloc/TPM_Free in library code
Stefan Berger [Fri, 15 Jun 2018 21:41:33 +0000 (17:41 -0400)]
Use malloc/free rather than TPM_Malloc/TPM_Free in library code

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: Add AC_CONFIG_AUX_DIR to configure.ac
Stefan Berger [Mon, 28 May 2018 00:31:55 +0000 (20:31 -0400)]
build-sys: Add AC_CONFIG_AUX_DIR to configure.ac

The Travis build of swtpm now has a problem due to missing ltmain.sh. Add
AC_CONFIG_AUX_DIR to configure.ac to resolve the issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: add a simple autogen.sh
Marc-André Lureau [Fri, 25 May 2018 12:06:02 +0000 (14:06 +0200)]
build-sys: add a simple autogen.sh

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agotpm12: fix uninitialized variable warning
Marc-André Lureau [Fri, 25 May 2018 11:07:01 +0000 (13:07 +0200)]
tpm12: fix uninitialized variable warning

clang complains:

tpm12/tpm_init.c:666:9: error: variable 'tag' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
    if (rc == 0) {
        ^~~~~~~
tpm12/tpm_init.c:746:9: note: uninitialized use occurs here
    if (tag == TPM_TAG_STCLEAR_DATA) {
        ^~~
tpm12/tpm_init.c:666:5: note: remove the 'if' if its condition is always true
    if (rc == 0) {
    ^~~~~~~~~~~~~
tpm12/tpm_init.c:662:28: note: initialize the variable 'tag' to silence this warning
    TPM_STRUCTURE_TAG   tag;
                           ^
                            = 0

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agobuild-sys: remove generated files
Marc-André Lureau [Fri, 25 May 2018 12:05:33 +0000 (14:05 +0200)]
build-sys: remove generated files

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agoDereference the pointer rather than the pointer to the pointer
Stefan Berger [Mon, 14 May 2018 20:48:19 +0000 (16:48 -0400)]
Dereference the pointer rather than the pointer to the pointer

A bug discovered by coverity. This fixes the bug.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoLoad permanent state before testing volatile or save state
Stefan Berger [Sun, 13 May 2018 23:32:11 +0000 (19:32 -0400)]
Load permanent state before testing volatile or save state

The permanent state has to be loaded before the volatile or save state blobs
can be tested since they are connected to the permanenent state.

We implement TPM_PermanentAll_NVLoad_Preserve that makes a copy of any
cached permanent state blobs before we load the permanent state via
TPM_PermanentAll_NVLoad, which would consume and free any cached state blob,
if there was one (would fall back to reading from file otherwise). We then
set the copy of any cached permanent state blob back so that it can be used
when the TPM 1.2 start.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoClear the cached blobs if SetState fails on checking one of them
Stefan Berger [Sun, 13 May 2018 23:16:09 +0000 (19:16 -0400)]
Clear the cached blobs if SetState fails on checking one of them

Clear all the cached states blobs set using TPMLIB_SetState if one
of them cannot be accepted.

Signed-off-by: Stfean Berger <stefanb@linux.vnet.ibm.com>
6 years agoExpose the two new API calls TPMLIB_Get/SetState
Stefan Berger [Fri, 11 May 2018 20:05:28 +0000 (16:05 -0400)]
Expose the two new API calls TPMLIB_Get/SetState

Expose the two new API calls TPMLIB_GetState() and TPMLIB_SetState().
Fix one parameter in the TPMLIB_GetState() call.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoFix a bug introduced in 3238742947 (TPMLIB_ValidateState)
Stefan Berger [Fri, 11 May 2018 03:45:47 +0000 (23:45 -0400)]
Fix a bug introduced in 3238742947 (TPMLIB_ValidateState)

The permanent state has to be loaded before either the volatile
or the save state can be validated.

Also fix another bug that was testing for whether there was no
cached state. It should test whether there is a cached state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoTPM_MainInit write permanent state blob if SetState() blob was used
Stefan Berger [Sun, 18 Mar 2018 22:22:51 +0000 (18:22 -0400)]
TPM_MainInit write permanent state blob if SetState() blob was used

If the permanent state was set using SetState() write the permanent
state once we successfully read the volatile state and can use it.
This way we have the state in a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoModify TPM_NVRAM_LoadData() to try to get cached state blob
Stefan Berger [Sun, 11 Mar 2018 00:13:01 +0000 (19:13 -0500)]
Modify TPM_NVRAM_LoadData() to try to get cached state blob

Modify TPM_NVRAM_LoadData() to try to get the cached state blob before trying
to read the state blob from the file. We clear the state blob as part of
passing it to the TPM.

A side effect is now that if TPMLIB_ValidateState is called on a blob that
this call would not remove the cached blob. So we have to save a copy before
reading (and parsing) the state blob so we still have it when TPM_MainInit()
is called.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoAdd APIs for getting and setting all state blobs
Stefan Berger [Sat, 10 Mar 2018 23:45:36 +0000 (18:45 -0500)]
Add APIs for getting and setting all state blobs

This patch adds APIs for getting and setting all types of state
blobs. We cache these blobs and allow them to be picked up when
the TPM starts. It will get any of these state blobs, if they
were set, before we go out and try to read the state blob from
a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoRefactor TPM12_ValidateState to implement loop
Stefan Berger [Sun, 11 Mar 2018 00:13:01 +0000 (19:13 -0500)]
Refactor TPM12_ValidateState to implement loop

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoAdd TPMAttributes JSON object to GetInfo interface
Stefan Berger [Fri, 4 May 2018 23:33:08 +0000 (19:33 -0400)]
Add TPMAttributes JSON object to GetInfo interface

Requesting TPMLIB_INFO_TPMATTRIBUTES returns:

{
  "TPMAttributes": {
    "manufacturer": "id:00001014",
    "version": "id:00740001",
    "model": "swtpm"
  }
}

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoImplement TPMLIB_GetInfo() to for example get TPM spec. info
Stefan Berger [Mon, 23 Apr 2018 10:29:04 +0000 (06:29 -0400)]
Implement TPMLIB_GetInfo() to for example get TPM spec. info

The EK certificates need information about the TPM specification that was
implemented. The best place to get the information from seems the TPM itself.
So we implement a function TPMLIB_GetInfo() to allow to query for the TPM
specification information and possibly other information in the future.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoFix logic invoking validation of state
Stefan Berger [Wed, 28 Mar 2018 01:51:21 +0000 (21:51 -0400)]
Fix logic invoking validation of state

The logic for invoking the validation of the TPM 1.2 state was
broken. The validation of volatile and save state state requires
that the permanent state is available, so we always load it
first.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoFix typos for logical and
Stefan Berger [Tue, 27 Mar 2018 23:56:01 +0000 (19:56 -0400)]
Fix typos for logical and

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoImplement TPMLIB_ValidateState() to test state blobs early
Stefan Berger [Sat, 17 Feb 2018 18:10:12 +0000 (13:10 -0500)]
Implement TPMLIB_ValidateState() to test state blobs early

Implement TPMLIB_ValidateState(), which is supposed to be used
for checking usability of state blobs before TPMLIB_MainInit()
is called or TPM_Startup has been sent to the TPM.

This function is useful to be called once TPM state blobs
have been migrated to a destination and we need to check
whether libtpms can use these state blobs and if not
we have a chance to fall back to the migration source host.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoAlways return minimum and maximum buffer sizes
Stefan Berger [Tue, 26 Dec 2017 15:17:47 +0000 (10:17 -0500)]
Always return minimum and maximum buffer sizes

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoSupport a range of 3k to 4k for TPM 1.2 buffer size
Stefan Berger [Tue, 19 Dec 2017 00:33:48 +0000 (19:33 -0500)]
Support a range of 3k to 4k for TPM 1.2 buffer size

Extend the previous support of a fixed buffer size to work
with a minimum of 3k and a maximum of 4k.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: fix Cygwin compiler warning
Stefan Berger [Mon, 13 Nov 2017 15:15:36 +0000 (10:15 -0500)]
build: fix Cygwin compiler warning

Cygwin compiler complains about comparison of signed and unsigned
integer on the ~0.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoAdd unsuppressable internal logging using ~0 indent
Stefan Berger [Sat, 11 Nov 2017 15:43:14 +0000 (10:43 -0500)]
Add unsuppressable internal  logging using ~0 indent

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoExtend TPMLIB_SetBufferSize() call with min/max size parameters
Stefan Berger [Sun, 5 Nov 2017 16:57:01 +0000 (11:57 -0500)]
Extend TPMLIB_SetBufferSize() call with min/max size parameters

Also allow to get the minimum and maximum supported buffer size
with the TPMLIB_SetBufferSize() call.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoMake TPMLIB_SetBufferSize function visible
Stefan Berger [Sat, 4 Nov 2017 06:08:11 +0000 (02:08 -0400)]
Make TPMLIB_SetBufferSize function visible

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoImplement TPMLIB_SetBufferSize() for setting the size of the I/O buffer
Stefan Berger [Sat, 4 Nov 2017 04:27:10 +0000 (00:27 -0400)]
Implement TPMLIB_SetBufferSize() for setting the size of the I/O buffer

Implement TPMLIB_SetBufferSize() for setting the size of the I/O buffer
that the TPM may advertise. For TPM 1.2 the size remains fixed since the
TIS interface can handle the current 4096 bytes.

This function will be important for TPM 2 with a CRB interface that cannot
handle 4096 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: add -lc when checking for missing symbols on OpenBSD
Stefan Berger [Wed, 11 Oct 2017 21:31:51 +0000 (17:31 -0400)]
build: add -lc when checking for missing symbols on OpenBSD

When checking for missing symbols we need to add -lc to the libraries
passed to gcc otherwise we always see lots of missing symbols even if
there aren't any.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Only add -Wall -Werror etc. if user did not set CFLAGS explicitly
Stefan Berger [Wed, 11 Oct 2017 20:08:51 +0000 (16:08 -0400)]
build: Only add -Wall -Werror etc. if user did not set CFLAGS explicitly

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: work around possibly missing tools
Stefan Berger [Wed, 11 Oct 2017 19:42:40 +0000 (15:42 -0400)]
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>
6 years agotpm12: LibreSSL seems to not have the new OpenSSL 1.1 API
Stefan Berger [Wed, 11 Oct 2017 18:45:41 +0000 (14:45 -0400)]
tpm12: LibreSSL seems to not have the new OpenSSL 1.1 API

LibreSSL on OpenBSD seems to not support the new API of OpenSSL 1.1.
So create a new #define OPENSSL_OLD_API that is set if the old API
is to be used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: fix out of tree builds
André Draszik [Mon, 9 Oct 2017 11:38:21 +0000 (12:38 +0100)]
build: fix out of tree builds

../libtool  --tag=CC   --mode=link gcc -include tpm_library_conf.h -I../../include/libtpms -fstack-protector-strong -Wl,-z,relro -Wl,-z,now  -DTPM_V12 -DTPM_PCCLIENT -DTPM_VOLATILE_LOAD -DTPM_ENABLE_ACTIVATE -DTPM_AES -DTPM_LIBTPMS_CALLBACKS -DTPM_NV_DISK -DTPM_POSIX  -g -O2 -Wall -Werror -Wreturn-type -Wsign-compare -Wl,--version-script=./libtpms.syms -version-info 6:0:6 -no-undefined  -o libtpms.la -rpath /usr/local/lib libtpms_la-tpm_library.lo libtpms_tpm12.la -lcrypto
libtool: link: gcc -shared  -fPIC -DPIC  .libs/libtpms_la-tpm_library.o  -Wl,--whole-archive ./.libs/libtpms_tpm12.a -Wl,--no-whole-archive  -lcrypto  -fstack-protector-strong -Wl,-z -Wl,relro -Wl,-z -Wl,now -g -O2 -Wl,--version-script=./libtpms.syms   -Wl,-soname -Wl,libtpms.so.0 -o .libs/libtpms.so.0.6.0
/usr/bin/ld: cannot open linker script file ./libtpms.syms: No such file or directory

libtpms.syms is inside the source directory, so when doing out
of tree builds it can't be found - fix the libtool invocation.

Signed-off-by: André Draszik <adraszik@tycoint.com>
6 years agotpm12: Use latests tpm_delegate fixing code format
Stefan Berger [Thu, 5 Oct 2017 13:40:07 +0000 (09:40 -0400)]
tpm12: Use latests tpm_delegate fixing code format

Signed-off-by: Stefan Berger <stefanb@linxu.vnet.ibm.com>
6 years agotpm12: use latest tpm_pcr.c fixing return code assignment
Stefan Berger [Thu, 5 Oct 2017 13:37:47 +0000 (09:37 -0400)]
tpm12: use latest tpm_pcr.c fixing return code assignment

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agobuild: integrate Travis CI automation with Coverty Scan
Stefan Berger [Fri, 22 Sep 2017 15:27:35 +0000 (11:27 -0400)]
build: integrate Travis CI automation with Coverty Scan

Integrate the Travis CI automated build & test with Coverity Scan.
Automatically submit a Coverity Scan if we push to the coverity_scan
branch.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoci: add .travis.yml
Stefan Berger [Mon, 31 Jul 2017 16:30:42 +0000 (12:30 -0400)]
ci: add .travis.yml

Add Travis build script.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotpm12: use latest tpm_crypto.c for OpenSSL 1.1 support
Stefan Berger [Fri, 28 Jul 2017 21:04:10 +0000 (17:04 -0400)]
tpm12: use latest tpm_crypto.c for OpenSSL 1.1 support

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotpm12: use latest tpm_pcr.c adding more debugging output
Stefan Berger [Fri, 28 Jul 2017 21:00:21 +0000 (17:00 -0400)]
tpm12: use latest tpm_pcr.c adding more debugging output

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotpm12: use latest tpm_daa.c fixing return code assignments and a bug
Stefan Berger [Fri, 28 Jul 2017 20:57:58 +0000 (16:57 -0400)]
tpm12: use latest tpm_daa.c fixing return code assignments and a bug

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotpm12: use latest tpm_nvram.c that display additional error message
Stefan Berger [Fri, 28 Jul 2017 20:56:29 +0000 (16:56 -0400)]
tpm12: use latest tpm_nvram.c that display additional error message

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotpm12: use latest tpm_svnrevision.c that increase major and minor numbers
Stefan Berger [Fri, 28 Jul 2017 20:54:15 +0000 (16:54 -0400)]
tpm12: use latest tpm_svnrevision.c that increase major and minor numbers

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agotpm12: use latest tpm_transport.c with a return code assigned
Stefan Berger [Fri, 28 Jul 2017 20:52:55 +0000 (16:52 -0400)]
tpm12: use latest tpm_transport.c with a return code assigned

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoIgnore a few more files and delete depcomp
Stefan Berger [Thu, 6 Apr 2017 18:17:30 +0000 (14:17 -0400)]
Ignore a few more files and delete depcomp

Ignore *.log and *.trs files from the test suite.
Ignore compile and the 'missing' file.
Remove the depcomp file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoFix logging of prefix for TPM_PrintAll
Stefan Berger [Thu, 30 Mar 2017 12:23:48 +0000 (08:23 -0400)]
Fix logging of prefix for TPM_PrintAll

7 years agoConvert another vdprintf to dprintf
Stefan Berger [Fri, 3 Feb 2017 15:58:22 +0000 (10:58 -0500)]
Convert another vdprintf to dprintf

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoUse format '%s' for call to dprintf
Stefan Berger [Wed, 1 Feb 2017 01:10:51 +0000 (20:10 -0500)]
Use format '%s' for call to dprintf

Fix the dprintf call to use a format parameter that otherwise causes
errors with gcc on certain platforms.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
7 years agoAdd missing include for stdarg.h
Stefan Berger [Sun, 12 Feb 2017 02:06:19 +0000 (21:06 -0500)]
Add missing include for stdarg.h

Fix compilation problems like the following:

 /usr/local/lib/libtpms.so: undefined reference to `va_start'
 /usr/local/lib/libtpms.so: undefined reference to `va_end'

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