Commit Graph

1293 Commits

Author SHA1 Message Date
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
88dfea52cf 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>
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