From 9b748d1bdcb24efac3bc5a5897b75a21f7ac4ec3 Mon Sep 17 00:00:00 2001 From: Audric Date: Wed, 15 Apr 2026 21:13:58 +0200 Subject: [PATCH] TWIN inbound: validate HMAC and local_prefix before handoff Add HMAC verification (msg.verify) and local_prefix equality check in Reflector::twinPendingFrameReceived, after the role check and before handing the connection off to TwinLink::acceptInboundConnection. HMAC is checked first (fail-fast, avoids leaking prefix info on bad secret). Expose secret() and localPrefix() as const accessors on TwinLink. --- src/svxlink/reflector/Reflector.cpp | 20 +++++++++++++++++++- src/svxlink/reflector/TwinLink.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/svxlink/reflector/Reflector.cpp b/src/svxlink/reflector/Reflector.cpp index 7540ff1..7899d16 100644 --- a/src/svxlink/reflector/Reflector.cpp +++ b/src/svxlink/reflector/Reflector.cpp @@ -4023,7 +4023,25 @@ void Reflector::twinPendingFrameReceived(Async::FramedTcpConnection* con, return; } - // Secret/prefix validation lives inside TwinLink::acceptInboundConnection. + // Verify HMAC (shared secret proof) before leaking any other info. + if (!msg.verify(m_twin_link->secret())) + { + std::cerr << "*** ERROR: TWIN inbound: authentication failed " + << "(wrong secret)" << std::endl; + rejectPending(); + return; + } + + // Twins must share the same LOCAL_PREFIX. + if (msg.localPrefix() != m_twin_link->localPrefix()) + { + std::cerr << "*** ERROR: TWIN inbound: local_prefix mismatch: " + << "ours='" << m_twin_link->localPrefix() + << "' theirs='" << msg.localPrefix() << "'" << std::endl; + rejectPending(); + return; + } + // Clean up our pending entry and hand off. delete pit->second; // timer m_twin_pending_cons.erase(pit); diff --git a/src/svxlink/reflector/TwinLink.h b/src/svxlink/reflector/TwinLink.h index 49f87c4..b86decf 100644 --- a/src/svxlink/reflector/TwinLink.h +++ b/src/svxlink/reflector/TwinLink.h @@ -95,6 +95,8 @@ class TwinLink bool isActive(void) const; const std::string& partnerHost(void) const { return m_peer_host; } uint16_t partnerPort(void) const { return m_peer_port; } + const std::string& secret(void) const { return m_secret; } + const std::string& localPrefix(void) const { return m_local_prefix; } private: using FramedTcpClient =