100 lines
3.2 KiB
Rust
100 lines
3.2 KiB
Rust
use crate::*;
|
|
|
|
#[::tracing_test::traced_test]
|
|
#[::tokio::test]
|
|
async fn test_connection_dirsync() {
|
|
use enc::asym::{KeyID, PrivKey, PubKey};
|
|
let rand = enc::Random::new();
|
|
let (priv_exchange_key, pub_exchange_key) =
|
|
match enc::asym::KeyExchangeKind::X25519DiffieHellman.new_keypair(&rand)
|
|
{
|
|
Ok((privkey, pubkey)) => {
|
|
(PrivKey::Exchange(privkey), PubKey::Exchange(pubkey))
|
|
}
|
|
Err(_) => {
|
|
assert!(false, "Can't generate random keypair");
|
|
return;
|
|
}
|
|
};
|
|
let cfg_client = {
|
|
let mut cfg = config::Config::default();
|
|
cfg.threads = Some(::core::num::NonZeroUsize::new(1).unwrap());
|
|
cfg
|
|
};
|
|
let test_domain: Domain = "example.com".into();
|
|
let cfg_server = {
|
|
let mut cfg = cfg_client.clone();
|
|
cfg.server_keys = [config::ServerKey {
|
|
id: KeyID(42),
|
|
priv_key: priv_exchange_key,
|
|
pub_key: pub_exchange_key,
|
|
}]
|
|
.to_vec();
|
|
cfg.servers = [config::AuthServer {
|
|
fqdn: test_domain.clone(),
|
|
keys: [KeyID(42)].to_vec(),
|
|
}]
|
|
.to_vec();
|
|
cfg
|
|
};
|
|
|
|
let (server, mut srv_workers) =
|
|
Fenrir::with_workers(&cfg_server).await.unwrap();
|
|
let (client, mut cli_workers) =
|
|
Fenrir::with_workers(&cfg_client).await.unwrap();
|
|
let mut srv_worker = srv_workers.pop().unwrap();
|
|
let mut cli_worker = cli_workers.pop().unwrap();
|
|
|
|
::std::thread::spawn(move || {
|
|
let rt = ::tokio::runtime::Builder::new_current_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap();
|
|
let local_thread = ::tokio::task::LocalSet::new();
|
|
local_thread.spawn_local(async move {
|
|
srv_worker.work_loop().await;
|
|
});
|
|
|
|
local_thread.spawn_local(async move {
|
|
::tokio::time::sleep(::std::time::Duration::from_millis(100)).await;
|
|
cli_worker.work_loop().await;
|
|
});
|
|
rt.block_on(local_thread);
|
|
});
|
|
|
|
use crate::dnssec::{record, Record};
|
|
|
|
let port: u16 = server.addresses()[0].port();
|
|
|
|
let dnssec_record = Record {
|
|
public_keys: [(KeyID(42), pub_exchange_key)].to_vec(),
|
|
addresses: [record::Address {
|
|
ip: ::std::net::IpAddr::V4(::std::net::Ipv4Addr::new(127, 0, 0, 1)),
|
|
port: Some(::core::num::NonZeroU16::new(port).unwrap()),
|
|
priority: record::AddressPriority::P1,
|
|
weight: record::AddressWeight::W1,
|
|
handshake_ids: [handshake::ID::DirectorySynchronized].to_vec(),
|
|
public_key_idx: [record::PubKeyIdx(0)].to_vec(),
|
|
}]
|
|
.to_vec(),
|
|
key_exchanges: [enc::asym::KeyExchangeKind::X25519DiffieHellman]
|
|
.to_vec(),
|
|
hkdfs: [enc::hkdf::Kind::Sha3].to_vec(),
|
|
ciphers: [enc::sym::Kind::XChaCha20Poly1305].to_vec(),
|
|
};
|
|
|
|
::tokio::time::sleep(::std::time::Duration::from_millis(500)).await;
|
|
match client
|
|
.connect_resolved(dnssec_record, &test_domain, auth::SERVICEID_AUTH)
|
|
.await
|
|
{
|
|
Ok((_, _)) => {}
|
|
Err(e) => {
|
|
assert!(false, "Err on client connection: {:?}", e);
|
|
}
|
|
}
|
|
|
|
server.graceful_stop().await;
|
|
client.graceful_stop().await;
|
|
}
|