feat: drop unknown typed frames instead of storing as chat
Classify decrypted plaintext before append_message so loc/prf/inv/rcp/png and unknown xxx[space] prefixes never land in the message log.
This commit is contained in:
parent
cbbf3f6baa
commit
c9d85d9ae5
4 changed files with 105 additions and 18 deletions
44
src/node.rs
44
src/node.rs
|
|
@ -9,6 +9,7 @@ use futures::io::{AsyncRead, AsyncWrite};
|
|||
use tor_cell::relaycell::msg::Connected;
|
||||
use tor_hsservice::{RunningOnionService, handle_rend_requests};
|
||||
|
||||
use crate::dispatch::{self, Kind};
|
||||
use crate::frame;
|
||||
use crate::hs::{self, Client, HS_PORT};
|
||||
use crate::loc;
|
||||
|
|
@ -308,26 +309,33 @@ impl Node {
|
|||
.map_err(session_err)?;
|
||||
let ct = frame::read_frame(stream).await.map_err(|e| e.to_string())?;
|
||||
let pt = sess.decrypt(&ct).map_err(session_err)?;
|
||||
if let Some(loc) = loc::decode(&pt) {
|
||||
let applied = store.lock().map_err(|e| e.to_string())?.apply_loc(
|
||||
&sess.peer_identity,
|
||||
&loc.onion,
|
||||
loc.ts,
|
||||
&loc.sig,
|
||||
);
|
||||
match applied {
|
||||
Ok(true) => {}
|
||||
Ok(false) => eprintln!("loc dropped (bad sig, stale ts, or unknown friend)"),
|
||||
Err(e) => return Err(e.to_string()),
|
||||
match dispatch::classify(&pt) {
|
||||
Kind::Loc => {
|
||||
if let Some(loc) = loc::decode(&pt) {
|
||||
let applied = store.lock().map_err(|e| e.to_string())?.apply_loc(
|
||||
&sess.peer_identity,
|
||||
&loc.onion,
|
||||
loc.ts,
|
||||
&loc.sig,
|
||||
);
|
||||
match applied {
|
||||
Ok(true) => {}
|
||||
Ok(false) => eprintln!("loc dropped (bad sig, stale ts, or unknown friend)"),
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
return Ok(());
|
||||
Kind::Chat => {
|
||||
store
|
||||
.lock()
|
||||
.map_err(|e| e.to_string())?
|
||||
.append_message(&sess.peer_identity, "in", &pt)
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
Kind::Profile | Kind::Invoice | Kind::Receipt | Kind::Ping | Kind::Drop => Ok(()),
|
||||
}
|
||||
store
|
||||
.lock()
|
||||
.map_err(|e| e.to_string())?
|
||||
.append_message(&sess.peer_identity, "in", &pt)
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue