feat(satellite): resolve secret per-id in MsgPeerHello handler
This commit is contained in:
1 parent
5ded17fd24
commit
93c396eef9
3 files changed
+25
-12
No files matched your search
@@ -2785,7 +2785,7 @@ void Reflector::satelliteConnected(Async::FramedTcpConnection* con)
|
|||||||
{
|
{
|
||||||
geulog::info("satellite", "SAT: Inbound connection from ",
|
geulog::info("satellite", "SAT: Inbound connection from ",
|
||||||
con->remoteHost(), ":", con->remotePort());
|
con->remoteHost(), ":", con->remotePort());
|
||||||
auto* link = new SatelliteLink(this, con, m_satellite_secret);
|
auto* link = new SatelliteLink(this, con);
|
||||||
link->linkFailed.connect(
|
link->linkFailed.connect(
|
||||||
sigc::mem_fun(*this, &Reflector::onSatelliteLinkFailed));
|
sigc::mem_fun(*this, &Reflector::onSatelliteLinkFailed));
|
||||||
link->statusChanged.connect(
|
link->statusChanged.connect(
|
||||||
|
|||||||
@@ -87,9 +87,8 @@ void sanitizeJsonStrings(Json::Value& v, unsigned depth = 0)
|
|||||||
|
|
||||||
|
|
||||||
SatelliteLink::SatelliteLink(Reflector* reflector,
|
SatelliteLink::SatelliteLink(Reflector* reflector,
|
||||||
Async::FramedTcpConnection* con,
|
Async::FramedTcpConnection* con)
|
||||||
const std::string& secret)
|
: m_reflector(reflector), m_con(con),
|
||||||
: m_reflector(reflector), m_con(con), m_secret(secret),
|
|
||||||
m_hello_received(false),
|
m_hello_received(false),
|
||||||
m_heartbeat_timer(1000, Timer::TYPE_PERIODIC),
|
m_heartbeat_timer(1000, Timer::TYPE_PERIODIC),
|
||||||
m_hb_tx_cnt(HEARTBEAT_TX_CNT_RESET),
|
m_hb_tx_cnt(HEARTBEAT_TX_CNT_RESET),
|
||||||
@@ -299,24 +298,39 @@ void SatelliteLink::handleMsgPeerHello(std::istream& is)
|
|||||||
return;
|
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 '",
|
geulog::error("satellite",
|
||||||
msg.id(), "'");
|
"No secret configured to authenticate satellite '",
|
||||||
|
msg.id(), "' (no SECRET_<id>= match and no fallback "
|
||||||
|
"SECRET=) — rejecting");
|
||||||
m_con->disconnect();
|
m_con->disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!msg.verify(secret))
|
||||||
|
{
|
||||||
|
geulog::error("satellite",
|
||||||
|
"Authentication failed for satellite '", msg.id(),
|
||||||
|
"' (pinned=", (pinned ? "true" : "false"), ")");
|
||||||
|
m_con->disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_resolved_secret = secret;
|
||||||
m_satellite_id = msg.id();
|
m_satellite_id = msg.id();
|
||||||
m_hello_received = true;
|
m_hello_received = true;
|
||||||
|
|
||||||
geulog::info("satellite", "Satellite '", m_satellite_id, "' authenticated");
|
geulog::info("satellite", "Satellite '", m_satellite_id,
|
||||||
|
"' authenticated (pinned=", (pinned ? "true" : "false"), ")");
|
||||||
|
|
||||||
// Send hello reply so the satellite client can set m_hello_received
|
// 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
|
// parent→satellite traffic, keeping the connection alive through
|
||||||
// firewalls / NAT devices that drop idle TCP sessions.
|
// firewalls / NAT devices that drop idle TCP sessions.
|
||||||
sendMsg(MsgPeerHello("PARENT", "", 0, m_secret,
|
sendMsg(MsgPeerHello("PARENT", "", 0, m_resolved_secret,
|
||||||
MsgPeerHello::ROLE_PEER));
|
MsgPeerHello::ROLE_PEER));
|
||||||
|
|
||||||
// Bring the new satellite up to speed: schedule a debounced node-list
|
// Bring the new satellite up to speed: schedule a debounced node-list
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ The parent always wins talker arbitration over satellites.
|
|||||||
class SatelliteLink : public sigc::trackable
|
class SatelliteLink : public sigc::trackable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SatelliteLink(Reflector* reflector, Async::FramedTcpConnection* con,
|
SatelliteLink(Reflector* reflector, Async::FramedTcpConnection* con);
|
||||||
const std::string& secret);
|
|
||||||
~SatelliteLink(void);
|
~SatelliteLink(void);
|
||||||
|
|
||||||
bool isAuthenticated(void) const { return m_hello_received; }
|
bool isAuthenticated(void) const { return m_hello_received; }
|
||||||
@@ -91,7 +90,7 @@ class SatelliteLink : public sigc::trackable
|
|||||||
|
|
||||||
Reflector* m_reflector;
|
Reflector* m_reflector;
|
||||||
Async::FramedTcpConnection* m_con;
|
Async::FramedTcpConnection* m_con;
|
||||||
std::string m_secret;
|
std::string m_resolved_secret; // set in handleMsgPeerHello
|
||||||
std::string m_satellite_id;
|
std::string m_satellite_id;
|
||||||
bool m_hello_received;
|
bool m_hello_received;
|
||||||
Async::Timer m_heartbeat_timer;
|
Async::Timer m_heartbeat_timer;
|
||||||
|
|||||||
Reference in new issue
Block a user