Commit Graph

1281 Commits

Author SHA1 Message Date
Stefan Berger
c7baa7e1ac tpm2: Deduplicate verbs in Commands, Algorithms and Attributes in profile
Deduplicate verbs in Commands, Algorithms, and Attributes strings in a
profile and when a verb with an '=' sign is found, such as
ecc-min-size=224, and there is a duplicate later in the string, such as
ecc-min-size=256, then keep the last one.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-11 16:14:08 -04:00
Stefan Berger
7d95e9ce41 tpm2: Remove test case for OpenSSL SSKDF to KDFe comparison
Remove the test case and renaming of the reference implementation of
CryptKDFe. Reverting this patch would bring the test case back in case
it was necessary.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:56:44 -04:00
Stefan Berger
2ff2f84170 tests: Rename reference KDFe implemention to ReferenceCryptKDFe for tests
To still be able to run the KDFe test case when the OpenSSL replacement
for the KDFe is to be used, rename the reference implemention to
ReferenceCryptKDFe that coexists with the CryptKDFe function that then
calls OSSLCryptKDFe.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:56:44 -04:00
Stefan Berger
209b9adcd3 tpm2: Use OpenSSL-based KDFe implementation if possible
Use the OpenSSL-based KDFe implementation when USE_OPENSSL_FUNCTIONS_SSKDF
is set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:56:44 -04:00
Stefan Berger
c0dcce5afd tests: Add KDFe replacement by OpenSSL 'SSKDF' and test case
Implement a KDFe replacement using OpenSSL's SSKDF and add a test
case that compares the current implementation against the one based
on the OpenSSL SSKDF.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:56:44 -04:00
Stefan Berger
37ca5d3ddb build-sys: Check for availability of SSKDF (KDFe) in OpenSSL
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:56:44 -04:00
Stefan Berger
d635ef81e2 tpm2: Prevent HMAC creation & verification with sha1: no-sha1-hmac
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:43:05 -04:00
Stefan Berger
24afa414ff tpm2: Prevent HMAC verification with sha1: no-sha1-hmac-verification
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:43:05 -04:00
Stefan Berger
b389781f49 tpm2: Prevent HMAC creation with sha1: no-sha1-hmac-creation
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-09 14:43:05 -04:00
Stefan Berger
e983cdf05c tpm2: Display RuntimeAttributes as part of TPMLIB_GetInfo
Display RuntimeAttributes as part of TPMLIB_GetInfo when the flag
'128' (0x80) is set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
38a2ad9e1b tpm2: Implement RuntimeAttributesGet to print out attributes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
e197df642b tpm2: Implement attribute for FIPS-enabled host: fips-host
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
2d8d6a256c tpm2: Prevent SHA1 signature verification: no-sha1-verification
Prevent SHA1 signature verification like FIPS mode on the host does
by implementing attribute no-sha1-signing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
2fc551ffbc tpm2: Prevent SHA1 signature generation using new flag: no-sha1-signing
Prevent SHA1 signature generation like FIPS mode on the host does
for RSA and all ECC (ecdsa, ecdaa, ecschnorr, sm2) signing algorithms
by implementing attribute no-sha1-signing.
Since CryptRSASign and CryptEccSign are called from CryptSign the
check for SHA1 can be done there. The other call locations are
from the algorithm test functions where the default hash is SHA512.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
2db51d0f88 tpm2: Prevent unpadded/raw RSA en- and decryption: no-unpadded-encryption
Implement attribute no-unpadded-encrytion to prevent unpadded/raw RSA
encryption and decryption.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
2a296082f0 tpm2: Implement function checking attributeFlags
Implement function to check whether a profile requires attribute
flags to be 'enforced'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
45467a2d83 tpm2: Implement support for RuntimeAttributes (StateFormatLevel 7)
Implement support for RuntimeAttributes which will be provided using
the Attribute key in the map.

Implement a fip-host attribute that at this point does not do much.

Add test case for fips-host attribute.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-03 10:28:55 -04:00
Stefan Berger
f5518e596e tests: Use free rather than TPM_Free (OS/X)
Use free rather than TPM_Free to avoid the following warning:

tpm2_setprofile.c:377:18: warning: passing 'char *' to parameter \
  of type 'unsigned char *' converts between pointers to integer \
  types with different sign [-Wpointer-sign]

        TPM_Free(profile);

../include/libtpms/tpm_memory.h:57:36: note: passing argument to \
  parameter 'buffer' here

