From 720c28fa6da87b591f85a62a77ea4f31f9f66b89 Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Thu, 5 Dec 2024 20:49:52 +0000 Subject: [PATCH 1/3] chore(bindings): update clap dev dependency --- bindings/rust/s2n-tls-tokio/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/rust/s2n-tls-tokio/Cargo.toml b/bindings/rust/s2n-tls-tokio/Cargo.toml index fc6db8d014d..5ce2a57cb0a 100644 --- a/bindings/rust/s2n-tls-tokio/Cargo.toml +++ b/bindings/rust/s2n-tls-tokio/Cargo.toml @@ -20,7 +20,7 @@ tokio = { version = "1", features = ["net", "time"] } [dev-dependencies] s2n-tls = { path = "../s2n-tls", features = ["unstable-testing"] } -clap = { version = "3", features = ["derive"] } +clap = { version = "4", features = ["derive"] } rand = { version = "0.8" } tokio = { version = "1", features = [ "io-std", "io-util", "macros", "net", "rt-multi-thread", "test-util", "time"] } tokio-macros = "=2.3.0" From 5647cd152a815e7773bf9b4dbc315f12a2f29171 Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Thu, 5 Dec 2024 22:17:58 +0000 Subject: [PATCH 2/3] chore: move tokio client/server example --- bindings/rust-examples/Cargo.toml | 2 +- .../certs/ca-cert.pem | 0 .../certs/generate.sh | 0 .../certs/kangaroo-chain.pem | 0 .../certs/kangaroo-key.pem | 0 .../certs/wombat-chain.pem | 0 .../certs/wombat-key.pem | 0 .../src/bin/client.rs | 2 +- .../src/bin/server.rs | 4 ++-- .../rust-examples/tokio-server-client/Cargo.toml | 13 +++++++++++++ .../tokio-server-client/src/bin}/client.rs | 6 +++--- .../tokio-server-client/src/bin}/server.rs | 5 +++-- .../rust-examples/tokio-server-client/src/lib.rs | 14 ++++++++++++++ bindings/rust/s2n-tls-tokio/Cargo.toml | 1 - 14 files changed, 37 insertions(+), 10 deletions(-) rename bindings/rust-examples/{client-hello-config-resolution => }/certs/ca-cert.pem (100%) rename bindings/rust-examples/{client-hello-config-resolution => }/certs/generate.sh (100%) rename bindings/rust-examples/{client-hello-config-resolution => }/certs/kangaroo-chain.pem (100%) rename bindings/rust-examples/{client-hello-config-resolution => }/certs/kangaroo-key.pem (100%) rename bindings/rust-examples/{client-hello-config-resolution => }/certs/wombat-chain.pem (100%) rename bindings/rust-examples/{client-hello-config-resolution => }/certs/wombat-key.pem (100%) create mode 100644 bindings/rust-examples/tokio-server-client/Cargo.toml rename bindings/{rust/s2n-tls-tokio/examples => rust-examples/tokio-server-client/src/bin}/client.rs (91%) rename bindings/{rust/s2n-tls-tokio/examples => rust-examples/tokio-server-client/src/bin}/server.rs (97%) create mode 100644 bindings/rust-examples/tokio-server-client/src/lib.rs diff --git a/bindings/rust-examples/Cargo.toml b/bindings/rust-examples/Cargo.toml index 0b4ca8be1aa..a718b4ff287 100644 --- a/bindings/rust-examples/Cargo.toml +++ b/bindings/rust-examples/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ - "client-hello-config-resolution", + "client-hello-config-resolution", "tokio-server-client", ] resolver = "2" diff --git a/bindings/rust-examples/client-hello-config-resolution/certs/ca-cert.pem b/bindings/rust-examples/certs/ca-cert.pem similarity index 100% rename from bindings/rust-examples/client-hello-config-resolution/certs/ca-cert.pem rename to bindings/rust-examples/certs/ca-cert.pem diff --git a/bindings/rust-examples/client-hello-config-resolution/certs/generate.sh b/bindings/rust-examples/certs/generate.sh similarity index 100% rename from bindings/rust-examples/client-hello-config-resolution/certs/generate.sh rename to bindings/rust-examples/certs/generate.sh diff --git a/bindings/rust-examples/client-hello-config-resolution/certs/kangaroo-chain.pem b/bindings/rust-examples/certs/kangaroo-chain.pem similarity index 100% rename from bindings/rust-examples/client-hello-config-resolution/certs/kangaroo-chain.pem rename to bindings/rust-examples/certs/kangaroo-chain.pem diff --git a/bindings/rust-examples/client-hello-config-resolution/certs/kangaroo-key.pem b/bindings/rust-examples/certs/kangaroo-key.pem similarity index 100% rename from bindings/rust-examples/client-hello-config-resolution/certs/kangaroo-key.pem rename to bindings/rust-examples/certs/kangaroo-key.pem diff --git a/bindings/rust-examples/client-hello-config-resolution/certs/wombat-chain.pem b/bindings/rust-examples/certs/wombat-chain.pem similarity index 100% rename from bindings/rust-examples/client-hello-config-resolution/certs/wombat-chain.pem rename to bindings/rust-examples/certs/wombat-chain.pem diff --git a/bindings/rust-examples/client-hello-config-resolution/certs/wombat-key.pem b/bindings/rust-examples/certs/wombat-key.pem similarity index 100% rename from bindings/rust-examples/client-hello-config-resolution/certs/wombat-key.pem rename to bindings/rust-examples/certs/wombat-key.pem diff --git a/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs b/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs index a9c9518cf8a..64c94283c7a 100644 --- a/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs +++ b/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs @@ -22,7 +22,7 @@ struct Cli { async fn main() -> Result<(), Box> { let args = Cli::parse(); let mut config = s2n_tls::config::Config::builder(); - let ca: Vec = std::fs::read(env!("CARGO_MANIFEST_DIR").to_owned() + "/certs/ca-cert.pem")?; + let ca: Vec = std::fs::read(env!("CARGO_MANIFEST_DIR").to_owned() + "/../certs/ca-cert.pem")?; config.set_security_policy(&DEFAULT_TLS13)?; config.trust_pem(&ca)?; diff --git a/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs b/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs index 958fdb51633..2f7ed5aef96 100644 --- a/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs +++ b/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs @@ -72,8 +72,8 @@ impl ClientHelloCallback for AnimalConfigResolver { } fn server_config(animal: &str) -> s2n_tls::config::Config { - let cert_path = format!("{}/certs/{}-chain.pem", env!("CARGO_MANIFEST_DIR"), animal); - let key_path = format!("{}/certs/{}-key.pem", env!("CARGO_MANIFEST_DIR"), animal); + let cert_path = format!("{}/../certs/{}-chain.pem", env!("CARGO_MANIFEST_DIR"), animal); + let key_path = format!("{}/../certs/{}-key.pem", env!("CARGO_MANIFEST_DIR"), animal); let cert = std::fs::read(cert_path).unwrap(); let key = std::fs::read(key_path).unwrap(); let mut config = s2n_tls::config::Builder::new(); diff --git a/bindings/rust-examples/tokio-server-client/Cargo.toml b/bindings/rust-examples/tokio-server-client/Cargo.toml new file mode 100644 index 00000000000..7aff37a6685 --- /dev/null +++ b/bindings/rust-examples/tokio-server-client/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "tokio-server-client" +version.workspace = true +authors.workspace = true +publish.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +clap = { version = "4", features = ["derive"] } +s2n-tls-tokio = { path = "../../rust/s2n-tls-tokio" } +s2n-tls = { path = "../../rust/s2n-tls" } +tokio = { version = "1", features = ["full"] } diff --git a/bindings/rust/s2n-tls-tokio/examples/client.rs b/bindings/rust-examples/tokio-server-client/src/bin/client.rs similarity index 91% rename from bindings/rust/s2n-tls-tokio/examples/client.rs rename to bindings/rust-examples/tokio-server-client/src/bin/client.rs index eebc3e115ac..70b6481cb9a 100644 --- a/bindings/rust/s2n-tls-tokio/examples/client.rs +++ b/bindings/rust-examples/tokio-server-client/src/bin/client.rs @@ -8,11 +8,11 @@ use std::{error::Error, fs}; use tokio::{io::AsyncWriteExt, net::TcpStream}; /// NOTE: this certificate is to be used for demonstration purposes only! -const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/cert.pem"); +const DEFAULT_CA: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/ca-cert.pem"); #[derive(Parser, Debug)] struct Args { - #[clap(short, long, default_value_t = String::from(DEFAULT_CERT))] + #[clap(short, long, default_value_t = String::from(DEFAULT_CA))] trust: String, addr: String, } @@ -29,7 +29,7 @@ async fn run_client(trust_pem: &[u8], addr: &str) -> Result<(), Box> // Connect to the server. let stream = TcpStream::connect(addr).await?; - let tls = client.connect("localhost", stream).await?; + let tls = client.connect("www.kangaroo.com", stream).await?; println!("{:#?}", tls); // Split the stream. diff --git a/bindings/rust/s2n-tls-tokio/examples/server.rs b/bindings/rust-examples/tokio-server-client/src/bin/server.rs similarity index 97% rename from bindings/rust/s2n-tls-tokio/examples/server.rs rename to bindings/rust-examples/tokio-server-client/src/bin/server.rs index 3e549ef10e9..4c4b2377b4a 100644 --- a/bindings/rust/s2n-tls-tokio/examples/server.rs +++ b/bindings/rust-examples/tokio-server-client/src/bin/server.rs @@ -8,8 +8,9 @@ use std::{error::Error, fs}; use tokio::{io::AsyncWriteExt, net::TcpListener}; /// NOTE: this certificate and key are to be used for demonstration purposes only! -const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/cert.pem"); -const DEFAULT_KEY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/key.pem"); +const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/kangaroo-chain.pem"); +const DEFAULT_KEY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/kangaroo-key.pem"); + #[derive(Parser, Debug)] struct Args { diff --git a/bindings/rust-examples/tokio-server-client/src/lib.rs b/bindings/rust-examples/tokio-server-client/src/lib.rs new file mode 100644 index 00000000000..b93cf3ffd9c --- /dev/null +++ b/bindings/rust-examples/tokio-server-client/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/bindings/rust/s2n-tls-tokio/Cargo.toml b/bindings/rust/s2n-tls-tokio/Cargo.toml index 5ce2a57cb0a..fed49ae3129 100644 --- a/bindings/rust/s2n-tls-tokio/Cargo.toml +++ b/bindings/rust/s2n-tls-tokio/Cargo.toml @@ -20,7 +20,6 @@ tokio = { version = "1", features = ["net", "time"] } [dev-dependencies] s2n-tls = { path = "../s2n-tls", features = ["unstable-testing"] } -clap = { version = "4", features = ["derive"] } rand = { version = "0.8" } tokio = { version = "1", features = [ "io-std", "io-util", "macros", "net", "rt-multi-thread", "test-util", "time"] } tokio-macros = "=2.3.0" From 7a38b9788ce6d9138409a175a688510d4318763f Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Fri, 6 Dec 2024 00:10:57 +0000 Subject: [PATCH 3/3] cargo fmt --- .../src/bin/client.rs | 3 ++- .../src/bin/server.rs | 6 +++++- .../rust-examples/tokio-server-client/Cargo.toml | 4 ++-- .../tokio-server-client/src/bin/client.rs | 2 +- .../tokio-server-client/src/bin/server.rs | 1 - .../rust-examples/tokio-server-client/src/lib.rs | 14 -------------- 6 files changed, 10 insertions(+), 20 deletions(-) delete mode 100644 bindings/rust-examples/tokio-server-client/src/lib.rs diff --git a/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs b/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs index 64c94283c7a..e79da70b888 100644 --- a/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs +++ b/bindings/rust-examples/client-hello-config-resolution/src/bin/client.rs @@ -22,7 +22,8 @@ struct Cli { async fn main() -> Result<(), Box> { let args = Cli::parse(); let mut config = s2n_tls::config::Config::builder(); - let ca: Vec = std::fs::read(env!("CARGO_MANIFEST_DIR").to_owned() + "/../certs/ca-cert.pem")?; + let ca: Vec = + std::fs::read(env!("CARGO_MANIFEST_DIR").to_owned() + "/../certs/ca-cert.pem")?; config.set_security_policy(&DEFAULT_TLS13)?; config.trust_pem(&ca)?; diff --git a/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs b/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs index 2f7ed5aef96..064d274d2af 100644 --- a/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs +++ b/bindings/rust-examples/client-hello-config-resolution/src/bin/server.rs @@ -72,7 +72,11 @@ impl ClientHelloCallback for AnimalConfigResolver { } fn server_config(animal: &str) -> s2n_tls::config::Config { - let cert_path = format!("{}/../certs/{}-chain.pem", env!("CARGO_MANIFEST_DIR"), animal); + let cert_path = format!( + "{}/../certs/{}-chain.pem", + env!("CARGO_MANIFEST_DIR"), + animal + ); let key_path = format!("{}/../certs/{}-key.pem", env!("CARGO_MANIFEST_DIR"), animal); let cert = std::fs::read(cert_path).unwrap(); let key = std::fs::read(key_path).unwrap(); diff --git a/bindings/rust-examples/tokio-server-client/Cargo.toml b/bindings/rust-examples/tokio-server-client/Cargo.toml index 7aff37a6685..b2fc2d0f397 100644 --- a/bindings/rust-examples/tokio-server-client/Cargo.toml +++ b/bindings/rust-examples/tokio-server-client/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true edition.workspace = true [dependencies] -clap = { version = "4", features = ["derive"] } -s2n-tls-tokio = { path = "../../rust/s2n-tls-tokio" } s2n-tls = { path = "../../rust/s2n-tls" } +s2n-tls-tokio = { path = "../../rust/s2n-tls-tokio" } tokio = { version = "1", features = ["full"] } +clap = { version = "4", features = ["derive"] } diff --git a/bindings/rust-examples/tokio-server-client/src/bin/client.rs b/bindings/rust-examples/tokio-server-client/src/bin/client.rs index 70b6481cb9a..9f108f77350 100644 --- a/bindings/rust-examples/tokio-server-client/src/bin/client.rs +++ b/bindings/rust-examples/tokio-server-client/src/bin/client.rs @@ -7,7 +7,7 @@ use s2n_tls_tokio::TlsConnector; use std::{error::Error, fs}; use tokio::{io::AsyncWriteExt, net::TcpStream}; -/// NOTE: this certificate is to be used for demonstration purposes only! +/// NOTE: this ca is to be used for demonstration purposes only! const DEFAULT_CA: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/ca-cert.pem"); #[derive(Parser, Debug)] diff --git a/bindings/rust-examples/tokio-server-client/src/bin/server.rs b/bindings/rust-examples/tokio-server-client/src/bin/server.rs index 4c4b2377b4a..4ca86ead206 100644 --- a/bindings/rust-examples/tokio-server-client/src/bin/server.rs +++ b/bindings/rust-examples/tokio-server-client/src/bin/server.rs @@ -11,7 +11,6 @@ use tokio::{io::AsyncWriteExt, net::TcpListener}; const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/kangaroo-chain.pem"); const DEFAULT_KEY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/kangaroo-key.pem"); - #[derive(Parser, Debug)] struct Args { #[clap(short, long, requires = "key", default_value_t = String::from(DEFAULT_CERT))] diff --git a/bindings/rust-examples/tokio-server-client/src/lib.rs b/bindings/rust-examples/tokio-server-client/src/lib.rs deleted file mode 100644 index b93cf3ffd9c..00000000000 --- a/bindings/rust-examples/tokio-server-client/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -}