Commit Graph

997 Commits

Author SHA1 Message Date
Marc-André Lureau
37ca75c707 build-sys: remove -Wstrict-aliasing=3
The option doesn't exist with clang, and is default with gcc -Wall
already.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-06-15 18:07:49 -04:00
Marc-André Lureau
ec0f7ed195 build-sys: move hardening linker flags to ldflags
Fixes unusued flags warnings with clang.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
effd551cfb tpm2: enable sha512 (breaks compatiblity)
Enable SHA512. Since the TPM 2 expects to see PCR values for
the SHA512 bank in some of its structures, this breaks
compatibility with existing state files.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
470d94d242 tpm2: convert rest of structures to write downgradeable state
Also write those structure related to PERSISTENT_ALL to have
a header with version 2 and a tail that allows the state to be
extended and downgraded.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
634db67243 tpm2: tie volatile state of TPM to persistent state
Write the persistent state's EP,SP, and PPSeed values into the
volatile state and check them when reading. This way we can
prevent that arbitrary volatile and persistent state blobs are
used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
8799e156ba Extend NVRAM memory size to 128kb
Increase the NVRAM memory size to 128kb. That should be it for good.

We accept smaller NVRAM sizes from stored state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
63ce125c7d Write different header for SHA384 and SHA512 in shared function
SHA512 is currently not enabled since until a short while ago the test
data was missing. So before we enable it, we should differentiate between
writing adn reading of SHA384 and SHA512 data by using a different magic
in the header. We assign the existing value of the magic for the SHA384
that we currently use and assign SHA512 a new value.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
aa51031256 Increase MIN_EVICT_OBJECTS to 7 for value of TPM_PT_HR_PERSISTENT_MIN
Adapt the MIN_EVICT_OBJETCS #define value to 7 so that it meeds to
TPM Profile (PTP) Specification and TPM_PT_HR_PERSISTENT_MIN returns
the proper value.

We allow to read the state from a TPM that had a lesser value before.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
f6ab7aeeb1 Update TpmToOsslMath.c to look similar to latest code
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
8850c55258 Update to latest version: CryptHash.c
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
f37f2efa31 Update to latest version: Ecc/Hash/RsaTestData.h
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
33d616125f Update to latest version: MAC_fp.h
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
22ce15897d Update to latest version: MathOnByteBuffers.c
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
c5f6ffa6f8 Update to latest version: TpmToOsslMath.h
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
8947327c7e tpm2: 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>
2018-06-15 18:07:49 -04:00
Stefan Berger
e296c14939 tpm2: pass state set via SetState() to TPM 2
If state was set using SetState() then the cached blob needs
to be passed to the TPM 2 before trying to read the state from
a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
e3ebc65206 tpm2: implement TPM2_Get/SetState
Implement the Get/SetState functions for TPM 2 so we can
also pass a blob in the TPM 2 case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
ea41cca0e1 tpm2: Clear the cached states when a different TPM version is chosen
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
21b37cd6bb tpm2: Implement _rpc__Signal_IsPowerOn
Implement _rcp__Signal_IsPowerOn() so we can detect whether the
TPM 2 is running.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
fe003b7a2b tpm2: return TPM_RC_FAILURE in case of blockSize == 0
Coverity is complaining about the case of blockSize == 0. Later on in
CryptSymmetricDecrypt() this case is intercepted as well and
TPM_RC_FAILURE is returned. We just do this a little earlier.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
12ee6008f0 tpm2: Do NULL pointer check before dereferencing
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
90f1760304 tpm2: Do NULL pointer check before dereferencing
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
34924e876c tpm2: Do NULL pointer check before dereferencing
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
6bedcc9654 tpm2: initialize a couple of variable to make coverity happy
Coverity complains that a couple of variables read from the
stream may not be initialized. It shouldn't be possible to
have them not initialized since we would otherwise have an
error value in rc. Nevertheless, initialize them.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
f19bf6c6dc tpm2: Check against unreasonably large datasize value from stream
Check the read datasize against an unreasonably large value and
log in case we encounter a bad value. This particular value cannot
be larger than 64k and a few bytes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
03d2b4f718 tpm2: Get return value into rc
In one case we missed to assign the return value for rc.
In another case check rc value before doing operation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
387465d7eb tpm2: Cast values to proper datatypes
The unsigned int needs to be checked as an int against >= 0.
The bit to move needs to be a 1ULL type.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
f20c4d5da5 tpm2: Fix calculation of array_size
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
3c09c6a4da tpm2: Make loop counter a size_t
Some versions of gcc complain about the loop counter being
a signed int when compared against a sizeof() results. This
patch fixes this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
ffb56b4448 tpm2: Enable a few more algorithms
Enable a few more algorithm for the TPM2. We have to adapt NVMarshal.c
to allow the enablement of these algorithms without rejecting existing
state. We do this through the 'LE' comparison operator that allows us
to read state from an implementation that didn't have it enabled while
we now have it enabled.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
b5f83051f2 tpm2: Enable support for SM2
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
1281c404ba tpm2: Enable support for ECMQV
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
358068c999 tpm2: Write comments about comparison operators
Write comments about the comparison operators used for comparing
compile time options/switches of the state that's being read from
another implementation versus the ones used in the current
implementation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
23af2b5472 merge into Allow state downgrading 2018-06-15 18:07:48 -04:00
Stefan Berger
ca29a44465 tpm2: Allow state downgrading starting with version 2 headers
Write version 2 headers for all versioned structures and append
a trailer that can hold future version data and that can be
skipped. The skipping allows us to downgrade state, meaning if
version 3 appended some data but we read it with version 2,
we don't need the version 3 data but can skip it. We loose data
this way, but can keep the TPM 2 running.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
ed275d52e0 tpm2: Prepare header for v2 including min. necessary version to parse
Prepare the header we are using for writing out the state blobs
for version 2 where we will including the minimum version necessary
to read a particular structure.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
69966d6d36 tpm2: Throw error on missing data for hash algorithms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
06f8e83e03 tpm2: cast to long int for match to %ld on 32bit platform
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
8e97e43514 tpm2: Implement TPM2_PersistentAllStore and use it
Implement TPM2_PersistentAllStore that allocates a buffer big
enough to store all the persistent state and returns that buffer
along with the number of valid bytes.

