chore(rp): Simplify code to setup Rosenpass AppServer

This commit is contained in:
Karolin Varner
2025-08-02 18:32:31 +02:00
parent 8561aaf137
commit 41eb620751

View File

@@ -426,41 +426,35 @@ impl Drop for WireGuardDevice {
/// Sets up the rosenpass link and wireguard and configures both with the configuration specified by /// Sets up the rosenpass link and wireguard and configures both with the configuration specified by
/// `options`. /// `options`.
pub async fn exchange(options: ExchangeOptions) -> Result<()> { pub async fn exchange(options: ExchangeOptions) -> Result<()> {
// Load the server parameter files
// TODO: Should be async, but right now its now // TODO: Should be async, but right now its now
let wgsk = options let wgsk = options
.private_keys_dir .private_keys_dir
.join("wgsk") .join("wgsk")
.apply(WgSecretKey::load_b64::<WG_B64_LEN, _>)?; .apply(WgSecretKey::load_b64::<WG_B64_LEN, _>)?;
let rpsk = options.private_keys_dir.join("pqsk").apply(SSk::load)?;
let rppk = options.private_keys_dir.join("pqpk").apply(SPk::load)?;
// Setup the WireGuard device
let device = options.dev.as_deref().unwrap_or("rosenpass0"); let device = options.dev.as_deref().unwrap_or("rosenpass0");
let mut device = WireGuardDevice::create_device(device.to_owned()).await?; let mut device = WireGuardDevice::create_device(device.to_owned()).await?;
// Assign WG secret key & port
device device
.set_private_key_and_listen_addr(&wgsk, options.listen.map(|ip| ip.port() + 1)) .set_private_key_and_listen_addr(&wgsk, options.listen.map(|ip| ip.port() + 1))
.await?; .await?;
// Assign the public IP address for the interface
if let Some(ref ip) = options.ip { if let Some(ref ip) = options.ip {
device.add_ip_address(ip).await?; device.add_ip_address(ip).await?;
} }
// set up the rosenpass AppServer
let pqsk = options.private_keys_dir.join("pqsk");
let pqpk = options.private_keys_dir.join("pqpk");
let sk = SSk::load(&pqsk)?;
let pk = SPk::load(&pqpk)?;
let mut srv = Box::new(AppServer::new( let mut srv = Box::new(AppServer::new(
Some((sk, pk)), Some((rpsk, rppk)),
if let Some(listen) = options.listen { Vec::from_iter(options.listen),
vec![listen] match options.verbose {
} else { true => Verbosity::Verbose,
Vec::with_capacity(0) false => Verbosity::Quiet,
},
if options.verbose {
Verbosity::Verbose
} else {
Verbosity::Quiet
}, },
None, None,
)?); )?);