Commit Graph

9840 Commits

Author SHA1 Message Date
Gilles Peskine
6f8d7f1b8c PKCS#1v1.5 signature: better cleanup of temporary values
Zeroize temporary buffers used to sanity-check the signature.

If there is an error, overwrite the tentative signature in the output
buffer.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:28:26 +01:00
Gilles Peskine
cd9e751f2f mbedtls_ssl_parse_finished: zeroize expected finished value on error
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:28:26 +01:00
Gilles Peskine
75b596fc3c mbedtls_ssl_cookie_check: zeroize expected cookie on cookie mismatch
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:18:44 +01:00
Gilles Peskine
8dc7b243ae mbedtls_cipher_check_tag: zeroize expected tag on tag mismatch
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:15:39 +01:00
Dave Rodgman
1f0f42f1d1 Merge pull request #5315 from gilles-peskine-arm/missing-ret-check-mbedtls_md_hmac-2.16
Backport 2.16: Check HMAC return values
2021-12-13 10:51:32 +00:00
Gilles Peskine
a89bdf03ba Catch failures of md_hmac operations
Check the return values of mbedtls_md_xx functions in our code. We were
already doing that everywhere for hash calculations, but not for HMAC
calculations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-11 17:37:47 +01:00
Gilles Peskine
95f869c9fb Move changelog entry file that was in the wrong directory
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-11 17:37:47 +01:00
Gilles Peskine
957e383f87 Zeroize local MAC variables
Zeroize local MAC variables used for CBC+HMAC cipher suites. In encryption,
this is just good hygiene but probably not needed for security since the
data protected by the MAC that could leak is about to be transmitted anyway.
In DTLS decryption, this could be a security issue since an adversary could
learn the MAC of data that they were trying to inject. At least with
encrypt-then-MAC, the adversary could then easily inject a datagram with
a corrected packet. TLS would still be safe since the receiver would close
the connection after the bad MAC.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-11 17:37:47 +01:00
Gilles Peskine
6ec13af413 Merge pull request #5307 from gilles-peskine-arm/test-missing-ret-check-202112-2.16
Backport 2.16: Missing error checks + test bug on unlikely failure
2021-12-10 17:41:46 +01:00
Gilles Peskine
a0b0dcea7d Don't fail until everything is initialized
Can't call mbedtls_cipher_free(&invalid_ctx) in cleanup if
mbedtls_cipher_init(&invalid_ctx) hasn't been called.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-10 15:21:58 +01:00
Gilles Peskine
4423cd3361 Check return values in more places
Selective replacement of
```
^\( *\)\(mbedtls_\(md\|cipher\)_[A-Z_a-z0-9]+\)\((.*)\);
```
by
```
\1if( \2\4 != 0 )
\1{
\1    mbedtls_fprintf( stderr, "\2() returned error\\n" );
\1    goto exit;
\1}
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-10 15:21:58 +01:00
Gilles Peskine
6ce0692d88 Merge pull request #5302 from paul-elliott-arm/test_suite_cipher_returns_2.16
Backport 2.16: Add checked return to cipher setup in Cipher tests
2021-12-10 10:40:04 +01:00
Gilles Peskine
dc31a4166b Merge pull request #5300 from paul-elliott-arm/crypt_and_hash_prog_2.16
Backport 2.16: Add checks for return values to md functions in crypt and hash
2021-12-09 23:32:46 +01:00
Gilles Peskine
8727985683 Merge pull request #5281 from davidhorstmann-arm/2.16-improve-cmac-docs
Backport 2.16: Reword documentation of CMAC operations
2021-12-09 23:28:42 +01:00
Paul Elliott
4eadb02bf9 Add checked return to cipher setup
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-09 21:38:48 +00:00
Paul Elliott
32c42242ce Add checks for return values to md functions
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-09 18:55:31 +00:00
David Horstmann
f39bd9739d Reword documentation of CMAC operations
Change the wording of the documentation for some CMAC functions,
as the existing wording, while technically correct, can be
easy to misunderstand. The reworded docs explain the flow of
a CMAC computation a little more fully.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2021-12-07 12:30:52 +00:00
Gilles Peskine
286bd2427f Merge pull request #5271 from gilles-peskine-arm/fix-builds-with-only-mbedtls_bignum_c-defined-2.16
Backport 2.16: Fix builds when config.h only defines MBEDTLS_BIGNUM_C
2021-12-07 12:38:03 +01:00
Gilles Peskine
942f8b6854 Add changelog entry for build error fixes
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-06 20:56:55 +01:00
Tom Cosgrove
7b420a896f Fix builds when config.h only defines MBEDTLS_BIGNUM_C
Fixes #4929

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2021-12-06 20:42:50 +01:00
Gilles Peskine
1d2c74cee0 Merge pull request #5135 from openluopworld/origin/mbedtls-2.16
Backport 2.16: Fix GCM calculation with very long IV
2021-11-22 22:22:42 +01:00
Gilles Peskine
c634df23ac Merge pull request #5215 from tom-cosgrove-arm/pr5105-2.16
Backport 2.16: doc improvement in aes include
2021-11-22 22:21:52 +01:00
Tom Cosgrove
a5f85c860b further improvements to sha256 docs
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2021-11-22 15:35:27 +00:00
Tom Cosgrove
f4307d55da doc improvement in aes include
Remove description of non-existing "mode" parameter from the docs of mbedtls_aes_crypt_ctr

Backport of #5105

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2021-11-22 15:01:25 +00:00
Gilles Peskine
62d5f8101e Merge pull request #5151 from tom-cosgrove-arm/serialise-builds-of-archives-on-windows-2.16
Backport 2.16: Serialise builds of the .a files on Windows
2021-11-10 16:01:25 +01:00
Tom Cosgrove
0a817205cf Serialise builds of the .a files on Windows
This is a workaround for an issue with mkstemp() in older MinGW releases that
causes simultaneous creation of .a files in the same directory to fail.

Fixes #5146

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2021-11-10 12:29:30 +00:00
openluopworld
ed798a9092 An initialization vector IV can have any number of bits between 1 and
2^64. So it should be filled to the lower 64-bit in the last step
when computing ghash.

Signed-off-by: openluopworld <wuhanluop@163.com>
2021-11-05 19:40:40 +08:00
Manuel Pégourié-Gonnard
d895668359 Merge pull request #5088 from gilles-peskine-arm/test_ssl_o2-2.16
Backport 2.16: Build with -O2 when running ssl-opt
2021-10-29 09:25:37 +02:00
paul-elliott-arm
27fc78690c Merge pull request #5098 from gilles-peskine-arm/ssl-opt-resend-retry-2.16
Backport 2.16: Retry a test case if it fails due to an unexpected resend
2021-10-27 16:24:05 +01:00
Manuel Pégourié-Gonnard
70227d217d Merge pull request #4819 from gilles-peskine-arm/base64-no-table-2.16
Backport 2.16: range-based constant-flow base64
2021-10-27 12:18:42 +02:00
Gilles Peskine
cd1d83c9b2 Merge pull request #5112 from paul-elliott-arm/ssl_opt_fixes_2.16
Backport 2.16: Ssl opt fixes
2021-10-26 20:50:56 +02:00
Paul Elliott
46e57d986b Remove bash specific code
Use case pattern matching instead of multiline split, given there is
only the well formatted PIDs to match on this should be safe.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-10-26 11:07:24 +01:00
Paul Elliott
355a1f4bc8 Remove use of -p with lsof
On machines with more modern kernels (>5.4 from testing so far) the
useage of -b seems to conflict with the usage of -p. Whilst the usage of
-b seems like a good idea to avoid blocks as we are tight looping on it,
the usage of -p seems to require the usage of stat() (specifically in
/proc) which -b forbids. All you get is a load of warnings
(suppressable by -w) but never a positive result, which means that all
servers are reported as "Failed to start". We are not keen on losing
-b, so instead parse the output of lsof (using -F to format it) to
check the if PIDs that it outputs match that we are looking for.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-10-26 11:07:13 +01:00
Gilles Peskine
8e82c78954 Fix typo in documentation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-25 21:14:06 +02:00
Gilles Peskine
cda1281ee2 Fix copypasta in comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-25 21:13:27 +02:00
Gilles Peskine
3712501465 Move is-it-resend logic into a function
Improve the code structure in case we want to add other similar conditions
later. Document better what we're doing, and document why we're doing it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
838902547c Retry if a test case fails because of an unexpected resend
Palliative for https://github.com/ARMmbed/mbedtls/issues/3377. If a test
case fails due to an unexpected resend, allow retrying, like in the case of
a client timeout.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
e31a9ea601 Move retry logic into check_test_failure
This will allow having other retry conditions, in particular based on
run_test options.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
ad58e92eac Move the core loop of run_test into an auxiliary function
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
342147a8a8 Move some code of run_test into auxiliary functions
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
87b036f572 Add trivial record_outcome function to facilitate backports
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
30b8132ca9 Remove redundant "should we skip?" block
There's a second one just below.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-21 11:25:40 +02:00
Gilles Peskine
77624b2bd8 Always set a build type for cmake when building for testing
Set the build type to Release (-O2) when running CPU-intensive tests (ssl-opt,
or unit tests with debug features). A build type of Check (-Os) would be best
when the main objective of the build is to check for build errors or warnings
and there aren't many tests to run; in this commit there are no such test
cases to change. Only use cmake with no build type (which results in not
passing a -O option, and thus missing some GCC warnings) when exercising cmake
features.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-19 21:39:45 +02:00
Gilles Peskine
13236707a2 Fix cmake invocation syntax
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-18 20:28:00 +02:00
Gilles Peskine
858373a26e Switch cmake -O2 builds around to where we test a lot
Use Release mode (-O2) for component_test_full_cmake_clang which runs SSL
tests.

To have some coverage with Check mode (which enables more compiler warnings
but compiles with -Os), change a few other builds that only run unit tests
at most to Check mode.

Don't add any new builds, to keep the total build volume down. We don't need
extensive coverage of all combinations, just a reasonable set.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-18 20:27:05 +02:00
Gilles Peskine
3638a962bc Clarify a comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-18 20:24:41 +02:00
Gilles Peskine
2ae243139d Correct support function name
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-18 20:24:38 +02:00
Gilles Peskine
c1317759f2 Build with -O2 when running ssl-opt
SSL testing benefits from faster executables, so use -O2 rather than -O1.
Some builds use -O1, but that's intended for jobs that only run unit tests,
where the build takes longer than the tests.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-18 20:24:35 +02:00
Gilles Peskine
90b10c379f Merge pull request #4847 from mstarzyk-mobica/ecb-alt-ret-2.16
Backport 2.16: Catch failures of mbedtls_aes_crypt_ecb and its DES equivalents
2021-10-14 12:10:58 +02:00
Gilles Peskine
91341c35f9 Merge pull request #5074 from paul-elliott-arm/fix-resumption-openssl-client-tests-2.16
Backport 2.16: Use newer OpenSSL for tests failing with the old
2021-10-13 21:05:09 +02:00