feat: added a basic interactivity to the client
This commit is contained in:
@@ -65,7 +65,7 @@ fn get_current_capabilities() -> anyhow::Result<Capabilities> {
|
||||
return Err(std::io::Error::last_os_error())?;
|
||||
}
|
||||
|
||||
let docker_container = false;
|
||||
let docker_container = std::fs::read_to_string("/proc/1/cgroup")? != "0::/\n";
|
||||
let docker_breakout = false;
|
||||
let uid = unsafe { libc::getuid() };
|
||||
let root = uid == 0;
|
||||
@@ -76,6 +76,9 @@ fn get_current_capabilities() -> anyhow::Result<Capabilities> {
|
||||
TransportType::Udp
|
||||
};
|
||||
let userent = get_username(uid)?;
|
||||
let hostname = std::fs::read_to_string("/etc/hostname")
|
||||
.map(|s| s.trim().to_string())
|
||||
.ok();
|
||||
|
||||
Ok(Capabilities {
|
||||
operating_system: if cfg!(target_os = "linux") {
|
||||
@@ -89,6 +92,7 @@ fn get_current_capabilities() -> anyhow::Result<Capabilities> {
|
||||
root,
|
||||
userent,
|
||||
transport,
|
||||
hostname,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,6 +108,7 @@ fn get_current_capabilities() -> anyhow::Result<Capabilities> {
|
||||
root: userent.as_deref() == Some("Administrator"),
|
||||
userent,
|
||||
transport: TransportType::Udp,
|
||||
hostname: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ struct ConnectionInformation {
|
||||
srcip: Ipv4Addr,
|
||||
dstip: Ipv4Addr,
|
||||
srcport: u16,
|
||||
packet_sender: Sender<EthernetPacket>,
|
||||
}
|
||||
|
||||
impl ConnectionInformation {
|
||||
@@ -79,6 +80,11 @@ impl ConnectionInformation {
|
||||
|
||||
Ok(rmp_serde::from_slice(&data)?)
|
||||
}
|
||||
|
||||
fn send(&self, packet: EthernetPacket) -> anyhow::Result<()> {
|
||||
self.packet_sender.send(packet)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_connection_handler(
|
||||
@@ -132,6 +138,7 @@ pub fn spawn_connection_handler(
|
||||
srcip: ip_pkt.source_ip(),
|
||||
dstip: ip_pkt.dest_ip(),
|
||||
srcport: udp_pkt.srcport(),
|
||||
packet_sender,
|
||||
}
|
||||
};
|
||||
let close = {
|
||||
@@ -145,7 +152,7 @@ pub fn spawn_connection_handler(
|
||||
let (packet_handler_sender, packet_handler) = channel();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = authenticate(capabilities, packet_handler, conninfo, packet_sender, close) {
|
||||
if let Err(e) = authenticate(capabilities, packet_handler, conninfo, close) {
|
||||
eprintln!("connection thread died: {e:?}");
|
||||
}
|
||||
});
|
||||
@@ -159,7 +166,6 @@ fn authenticate<F: Fn()>(
|
||||
capabilities: Arc<Capabilities>,
|
||||
packet_handler: Receiver<EthernetPacket>,
|
||||
conninfo: ConnectionInformation,
|
||||
packet_sender: Sender<EthernetPacket>,
|
||||
close: F,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut counter = 0;
|
||||
@@ -169,15 +175,16 @@ fn authenticate<F: Fn()>(
|
||||
close();
|
||||
}
|
||||
|
||||
let next_pkt = conninfo.encrypt_and_sign(
|
||||
&[
|
||||
&conninfo.local_sign_keypair.public.to_bytes(),
|
||||
&conninfo.local_enc_pubkey.to_bytes(),
|
||||
&*(rmp_serde::to_vec(&*capabilities)?),
|
||||
]
|
||||
.concat(),
|
||||
conninfo.send(
|
||||
conninfo.encrypt_and_sign(
|
||||
&[
|
||||
&conninfo.local_sign_keypair.public.to_bytes(),
|
||||
&conninfo.local_enc_pubkey.to_bytes(),
|
||||
&*(rmp_serde::to_vec(&*capabilities)?),
|
||||
]
|
||||
.concat(),
|
||||
)?,
|
||||
)?;
|
||||
packet_sender.send(next_pkt)?;
|
||||
|
||||
match packet_handler.recv_timeout(std::time::Duration::from_millis(250)) {
|
||||
Ok(p) => {
|
||||
@@ -204,14 +211,13 @@ fn authenticate<F: Fn()>(
|
||||
}
|
||||
}
|
||||
|
||||
handle_full_connection(capabilities, packet_handler, conninfo, packet_sender, close)
|
||||
handle_full_connection(capabilities, packet_handler, conninfo, close)
|
||||
}
|
||||
|
||||
fn handle_full_connection<F>(
|
||||
capabilities: Arc<Capabilities>,
|
||||
packet_handler: Receiver<EthernetPacket>,
|
||||
conninfo: ConnectionInformation,
|
||||
packet_sender: Sender<EthernetPacket>,
|
||||
close: F,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user