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:
1 parent
4b6346d4ab
commit
9b748d1bdc
2 files changed
+21
-1
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in new issue
Block a user