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.
This commit is contained in:
Audric committed 2026-04-15 21:13:58 +02:00
1 parent 4b6346d4ab
commit 9b748d1bdc
2 files changed
+21 -1

No files matched your search

+19 -1
View File
@@ -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);