Encryption and One-Way-Control (#200)

This is a major rewrite of the core networking logic enabling one-way control and encryption through the webrtc-dtls crate.

closes #164 
closes #104
This commit is contained in:
Ferdinand Schober
2024-11-09 13:54:43 +01:00
committed by GitHub
parent 0d074e19f1
commit 7677fae14b
38 changed files with 4003 additions and 1374 deletions

View File

@@ -1,5 +1,5 @@
use std::{
collections::HashSet,
collections::{HashMap, HashSet},
env::VarError,
fmt::Display,
io,
@@ -33,7 +33,7 @@ pub enum ConnectionError {
}
#[derive(Debug, Error)]
pub enum ListenerCreationError {
pub enum IpcListenerCreationError {
#[error("could not determine socket-path: `{0}`")]
SocketPath(#[from] SocketPathError),
#[error("service already running!")]
@@ -51,7 +51,7 @@ pub enum IpcError {
#[error(transparent)]
Connection(#[from] ConnectionError),
#[error(transparent)]
Listen(#[from] ListenerCreationError),
Listen(#[from] IpcListenerCreationError),
}
pub const DEFAULT_PORT: u16 = 4242;
@@ -65,6 +65,17 @@ pub enum Position {
Bottom,
}
impl Position {
pub fn opposite(&self) -> Self {
match self {
Position::Left => Position::Right,
Position::Right => Position::Left,
Position::Top => Position::Bottom,
Position::Bottom => Position::Top,
}
}
}
#[derive(Debug, Error)]
#[error("not a valid position: {pos}")]
pub struct PositionParseError {
@@ -150,7 +161,7 @@ pub struct ClientState {
/// This should generally be the socket address where data
/// was last received from.
pub active_addr: Option<SocketAddr>,
/// tracks whether or not the client is responding to pings
/// tracks whether or not the client is available for emulation
pub alive: bool,
/// ips from dns
pub dns_ips: Vec<IpAddr>,
@@ -186,6 +197,14 @@ pub enum FrontendEvent {
CaptureStatus(Status),
/// emulation status
EmulationStatus(Status),
/// authorized public key fingerprints have been updated
AuthorizedUpdated(HashMap<String, String>),
/// public key fingerprint of this device
PublicKeyFingerprint(String),
/// incoming connected
IncomingConnected(String, SocketAddr, Position),
/// incoming disconnected
IncomingDisconnected(SocketAddr),
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
@@ -218,9 +237,13 @@ pub enum FrontendRequest {
EnableEmulation,
/// synchronize all state
Sync,
/// authorize fingerprint (description, fingerprint)
AuthorizeKey(String, String),
/// remove fingerprint (fingerprint)
RemoveAuthorizedKey(String),
}
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
pub enum Status {
#[default]
Disabled,

View File

@@ -20,7 +20,7 @@ use tokio::net::TcpListener;
#[cfg(windows)]
use tokio::net::TcpStream;
use crate::{FrontendEvent, FrontendRequest, IpcError, ListenerCreationError};
use crate::{FrontendEvent, FrontendRequest, IpcError, IpcListenerCreationError};
pub struct AsyncFrontendListener {
#[cfg(windows)]
@@ -40,7 +40,7 @@ pub struct AsyncFrontendListener {
}
impl AsyncFrontendListener {
pub async fn new() -> Result<Self, ListenerCreationError> {
pub async fn new() -> Result<Self, IpcListenerCreationError> {
#[cfg(unix)]
let (socket_path, listener) = {
let socket_path = crate::default_socket_path()?;
@@ -51,7 +51,7 @@ impl AsyncFrontendListener {
// of lan-mouse is already running
match UnixStream::connect(&socket_path).await {
// connected -> lan-mouse is already running
Ok(_) => return Err(ListenerCreationError::AlreadyRunning),
Ok(_) => return Err(IpcListenerCreationError::AlreadyRunning),
// lan-mouse is not running but a socket was left behind
Err(e) => {
log::debug!("{socket_path:?}: {e} - removing left behind socket");
@@ -63,9 +63,9 @@ impl AsyncFrontendListener {
Ok(ls) => ls,
// some other lan-mouse instance has bound the socket in the meantime
Err(e) if e.kind() == ErrorKind::AddrInUse => {
return Err(ListenerCreationError::AlreadyRunning)
return Err(IpcListenerCreationError::AlreadyRunning)
}
Err(e) => return Err(ListenerCreationError::Bind(e)),
Err(e) => return Err(IpcListenerCreationError::Bind(e)),
};
(socket_path, listener)
};
@@ -75,9 +75,9 @@ impl AsyncFrontendListener {
Ok(ls) => ls,
// some other lan-mouse instance has bound the socket in the meantime
Err(e) if e.kind() == ErrorKind::AddrInUse => {
return Err(ListenerCreationError::AlreadyRunning)
return Err(IpcListenerCreationError::AlreadyRunning)
}
Err(e) => return Err(ListenerCreationError::Bind(e)),
Err(e) => return Err(IpcListenerCreationError::Bind(e)),
};
let adapter = Self {