Commit Graph

918 Commits

Author SHA1 Message Date
Stefan Berger
57d628a5ce tpm12: Get rid of usage of sprintf and use snprintf instead
Get rid of the usage of an sprintf and use snprintf instead. In this
case the buffer is 128, so big enough to not cause problems, though.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-10-17 11:06:48 -04:00
Stefan Berger
7bd2fb0d42 tpm12: Fix potential buffer overflow in filename creation
Fix a potential buffer overflow bug in the creation of filenames
that were using sprintf() rather than snprintf(). The buffer overflow
could occurr if the buffer is longer than 4096 bytes. The state path
may alone be 4096 bytes and could possibly trigger the overflow.

Swtpm for example is not affected from this since it uses the callbacks
that are invoked before the faulty function is called.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-10-17 11:06:48 -04:00
Stefan Berger
8ddc460ad1 tpm2: Check data size to be at least size of hash
Check the size of the available data before hashing them. A minimum
of 20 bytes needs to be passed into the function so that we can hash
the data 'before' it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reported-by: Yi Ren <yunye.ry@alibaba-inc.com>
2019-08-06 09:30:52 -04:00
Stefan Berger
625abcc688 Bump up the revision of the library for next version to 0.8.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 13:54:18 -04:00
Stefan Berger
d061d8065b debian: Build now also requires g++ for fuzz test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 12:27:37 -04:00
Stefan Berger
c962433be0 RPM: Build now also requires gcc-c++ for fuzz test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 12:27:37 -04:00
Stefan Berger
39b1301d64 CHANGES: Add entry about significant changes for 0.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 12:03:52 -04:00
Stefan Berger
2c0249e06d RPM: Set the release number to 0.7.0-0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 12:03:52 -04:00
Stefan Berger
0ea02181e5 debian: Adapt changelog for 0.7.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-19 12:03:52 -04:00
Stefan Berger
24a22ef733 tpm2: Fix Coverity complaint by using iv.t.buffer
Fix a Coverity complaint by using iv.t.buffer rather than the
1-byte synonym (due to union) iv.b.buffer.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-09 10:46:42 -04:00
Stefan Berger
a60df6fe56 build-sys: Require only autoconf 2.63 for older systems
autoconf 2.63 is sufficient as a dependency for AX_CHECK_DEFINE

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-20 13:08:39 -04:00
Stefan Berger
763d7a89de build-sys: Implement AX_CHECK_DEFINE and use for OpenSSL #define's
Some of the functions that OpenSSL uses are #define's for which
we need to check using a new AX_CHECK_DEFINE. We need to check for
them also because they were added at different points in time.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-20 12:42:58 -04:00
Stefan Berger
6ae0d8c52c tpm2: Implement key creation with OpenSSL for rand == NULL
Implement key creation with OpenSSL if rand == NULL, meaning
that we create a non-KDF-derived key, so a purely random key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-20 12:23:29 -04:00
Stefan Berger
e793051573 tpm2: Use OpenSSL for decryption and signature verification
Use OpenSSL funtions now also for decryption and signature verification.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 15:10:19 -04:00
Stefan Berger
05dc373b59 tpm2: Use OpenSSL functions for encrypting and signing using RSA keys
Use the CRT (Chinese Remainder Theorem) method for doing the RSA
operations. Unfortunately it is not sufficient to just pass the
precalculated dP, dQ, and qInv parameters to OpenSSL private key
crypto functions but it also needs D, which is a bit more involved
to calculate.

We are not caching D (private exponent) as part of the OBJECT since
the OBJECT lives in size-limited NVRAM and we would need to add
'D' to the privateExponent_t, which would make it bigger and which
would allow less keys to fit into memory, which in turn could be-
come an issue if we wanted to resume a TPM that filled up the NVRAM
with keys and now less keys would fit into the NVRAM.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 13:57:45 -04:00
Stefan Berger
a572dbc424 tpm2: Implement helpers for creating OpenSSL RSA keys
Implement helper functions to create an RSA public and private
key. Create the latter with the CRT parameters.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 13:57:45 -04:00
Stefan Berger
bc681a1bc9 tmp2: Implement helper to get digest name from hashAlg
Implement a helper that converts a hash algorithm Id to a digest
name for lookup with OpenSSL.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 13:57:45 -04:00
Stefan Berger
6c901e3270 build-sys: Check for RSA functions needed in OpenSSL libcrypto
Check for RSA functions we need for calling the cryto lib for
doing RSA operations. Set the environment variable
USE_OPENSSL_FUNCTIONS_RSA to '1' if found, to '0' otherwise.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 13:57:45 -04:00
Stefan Berger
73264c8442 build-sys: Add missing space at end of string
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 13:57:45 -04:00
Stefan Berger
fee2ae97bc tpm2: Use OpenSSL to create TDES keys if rand == NULL
Use OpenSSL function to create TDES keys if rand == NULL,
which indicates that a truely random key needs to be generated
rather than one derived from a KDF.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-19 10:12:24 -04:00
Stefan Berger
fcd2d24e1a tpm2: Add comment 'libtpms added' to added #include
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-17 18:57:21 -04:00
Stefan Berger
15e8d05b07 tpm2: Add comment 'libtpms added' to BnConvert.c change
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-17 18:57:21 -04:00
Stefan Berger
271b05fdcf tpm2: Add 'libtpms bugfix' comment to CMAC fix
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-17 18:57:21 -04:00
Stefan Berger
08ede08509 tpm2: Add comment 'libtpms added'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-17 18:57:21 -04:00
Stefan Berger
c5ba5e1291 tpm2: Remove duplicate CryptUtil_fp.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-10 11:19:58 -04:00
Stefan Berger
afbb327423 Implement EC key generation using OpenSSL functions if rand == NULL
Use OpenSSL functions to create EC keys only for the case that
rand == NULL in which case no KDF is being used and where we can
create a truly random key. This doesn't break the upgrade path.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-10 11:19:58 -04:00
Stefan Berger
d175ee918b tpm2: Also include openssl/ecdsa.h for older openssl versions
Older OpenSSL versions had the ECDSA headers in openssl/ecdsa.h, so
include this file as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-04 15:36:10 -04:00
Stefan Berger
55f5988781 tpm2: Switch ECDSA signature creation to OpenSSL
Use OpenSSL crypto library now also for the ECDSA signature creation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-04 15:36:10 -04:00
Stefan Berger
82686260c7 tpm2: Make OsslToTpmBn's BIGNUM parameter const
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-04 15:36:10 -04:00
Stefan Berger
46869d307e Switch ECDSA signature verification to OpenSSL
Switch the ECDSA signature verification to OpenSSL. Do the signature
creation in the next step so we can verify the creation / verification
against the original TPM 2 code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-06-03 18:18:13 -04:00
Stefan Berger
4e1cd261ef build-sys: Add support for --disable-use-openssl-functions
OpenSSL's crypto library does not support all crypto functionality
we need in all versions. Elliptic curve support via EVP seems to
have been added much later than for example symmetric crypto support.
So, we move the USE_OPENSSL_FUNCTIONS out of Implementation.h
into configure.ac and let the build system detect what functionality
is available in the crypto library. In this patch we now also rename
USE_OPENSSL_FUNCTIONS to USE_OPENSSL_FUNCTIONS_SYMMETRIC to indicate
that we can use the symmetric crypto functions of the crypto lib.

