Commit Graph

900 Commits

Author SHA1 Message Date
Stefan Berger
4521d02dc5 tpm2: rev162: Rename TPM_GENERATED to TPM_CONSTANTS32
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:45:29 -04:00
Stefan Berger
c3b7295941 tpm2: rev162: Refactor code in ComputeContextProtectionKey
Do some simple code refactoring.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:45:29 -04:00
Stefan Berger
1e3b70543f tpm2: rev162: Change SCHEME to KDF_SCHEME in datatypes related to KDF
A simple renaming operation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:45:29 -04:00
Stefan Berger
05c032777f tpm2: rev162: Trivial whitespace and comment changes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:45:29 -04:00
Stefan Berger
ae710d3872 tpm2: Set the PSS salt length to the digest length
Call EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, -1) when creating an RSA
signature to set the PSS salt length to the digest length. Without
this call we previously set the salt length to the maximum
permissible value, but this is not how TPM 2 implements it.

Per interoperability testing between signatures created previously
with the max. permissible value and the new code, which does not
modify the signature verification code, old signatures still verify.
New signatures also verify.

This patch may solve interoperability with hardware TPMs that signatures
created following this patch now verify on hardware TPMs as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:24:47 -04:00
Stefan Berger
78de69d2d4 tpm2: Always use a temporary buffer for decryption
Always use a temporary buffer large enough to meet the requirements of the
EVP_DecryptUpdate() call.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:24:47 -04:00
Stefan Berger
2233af9ca1 tpm2: Add call to EVP_CIPHER_CTX_set_padding(ctx, 0) in sym. decryption
Add missing call of EVP_CIPHER_CTX_set_padding(ctx, 0) in the symmetric
decryption case. This was missing and failed some decryption cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:24:47 -04:00
Stefan Berger
dc1365a77e tpm2: Add missing input size check for CryptSymmetricDecrypt
Add a missing input size check for CryptSymmetricDecrypt so that we return
the proper error code TPM_RC_SIZE in case the input size is not a multiple
of the block size. Before TPM_RC_FAILURE was returned.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-27 07:24:47 -04:00
Stefan Berger
505ef841c0 tpm2: Fix output buffer parameter and size for RSA decyrption
For the RSA decryption we have to use an output buffer of the size of the
(largest possible) RSA key for the decryption to always work.

This fixes a stack corruption bug that caused a SIGBUS and termination of
'swtpm'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-23 09:36:51 -04:00
Stefan Berger
819caa4be8 tpm2: Remove space after 'IBM' in MANUFACTURER
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-18 11:22:21 -04:00
Stefan Berger
a9900d4128 tpm2: Add missing EC Curve cases in Unmarshal function
Add missing EC Curve cases in Unmarshal function.
Also, don't accept curves that are not usable during runtime because OpenSSL
may not support them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-15 12:55:43 -04:00
Stefan Berger
9f915067fe tpm2: Runtime filter useable EC Curves before advertising them
Runtime filter useable EC Curves before advertising them as being
supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-15 12:55:43 -04:00
Stefan Berger
f3f78c72a5 tpm2: Fix a gcc 10.1.0 complaint
This PR addresses issue 133: https://github.com/stefanberger/libtpms/issues/133

bin/sh ../libtool  --tag=CC   --mode=compile x86_64-pc-linux-gnu-gcc \
  -DHAVE_CONFIG_H -I. -I..    -include tpm_library_conf.h \
  -I../include/libtpms -I../include/libtpms -fstack-protector-strong \
  -D_POSIX_ -DTPM_POSIX -DTPM_LIBTPMS_CALLBACKS -I ./tpm2 \
  -I ./tpm2/crypto -I ./tpm2/crypto/openssl -g -O2 \
  -DUSE_OPENSSL_FUNCTIONS_SYMMETRIC=1 -DUSE_OPENSSL_FUNCTIONS_EC=1 \
  -DUSE_OPENSSL_FUNCTIONS_ECDSA=1 -DUSE_OPENSSL_FUNCTIONS_RSA=1 \
  -Wall -Werror -Wreturn-type -Wsign-compare -Wno-self-assign \
  -c -o tpm2/libtpms_tpm2_la-NVDynamic.lo `test -f 'tpm2/NVDynamic.c' \
  || echo './'`tpm2/NVDynamic.c
