Commit Graph

1293 Commits

Author SHA1 Message Date
Stefan Berger
de921c3ead Revert "Object: clear out sensitive area if on load if not provided"
This reverts commit e82727e546.

The issue has previously been resolved in commit 17255da54c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-17 20:28:04 -04:00
Rob Shearman
e82727e546 Object: clear out sensitive area if on load if not provided
When an object is later marshalled in TPM2_ContextSave, the publicOnly
attribute isn't taken into account and therefore potentially stale
sensitive information can be marshalled, which is a problem if the
buffer sizes it contains have values that are too large - this
triggers assertion failures.

Avoid this by clearing out the sensitive area upon ObjectLoad if not
provided, making the behaviour consistent with when a fresh, unused,
object entry is used.

Signed-off-by: Rob Shearman <rob@graphiant.com>
2023-08-14 08:45:55 -04:00
Stefan Berger
c702d72afb tpm2: Use GET_ATTRIBUTE to get commandIndex from s_ccAttr
Fix two locations where s_ccAttr[0].commandIndex is used to access the
commandIndex, which does not work when bitfields are not used. Use
GET_ATTRIBUTE() to access the field so that it works when bitfields are
used and when they are not used. There are several locations in this
file where GET_ATTRIBUTE() is already used to access commandIndex.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-03 11:34:43 -04:00
Stefan Berger
6690ea89f7 tpm2: Fix spelling errors
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-17 20:37:20 -04:00
Stefan Berger
c9d8fb30bc man: Fix spelling error
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-17 20:37:20 -04:00
Stefan Berger
63b9c36a16 Insert assert ensuring *buflen != BUFLEN_EMPTY_BUFFER (Coverity)
Address a false positive issue detect by Coverity (CID 1517797)
about *buflen.

Per this assignment of buflen

cached_blobs[st].buflen = buffer ? buflen : BUFLEN_EMPTY_BUFFER;

the following is true:

If cached_blobs[].buffer is     NULL then *buflen  = BUFLEN_EMPTY_BUFFER
If cached_blobs[].buffer is not NULL then *buflen != BUFLEN_EMPTY_BUFFER

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-13 16:40:35 -04:00
Stefan Berger
f2b5d0c128 tpm12: Use proper format specifier %zu for size_t (CID1517801 & 1517798)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-12 18:31:22 -04:00
Fergus Dall
52e98e9758 tpm2: Add test vectors for camellia-192
Signed-off-by: Fergus Dall <sidereal@google.com>
2023-06-05 07:28:16 -04:00
Stefan Berger
2ef7f12aed CHANGES: Write a note about changes to SignedCompareB()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-04-17 12:28:47 -04:00
Ben Lytle
0c32f39788 tpm2: fix missing algorithm macro checks
Signed-off-by: Ben Lytle <ben.dav.lytle@hpe.com>
2023-03-17 15:28:36 -04:00
Stefan Berger
dc1aac1ecf tpm2: rev164: Synchronize _TPM_Init() with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
5a7d238653 tpm2: rev164: Sync BN_CONST definition (not used by libtpms)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
2f1fb4c549 tpm2: rev164: Add implementation for TPM2_ECC_Encrypt/Decrypt
Add the implementation for TPM2_ECC_Encrypt/Decrypt. It cannot be
easily enabled due to possible downgrading requirements and also
issues with size-expansion of the PERSISTENT_DATA.auditCommands from
14 to 15 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
6ac04e4681 tpm2: rev164: Simplify SignedCompareB() implementation
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
496b64c561 tpm2: rev164: Fix CommandDispatchData for CertifyX509Data
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
74a9ab5515 tpm2: rev164: Trivial whitespace, command, and libtpms-unused changes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
c9f9fc52cf tpm2: Fix issue in CryptParameterEncryption() (TPM 2 errata v1.4)
Sync with upstream to fix issue in CryptParameterEncryption() from TPM 2
errate v1.4 2.6.1:

