Skip to content

Commit 8827493

Browse files
committed
fsm: reject unknown IK initiators by default
1 parent b473092 commit 8827493

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎fsm/src/handshake/ik.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn handle_1<M: StreamMeta>(
6262
}
6363

6464
let peer = fsm.state.peer.clone();
65-
if pattern == IkPattern::Kk && peer.is_none() {
65+
if peer.is_none() && (pattern == IkPattern::Kk || !fsm.config.accept_unknown_ik) {
6666
return Err(ReceiveError::NoPeer);
6767
}
6868
if peer.as_ref().is_some_and(|peer| route.sender != peer.qid) {

‎fsm/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ impl StreamMeta for () {
165165
/// timing and buffering knobs for `QlFsm`
166166
#[derive(Debug, Clone, Copy)]
167167
pub struct QlFsmConfig {
168+
/// accept IK initiators without a bound peer
169+
pub accept_unknown_ik: bool,
168170
/// overall time limit for one handshake attempt
169171
pub handshake_timeout: Duration,
170172
pub session: SessionConfig,
@@ -173,6 +175,7 @@ pub struct QlFsmConfig {
173175
impl Default for QlFsmConfig {
174176
fn default() -> Self {
175177
Self {
178+
accept_unknown_ik: false,
176179
handshake_timeout: Duration::from_secs(5),
177180
session: SessionConfig::default(),
178181
}

‎fsm/src/tests/handshake.rs‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,32 @@ fn connect_kk_replaces_in_flight_attempt_and_ignores_stale_reply() {
301301
}
302302

303303
#[test]
304-
fn inbound_ik1_auto_binds_unbound_responder() {
305-
let mut harness = Harness::paired(QlFsmConfig::default(), true, false);
304+
fn inbound_ik1_rejects_unknown_peer_by_default() {
305+
for armed in [false, true] {
306+
let mut harness = Harness::paired(QlFsmConfig::default(), true, false);
307+
if armed {
308+
harness.b.fsm.arm_pairing(pairing_token(9));
309+
}
310+
311+
harness.connect_ik(Side::A).unwrap();
312+
let ik1 = harness.next_outbound(Side::A).unwrap();
313+
let time = harness.time();
314+
let Node { fsm, crypto } = &mut harness.b;
315+
assert_eq!(fsm.receive(time, ik1, crypto), Err(ReceiveError::NoPeer));
316+
assert!(harness.b.fsm.peer().is_none());
317+
assert!(matches!(harness.b.fsm.state.link, LinkState::Idle));
318+
assert!(harness.drain_events(Side::B).is_empty());
319+
assert!(harness.next_outbound(Side::B).is_none());
320+
}
321+
}
322+
323+
#[test]
324+
fn inbound_ik1_auto_binds_unbound_responder_when_enabled() {
325+
let config = QlFsmConfig {
326+
accept_unknown_ik: true,
327+
..QlFsmConfig::default()
328+
};
329+
let mut harness = Harness::paired(config, true, false);
306330

307331
harness.connect_ik(Side::A).unwrap();
308332
harness.pump();

‎fsm/src/tests/proptest.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl Runner {
154154
..SessionConfig::default()
155155
},
156156
handshake_timeout: Duration::from_millis(60),
157+
..QlFsmConfig::default()
157158
};
158159

159160
Self {

‎runtime/src/tests/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ fn default_runtime_config() -> RuntimeConfig {
623623
..SessionConfig::default()
624624
},
625625
handshake_timeout: Duration::from_millis(300),
626+
..QlFsmConfig::default()
626627
},
627628
..Default::default()
628629
}

0 commit comments

Comments
 (0)