libtool: compile:  x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. \
  -I.. -include tpm_library_conf.h -I../include/libtpms \
  -I../include/libtpms -fstack-protector-strong -D_POSIX_ -DTPM_POSIX \
  -DTPM_LIBTPMS_CALLBACKS -I ./tpm2 -I ./tpm2/crypto \
  -I ./tpm2/crypto/openssl -g -O2 -DUSE_OPENSSL_FUNCTIONS_SYMMETRIC=1 \
  -DUSE_OPENSSL_FUNCTIONS_EC=1 -DUSE_OPENSSL_FUNCTIONS_ECDSA=1 \
  -DUSE_OPENSSL_FUNCTIONS_RSA=1 -Wall -Werror -Wreturn-type -Wsign-compare \
  -Wno-self-assign -c tpm2/NVDynamic.c  -fPIC -DPIC \
  -o tpm2/.libs/libtpms_tpm2_la-NVDynamic.o
tpm2/NVDynamic.c: In function ?NvNextByType?:
tpm2/NVDynamic.c:126:10: error: ?nvHandle? may be used uninitialized in this function [-Werror=maybe-uninitialized]
  126 |  *handle = nvHandle;
      |  ~~~~~~~~^~~~~~~~~~
tpm2/NVDynamic.c: At top level:

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-12 14:02:57 -04:00
Stefan Berger
62f66e5c37 tpm2: Prevent RSA 3072 related out-of-bounds access to sieveMarks[5]
PrimeSieve was accessing the sieveMarks array at out-of-bounds index 5
due to a bug in other parts of the code. This patch fixes the issue
and prevents this access by limiting the values that 'next' can take on.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 17:56:17 -04:00
Stefan Berger
b7b670c787 tpm2: Fix memory leaks in TPM2_GetInfo()
This patch fixes two memory leaks in the new code in TPM2_GetInfo().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 09:28:30 -04:00
Stefan Berger
e97909d845 tpm2: Add RSAKeySizes field to TPM2_GetInfo() JSON under new flag
Return the RSAKeySizes in the JSON produced by TPM2_GetInfo() under
a new flag with value '4'. This helps higher level tools and users
to easily determine what key sizes are supported for RSA.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 08:01:26 -04:00
Stefan Berger
61cb823169 tpm2: Start supporting RSA 3072 keys
Start supporting RSA 3072 keys.

NVMarshal.c: We now accept state that was written by libtpms when RSA keys
sizes were 2048 or are 3072, basically less-or-equal than 3072.

Also increase the NVRAM memory size by ~45 kb to accommodate the worst
case where the USER NVRAM is full of 65 2048 bit persisted keys whose 65
OBJECTs are now expanding and need to again fit into the NVRAM. We have
to add exactly 45760 bytes to accomodate this case. See swtpm test
case test_tpm2_save_load_state_2. 65 * 704 = 45760.

NOTE: BETTER TO NOT BACKPORT!!! MAY NEGATIVELY AFFECT UPGRADE PATH!

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 08:01:26 -04:00
Stefan Berger
8016592b34 tpm2: Increase MAX_CONTEXT_SIZE to 2680 for RSA 3072 bit keys
Increase the MAX_CONTEXT_SIZE to 2680 to support the increased context
size when using 3072 bit keys.

NVMarhsal.c: Accept MAX_CONTEXT_SIZE values of less-or-equal the 2680,
which also accepts context sizes of the old value 2474.

NOTE: BETTER TO NOT BACKPORT!

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 08:01:26 -04:00
Stefan Berger
391d878197 tests: Display sizes of components of OBJECT when OBJECT size changes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-05-04 08:01:26 -04:00
Stefan Berger
92d1544b0d tpm2: Add a pAssert after a statement causing unfounded Coverity complaint
This is the Coverity complaint about the line

