disable auth for now

This commit is contained in:
2025-11-16 16:50:34 -05:00
parent 7d73a8344a
commit 8fe403b94d
6 changed files with 170 additions and 83 deletions

View File

@@ -1,19 +1,8 @@
use quinn::{
Endpoint,
crypto::rustls::QuicServerConfig,
rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer},
};
use std::{fs, net::SocketAddr, path::Path, str::FromStr, sync::Arc};
use crate::net::{ClientMsg, server::listen};
use tracing::Instrument;
use crate::net::ClientMsg;
#[tokio::main]
pub async fn run_server() {
quinn::rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.unwrap();
let dirs = directories_next::ProjectDirs::from("", "", "openworm").unwrap();
let path = dirs.data_local_dir();
let endpoint = listen(path);
@@ -27,43 +16,6 @@ pub async fn run_server() {
}
});
}
println!("hello world!");
}
pub fn listen(data_path: &Path) -> Endpoint {
let cert_path = data_path.join("cert.der");
let key_path = data_path.join("key.der");
let (cert, key) = match fs::read(&cert_path).and_then(|x| Ok((x, fs::read(&key_path)?))) {
Ok((cert, key)) => (
CertificateDer::from(cert),
PrivateKeyDer::try_from(key).unwrap(),
),
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap();
let key = PrivatePkcs8KeyDer::from(cert.signing_key.serialize_der());
let cert = cert.cert.into();
fs::create_dir_all(data_path).expect("failed to create certificate directory");
fs::write(&cert_path, &cert).expect("failed to write certificate");
fs::write(&key_path, key.secret_pkcs8_der()).expect("failed to write private key");
(cert, key.into())
}
Err(e) => {
panic!("failed to read certificate: {}", e);
}
};
let server_crypto = quinn::rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(vec![cert], key)
.unwrap();
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(
QuicServerConfig::try_from(server_crypto).unwrap(),
));
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
transport_config.max_concurrent_uni_streams(0_u8.into());
quinn::Endpoint::server(server_config, SocketAddr::from_str("[::1]:4433").unwrap()).unwrap()
}
async fn handle_connection(conn: quinn::Incoming) -> std::io::Result<()> {