Commit Graph

1281 Commits

Author SHA1 Message Date
Stefan Berger
49f15d6466 tpm2: Add padding to structures needed by some architectures
One m68k int's only need to be 2-byte aligned and therefore the size of
some data structures is not as expected. Fix this by adding artificial
padding where necessary.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-01 10:25:09 -04:00
Stefan Berger
1888bdfd6d tpm2: Add more asserts for offsets and sizes of structures
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>
2025-05-01 10:23:49 -04:00
Stefan Berger
5695736b4f tpm2 + test: Make it compilable on Debian GNU Hurd
The simple changes make it compilable on GNU Hurd where it is currently
failing to build.

Link: https://buildd.debian.org/status/package.php?p=libtpms&suite=sid
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 12:16:21 -04:00
Stefan Berger
3a63c3f3df ci: Update from ubuntu-20.04 to ubuntu-22.04 due to EOL
Ubuntu 20.04 is EOL. Therefore, upgrade it to 22.04.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 12:01:31 -04:00
Stefan Berger
567983d859 tpm2: Restrict NV index datasize to MAX_NV_INDEX_SIZE (CID 1608875)
Resolve an issue reported by Coverity caused by the maximum value of
datasize (max. size of an NV index) that was allowed to be 0x10100
(17 bits) even though later on it tried to read an array of maximum size
expressed by 16 bits (Coverity complaint). However, the maximum value of
datasize could only ever have been MAX_NV_INDEX_SIZE, which is gated by
restrictions on the size of an NV index. Therefore, restrict the maximum
datasize of an NV index to MAX_NV_INDEX_SIZE (2048 bytes) since this is
the maximum size that an NV index can be defined for.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-09 10:30:16 -04:00
Stefan Berger
796352fe5c ci: Add a coverity workflow
Trigger the coverity scan workflow when pushing to coverity_scan branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-08 22:55:09 -04:00
Stefan Berger
ecb769cdb8 ci: Add github actions script for test builds
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-16 11:32:48 -05:00
Stefan Berger
850c5db370 tpm2: Fix a compilation error in frozen profile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-13 16:21:16 -05:00
Stefan Berger
5d1014abf2 tpm2: Freeze default-v1 profile
For any new commands, algorithms, and attributes a new profile 'default-v2'
has to be started.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-13 13:48:30 -05:00
Stefan Berger
c56f8f779c tpm2: Add asserts to silence compiler warning due to -Wstringop-overflow=
The following error occurrs on Fedora build servers. To silence the
compiler warning add runtime asserts:

tpm2/crypto/openssl/CryptCmac.c: In function 'CryptCmacEnd':
tpm2/crypto/openssl/CryptCmac.c:194:48: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  194 |             subkey.t.buffer[subkey.t.size - 1] ^= xorVal;
      |                                                ^
tpm2/TpmTypes.h:1477:33: note: at offset -1 into destination object 'buffer' of size 16
 1477 |         BYTE                    buffer[MAX_SYM_BLOCK_SIZE];
      |                                 ^
lto1: all warnings being treated as errors

In CryptCmacStart the following initialization is done:

cState->iv.t.size = CryptGetSymmetricBlockSize(def->algorithm, def->keyBits.sym);

Also ensure that CryptGetSymmetricBlockSize in this case also always returns
a valid size to the TPM2B_IV that it is initializing, which would be the root
cause of any error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-06 12:56:21 -05:00
Stefan Berger
3209d3b57d Travis: Downgrade to setuptools 59.6.0 to avoid error in 71.x
There seems to be a well known error in setuptools 71.x that prevents
installation of cpp-coveralls on Travis now:

File "/usr/local/lib/python3.10/dist-packages/setuptools/_core_metadata.py", line 285, in _distribution_fullname

    canonicalize_version(version, strip_trailing_zero=False),

TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'

Fall back to the default version that is used in Ubuntu Jammy (59.6.0)
since later versions also lead to the same error.