"The functions CryptParameterEncryption() and CryptParameterDecryption() in
the reference code in Part 4, 10.2.6.6.5 and 10.2.6.6.6 do not correctly
check the size of the parameter buffer to be encrypted or decrypted. To fix
the issue, the functions should be corrected to check that the parameter
buffer (a TPM2B type field) is at least 2 bytes in length and should use
the function UINT16_Unmarshal() to read the size of the buffer instead of"
BYTE_ARRAY_TO_UINT16().

[...]

The fixed CryptParameterEncryption() function will enter failure mode and
return TPM_RC_FAILURE if the internal response buffer does not contain
enough data for the UINT16 size field."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
9425f82960 tpm2: Sync fix in TPM2_PolicyAuthorize() with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
d35a48b284 tpm2: Sync CryptParameterDecrypt implementation with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
fb86111ca9 tpm2: Fix issue related to CryptGenerateKeyDes (TPM 2 errata v1.4)
Fix the following issue from TPM 2 errata v1.4 2.6.3:

"The function CryptGenerateKeyDes() in the reference code in Part 4,
0.2.9.2.3 does not correctly check the symmetric key size provided in the
sensitive parameter. To fix the issue, the function will check that the
size of the requested TDES key is a multiple of 8 bytes or otherwise the
TPM will return TPM_RC_SYMMETRIC."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
6e95c68503 tests: Add test cases for CVE-2023-1017 and CVE-2023-1018
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-02 09:32:38 -05:00
Stefan Berger
ddbc966ccc tests: Refactor repetitive test scripts to use one common script
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-02 09:32:38 -05:00
Stefan Berger
eb8a76807a tests: Use double quotes on command parameters (shellcheck)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-02 09:32:38 -05:00
Stefan Berger
92f470c1b0 tpm2: Check size of TPM2B_NAME buffer before reading 2 bytes from it
Fix the missing buffer size check that the TPM 2 errata v1.4 mentions in
2.6.2 by adding a buffer size check before reading 2 bytes from a
TPM2B_NAME buffer. There's no known CVE for this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 17:26:57 -05:00
Stefan Berger
324dbb4c27 tpm2: Check size of buffer before accessing it (CVE-2023-1017 & -1018)
Check that there are sufficient bytes in the buffer before reading the
cipherSize from it. Also, reduce the bufferSize variable by the number
of bytes that make up the cipherSize to avoid reading and writing bytes
beyond the buffer in subsequent steps that do in-place decryption.

This fixes CVE-2023-1017 & CVE-2023-1018.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:56:38 -05:00
Stefan Berger
b87306ca12 tpm2: Add a caching layer to GetEVPCipher() helper function
Add a caching layer to GetEVPCipher() to avoid having to call evpfn()
mulitple times. Instead, return the 'const EVP_CIPHER *' that a single
call to evpfn() (for a particular algorithm + mode + key size) returned
and cache it for subsequent calls.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 12:04:59 -05:00
Stefan Berger
66d178b981 Travis: Update from focal to jammy and from bionic to focal
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 20:22:04 -05:00
Stefan Berger
0de6f656b8 tpm2: Replace usage of deprecated DES_random_key() (OSSL 3)
Replace usage of deprecated DES_random_key() with EVP_CIPHER API calls.
These newer calls are much more time consuming than the deprecated call.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 17:24:17 -05:00
Stefan Berger
7b8572355b tpm2: Replace deprecated EC_POINTs_mul() (OSSL 3)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 17:15:11 -05:00
Stefan Berger
574aeb1df2 Travis: Update from bionic to focal and from xenial to bionic
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 12:26:45 -05:00
Stefan Berger
d08b929ded tpm2: Use EVP_CIPHER_CTX_get_params() to get IV
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-13 06:50:42 -05:00
Stefan Berger
06ada5ad3e tpm2: Skip call to DoEVPGetIV() if ivLen = 0
The ivLen may be 0 for ECB and in this case we can skip the call to
DoEVPGetIV().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-13 06:50:42 -05:00
Stefan Berger
f531ad6927 tpm2: Refactor code that gets current IV
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-13 06:50:42 -05:00
Stefan Berger
520a2fa27d
Update bug_report.md
Make exact steps to recreate the issue a requirement for the bug report.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-10-10 07:55:32 -04:00
orbea
0c2bc32a21 tests: Fix the build with slibtool
When building the tests with `make check` and slibtool the tests will
then all fail to load libtpms.so.0.

  $ ./base64decode
  /tmp/libtpms/tests/.libs/base64decode: error while loading shared libraries: libtpms.so.0: cannot open shared object file: No such file or directory