Using the OpenSSL crypto support is enabled by default, so one has
to use --disable-use-openssl-functions, which we do for Travis now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 16:25:15 -04:00
Stefan Berger
dfe7816ae3 Travis: Add a Travis build for the case 'USE_OPENSSL_FUNCTIONS NO'
Maintain the build for the case of USE_OPENSSL_FUNCTIONS set to NO
where we build the original TPM 2 code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 12:23:05 -04:00
Stefan Berger
e91633b271 tpm2: Convert symmetric cipher implementations to use OpenSSL functions
Convert functions for symmetric encryption via AES and TDES to
use OpenSSL EVP functions where necessary. Leave the old code around
and use the #if USE_OPENSSL_FUNCTIONS to activate the new parts.

OpenSSL does not provide an implementation for TDES in CTR mode, so
we reuse the original TPM 2 code for this mode.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 12:23:05 -04:00
Stefan Berger
8de7f334c7 tpm2: Implement helper for getting OpenSSL crypto functions
Implement helper for getting OpenSSL crypto functions from
crytpo algorithm IDs, encryption modes, and key sizes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 12:23:05 -04:00
Stefan Berger
f5e4768265 tpm2: Introduce clear_and_free() to clear memory before freeing
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 12:23:05 -04:00
Stefan Berger
1ae430e708 tpm2: Introduce #define USE_OPENSSL_FUNCTIONS
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 12:23:05 -04:00
Stefan Berger
31e4db99f4 tpm2: Add fall through comment to address Coverity finding
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 10:11:33 -04:00
Stefan Berger
bca3109634 tpm2: Rearrange code in _plat__IsNvAvailable to avoid unused var
Rerrange the code in _plat__IsNvavailable to avoid an unused
variable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 10:11:33 -04:00
Stefan Berger
1b2c4fc5b9 tpm2: Fix coverity scan errors in NvFileSize
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 10:11:33 -04:00
Stefan Berger
cbc70e79d5 Travis: If building coverity_scan branch, build only job number 1
Only build one job when building the coverity branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-30 10:11:33 -04:00
Stefan Berger
7e6473b938 tpm2: Clear all EC_POINT and BIGNUM before freeing
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-24 12:59:10 -04:00
Stefan Berger
10d4e5fd9d tpm2: Rename NV_ROUNDUP to TPM2_ROUNDUP and move to new Utils.h
Move NV_ROUNDUP to Utils.h and call it TPM2_ROUNDUP for reuse by
other functions.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-23 11:39:24 -04:00
Stefan Berger
e2129d2939 tpm2: Add CMAC test cases from RFC 4493
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-09 23:11:27 -04:00
Stefan Berger
137b9da5c8 tpm2: Reset the internal CMAC state when starting a CMAC
Initialize the internal CMAC state to 0s when starting a CMAC.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-09 23:11:27 -04:00
Stefan Berger
a829ddbdeb Extend TDES test cases (CFB, OFB) with test cases for short input
Add TDES test cases testing CFB and OFB with non-blocksized short
input.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-08 14:59:55 -04:00
Stefan Berger
c14f1b01c9 tpm2: Extend internal test case with tests for TDES
Also test the TDES implementations.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-08 11:11:41 -04:00
Stefan Berger
cb386e4c7f tpm2: Add script to re-generate the test data for AES and new test for TDES
Add a script that uses openssl to create the test data we are using
in the TPM 2 code already. Extend this script with TDES 128 and 192 bit
key sizes and tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-08 11:11:41 -04:00
Stefan Berger
bd7dc396e1 tests: Add a test program to run the TPM 2 self tests
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00
Stefan Berger
edd720a1ad tests: Restrict number of command line parameters to fuzz
Restrict the number of command line parameters passed to the
fuzz program in order not to overstep command line parameter
size restrictions.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00
Stefan Berger
04971a0fb9 tests: run a lot less tests in base64decode.sh
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-05-07 16:01:48 -04:00