In this patch we move code from _plat__NvCommit() into this new
function and call this new function now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
418a10a4cc 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
f678eab755 tpm2: add missing newline after error message
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
78a29529b2 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
4c450fe7a4 tpm2: Add test harness for marshalling and reconstructing NVChip 2018-06-15 18:07:48 -04:00
Stefan Berger
ac443b727b 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
db573f0e41 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
63c4a78edd 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
ab877068ba 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
b8e5802e60 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
574426686e 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
e2248d0eb7 tpm2: Add missing offset checks and comments about gaps to test case
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
06f057db49 tpm2: Make tpmclock() a public function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
9a72be9cc7 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
c0c0515dd8 tpm2: Fix memory leak in VolatileLoad()
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
4213dfa2d3 tpm2: Implement TPM2_ValidateState
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
218b8a179d 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
1cdb5cf9ff 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
4515414c30 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
f2716accb2 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
d2fca8e4c9 tpm2: Fix compiler error due to comparison with different signedness
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
63f70197c8 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
8fb8816c3c tpm2: add missing header filenames
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
d4b9d10ce9 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
055f7f313c tpm2: make I/O buffer sizes adjustable
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:48 -04:00
Stefan Berger
5a273f8ead 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
1ad2f26704 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
659db6b2b8 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
d93761932d 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
c55d458d7c 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
3357aa7b0a 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
a931e31cf9 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
41dd3fe4f9 tpm2: Support bitfields for big endian 2018-06-15 18:07:48 -04:00
Stefan Berger
360432f645 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
8822699fb2 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>
2018-06-15 18:07:48 -04:00
Stefan Berger
245dac9b71 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
3eaf453125 tpm2: Write TPMEstablished BOOL in volatile state
Write the TPMEstablished BOOL in volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:47 -04:00
Stefan Berger
fad1e91698 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
a6d8f3f3c1 Enable TPM 2 on big endian systems
Enable TPM 2 on big endian systems.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:47 -04:00
Stefan Berger
468f0f3d96 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.
2018-06-15 18:07:47 -04:00
Stefan Berger
00f85ac180 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
0eaae34cc5 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
3cf528aaac 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
7675c9371c Revert "Fix TPM_PROOF to work with older versions"
This reverts commit 986eb59f13f12c0452895c7c0fbbffb338787132.
2018-06-15 18:07:47 -04:00
Stefan Berger
4ffc27dd4c Fix TPM_PROOF to work with older versions 2018-06-15 18:07:47 -04:00
Stefan Berger
6dfef61a1e 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
487f6fa98d 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
bd2c540c3f tpm2: fix a bug in rev146 of the TPM2 code 2018-06-15 18:07:47 -04:00
Stefan Berger
b19b6ed343 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
992a5bfad8 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>
2018-06-15 18:07:47 -04:00
Stefan Berger
ccce8b5f49 Add TPM 2 code
Add TPM 2 code.

