| 1 | This example shows how to use the s2n-tls client hello callback to configure different TLS configs based on the Server Name Indication (SNI) in the client hello. The [server](src/bin/server.rs) sets up two configs for two different sni's, `www.wombat.com` and `www.kangaroo.com`. These configs are set up with different cipher preferences so that the allowed TLS versions are dependent on the client SNI. |
| 2 | |
| 3 | To run this example, first start the server in one terminal |
| 4 | ``` |
| 5 | cargo run --bin server |
| 6 | ``` |
| 7 | Then run the client in another terminal, setting the appropriate SNI. |
| 8 | |
| 9 | ### Kangaroo SNI |
| 10 | ``` |
| 11 | cargo run --bin client www.kangaroo.com |
| 12 | ``` |
| 13 | ``` |
| 14 | TlsStream { |
| 15 | connection: Connection { |
| 16 | handshake_type: "NEGOTIATED|FULL_HANDSHAKE|MIDDLEBOX_COMPAT", |
| 17 | cipher_suite: "TLS_AES_128_GCM_SHA256", |
| 18 | actual_protocol_version: TLS13, |
| 19 | selected_key_exchange_group: "x25519", |
| 20 | .. |
| 21 | }, |
| 22 | } |
| 23 | The server said Hello, you are speaking to www.kangaroo.com |
| 24 | ``` |
| 25 | We can see that the server successfully responded with the appropriate `www.kangaroo.com` certificate, resulting in a successful handshake. |
| 26 | |
| 27 | ### Wombat SNI |
| 28 | ``` |
| 29 | cargo run --bin client www.wombat.com |
| 30 | ``` |
| 31 | ``` |
| 32 | TlsStream { |
| 33 | connection: Connection { |
| 34 | handshake_type: "NEGOTIATED|FULL_HANDSHAKE|TLS12_PERFECT_FORWARD_SECRECY", |
| 35 | cipher_suite: "ECDHE-ECDSA-AES128-SHA", |
| 36 | actual_protocol_version: TLS12, |
| 37 | selected_key_exchange_group_name: "secp256r1", |
| 38 | .. |
| 39 | }, |
| 40 | } |
| 41 | The server said Hello, you are speaking to www.wombat.com |
| 42 | ``` |
| 43 | Once again there is a successful handshake showing that the server responded with the proper certificate. In this case, the config that the server configured for `www.wombat.com` did not support TLS 1.3, so the TLS 1.2 was negotiated instead. |
| 44 | |
| 45 | ## Async Config Resolution |
| 46 | The [async load server](src/bin/async_load_server.rs) has the same functionality as the default [server](src/bin/server.rs), but implements the config resolution in an asynchronous manner. This allows the certificates to be loaded from disk without blocking the tokio runtime. A similar technique could be used to retrieve certificates over the network without blocking the runtime. |