From 93c396eef9a7ff990105ca03a9bc51f4c5fc77e5 Mon Sep 17 00:00:00 2001 From: Audric Date: Sun, 17 May 2026 01:04:25 +0200 Subject: [PATCH] feat(satellite): resolve secret per-id in MsgPeerHello handler --- src/svxlink/reflector/Reflector.cpp | 2 +- src/svxlink/reflector/SatelliteLink.cpp | 38 +++++++++++++++++-------- src/svxlink/reflector/SatelliteLink.h | 5 ++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/svxlink/reflector/Reflector.cpp b/src/svxlink/reflector/Reflector.cpp index 94ec4c0..20ac01a 100644 --- a/src/svxlink/reflector/Reflector.cpp +++ b/src/svxlink/reflector/Reflector.cpp @@ -2785,7 +2785,7 @@ void Reflector::satelliteConnected(Async::FramedTcpConnection* con) { geulog::info("satellite", "SAT: Inbound connection from ", con->remoteHost(), ":", con->remotePort()); - auto* link = new SatelliteLink(this, con, m_satellite_secret); + auto* link = new SatelliteLink(this, con); link->linkFailed.connect( sigc::mem_fun(*this, &Reflector::onSatelliteLinkFailed)); link->statusChanged.connect( diff --git a/src/svxlink/reflector/SatelliteLink.cpp b/src/svxlink/reflector/SatelliteLink.cpp index fbad4d4..0d76828 100644 --- a/src/svxlink/reflector/SatelliteLink.cpp +++ b/src/svxlink/reflector/SatelliteLink.cpp @@ -87,9 +87,8 @@ void sanitizeJsonStrings(Json::Value& v, unsigned depth = 0) SatelliteLink::SatelliteLink(Reflector* reflector, - Async::FramedTcpConnection* con, - const std::string& secret) - : m_reflector(reflector), m_con(con), m_secret(secret), + Async::FramedTcpConnection* con) + : m_reflector(reflector), m_con(con), m_hello_received(false), m_heartbeat_timer(1000, Timer::TYPE_PERIODIC), m_hb_tx_cnt(HEARTBEAT_TX_CNT_RESET), @@ -299,25 +298,40 @@ void SatelliteLink::handleMsgPeerHello(std::istream& is) return; } - if (!msg.verify(m_secret)) + std::string secret; + bool pinned = false; + if (!m_reflector->resolveSatelliteSecret(msg.id(), secret, pinned)) { - geulog::error("satellite", "Authentication failed for satellite '", - msg.id(), "'"); + geulog::error("satellite", + "No secret configured to authenticate satellite '", + msg.id(), "' (no SECRET_= match and no fallback " + "SECRET=) — rejecting"); m_con->disconnect(); return; } - m_satellite_id = msg.id(); - m_hello_received = true; + if (!msg.verify(secret)) + { + geulog::error("satellite", + "Authentication failed for satellite '", msg.id(), + "' (pinned=", (pinned ? "true" : "false"), ")"); + m_con->disconnect(); + return; + } - geulog::info("satellite", "Satellite '", m_satellite_id, "' authenticated"); + m_resolved_secret = secret; + m_satellite_id = msg.id(); + m_hello_received = true; + + geulog::info("satellite", "Satellite '", m_satellite_id, + "' authenticated (pinned=", (pinned ? "true" : "false"), ")"); // Send hello reply so the satellite client can set m_hello_received - // and start forwarding local events. This also generates early + // and start forwarding local events. This also generates early // parent→satellite traffic, keeping the connection alive through // firewalls / NAT devices that drop idle TCP sessions. - sendMsg(MsgPeerHello("PARENT", "", 0, m_secret, - MsgPeerHello::ROLE_PEER)); + sendMsg(MsgPeerHello("PARENT", "", 0, m_resolved_secret, + MsgPeerHello::ROLE_PEER)); // Bring the new satellite up to speed: schedule a debounced node-list // emission so it receives the parent's combined view (parent-local diff --git a/src/svxlink/reflector/SatelliteLink.h b/src/svxlink/reflector/SatelliteLink.h index eba8ad5..5a177f9 100644 --- a/src/svxlink/reflector/SatelliteLink.h +++ b/src/svxlink/reflector/SatelliteLink.h @@ -26,8 +26,7 @@ The parent always wins talker arbitration over satellites. class SatelliteLink : public sigc::trackable { public: - SatelliteLink(Reflector* reflector, Async::FramedTcpConnection* con, - const std::string& secret); + SatelliteLink(Reflector* reflector, Async::FramedTcpConnection* con); ~SatelliteLink(void); bool isAuthenticated(void) const { return m_hello_received; } @@ -91,7 +90,7 @@ class SatelliteLink : public sigc::trackable Reflector* m_reflector; Async::FramedTcpConnection* m_con; - std::string m_secret; + std::string m_resolved_secret; // set in handleMsgPeerHello std::string m_satellite_id; bool m_hello_received; Async::Timer m_heartbeat_timer;