-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
274 changed files
with
3,039 additions
and
1,942 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*target/ | ||
*Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[workspace] | ||
members = [ | ||
"client-hello-config-resolution", | ||
] | ||
resolver = "2" | ||
|
||
[workspace.package] | ||
version = "0.0.1" | ||
authors = ["AWS s2n"] | ||
publish = false | ||
license = "Apache-2.0" | ||
edition = "2021" |
13 changes: 13 additions & 0 deletions
13
bindings/rust-examples/client-hello-config-resolution/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "client-hello-config-resolution" | ||
version.workspace = true | ||
authors.workspace = true | ||
publish.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
clap = { version = "4", features = ["derive"] } | ||
s2n-tls = { path = "../../rust/s2n-tls" } | ||
s2n-tls-tokio = { path = "../../rust/s2n-tls-tokio" } | ||
tokio = { version = "1", features = ["full"] } |
43 changes: 43 additions & 0 deletions
43
bindings/rust-examples/client-hello-config-resolution/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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. | ||
|
||
To run this example, first start the server in one terminal | ||
``` | ||
cargo run --bin server | ||
``` | ||
Then run the client in another terminal, setting the appropriate SNI. | ||
|
||
### Kangaroo SNI | ||
``` | ||
cargo run --bin client www.kangaroo.com | ||
``` | ||
``` | ||
TlsStream { | ||
connection: Connection { | ||
handshake_type: "NEGOTIATED|FULL_HANDSHAKE|MIDDLEBOX_COMPAT", | ||
cipher_suite: "TLS_AES_128_GCM_SHA256", | ||
actual_protocol_version: TLS13, | ||
selected_curve: "x25519", | ||
.. | ||
}, | ||
} | ||
The server said Hello, you are speaking to www.kangaroo.com | ||
``` | ||
We can see that the server successfully responded with the appropriate `www.kangaroo.com` certificate, resulting in a successful handshake. | ||
|
||
### Wombat SNI | ||
``` | ||
cargo run --bin client www.wombat.com | ||
``` | ||
``` | ||
TlsStream { | ||
connection: Connection { | ||
handshake_type: "NEGOTIATED|FULL_HANDSHAKE|TLS12_PERFECT_FORWARD_SECRECY", | ||
cipher_suite: "ECDHE-ECDSA-AES128-SHA", | ||
actual_protocol_version: TLS12, | ||
selected_curve: "secp256r1", | ||
.. | ||
}, | ||
} | ||
The server said Hello, you are speaking to www.wombat.com | ||
``` | ||
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. |
12 changes: 12 additions & 0 deletions
12
bindings/rust-examples/client-hello-config-resolution/certs/ca-cert.pem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIB3DCCAWKgAwIBAgIUaAjZTaFhJNRyFtFQut1CdrY7RH0wCgYIKoZIzj0EAwMw | ||
HDELMAkGA1UEBhMCVVMxDTALBgNVBAMMBHJvb3QwIBcNMjQwMTI3MDAwODQ4WhgP | ||
MjIwMzA3MDQwMDA4NDhaMBwxCzAJBgNVBAYTAlVTMQ0wCwYDVQQDDARyb290MHYw | ||
EAYHKoZIzj0CAQYFK4EEACIDYgAEclmOmfFLoQR+mupZSc7J3IfZ6OV0IphUHWwv | ||
iH9BvkGh4OX+RZfafa4hw90A5fk0ps520Dt04tHwotLBNkdQcWDJunOhw8ydebIP | ||
TaP0V8OgxFs+P4kpBkMVNB3H+PK6o2MwYTAdBgNVHQ4EFgQU2ic6pZKpiyOr5aPt | ||
YhABB9hJC5QwHwYDVR0jBBgwFoAU2ic6pZKpiyOr5aPtYhABB9hJC5QwDwYDVR0T | ||
AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAgQwCgYIKoZIzj0EAwMDaAAwZQIxAMtZ | ||
+QqC0LGdqUxdr2woMr6pUNAaZYaxm6APPqyKsjVqNaKadiSueNbbbc+seKJXbwIw | ||
Zl0HNHzmoNAMkpgx5BCukjL1v07C571diSW4Z/P96t8tUzi/2rUOoFlJYU0B8cib | ||
-----END CERTIFICATE----- |
80 changes: 80 additions & 0 deletions
80
bindings/rust-examples/client-hello-config-resolution/certs/generate.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# immediately bail if any command fails | ||
set -e | ||
|
||
echo "generating CA" | ||
openssl req -new -noenc -x509 \ | ||
-newkey ec \ | ||
-pkeyopt ec_paramgen_curve:P-384 \ | ||
-keyout ca-key.pem \ | ||
-out ca-cert.pem \ | ||
-days 65536 \ | ||
-SHA384 \ | ||
-subj "/C=US/CN=root" \ | ||
-addext "basicConstraints = critical,CA:true" \ | ||
-addext "keyUsage = critical,keyCertSign" | ||
|
||
echo "generating wombat private key and CSR" | ||
openssl req -new -noenc \ | ||
-newkey ec \ | ||
-pkeyopt ec_paramgen_curve:P-384 \ | ||
-keyout wombat-key.pem \ | ||
-out wombat.csr \ | ||
-subj "/C=US/CN=wombat" \ | ||
-addext "subjectAltName = DNS:www.wombat.com" | ||
|
||
echo "generating kangaroo private key and CSR" | ||
openssl req -new -noenc \ | ||
-newkey ec \ | ||
-pkeyopt ec_paramgen_curve:P-384 \ | ||
-keyout kangaroo-key.pem \ | ||
-out kangaroo.csr \ | ||
-subj "/C=US/CN=kangaroo" \ | ||
-addext "subjectAltName = DNS:www.kangaroo.com" | ||
|
||
echo "generating wombat server certificate and signing it" | ||
openssl x509 -days 65536 \ | ||
-req -in wombat.csr \ | ||
-SHA384 \ | ||
-CA ca-cert.pem \ | ||
-CAkey ca-key.pem \ | ||
-CAcreateserial \ | ||
-out wombat-cert.pem \ | ||
-copy_extensions=copyall | ||
|
||
echo "generating kangaroo certificate and signing it" | ||
openssl x509 -days 65536 \ | ||
-req -in kangaroo.csr \ | ||
-SHA384 \ | ||
-CA ca-cert.pem \ | ||
-CAkey ca-key.pem \ | ||
-CAcreateserial \ | ||
-out kangaroo-cert.pem \ | ||
-copy_extensions=copyall | ||
|
||
touch wombat-chain.pem | ||
cat wombat-cert.pem >> wombat-chain.pem | ||
cat ca-cert.pem >> wombat-chain.pem | ||
|
||
touch kangaroo-chain.pem | ||
cat kangaroo-cert.pem >> kangaroo-chain.pem | ||
cat ca-cert.pem >> kangaroo-chain.pem | ||
|
||
echo "verifying server certificates" | ||
openssl verify -CAfile ca-cert.pem wombat-cert.pem | ||
openssl verify -CAfile ca-cert.pem kangaroo-cert.pem | ||
|
||
# certificate signing requests are never used after the certs are generated | ||
rm wombat.csr | ||
rm kangaroo.csr | ||
rm ca-cert.srl | ||
|
||
# the private keys of the CA are never needed after signing | ||
rm ca-key.pem | ||
rm wombat-cert.pem | ||
rm kangaroo-cert.pem | ||
|
Oops, something went wrong.