This happens because they are linked with -ltpms rather than the
libtpms.la file which has unexpected results with slibtool. GNU libtool
does some magic to make this work while slibtool fails to link the
dependency.

The correct way to link internal dependencies is directly with the
libtool archive (.la) files where the -lfoo linker flags should be only
used with external dependencies. Additionally -no-undefined is added to
the LDFLAGS to ensure there aren't undefined references in the future.

Note:

* This doesn't happen if libtpms is installed to the system and the tests
  find the already installs libtpms rather than the newly built library.

* GNU libtool silently ignores -no-undefined, but slibtool will respect
  it.

Signed-off-by: orbea <orbea@riseup.net>
2022-07-16 22:32:30 -04:00
William Roberts
554a13379f MAINTAINERS: add LibreSSL maintainer
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2022-07-12 17:28:40 -04:00
Stefan Berger
f1e8b6c694 tests: Add license identifier to test cases
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-07-12 11:30:53 -04:00
Stefan Berger
4e5dffc08a tests: Fix outdated output of expected file size in case of error
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-07-12 11:30:53 -04:00
William Roberts
c6c8f63686 Revert "tpm_crypto: support libressl api"
This reverts commit 9afebc712a.

The issue is that opensslv.h is not included and thus the
OPENSSL_VERSION_NUMBER is not getting set.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
2022-07-12 11:28:47 -04:00
William Roberts
27beabc518 tpm_crypto: support libressl api
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2022-07-09 13:30:55 -04:00
William Roberts
4970a8a0c7 tpm_crypto: simplify OSSL version ifdef
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2022-07-09 13:30:55 -04:00
Stefan Berger
f20a7d7d41 Add MAINTAINERS file to project
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-06-20 16:15:06 -04:00
Stefan Berger
086e1bcb8b tpm2: Fix a typo in PERSISTENT_ALL_Unmarshal
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-06-15 10:35:08 -04:00
Stefan Berger
9c63f076ec tpm2: Implement OpenSSLCryptRsaGenerateKey for OpenSSL 3.0 case
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-31 20:31:10 -04:00
Stefan Berger
d215cfd612 tpm2: Implement BuildRSAKey for OpenSSL 3.0 case
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-31 20:31:10 -04:00
Stefan Berger
e998c06694 tpm2: Delay creation of EVP_PKEY in InitOpenSSLRSAPrivateKey
Delay the creation of the EVP_PKEY in InitOpenSSLRSAPrivateKey
so that we can create the key with all the parameters at once.
We have to do this since with the OpenSSL 3.0 API we cannot set
parameters after the initial creation of the key anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-31 20:31:10 -04:00
Stefan Berger
c8523779f2 tpm2: Implement DoRSACheckKey with OpenSSL 3.0 API
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-31 20:31:10 -04:00
Stefan Berger
f7ccda56fb tpm2: Implement ObjectGetPublicParameters to get N and E from OBJECT
Get the BIGNUMs N and E from an RSA key OBJECT. The purpose of
this refactoring is be able to reuse the new function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-31 20:31:10 -04:00
Stefan Berger
3eef1fb035 tpm2: Implement BuildRSAKey for building an RSA EVP_PKEY
Implement BuildRSAKey for building an RSA EVP_PKEY from copies
of the BIGNUMs it gets passed. This way it is clear that the
caller has to free the BIGNUMs it passed itself also in case of
error returned by BuildRSAKey.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-31 20:31:10 -04:00
Stefan Berger
6a919f1c6a tpm2: Do not access variable if it could not be read from buffer (Coverity)
Exit the loop when the variable could not be filled with data from the
byte stream. This avoids accessing the variable 'element' in case it
wasn't initialized. The old could would have accessed the possibly
uninitialized variable but exited the loop immediately after.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-28 20:07:35 -04:00