Fail fast on wrong network certificate when joining
Description
cchost application is going on a loop when join command is supplied with wrong network cert
Steps to reproduce the behavior.
- Start a new network
- Join to the network with same IP:port but a different network certificate
Expected behavior Join should fail fast rather than on a infinite loop
Environment information Commit on master 316d57a80b915a3ff98a8cb5d82bdf46ce9ce06b
Additional context
./cchost --enclave-file=libloggingenc.so.signed --consensus raft --enclave-type=debug --ledger-file=ccf4q.ledger --node-cert-file=node_cert.pem --quote-file=quote.bin --host-log-level=info --raft-election-timeout-ms=100000 --raft-timeout-ms=500 --node-address=10.240.0.68:3100 --rpc-address=10.240.0.68:3200 join --network-cert-file=network_cert.pem --target-rpc-address 10.240.0.69:3200
2020-01-28T10:17:54.540007Z [info ] /tmp/CCF/src/host/main.cpp:376 | Creating new node - joining existing network at 10.240.0.69:3200
2020-01-28T10:17:54.783241Z [info ] /tmp/CCF/src/host/main.cpp:399 | Created new node
2020-01-28T10:17:54.783486Z -0.243 [info ] /tmp/CCF/src/node/nodestate.h:1089 | Node TLS connections now accepted
2020-01-28T10:17:57.736523Z -0.155 [info ] F/src/enclave/framedtlsendpoint.h:37 | Received additional data for 9223372036854775811, ignoring due to status 3
2020-01-28T10:18:13.510969Z -0.842 [info ] F/src/enclave/framedtlsendpoint.h:37 | Received additional data for 9223372036854775826, ignoring due to status 3
2020-01-28T10:18:13.510990Z -0.842 [info ] F/src/enclave/framedtlsendpoint.h:37 | Received additional data for 9223372036854775826, ignoring due to status 3
2020-01-28T10:18:13.510993Z -0.842 [info ] F/src/enclave/framedtlsendpoint.h:37 | Received additional data for 9223372036854775826, ignoring due to status 3
2020-01-28T10:18:14.543082Z -0.879 [info ] F/src/enclave/framedtlsendpoint.h:37 | Received additional data for 9223372036854775827, ignoring due to status 3
The loop is there to retry in case one of two failures occurs:
- temporary network failure
- TLS verification failure, because the target node is itself joining the network and isn't yet endorsed by the network identity.
It's very difficult/impossible to distinguish the second from trying to connect to a network with a completely different identity (either way it's a TLS verification failure). @iqsarv we could cap the number of retries if it helps?
We could have a configurable max number of retries or timeout in case of TLS verification failure.
Let me know if it is fine for me to take up this one.
Sounds good, it's more than fine for you to take it up, it's much appreciated! :)
As discussed with @achamayou, we should shutdown the joining node with the appropriate message if the TLS handshake fails with an authentication error. This should be feasible as the TLS stack returns a MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED error code.