This is rev. 142 code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:47 -04:00
Stefan Berger
707a9046cd Use malloc/free rather than TPM_Malloc/TPM_Free in library code
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:02:04 -04:00
Marc-André Lureau
c6c2a38b6e 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>
2018-05-25 22:25:46 -04:00
Stefan Berger
ee69f37801 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>
2018-05-14 16:48:22 -04:00
Stefan Berger
f031191a1d 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>
2018-05-13 19:32:33 -04:00
Stefan Berger
7071a43bab 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>
2018-05-13 19:23:23 -04:00
Stefan Berger
ec672b4e37 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>
2018-05-11 16:10:09 -04:00
Stefan Berger
51f7c2f0b7 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>
2018-05-10 23:48:16 -04:00
Stefan Berger
8bedcb30cb 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>
2018-05-10 16:35:09 -04:00
Stefan Berger
7bbb41a1fd 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>
2018-05-10 16:35:09 -04:00
Stefan Berger
c76f52efd3 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>
2018-05-10 16:35:09 -04:00
Stefan Berger
3238742947 Refactor TPM12_ValidateState to implement loop
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-10 16:06:15 -04:00
Stefan Berger
fe481765b9 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>
2018-05-04 19:36:05 -04:00
Stefan Berger
70547a758b 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>
2018-04-23 07:10:01 -04:00
Stefan Berger
aef3e6fd6b 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>
2018-03-27 21:56:54 -04:00
Stefan Berger
f9d920470d Fix typos for logical and
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 19:56:03 -04:00
Stefan Berger
e11dbf255b 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>
2018-02-17 15:00:39 -05:00
Stefan Berger
d77f29d64e Always return minimum and maximum buffer sizes
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-26 10:17:53 -05:00
Stefan Berger
ccdf2457c7 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>
2017-12-18 19:33:51 -05:00
Stefan Berger
3388d45082 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>
2017-11-13 10:15:39 -05:00
Stefan Berger
02db69c85a Add unsuppressable internal logging using ~0 indent
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 10:44:02 -05:00
Stefan Berger
ae3f105ac3 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>
2017-11-05 11:57:07 -05:00
Stefan Berger
d1e71620dd Make TPMLIB_SetBufferSize function visible
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-04 02:08:15 -04:00
Stefan Berger
bc195a3452 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>
2017-11-04 00:52:30 -04:00
Stefan Berger
46727502fc 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>
2017-10-12 12:46:34 -04:00
Stefan Berger
c525dad4e4 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>
2017-10-12 12:46:34 -04:00
André Draszik
9649f4b866 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>
2017-10-09 08:19:02 -04:00
Stefan Berger
4ea0a044ca tpm12: Use latests tpm_delegate fixing code format
Signed-off-by: Stefan Berger <stefanb@linxu.vnet.ibm.com>
2017-10-05 09:40:11 -04:00
Stefan Berger
c5ec1eaee0 tpm12: use latest tpm_pcr.c fixing return code assignment
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 09:37:50 -04:00
Stefan Berger
ddba883aa3 tpm12: use latest tpm_crypto.c for OpenSSL 1.1 support
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-28 17:14:39 -04:00
Stefan Berger
57996002ec tpm12: use latest tpm_pcr.c adding more debugging output
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-28 17:14:28 -04:00
Stefan Berger
98e9b92325 tpm12: use latest tpm_daa.c fixing return code assignments and a bug
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-28 17:14:24 -04:00
Stefan Berger
9da4b2802f tpm12: use latest tpm_nvram.c that display additional error message
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-28 17:14:19 -04:00
Stefan Berger
8c95adc480 tpm12: use latest tpm_svnrevision.c that increase major and minor numbers
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-28 17:14:13 -04:00
Stefan Berger
2855c5abfb tpm12: use latest tpm_transport.c with a return code assigned
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-28 17:14:08 -04:00
Stefan Berger
187b09b431 Fix logging of prefix for TPM_PrintAll 2017-03-30 08:24:18 -04:00
Stefan Berger
563eb905d8 Convert another vdprintf to dprintf
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-15 08:10:11 -04:00
Stefan Berger
f94b80e0d6 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>
2017-03-15 08:10:00 -04:00
Stefan Berger
a89da16e69 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>
2017-02-11 21:06:29 -05:00
Stefan Berger
ad44846dda Move TPMLIB_SetDebug* symbols under 0.6.0 release
Move the TPMLIB_SetDebug* symbols under the 0.6.0 release.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-24 11:23:09 -05:00
Stefan Berger
942501e3b2 Replace vdprintf with dprintf where possible
vdprintf with a NULL parameter on the 3rd position crashes
on Linux. Replace it with dprintf.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 19:46:49 -05:00
Stefan Berger
7fb176bcc4 Implement API calls for enabling debug output
Add API calls TPMLIB_SetDebugFD(), TPMLIB_SetDebugLevel(),
TPMLIB_SetDebugPrefix().