void       TPM_Free(unsigned char *buffer);

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-30 18:27:26 -04:00
Stefan Berger
16e648e98f tpm2: Implement TPMLIB_WasManufactured API call
Implement TPMLIB_WasManufactured API call for a TPM 2 so that callers can
detect whether a TPM 2 instance was newly created and therefore the
profile that was set was also applied.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-30 16:25:47 -04:00
Stefan Berger
2dc1af12e5 rev180: Add missing entry to sieveMarks array
Add the missing entry to the sieveMarks array. The new entry would only
be used for RSA 3072 keys but due to the following change in
RsaAdjustPrimeLimit it will not be used.

  primeLimit = s_LastPrimeInTable - 2;  // libtpms: Fix for 3072 bit keys to avoid mark=5

If it was to be used (above change removed) it would occasionally produce
different RSA 3072 prime numbers from the TPM's seeds and therefore any
change to the above will have to depend on the SEED_COMPAT_LEVEL so that
the same keys are always produced.

Use the full sieveMarks array to generate RSA 3072 keys when
SEED_COMPAT_LEVEL > SEED_COMPAT_LEVEL_RSA_PRIME_ADJUST_PREREV169,
otherwise keep the previous adjustment to avoid mark=5.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-21 10:54:23 -04:00
Stefan Berger
c63fd3f765 rev183: Sync ActGetCapabilityData with upstream
Since go.preservedSignaled is not available due to __ACT_DISABLED being defined
apply the same conditional code enablement here.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 15:28:21 -04:00
Stefan Berger
046ee612ac rev183: Sync _plat__Signal_PowerOff with upstream
Since ACT_SUPPORT is set to YES in libtpms this change has no effect.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 15:28:21 -04:00
Stefan Berger
89092a12f9 rev183: Update TPM_SPEC_VERSION and related defines to reflect rev183
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 13:17:28 -04:00
Stefan Berger
037eb0e2bb tpm2: Return TPM_RC_VALUE upon decryption failure
When decryption fails then return TPM_RC_VALUE rather than TPM_RC_FAILURE.
The old error code could indicate to an application or driver that
something is wrong with the TPM (has possibly gone into failure mode) even
though only the decryption failed, possibly due to a wrong key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 10:46:50 -04:00
Stefan Berger
d3ce650f93 tpm2: Include limits.h for UINT_MAX (BSD)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 10:16:02 -04:00
Stefan Berger
4b89a028dd rev180: Sync whitespace changes and changes to comments
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2024-07-29 11:25:31 -04:00
Stefan Berger
ca3d592758 rev180: Add new function to generate RSA primes but do not use it
Some time around rev169 a new function to generate RSA prime numbers was
introduced. Add this function but keep it disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-29 08:43:35 -04:00
Stefan Berger
09a67f4588 tpm2: Move code out of RsaAdjustPrimeCandidate
To simplify the code and get rid of the libtpms-specific implementation
of RsaAdjustPrimeCandidate move its code into the case statements in
TpmRsa_GeneratePrimeForRSA.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-29 08:43:35 -04:00
Stefan Berger
aa582228d6 tpm2: Move RsaAdjustPrimeCandidate_New
Revision 1.69 received new code for RsaAdjustPrimeCandidate. Before
adding the new function (while keeping it unused since it does not
add much value) move the existing function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-29 08:43:35 -04:00
Stefan Berger
a5affce5cd rev180: Add TpmMath_GetRandomBits but disable it since unused.
Add TPmMath_GetRandomBits but disable it since it will remain unused
for now.

Modify the code to properly mask the bits in the first byte of the byte
stream produced as big endian number.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-29 08:43:35 -04:00
Stefan Berger
247a100cd8 tpm2: Add ecc-sm2-p256 to all profiles
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-26 22:34:38 -04:00
Stefan Berger
ea68ece7a7 tpm2: Disable curves whose keysize is too small and than can be disabled
When ecc-min-size is given use it to disable all curves whose keysize is
too small and that can be disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-26 22:34:38 -04:00
Stefan Berger
37c5b7d546 tpm2: Fix display of disabled elliptic curve algorithms
If elliptic curve algorithms were enabled with a shortcut the output
may have shown the individual curves as disabled, even though this is
not the case. Remove the enabledEccCurvesPrint bitfield since it
leads to misleading output.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-26 22:34:38 -04:00
Stefan Berger
869bfa53d9 tpm2: Prevent list of disabled algorithms to start with a comma
The list of disabled algorithms may have started with a comma if the first
disabled algorithm was an ec curve. Fix this by passing the 'first'
variable and using it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-26 22:34:38 -04:00
Stefan Berger
18cffed604 tests: Use %zu for size_t
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-26 22:34:38 -04:00
Stefan Berger
1df35f6c77 tpm2: Change marshalled fields of OBJECT (StateFormatLevel 6)
Bump up the StateFormatLevel to 6 and use it to introduce a new OBJECT
marshalling format version '4' that slighly changes how an OBJECT is
marshalled:

- only marshal the private exponent for an RSA key
- always marshal the new hierarchy field

The marshalling code can still write previous version '3' when an older
StateFormatLevel is used to support backwards compatibility.

Adjust the test cases marshalling an RSA key OBJECT to check against
expected sizes across a series of StateFormatLevels.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-25 11:17:42 -04:00
Stefan Berger
67447f6c88 rev180: Add but not enable new Svn- and FirmwareLimited hierarchies
Introduce new hierarchies SvnLimited and FirmwareLimited but do not enable
them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-25 11:17:42 -04:00
Stefan Berger
a5977d2018 rev180: Add hierarchy field to OBJECT and use it
Add new field hierarchy to OBJECT and assign values to it and access it.

Beyond the sync with upstream we need to also set the hierachy when
- an older OBJECT is converted to the current OBJECT
- an OBJECT is unmarshalled

Remove ObjectGetHierarchy since it is not needed anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-25 11:17:42 -04:00
Stefan Berger
ef4af2f0de tpm2: Move code to determine OBJECT hierarchy by its attribute flags
Move code that determines an OBJECT's hierarchy by its attribute flags
into BackwardsCompatibilityObject.c since it will soon only serve the
purpose of backwards compatibility.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-25 11:17:42 -04:00
Stefan Berger
fade216e73 tpm2: Add missing argument for string format
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-25 10:49:09 -04:00
Stefan Berger
0f2506fc41 tpm2: NVMarshal: Add missing case of skipping a block when none is there
Add handling of the case of wanting to skip a block of code when no data
are in the byte stream. This case has not occurred so far where a block
of unmarshalling code needed to be skipped but also no data were there in
the byte stream - it would have otherwise lead to errors while trying to
unmarshal data that were not there. So far there was simply no code there
that should have been skipped.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-24 15:51:06 -04:00
Stefan Berger
edd8b65a1d tpm2: Add missing semicolons in BIG_ENDIAN_TPM code
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-23 15:55:27 -04:00
Stefan Berger
c47b17e209 tpm2: Filter-out unusable and runtime-disabled curves
Allow completely arbitrary TPM_ECC_CURVE's to be passed to
RuntimeAlgorithmKeySizeCheckEnabled by checking that its value lies within
the bitfield and if it doesn't return a FALSE. Out-of-bounds values passed
to TEST_BIT would have caused a pAssert failure.

Call this function now early from CryptCapGetOneECCCurve that now can pass
any value as a TPM_ECC_CRUVE without causing a failure when filtering
out disabled or runtime unusable curves.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 08:28:07 -04:00
Stefan Berger
3327a145fa tpm2: Filter-out runtime-unsupported algId in AlgorithmCapGetOneImplemented
Allow completely arbitrary TPM_ALG_ID's to be passed to
RuntimeAlgorithmCheckEnabled by checking that its value lies withing the
bitfield and if it doesn't return a FALSE. Out-of-bounds values passed
to TEST_BIT would have caused a pAssert failure.

Call this function now early on from AlgorithmCapGetOneImplemented that
now can pass any value as a TPM_ALG_ID without causing a failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 08:28:07 -04:00
Stefan Berger
a76e8802e8 tests: Add test case when user chooses specific StateFormatLevel
Test that a user is able to choose a specific StateFormatLevel that is not
required by any of the chosen commands but enables a bugfix in the TPM 2
code for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 08:27:49 -04:00
Stefan Berger
d6c1b22f60 tpm2: Rework failure codes retruned by GetStateFormatLevelFromJSON
Replace failure code TPM_RC_FAILURE when an invalid interger is encounterd
while parsing the StateFormatLevel from the json and have it return
TPM_RC_VALUE. Also improve the handling of the different error codes
returned from this function by a caller.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-19 16:18:50 -04:00
Stefan Berger
c254804d59 tpm2: Return TPM_RC_VALUE when profile cannot be found by name
Return TPM_RC_VALUE rather than TPM_RC_FAILURE when a profile cannot
be found by its name.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-19 16:18:50 -04:00
Stefan Berger
ae970a547a tpm2: Change RuntimeAlgorithm's TPM_RC_FAILUREs to TPM_RC_VALUE
To leave TPM_RC_FAILURE for more severe failures replace it with
TPM_RC_VALUE.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-19 16:18:50 -04:00
Stefan Berger
e578709ca1 tpm2: Disable unused code related to TPM2_NV_DefineSpace2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-19 16:04:10 -04:00
Stefan Berger
714511aef7 tpm2: Intercept unsupported external and permanent NV indices
Intercept newly added unsupported external and permanent NV indices when
trying to unmarshal and NV index. Add a test case that was using an
unsupported external NV index.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-19 16:04:10 -04:00