Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(s2n-tls-hyper): Add hyper client/server example #5069

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bindings/rust-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[workspace]
members = [
"client-hello-config-resolution", "tokio-server-client",
"client-hello-config-resolution",
"hyper-server-client",
"tokio-server-client",
]
resolver = "2"

Expand Down
20 changes: 10 additions & 10 deletions bindings/rust-examples/certs/ca-cert.pem
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIB3DCCAWKgAwIBAgIUaAjZTaFhJNRyFtFQut1CdrY7RH0wCgYIKoZIzj0EAwMw
HDELMAkGA1UEBhMCVVMxDTALBgNVBAMMBHJvb3QwIBcNMjQwMTI3MDAwODQ4WhgP
MjIwMzA3MDQwMDA4NDhaMBwxCzAJBgNVBAYTAlVTMQ0wCwYDVQQDDARyb290MHYw
EAYHKoZIzj0CAQYFK4EEACIDYgAEclmOmfFLoQR+mupZSc7J3IfZ6OV0IphUHWwv
iH9BvkGh4OX+RZfafa4hw90A5fk0ps520Dt04tHwotLBNkdQcWDJunOhw8ydebIP
TaP0V8OgxFs+P4kpBkMVNB3H+PK6o2MwYTAdBgNVHQ4EFgQU2ic6pZKpiyOr5aPt
YhABB9hJC5QwHwYDVR0jBBgwFoAU2ic6pZKpiyOr5aPtYhABB9hJC5QwDwYDVR0T
AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAgQwCgYIKoZIzj0EAwMDaAAwZQIxAMtZ
+QqC0LGdqUxdr2woMr6pUNAaZYaxm6APPqyKsjVqNaKadiSueNbbbc+seKJXbwIw
Zl0HNHzmoNAMkpgx5BCukjL1v07C571diSW4Z/P96t8tUzi/2rUOoFlJYU0B8cib
MIIB2zCCAWKgAwIBAgIUFGw6MYghVw9GrlpnQwZUmB0HHbwwCgYIKoZIzj0EAwMw
HDELMAkGA1UEBhMCVVMxDTALBgNVBAMMBHJvb3QwIBcNMjUwMTI4MjEyNDU2WhgP
MjIwNDA3MDUyMTI0NTZaMBwxCzAJBgNVBAYTAlVTMQ0wCwYDVQQDDARyb290MHYw
EAYHKoZIzj0CAQYFK4EEACIDYgAEAzmebLd0GPptVlLK68gdNVVxmzTqI/ppHwYs
rn8D+0yUvD2SZj8Pkxq+Ow/gVK16CC2pY9o24xagYRhJ9RUgIrocC9k0c61QquXq
Sz58dWyajw5/gBGFxryWlaoRiC4uo2MwYTAdBgNVHQ4EFgQUSvDRw0hufm/4UxQS
m97QrxknijwwHwYDVR0jBBgwFoAUSvDRw0hufm/4UxQSm97QrxknijwwDwYDVR0T
AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAgQwCgYIKoZIzj0EAwMDZwAwZAIwCnoD
mXfz4EZaUBZpfKbYBg6GxdGbpURJkWD4TaYK75JqWSYsQNZQQpCOOBG5zjcGAjAl
i5bAyEtIJW33HzZUuCpZpc6rhFLv97b4HIRdDd1kgSMYBwUfi371de/H24vuC/s=
-----END CERTIFICATE-----
26 changes: 26 additions & 0 deletions bindings/rust-examples/certs/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ openssl req -new -noenc \
-subj "/C=US/CN=kangaroo" \
-addext "subjectAltName = DNS:www.kangaroo.com"

echo "generating localhost private key and CSR"
openssl req -new -noenc \
-newkey ec \
-pkeyopt ec_paramgen_curve:P-384 \
-keyout localhost-key.pem \
-out localhost.csr \
-subj "/C=US/CN=localhost" \
-addext "subjectAltName = DNS:localhost"

echo "generating wombat server certificate and signing it"
openssl x509 -days 65536 \
-req -in wombat.csr \
Expand All @@ -56,6 +65,16 @@ openssl x509 -days 65536 \
-out kangaroo-cert.pem \
-copy_extensions=copyall