Convert the internal printing of debugging strings to
correspond to the log level. Print the prefix in front
of every line.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 18:53:31 -05:00
Stefan Berger
39c9604a92 Introduce internal interface to reach TPM functionality
Introduce an internal interface that allows us to reach TPM functionality
from the libary's API layer. This prepares the code for the addition
of a new API function that lets us choose which TPM to use, TPM 1.2 or
TPM2. Currently only TPM 1.2 functionality is available.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-08 09:07:54 -05:00
Stefan Berger
23b958af05 Move TPM1.2 code to src/tpm12 directory
Move all TPM1.2 code to src/tpm12 directory. Adapt the Makefile.am
to point to tpm12 directory for the TPM1.2 sources.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 19:14:30 -05:00
Stefan Berger
bfb1c7739a Use hardening CFLAGS
Add hardening CFLAGS -D_FORTIFY_SOURCE=2 and stack protector.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-02-02 06:58:59 -05:00
Stefan Berger
d987a4b844 Fix a memory leak in the TPMLibrary interface
Fix a memory leak in TPMLIB_Terminate.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
2014-07-02 21:56:58 -04:00
Stefan Berger
9b392bf3fb Fix support for ARM64
Fix support for ARM64 by testing for whether __aarch64__ is defined.

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-06-30 15:04:15 -04:00
Stefan Berger
b886be8010 Clear NVRAM area before deleting it
Clear the NVRAM area before deleting it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-06-30 15:04:15 -04:00
Stefan Berger
38e1c44281 Build dll on cygwin and build OpenSSL build cleanup
Fix the build process to build a dll on cygwin and remove
freebl specific shell calls when building for OpenSSL.

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

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-13 16:39:13 -05:00
Stefan Berger
55c0004468 Fix compile error on cygwin
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-08 11:44:01 -05:00
Stefan Berger
30a95c3c82 Make libtpms compileable with OpenSSL
Implement missing base64 decoder support when using OpenSSL library.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-08 11:43:51 -05:00
Stefan Berger
ba95ec6290 Address coverity warnings
Fixed typing errors.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-07 15:18:02 -05:00
Stefan Berger
337717ab32 Address coverity warnings
Handle function return codes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2014-01-07 15:16:54 -05:00
Stefan Berger
ebcefd0548 Rename function TPM_SBuffer_Set to TPM_Sbuffer_Set
Minor typo in function name

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2013-12-20 16:41:39 -05:00
Stefan Berger
93a6459a8e Fix spacing in tpm_audit.c
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2013-12-20 16:40:36 -05:00
Stefan Berger
f1eb496720 A fix related to the physical presence flag
The physical presence flag should not be used if CMD enable is false

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
2013-12-20 16:40:20 -05:00
Stefan Berger
4e3500d5d5 Fix a typo in tpm_crypto.c
Trivial typo in comment

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

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

The code is licensed under the Modified BSD License.

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