test: add tests for noise

This commit is contained in:
Yujia Qiao 2021-12-24 21:04:21 +08:00 committed by Yujia Qiao
parent 46ec6400e4
commit a3684686e1
4 changed files with 99 additions and 25 deletions

View File

@ -1,33 +1,47 @@
[client]
remote_addr = "example.com:2333"
default_token = "default_token_if_not_specify"
remote_addr = "example.com:2333" # Necessary. The address of the server
default_token = "default_token_if_not_specify" # Optional. The default token of services, if they don't define their own ones
[client.transport]
type = "tcp"
[client.transport.tls]
trusted_root = "ca.pem"
hostname = "example.com"
type = "tcp" # Optional. Possible values: ["tcp", "tls"]. Default: "tcp"
[client.services.service1]
token = "whatever"
local_addr = "127.0.0.1:1081"
[client.transport.tls] # Necessary if `type` is "tls"
trusted_root = "ca.pem" # Necessary. The certificate of CA that signed the server's certificate
hostname = "example.com" # Optional. The hostname that the client uses to validate the certificate. If not set, fallback to `client.remote_addr`
[client.services.service2]
[client.transport.noise] # Noise protocol. See `docs/security.md` for further explanation
pattern = "Noise_NK_25519_ChaChaPoly_BLAKE2s" # Optional. Default value as shown
local_private_key = "key_encoded_in_base64" # Optional
remote_public_key = "key_encoded_in_base64" # Optional
[client.services.service1] # A service that needs forwarding. The name `service1` can change arbitrarily, as long as identical to the name in the server's configuration
type = "tcp" # Optional. The protocol that needs forwarding. Possible values: ["tcp", "udp"]. Default: "tcp"
token = "whatever" # Necessary if `client.default_token` not set
local_addr = "127.0.0.1:1081" # Necessary. The address of the service that needs to be forwarded
[client.services.service2] # Multiple services can be defined
local_addr = "127.0.0.1:1082"
[server]
bind_addr = "0.0.0.0:2333"
default_token = "default_token_if_not_specify"
bind_addr = "0.0.0.0:2333" # Necessary. The address that the server listens for clients. Generally only the port needs to be change.
default_token = "default_token_if_not_specify" # Optional
[server.transport]
type = "tls"
[server.transport.tls]
pkcs12 = "identify.pfx"
pkcs12_password = "password"
type = "tcp" # Same as `[client.transport]`
[server.services.service1]
token = "whatever"
bind_addr = "0.0.0.0:8081"
[server.transport.tls] # Necessary if `type` is "tls"
pkcs12 = "identify.pfx" # Necessary. pkcs12 file of server's certificate and private key
pkcs12_password = "password" # Necessary. Password of the pkcs12 file
[server.transport.noise] # Same as `[client.transport.noise]`
pattern = "Noise_NK_25519_ChaChaPoly_BLAKE2s"
local_private_key = "key_encoded_in_base64"
remote_public_key = "key_encoded_in_base64"
[server.services.service1] # The service name must be identical to the client side
type = "tcp" # Optional. Same as the client `[client.services.X.type]
token = "whatever" # Necesary if `server.default_token` not set
bind_addr = "0.0.0.0:8081" # Necessary. The address of the service is exposed at. Generally only the port needs to be change.
[server.services.service2]
bind_addr = "0.0.0.1:8082"

View File

@ -0,0 +1,27 @@
[client]
remote_addr = "localhost:2333"
default_token = "default_token_if_not_specify"
[client.transport]
type = "noise"
[client.transport.noise]
remote_public_key = "mEnUEACy9UrTBmwoCJb6fcKWBRdvfD9XzuBVsroOLFg="
[client.services.echo]
local_addr = "localhost:8080"
[client.services.pingpong]
local_addr = "localhost:8081"
[server]
bind_addr = "0.0.0.0:2333"
default_token = "default_token_if_not_specify"
[server.transport]
type = "noise"
[server.transport.noise]
local_private_key = "kQiSRtS3bs8BoGCJYgFnl1FLrTG1lV53Dj8jSjmg8tE="
[server.services.echo]
bind_addr = "0.0.0.0:2334"
[server.services.pingpong]
bind_addr = "0.0.0.0:2335"

