From ff18ea813e100b005488ad6df98658e2b164a4b2 Mon Sep 17 00:00:00 2001 From: Stephen <webmaster@scd31.com> Date: Tue, 18 Apr 2023 12:05:11 -0300 Subject: [PATCH] prevent replay attacks --- src/aprs.rs | 10 ++++++---- src/control.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/aprs.rs b/src/aprs.rs index a72a5bd..0194f44 100644 --- a/src/aprs.rs +++ b/src/aprs.rs @@ -61,7 +61,7 @@ impl CommandHandler { } } - pub fn process_forever(&self) { + pub fn process_forever(&mut self) { tokio::runtime::Builder::new_current_thread() .enable_all() .build() @@ -76,7 +76,7 @@ impl CommandHandler { }); } - async fn connect_and_process(&self) -> anyhow::Result<()> { + async fn connect_and_process(&mut self) -> anyhow::Result<()> { // TODO don't hardcode this let mut tnc = Tnc::connect_tcp("localhost:8001").await?; @@ -89,7 +89,7 @@ impl CommandHandler { Ok(()) } - fn process_packet(&self, packet: &AprsPacket) { + fn process_packet(&mut self, packet: &AprsPacket) { if let AprsData::Message(msg) = &packet.data { if msg.addressee == self.callsign.as_bytes() { if let Err(e) = self.process_msg(&msg.text) { @@ -99,7 +99,7 @@ impl CommandHandler { } } - fn process_msg(&self, msg: &[u8]) -> anyhow::Result<()> { + fn process_msg(&mut self, msg: &[u8]) -> anyhow::Result<()> { let msg = String::from_utf8(msg.to_vec())?; let mut iter = msg.split('|'); @@ -122,6 +122,8 @@ impl CommandHandler { bail!("Given ID too small"); } + self.min_id = id + 1; + let cmd = Command::decode(cmd.as_bytes()).context("Invalid command")?; match cmd { diff --git a/src/control.rs b/src/control.rs index 3b7af03..7a21b0e 100644 --- a/src/control.rs +++ b/src/control.rs @@ -66,7 +66,7 @@ impl Controller { // used to request HD images, as well as // to initiate burst/cutdown fn aprs_thread(config: Config, tx: Sender<u8>) { - let handler = CommandHandler::new( + let mut handler = CommandHandler::new( config.callsign, config.secret, config.burst_command, -- GitLab