Base the enabledCommands array on the command index rather than the command
code since the latter left the first few bytes always unused since command
codes start at 0x11f only.
After this change, ppList, auditCommands, and enabledCommandsByIdx bitmaps
are all based on command indices.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Coverity complains that the pAssert_RC's always evaluate to true and
are therefore useless. Deactivate them (wait for upstream to remove them).
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
On m68k int's only need to be 2-byte aligned and therefore the size of
some data structures or offsets of fields within data structures is not
as expected. Fix this by adding artificial m68k-specific padding where
necessary. If padding was added on any other architecture, it would not
make a difference there. Similarly, if some day m68k gcc was to align int's
as expected, the artifical padding would not have any influence on the
expected sizes and offsets and could be removed.
With the padding applied, swtpm should now be able to read state written
by other architectures. This is for example the case with swtpm test cases.
Link: https://wiki.debian.org/M68k/Alignment
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Before adding padding to the data structures, add asserts for offsets and
sizes of data structures so that none of these will change due to padding.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Extend the test with 2 more expected sizes for marhshalled RSA key
OBJECT for up to the current StateFormatLevel 8.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
OBJECTs are only written into NVRAM by using marshalling functions, which
should take the same number of bytes for the same OBJECT on all
architectures. So the increase of the size of an OBJECT is not a concern
anymore. Nevertheless, get 'notification' about the increase of the size
of OBJECTs on x86_64.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
It is not necessary anymore to check for an increase of the sizes of the
PERSISTENT_DATA ppList and auditCommands fields since they are marshalled
with an array-size indicator.
Any previous version of libtpms should be able to resume a profile with
the ppList and auditCommands written with a later version. If later
versions have new commands, then those new commands must be added beyond
the current TPM_CC_FIRST. The ppList and auditCommands may be bigger
than before but can be truncated IFF new commands were added. These
new commands will not be usable with the older verison of libtpms based
on the StateFormatLevel then.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Use the BITS_TO_BYTES macro where the number of bits is used for
calculating the size of a byte array.
Also, make the clearing of the rest of the byte arrays (ppList and
auditCommands) a bit more efficient than clearing the whole array
before copying the new data into it.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
The current libtpms v0.10.2 does not accept a TPM 2 state that was written
with a more recent version of libtpms if the sizes of ppList and/or
auditCommands increased. Remove the asserts that trigger state reading
failures and limit array_size to the sizeof(data->ppList) and
sizeof(data->auditCommands) respectively . More recent versions of libtpms,
if they support more TPM 2 commands, will extend these arrays but those new
commands will not be usable by older versions of libtpms (via profile and
StateFormatLevel) and can therefore be ignored by truncating those arrays.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
openssl defines SIXTY_FOUR_BIT for this architecture
./tpm2/crypto/openssl/tpm_radix.h:74:4: error: #error Need to determine RADIX_BITS value
74 | # error Need to determine RADIX_BITS value
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
The check covering bufferSize == 0 causes a compatibility issue as
described in #559 where a valid command is passed.
Also, bufferSize should never be <0 since the preceeding UINT16_Unmarshal()
would check whether sufficient bytes are available for unmarshalling
and would return an error code if this was not the case. Otherwise it would
return TPM_RC_SUCCESS along with the unmarshalled value. The bufferSize
would then only be 0 (as lowest possible value) in the success case.
Reported-by: Daniel Trick <daniel.trick@sit.fraunhofer.de>
Resolves: https://github.com/stefanberger/libtpms/issues/559
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
When the user passes no command profile, then the default command profile
of the (custom) profile will be used. If the user limits the
StateFormatLevel by setting it in the profile, then all those commands from
the default command profile that exceed the given StateFormatLevel have to
be filtered-out to avoid a rejection of the command profile. Therefore, add
a parameter to indicate that filtering of commands should be done and
return a new string with the enabled command codes if any command was
filtered-out.
Add a test case that demonstrates the filtering-out of commands 0x199 and
0x19a (from the default command profile) due to the choice of
StateFormatLevel '2'. Both command codes were enable in StateFormatLevel
'3'.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Not all callers of RuntimeCommandsPrint will want to have the returned
string use quotation marks at the beginning and end of the string.
Therefore, add a quote parameter to this function that allows to avoid
the quoting. Adapt the single caller to pass a quotation mark.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Refactor the code to have own function for ECC key size checking. Later on
other algorithms may get their own function as well.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Refactor some Ecc-specific code in AlgorithmProfile.c so it can be reused
for other algorithms later on as well.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Properly fill out the TPMS_SIG_SCHEME_RSAPSS structure, especially the
hashAlg that's found in TPMS_SCHEME_HASH, so that stricter marshalling
implementations do not refuse to marshal the structure.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Move many files to the BSD-2-clause license that either
- have no modifications in them at all
- where all modifictions are from 'me'
- where I have permission to move the modifications by 3rd parties under
the new license
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Split-out those TPM 2 command functions that need to be adapted due to the
functions they call returning an error code. Split them out into their own
files so they can be synchronized easier.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Split-out those TPM 2 command functions that need to be adapted due to the
functions they call returning an error code. Split them out into their own
files so they can be synchronized easier.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>