infoDataSize = TimeGetMarshaled(&infoData);

CID 1402057: Out-of-bounds access (OVERRUN)
1. overrun-buffer-val: Overrunning array infoData of 32 bytes by passing
  it to a function which accesses it at byte offset 255.

TimeGetMarshaled() correctly serializes into &infoData, which is casted to
a buffer and then the data are written into the buffer. Also only 25 bytes,
as indicated by infoDataSize, are used, which is less than sizeof(infoData),
which is 32.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-24 17:19:58 -04:00
Stefan Berger
db80bd9ea1 build-sys: Remove 'experimental' tag from --with-tpm2
TPM 2 support has been in libtpms for quite some time now
and the experimental tag can be removed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-21 11:23:23 -04:00
Stefan Berger
91b947f41e tpm2: Comment dead code in Unmarshal.c/Marshal.c
This patch comments unreference/dead code in Unmarshal.c/Marshal.c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-17 09:52:57 -04:00
Stefan Berger
157630bcc4 tpm2: Comment unused hash and RSA related functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
b19d7f6aca CHANGES: Add entry about changes for 0.8.0 so far
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
a171839cab gitignore: Ignore .dirstamp files
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
82342abebe tpm2: Upgrade advertised revision to rev 159
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
e6bbb8755e tpm2: Sync TpmToOsslMath.c with svn repo
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
0fc4f49119 tpm2: Initialize g_daUsed to False on startup (bugfix?)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
5c91611028 tpm2: Deactivate unused BnIsProbablyPrime() and BnGcd()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
dd84e23a2d tpm2: Fix conditional compile of TPM2_Vendor_TCG_Test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
f4c1824ec0 tpm2: ACT: Update CommandDispatchData.h to latest version
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
569a9e03ea tpm2: ACT: Add rest of ACT code
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
46c267da85 tpm2: ACT: Extend case statements with FOR_EACH_ACT
Since none of the ACTs are enabled, the FOR_EACH_ACT statements
will all be no-ops.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
f4b7a835ee tpm2: ACT: Add (disabled) ACT fields to ORDERLY_DATA and STATE_CLEAR_DATA
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
1f4c70cd3c tpm2: ACT: Extend TPM2_Getcapability with TPM_CAP_ACT
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
213271eed8 tpm2: ACT: #define __ACT_DISABLED if no RH_ACT_* is YES
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
fd41faa54a tpm2: ACT: Add data structures, defines, and un/marshalling code
Disable ACT via the TpmProfile.h's RH_ACT_{0,1,A) settings of NO.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
69537eca7e tpm2: Add comment to MAX_CONTEXT_SIZE in TpmProfile.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
fce3cafa1a tpm2: Have default case return TPM_RC_VALUE rather than FAIL()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
9cf21831ba tpm2: Move CONTEXT_COUNTER defintion to GpMacros.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
2a28b96aac tpm2: Use CONTEXT_SLOT definition from TpmProfile.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
1f686aa8e9 tpm2: Remove unused define of CONTEXT_SLOT in Global.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
fb94dadeca tpm2: Rename TPM_MAX_DERIVATION_BITS to MAX_DERIVATION_BITS
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
57bfde7bf7 tpm2: Include Platform_fp.h in AttestationCommands.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
6c2517355c tpm2: Remove unused RADIX_BITS and BSIZE defines from TpmProfile.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
99e025c3d9 tpm2: Return int rather than BOOL on _plat__* functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
69d0950e34 tpm2: Move #defines for hash and sym alignment out of TpmProfile.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
2296a4dd2a tpm2: Comments and whitespace changes only
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
25a9338eb4 tpm2: Assign TPM_ALG_ERROR to hashAlg rather than direct return
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00
Stefan Berger
c9bc79eaa5 tpm2: Remove PRIVATE_VENDOR_SPECIFIC_BYTES from GpMacros.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-04-14 16:03:45 -04:00