CCF/tests
Renato Golin 4a364317cb
Implement TLS in OpenSSL, support TLS 1.3 (#3361)
* Implement TLS in OpenSSL, support TLS 1.3

This is a large commit, implementing the TLS layer in OpenSSL,
together with mbedTLS, and is part of a transition to eliminate
mbedTLS from the codebase.

The src/crypto part is done already and this is a similar effort
on src/tls. The last part is src/clients (used for testing) and
will be done as a future patch, with extensive testing separate
than this work.

This commit has a temporary structure, to allow a compiler flag
to switch between OpenSSL and mbedTLS. Unlike src/crypto, we want
the transition to be as short lived as possible, so we didn't try
to create common classes, just an include trick to use the right
library.

The main changes, in order from most generic to most specific, are:

1.  The CMake flag `TLS_PROVIDER_IS_MBEDTLS` was introduced, turned
    OFF by default, to build CCF with mbedTLS instead of OpenSSL. This
    is for testing, in case we find issues with the new implementation.
    This is in addition to `CRYPTO_PROVIDER_IS_MBEDTLS` so we can set
    each flag independently.
2.  The OpenSSL library (`libssl`) that we use is from the same place
    we pick the Crypto library (`libcrypto`). Either the system or
    OpenEnclave, decided elsewhere. No new libraries are needed.
3.  Some of the existing mbedTLS headers were moved to src/clients to
    isolate that migration from the server side. So far, it only
    needed `ca.h` and `cert.h`, which are self-conatined. Those
    will be removed with the mbedTLS cleanup.
4.  A number of `#ifdef TLS_PROVIDER_IS_MBEDTLS` were added where
    there was no other way to common up implementation. Most notably
    in the previous TLS headers (`src/tls/*.h`) that are now just
    wrappers to the actual headers (`src/tls/{mbedtls,openssl}/*.h`).
5.  All TLS errors on both mbedTLS and OpenSSL have been #defined
    to a common set of `TLS_ERR_` errors, to allow for common error
    handlind, including `WANT_READ` and `WANT_WRITE`. To keep the
    mbedTLS way, OpenSSL has a hack to return the negative
    counterparts of the error codes, so that we can treat them as
    errors, like mbedTLS.
6.  To keep the current CCF implementation intact, we had to keep
    the callback mechanism in OpenSSL. This isn't the most natural
    way of handling BIOs but it works. Both `tls_endpoint` and
    `tls_test` have a similar implementation, handling asynchronous
    I/O. This should disappear later (probably well after removing
    mbedTLS from the codebase), once we manage to get BIOs directly
    to the users, from the OpenSSL implementation.
7.  A number of mbedTLS functionality, most notably in `context.h`,
    has been adapted to allow a common implementation between the
    two libraries, for example `peer_cert()` and `get_verify_error`.
8.  A copy of `crypto::error_string()` is present in the TLS side
    so that we can more easily control each (crypto/tls) with the
    CMake flags.
9.  A number of log messages were added or changed to convey more
    information to help diagnose TLS issues. Not all development
    log messages survived into the production patch, but those that
    did can still convey most of the information and help at least
    zero in on where you need to add more logs later.
10. Removed two unused methods in `Context`: `available_bytes` and
    `set_require_auth`. Those were never called and had no easy
    equivalent in OpenSSL. Added exceptions for some unused parameters
    in OpenSSL's `CA` and `Cert` to make sure we never use them.
    If those never hit on any further testing or benchmarking, then
    we're safe to remove them when we clean up mbedTLS.
11. Added a number of `FIXME` comments, highlighting the assumptions
    from reading the mbedTLS code and what the tests have shown it
    does/needs. Some of them may be wrong, and if so, we need to
    fix them before we start with the mbedTLS cleanup.
12. Added a very large `get_verify_error` in `OpenSSL::Context`
    with all errors the `verify_result` can throw. This wasn't
    really necessary but was added as a debugging tool. Once we're
    happy none of those weird corner cases happen on our code, we
    should really remove all unused ones and common up in a
    `case default:`, where developers can add specific ones later
    for debugging purposes again.
13. Updated the `tls_test` to handle multi-part messages (past 16K),
    supporting large messages, like `tls_endpoint`. Also truncated
    the large messages to make it easier to read the test logs.
14. Changed the e2e_logging.py large message range from 2^10
    (instead of 2^14), to help developers see some messages pass
    before the 16K threshold, which helped me realise what the
    problem was.
15. Added a long README document with all core issues with the port,
    and discussions on how to clean up in the future.

* Trying to fix the ubsan error

* Remove unnecessary FIXMEs

* Add FIXME to check-todo.sh

* We don't need MbedTLS entropy for OpenSSL

The entropy source isn't a generic implementation, but one based on
mbedTLS, which we don't need for OpenSSL. This removes the last
FIXME.

* Restrict SSL cipher to TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256

To improve security and keep the same behaviour, this commit forces
specific TLS1.2 and TLS1.3 ciphers that were used in the mbedTLS
implementation.

This fixes all problems in the tls_report but one:
Secure Client-Initiated Renegotiation
 -> VULNERABLE (NOT ok), DoS threat (6 attempts)

This will be looked at on the next patch.

* Disable renegotiation to avoid DoS attacks

This makes the tls_report identical to previous mbedTLS.

* Free temporary BIOs in CA/Cert c-tors

Detected by leak sanitizers, but I should have known better...

* Use Unique_BIO|X509 in peer_cert to avoid leaks

Following the C-style code in OpenSSL's documentation was a bad
idea. Using unique_ptr wrappers to guarantee nothing leaks.

* Simplify get_verify_error to avoid UB on memcpy

Same as previous UB, writing at the end of a string. Using std::string
to avoid any memory manipulation by hand.

* Fix typos
2022-01-09 15:16:46 +00:00
..
infra Application claims digest in ledger and receipts (#3292) 2022-01-09 12:33:35 +00:00
js-app-bundle Document forwarding_required & mode in app.json (#2475) 2021-04-15 18:25:37 +01:00
js-authentication Run some end to end tests concurrently (#2927) 2021-09-07 14:56:08 +01:00
js-content-types Run some end to end tests concurrently (#2927) 2021-09-07 14:56:08 +01:00
js-custom-authorization Parse multiple values, plus priority, from `ACCEPT` header (#3098) 2021-10-18 14:32:30 +01:00
js-launch-host-process Fix pylint issues (#2905) 2021-08-23 09:59:42 +00:00
js-limits Run some end to end tests concurrently (#2927) 2021-09-07 14:56:08 +01:00
js-modules Application claims digest in ledger and receipts (#3292) 2022-01-09 12:33:35 +00:00
npm-app Unpin typescript (#3193) 2021-11-09 15:29:53 +00:00
raft_scenarios Don't send AppendEntries inline while processing a NACK, wait for the next tick (#3151) 2021-11-02 17:08:54 +00:00
sandbox JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
suite Infra: cleanup `e2e_logging.py` (#3333) 2021-12-20 17:29:35 +00:00
ca_certs.py Run some end to end tests concurrently (#2927) 2021-09-07 14:56:08 +01:00
certs.py Listen for client RPCs on multiple interfaces on each node (#2628) 2021-08-09 17:00:40 +01:00
cimetrics_env.sh python 3.7 to 3.8 (#1592) 2020-09-11 16:33:09 +01:00
cleanup_iptables.py Python infra for testing node partitions (#2553) 2021-05-11 17:13:07 +01:00
code_update.py JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
committable.py JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
config.jinja JSON configuration misc renames (#3290) 2021-12-09 15:38:36 +00:00
connections.py Multiple RPC interfaces redirection (#3300) 2021-12-15 10:40:13 +00:00
docker_wrap.sh JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
e2e_batched.py Infra: cleanup `e2e_logging.py` (#3333) 2021-12-20 17:29:35 +00:00
e2e_common_endpoints.py Infra: cleanup `e2e_logging.py` (#3333) 2021-12-20 17:29:35 +00:00
e2e_logging.py Implement TLS in OpenSSL, support TLS 1.3 (#3361) 2022-01-09 15:16:46 +00:00
e2e_operations.py Multiple RPC interfaces redirection (#3300) 2021-12-15 10:40:13 +00:00
e2e_suite.py Infra: cleanup `e2e_logging.py` (#3333) 2021-12-20 17:29:35 +00:00
e2e_tutorial.py Infra: Consider multiple read-only ledger directories (#3208) 2021-11-11 18:18:17 +00:00
election.py Infra: cleanup `e2e_logging.py` (#3333) 2021-12-20 17:29:35 +00:00
generate_vegeta_targets.py Vegeta CLI target generator (#1771) 2020-10-19 16:29:35 +01:00
governance.py Multiple RPC interfaces redirection (#3300) 2021-12-15 10:40:13 +00:00
governance_history.py Check that tables marked as experimental are not present in ledger (#3131) 2021-10-27 06:27:44 +00:00
governance_js.py Atomic proposal application (#3207) 2021-11-17 18:28:19 +00:00
historical_query_perf.py Misc fixes, mostly typos (#3281) 2021-12-03 18:02:05 +00:00
jwt_test.py Fix `/gov/jwt_keys/all` endpoint which always returned one kid (#3253) 2021-11-26 13:57:18 +00:00
lts_compatibility.py Application claims digest in ledger and receipts (#3292) 2022-01-09 12:33:35 +00:00
memberclient.py Run some end to end tests concurrently (#2927) 2021-09-07 14:56:08 +01:00
membership.py Infra: cleanup `e2e_logging.py` (#3333) 2021-12-20 17:29:35 +00:00
nobuiltins.py Another fix for 'nobuiltins' (#3160) 2021-11-04 12:54:02 +00:00
partitions_test.py JSON configuration: time strings (#3282) 2021-12-09 10:00:00 +00:00
perf_logging_scenario_100txs.json Make what we can prettier (#1862) 2020-11-10 10:57:56 +00:00
plot_node_load.py Update ringbuffer ledger API - fetch ranges rather than individual entries (#3188) 2021-11-10 13:00:54 +00:00
raft_scenarios_gen.py Fix pylint issues (#2905) 2021-08-23 09:59:42 +00:00
raft_scenarios_runner.py Fix pylint issues (#2905) 2021-08-23 09:59:42 +00:00
reconfiguration.py Multiple RPC interfaces redirection (#3300) 2021-12-15 10:40:13 +00:00
recovery.py JSON configuration: size strings (#3272) 2021-12-06 16:56:05 +00:00
requirements.txt JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
rotation.py cmake: standalone samples (#2990) 2021-09-17 09:51:25 +01:00
schema.py JSON configuration: size strings (#3272) 2021-12-06 16:56:05 +00:00
sgxinfo.sh Update `sgxinfo.sh` script for 5.11 kernel (#2903) 2021-08-23 17:34:27 +00:00
start_network.py JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
test_install.sh JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
test_install_build.sh Clang 10 toolchain & default compiler updates (#2739) 2021-08-02 20:09:32 +01:00
test_python_cli.sh Renew node certificate proposal (#2924) 2021-10-28 13:51:32 +01:00
tests.sh Set env var correctly (#2950) 2021-09-07 09:23:16 +01:00
tlstest.py JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00
upload_pico_metrics.py Add benchmark for `std::map`/`unordered_map` (#3227) 2021-11-19 17:01:28 +00:00
vegeta_stress.py JSON configuration for `cchost` (#3209) 2021-11-23 17:35:01 +00:00