feat(satellite): parse per-id SECRET_<id>= entries in [SATELLITE]

This commit is contained in:
Audric committed 2026-05-17 00:49:43 +02:00
1 parent 0c23d5a627
commit d6110f91cb
2 files changed
+78 -6

No files matched your search

+56 -5
View File
@@ -2688,22 +2688,73 @@ void Reflector::trunkPendingTimeout(Async::Timer* t)
void Reflector::initSatelliteServer(void) void Reflector::initSatelliteServer(void)
{ {
std::string sat_port; std::string sat_port;
std::string sat_secret; if (!m_cfg->getValue("SATELLITE", "LISTEN_PORT", sat_port))
if (!m_cfg->getValue("SATELLITE", "LISTEN_PORT", sat_port) ||
!m_cfg->getValue("SATELLITE", "SECRET", sat_secret) ||
sat_secret.empty())
{ {
return; // No [SATELLITE] section — not accepting satellites return; // No [SATELLITE] section — not accepting satellites
} }
// Fallback (optional). Empty/absent means "no fallback".
m_satellite_secret.clear();
std::string sat_secret;
if (m_cfg->getValue("SATELLITE", "SECRET", sat_secret))
{
m_satellite_secret = sat_secret; m_satellite_secret = sat_secret;
}
// Per-id secrets: enumerate every tag in [SATELLITE] starting with
// "SECRET_" and validate the suffix against [A-Za-z0-9-]+. Malformed
// entries are logged and ignored.
m_satellite_secrets.clear();
auto isValidIdChar = [](char c) {
return (c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ||
c == '-';
};
for (const std::string& tag : m_cfg->listSection("SATELLITE"))
{
static const std::string kPrefix = "SECRET_";
if (tag.compare(0, kPrefix.size(), kPrefix) != 0) continue;
std::string id = tag.substr(kPrefix.size());
bool valid = !id.empty();
for (char c : id)
{
if (!isValidIdChar(c)) { valid = false; break; }
}
if (!valid)
{
geulog::warn("satellite", "ignoring malformed [SATELLITE] secret "
"key '", tag, "' — id must be [A-Za-z0-9-]+");
continue;
}
std::string value;
m_cfg->getValue("SATELLITE", tag, value);
if (value.empty())
{
geulog::warn("satellite", "ignoring empty [SATELLITE] secret value "
"for key '", tag, "'");
continue;
}
m_satellite_secrets[id] = value;
}
if (m_satellite_secret.empty() && m_satellite_secrets.empty())
{
geulog::warn("satellite",
"[SATELLITE] has neither SECRET= nor any SECRET_<id>= — "
"all satellite connections will be rejected");
}
m_sat_srv = new TcpServer<FramedTcpConnection>(sat_port); m_sat_srv = new TcpServer<FramedTcpConnection>(sat_port);
m_sat_srv->clientConnected.connect( m_sat_srv->clientConnected.connect(
sigc::mem_fun(*this, &Reflector::satelliteConnected)); sigc::mem_fun(*this, &Reflector::satelliteConnected));
m_sat_srv->clientDisconnected.connect( m_sat_srv->clientDisconnected.connect(
sigc::mem_fun(*this, &Reflector::satelliteDisconnected)); sigc::mem_fun(*this, &Reflector::satelliteDisconnected));
geulog::info("core", "Satellite server listening on port ", sat_port); geulog::info("core", "Satellite server listening on port ", sat_port,
" (per-id secrets: ", m_satellite_secrets.size(),
", fallback: ", (m_satellite_secret.empty() ? "no" : "yes"),
")");
} /* Reflector::initSatelliteServer */ } /* Reflector::initSatelliteServer */
+22 -1
View File
@@ -317,6 +317,26 @@ class Reflector : public sigc::trackable
const std::vector<uint8_t>& audio); const std::vector<uint8_t>& audio);
void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg); void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg);
/**
* Resolve the HMAC secret to verify a satellite's MsgPeerHello.
*
* Lookup rule:
* 1. If [SATELLITE].SECRET_<id> is configured, return that value
* and set pinned=true. Caller MUST reject the connection on
* HMAC mismatch — there is no fallback once an id is pinned.
* 2. Otherwise, if [SATELLITE].SECRET is configured, return it
* with pinned=false.
* 3. Otherwise return false (no secret available — reject).
*
* @param id SATELLITE_ID from the incoming hello.
* @param out_secret On true return, the secret to verify against.
* @param out_pinned On true return, whether the per-id path was used.
* @return true if a secret was resolved.
*/
bool resolveSatelliteSecret(const std::string& id,
std::string& out_secret,
bool& out_pinned) const;
void publishRxUpdate(ReflectorClient* client); void publishRxUpdate(ReflectorClient* client);
// Push the rich per-client status blob (rx, monitoredTGs, qth, ...) // Push the rich per-client status blob (rx, monitoredTGs, qth, ...)
// to Redis. Cheap no-op if Redis is not configured. // to Redis. Cheap no-op if Redis is not configured.
@@ -455,7 +475,8 @@ class Reflector : public sigc::trackable
bool m_is_satellite = false; bool m_is_satellite = false;
SatelliteClient* m_satellite_client = nullptr; SatelliteClient* m_satellite_client = nullptr;
FramedTcpServer* m_sat_srv = nullptr; FramedTcpServer* m_sat_srv = nullptr;
std::string m_satellite_secret; std::string m_satellite_secret; // fallback (optional)
std::map<std::string, std::string> m_satellite_secrets; // per-id (optional)
std::map<Async::FramedTcpConnection*, SatelliteLink*> m_satellite_con_map; std::map<Async::FramedTcpConnection*, SatelliteLink*> m_satellite_con_map;
std::vector<SatelliteLink*> m_sat_cleanup_pending; std::vector<SatelliteLink*> m_sat_cleanup_pending;
Async::Timer m_sat_cleanup_timer; Async::Timer m_sat_cleanup_timer;