Link: https://github.com/pypa/setuptools/issues/4483
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-06 12:56:21 -05:00
Stefan Berger
f22745c729 debian: Use --disable-hardening to avoid multiple usages of -D_FORTIFY_SOURCE=.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 10:52:20 -05:00
Stefan Berger
8061411962 tpm2: Add padding to OBJECT for 32bit targets
The nvram_offsets test fails on 32bit targets due to an unexpected size
of an OBJECT. This was due to missing padding.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 10:52:20 -05:00
Stefan Berger
bdd9a771f7 build-sys: Build libtpms v0.11.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 10:52:20 -05:00
Stefan Berger
17f253a767 rpm/debian: Add 0.10.0 entry to changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-14 07:51:51 -05:00
Stefan Berger
80aa61bae1 CHANGES: Updated CHANGES document for 0.10.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-14 07:51:51 -05:00
Stefan Berger
ad6e794d11 man: Fix spelling mistakes and mentioned Attributes for profiles
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-13 12:05:59 -05:00
Stefan Berger
7e2526a265 tests: Initialize len_cmp to 0 so it has an assigned value
Avoid the following error message due to potentially
uninitialized variable:

base64decode.c:64:20: warning: The right operand of '!=' is a garbage \
  value [core.UndefinedBinaryOperatorResult] <--[clang]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
64d263aff0 build-sys: Do not build statically linked tests when --disable-static used
When --disable-static is used statically linked tests cannot be run.
Therefore, put the evaluation of --enable-static-tests after
--disable-static has been tested for and only set ENABLE_STATIC_TESTS
if both are 'yes'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
fa4f9ab561 tests: Ignore gcc -Wmissing-braces on OBJECT initialization
Have gcc ignore -Wmissing-braces to suppress 15 of these types of
warnings:

/home/stefanb/dev/libtpms/tests/object_size.c:13:21: warning: missing braces around initializer [-Wmissing-braces] <--[gcc]
   13 |     OBJECT object = {
      |                     ^
/home/stefanb/dev/libtpms/tests/object_size.c:13:21: warning: missing braces around initializer [-Wmissing-braces] <--[gcc]
[...]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
48d52b5e40 tests: Initialize cmd with NULL at top of function
Fix the following gcc warning on Fedora rawhide:

tpm2_cve-2023-1017.c: In function ‘main’:
tpm2_cve-2023-1017.c:169:5: warning: ‘cmd’ may be used uninitialized [-Wmaybe-uninitialized]
  169 |     free(cmd);
      |     ^~~~~~~~~
tpm2_cve-2023-1017.c:125:20: note: ‘cmd’ was declared here
  125 |     unsigned char *cmd = malloc(maxcmdsize);
      |                    ^~~

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
b8c9153a3f tpm2: Only copy Attributes when non-modifyable profile is chosen
If the user provides no Attributes field in the profile then do not copy
the attributes from the internal profile if that profile may be modified.
In this case assume that the the user wanted no attributes. It now is
also unnecessary that any Attributes be set in a modifyable profile ever,
since they will not be copied.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 16:30:30 -04:00
Stefan Berger
a5248a9859 test: Allow setting Attributes in JSON profile with an empty string
Adjust the regex checking the JSON input to allow for empty string values,
which will be only used by 'Attributes' since they are all optional.
Then, allow the user to provide an empty string with the Attributes in the
JSON like this: {...,"Attributes":"", ...}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 16:30:30 -04:00
Stefan Berger
aef0ecbeb4 tpm2: Add missing attributes to code documentation and man pages
Add attributes documentation where found missing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 16:30:30 -04:00
Stefan Berger
ecff064e8d tpm2: Implement check to disable ECC key derivation: no-ecc-key-derivation
Per "TCG FIPS 140-3 guidance for TPM 2.0" document the following functions
must prevent an asymmetric ECC key derivation:
- Table 14: TPM2_CreateLoaded
- Table 18: TPM2_ZGen_2Phase
- Table 26: TPM2_Commit
- Table 26: TPM2_EC_Ephemeral

Return TPM_RC_TYPE as a return code to indicate failure of deriving a key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:24 -04:00
Stefan Berger
774cee962e tpm2: Restrict profile names to 32 characters
Restrict profile names to 32 characters to avoid having to carry
excessively long names in the TPM's state file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-10 08:42:36 -04:00
Stefan Berger
0d8377b1b4 tpm2: Allow setting the minimum HMAC key size: hmac-min-key-size
Allow setting the minimum HMAC key size and add enforcement gates.

Check that the value of hmac=min-key-size given in the profile is not
larger than 1024. This value is taken from the maximum size of
TPM2B_SENSITIVE, which is MAX_SYM_DATA (=128), which can be provided as
key to an HMAC.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-08 15:55:19 -04:00
Stefan Berger
57074695bc tpm2: Mark unused function parameters to avoid static analyzer warnings
Some function parameters are unused due to OpenSSL usage and other changes
by libtpms. Mark those as unused to avoid static analyzer warnings.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-03 14:35:16 -04:00
Stefan Berger
cbd894e281 tpm2: Add fallthrough comments to avoid static analyzer warnings
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-03 14:35:16 -04:00
Stefan Berger
648cc1ec78 tpm2: Wrap asprintf to avoid static analyzer warnings
To avoid static analyzer warnings due to non-literal format strings being
used, wrap asprintf in TPMLIB_asprintf and call vasprintf from there.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-03 14:35:16 -04:00
Stefan Berger
21e19ffe8d tpm2: Run PCT test on RSA keys and EC signing keys: pct
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-03 14:06:33 -04:00
Stefan Berger
81fbc10a7e tpm2: Implement pairwise consistency test for RSA keys
Implemewnt a pairwise consistency test for RSA keys that is to be enabled
with FIPS_COMPLIANT #define temporarily. Test encryption+decryption and
sign+verify with the created key on random input data.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-03 14:06:33 -04:00
Stefan Berger
99b52fa982 tpm2: Enable DRBG continous test: drbg-continous-test
drbg-continous-test enables an existing code block that was previously
only enabled when FIPS_COMPLIANT #define was set. This code block
ensures that previous 4 consecutive random numbers do not appear again
at the beginning of a 16-byte block.

Extend an existing test case with this new attribute.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-03 08:52:35 -04:00
Stefan Berger
363cbae3b0 tpm2: Allow naming of custom profiles with prefix 'custom:'
Allow the name of custom profiles to also have the prefix 'custom:'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-01 10:56:52 -04:00
Stefan Berger
6adb99a42c tpm2: Add an assert(profileJSON) since it must never be NULL
When profileJSON is passed to String_Marshal it must never be NULL.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
ab3da80dec tpm2: Compare CONTEXT_ENCRYPT_ALG against ALG_AES_VALUE
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
2a883017d6 tpm2: Remove unused function parameters or mark them as unused
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
8b4ad203d0 tpm2: Correct the ending of the string at max characters
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
b97c3bb776 tpm2: Check for n < 0 from asprintf before return
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
27ceda7173 tpm2: Cast void * to BYTE * when doing arithmetic
To avoid warnings from the static analyzer cast void * to BYTE *
when doing arithmetic.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
3b5b842e16 tpm2: Use mgs parameter in error log message
Use unused msg parameter in error log message

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 09:32:02 -04:00
Stefan Berger
11dfb9a611 tpm2: Check context hash algorithm with static assert
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 21:17:21 -04:00
Stefan Berger
8b3efff19e tpm2: Add const qualifier to char array in StringToUint32
Only constant strings will be passed to StringToUint32 and therefore
add the const qualifier.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 21:17:21 -04:00
Stefan Berger
e6c1ac7062 tpm2: Declare constant string as const char *
Only constant strings will be assigned to the static array, so make the
name field also a const char *.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 21:17:21 -04:00
Stefan Berger
3b0bc31692 build-sys: Set -Wshadow to avoid shadowing variables
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 19:39:55 -04:00
Stefan Berger
7cbdd6113d tpm2: Rename variable to avoid clashes with type and shadowing
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 19:39:55 -04:00
Stefan Berger
0903c69105 tpm2: Rename block_skip to block_skip_t to avoid shadowing
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 19:39:55 -04:00
Stefan Berger
a811c35fca tpm2: Rename buffer to objbuf to avoid shadowing buffer variable
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-23 19:39:55 -04:00
Stefan Berger
e898872637 tpm2: Adjust selection of StateFormatLevel
When a non-modifyable profile is chosen then copy the StateFormatLevel
(SFL) from the internal profile as before. A reason for copying the SFL
is also because the user is not allowed to make modifications to this
type of profile. Otherwise, if the user chooses a modifyable profile,
then let the user choose the StateFormatLevel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-13 17:04:38 -04:00
Stefan Berger
46548da8ed tpm2: Add missing break statement
Add a missing break statement that was forgotten in recent
commit b389781f49.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-11 19:01:26 -04:00