echo "generating localhost certificate and signing it"
openssl x509 -days 65536 \
-req -in localhost.csr \
-SHA384 \
-CA ca-cert.pem \
-CAkey ca-key.pem \
-CAcreateserial \
-out localhost-cert.pem \
-copy_extensions=copyall

touch wombat-chain.pem
cat wombat-cert.pem >> wombat-chain.pem
cat ca-cert.pem >> wombat-chain.pem
Expand All @@ -64,17 +83,24 @@ touch kangaroo-chain.pem
cat kangaroo-cert.pem >> kangaroo-chain.pem
cat ca-cert.pem >> kangaroo-chain.pem

touch localhost-chain.pem
cat localhost-cert.pem >> localhost-chain.pem
cat ca-cert.pem >> localhost-chain.pem

echo "verifying server certificates"
openssl verify -CAfile ca-cert.pem wombat-cert.pem
openssl verify -CAfile ca-cert.pem kangaroo-cert.pem
openssl verify -CAfile ca-cert.pem localhost-cert.pem

# certificate signing requests are never used after the certs are generated
rm wombat.csr
rm kangaroo.csr
rm localhost.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
rm localhost-cert.pem

42 changes: 21 additions & 21 deletions bindings/rust-examples/certs/kangaroo-chain.pem
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIB3TCCAWKgAwIBAgIUJhUgxiGTEOtg0JBtu9SrS7PPvo0wCgYIKoZIzj0EAwMw
HDELMAkGA1UEBhMCVVMxDTALBgNVBAMMBHJvb3QwIBcNMjQwMTI3MDAwODQ4WhgP
MjIwMzA3MDQwMDA4NDhaMCAxCzAJBgNVBAYTAlVTMREwDwYDVQQDDAhrYW5nYXJv
bzB2MBAGByqGSM49AgEGBSuBBAAiA2IABCzesg6GHI5tMP4JuMvpiVHsc+CStyTy
JQQZ4jyj4fVfgqCcPVo6qJq6DjPepMRkm5tLtFrdavl8/ZZpiCi5vLSymUxliFXD
9DD8GO5naa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NVHQ8BAf8EBAMCAgQwCgYIKoZIzj0EAwMDZwAwZAIwCnoD
mXfz4EZaUBZpfKbYBg6GxdGbpURJkWD4TaYK75JqWSYsQNZQQpCOOBG5zjcGAjAl
i5bAyEtIJW33HzZUuCpZpc6rhFLv97b4HIRdDd1kgSMYBwUfi371de/H24vuC/s=
-----END CERTIFICATE-----
8 changes: 4 additions & 4 deletions bindings/rust-examples/certs/kangaroo-key.pem
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-----BEGIN PRIVATE KEY-----
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDB8OJA0z/nzPkogIasW
B8xhhROb0sDbHEqYwStAdDKEWGCLGyy46/5sMprtht8bBpahZANiAAQs3rIOhhyO
bTD+CbjL6YlR7HPgkrck8iUEGeI8o+H1X4KgnD1aOqiaug4z3qTEZJubS7Ra3Wr5
fP2WaYgouby0splMZYhVw/Qw/BjuZ2mgZ1thJrmAnDawdBSSXymbq1Q=
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDQb27I4N/bli1Akl+n
t2jd6CEXwqQbpcgD9lgEXBYigObKYfXb08UNZDC3HH4VVNahZANiAASS+236DAnU
Z5K/X/jjGLWaaCdd4YRh/CaknQ0Bksv0n8BKPAG5gxBerXNxxpAqcdPytUOZRDbI
X7esvt5+EJ/KvvbsuGiP3Pn5vBRym6KHu+PJ8MXR6PhnM5cycD0dyPY=
-----END PRIVATE KEY-----
24 changes: 24 additions & 0 deletions bindings/rust-examples/certs/localhost-chain.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIB1TCCAVygAwIBAgIUIbygx2K+SoQizZPmr+WpBYAyC+YwCgYIKoZIzj0EAwMw
HDELMAkGA1UEBhMCVVMxDTALBgNVBAMMBHJvb3QwIBcNMjUwMTI4MjEyNDU2WhgP
MjIwNDA3MDUyMTI0NTZaMCExCzAJBgNVBAYTAlVTMRI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QQpCOOBG5zjcGAjAl
i5bAyEtIJW33HzZUuCpZpc6rhFLv97b4HIRdDd1kgSMYBwUfi371de/H24vuC/s=
-----END CERTIFICATE-----
6 changes: 6 additions & 0 deletions bindings/rust-examples/certs/localhost-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-----BEGIN PRIVATE KEY-----
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDnJ1xbUHAxZthbja8u
7QZBCRQg+/lsKjZzswdK9EW6gzlL+RLg5JsMNAEHJgbRZcihZANiAAR2LB4AO/2V
unUoHiAtRESZM+by7BGsT9rYfTfRksznhwhutBT1uEFlCMJdUWt48DYDPiURi8p0
Tyeb/eXTtVsvRmXcg99JFnih1VZj7EORZxi+ERGnRE26Um+5Ki/UORw=
-----END PRIVATE KEY-----
40 changes: 20 additions & 20 deletions bindings/rust-examples/certs/wombat-chain.pem
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIB2DCCAV6gAwIBAgIUJhUgxiGTEOtg0JBtu9SrS7PPvowwCgYIKoZIzj0EAwMw
HDELMAkGA1UEBhMCVVMxDTALBgNVBAMMBHJvb3QwIBcNMjQwMTI3MDAwODQ4WhgP
MjIwMzA3MDQwMDA4NDhaMB4xCzAJBgNVBAYTAlVTMQ8wDQYDVQQDDAZ3b21iYXQw
djAQBgcqhkjOPQIBBgUrgQQAIgNiAARUye9Qgw5N7T8nk6DFoUwPVzSnQy9v4v0V
8SOUZmRwBqmFSJ9Vm988BwAcPFHdmQ13Za4XTkDbQvMmgzntIIIziiyaJQAazRFG
Y2Ex4V/YBiIsuh5wPOXjtvOtgVMXBgijXTBbMBkGA1UdEQQSMBCCDnd3dy53b21i
YXQuY29tMB0GA1UdDgQWBBS+Tbl0gagSNimLM5q2EgeBIMEAfzAfBgNVHSMEGDAW
gBTaJzqlkqmLI6vlo+1iEAEH2EkLlDAKBggqhkjOPQQDAwNoADBlAjAKqbrv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indings/rust-examples/certs/wombat-key.pem
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-----BEGIN PRIVATE KEY-----
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDO2TkDRDnGfKAvjH9+
SliejJgLp6ONEdNAgfimOEDWgfMJiyYEPp9WhZkASDVTaB2hZANiAARUye9Qgw5N
7T8nk6DFoUwPVzSnQy9v4v0V8SOUZmRwBqmFSJ9Vm988BwAcPFHdmQ13Za4XTkDb
QvMmgzntIIIziiyaJQAazRFGY2Ex4V/YBiIsuh5wPOXjtvOtgVMXBgg=
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDCKRIdzyeIA/FHH3W4p
ZsAyrZJgeJSwwAksPKP2gSzCfgk0xMETNLix0+2wwDfrFOChZANiAAS+0VxsqVGq
GA00CH7TNweWiBQCo8077bxmYL67K1IbKUL9A7/E0QvpXKX+ZL5avFf+Xuq73Ywj
HDluvciNfyYp7S2GOa9bB3YjX1O6VWye3LP2IPqDRPfrECsULfZ47rE=
-----END PRIVATE KEY-----
19 changes: 19 additions & 0 deletions bindings/rust-examples/hyper-server-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "hyper-server-client"
version.workspace = true
authors.workspace = true
publish.workspace = true
license.workspace = true
edition.workspace = true

