diff --git a/Cargo.lock b/Cargo.lock index a1e954d..b4fc428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1363,6 +1363,7 @@ dependencies = [ "rand", "rcgen", "reqwest", + "ring", "rmp-serde 1.1.1", "rustls", "rusty_ulid 1.0.0", diff --git a/crates/ptth_quic/Cargo.toml b/crates/ptth_quic/Cargo.toml index 2e25ff4..f8bc363 100644 --- a/crates/ptth_quic/Cargo.toml +++ b/crates/ptth_quic/Cargo.toml @@ -17,6 +17,7 @@ hyper = { version = "0.14.23", features = ["http1", "server", "stream", "tcp"] } quinn = "0.9.3" rand = "0.8.5" rcgen = "0.10.0" +ring = "0.16.20" rmp-serde = "1.1.1" rustls = "0.20.7" rusty_ulid = "1.0.0" diff --git a/crates/ptth_quic/src/crypto.rs b/crates/ptth_quic/src/crypto.rs new file mode 100644 index 0000000..edfe197 --- /dev/null +++ b/crates/ptth_quic/src/crypto.rs @@ -0,0 +1,32 @@ + +#[cfg (test)] +mod test { + #[test] + fn signing () -> anyhow::Result <()> { + use std::fs; + use ring::{ + signature::{ + self, + Ed25519KeyPair, + KeyPair, + }, + }; + + fs::create_dir_all ("untracked")?; + + let rng = ring::rand::SystemRandom::new (); + let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8 (&rng).map_err (|_| anyhow::anyhow! ("generate_pkcs8"))?; + + let key_pair = Ed25519KeyPair::from_pkcs8 (pkcs8_bytes.as_ref ()).map_err (|_| anyhow::anyhow! ("from_pkcs8"))?; + + const MESSAGE: &[u8] = b":V"; + let sig = key_pair.sign (MESSAGE); + + let peer_public_key_bytes = key_pair.public_key ().as_ref (); + let peer_public_key = signature::UnparsedPublicKey::new (&signature::ED25519, peer_public_key_bytes); + + peer_public_key.verify (MESSAGE, sig.as_ref ()).map_err (|_| anyhow::anyhow! ("verify"))?; + + Ok (()) + } +} diff --git a/crates/ptth_quic/src/lib.rs b/crates/ptth_quic/src/lib.rs index 5cf334c..0d695be 100644 --- a/crates/ptth_quic/src/lib.rs +++ b/crates/ptth_quic/src/lib.rs @@ -1,7 +1,11 @@ pub mod client_proxy; pub mod connection; +pub mod crypto; pub mod executable_end_server; pub mod executable_relay_server; pub mod prelude; pub mod protocol; pub mod quinn_utils; + +#[cfg (test)] +mod tests; diff --git a/crates/ptth_quic/src/tests.rs b/crates/ptth_quic/src/tests.rs new file mode 100644 index 0000000..d110bc6 --- /dev/null +++ b/crates/ptth_quic/src/tests.rs @@ -0,0 +1,14 @@ +#[test] +fn end_to_end () -> anyhow::Result <()> { + let rt = tokio::runtime::Runtime::new ()?; + rt.block_on (end_to_end_async ())?; + Ok (()) +} + +async fn end_to_end_async () -> anyhow::Result <()> { + + + // let task_relay = crate::executable_relay_server::main (); + + Ok (()) +}