View File

@ -0,0 +1,31 @@
[client]
remote_addr = "localhost:2332"
default_token = "default_token_if_not_specify"
[client.transport]
type = "noise"
[client.transport.noise]
remote_public_key = "mEnUEACy9UrTBmwoCJb6fcKWBRdvfD9XzuBVsroOLFg="
[client.services.echo]
type = "udp"
local_addr = "localhost:8080"
[client.services.pingpong]
type = "udp"
local_addr = "localhost:8081"
[server]
bind_addr = "0.0.0.0:2332"
default_token = "default_token_if_not_specify"
[server.transport]
type = "noise"
[server.transport.noise]
local_private_key = "kQiSRtS3bs8BoGCJYgFnl1FLrTG1lV53Dj8jSjmg8tE="
[server.services.echo]
type = "udp"
bind_addr = "0.0.0.0:2334"
[server.services.pingpong]
type = "udp"
bind_addr = "0.0.0.0:2335"

View File

@ -56,6 +56,7 @@ async fn tcp() -> Result<()> {
test("tests/for_tcp/tcp_transport.toml", Type::Tcp).await?;
test("tests/for_tcp/tls_transport.toml", Type::Tcp).await?;
test("tests/for_tcp/noise_transport.toml", Type::Tcp).await?;
Ok(())
}
@ -80,6 +81,7 @@ async fn udp() -> Result<()> {
test("tests/for_udp/tcp_transport.toml", Type::Udp).await?;
test("tests/for_udp/tls_transport.toml", Type::Udp).await?;
test("tests/for_udp/noise_transport.toml", Type::Udp).await?;
Ok(())
}
@ -91,7 +93,7 @@ async fn test(config_path: &'static str, t: Type) -> Result<()> {
// Start the client
info!("start the client");
tokio::spawn(async move {
let client = tokio::spawn(async move {
run_rathole_client(&config_path, client_shutdown_rx)
.await
.unwrap();
@ -102,12 +104,12 @@ async fn test(config_path: &'static str, t: Type) -> Result<()> {
// Start the server
info!("start the server");
tokio::spawn(async move {
let server = tokio::spawn(async move {
run_rathole_server(&config_path, server_shutdown_rx)
.await
.unwrap();
});
time::sleep(Duration::from_secs(1)).await; // Wait for the client to retry
time::sleep(Duration::from_millis(2000)).await; // Wait for the client to retry
info!("echo");
echo_hitter(ECHO_SERVER_ADDR_EXPOSED, t).await.unwrap();
@ -119,7 +121,7 @@ async fn test(config_path: &'static str, t: Type) -> Result<()> {
// Simulate the client crash and restart
info!("shutdown the client");
client_shutdown_tx.send(true)?;
time::sleep(Duration::from_millis(500)).await;
let _ = tokio::join!(client);
info!("restart the client");
let client_shutdown_rx = client_shutdown_tx.subscribe();
@ -140,7 +142,7 @@ async fn test(config_path: &'static str, t: Type) -> Result<()> {
// Simulate the server crash and restart
info!("shutdown the server");
server_shutdown_tx.send(true)?;
time::sleep(Duration::from_millis(500)).await;
let _ = tokio::join!(server);
info!("restart the server");
let server_shutdown_rx = server_shutdown_tx.subscribe();
@ -149,7 +151,7 @@ async fn test(config_path: &'static str, t: Type) -> Result<()> {
.await
.unwrap();
});
time::sleep(Duration::from_secs(1)).await; // Wait for the client to retry
time::sleep(Duration::from_millis(2000)).await; // Wait for the client to retry
// Simulate heavy load
info!("lots of echo and pingpong");