[dependencies]
s2n-tls = { path = "../../rust/extended/s2n-tls" }
s2n-tls-tokio = { path = "../../rust/extended/s2n-tls-tokio" }
s2n-tls-hyper = { path = "../../rust/standard/s2n-tls-hyper" }
tokio = { version = "1", features = ["full"] }
hyper = { version = "1" }
hyper-util = { version = "0.1", features = ["client-legacy", "server", "tokio", "http1", "http2"]}
http-body-util = { version = "0.1" }
clap = { version = "4", features = ["derive"]}
http = { version = "1" }
bytes = { version = "1" }
20 changes: 20 additions & 0 deletions bindings/rust-examples/hyper-server-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This example demonstrates how to use s2n-tls with the [hyper](https://hyper.rs/) HTTP library.

The server example demonstrates how to use s2n-tls with the [hyper-util server](https://docs.rs/hyper-util/latest/hyper_util/server/conn/auto/struct.Builder.html). The client example demonstrates how to use s2n-tls with the [hyper-util client](https://docs.rs/hyper-util/latest/hyper_util/client/legacy/struct.Builder.html), via the [s2n-tls-hyper](../../rust/standard/s2n-tls-hyper) compatibility crate.

Start the example server as follows:
```
cargo run --bin server
```

The server will listen for incoming TLS connections, and echo the contents of HTTP requests back to the client in an HTTP response.

Connect to the server with the example client as follows:
```
cargo run --bin client -- --body "some text to send to the server"
```
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I run the client without the server? Like cargo run --bin client -- --addr "google.com"?

Right now I think it'd fail because of no echo, but should it maybe just print the response or something instead or asserting the response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it'd work on other servers too! That makes sense, I'll remove the assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that it works by testing amazon.com. 🤔

❯ cargo run --bin client -- --addr www.amazon.com
...
</div></body></html>
<!--       _
       .__(.)< (MEOW)
        \___)   
 ~~~~~~~~~~~~~~~~~~-->
<!-- sp:eh:4jC4pgPb20I/tYlRalVa1l4nPSi6Gt0bZQsubiOGQJlqO8NWckvdYiuBYPNtEiusycvzshYbU3Ch/J3giUKgYFukhBylN1bgfwad0xtHjb+r6Cf25uNOaFnyego= -->


The example client simply sends a GET request to the server, and can be configured to use a different server address:
```
cargo run --bin client -- --addr www.amazon.com
```
60 changes: 60 additions & 0 deletions bindings/rust-examples/hyper-server-client/src/bin/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use bytes::Bytes;
use clap::Parser;
use http_body_util::{BodyExt, Full};
use hyper_util::{client::legacy::Client, rt::TokioExecutor};
use std::error::Error;
use std::str::FromStr;

/// NOTE: this CA is to be used for demonstration purposes only!
const CA: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/ca-cert.pem"));

#[derive(Parser)]
struct Args {
#[clap(short, long, default_value = "localhost:1142")]
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, mostly curious: Why 1142? I'm not sure that's a random choice I've seen before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the last part of my phone number :D

addr: String,
#[clap(short, long, default_value = "")]
body: String,
}

async fn run_client(addr: &str, request_body: Vec<u8>) -> Result<(), Box<dyn Error>> {
// Configure the s2n-tls client.
let config = {
let mut builder = s2n_tls::config::Builder::new();
builder.trust_pem(CA)?;
builder.build()?
};

// Create a hyper-util client with this configuration, using the s2n-tls-hyper HttpsConnector.
let connector = s2n_tls_hyper::connector::HttpsConnector::new(config);
let client: Client<_, Full<Bytes>> = Client::builder(TokioExecutor::new()).build(connector);

// Create an HTTP request to send to the server.
let uri = http::Uri::from_str(format!("https://{addr}/").as_str())?;
let request: http::Request<Full<Bytes>> = http::Request::builder()
.method(http::Method::GET)
.uri(uri)
.body(Full::from(request_body.clone()))?;

// Send the request to the server.
let response = client.request(request).await?;
assert_eq!(response.status(), http::StatusCode::OK);

// Get the response body.
let response_body = response.into_body().collect().await?.to_bytes();
println!(
"Response body: \n{}",
String::from_utf8_lossy(&response_body)
);

Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
run_client(&args.addr, args.body.into_bytes()).await?;
Ok(())
}
Loading
Loading