rdp: lookup cert/key from .config by default

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2024-11-19 16:31:17 +04:00
parent ffb7492d9e
commit 1927fffb21
6 changed files with 84 additions and 9 deletions

49
Cargo.lock generated
View File

@ -1067,6 +1067,27 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "dirs"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "displaydoc" name = "displaydoc"
version = "0.2.5" version = "0.2.5"
@ -2660,6 +2681,16 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.6.0",
"libc",
]
[[package]] [[package]]
name = "libusb1-sys" name = "libusb1-sys"
version = "0.7.0" version = "0.7.0"
@ -2991,6 +3022,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]] [[package]]
name = "option-operations" name = "option-operations"
version = "0.5.0" version = "0.5.0"
@ -3512,6 +3549,7 @@ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",
"clap 4.5.20", "clap 4.5.20",
"dirs",
"enumflags2", "enumflags2",
"futures-util", "futures-util",
"ironrdp", "ironrdp",
@ -3701,6 +3739,17 @@ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
] ]
[[package]]
name = "redox_users"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.11.1" version = "1.11.1"

View File

@ -8,8 +8,9 @@ use zbus::{
fdo, fdo,
fdo::ManagedObjects, fdo::ManagedObjects,
names::{BusName, OwnedUniqueName, UniqueName, WellKnownName}, names::{BusName, OwnedUniqueName, UniqueName, WellKnownName},
proxy::OwnerChangedStream,
zvariant::OwnedObjectPath, zvariant::OwnedObjectPath,
Connection, proxy::OwnerChangedStream, Connection,
}; };
#[cfg(unix)] #[cfg(unix)]

View File

@ -32,3 +32,4 @@ ironrdp = { git = "https://github.com/Devolutions/IronRDP", features = [
futures-util = "0.3" futures-util = "0.3"
zbus.workspace = true zbus.workspace = true
enumflags2 = "0.7.10" enumflags2 = "0.7.10"
dirs = "5.0.1"

View File

@ -21,7 +21,7 @@ pub struct Args {
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
pub enum Commands { pub enum Commands {
/// Start a RDP server /// Start a RDP server
#[command(arg_required_else_help = true)] #[command()]
Serve(ServerArgs), Serve(ServerArgs),
} }
@ -34,11 +34,11 @@ pub struct ServerArgs {
/// Path to tls certificate /// Path to tls certificate
#[clap(short, long, value_parser)] #[clap(short, long, value_parser)]
pub cert: PathBuf, pub cert: Option<PathBuf>,
/// Path to private key /// Path to private key
#[clap(short, long, value_parser)] #[clap(short, long, value_parser)]
pub key: PathBuf, pub key: Option<PathBuf>,
/// RemoteFx encoding /// RemoteFx encoding
#[clap(value_enum, long, default_value = "enable")] #[clap(value_enum, long, default_value = "enable")]

View File

@ -3,7 +3,9 @@ mod display;
mod input; mod input;
mod sound; mod sound;
use anyhow::Error; use std::path::PathBuf;
use anyhow::{bail, Error};
use enumflags2::BitFlags; use enumflags2::BitFlags;
use ironrdp::server::{Credentials, ServerEvent, TlsIdentityCtx}; use ironrdp::server::{Credentials, ServerEvent, TlsIdentityCtx};
@ -35,6 +37,25 @@ impl Server {
} }
pub async fn run(&mut self) -> Result<(), Error> { pub async fn run(&mut self) -> Result<(), Error> {
let (cert, key) = match (&self.args.cert, &self.args.key) {
(Some(cert), Some(key)) => (cert.as_path().to_owned(), key.as_path().to_owned()),
(None, None) => {
let mut config_dir = dirs::config_dir().expect("configuration directory");
config_dir.push("qemu-rdp");
let cert: PathBuf = [config_dir.clone(), PathBuf::from("cert.der")]
.iter()
.collect();
let key: PathBuf = [config_dir, PathBuf::from("key.der")].iter().collect();
(cert, key)
}
_ => {
bail!("Provide both --cert and --key")
}
};
println!("Waiting for org.qemu...");
Display::lookup(&self.dbus, true, None).await?;
let dbus_display = Display::new::<()>(&self.dbus, None).await?; let dbus_display = Display::new::<()>(&self.dbus, None).await?;
let handler = InputHandler::connect(&dbus_display).await?; let handler = InputHandler::connect(&dbus_display).await?;
@ -48,8 +69,7 @@ impl Server {
} }
}; };
let tls = let tls = TlsIdentityCtx::init_from_paths(&cert, &key)?;
TlsIdentityCtx::init_from_paths(self.args.cert.as_path(), self.args.key.as_path())?;
let mut server = RdpServer::builder() let mut server = RdpServer::builder()
.with_addr(self.args.bind_addr) .with_addr(self.args.bind_addr)
.with_hybrid(tls.make_acceptor()?, tls.pub_key) .with_hybrid(tls.make_acceptor()?, tls.pub_key)
@ -80,7 +100,11 @@ impl Server {
.request_name_with_flags("org.QemuDisplay", BitFlags::EMPTY) .request_name_with_flags("org.QemuDisplay", BitFlags::EMPTY)
.await?; .await?;
server.run().await println!("Starting RDP server, args: {:?}", self.args);
println!("Cert: {cert:?}, Key: {key:?}");
server.run().await?;
println!("RDP server ended");
Ok(())
} }
} }

View File

@ -77,7 +77,7 @@ async fn display_from_opt(opt: Rc<RefCell<AppOptions>>) -> Option<Display<'stati
.map(Into::into) .map(Into::into)
} else { } else {
if opt.borrow().wait { if opt.borrow().wait {
unimplemented!(); // FIXME Display::lookup(&conn, true, None).await.unwrap();
} }
BusName::try_from("org.qemu").ok() BusName::try_from("org.qemu").ok()
}; };