mirror of
https://github.com/ratspeak/rsLXST
synced 2026-11-22 23:10:37 +00:00
telephony: ignore unauthenticated Link proof candidates
This commit is contained in:
1 parent
260e41ada6
commit
3bc4d9d8ec
2 files changed
+60
-7
No files matched your search
@@ -3285,8 +3285,12 @@ impl TelephonyRnsEndpoint {
|
||||
| DestinationEvent::LinkRequest { .. }
|
||||
| DestinationEvent::LinkClosed { .. } => return Ok(None),
|
||||
};
|
||||
let (header, data_offset) = rns_wire::header::PacketHeader::unpack(&raw)
|
||||
.map_err(|err| Error::LinkOperation(err.to_string()))?;
|
||||
let Ok((header, data_offset)) = rns_wire::header::PacketHeader::unpack(&raw) else {
|
||||
// A pending attempt can see unauthenticated candidates before the
|
||||
// authentic LRPROOF arrives. Malformed candidates are not terminal
|
||||
// and must not win that race.
|
||||
return Ok(None);
|
||||
};
|
||||
if header.destination_hash != link_id
|
||||
|| header.flags.packet_type != rns_wire::flags::PacketType::Proof
|
||||
|| raw.len() <= data_offset
|
||||
@@ -3302,10 +3306,16 @@ impl TelephonyRnsEndpoint {
|
||||
identity_ed25519_pub.copy_from_slice(&attempt.remote_public_key[32..64]);
|
||||
let verify_key = Ed25519PublicKey::from_bytes(&identity_ed25519_pub)
|
||||
.map_err(|err| Error::LinkProofInvalid(err.to_string()))?;
|
||||
let rtt_data = attempt
|
||||
.link
|
||||
.validate_proof(&raw[data_offset..], &verify_key, &identity_ed25519_pub)
|
||||
.map_err(|err| Error::LinkProofInvalid(format!("{err:?}")))?;
|
||||
let Ok(rtt_data) =
|
||||
attempt
|
||||
.link
|
||||
.validate_proof(&raw[data_offset..], &verify_key, &identity_ed25519_pub)
|
||||
else {
|
||||
// LRPROOF candidates are unauthenticated until this validation
|
||||
// succeeds. Ignore an invalid first arrival so the attempt remains
|
||||
// pending for a later authentic proof or its normal timeout.
|
||||
return Ok(None);
|
||||
};
|
||||
attempt.link.update_phy_stats_force(
|
||||
metrics.rssi.map(f64::from),
|
||||
metrics.snr.map(f64::from),
|
||||
|
||||
@@ -3073,6 +3073,29 @@ fn outgoing_link_attempt_promotes_after_proof_and_drives_available_signal() {
|
||||
|
||||
let (mut responder, proof_data) =
|
||||
Link::new_responder(&request_data, &remote_signing_key, destination_hash, 1).unwrap();
|
||||
let mut invalid_proof_data = proof_data.clone();
|
||||
*invalid_proof_data.last_mut().unwrap() ^= 0x01;
|
||||
link_event_tx
|
||||
.try_send(DestinationEvent::InboundPacket {
|
||||
raw: Bytes::from(link_proof_packet(link_id, &invalid_proof_data)),
|
||||
interface_id: 7,
|
||||
metrics: PacketMetrics {
|
||||
rssi: Some(-12.0),
|
||||
snr: Some(30.0),
|
||||
q: Some(99.0),
|
||||
},
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(endpoint.try_recv_link_event().unwrap(), None);
|
||||
let pending = &endpoint.outgoing_attempts[&link_id].link;
|
||||
assert_eq!(pending.state, rns_link::link::LinkState::Pending);
|
||||
assert_eq!(pending.get_rssi(), None);
|
||||
assert!(matches!(
|
||||
transport_rx.try_recv(),
|
||||
Err(mpsc::error::TryRecvError::Empty)
|
||||
));
|
||||
|
||||
link_event_tx
|
||||
.try_send(DestinationEvent::InboundPacket {
|
||||
raw: Bytes::from(link_proof_packet(link_id, &proof_data)),
|
||||
@@ -3807,7 +3830,7 @@ fn outgoing_link_attempt_timeout_is_driven_by_endpoint_tick() {
|
||||
let (transport_tx, mut transport_rx) = mpsc::channel(8);
|
||||
let mut endpoint = TelephonyRnsEndpoint::register(transport_tx, &local_identity).unwrap();
|
||||
let _registration = transport_rx.try_recv().unwrap();
|
||||
let (_event_tx, event_rx) = mpsc::channel(1);
|
||||
let (event_tx, event_rx) = mpsc::channel(1);
|
||||
let (mut link, _request) = Link::new_initiator(link(0xA9), 1);
|
||||
link.establishment_timeout = Duration::ZERO;
|
||||
let link_id = link.link_id;
|
||||
@@ -3820,6 +3843,26 @@ fn outgoing_link_attempt_timeout_is_driven_by_endpoint_tick() {
|
||||
},
|
||||
);
|
||||
|
||||
event_tx
|
||||
.try_send(DestinationEvent::InboundPacket {
|
||||
raw: Bytes::from(link_proof_packet(link_id, &[0xA5; 96])),
|
||||
interface_id: 44,
|
||||
metrics: PacketMetrics {
|
||||
rssi: Some(-1.0),
|
||||
snr: Some(60.0),
|
||||
q: Some(100.0),
|
||||
},
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(endpoint.try_recv_link_event().unwrap(), None);
|
||||
let pending = &endpoint.outgoing_attempts[&link_id].link;
|
||||
assert_eq!(pending.state, rns_link::link::LinkState::Pending);
|
||||
assert_eq!(pending.get_rssi(), None);
|
||||
assert!(matches!(
|
||||
transport_rx.try_recv(),
|
||||
Err(mpsc::error::TryRecvError::Empty)
|
||||
));
|
||||
|
||||
endpoint.tick_reticulum();
|
||||
assert_eq!(
|
||||
endpoint.try_recv_link_event().unwrap(),
|
||||
|
||||
Reference in new issue
Block a user