From 1f4ffdfee959614e3afe7e7daab06a040ca1ac41 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 13 Jan 2023 20:43:13 +0000 Subject: Various improvements to the cloak system. - Only rewrite cloak => cloaking if the cloak_md5 module is also loaded. - Include the cloak method in the link data. - If 1206 servers are using different cloak methods then ignore the other data when telling operators about the link failure. - Clean up the code in a few places. --- src/modules/m_cloak_sha256.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/modules/m_cloak_sha256.cpp') diff --git a/src/modules/m_cloak_sha256.cpp b/src/modules/m_cloak_sha256.cpp index ebd0c178d..a8ad87a5e 100644 --- a/src/modules/m_cloak_sha256.cpp +++ b/src/modules/m_cloak_sha256.cpp @@ -85,7 +85,7 @@ private: const std::string beta = Hash(InspIRCd::Format("%u.%u.%u", a, b, c)); const std::string gamma = Hash(InspIRCd::Format("%u.%u", a, b)); - return Wrap(InspIRCd::Format("%s.%s.%s", alpha.c_str(), beta.c_str(), gamma.c_str()), "."); + return Wrap(InspIRCd::Format("%s.%s.%s", alpha.c_str(), beta.c_str(), gamma.c_str()), '.'); } std::string CloakIPv6(const unsigned char* address) @@ -109,7 +109,7 @@ private: const std::string beta = Hash(InspIRCd::Format("%x:%x:%x:%x:%x:%x:%x", a, b, c, d, e, f, g)); const std::string gamma = Hash(InspIRCd::Format("%x:%x:%x:%x", a, b, c, d)); - return Wrap(InspIRCd::Format("%s:%s:%s", alpha.c_str(), beta.c_str(), gamma.c_str()), ":"); + return Wrap(InspIRCd::Format("%s:%s:%s", alpha.c_str(), beta.c_str(), gamma.c_str()), ':'); } std::string CloakHost(const std::string& host, char separator) @@ -136,14 +136,14 @@ private: return out; } - std::string Wrap(const std::string& cloak, const char* separator) + std::string Wrap(const std::string& cloak, char separator) { std::string fullcloak; if (!prefix.empty()) - fullcloak.append(prefix).append(separator); + fullcloak.append(prefix).append(1, separator); fullcloak.append(cloak); if (!suffix.empty()) - fullcloak.append(separator).append(suffix); + fullcloak.append(1, separator).append(suffix); return fullcloak; } @@ -190,15 +190,11 @@ public: // IMPORTANT: link data is sent over unauthenticated server links so we // can't directly send the key here. Instead we use dummy cloaks that // allow verification of or less the same thing. - irc::sockets::sockaddrs sa; - if (sa.from_ip("123.123.123.123")) - data["cloak-v4"] = sha256 ? CloakAddress(sa) : broken; + data["cloak-v4"] = sha256 ? Generate("123.123.123.123") : broken; + data["cloak-v6"] = sha256 ? Generate("dead:beef:cafe::") : broken; + data["cloak-host"] = sha256 ? Generate("cloak.inspircd.org") : broken; + data["cloak-unix"] = sha256 ? Generate("/inspircd/cloak.sock") : broken; - if (sa.from_ip("dead:beef:cafe::")) - data["cloak-v6"] = sha256 ? CloakAddress(sa) : broken; - - data["cloak-host"] = sha256 ? CloakHost("cloak.inspircd.org", '.') : broken; - data["cloak-unix"] = sha256 ? CloakHost("/inspircd/cloak.sock", '/') : broken; data["host-parts"] = ConvToStr(hostparts); data["prefix"] = prefix; data["suffix"] = suffix; -- cgit v1.3.1-10-gc9f91